mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 12:16:39 +00:00
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:
@@ -63,12 +63,18 @@ impl Exporter<'_> {
|
||||
/// missing or left out, its pixels can't be decoded, or its color channel exceeds
|
||||
/// [`vectorcraft_doc::MAX_RASTER_ALLOC`]; cached by key and paint (and size when images are
|
||||
/// resampled), image rejections too.
|
||||
/// With `interpolate` (and the export's own setting), viewers may smooth it.
|
||||
pub(super) fn colorized_image(&mut self, im: &vectorcraft_doc::ImageObject, paint: &Paint, interpolate: bool) -> Option<Image> {
|
||||
/// With `interpolate` (and the export's own setting), viewers may smooth it. With `overprint`
|
||||
/// a gray or CMYK color is written as a DeviceN space of the process inks it holds, so the plates it
|
||||
/// leaves at zero keep the inks below: the nonzero overprint mode does not apply to an image's
|
||||
/// samples (ISO 32000-1 §8.6.7).
|
||||
pub(super) fn colorized_image(&mut self, im: &vectorcraft_doc::ImageObject, paint: &Paint, interpolate: bool, overprint: bool) -> Option<Image> {
|
||||
let Paint::Solid { color, swatch, tint } = paint else { return None };
|
||||
let size = self.image_size(im);
|
||||
let interpolate = interpolate && self.interpolate;
|
||||
let mut cache = format!("{}\u{0}{paint:?}", im.key);
|
||||
if overprint {
|
||||
cache.push_str("\u{0}overprint");
|
||||
}
|
||||
if self.downsampled() {
|
||||
cache.push_str(&format!("\u{0}{:.3}x{:.3}", size.0, size.1));
|
||||
}
|
||||
@@ -103,14 +109,24 @@ impl Exporter<'_> {
|
||||
} else {
|
||||
DeviceNSpace::new(spot_colorants)
|
||||
};
|
||||
let (samples, space) = match &device_n {
|
||||
Some(d) if registration => (vec![q(*tint); d.colorants().len()], ImageColorspace::DeviceN),
|
||||
Some(_) => (vec![q(*tint)], ImageColorspace::DeviceN),
|
||||
None if registration => (vec![q(*tint); 4], ImageColorspace::Cmyk),
|
||||
let (samples, space, device_n) = match &device_n {
|
||||
Some(d) if registration => (vec![q(*tint); d.colorants().len()], ImageColorspace::DeviceN, Some(d.clone())),
|
||||
Some(d) => (vec![q(*tint)], ImageColorspace::DeviceN, Some(d.clone())),
|
||||
None if registration => (vec![q(*tint); 4], ImageColorspace::Cmyk, None),
|
||||
None => match self.page_color(color) {
|
||||
Color::Gray { k } => (vec![q(1.0 - k)], ImageColorspace::Luma),
|
||||
Color::Cmyk { c, m, y, k } => ([c, m, y, k].map(q).to_vec(), ImageColorspace::Cmyk),
|
||||
other => (other.to_rgb().map(q).to_vec(), ImageColorspace::Rgb),
|
||||
// An overprinting gray: black ink only.
|
||||
Color::Gray { k } if overprint && k > 0.0 => {
|
||||
(vec![q(k)], ImageColorspace::DeviceN, DeviceNSpace::new([Colorant::Process(Process::Black)]))
|
||||
}
|
||||
Color::Gray { k } => (vec![q(1.0 - k)], ImageColorspace::Luma, None),
|
||||
// An overprinting CMYK color: the process inks it puts down.
|
||||
Color::Cmyk { c, m, y, k } if overprint && [c, m, y, k].iter().any(|v| *v > 0.0) => {
|
||||
let inks: Vec<(Process, f32)> = Process::ALL.into_iter().zip([c, m, y, k]).filter(|(_, v)| *v > 0.0).collect();
|
||||
let space = DeviceNSpace::new(inks.iter().map(|(p, _)| Colorant::Process(*p)));
|
||||
(inks.iter().map(|(_, v)| q(*v)).collect(), ImageColorspace::DeviceN, space)
|
||||
}
|
||||
Color::Cmyk { c, m, y, k } => ([c, m, y, k].map(q).to_vec(), ImageColorspace::Cmyk, None),
|
||||
other => (other.to_rgb().map(q).to_vec(), ImageColorspace::Rgb, None),
|
||||
},
|
||||
};
|
||||
if tinted_color_len(samples.len(), n).is_none() {
|
||||
@@ -465,10 +481,10 @@ mod tests {
|
||||
for key in ["missing", "bad", "left-out"] {
|
||||
let image =
|
||||
ImageObject { key: key.into(), width: 1, height: 1, xf: Affine::IDENTITY, link: None, placement: Default::default(), pixels: None };
|
||||
assert!(exporter.colorized_image(&image, &paint, true).is_none(), "{key}");
|
||||
assert!(exporter.colorized_image(&image, &paint, true, false).is_none(), "{key}");
|
||||
let cache = format!("{key}\u{0}{paint:?}");
|
||||
assert!(matches!(exporter.images.get(&cache), Some(None)), "rejection for {key} was not cached");
|
||||
assert!(exporter.colorized_image(&image, &paint, true).is_none(), "second call for {key}");
|
||||
assert!(exporter.colorized_image(&image, &paint, true, false).is_none(), "second call for {key}");
|
||||
}
|
||||
assert_eq!(exporter.images.len(), 3);
|
||||
}
|
||||
@@ -500,7 +516,7 @@ mod tests {
|
||||
pixels: None,
|
||||
};
|
||||
for scale in [10.0, 20.0] {
|
||||
assert!(exporter.colorized_image(&image("pic", scale), &paint, true).is_some(), "colorized at {scale}");
|
||||
assert!(exporter.colorized_image(&image("pic", scale), &paint, true, false).is_some(), "colorized at {scale}");
|
||||
let art = vectorcraft_doc::Node::new(doc.layers[0].id, vectorcraft_doc::NodeKind::Image(Box::new(image("alpha", scale))));
|
||||
let mask = vectorcraft_doc::OpacityMask::new(art, true);
|
||||
let inks = image("inks", scale);
|
||||
|
||||
@@ -434,12 +434,7 @@ impl Exporter<'_> {
|
||||
(Some(p @ Paint::Solid { .. }), im) if self.doc.image_blob(&im).is_none_or(vectorcraft_doc::ImageBlob::takes_colorize) => {
|
||||
let im = &*im;
|
||||
if writable(s, im.xf, Rect::new(0.0, 0.0, im.width.max(1).into(), im.height.max(1).into())) {
|
||||
if let Some(colorized) = self.colorized_image(im, p, !n.extras().pixelated) {
|
||||
self.image(s, im, Some(colorized), n.extras().pixelated);
|
||||
} else {
|
||||
self.image_left_out = self.image_left_out.map(|_| true);
|
||||
self.warn(UNDECODED);
|
||||
}
|
||||
self.colorized(s, n, im, p);
|
||||
} else if self.image_left_out.is_some() {
|
||||
self.image_left_out = Some(true);
|
||||
self.warn(super::exporter::UNWRITABLE_IMAGE);
|
||||
@@ -527,6 +522,27 @@ impl Exporter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw image `im` of node `n` colorized with `p` ([`Self::colorized_image`]), overprinting
|
||||
/// when its color does ([`Node::colorize_overprints`]). A white color that is not a spot ink
|
||||
/// ([`Document::spot_ink`]) and overprints (Discard White Overprint off) puts no ink down, so
|
||||
/// it paints nothing.
|
||||
fn colorized(&mut self, s: &mut Surface, n: &Node, im: &vectorcraft_doc::ImageObject, p: &Paint) {
|
||||
let overprint = n.colorize_overprints() && self.overprint;
|
||||
if overprint && !self.doc.setup.discard_white_overprint && !self.doc.spot_ink(p) && vectorcraft_doc::overprint::is_white(p) {
|
||||
return;
|
||||
}
|
||||
match self.colorized_image(im, p, !n.extras().pixelated, overprint) {
|
||||
Some(colorized) => {
|
||||
let pixelated = n.extras().pixelated;
|
||||
self.overprinting(s, overprint, p, |ex, s| ex.image(s, im, Some(colorized), pixelated));
|
||||
}
|
||||
None => {
|
||||
self.image_left_out = self.image_left_out.map(|_| true);
|
||||
self.warn(UNDECODED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gradient mesh `m` as one PDF Type 6 (Coons patch) shading filling its outline (ISO 32000-1,
|
||||
/// 8.7.4.5.7): each patch blends its corner colours bilinearly, as the canvas draws it, and
|
||||
/// the viewer or RIP does so smoothly at its own resolution. Cutting the mesh into flat quads
|
||||
@@ -619,9 +635,9 @@ impl Exporter<'_> {
|
||||
|
||||
/// Draw a fill or stroke of `paint` with `draw`: as a form marked to overprint when it
|
||||
/// `overprints`, paints and overprints are kept (but not a white one with Discard White
|
||||
/// Overprint).
|
||||
/// Overprint, [`Document::discards_white_overprint`]).
|
||||
pub(super) fn overprinting(&mut self, s: &mut Surface, overprints: bool, paint: &Paint, draw: impl FnOnce(&mut Self, &mut Surface)) {
|
||||
let white = || self.doc.setup.discard_white_overprint && vectorcraft_doc::overprint::is_white(paint);
|
||||
let white = || self.doc.discards_white_overprint(paint);
|
||||
if overprints && self.overprint && !paint.is_none() && !white() {
|
||||
self.overprinted = true;
|
||||
crate::forms::form(s, Mark::Overprint, |s| draw(self, s));
|
||||
@@ -634,7 +650,7 @@ impl Exporter<'_> {
|
||||
/// with [`Self::darken_overprints`] an overprinting one is drawn with Darken (not a white one
|
||||
/// with Discard White Overprint).
|
||||
pub(super) fn char_overprinting(&mut self, s: &mut Surface, overprints: bool, paint: &Paint, draw: impl FnOnce(&mut Self, &mut Surface)) {
|
||||
let white = vectorcraft_doc::overprint::is_white(paint) && self.doc.setup.discard_white_overprint;
|
||||
let white = self.doc.discards_white_overprint(paint);
|
||||
if overprints && self.darken_overprints && !paint.is_none() && !white {
|
||||
s.push_blend_mode(krilla::blend::BlendMode::Darken);
|
||||
self.overprinting(s, overprints, paint, draw);
|
||||
|
||||
@@ -40,7 +40,7 @@ use kurbo::{Affine, Rect, Vec2};
|
||||
use serde::Serialize;
|
||||
use vectorcraft_color::cms::{self, ProfileKind};
|
||||
use vectorcraft_doc::marks::PrinterMarks;
|
||||
use vectorcraft_doc::overprint::{OverprintBlack, clear_overprints, darken_overprints};
|
||||
use vectorcraft_doc::overprint::{DiscardWhite, OverprintBlack, clear_overprints, darken_overprints};
|
||||
use vectorcraft_doc::{ColorMode, Document, Node, NodeKind};
|
||||
|
||||
pub use layout::{MAX_COPIES_PER_SHEET, MAX_TILES, TileGrid};
|
||||
@@ -411,12 +411,12 @@ fn composite_overprints(doc: &mut Document, set: &PrintSettings) {
|
||||
if set.output.mode == OutputMode::Separations || how == PrintOverprints::Preserve {
|
||||
return;
|
||||
}
|
||||
let discard_white = doc.setup.discard_white_overprint;
|
||||
let discard_white = DiscardWhite::of(doc);
|
||||
let symbols = doc.symbols.iter_mut().map(|s| &mut s.art);
|
||||
let nodes = doc.layers.iter_mut().chain(symbols).chain(doc.patterns.iter_mut().flat_map(|p| p.art.iter_mut()));
|
||||
for n in nodes {
|
||||
if how == PrintOverprints::Simulate {
|
||||
darken_overprints(n, discard_white);
|
||||
darken_overprints(n, &discard_white, &doc.images);
|
||||
}
|
||||
clear_overprints(n);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ use vectorcraft_color::cms::{self, Cms, Model, ProfileKind};
|
||||
use vectorcraft_color::swatch::REGISTRATION;
|
||||
use vectorcraft_color::{BlendMode, Color, GradientKind, GradientStop, Paint};
|
||||
use vectorcraft_doc::inks::{Link, StopPlates, inks, plates, spot_color, stop_inks, visit_node_colors};
|
||||
use vectorcraft_doc::overprint::{darken_overprints, is_black_ink, is_white};
|
||||
use vectorcraft_doc::overprint::{
|
||||
DiscardWhite, colorized_shown_key, darken_overprints, image_overprints_whole, image_row_draws, is_black_ink, is_colorized_image, refuses_colorize,
|
||||
};
|
||||
use vectorcraft_doc::{AppearanceItem, ColorMode, Document, ImageBlob, Node, NodeKind};
|
||||
|
||||
use super::{DEFAULT_FREQUENCY, InkSettings, PrintInk, PrintSettings};
|
||||
@@ -236,16 +238,26 @@ impl<'a> Separator<'a> {
|
||||
|
||||
/// Overprinting fills and strokes of `a`'s subtree with a Normal blending mode, and
|
||||
/// overprinting character fills and strokes, that put none of ink `plate` down leave its plate
|
||||
/// as it is: they are drawn as nothing on it (white ones with `discard_white` aside, which
|
||||
/// knock out). A writer without blending modes (PostScript) then keeps the ink below them,
|
||||
/// as it is: they are drawn as nothing on it (white ones that `discard_white` knocks out
|
||||
/// aside, [`DiscardWhite::discards`]). A writer without blending modes (PostScript) then keeps the ink below them,
|
||||
/// where it would draw their Darken as a knockout. One that puts any ink down is drawn, and on
|
||||
/// a PostScript plate its ink replaces the ink below, as a nonzero component of an overprinting
|
||||
/// color replaces the backdrop's with overprint mode 1 (ISO 32000-1, 11.7.4.2). On a
|
||||
/// PostScript plate, the stops and points of such a gradient that put none of the ink down
|
||||
/// become paper white ([`Self::clear_inkless_stops`]), which the writer leaves out there.
|
||||
fn clear_inkless_overprints(&self, plate: &str, a: &mut Arc<Node>, discard_white: bool) {
|
||||
let inkless = |overprint: bool, p: &Paint| overprint && !p.is_none() && !(discard_white && is_white(p)) && self.no_ink(plate, p);
|
||||
/// become paper white ([`Self::clear_inkless_stops`]), which the writer leaves out there. A
|
||||
/// colorized image that overprints as a whole ([`image_overprints_whole`]) and whose color puts
|
||||
/// none of the ink down is hidden on the plate once none of its rows draws there; while a row
|
||||
/// draws, the PostScript writer leaves out the image's paper-white pixels and draws the row.
|
||||
/// A colorized image that does not overprint as a whole, or whose pixels don't take its color
|
||||
/// ([`refuses_colorize`]) and so print as they are, knocks out on the plate.
|
||||
fn clear_inkless_overprints(&self, plate: &str, a: &mut Arc<Node>, discard_white: &DiscardWhite) {
|
||||
let inkless = |overprint: bool, p: &Paint| overprint && !p.is_none() && !discard_white.discards(p) && self.no_ink(plate, p);
|
||||
let n = Arc::make_mut(a);
|
||||
let whole = image_overprints_whole(n, discard_white, &self.doc.images);
|
||||
if n.colorize_overprints() && !whole {
|
||||
n.extras_mut().colorize_overprint = false;
|
||||
}
|
||||
let image = whole && n.extras().colorize.as_deref().is_some_and(|p| self.no_ink(plate, p));
|
||||
for it in &mut n.appearance.items {
|
||||
let normal = match it {
|
||||
AppearanceItem::Fill(l) => l.blend == BlendMode::Normal,
|
||||
@@ -257,6 +269,9 @@ impl<'a> Separator<'a> {
|
||||
self.clear_inkless_stops(plate, it.paint_mut());
|
||||
}
|
||||
}
|
||||
if image && !n.appearance.items.iter().any(image_row_draws) {
|
||||
n.visible = false;
|
||||
}
|
||||
if let NodeKind::Text(t) = &mut n.kind {
|
||||
for r in &mut t.runs {
|
||||
if inkless(r.style.overprint_fill, &r.style.fill) {
|
||||
@@ -281,12 +296,12 @@ impl<'a> Separator<'a> {
|
||||
/// ink the plate below shows through instead of being knocked out.
|
||||
pub fn plate(&self, plate: &str) -> Document {
|
||||
let mut d = self.doc.clone();
|
||||
let discard_white = d.setup.discard_white_overprint;
|
||||
let discard_white = DiscardWhite::of(self.doc);
|
||||
let mut colorized = BTreeSet::new();
|
||||
let nodes = d.layers.iter_mut().chain(d.symbols.iter_mut().map(|s| &mut s.art)).chain(d.patterns.iter_mut().flat_map(|p| p.art.iter_mut()));
|
||||
for n in nodes {
|
||||
self.clear_inkless_overprints(plate, n, discard_white);
|
||||
darken_overprints(n, discard_white);
|
||||
self.clear_inkless_overprints(plate, n, &discard_white);
|
||||
darken_overprints(n, &discard_white, &d.images);
|
||||
self.node(plate, Arc::make_mut(n));
|
||||
keep_colorized_pixels(n, &d.images, &mut colorized);
|
||||
}
|
||||
@@ -345,22 +360,15 @@ fn colorized_key(key: &str) -> String {
|
||||
/// paint ([`ImageBlob::takes_colorize`]) loses the paint instead, and is separated as the image it
|
||||
/// shows.
|
||||
fn keep_colorized_pixels(n: &mut Arc<Node>, images: &BTreeMap<String, ImageBlob>, keys: &mut BTreeSet<String>) {
|
||||
let colorized = |n: &Node| matches!(n.kind, NodeKind::Image(ref im) if im.pixels.is_none()) && n.extras().colorize.is_some();
|
||||
if !colorized(n) && n.children().is_none_or(|ch| ch.is_empty()) {
|
||||
if !is_colorized_image(n) && n.children().is_none_or(|ch| ch.is_empty()) {
|
||||
return;
|
||||
}
|
||||
let node = Arc::make_mut(n);
|
||||
let shown = match &node.kind {
|
||||
NodeKind::Image(im) if colorized(node) => {
|
||||
let mask = Document::color_mask_of(node).filter(|m| m.made_for(im) && images.contains_key(&m.key));
|
||||
Some(mask.map_or(&im.key, |m| &m.key).clone())
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if shown.as_ref().and_then(|key| images.get(key)).is_some_and(|b| !b.takes_colorize()) {
|
||||
let shown = colorized_shown_key(node, images);
|
||||
if refuses_colorize(node, images) {
|
||||
node.extras_mut().colorize = None;
|
||||
}
|
||||
if let Some(key) = shown.filter(|_| colorized(node)) {
|
||||
if let Some(key) = shown.filter(|_| is_colorized_image(node)) {
|
||||
if let Some(e) = node.extras_if_any() {
|
||||
e.color_mask = None;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,40 @@ fn a_process_color_writes_the_image_in_that_color_with_a_soft_mask() {
|
||||
assert_eq!(images(&pdf(&doc(ColorMode::Cmyk, None))), [("DeviceGray".into(), vec![], false)]);
|
||||
}
|
||||
|
||||
/// A colorized image whose color overprints is drawn with an overprinting graphics state
|
||||
/// (ISO 32000-1 §8.6.7), its DeviceN image unchanged; one that knocks out sets none.
|
||||
#[test]
|
||||
fn an_overprinting_colorized_image_sets_overprint() {
|
||||
let spot = Paint::Solid { color: Color::cmyk(0.0, 1.0, 1.0, 0.0), swatch: Some("Ink".into()), tint: 1.0 };
|
||||
let mut d = doc(ColorMode::Cmyk, Some(spot));
|
||||
let text = |d: &Document| String::from_utf8_lossy(&pdf(d)).into_owned();
|
||||
assert!(!text(&d).contains("/OP true"), "a knocking-out image sets no overprint");
|
||||
let Some(id) = d.layers[0].children().and_then(|c| c.first()).map(|n| n.id) else { panic!("the image") };
|
||||
d.node_mut(id).unwrap().extras_mut().colorize_overprint = true;
|
||||
let out = pdf(&d);
|
||||
assert!(text(&d).contains("/OP true/op true"), "the image overprints");
|
||||
assert!(images(&out).contains(&("DeviceN".into(), vec!["Ink".into()], true)), "still the ink's DeviceN image");
|
||||
|
||||
// A process color is written in only the process inks it puts down, so its zero plates keep
|
||||
// the inks below: an image's samples take no part in the nonzero overprint mode.
|
||||
let mut d = doc(ColorMode::Cmyk, Some(Paint::solid(Color::cmyk(0.0, 0.0, 0.0, 1.0))));
|
||||
assert_eq!(images(&pdf(&d)), [("DeviceGray".into(), vec![], false), ("DeviceCMYK".into(), vec![], true)], "knocking out: CMYK");
|
||||
let Some(id) = d.layers[0].children().and_then(|c| c.first()).map(|n| n.id) else { panic!("the image") };
|
||||
d.node_mut(id).unwrap().extras_mut().colorize_overprint = true;
|
||||
assert!(images(&pdf(&d)).contains(&("DeviceN".into(), vec!["Black".into()], true)), "{:?}", images(&pdf(&d)));
|
||||
// A gray color is black ink alone.
|
||||
d.node_mut(id).unwrap().extras_mut().colorize = Some(Box::new(Paint::solid(Color::Gray { k: 0.6 })));
|
||||
assert!(images(&pdf(&d)).contains(&("DeviceN".into(), vec!["Black".into()], true)), "{:?}", images(&pdf(&d)));
|
||||
|
||||
// White knocks out with Discard White Overprint (the default), as a white fill does; without
|
||||
// it, an overprinting white process color puts no ink down and paints nothing.
|
||||
d.node_mut(id).unwrap().extras_mut().colorize = Some(Box::new(Paint::solid(Color::cmyk(0.0, 0.0, 0.0, 0.0))));
|
||||
assert_eq!(images(&pdf(&d)).len(), 2, "the white image and its soft mask");
|
||||
assert!(!text(&d).contains("/OP true"), "white knocks out");
|
||||
d.setup.discard_white_overprint = false;
|
||||
assert!(images(&pdf(&d)).is_empty(), "{:?}", images(&pdf(&d)));
|
||||
}
|
||||
|
||||
/// Registration prints on every plate: the process inks and the document's spot inks.
|
||||
#[test]
|
||||
fn registration_writes_the_image_in_every_ink() {
|
||||
@@ -303,6 +337,96 @@ fn separations_print_the_image_on_its_ink_plate() {
|
||||
}
|
||||
}
|
||||
|
||||
/// On printed separations an overprinting colorized image is hidden on the plates its color puts
|
||||
/// no ink on, so a writer without blending modes (PostScript) keeps the ink below it there; a
|
||||
/// knocking-out one is drawn on every plate.
|
||||
#[test]
|
||||
fn separations_hide_an_overprinting_image_on_plates_without_its_ink() {
|
||||
let spot = Paint::Solid { color: Color::cmyk(0.0, 1.0, 1.0, 0.0), swatch: Some("Ink".into()), tint: 1.0 };
|
||||
let shown = |overprint: bool, postscript: bool| {
|
||||
let mut d = doc(ColorMode::Cmyk, Some(spot.clone()));
|
||||
let id = d.layers[0].children().unwrap()[0].id;
|
||||
d.node_mut(id).unwrap().extras_mut().colorize_overprint = overprint;
|
||||
let settings: PrintSettings = serde_json::from_value(serde_json::json!({"output": {"mode": "separations"}})).unwrap();
|
||||
let names: Vec<String> = print_inks(&d, &settings).0.into_iter().map(|i| i.name).collect();
|
||||
let job = plan(&d, &PrintOptions { settings, postscript, ..Default::default() }).unwrap();
|
||||
names.into_iter().zip(&job.plates).map(|(name, p)| (name, p.layers[0].children().unwrap()[0].visible)).collect::<Vec<_>>()
|
||||
};
|
||||
for postscript in [true, false] {
|
||||
let knocking = shown(false, postscript);
|
||||
assert!(knocking.len() > 1 && knocking.iter().all(|(_, v)| *v), "{knocking:?}");
|
||||
for (name, visible) in shown(true, postscript) {
|
||||
assert_eq!(visible, name == "Ink", "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
// With a drop shadow of its own the image knocks out on every plate, so the PostScript
|
||||
// writer draws it there.
|
||||
let mut d = doc(ColorMode::Cmyk, Some(spot));
|
||||
let id = d.layers[0].children().unwrap()[0].id;
|
||||
let n = d.node_mut(id).unwrap();
|
||||
n.extras_mut().colorize_overprint = true;
|
||||
n.appearance.effects.push(vectorcraft_doc::Effect { id: "stylize.dropShadow".into(), params: serde_json::json!({}), visible: true });
|
||||
let settings: PrintSettings = serde_json::from_value(serde_json::json!({"output": {"mode": "separations"}})).unwrap();
|
||||
let job = plan(&d, &PrintOptions { settings, postscript: true, ..Default::default() }).unwrap();
|
||||
for p in &job.plates {
|
||||
let image = &p.layers[0].children().unwrap()[0];
|
||||
assert!(image.visible && !image.extras().colorize_overprint, "{:?}", image.extras());
|
||||
}
|
||||
}
|
||||
|
||||
/// With Discard White Overprint on, an overprinting colorized image in a tint of a spot ink whose
|
||||
/// color is white still overprints, in the PDF and on printed separations: it prints as that ink,
|
||||
/// not as paper white.
|
||||
#[test]
|
||||
fn a_white_spot_ink_image_overprints_with_discard_white_overprint() {
|
||||
let white = Color::cmyk(0.0, 0.0, 0.0, 0.0);
|
||||
let spot = Paint::Solid { color: white, swatch: Some("White Ink".into()), tint: 0.5 };
|
||||
let mut d = doc(ColorMode::Cmyk, Some(spot));
|
||||
d.swatches.push(Swatch { name: "White Ink".into(), paint: Paint::solid(white), global: true, spot: true });
|
||||
d.setup.discard_white_overprint = true;
|
||||
let id = d.layers[0].children().unwrap()[0].id;
|
||||
d.node_mut(id).unwrap().extras_mut().colorize_overprint = true;
|
||||
let out = pdf(&d);
|
||||
assert!(String::from_utf8_lossy(&out).contains("/OP true/op true"), "the image overprints");
|
||||
assert!(images(&out).contains(&("DeviceN".into(), vec!["White Ink".into()], true)), "{:?}", images(&out));
|
||||
|
||||
let settings: PrintSettings = serde_json::from_value(serde_json::json!({"output": {"mode": "separations"}})).unwrap();
|
||||
let names: Vec<String> = print_inks(&d, &settings).0.into_iter().map(|i| i.name).collect();
|
||||
for postscript in [true, false] {
|
||||
let job = plan(&d, &PrintOptions { settings: settings.clone(), postscript, ..Default::default() }).unwrap();
|
||||
for (name, p) in names.iter().zip(&job.plates) {
|
||||
assert_eq!(p.layers[0].children().unwrap()[0].visible, name == "White Ink", "{name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An overprinting colorized image whose pixels don't take its color (a color preview of its
|
||||
/// file) is separated as those pixels on every plate, so it is not hidden on the plates its
|
||||
/// color puts no ink on.
|
||||
#[test]
|
||||
fn separations_show_an_overprinting_image_whose_pixels_refuse_its_color() {
|
||||
let spot = Paint::Solid { color: Color::cmyk(0.0, 1.0, 1.0, 0.0), swatch: Some("Ink".into()), tint: 1.0 };
|
||||
for postscript in [true, false] {
|
||||
let mut d = doc(ColorMode::Cmyk, Some(spot.clone()));
|
||||
let preview = Arc::new(vectorcraft_doc::links::missing_placeholder().unwrap());
|
||||
d.images.insert(
|
||||
"pic".into(),
|
||||
ImageBlob { mime: "image/png".into(), bytes: preview.clone(), proxy: Some(preview), file_font: Default::default() },
|
||||
);
|
||||
let id = d.layers[0].children().unwrap()[0].id;
|
||||
d.node_mut(id).unwrap().extras_mut().colorize_overprint = true;
|
||||
let settings: PrintSettings = serde_json::from_value(serde_json::json!({"output": {"mode": "separations"}})).unwrap();
|
||||
let job = plan(&d, &PrintOptions { settings, postscript, ..Default::default() }).unwrap();
|
||||
assert!(job.plates.len() > 1);
|
||||
for p in &job.plates {
|
||||
let n = &p.layers[0].children().unwrap()[0];
|
||||
assert!(n.visible, "postscript {postscript}: the pixels print on every plate");
|
||||
assert!(n.extras().colorize.is_none() && !n.extras().colorize_overprint, "postscript {postscript}: {:?}", n.extras());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Printed separations separate a colorized image with a color mask as it shows: the pixels the
|
||||
/// mask hides print on no plate.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user