Images: Overprint Fill makes a colorized image's color overprint

A grayscale or 1-bit image colorized with a fill color had no way to
overprint: object.setOverprint {fill: true} changed nothing, since an
image has no fill row. The color now carries its own overprint flag
(colorize_overprint in native files).

- object.setOverprint (fill, without item) and attributes.info set and
  read it; Overprint Black and Print Ink Fixes' Remove White Overprint
  treat the color as the image's fill.
- Overprint Preview, Separations Preview and printed separations show
  the inks below the image where its color has none; on a plate the
  color puts no ink on, the image is left out.
- PDF export draws the image in an overprinting graphics state, a
  process color as an image of only the process inks it puts down.
- EPS export turns overprinting on for it, and now leaves white fills,
  strokes and colorized images knocking out with Discard White
  Overprint, as PDF export does.
- A legacy .ai file writes it as the image mask's fill overprint and
  reads it back. Warped pieces, geometry-effect copies and flattening
  keep or drop it as they do for fills.
- A white spot color is an ink: with Discard White Overprint it keeps
  overprinting in PDF and EPS export and in both previews.

Docs: docs/mcp.md (Overprint, Print Ink Fixes), docs/target-app-parity.md.
This commit is contained in:
dotCooCoo committed 2026-11-22 06:15:41 -08:00
1 parent db9acab4da
commit 4f73ef7fbb
29 files changed
+583 -83

No files matched your search

+92
View File
@@ -707,6 +707,98 @@ fn a_color_image_takes_a_fill_item_as_before() {
assert!(s.doc().unwrap().doc.node(id).unwrap().appearance.fill().is_some(), "a fill item, as before");
}
#[test]
fn overprint_fill_makes_a_colorized_images_color_overprint() {
let mut s = session();
let id = image(&mut s, "gray", gray(false));
let overprints = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().colorize_overprints();
// Before the image is colorized it has no fill to overprint.
let r = s.execute("object.setOverprint", &json!({"fill": true})).unwrap();
assert_eq!(r["changed"], 0);
s.execute("paint.setFill", &json!({"swatch": "Ink"})).unwrap();
let r = s.execute("object.setOverprint", &json!({"fill": true})).unwrap();
assert_eq!(r["changed"], 1);
assert!(overprints(&s));
assert_eq!(s.execute("attributes.info", &json!({})).unwrap()["overprintFill"], true);
// A second time nothing changes, and no undo step is recorded.
let r = s.execute("object.setOverprint", &json!({"fill": true})).unwrap();
assert_eq!(r["changed"], 0);
// Native files keep it.
let d = &s.doc().unwrap().doc;
let back = vectorcraft_format::load(&vectorcraft_format::save(d, false)).unwrap();
assert!(back.node(id).unwrap().colorize_overprints());
// EPS turns overprinting on for the image's ink.
let out = s.execute("document.exportEps", &json!({"previewFormat": "none", "useArtboards": false})).unwrap();
let bytes = vectorcraft_format::base64_decode(out["dataBase64"].as_str().unwrap()).unwrap();
let ps = String::from_utf8_lossy(&bytes);
let (Some(on), Some(mask)) = (ps.find("true op"), ps.find("imagemask")) else { panic!("{ps}") };
assert!(on < mask, "overprint is on before the image is drawn");
// A legacy .ai file writes the image mask with its fill overprint, which opens again.
let r = s.execute("file.saveCopy", &json!({"format": "ai", "aiVersion": "7"})).unwrap();
let mut t = Session::new();
t.execute("document.open", &json!({"name": "t.ai", "dataBase64": r["dataBase64"]})).unwrap();
let mut opened = vec![];
t.doc().unwrap().doc.walk(|n| {
if matches!(n.kind, NodeKind::Image(_)) {
opened.push(n.colorize_overprints());
}
});
assert_eq!(opened, [true]);
s.execute("edit.undo", &json!({})).unwrap();
assert!(!overprints(&s), "undo makes it knock out again");
assert_eq!(s.execute("attributes.info", &json!({})).unwrap()["overprintFill"], false);
}
/// Overprint Black and Print Ink Fixes' Remove White Overprint treat a colorized image's color as
/// its fill.
#[test]
fn overprint_black_and_print_fixes_reach_a_colorized_images_color() {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 200, "height": 200, "colorMode": "cmyk"})).unwrap();
let id = image(&mut s, "gray", gray(false));
let overprints = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().colorize_overprints();
s.execute("paint.setFill", &json!({"color": {"c": 0, "m": 0, "y": 0, "k": 100}})).unwrap();
let v = s.execute("edit.colors.overprintBlack", &json!({})).unwrap();
assert!(overprints(&s), "a black image overprints: {v}");
s.execute("paint.setFill", &json!({"color": {"c": 0, "m": 0, "y": 0, "k": 0}})).unwrap();
assert!(overprints(&s), "a new color keeps the flag");
let v = s.execute("addon.color.printFixes", &json!({"removeWhiteOverprint": true})).unwrap();
assert_eq!(v["whiteOverprintRemoved"], 1, "{v}");
assert!(!overprints(&s), "white knocks out again");
}
/// A flattening for a file that writes colorized images in their ink (EPS) keeps the image, and
/// without Preserve Overprints its color knocks out again, as fills do; with it, the color keeps
/// overprinting.
#[test]
fn flattening_without_preserve_overprints_drops_a_colorized_images_overprint() {
let mut s = session();
image(&mut s, "gray", gray(false));
s.execute("paint.setFill", &json!({"swatch": "Ink"})).unwrap();
s.execute("object.setOverprint", &json!({"fill": true})).unwrap();
// A translucent square elsewhere gives the flattener something to flatten.
let square = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap();
s.execute("transparency.set", &json!({"ids": [square], "opacity": 50})).unwrap();
let overprints = |preserve: bool| {
let mut options = crate::cmd::flatten::FlattenOptions::preset("low").unwrap();
(options.keeps_colorize, options.preserve_overprints) = (true, preserve);
let flat = crate::cmd::flatten::flatten_document(&s.doc().unwrap().doc, &options).unwrap().unwrap();
let mut found = vec![];
flat.walk(|n| {
if matches!(n.kind, NodeKind::Image(_)) {
found.push(n.colorize_overprints());
}
});
found
};
assert_eq!(overprints(true), [true]);
assert_eq!(overprints(false), [false]);
}
#[test]
fn colorized_images_save_and_open_with_their_color() {
let mut s = session();