Print: an overprinting freeform gradient leaves out the cells its plate samples write without ink

On a PostScript plate, an overprinting freeform gradient left out only the
cells whose color is paper white. A cell such as 0.1% cyan rounds to no ink
in the 8-bit samples, yet it was kept and painted paper over the ink below.
The cells are now classified from the samples the image writes.

At Level 2, a field drawn again inside the clip of its inked cells was
charged its samples a second time against the page limit, so a page with
room for a reference to the image already kept left the placement out with
the too-large warning. The check now charges the reference when the image
is already kept.

Follows #8400.
This commit is contained in:
dotCooCoo committed 2026-11-20 22:47:38 -08:00
1 parent 9fff48d88f
commit 5ea4753750
4 files changed
+83 -26

No files matched your search

+13
View File
@@ -403,3 +403,16 @@ fn overprinting_gradient_strokes_type_freeforms_and_spot_inks_keep_the_ink_below
];
assert_keeps_the_ink_below(&cases);
}
#[test]
fn an_overprinting_freeform_gradient_leaves_out_the_cells_its_samples_write_without_ink_on_a_postscript_plate() {
// 0.1% cyan around the left point: not paper white, but the plate's 8-bit samples write it as
// none of the ink, so the cyan below prints there.
let (faint, inked) = (Color::cmyk(0.001, 0.3, 0.0, 0.0), Color::cmyk(0.6, 0.3, 0.0, 0.0));
let mut freeform = GradientPaint::new(Gradient::new(GradientKind::Freeform, vec![GradientStop::new(0.0, faint), GradientStop::new(1.0, inked)]));
let pure = |at: Point, c: Color| FreeformPoint { spread: 0.9, ..FreeformPoint::new(at, c) };
freeform.freeform =
Some(Freeform { points: vec![pure(Point::new(50.0, 50.0), faint), pure(Point::new(150.0, 50.0), inked)], ..Default::default() });
let cyan = Paint::solid(Color::cmyk(1.0, 0.0, 0.0, 0.0));
assert_keeps_the_ink_below(&[("faint", overprinting(Paint::Gradient(Box::new(freeform)), Paint::None), cyan, "Cyan")]);
}
+37 -25
View File
@@ -8,7 +8,6 @@ use std::sync::Arc;
use kurbo::Shape;
use vectorcraft_color::{BlendMode, Color, GradientKind, GradientPaint, Paint};
use vectorcraft_doc::overprint::is_white;
use vectorcraft_doc::{
AppearanceItem, ColorMode, Document, Effect, ImageBlob, LineCap, LineJoin, Node, NodeKind, StrokeAlign, StrokeLayer, SymbolBoxes, TextObject,
};
@@ -1586,30 +1585,34 @@ impl<'a> Scene<'a> {
let field = g.freeform_on(b).model_field(spread_scale(b));
let q = |v: f32| (unit(v) * 255.0).round() as u8;
let (w, h) = (u32::from(cols), u32::from(rows));
// Overprinting on a plate: the cells of paper white put none of the ink down, so they are
// left out, as clear pixels at Level 3 and outside a clip of the other cells at Level 2.
let blank: Option<Vec<bool>> = self.keep_below.then(|| field.grid(area, cols, rows).map(|(c, _)| is_white(&Paint::solid(c))).collect());
let in_inks = field.model() == Some(Model::Cmyk) || (self.cmyk && field.model() == Some(Model::Gray));
// Each cell's samples: its inks or its RGB, then its alpha.
let (mut samples, paper): (Vec<u8>, u8) = if in_inks {
let inks = field.grid(area, cols, rows).flat_map(|(color, a)| {
let [c, m, y, k] = color.to_cmyk();
[q(c), q(m), q(y), q(k), q(a)]
});
(inks.collect(), 0)
} else {
(field.display_grid(area, cols, rows).flat_map(|(c, a)| [q(c[0]), q(c[1]), q(c[2]), q(a)]).collect(), 255)
};
let n = if in_inks { 5 } else { 4 };
// Overprinting on a plate: the cells whose samples put none of the ink down are left out,
// as clear pixels at Level 3 and outside a clip of the other cells at Level 2.
let blank: Option<Vec<bool>> = self.keep_below.then(|| samples.chunks(n).map(|s| s.iter().take(n - 1).all(|&v| v == paper)).collect());
let blank = blank.filter(|b| b.contains(&true));
if blank.as_ref().is_some_and(|b| !b.contains(&false)) {
return;
}
let keyed = self.o.level == Level::Three;
let clear = |i: usize, a: u8| if keyed && blank.as_ref().is_some_and(|b| b[i]) { 0 } else { a };
let image = if field.model() == Some(Model::Cmyk) || (self.cmyk && field.model() == Some(Model::Gray)) {
let inks: Vec<u8> = field
.grid(area, cols, rows)
.enumerate()
.flat_map(|(i, (color, a))| {
let [c, m, y, k] = color.to_cmyk();
[q(c), q(m), q(y), q(k), clear(i, q(a))]
})
.collect();
self.encode_inks(&inks, w, h)
} else {
let rgba: Vec<u8> =
field.display_grid(area, cols, rows).enumerate().flat_map(|(i, (c, a))| [q(c[0]), q(c[1]), q(c[2]), clear(i, q(a))]).collect();
self.encode_image(&rgba, w, h)
};
if let Some(b) = blank.as_ref().filter(|_| keyed) {
for (s, _) in samples.chunks_mut(n).zip(b).filter(|(_, blank)| **blank) {
if let Some(a) = s.last_mut() {
*a = 0;
}
}
}
let image = if in_inks { self.encode_inks(&samples, w, h) } else { self.encode_image(&samples, w, h) };
let Some(image) = image else { return };
let cells = blank.filter(|_| !keyed).map(|b| {
let (cw, ch) = (area.width() / f64::from(cols), area.height() / f64::from(rows));
@@ -1631,8 +1634,13 @@ impl<'a> Scene<'a> {
bp
});
if let Some(bp) = &cells {
// Each row's run of cells is a rectangle of five path elements, about 60 bytes.
if self.size().saturating_add(bp.elements().len().saturating_mul(12)).saturating_add(image.inline_len) > self.max_body {
// Each row's run of cells is a rectangle of five path elements, about 60 bytes. The
// image is a reference when one encoded the same is already drawn.
let cost = self
.kept_field(&image)
.and_then(|i| self.codes.get(i))
.map_or(image.inline_len, |c| if c.uses == 0 { c.inline_len } else { c.ref_len });
if self.size().saturating_add(bp.elements().len().saturating_mul(12)).saturating_add(cost) > self.max_body {
self.warn(TOO_LARGE);
return;
}
@@ -1649,9 +1657,7 @@ impl<'a> Scene<'a> {
/// image already kept when one is encoded the same.
fn place_field(&mut self, image: ImageCode, place: Affine) {
let key = image.content_key();
let found =
self.fields.get(&key).and_then(|bucket| bucket.iter().copied().find(|&i| self.codes.get(i).is_some_and(|c| c.same_image(&image))));
let i = match found {
let i = match self.kept_field(&image) {
Some(i) => i,
None => {
// A field that can't be placed isn't kept.
@@ -1667,6 +1673,12 @@ impl<'a> Scene<'a> {
self.place_image(i, place);
}
/// The index in `codes` of a kept freeform gradient image encoded the same as `image`.
fn kept_field(&self, image: &ImageCode) -> Option<usize> {
let bucket = self.fields.get(&image.content_key())?;
bucket.iter().copied().find(|&i| self.codes.get(i).is_some_and(|c| c.same_image(image)))
}
/// Forget the encoded images after the first `n` codes that no placement draws any longer, and
/// the cache entries that name them: placed images, colorized images and fields. A code that a
/// placement still draws keeps itself and every code before it.
+32
View File
@@ -1605,6 +1605,38 @@ fn a_field_taken_back_at_the_page_limit_leaves_no_image_behind() {
assert!(page.setup.contains("/VCim0 VCsrc") && !page.setup.contains("VCim1"), "{}", page.setup);
}
/// On a plate at Level 2, an overprinting field drawn again inside the clip of its inked cells
/// is charged the reference to the image already kept against the page limit, not its samples a
/// second time: a page with room for that reference keeps both placements.
#[test]
fn a_repeated_field_clipped_on_a_plate_is_charged_its_reference_at_the_page_limit() {
let square = |d: &mut Document| {
// Wide spreads of pure color: paper white around the left point.
let mut g = GradientPaint::new(Gradient { kind: GradientKind::Freeform, ..Default::default() });
let pure = |x: f64, c: Color| FreeformPoint { spread: 0.9, ..FreeformPoint::new(Point::new(x, 32.0), c) };
g.freeform = Some(Freeform { points: vec![pure(12.0, Color::gray(0.0)), pure(52.0, Color::gray(0.6))], ..Default::default() });
let mut n = path(d, shapes::rectangle(Rect::new(0.0, 0.0, 64.0, 64.0)), Paint::Gradient(Box::new(g)), Paint::None, 0.0);
for it in &mut n.appearance.items {
*it.overprint_mut() = true;
}
n
};
let twice = doc_with(|d| vec![square(d), square(d)]);
let o = EpsOptions { level: Level::Two, ..opts(&twice) };
let full = crate::scene::Scene::new(&twice, &o).on_plate(true).run();
assert!(full.warnings.is_empty(), "{:?}", full.warnings);
assert_eq!(reuses(&full.body, 0, Level::Two), 2, "{}", full.body);
assert!(full.body.contains("\nW\n"), "the inked cells clip the image: {}", full.body);
// The image's samples are in the setup and the body draws them twice. The limit leaves room
// for the body and the samples twice over (the clip is charged more than it writes), though
// not for the samples charged again at the second placement.
assert!(full.setup.len() > 2_000, "{}", full.setup.len());
let limit = full.body.len() + 2 * full.setup.len();
let page = crate::scene::Scene::new(&twice, &o).on_plate(true).with_max_body(limit).run();
assert!(page.warnings.is_empty(), "{:?}", page.warnings);
assert_eq!((&page.setup, &page.body), (&full.setup, &full.body));
}
/// A 200 × 200 pt document holding 8 × 8 pixels of noise as image `pic` and a three-pixel gray ramp
/// as image `gray`, its first layer holding what `nodes` makes.
fn image_doc_with(nodes: impl FnOnce(&mut Document) -> Vec<Node>) -> Document {
+1 -1
View File
@@ -2374,7 +2374,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- In the Separations Preview panel, an Alt-click (Option-click on macOS) on the eye of the plate shown alone shows every plate again, spot plates included, as [the help page](https://helpx.adobe.com/illustrator/using/printing-color-separations.html) describes for a second modified click on the eye (`view.separationsPreview {soloToggle: plate}`); an Alt-click on a plate shown among others shows only that plate, as the help page describes for the first one. VectorCraft's own rules: an Alt-click on a hidden plate, on another plate while one shows alone or while no plate is shown shows only that plate, and `only` still shows just the named plate when repeated (`crates/engine/src/tests/colormgmt.rs`, `crates/ui-egui/src/panels/separations.rs`).
- Desktop print transport uses `craft-print` for CUPS and modern Windows. Sheet composition, copies, separations and colour management remain in VectorCraft. The Print dialog's Media list also carries the Japanese papers — JIS B4 257 × 364 mm, JIS B5 182 × 257 mm and JIS B6 128 × 182 mm beside the ISO B4/B5 (250 × 353 and 176 × 250 mm, kept so settings and presets saved before them keep their paper), and はがき 100 × 148 mm, 往復はがき 148 × 200 mm, 封筒 長形3号 120 × 235 mm, 長形4号 90 × 225 mm, 角形2号 240 × 332 mm, 角形3号 216 × 277 mm and 四六判 127 × 188 mm; the JSON id or the dialog label names a paper, any case and spacing (`B5 (JIS)` or `b5jis`) (`crates/pdf/src/print/settings.rs`, `crates/pdf/src/tests/print.rs`). The print-preview and physical-device fidelity gaps remain, so print scores and hours are unchanged.
- The Print dialog's Document Ink Options list shows an icon before each spot ink's name, and a click on it prints that one ink as process inks (on the Cyan, Magenta, Yellow and Black plates, with no plate of its own) or as a spot ink again, as [the help page](https://helpx.adobe.com/illustrator/using/printing-color-separations.html) describes for single spot colors. Other spot inks keep their plates, and spot gradient stops and DCS images' spot plates follow each ink's choice (`print.setup {settings: {output: {inks: [{name, convertToProcess: true}]}}}`, kept with the document and in print presets; `print.preview` lists every ink as `documentInks`). These are VectorCraft's own rules: Convert All Spot Colors to Process converts every spot ink and dims the icons while keeping each ink's own choice, a converted ink's Print, Frequency and Angle are dimmed and kept, and process inks and Registration have no icon. Evidence: `print::one_spot_ink_converts_to_process_and_the_others_keep_their_plates`, `print::converting_every_spot_ink_overrides_and_keeps_each_inks_own_choice`, `print::a_spot_gradient_stop_prints_its_process_plates`, `cmykimages::a_dcs_image_converts_only_the_spot_ink_chosen`, `tests::print::a_spot_ink_converted_to_process_is_saved_and_listed_without_a_plate`, `dialogs::tests_print::a_spot_inks_icon_converts_it_to_process_and_back`. Print scores and hours are unchanged.
- On a PostScript plate, an overprinting gradient that puts the plate's ink down in some places and none in others leaves the ink below where it puts none: the stretches between stops of paper white and the padding past an end that is painted paper white (with the end stop's color at Level 2 and the color of the stretch next to it in a Level 3 smooth shading, which differ when two stops share the end's offset) are clipped out of a linear, radial or diamond gradient, the wedges of paper white out of a conic one, and the cells of paper white out of a freeform one (masked at Level 3, clipped at Level 2). This holds for fills, strokes and characters, and on spot plates. Where the gradient puts ink down, its amount replaces the ink below as before. A stop or point with up to half a percent of another ink in a color that counts as black puts none down, as a solid fill of that color does. PDF plates are unchanged. These are VectorCraft's own rules. Evidence: `print::tests::an_overprinting_gradient_keeps_the_ink_below_where_it_puts_none_on_a_postscript_plate`, `print::tests::an_overprinting_gradient_with_a_hard_stop_at_an_end_keeps_the_ink_below_on_a_postscript_plate` and `print::tests::overprinting_gradient_strokes_type_freeforms_and_spot_inks_keep_the_ink_below_on_postscript_plates` (`vectorcraft-eps`), `tests::print::a_near_black_stop_of_an_overprinting_gradient_puts_no_cyan_on_postscript_plates`.
- On a PostScript plate, an overprinting gradient that puts the plate's ink down in some places and none in others leaves the ink below where it puts none: the stretches between stops of paper white and the padding past an end that is painted paper white (with the end stop's color at Level 2 and the color of the stretch next to it in a Level 3 smooth shading, which differ when two stops share the end's offset) are clipped out of a linear, radial or diamond gradient, the wedges of paper white out of a conic one, and the cells whose 8-bit samples carry none of the plate's ink out of a freeform one (masked at Level 3, clipped at Level 2). This holds for fills, strokes and characters, and on spot plates. Where the gradient puts ink down, its amount replaces the ink below as before. A stop or point with up to half a percent of another ink in a color that counts as black puts none down, as a solid fill of that color does. PDF plates are unchanged. These are VectorCraft's own rules. Evidence: `print::tests::an_overprinting_gradient_keeps_the_ink_below_where_it_puts_none_on_a_postscript_plate`, `print::tests::an_overprinting_gradient_with_a_hard_stop_at_an_end_keeps_the_ink_below_on_a_postscript_plate`, `print::tests::overprinting_gradient_strokes_type_freeforms_and_spot_inks_keep_the_ink_below_on_postscript_plates` and `print::tests::an_overprinting_freeform_gradient_leaves_out_the_cells_its_samples_write_without_ink_on_a_postscript_plate` (`vectorcraft-eps`), `tests::print::a_near_black_stop_of_an_overprinting_gradient_puts_no_cyan_on_postscript_plates`.
- The Print dialog's Output section has Overprint Black under Convert All Spot Colors to Process, off by default and available with Separations ([Print color separations](https://helpx.adobe.com/illustrator/using/printing-color-separations.html) lists it among the separation options): black art then leaves the inks under it on the other plates (`print.setup {settings: {output: {overprintBlack: true}}}`, kept with the document and in print presets). Solid 100% K or 100% gray fills, strokes and characters (to within half a percent, as Edit › Edit Colors › Overprint Black counts them), and gradients whose every stop (every color point of a freeform gradient) is, overprint; rich, RGB, Lab, spot-linked and lighter blacks are not marked, paints already set to overprint keep that setting, and only the printed copy is marked. These limits are VectorCraft's own rules. Characters set to overprint now also leave the inks below them on printed PDF plates, a type object's own fill in a PDF is drawn with its blending mode, and Edit › Edit Colors › Overprint Black counts a gradient with a stop linked to a spot swatch as a spot black, as it counts a solid one, and a freeform gradient by the color points it draws from. On a plate, an overprinting paint that puts none of that plate's ink down is drawn as nothing; on PostScript plates so is up to half a percent of another ink in a color that counts as black, and any other faint ink stays on the plate. A black linked to a swatch the document lacks separates from its own values, so on PostScript plates it counts as an unlinked black (VectorCraft's own rule). Evidence: `print::overprint_black_keeps_the_inks_under_solid_black_on_separations`, `print::overprint_black_keeps_the_cyan_under_near_and_freeform_blacks_on_postscript_plates`, `print::overprint_black_keeps_the_cyan_under_a_near_black_linked_to_a_missing_swatch_on_postscript_plates`, `print::overprinting_near_blacks_linked_to_a_missing_swatch_keep_the_cyan_on_postscript_plates`, `print::overprinting_paints_keep_their_faint_ink_on_postscript_plates`, `print::overprinting_type_leaves_the_inks_below_on_separations`, `print::a_type_objects_own_black_fill_overprints_on_separations`, `tests::print::overprint_black_is_saved_with_the_setup_and_in_presets`, `overprint::tests::a_gradient_with_a_spot_linked_stop_is_black_only_with_spot`, `overprint::tests::a_freeform_gradient_is_black_when_every_point_is`. Print scores and hours are unchanged.
- The Print dialog's General section (and the print preset editor) has a link button after Scale W and H, as the Custom scale has one on [the help page](https://helpx.adobe.com/illustrator/desktop/save-and-export/export-files-to-different-formats/print-documents-in-illustrator.html), where turning it off scales the width and height apart. While it is on, typing either percentage sets the other, and turning it on sets H to W. It is on for new settings, dimmed with the fields unless Scaling is Custom or a tiling choice, toggled with a click, Space or Enter, and named with its on or off state for screen readers. W and H take 1–1000% in the fields. The link is kept with the document's print settings and in print presets (`print.setup {settings: {scale: {linked}}}`); settings saved without it read it as off, so they print as before. Its default, the tiling choices and the agent rules are VectorCraft's own. Evidence: `print::the_scale_link_is_on_for_new_settings_and_off_for_a_saved_scale_without_it`, `tests::print::the_scale_link_keeps_width_and_height_equal`, `tests::print::a_scale_saved_without_the_link_keeps_its_width_and_height`, `dialogs::tests_print::the_scale_link_keeps_scale_width_and_height_equal`, `dialogs::tests_print::a_print_preset_keeps_the_scale_link`. Print scores and hours are unchanged.
- A PDF, PDF-compatible `.ai` or `.ait` opened from its pages or its editing copy opens with the File Info that its XMP packet and its document information dictionary give: the title (`dc:title`, its `x-default` item first, else Info `Title`), the author, description, keywords, copyright status, notice and URL, and the created and modified dates, the XMP packet's value where both give one (`crates/pdf/src/tests/file_info.rs`, `crates/engine/src/tests/fileinfo.rs`). An SVG opens with the title of its root `<title>`. The title is File Info's alone (`DocMetadata::title`): the document's name stays the file's name with its extension, a file that gives no title leaves File Info with that name, and exports (PDF, SVG, PNG, EPS, `.ai`) and native saves carry it; changing the title in File Info sets the document's name as before (#3626).