Merge pull request #9102 from dotCooCoo/feat/colorized-image-overprint

Images: Overprint Fill makes a colorized image's color overprint
This commit is contained in:
BFlat authored and GitHub committed 2026-11-24 16:39:55 +07:00
commit d48c4207f7
30 files changed
+1176 -112

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Print Ink Fixes",
["Object", "Plug-ins", "Color Effects"],
None,
"{scope?: \"selection\" (the selection, or `ids`; by default, the document while nothing is selected) | \"document\" (every layer), inkLimit?: total ink % 1..400 (0 or left out: off), excludePureBlack?: true (black-only and grey colours keep their ink), removeWhiteOverprint?: false (white fills and strokes stop overprinting), overprintBlack?: black % 1..100 (black-only and grey fills and strokes this dark or darker overprint, as edit.colors.overprintBlack; 0 or left out: off), textOnly?: false (Overprint Black on type only), fill?: true, stroke?: true, ids?: [id…]} prepare a CMYK document's inks for print as one undo step: CMYK colours (solid, gradient stops, gradient meshes) with more total ink than inkLimit are scaled down to it (colours of spot swatches and Registration stay), white overprint is removed and black overprint set. Refused in RGB documents (File › Document Color Mode › CMYK Color first). On a path directly in a graph series, the graph also stores a paint the ink limit changes on the topmost visible fill or stroke, and on a graph label the new paint of its characters and rows for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md) → {changed, inkLimited: paints and meshes scaled, whiteOverprintRemoved: objects, blackOverprinted: objects}",
"{scope?: \"selection\" (the selection, or `ids`; by default, the document while nothing is selected) | \"document\" (every layer), inkLimit?: total ink % 1..400 (0 or left out: off), excludePureBlack?: true (black-only and grey colours keep their ink), removeWhiteOverprint?: false (white fills and strokes, and colorized images with a white color, stop overprinting), overprintBlack?: black % 1..100 (black-only and grey fills and strokes this dark or darker overprint, as edit.colors.overprintBlack; 0 or left out: off), textOnly?: false (Overprint Black on type only), fill?: true, stroke?: true, ids?: [id…]} prepare a CMYK document's inks for print as one undo step: CMYK colours (solid, gradient stops, gradient meshes) with more total ink than inkLimit are scaled down to it (colours of spot swatches and Registration stay), white overprint is removed and black overprint set. Refused in RGB documents (File › Document Color Mode › CMYK Color first). On a path directly in a graph series, the graph also stores a paint the ink limit changes on the topmost visible fill or stroke, and on a graph label the new paint of its characters and rows for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md) → {changed, inkLimited: paints and meshes scaled, whiteOverprintRemoved: objects, blackOverprinted: objects}",
has_doc,
print_fixes::run
),
@@ -98,6 +98,11 @@ impl Fixes {
off(self.stroke, is_white(&r.style.stroke), &mut r.style.overprint_stroke);
}
}
// A colorized image's color is its fill.
if n.colorize_overprints() {
let white = n.extras().colorize.as_deref().is_some_and(is_white);
off(self.fill, white, &mut n.extras_mut().colorize_overprint);
}
changed
}
+1 -1
View File
@@ -169,7 +169,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Overprint Black…",
["Edit", "Edit Colors"],
None,
"{remove?: false, percentage?: 100, fill?: true, stroke?: true, includeCmyBlacks?: false, includeSpotBlacks?: false, ids?} make the black fills and/or strokes of the selection (or ids; groups: their contents; type: its characters) overprint, or stop (remove). Black: K ≥ percentage with no C, M or Y (any with includeCmyBlacks), not linked to a spot swatch (unless includeSpotBlacks); a gradient is black when every stop is → {changed: objects}",
"{remove?: false, percentage?: 100, fill?: true, stroke?: true, includeCmyBlacks?: false, includeSpotBlacks?: false, ids?} make the black fills and/or strokes of the selection (or ids; groups: their contents; type: its characters; a grayscale or 1-bit image colorized by paint.setFill: its color, as a fill) overprint, or stop (remove). Black: K ≥ percentage with no C, M or Y (any with includeCmyBlacks), not linked to a spot swatch (unless includeSpotBlacks); a gradient is black when every stop is → {changed: objects}",
has_doc,
super::overprint::overprint_black
),
+5
View File
@@ -1154,11 +1154,16 @@ fn drop_own_overprints(n: &mut Node) {
(r.style.overprint_fill, r.style.overprint_stroke) = (false, false);
}
}
// An image keeps the flag after its color is removed, and a later color would overprint.
if n.extras().colorize_overprint {
n.extras_mut().colorize_overprint = false;
}
}
}
fn overprints(n: &Node) -> bool {
n.appearance.items.iter().any(AppearanceItem::overprint)
|| n.extras().colorize_overprint
|| matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(|r| r.style.overprint_fill || r.style.overprint_stroke))
}
+14 -1
View File
@@ -21,7 +21,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Overprint",
[],
None,
"{fill?: bool, stroke?: bool, item?: appearance item index|null, ids?|id?, target?: \"object\"|\"contents\"} make fills and/or strokes overprint (Overprint Preview, Separations Preview) or knock out: item's, else every fill or stroke of the painted objects (groups: their contents; type: its characters too). Without item and ids, the Appearance panel's active item stands in when it is of that kind. A whole Live Paint group (also its contents with `item`) takes the fill flags on its faces and the stroke flags on its edges, and its hidden source paths keep theirs → {changed: objects}",
"{fill?: bool, stroke?: bool, item?: appearance item index|null, ids?|id?, target?: \"object\"|\"contents\"} make fills and/or strokes overprint (Overprint Preview, Separations Preview) or knock out: item's, else every fill or stroke of the painted objects (groups: their contents; type: its characters too; a grayscale or 1-bit image colorized by paint.setFill: without item, the fill flags set whether its color overprints). Without item and ids, the Appearance panel's active item stands in when it is of that kind. A whole Live Paint group (also its contents with `item`) takes the fill flags on its faces and the stroke flags on its edges, and its hidden source paths keep theirs → {changed: objects}",
has_doc,
set_overprint
),
@@ -97,9 +97,18 @@ fn flags(n: &Node, fill: bool, index: Option<usize>) -> Vec<bool> {
if let (None, NodeKind::Text(t)) = (index, &n.kind) {
v.extend(t.runs.iter().map(|r| if fill { r.style.overprint_fill } else { r.style.overprint_stroke }));
}
if fill && index.is_none() && colorized(n) {
v.push(n.extras().colorize_overprint);
}
v
}
/// Is `n` an image colorized with a color, whose fill overprint is its color's
/// ([`vectorcraft_doc::NodeExtras::colorize_overprint`])?
fn colorized(n: &Node) -> bool {
matches!(n.kind, NodeKind::Image(_)) && n.extras().colorize.as_deref().is_some_and(|p| !p.is_none())
}
/// [`flags`], to change.
fn flags_mut(n: &mut Node, fill: bool, index: Option<usize>) -> Vec<&mut bool> {
let mut v: Vec<&mut bool> = n
@@ -178,6 +187,10 @@ pub(super) fn apply_overprint(d: &mut Document, jobs: &[OverprintJob], cmd: &str
changed.insert(*id);
}
}
if *fill && index.is_none() && colorized(n) && n.extras().colorize_overprint != *on {
n.extras_mut().colorize_overprint = *on;
changed.insert(*id);
}
}
}
Ok(())
+7 -1
View File
@@ -678,7 +678,13 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool)
characters.borrow_mut().push(n.id);
}
if index.is_none() && colorized.contains(&n.id) {
n.extras_mut().colorize = paint.color().map(|_| Box::new(paint.clone()));
let colorize = paint.color().map(|_| Box::new(paint.clone()));
// Without a color the image has nothing to overprint, and a later color starts
// knocking out.
if colorize.is_none() {
n.extras_mut().colorize_overprint = false;
}
n.extras_mut().colorize = colorize;
return Ok(());
}
if index.is_none()
+125
View File
@@ -707,6 +707,131 @@ 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);
// Taking the color off drops its overprint, so a new color knocks out.
s.execute("object.setOverprint", &json!({"fill": true})).unwrap();
s.execute("paint.setFill", &json!({"none": true})).unwrap();
assert!(!s.doc().unwrap().doc.node(id).unwrap().extras().colorize_overprint);
s.execute("paint.setFill", &json!({"swatch": "Ink"})).unwrap();
assert!(!overprints(&s), "a new color starts knocking out");
}
/// 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]);
}
/// Flattening without Preserve Overprints also clears the overprint an image keeps after its
/// color was removed, so a color given to it later knocks out.
#[test]
fn flattening_without_preserve_overprints_clears_an_uncolored_images_overprint() {
let mut s = session();
let id = image(&mut s, "gray", gray(false));
s.execute("paint.setFill", &json!({"swatch": "Ink"})).unwrap();
s.execute("object.setOverprint", &json!({"fill": true})).unwrap();
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 mut d = (*s.doc().unwrap().doc).clone();
let Some(n) = d.node_mut(id) else { panic!("the image") };
n.extras_mut().colorize = None;
assert!(n.extras().colorize_overprint && !n.colorize_overprints(), "the flag outlives the color");
let mut options = crate::cmd::flatten::FlattenOptions::preset("low").unwrap();
(options.keeps_colorize, options.preserve_overprints) = (true, false);
let flat = crate::cmd::flatten::flatten_document(&d, &options).unwrap().unwrap();
let mut found = vec![];
flat.walk(|n| {
if matches!(n.kind, NodeKind::Image(_)) {
found.push(n.extras().colorize_overprint);
}
});
assert_eq!(found, [false]);
}
#[test]
fn colorized_images_save_and_open_with_their_color() {
let mut s = session();