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
2026-11-24 16:39:55 +07:00
committed by GitHub
30 changed files with 1176 additions and 112 deletions
+3 -1
View File
@@ -821,7 +821,8 @@ impl<'a> Reader<'a> {
}
/// Add an image object with the state's transparency, `mask` as its opacity mask and
/// `colorize` as the color that colorizes it.
/// `colorize` as the color that colorizes it, which overprints while the fill overprint (`O`)
/// in force is on.
fn add_image_colorized(&mut self, im: ImageObject, mask: Option<OpacityMask>, colorize: Option<Paint>, hidden: bool) -> Result<(), String> {
let gs = self.gs.clone();
let mut node = self.new_node(NodeKind::Image(Box::new(im)), &gs);
@@ -829,6 +830,7 @@ impl<'a> Reader<'a> {
node.blend = gs.blend;
node.knockout_shape = gs.knockout_shape;
node.extras_mut().mask = mask.map(Box::new);
node.extras_mut().colorize_overprint = colorize.is_some() && gs.overprint_fill;
node.extras_mut().colorize = colorize.map(Box::new);
self.add(node, hidden)?;
self.image_tail = self.after_object;
+2 -2
View File
@@ -96,10 +96,10 @@ VCLegacy begin
/_l 256 string def /_s 128 string def
/_row {{currentfile _l readline not {exit} if dup length 1 gt {exit} if pop} loop
dup length 1 gt {dup length 1 sub 1 exch getinterval /ASCIIHexDecode filter _s readstring pop} {pop ()} ifelse} bd
% An image mask (ImageMask 1) paints its 0 bits in the fill color.
% An image mask (ImageMask 1) paints its 0 bits in the fill color, with the fill overprint.
/XI {1 eq /_im exch def pop pop pop /_ic exch def /_ib exch def /_ih exch def /_iw exch def pop pop pop pop
[1 0 0 -1 0 0] exch matrix concatmatrix
_on {gsave concat _im {_fc _iw _ih false [1 0 0 1 0 0] /_row load imagemask}
_on {gsave concat _im {_fc _fo setoverprint _iw _ih false [1 0 0 1 0 0] /_row load imagemask}
{_iw _ih _ib [1 0 0 1 0 0] /_row load false _ic 1 eq {1} {_ic} ifelse colorimage} ifelse grestore} {pop} ifelse} bd
% Type (15) is set by the app that reads the file: its operators take their operands and mark
% nothing; encodings (3.3) are skipped.
+41 -1
View File
@@ -1039,7 +1039,8 @@ fn colorized_images_keep_their_color() {
// Each row is a byte: the black pixels are 0 bits.
assert_eq!(data, &["%6996"], "{text}");
let at = text.find("%AI5_File:\n").unwrap();
assert!(text[..at].ends_with("0 0.5 1 0 k\n"), "{text}");
// Its color, and its fill overprint off.
assert!(text[..at].ends_with("0 0.5 1 0 k\n0 O\n"), "{text}");
assert!(out.warnings.is_empty(), "{:?}", out.warnings);
let read = crate::import(&out.bytes).unwrap().document;
let mut found = vec![];
@@ -1066,6 +1067,45 @@ fn colorized_images_keep_their_color() {
assert_eq!(out.warnings, [IMAGE_ALPHA]);
}
/// A colorized image mask takes the fill overprint in force: its own `O`, or without one the
/// last `O` before it, as it takes the fill color.
#[test]
fn a_colorized_image_mask_takes_the_fill_overprint_in_force() {
let opened = |square_overprints: bool, image_overprints: bool, drop_own: bool| {
let mut doc = Document::new(200.0, 100.0);
doc.layers.clear();
let layer = doc.add_layer(Some("Art"));
let mut square = shape(&mut doc, shapes::rectangle(Rect::new(5.0, 5.0, 45.0, 30.0)), red(), Paint::None);
if let Some(f) = square.appearance.fill_mut() {
f.overprint = square_overprints;
}
doc.insert(Some(layer), usize::MAX, square).unwrap();
let paint = Paint::solid(Color::cmyk(0.0, 0.5, 1.0, 0.0));
let mask: Vec<u8> = "1001011001101001".bytes().map(|b| if b == b'1' { 0 } else { 255 }).collect();
let mut bitmap = colorized_image(&mut doc, (8, 2), mask, &paint, (10.0, 10.0));
bitmap.extras_mut().colorize_overprint = image_overprints;
doc.insert(Some(layer), usize::MAX, bitmap).unwrap();
let mut text = String::from_utf8(write(&doc).bytes).unwrap();
if drop_own {
let own = format!("0 0.5 1 0 k\n{} O\n", u8::from(image_overprints));
assert!(text.contains(&own), "{text}");
text = text.replace(&own, "0 0.5 1 0 k\n");
}
let read = crate::import(text.as_bytes()).unwrap().document;
let mut found = vec![];
read.walk(|n| {
if matches!(n.kind, NodeKind::Image(_)) {
found.push(n.colorize_overprints());
}
});
found
};
assert_eq!(opened(false, true, false), [true]);
assert_eq!(opened(true, false, false), [false]);
assert_eq!(opened(true, false, true), [true], "the square's overprint stays in force");
assert_eq!(opened(false, true, true), [false], "and so does the square's knockout");
}
/// The pieces of a colorized warped image work out the image's coverage once, and an image with
/// other data works out its own: a black and white image's pieces are written as image masks
/// in its color, and a gray image's pieces with its color in their pixels.
+11 -9
View File
@@ -362,7 +362,7 @@ impl<'a> Writer<'a> {
}
None => im.xf,
};
self.image(blob, im.width, im.height, xf, colorize);
self.image(blob, im.width, im.height, xf, colorize.map(|p| (p, n.colorize_overprints())));
}
NodeKind::SymbolInstance { symbol, xf } => {
self.warn(LIVE);
@@ -1129,13 +1129,14 @@ impl<'a> Writer<'a> {
/// `%AI5_EndRaster`, then `F`. §8.4's examples have no `F`; without it, an app reading the file
/// can leave out an image in a clipping group and the art after it. No path is open there, so
/// the `F` paints nothing. `blob` holds the pixels, placed as a grid of `width` × `height`
/// by `xf`, and `colorize` is the solid color the image is colorized with. A colorized image
/// whose pixels are all black or white is written as an image mask (ImageMask 1, §8.1): its
/// color as the fill, then 1-bit samples, a 0 bit for each black pixel, which takes the color,
/// and a 1 bit for each white pixel, which is clear. Another colorized image is written with
/// by `xf`, and `colorize` is the solid color the image is colorized with and whether it
/// overprints. A colorized image whose pixels are all black or white is written as an image
/// mask (ImageMask 1, §8.1): its color as the fill with its fill overprint, then 1-bit
/// samples, a 0 bit for each black pixel, which takes the color, and a 1 bit for each white
/// pixel, which is clear. Another colorized image is written with
/// its color in its pixels. In a clipping group, an image whose pixels were written whole
/// already is written as the part of them the group shows ([`ai_ops::image_window`]).
fn image(&mut self, blob: Option<&ImageBlob>, width: u32, height: u32, xf: Affine, colorize: Option<&Paint>) {
fn image(&mut self, blob: Option<&ImageBlob>, width: u32, height: u32, xf: Affine, colorize: Option<(&Paint, bool)>) {
let flip = Affine::new([1.0, 0.0, 0.0, -1.0, 0.0, 0.0]);
let m = self.to_art * xf * flip;
if !invertible(m) {
@@ -1157,12 +1158,12 @@ impl<'a> Writer<'a> {
// The object places the image's own pixel grid (its width × height) wherever the file's is.
let fit = Affine::scale_non_uniform(f64::from(width.max(1)) / f64::from(w), f64::from(height.max(1)) / f64::from(h));
let coverage = match colorize {
Some(paint) => {
Some((paint, overprint)) => {
let Some((_, _, coverage)) = self.coverage(blob).filter(|(cw, ch, _)| (*cw, *ch) == (w, h)) else {
self.warn(UNDECODED);
return;
};
Some((paint, coverage))
Some((paint, overprint, coverage))
}
None => None,
};
@@ -1179,7 +1180,7 @@ impl<'a> Writer<'a> {
let (w, h) = (x1 - x0, y1 - y0);
// Over white.
let over = |c: u8, a: u8| ((u32::from(c) * u32::from(a) + 255 * (255 - u32::from(a)) + 127) / 255) as u8;
if let Some((paint, coverage)) = coverage {
if let Some((paint, overprint, coverage)) = coverage {
let coverage = ai_ops::window_samples(&coverage, img.width(), 1, window);
if coverage.iter().all(|&v| v == 0 || v == 255) {
let stride = (w as usize).div_ceil(8);
@@ -1191,6 +1192,7 @@ impl<'a> Writer<'a> {
}
}
self.color(paint, false);
self.line(if overprint { "1 O" } else { "0 O" });
self.raster(m, &format!("0 0 {w} {h} {w} {h} 1 1 0 0 0 1"), &bits);
return;
}
+136 -19
View File
@@ -219,6 +219,13 @@ enum Ink {
Spot { space: usize, tint: f32 },
}
/// One drawing of an overprinting colorized image: the name of the color space it is drawn in
/// and the amount of each of that space's inks ([`Scene::overprint_passes`]).
struct InkPass {
space: String,
values: Vec<f32>,
}
fn unit(v: f32) -> f32 {
if v.is_finite() { v.clamp(0.0, 1.0) } else { 0.0 }
}
@@ -589,8 +596,21 @@ impl<'a> Scene<'a> {
let im = &*shown;
let blob = self.doc.image_blob(im);
match n.extras().colorize.as_deref() {
// On a plate, an overprinting image whose color puts none of the plate's ink
// down is drawn as nothing, as such a solid color is ([`Self::on_plate`]).
Some(p)
if self.plate
&& self.o.overprint == Overprint::Preserve
&& n.colorize_overprints()
&& vectorcraft_doc::overprint::is_white(p) => {}
// Off a plate, a white process color knocks out with Discard White Overprint
// (a plate's colors come from the separator, which has applied it already); a
// spot ink with a white color still overprints, as it is written as that ink.
Some(p @ Paint::Solid { .. }) if blob.is_none_or(|b| b.gray_source().is_some()) => {
self.colorized_image(&im.key, blob, im.width, im.height, im.xf, p);
let discarded = !self.plate && self.doc.discards_white_overprint(p);
let on = self.overprint_on(n.colorize_overprints() && !discarded);
self.colorized_image(im, blob, p, on);
self.overprint_off(on);
}
_ => self.image(&im.key, blob, im.width, im.height, im.xf),
}
@@ -1875,14 +1895,90 @@ impl<'a> Scene<'a> {
i
}
/// Gray coverage in the selected process or Separation ink. Binary coverage is a stencil;
/// continuous coverage leaves zero pixels untouched at Level 3 and writes them as paper at Level 2.
fn colorized_image(&mut self, key: &str, blob: Option<&ImageBlob>, width: u32, height: u32, xf: Affine, paint: &Paint) {
let place = xf * Affine::scale_non_uniform(f64::from(width.max(1)), f64::from(height.max(1)));
/// Image `im` (its pixels `blob`) as gray coverage in the selected process or Separation ink.
/// Binary coverage is a stencil; continuous coverage leaves zero pixels untouched at Level 3
/// and writes them as paper at Level 2. With `overprint` a CMYK or gray color is written in only the
/// process inks it puts down ([`Self::overprint_passes`]), since a zero sample in an image
/// replaces the ink below it.
fn colorized_image(&mut self, im: &vectorcraft_doc::ImageObject, blob: Option<&ImageBlob>, paint: &Paint, overprint: bool) {
let place = im.xf * Affine::scale_non_uniform(f64::from(im.width.max(1)), f64::from(im.height.max(1)));
if !invertible(place) {
return;
}
let cache = (key.to_string(), format!("{paint:?}"));
match overprint.then(|| self.overprint_passes(paint)).flatten() {
Some(passes) => {
// A pass turned away (at the page limit) takes back the passes before it, so the
// image is never written with some of its inks.
let (was, placed, codes) = (self.body.len(), self.placements.len(), self.codes.len());
for pass in &passes {
let before = self.placements.len();
self.colorized_pass(&im.key, blob, place, paint, Some(pass));
if self.placements.len() == before {
self.body.truncate(was);
self.unplace(placed);
self.forget_codes(codes);
return;
}
}
}
None => self.colorized_pass(&im.key, blob, place, paint, None),
}
}
/// The color spaces an overprinting colorized image of `paint` is drawn in, each with the
/// amounts of its inks, when `paint` is a CMYK or gray process color (gray is black ink): at
/// Level 3 one DeviceN space of the process inks it puts down, at Level 2 a Separation space
/// for each of them. No pass when it puts no ink down. `None` for another paint, which is drawn
/// as it is without overprinting.
fn overprint_passes(&mut self, paint: &Paint) -> Option<Vec<InkPass>> {
let Paint::Solid { color, swatch, tint } = paint else { return None };
let c = match self.solid(color, swatch.as_deref(), *tint) {
Ink::Process(Space::Cmyk, c) => c,
// PostScript's gray is lightness.
Ink::Process(Space::Gray, [lightness, ..]) => [0.0, 0.0, 0.0, unit(1.0 - lightness)],
_ => return None,
};
let process: Vec<usize> = (0..4).filter(|&i| c[i] > 0.0).collect();
if process.is_empty() {
return Some(vec![]);
}
if self.o.level == Level::Three {
let GradientSpace::Inks(space, _) = self.device_n_space(&process, &[])? else { return None };
return Some(vec![InkPass { space, values: process.iter().map(|&i| c[i]).collect() }]);
}
Some(process.iter().map(|&i| InkPass { space: self.process_separation(i), values: vec![c[i]] }).collect())
}
/// The name of a Separation color space of process ink `i` (an index into CMYK) alone,
/// defined in the setup the first time.
fn process_separation(&mut self, i: usize) -> String {
const SEPARATIONS: [&str; 4] = [
"/Cyan /DeviceCMYK {0 0 0}",
"/Magenta /DeviceCMYK {0 exch 0 0}",
"/Yellow /DeviceCMYK {0 0 3 -1 roll 0}",
"/Black /DeviceCMYK {0 0 0 4 -1 roll}",
];
let def = format!("[/Separation {}]", SEPARATIONS[i.min(3)]);
let i = match self.device_n.iter().position(|d| *d == def) {
Some(i) => i,
None => {
let i = self.device_n.len();
let _ = writeln!(self.setup, "/VCdn{i} {def} def");
self.device_n.push(def);
i
}
};
format!("VCdn{i}")
}
/// One drawing of a colorized image on the unit square mapped by `place`: in `paint`, or with
/// `pass` in that pass's inks alone ([`Self::overprint_passes`]).
fn colorized_pass(&mut self, key: &str, blob: Option<&ImageBlob>, place: Affine, paint: &Paint, pass: Option<&InkPass>) {
let mut look = format!("{paint:?}");
if let Some(pass) = pass {
let _ = write!(look, "\u{0}{} {:?}", pass.space, pass.values);
}
let cache = (key.to_string(), look);
let encoded = match self.colorized_images.get(&cache) {
Some(e) => *e,
None => {
@@ -1898,7 +1994,7 @@ impl<'a> Scene<'a> {
{
self.encodes += 1;
}
let code = self.encode_colorized(blob, paint);
let code = self.encode_colorized(blob, paint, pass);
// An image that can't be placed isn't kept.
if let Some(c) = &code
&& self.size().saturating_add(c.inline_len).saturating_add(64) > self.max_body
@@ -1917,7 +2013,8 @@ impl<'a> Scene<'a> {
}
}
fn encode_colorized(&mut self, blob: Option<&ImageBlob>, paint: &Paint) -> Option<ImageCode> {
/// The operators and data of a colorized image of `paint`, or with `pass` of that pass's inks.
fn encode_colorized(&mut self, blob: Option<&ImageBlob>, paint: &Paint, pass: Option<&InkPass>) -> Option<ImageCode> {
let Some((w, h, coverage)) = blob.and_then(ImageBlob::coverage) else {
self.warn(UNDECODED);
return None;
@@ -1937,13 +2034,20 @@ impl<'a> Scene<'a> {
if !binary && clear && !keyed {
self.warn(IMAGE_ALPHA_L2);
}
// Zero tint is uncommon for covered spot pixels; process uses the same rare key as
// ordinary images. Nudge a covered collision so only clear pixels match the mask.
// Zero tint is uncommon for covered spot pixels (and those of a pass's inks); process
// uses the same rare key as ordinary images. Nudge a covered collision so only clear
// pixels match the mask.
let key = match ink {
_ if pass.is_some() => [0, 0, 0, 0],
Ink::Spot { .. } => [0, 0, 0, 0],
Ink::Process(Space::Gray, ..) => [0, 0, 0, 0],
Ink::Process(..) => [255, 0, 255, 0],
};
let n = match (pass, ink) {
(Some(pass), _) => pass.values.len(),
(None, Ink::Spot { .. }) => 1,
(None, Ink::Process(space, ..)) => space.n(),
};
let mut data = Vec::new();
if binary {
let stride = (w as usize).div_ceil(8);
@@ -1958,14 +2062,21 @@ impl<'a> Scene<'a> {
} else {
for &v in &coverage {
if v == 0 && keyed {
let n = match ink {
Ink::Spot { .. } => 1,
Ink::Process(space, ..) => space.n(),
};
data.extend(key.iter().take(n));
continue;
}
let a = f32::from(v) / 255.0;
if let Some(pass) = pass {
let mut samples: Vec<u8> = pass.values.iter().map(|&v| (255.0 * v * a).round() as u8).collect();
if keyed
&& samples.iter().all(|&s| s == 0)
&& let Some(first) = samples.first_mut()
{
*first = 1;
}
data.extend(samples);
continue;
}
match ink {
Ink::Spot { tint, .. } => {
let mut sample = (255.0 * tint * a).round() as u8;
@@ -1999,7 +2110,17 @@ impl<'a> Scene<'a> {
}
};
let mut prelude = String::new();
if binary {
if let Some(pass) = pass {
let _ = write!(prelude, "{} setcolorspace", pass.space);
if binary {
// imagemask takes its current ink from the graphics state.
for v in &pass.values {
let _ = write!(prelude, " {}", ps::num(f64::from(*v)));
}
prelude.push_str(" setcolor");
}
prelude.push('\n');
} else if binary {
// imagemask takes its current ink from the graphics state.
prelude.push_str(&self.ink_code(ink));
} else {
@@ -2012,10 +2133,6 @@ impl<'a> Scene<'a> {
}
}
}
let n = match ink {
Ink::Spot { .. } => 1,
Ink::Process(space, ..) => space.n(),
};
let decode = if binary { "1 0".to_string() } else { "0 1 ".repeat(n).trim_end().to_string() };
let mut dict = format!(
"<< /ImageType {} /Width {w} /Height {h} /BitsPerComponent {} /Decode [{decode}] /ImageMatrix [{w} 0 0 {h} 0 0]",
+124
View File
@@ -1163,6 +1163,130 @@ fn continuous_colorized_coverage_without_clear_pixels_only_warns_for_midtones()
assert_eq!(&pixels[6..], &[255, 0, 255]);
}
/// A CMYK document holding [`colorized_doc`]'s image of `gray` colorized with `color`, its color
/// overprinting or not.
fn overprinting_colorized_doc(gray: Vec<u8>, color: Color, overprint: bool) -> Document {
let mut d = colorized_doc(gray, Some(Paint::solid(color)));
d.color_mode = vectorcraft_doc::ColorMode::Cmyk;
let id = d.layers[0].children().unwrap()[0].id;
d.node_mut(id).unwrap().extras_mut().colorize_overprint = overprint;
d
}
/// At the page limit the Level 2 passes of an overprinting colorized image are left out
/// together: the image is never written with some of its inks.
#[test]
fn an_overprinting_colorized_image_at_the_page_limit_keeps_all_its_inks_or_none() {
let gray: Vec<u8> = (0..2000u32).map(|i| (i * 37 % 251) as u8).collect();
let one = overprinting_colorized_doc(gray.clone(), Color::cmyk(0.0, 0.0, 0.0, 1.0), true);
let two = overprinting_colorized_doc(gray, Color::cmyk(0.4, 0.0, 0.0, 1.0), true);
let o = EpsOptions { level: Level::Two, ..opts(&two) };
let (one, all) = (crate::scene::Scene::new(&one, &o).run().body.len(), crate::scene::Scene::new(&two, &o).run().body.len());
assert!(all > one + 1000, "{one} {all}");
let page = crate::scene::Scene::new(&two, &o).with_max_body(one + (all - one) / 2).run();
assert!(page.warnings.iter().any(|w| w.contains("too large")), "{:?}", page.warnings);
assert!(!page.body.contains("image") && !page.body.contains("VCdn"), "{}", page.body);
}
/// An overprinting colorized image in a CMYK color is written in only the process inks it puts
/// down, so the plates it leaves at zero keep the inks below: one DeviceN image at Level 3, a
/// Separation image for each ink at Level 2. Not overprinting, it stays one CMYK image.
#[test]
fn an_overprinting_colorized_image_writes_only_its_process_inks() {
let doc = overprinting_colorized_doc;
let ink = Color::cmyk(0.4, 0.0, 0.0, 1.0);
let d = doc(vec![0, 128, 255], ink, true);
let (ps, pixels, _) = colorized_samples(&d, Level::Three);
assert!(ps.contains("/VCdn0 [/DeviceN [/Cyan /Black ] /DeviceCMYK") && ps.contains("VCdn0 setcolorspace"), "{ps}");
assert!(!ps.contains("/DeviceCMYK setcolorspace") && ps.contains("/MaskColor [0 0 0 0]"), "{ps}");
assert_eq!(pixels, vec![102, 255, 51, 127, 0, 0]);
let (ps, pixels, _) = colorized_samples(&d, Level::Two);
assert!(ps.contains("/VCdn0 [/Separation /Cyan /DeviceCMYK {0 0 0}] def"), "{ps}");
assert!(ps.contains("/VCdn1 [/Separation /Black /DeviceCMYK {0 0 0 4 -1 roll}] def"), "{ps}");
assert!(ps.contains("VCdn0 setcolorspace") && ps.contains("VCdn1 setcolorspace") && !ps.contains("/DeviceN"), "{ps}");
assert_eq!(pixels, vec![102, 51, 0], "the cyan pass first");
assert_eq!(ps.matches("/ImageType 1").count(), 2, "one image per ink: {ps}");
// A gray color is black ink alone.
let gray = doc(vec![0, 128, 255], Color::Gray { k: 0.6 }, true);
for level in Level::ALL {
let (ps, ..) = colorized_samples(&gray, level);
assert!(ps.contains("/Black") && !ps.contains("/DeviceGray setcolorspace") && !ps.contains("/Cyan"), "{ps}");
}
// A stencil sets the pass's inks as its color.
let (ps, ..) = colorized_samples(&doc(vec![0, 255, 0], ink, true), Level::Three);
assert!(ps.contains("VCdn0 setcolorspace 0.4 1 setcolor") && ps.contains("imagemask"), "{ps}");
// Without overprinting, and with overprints discarded, one CMYK image as before.
let off = doc(vec![0, 128, 255], ink, false);
let discarded = |d: &Document, level| text(&export(d, &EpsOptions { level, overprint: Overprint::Discard, ..opts(d) }, None, None).unwrap());
for level in Level::ALL {
for ps in [colorized_samples(&off, level).0, discarded(&d, level)] {
assert!(ps.contains("/DeviceCMYK setcolorspace") && !ps.contains("VCdn"), "{ps}");
}
}
// Paper white that overprints (Discard White Overprint off) puts no ink down.
let mut white = doc(vec![0, 128, 255], Color::cmyk(0.0, 0.0, 0.0, 0.0), true);
white.setup.discard_white_overprint = false;
for level in Level::ALL {
let ps = page_of(&white, &EpsOptions { level, ..opts(&white) });
assert!(!ps.contains("image"), "{ps}");
}
// With Discard White Overprint on, it knocks out: one CMYK image, drawn without overprinting.
white.setup.discard_white_overprint = true;
for level in Level::ALL {
let ps = text(&export(&white, &EpsOptions { level, ..opts(&white) }, None, None).unwrap());
assert!(ps.contains("/DeviceCMYK setcolorspace") && !ps.contains("VCdn") && !ps.contains("true op"), "{ps}");
}
// The same image and color placed overprinting and not keeps two encodings.
let mut both = d.clone();
let mut n = (*both.layers[0].children().unwrap()[0]).clone();
n.id = both.alloc_id();
n.extras_mut().colorize_overprint = false;
both.insert(both.default_layer(), usize::MAX, n).unwrap();
let ps = text(&export(&both, &EpsOptions { level: Level::Three, ..opts(&both) }, None, None).unwrap());
assert!(ps.contains("VCdn0 setcolorspace") && ps.contains("/DeviceCMYK setcolorspace"), "{ps}");
}
/// On a separation plate, an overprinting colorized image whose color puts none of the plate's ink
/// down is drawn as nothing, so the ink below stays; one that knocks out, or whose overprint is
/// discarded, is drawn as paper. (The plate's colors come from the separator, which has already
/// applied Discard White Overprint.)
#[test]
fn a_plate_leaves_out_an_overprinting_image_without_its_ink() {
let body = |overprint: bool, preserve: bool| {
let mut d = colorized_doc(vec![0, 128, 255], Some(Paint::solid(Color::WHITE)));
d.setup.discard_white_overprint = false;
let id = d.layers[0].children().unwrap()[0].id;
d.node_mut(id).unwrap().extras_mut().colorize_overprint = overprint;
let o = EpsOptions { overprint: if preserve { Overprint::Preserve } else { Overprint::Discard }, ..opts(&d) };
crate::scene::Scene::new(&d, &o).on_plate(true).run().body
};
assert!(!body(true, true).contains("image"), "{}", body(true, true));
assert!(body(false, true).contains("image"), "{}", body(false, true));
assert!(body(true, false).contains("image"), "{}", body(true, false));
}
/// With Discard White Overprint on, an overprinting colorized image in a tint of a spot ink whose
/// color is white still overprints: it is written as that ink, which is not paper white.
#[test]
fn a_white_spot_ink_colorized_image_overprints_with_discard_white_overprint() {
let mut d = overprinting_colorized_doc(vec![0, 128, 255], Color::WHITE, true);
d.swatches.push(Swatch { name: "White Ink".into(), paint: Paint::solid(Color::WHITE), global: true, spot: true });
let id = d.layers[0].children().unwrap()[0].id;
d.node_mut(id).unwrap().extras_mut().colorize = Some(Box::new(Paint::Solid { color: Color::WHITE, swatch: Some("White Ink".into()), tint: 0.5 }));
d.setup.discard_white_overprint = true;
for level in Level::ALL {
let ps = text(&export(&d, &EpsOptions { level, ..opts(&d) }, None, None).unwrap());
assert!(ps.contains("(White Ink) cvn") && ps.contains("true op"), "{ps}");
}
}
#[test]
fn uncolorized_image_stays_on_original_eps_path() {
let d = colorized_doc(vec![0, 128, 255], None);