From 80a8ecfe05143ef979d87bccf3d5353cbea828b9 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 07:11:33 -0500 Subject: [PATCH] Write PDF vector colors without borrowing temporaries --- crates/pdf/src/write/raster.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/crates/pdf/src/write/raster.rs b/crates/pdf/src/write/raster.rs index d68713c28..1aa64ec3c 100644 --- a/crates/pdf/src/write/raster.rs +++ b/crates/pdf/src/write/raster.rs @@ -204,16 +204,26 @@ fn write_content_path(out: &mut String, path: &ContentPath) -> Option<()> { } fn write_device_color(out: &mut String, color: DeviceColor, stroke: bool) -> Option<()> { - let (values, operator): (&[f64], &str) = match color { - DeviceColor::Gray(value) => (&[value], if stroke { "G" } else { "g" }), - DeviceColor::Rgb(values) => (&values, if stroke { "RG" } else { "rg" }), - DeviceColor::Cmyk(values) => (&values, if stroke { "K" } else { "k" }), - }; - finite(values)?; - for value in values { - write!(out, "{value} ").ok()?; + match color { + DeviceColor::Gray(value) => { + finite(&[value])?; + writeln!(out, "{value} {}", if stroke { "G" } else { "g" }).ok()?; + } + DeviceColor::Rgb(values) => { + finite(&values)?; + for value in values { + write!(out, "{value} ").ok()?; + } + writeln!(out, "{}", if stroke { "RG" } else { "rg" }).ok()?; + } + DeviceColor::Cmyk(values) => { + finite(&values)?; + for value in values { + write!(out, "{value} ").ok()?; + } + writeln!(out, "{}", if stroke { "K" } else { "k" }).ok()?; + } } - writeln!(out, "{operator}").ok()?; Some(()) }