DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
PDF: [Paper] prints as no ink in print exports
japbcoelho108e34ff794a
diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rsindex 145b44d2a..7e491646a 100644--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@ -505,6 +505,11 @@ pub(crate) fn solid_fill(c: krilla::color::Color, opacity: f32) -> Fill {}impl Exporter<'_> {+ /// A print document, or a PDF/X file (whose output intent is CMYK).+ pub(crate) fn for_print(&self) -> bool {+ self.doc.settings.intent == designcraft_doc::Intent::Print || self.opts.standard == Standard::PdfX4+ }+pub(crate) fn warn(&mut self, w: impl Into<String>) {let w = w.into();if !self.warnings.contains(&w) {@@ -522,6 +527,10 @@ impl Exporter<'_> {let sw = self.doc.swatch(n)?;match &sw.value {SwatchValue::None => return None,+ // [Paper] prints no ink (it knocks out what lies below); its colour is only what+ // the screen shows. Written as RGB white (`1 1 1 rg`) it would put DeviceRGB in a+ // CMYK print file.+ SwatchValue::Paper { .. } if self.for_print() => return Some(device(&Color::cmyk(0.0, 0.0, 0.0, 0.0), self.rgb_only)),SwatchValue::Tint { base, tint: bt } => {t *= bt;n = base;diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rsindex 2bd9e04be..82ce3c821 100644--- a/crates/pdf/src/tests.rs+++ b/crates/pdf/src/tests.rs@@ -111,6 +111,21 @@ fn colours_keep_their_space() {assert!(s.contains("/Separation") && s.contains("/PANTONE#20Test"), "spot as Separation");}+/// [Paper] went into print PDFs as `1 1 1 rg`, DeviceRGB white.+#[test]+fn paper_prints_as_no_ink() {+ let mut d = doc_with_text("x");+ add_box(&mut d, Rect::new(36.0, 400.0, 136.0, 500.0), "[Paper]");+ let s = uncompressed(&d, PdfOptions::default());+ assert!(s.contains("0 0 0 0 k"), "CMYK, no ink");+ assert!(!s.contains("1 1 1 rg"), "no RGB white");+ // A web document keeps the paper colour.+ d.settings.intent = designcraft_doc::Intent::Web;+ assert!(uncompressed(&d, PdfOptions::default()).contains("1 1 1 rg"));+ // PDF/X has a CMYK output intent whatever the document's intent.+ assert!(!uncompressed(&d, PdfOptions { standard: Standard::PdfX4, ..Default::default() }).contains("1 1 1 rg"));+}+#[test]fn boxes_bleed_and_marks() {let mut d = doc_with_text("x");