PDF: a Document CMYK destination; Press Quality converts to it in RGB documents too (#3012 review)

A blank destination is the document's own profile, so in an RGB document Press Quality (Preserve
Numbers, blank) converted CMYK colours and images to RGB. Output › Destination can now be
DOCUMENT_CMYK, the CMYK profile of the colour settings in effect whatever the document's colour
mode (Illustrator's "Document CMYK"); Press Quality uses it, and the Save PDF dialog lists it after
Document profile. Test: in an RGB document a CMYK image keeps its inks and an RGB image comes out
CMYK.
This commit is contained in:
00xJ0
2026-10-21 16:55:17 +07:00
committed by bflatastic
parent 5d0b966548
commit 91107c89d2
5 changed files with 40 additions and 8 deletions
+2
View File
@@ -160,6 +160,8 @@ fn destination(set: &PdfSettings, mode: ColorMode, source: &Cms) -> Result<Optio
let name = o.destination.trim();
let fallback = if cmyk_only { crate::pdfx::cmyk_destination(set, source) } else { String::new() };
let name = match (name.is_empty(), mode) {
// Document CMYK: the CMYK profile in effect, in an RGB document too (#2950).
(false, _) if name.eq_ignore_ascii_case(crate::DOCUMENT_CMYK) => source.settings().cmyk.as_str(),
(false, _) => name,
(true, _) if cmyk_only => fallback.as_str(),
(true, ColorMode::Cmyk) => source.settings().cmyk.as_str(),
+6 -6
View File
@@ -5,8 +5,8 @@
use serde::{Deserialize, Serialize};
use crate::{
BleedSettings, ColorConversion, Compatibility, CompressionSettings, Downsample, ImageCodec, ImageCompression, JpegQuality, MonoCodec,
MonoCompression, OutputSettings, PdfSettings, Standard,
BleedSettings, ColorConversion, Compatibility, CompressionSettings, DOCUMENT_CMYK, Downsample, ImageCodec, ImageCompression, JpegQuality,
MonoCodec, MonoCompression, OutputSettings, PdfSettings, Standard,
};
/// The built-in preset every PDF export starts from.
@@ -62,16 +62,16 @@ pub fn builtin_presets() -> Vec<PdfPreset> {
PdfSettings { preserve_editing: true, ..Default::default() },
),
preset("High Quality Print", "For desktop printers and proofs: images stay at print resolution.", print(ImageCodec::Auto, false)),
// Converted to the document's profile, its own numbers kept: in a CMYK document RGB colours
// and images come out CMYK, as a press needs (#2950). A printer's published settings for
// Converted to Document CMYK, the numbers of colours already in it kept: RGB colours and
// images come out CMYK, in an RGB document too, as a press needs (#2950). A printer's published settings for
// the [Press Quality] preset list the same Output: Convert to Destination (Preserve
// Numbers), Document CMYK, no profiles included
// (https://postmediasolutions.com/hubfs/Website/Client%20Resources/PostmediaPrintPDFSpecSheet.pdf).
preset(
"Press Quality",
"For commercial printing: high-resolution images compressed losslessly, the document's bleed, colours converted to the document's profile with its own numbers kept (RGB comes out CMYK in a CMYK document).",
"For commercial printing: high-resolution images compressed losslessly, the document's bleed, and colours converted to the CMYK profile in effect (Document CMYK), keeping the numbers of colours already in it.",
PdfSettings {
output: OutputSettings { conversion: ColorConversion::PreserveNumbers, ..Default::default() },
output: OutputSettings { conversion: ColorConversion::PreserveNumbers, destination: DOCUMENT_CMYK.into(), ..Default::default() },
..print(ImageCodec::Zip, true)
},
),
+6 -1
View File
@@ -347,12 +347,17 @@ impl BleedSettings {
}
}
/// The Output destination that names the CMYK profile of the colour settings in effect, in an RGB
/// document as in a CMYK one (Illustrator's "Document CMYK"; #2950).
pub const DOCUMENT_CMYK: &str = "Document CMYK";
/// The Output section.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct OutputSettings {
pub conversion: ColorConversion,
/// Destination profile name (empty: the document's profile).
/// Destination profile name (empty: the document's profile; [`DOCUMENT_CMYK`]: the CMYK
/// profile in effect, whatever the document's colour mode).
pub destination: String,
pub profiles: ProfileInclusion,
/// PDF/X output intent profile name.
+20
View File
@@ -447,3 +447,23 @@ fn press_quality_writes_an_rgb_image_in_a_cmyk_document_as_cmyk() {
let w = written(&export_with_report(&d, &opts(json!({}))).unwrap().bytes);
assert_eq!(w[0].space, "DeviceRGB", "no conversion");
}
/// #3012 review: in an RGB document Press Quality converts to Document CMYK too, the CMYK
/// profile in effect: a CMYK image keeps its inks (not converted to RGB), and an RGB image comes
/// out CMYK.
#[test]
fn press_quality_writes_cmyk_in_an_rgb_document_too() {
let press = || PdfOptions { settings: builtin_preset("Press Quality").unwrap().settings, created: Some(1_700_000_000), ..Default::default() };
assert_eq!(press().settings.output.destination, DOCUMENT_CMYK);
let ink = [0u8, 102, 255, 0];
let tiff = ImageBlob::cmyk_tiff(&Inks::new(4, 4, flat(ink, 16)).unwrap()).unwrap();
let rgb = image::RgbImage::from_fn(4, 4, |x, y| image::Rgb([(x * 60) as u8, (y * 60) as u8, 128]));
let png_blob = ImageBlob { mime: "image/png".into(), bytes: Arc::new(png(rgb)), proxy: None };
for (what, blob) in [("CMYK image", tiff), ("RGB image", png_blob)] {
let mut d = image_doc(blob, 4, 4);
d.color_mode = ColorMode::Rgb;
let w = written(&export_with_report(&d, &press()).unwrap().bytes);
assert_eq!(w.len(), 1, "{what}: {w:?}");
assert_eq!(w[0].space, "DeviceCMYK", "{what} in an RGB document");
}
}
+6 -1
View File
@@ -599,7 +599,12 @@ fn output(ui: &mut egui::Ui, d: &mut Dialog) {
});
// PDF/X-1a converts to CMYK even without a conversion.
let converting = get(d, "output.conversion") != ColorConversion::None.id() || standard.cmyk_only();
row(ui, tl!("Destination:"), |ui| profile_pick(ui, d, "output.destination", &names(DOCUMENT_PROFILE), 1, converting));
// The document's own profile (blank), the CMYK profile in effect, then every profile.
let destinations: Vec<&str> = std::iter::once(DOCUMENT_PROFILE)
.chain(std::iter::once(vectorcraft_pdf::DOCUMENT_CMYK))
.chain(profiles.iter().map(|p| p.name.as_str()))
.collect();
row(ui, tl!("Destination:"), |ui| profile_pick(ui, d, "output.destination", &destinations, 2, converting));
row(ui, tl!("Profile inclusion:"), |ui| {
// A standard decides whether colours are tagged.
ui.add_enabled_ui(standard == Standard::None, |ui| pick::<ProfileInclusion>(ui, d, "output.profiles", 300.0, |_| true));