mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 11:23:43 +01:00
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:
1 parent
db9acab4da
commit
4f73ef7fbb
29 files changed
+583
-83
No files matched your search
@@ -1340,6 +1340,33 @@ mod tests {
|
||||
assert!(piece.knockout_outline().is_none());
|
||||
}
|
||||
|
||||
/// Each piece of a mesh-warped colorized image keeps its color and whether it overprints.
|
||||
#[test]
|
||||
fn mesh_warp_image_pieces_keep_an_overprinting_color() {
|
||||
let im = crate::ImageObject {
|
||||
key: "pic".into(),
|
||||
width: 4,
|
||||
height: 4,
|
||||
xf: Affine::scale(10.0),
|
||||
link: None,
|
||||
placement: Default::default(),
|
||||
pixels: None,
|
||||
};
|
||||
let mut n = Node::new(NodeId(3), NodeKind::Image(Box::new(im.clone())));
|
||||
n.extras_mut().colorize = Some(Box::new(Paint::solid(Color::BLACK)));
|
||||
n.extras_mut().colorize_overprint = true;
|
||||
for masked in [false, true] {
|
||||
let g = mesh_warp_image(&n, &im, &|p| p, 2, false, masked);
|
||||
let mut pieces = vec![];
|
||||
g.walk(&mut |c| {
|
||||
if matches!(c.kind, NodeKind::Image(_)) {
|
||||
pieces.push(c.colorize_overprints());
|
||||
}
|
||||
});
|
||||
assert_eq!(pieces, [true; 8], "masked {masked}");
|
||||
}
|
||||
}
|
||||
|
||||
/// More cells than the objects live art may make cut no pieces (the count overflowed).
|
||||
#[test]
|
||||
fn mesh_warp_image_past_the_budget_makes_an_empty_group() {
|
||||
|
||||
@@ -236,8 +236,9 @@ pub(crate) fn mesh_warp_image_with(
|
||||
if mesh_warp_cost(k) > MAX_GENERATED {
|
||||
return g;
|
||||
}
|
||||
// A grayscale image's fill color colorizes each piece; the group of pieces takes none.
|
||||
let colorize = n.extras().colorize.clone();
|
||||
// A grayscale image's fill color colorizes each piece, overprinting as the image's does; the
|
||||
// group of pieces takes none.
|
||||
let (colorize, colorize_overprint) = (n.extras().colorize.clone(), n.extras().colorize_overprint);
|
||||
// Each piece shows what the image shows: its color mask's masked pixels.
|
||||
let color_mask = n.extras().color_mask.clone();
|
||||
let (pw, ph) = (im.width as f64, im.height as f64);
|
||||
@@ -271,6 +272,7 @@ pub(crate) fn mesh_warp_image_with(
|
||||
let mut image = Node::new(n.id, NodeKind::Image(Box::new(ImageObject { xf, ..im.clone() })));
|
||||
image.extras_mut().pixelated = pixelated;
|
||||
image.extras_mut().colorize = colorize.clone();
|
||||
image.extras_mut().colorize_overprint = colorize_overprint;
|
||||
image.extras_mut().color_mask = color_mask.clone();
|
||||
if masked {
|
||||
// Preserve Shape Using Transparency: the triangle is the piece's alpha (a
|
||||
|
||||
@@ -63,6 +63,10 @@ pub struct NodeExtras {
|
||||
/// colorizes it. Each pixel is drawn in this color, as opaque as the pixel is dark, so white
|
||||
/// pixels are transparent. `None`: the image shows its own pixels.
|
||||
pub colorize: Option<Box<vectorcraft_color::Paint>>,
|
||||
/// Attributes panel › Overprint Fill on a colorized image: its color prints over the inks
|
||||
/// below instead of knocking them out. It counts only while [`Self::colorize`] is set
|
||||
/// ([`crate::Node::colorize_overprints`]).
|
||||
pub colorize_overprint: bool,
|
||||
/// Pathfinder panel › Make Compound Shape: this group is a compound shape
|
||||
/// ([`Node::is_compound_shape`], [`crate::compound_shape`]).
|
||||
pub compound_shape: bool,
|
||||
@@ -115,6 +119,7 @@ pub(super) static NO_EXTRAS: NodeExtras = NodeExtras {
|
||||
live_paint_gaps: None,
|
||||
objects_on_path: None,
|
||||
colorize: None,
|
||||
colorize_overprint: false,
|
||||
compound_shape: false,
|
||||
shape_mode: crate::ShapeMode::Add,
|
||||
symbol_overrides: Vec::new(),
|
||||
|
||||
@@ -51,6 +51,7 @@ impl Serialize for Node {
|
||||
e.live_paint_gaps.is_none(),
|
||||
e.objects_on_path.is_none(),
|
||||
e.colorize.is_none(),
|
||||
is_default(&e.colorize_overprint),
|
||||
is_default(&e.compound_shape),
|
||||
is_default(&e.shape_mode),
|
||||
e.symbol_overrides.is_empty(),
|
||||
@@ -99,6 +100,7 @@ impl Serialize for Node {
|
||||
field!("live_paint_gaps", &e.live_paint_gaps);
|
||||
field!("objects_on_path", &e.objects_on_path);
|
||||
field!("colorize", &e.colorize);
|
||||
field!("colorize_overprint", &e.colorize_overprint);
|
||||
field!("compound_shape", &e.compound_shape);
|
||||
field!("shape_mode", &e.shape_mode);
|
||||
field!("symbol_overrides", &e.symbol_overrides);
|
||||
@@ -244,6 +246,8 @@ pub(super) struct NodeWire {
|
||||
#[serde(default)]
|
||||
colorize: Option<Box<vectorcraft_color::Paint>>,
|
||||
#[serde(default)]
|
||||
colorize_overprint: bool,
|
||||
#[serde(default)]
|
||||
compound_shape: bool,
|
||||
#[serde(default)]
|
||||
shape_mode: crate::ShapeMode,
|
||||
@@ -477,6 +481,7 @@ impl From<NodeWire> for Node {
|
||||
live_paint_gaps: w.live_paint_gaps,
|
||||
objects_on_path: w.objects_on_path,
|
||||
colorize: w.colorize,
|
||||
colorize_overprint: w.colorize_overprint,
|
||||
compound_shape: w.compound_shape,
|
||||
shape_mode: w.shape_mode,
|
||||
symbol_overrides: w.symbol_overrides,
|
||||
|
||||
+189
-9
@@ -65,7 +65,8 @@ impl OverprintBlack {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set (or clear) the overprint of `n`'s own black fills and strokes and its characters'.
|
||||
/// Set (or clear) the overprint of `n`'s own black fills and strokes, its characters' and,
|
||||
/// for a colorized image, its color's.
|
||||
/// `spots`: the document's spot swatch names ([`Document::spot_names`]). Returns whether
|
||||
/// anything changed.
|
||||
pub fn apply(&self, n: &mut Node, spots: &[String]) -> bool {
|
||||
@@ -90,9 +91,18 @@ impl OverprintBlack {
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.colorize_black(n, spots) {
|
||||
set(&mut n.extras_mut().colorize_overprint);
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
/// Whether `n` is an image colorized with a black color that [`Self::fill`] covers: the color
|
||||
/// of a gray or 1-bit image is its fill ([`crate::NodeExtras::colorize`]).
|
||||
fn colorize_black(&self, n: &Node, spots: &[String]) -> bool {
|
||||
self.fill && matches!(n.kind, NodeKind::Image(_)) && n.extras().colorize.as_deref().is_some_and(|p| self.black(p, spots))
|
||||
}
|
||||
|
||||
/// [`Self::apply`] to every node of `a`'s subtree, copying only the nodes on the way to those
|
||||
/// that change. Returns whether anything changed.
|
||||
pub fn apply_deep(&self, a: &mut Arc<Node>, spots: &[String]) -> bool {
|
||||
@@ -136,36 +146,115 @@ impl OverprintBlack {
|
||||
(self.fill && r.style.overprint_fill != on && self.black(&r.style.fill, spots))
|
||||
|| (self.stroke && r.style.overprint_stroke != on && self.black(&r.style.stroke, spots))
|
||||
};
|
||||
n.appearance.items.iter().any(item) || matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(run))
|
||||
n.appearance.items.iter().any(item)
|
||||
|| matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(run))
|
||||
|| (n.extras().colorize_overprint != on && self.colorize_black(n, spots))
|
||||
}
|
||||
}
|
||||
|
||||
impl Node {
|
||||
/// Whether any fill or stroke of this subtree overprints (characters' aside).
|
||||
pub fn has_overprint(&self) -> bool {
|
||||
self.appearance.items.iter().any(|i| i.overprint()) || self.children().is_some_and(|c| c.iter().any(|c| c.has_overprint()))
|
||||
self.appearance.items.iter().any(|i| i.overprint())
|
||||
|| self.colorize_overprints()
|
||||
|| self.children().is_some_and(|c| c.iter().any(|c| c.has_overprint()))
|
||||
}
|
||||
|
||||
/// Whether this is an image colorized with a color ([`crate::NodeExtras::colorize`]) that
|
||||
/// overprints ([`crate::NodeExtras::colorize_overprint`]).
|
||||
pub fn colorize_overprints(&self) -> bool {
|
||||
let e = self.extras();
|
||||
matches!(self.kind, NodeKind::Image(_)) && e.colorize_overprint && e.colorize.as_deref().is_some_and(|p| !p.is_none())
|
||||
}
|
||||
}
|
||||
|
||||
/// Document Setup → Discard White Overprint as it applies to paints: off, or on with the names of
|
||||
/// the document's spot swatches. Paper white knocks out where it overprints; the color of a spot
|
||||
/// swatch is an ink of its own, so a white spot ink still overprints.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct DiscardWhite(Option<Vec<String>>);
|
||||
|
||||
impl DiscardWhite {
|
||||
/// The setting of document `doc`.
|
||||
pub fn of(doc: &Document) -> Self {
|
||||
Self(doc.setup.discard_white_overprint.then(|| doc.spot_names()))
|
||||
}
|
||||
|
||||
/// Whether `p` knocks out instead of overprinting.
|
||||
pub fn knocks_out(&self, p: &Paint) -> bool {
|
||||
self.0.as_ref().is_some_and(|spots| is_paper_white(p, |name| spots.iter().any(|s| s == name)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `p` is paper white ([`is_white`]) and not linked to a swatch that `spot` says is a
|
||||
/// spot ink.
|
||||
fn is_paper_white(p: &Paint, spot: impl Fn(&str) -> bool) -> bool {
|
||||
is_white(p) && !matches!(p, Paint::Solid { swatch: Some(name), .. } if spot(name))
|
||||
}
|
||||
|
||||
impl Document {
|
||||
/// Whether paint `p` is paper white: white ([`is_white`]) and not linked to a spot swatch,
|
||||
/// whose white is an ink.
|
||||
pub fn is_paper_white(&self, p: &Paint) -> bool {
|
||||
is_paper_white(p, |name| self.swatch(name).is_some_and(|w| w.spot))
|
||||
}
|
||||
|
||||
/// Whether paint `p` knocks out where it overprints under Document Setup → Discard White
|
||||
/// Overprint ([`DiscardWhite`]).
|
||||
pub fn discards_white(&self, p: &Paint) -> bool {
|
||||
self.setup.discard_white_overprint && self.is_paper_white(p)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether fill or stroke row `i` of an image draws: it is visible, has a paint and a visible
|
||||
/// effect, which gives a row on an image a shape of its own.
|
||||
pub fn image_row_draws(i: &crate::AppearanceItem) -> bool {
|
||||
i.visible() && !i.paint().is_none() && i.effects().iter().any(|e| e.visible)
|
||||
}
|
||||
|
||||
/// Whether paint `paint` of blend mode `blend` darkens when `overprint` asks it to: with the
|
||||
/// Normal blend, and not knocked out by `discard_white`.
|
||||
fn darkens(overprint: bool, blend: BlendMode, paint: &Paint, discard_white: &DiscardWhite) -> bool {
|
||||
overprint && blend == BlendMode::Normal && !discard_white.knocks_out(paint)
|
||||
}
|
||||
|
||||
/// Whether colorized image `n` is drawn overprinting as a whole: its color overprints
|
||||
/// ([`Node::colorize_overprints`]) with the Normal blend and is not knocked out by
|
||||
/// `discard_white`, and each row that draws ([`image_row_draws`]) overprints that way too. A
|
||||
/// colorized image's color is not a fill row, so the whole node overprints or none of it does.
|
||||
pub fn image_overprints_whole(n: &Node, discard_white: &DiscardWhite) -> bool {
|
||||
let row = |i: &crate::AppearanceItem| match i {
|
||||
crate::AppearanceItem::Fill(l) => darkens(l.overprint, l.blend, &l.paint, discard_white),
|
||||
crate::AppearanceItem::Stroke(l) => darkens(l.overprint, l.blend, &l.paint, discard_white),
|
||||
};
|
||||
n.colorize_overprints()
|
||||
&& n.extras().colorize.as_deref().is_some_and(|p| darkens(true, n.blend, p, discard_white))
|
||||
&& n.appearance.items.iter().filter(|i| image_row_draws(i)).all(row)
|
||||
}
|
||||
|
||||
/// Draw the overprinting fills and strokes of `a`'s subtree with Darken (those with a blend
|
||||
/// mode of their own keep it), copying only the nodes on the way to them: on screen and on a
|
||||
/// printed plate this approximates their inks printing over the inks below. Darken keeps the
|
||||
/// stronger ink of each plate (and each additive channel), so a colour overprinting itself stays
|
||||
/// that colour, where Multiply would darken it. With `discard_white`
|
||||
/// (Document Setup → Discard White Overprint) white fills and strokes knock out instead.
|
||||
pub fn darken_overprints(a: &mut Arc<Node>, discard_white: bool) {
|
||||
/// that colour, where Multiply would darken it. Paints that `discard_white` knocks out
|
||||
/// (Document Setup → Discard White Overprint) are left as they are. A colorized image darkens as
|
||||
/// a whole ([`image_overprints_whole`]).
|
||||
pub fn darken_overprints(a: &mut Arc<Node>, discard_white: &DiscardWhite) {
|
||||
if !a.has_overprint() {
|
||||
return;
|
||||
}
|
||||
let n = Arc::make_mut(a);
|
||||
let darkens = |overprint: bool, blend: BlendMode, paint: &Paint| overprint && blend == BlendMode::Normal && !(discard_white && is_white(paint));
|
||||
let whole = image_overprints_whole(n, discard_white);
|
||||
for it in &mut n.appearance.items {
|
||||
match it {
|
||||
crate::AppearanceItem::Fill(l) if darkens(l.overprint, l.blend, &l.paint) => l.blend = BlendMode::Darken,
|
||||
crate::AppearanceItem::Stroke(l) if darkens(l.overprint, l.blend, &l.paint) => l.blend = BlendMode::Darken,
|
||||
crate::AppearanceItem::Fill(l) if darkens(l.overprint, l.blend, &l.paint, discard_white) => l.blend = BlendMode::Darken,
|
||||
crate::AppearanceItem::Stroke(l) if darkens(l.overprint, l.blend, &l.paint, discard_white) => l.blend = BlendMode::Darken,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if whole {
|
||||
n.blend = BlendMode::Darken;
|
||||
}
|
||||
for c in n.children_mut().into_iter().flatten() {
|
||||
darken_overprints(c, discard_white);
|
||||
}
|
||||
@@ -208,6 +297,7 @@ impl Document {
|
||||
/// Whether any fill or stroke of `n`'s subtree overprints, characters' too.
|
||||
fn overprints_anywhere(n: &Node) -> bool {
|
||||
n.appearance.items.iter().any(|i| i.overprint())
|
||||
|| n.colorize_overprints()
|
||||
|| matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(|r| r.style.overprint_fill || r.style.overprint_stroke))
|
||||
|| n.children().is_some_and(|c| c.iter().any(|c| overprints_anywhere(c)))
|
||||
}
|
||||
@@ -227,6 +317,9 @@ pub fn clear_overprints(a: &mut Arc<Node>) {
|
||||
(r.style.overprint_fill, r.style.overprint_stroke) = (false, false);
|
||||
}
|
||||
}
|
||||
if n.colorize_overprints() {
|
||||
n.extras_mut().colorize_overprint = false;
|
||||
}
|
||||
for c in n.children_mut().into_iter().flatten() {
|
||||
clear_overprints(c);
|
||||
}
|
||||
@@ -348,6 +441,93 @@ mod tests {
|
||||
assert!(Arc::ptr_eq(&group, &marked), "and nothing is copied");
|
||||
}
|
||||
|
||||
/// A gray image colorized with `color`, its color overprinting, with the fill row `fill`.
|
||||
fn colorized(color: Paint, fill: Paint) -> Node {
|
||||
let im = crate::ImageObject {
|
||||
key: "pic".into(),
|
||||
width: 1,
|
||||
height: 1,
|
||||
xf: vectorcraft_geom::Affine::IDENTITY,
|
||||
link: None,
|
||||
placement: Default::default(),
|
||||
pixels: None,
|
||||
};
|
||||
let mut n = Node::new(NodeId(1), NodeKind::Image(Box::new(im)));
|
||||
n.appearance = Appearance::basic(fill, Paint::None, 0.0).into();
|
||||
n.extras_mut().colorize = Some(Box::new(color));
|
||||
n.extras_mut().colorize_overprint = true;
|
||||
n
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_white_spot_ink_overprints_under_discard_white() {
|
||||
let mut d = Document::new(100.0, 100.0);
|
||||
let white = Color::cmyk(0.0, 0.0, 0.0, 0.0);
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: "Opaque White".into(), paint: Paint::solid(white), global: true, spot: true });
|
||||
let spot = Paint::Solid { color: white, swatch: Some("Opaque White".into()), tint: 1.0 };
|
||||
let paper = Paint::solid(white);
|
||||
d.setup.discard_white_overprint = true;
|
||||
let discard = DiscardWhite::of(&d);
|
||||
assert!(discard.knocks_out(&paper) && d.discards_white(&paper), "paper white knocks out");
|
||||
assert!(!discard.knocks_out(&spot) && !d.discards_white(&spot), "a white spot ink is an ink");
|
||||
d.setup.discard_white_overprint = false;
|
||||
assert!(!DiscardWhite::of(&d).knocks_out(&paper) && !d.discards_white(&paper), "off: white overprints too");
|
||||
|
||||
// The previews darken the spot ink and leave paper white knocking out.
|
||||
let blend = |fill: Paint| {
|
||||
let mut n = Node::path(NodeId(1), Default::default(), Appearance::basic(fill, Paint::None, 0.0));
|
||||
if let Some(f) = n.appearance.fill_mut() {
|
||||
f.overprint = true;
|
||||
}
|
||||
let mut a = Arc::new(n);
|
||||
darken_overprints(&mut a, &discard);
|
||||
a.appearance.fill().map(|f| f.blend)
|
||||
};
|
||||
assert_eq!(blend(spot.clone()), Some(BlendMode::Darken));
|
||||
assert_eq!(blend(paper.clone()), Some(BlendMode::Normal));
|
||||
let image = |color: Paint| {
|
||||
let mut a = Arc::new(colorized(color, Paint::None));
|
||||
darken_overprints(&mut a, &discard);
|
||||
a.blend
|
||||
};
|
||||
assert_eq!((image(spot), image(paper)), (BlendMode::Darken, BlendMode::Normal), "a colorized image's color too");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_colorized_image_darkens_unless_its_rows_draw_an_effect() {
|
||||
let blend = |effect: Option<bool>, overprint: bool| {
|
||||
let mut n = colorized(cmyk(0.0, 0.0, 0.0, 1.0), cmyk(1.0, 0.0, 0.0, 0.0));
|
||||
if let Some(f) = n.appearance.fill_mut() {
|
||||
f.overprint = overprint;
|
||||
if let Some(visible) = effect {
|
||||
f.effects.push(crate::Effect { id: "path.offsetPath".into(), params: serde_json::json!({}), visible });
|
||||
}
|
||||
}
|
||||
let mut a = Arc::new(n);
|
||||
darken_overprints(&mut a, &DiscardWhite::default());
|
||||
a.blend
|
||||
};
|
||||
assert_eq!(blend(None, false), BlendMode::Darken, "a row with no effect paints nothing on an image");
|
||||
assert_eq!(blend(Some(false), false), BlendMode::Darken, "nor one whose effect is hidden");
|
||||
assert_eq!(blend(Some(true), false), BlendMode::Normal, "a knocking-out row drawn by its effect keeps knocking out");
|
||||
assert_eq!(blend(Some(true), true), BlendMode::Darken, "with an overprinting row the whole image overprints");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overprint_black_takes_a_black_colorized_image() {
|
||||
let off = |mut n: Node| {
|
||||
n.extras_mut().colorize_overprint = false;
|
||||
Arc::new(n)
|
||||
};
|
||||
let mut a = off(colorized(cmyk(0.0, 0.0, 0.0, 1.0), Paint::None));
|
||||
assert!(!OverprintBlack { fill: false, ..Default::default() }.apply_deep(&mut a, &[]), "the color is the image's fill");
|
||||
assert!(OverprintBlack::default().apply_deep(&mut a, &[]) && a.colorize_overprints());
|
||||
assert!(!OverprintBlack::default().apply_deep(&mut a, &[]), "nothing left to change");
|
||||
assert!(OverprintBlack { remove: true, ..Default::default() }.apply_deep(&mut a, &[]) && !a.colorize_overprints());
|
||||
let mut cyan = off(colorized(cmyk(1.0, 0.0, 0.0, 0.0), Paint::None));
|
||||
assert!(!OverprintBlack::default().apply_deep(&mut cyan, &[]), "a cyan image is not black");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_overprint_black_list_migrates() {
|
||||
let mut d = Document::new(100.0, 100.0);
|
||||
|
||||
@@ -1277,6 +1277,7 @@ fn as_art_opts(
|
||||
{
|
||||
let mut e = image.extras_mut();
|
||||
e.colorize = n.extras().colorize.clone();
|
||||
e.colorize_overprint = n.extras().colorize_overprint;
|
||||
e.pixelated = n.extras().pixelated;
|
||||
e.color_mask = n.extras().color_mask.clone();
|
||||
e.image_quad = n.extras().image_quad.clone();
|
||||
|
||||
@@ -701,21 +701,22 @@ fn a_nested_groups_gradient_follows_its_warped_image() {
|
||||
}
|
||||
|
||||
/// An image under a geometry effect other than a Warp draws as the image does: colorized by
|
||||
/// a grayscale image's fill color, and smoothed or not.
|
||||
/// a grayscale image's fill color, overprinting as it does, and smoothed or not.
|
||||
#[test]
|
||||
fn an_image_under_a_geometry_effect_keeps_its_color_and_smoothing() {
|
||||
let mut n = (*warp_test_image(1)).clone();
|
||||
n.appearance.effects = vec![fx("distort.roughen", json!({"size": 5, "detail": 10}))];
|
||||
n.extras_mut().colorize = Some(Box::new(vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(1.0, 0.0, 0.0))));
|
||||
n.extras_mut().colorize_overprint = true;
|
||||
n.extras_mut().pixelated = true;
|
||||
let art = crate::reshape::reshape(None, &n, None).unwrap();
|
||||
let mut seen = vec![];
|
||||
art.walk(&mut |c| {
|
||||
if matches!(c.kind, NodeKind::Image(_)) {
|
||||
seen.push((c.extras().colorize.clone(), c.extras().pixelated));
|
||||
seen.push((c.extras().colorize.clone(), c.colorize_overprints(), c.extras().pixelated));
|
||||
}
|
||||
});
|
||||
assert_eq!(seen, vec![(n.extras().colorize.clone(), true)]);
|
||||
assert_eq!(seen, vec![(n.extras().colorize.clone(), true, true)]);
|
||||
}
|
||||
|
||||
/// What `effects` make of `path` within `budget`.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
),
|
||||
|
||||
@@ -212,6 +212,8 @@ fn flattening_cropped_art_keeps_the_art_under_its_hidden_part() {
|
||||
fn overprints_are_kept_or_discarded() {
|
||||
let mut s = session(100.0, 100.0, 1);
|
||||
let id = s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 30, "height": 30})).unwrap()["id"].as_u64().unwrap();
|
||||
// Not white, which Discard White Overprint (on by default) knocks out.
|
||||
s.execute("paint.setFill", &json!({"ids": [id], "color": {"c": 100, "m": 0, "y": 0, "k": 0}})).unwrap();
|
||||
s.execute("attributes.set", &json!({"ids": [id], "overprintFill": true})).unwrap();
|
||||
let kept = postscript(&b64(&s.execute("document.exportEps", &json!({"previewFormat": "none"})).unwrap()));
|
||||
assert!(kept.contains("true op\n"), "{kept}");
|
||||
|
||||
@@ -1154,11 +1154,15 @@ fn drop_own_overprints(n: &mut Node) {
|
||||
(r.style.overprint_fill, r.style.overprint_stroke) = (false, false);
|
||||
}
|
||||
}
|
||||
if n.colorize_overprints() {
|
||||
n.extras_mut().colorize_overprint = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn overprints(n: &Node) -> bool {
|
||||
n.appearance.items.iter().any(AppearanceItem::overprint)
|
||||
|| n.colorize_overprints()
|
||||
|| matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(|r| r.style.overprint_fill || r.style.overprint_stroke))
|
||||
}
|
||||
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -821,7 +821,7 @@ 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 when the fill overprint (`O`) 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 +829,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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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![];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -507,9 +507,10 @@ impl<'a> Scene<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Turn overprinting on for one paint (when overprints are preserved); `false` when it stays off.
|
||||
fn overprint_on(&mut self, overprint: bool) -> bool {
|
||||
let on = overprint && self.o.overprint == Overprint::Preserve;
|
||||
/// Turn overprinting on for one paint (when overprints are preserved, and `paint` is not paper
|
||||
/// white with Discard White Overprint; a white spot ink still prints); `false` when it stays off.
|
||||
fn overprint_on(&mut self, overprint: bool, paint: &Paint) -> bool {
|
||||
let on = overprint && !self.doc.discards_white(paint) && self.o.overprint == Overprint::Preserve;
|
||||
if on {
|
||||
self.line("true op");
|
||||
}
|
||||
@@ -569,7 +570,9 @@ impl<'a> Scene<'a> {
|
||||
let blob = self.doc.image_blob(im);
|
||||
match n.extras().colorize.as_deref() {
|
||||
Some(p @ Paint::Solid { .. }) if blob.is_none_or(|b| b.gray_source().is_some()) => {
|
||||
let on = self.overprint_on(n.colorize_overprints(), p);
|
||||
self.colorized_image(&im.key, blob, im.width, im.height, im.xf, p);
|
||||
self.overprint_off(on);
|
||||
}
|
||||
_ => self.image(&im.key, blob, im.width, im.height, im.xf),
|
||||
}
|
||||
@@ -688,7 +691,7 @@ impl<'a> Scene<'a> {
|
||||
if p.is_none() {
|
||||
return;
|
||||
}
|
||||
let on = self.overprint_on(overprint);
|
||||
let on = self.overprint_on(overprint, p);
|
||||
match p {
|
||||
Paint::None => {}
|
||||
Paint::Solid { color, swatch, tint } => {
|
||||
@@ -791,7 +794,7 @@ impl<'a> Scene<'a> {
|
||||
};
|
||||
match &w.shape {
|
||||
WrittenShape::Stroke { width } => {
|
||||
let on = self.overprint_on(st.overprint);
|
||||
let on = self.overprint_on(st.overprint, &st.paint);
|
||||
self.line_style(st, *width);
|
||||
match &st.paint {
|
||||
Paint::Solid { color, swatch, tint } => {
|
||||
|
||||
@@ -446,6 +446,26 @@ fn spot_colours_are_separations_and_overprints_are_kept_or_dropped() {
|
||||
let page = checked_page(&ps);
|
||||
assert!(page.contains("true op\nVCsp0 setcolorspace 0.5 setcolor\n") && page.contains("false op"), "{page}");
|
||||
assert!(!page_of(&d, &EpsOptions { overprint: Overprint::Discard, ..opts(&d) }).contains("true op"));
|
||||
|
||||
// A white fill that overprints knocks out with Discard White Overprint (the default), and
|
||||
// overprints without it.
|
||||
let Some(id) = d.layers[0].children().and_then(|c| c.first()).map(|n| n.id) else { panic!("the rectangle") };
|
||||
if let Some(AppearanceItem::Fill(f)) = d.node_mut(id).unwrap().appearance.items.first_mut() {
|
||||
f.paint = Paint::solid(Color::WHITE);
|
||||
}
|
||||
assert!(d.setup.discard_white_overprint);
|
||||
assert!(!page_of(&d, &opts(&d)).contains("true op"));
|
||||
// A white spot ink is ink: it still overprints.
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: "White Ink".into(), paint: Paint::solid(Color::WHITE), global: true, spot: true });
|
||||
if let Some(AppearanceItem::Fill(f)) = d.node_mut(id).unwrap().appearance.items.first_mut() {
|
||||
f.paint = Paint::Solid { color: Color::WHITE, swatch: Some("White Ink".into()), tint: 1.0 };
|
||||
}
|
||||
assert!(page_of(&d, &opts(&d)).contains("true op"));
|
||||
if let Some(AppearanceItem::Fill(f)) = d.node_mut(id).unwrap().appearance.items.first_mut() {
|
||||
f.paint = Paint::solid(Color::WHITE);
|
||||
}
|
||||
d.setup.discard_white_overprint = false;
|
||||
assert!(page_of(&d, &opts(&d)).contains("true op"));
|
||||
}
|
||||
|
||||
const GOLD: Color = Color::Cmyk { c: 0.0, m: 0.2, y: 0.8, k: 0.1 };
|
||||
|
||||
@@ -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 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,20 @@ 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),
|
||||
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() {
|
||||
@@ -437,10 +449,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);
|
||||
}
|
||||
@@ -472,7 +484,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);
|
||||
|
||||
@@ -436,12 +436,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);
|
||||
@@ -529,6 +524,26 @@ impl Exporter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw image `im` of node `n` colorized with `p` ([`Self::colorized_image`]), overprinting
|
||||
/// when its color does ([`Node::colorize_overprints`]). Paper white that 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.is_paper_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
|
||||
@@ -620,11 +635,10 @@ 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).
|
||||
/// `overprints`, paints and overprints are kept (but not paper white with Discard White
|
||||
/// Overprint, [`vectorcraft_doc::Document::discards_white`]).
|
||||
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);
|
||||
if overprints && self.overprint && !paint.is_none() && !white() {
|
||||
if overprints && self.overprint && !paint.is_none() && !self.doc.discards_white(paint) {
|
||||
self.overprinted = true;
|
||||
crate::forms::form(s, Mark::Overprint, |s| draw(self, s));
|
||||
} else {
|
||||
@@ -636,8 +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;
|
||||
if overprints && self.darken_overprints && !paint.is_none() && !white {
|
||||
if overprints && self.darken_overprints && !paint.is_none() && !self.doc.discards_white(paint) {
|
||||
s.push_blend_mode(krilla::blend::BlendMode::Darken);
|
||||
self.overprinting(s, overprints, paint, draw);
|
||||
s.pop();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
clear_overprints(n);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ 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, darken_overprints, image_overprints_whole, image_row_draws, is_black_ink};
|
||||
use vectorcraft_doc::{AppearanceItem, ColorMode, Document, ImageBlob, Node, NodeKind};
|
||||
|
||||
use super::{DEFAULT_FREQUENCY, InkSettings, PrintInk, PrintSettings};
|
||||
@@ -236,16 +236,19 @@ 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,
|
||||
/// where it would draw their Darken as a knockout. One that puts any ink down is drawn, and on
|
||||
/// as it is: they are drawn as nothing on it (those that `discard_white` knocks out aside). 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.
|
||||
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.knocks_out(p) && self.no_ink(plate, p);
|
||||
let n = Arc::make_mut(a);
|
||||
let image = image_overprints_whole(n, discard_white) && 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 +260,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 +287,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(&d);
|
||||
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);
|
||||
self.node(plate, Arc::make_mut(n));
|
||||
keep_colorized_pixels(n, &d.images, &mut colorized);
|
||||
}
|
||||
|
||||
@@ -121,6 +121,43 @@ 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)));
|
||||
|
||||
// Paper white knocks out with Discard White Overprint (the default); without it, overprinting
|
||||
// white 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");
|
||||
d.setup.discard_white_overprint = false;
|
||||
assert!(images(&pdf(&d)).is_empty(), "{:?}", images(&pdf(&d)));
|
||||
|
||||
// A white spot ink is an ink: it overprints with Discard White Overprint too.
|
||||
let white = Color::cmyk(0.0, 0.0, 0.0, 0.0);
|
||||
d.swatches.push(Swatch { name: "Opaque White".into(), paint: Paint::solid(white), global: true, spot: true });
|
||||
d.node_mut(id).unwrap().extras_mut().colorize = Some(Box::new(Paint::Solid { color: white, swatch: Some("Opaque White".into()), tint: 1.0 }));
|
||||
d.setup.discard_white_overprint = true;
|
||||
assert!(text(&d).contains("/OP true/op true"), "the white spot ink overprints");
|
||||
}
|
||||
|
||||
/// 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 +340,30 @@ 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Printed separations separate a colorized image with a color mask as it shows: the pixels the
|
||||
/// mask hides print on no plate.
|
||||
#[test]
|
||||
|
||||
@@ -34,7 +34,7 @@ pub use vectorcraft_color::cms::{Intent, ProofSetup, ProofTarget};
|
||||
use vectorcraft_color::{Color, Paint, Swatch, SwatchGroup};
|
||||
pub use vectorcraft_doc::inks::{Inks, Link, Plate, inks, map_document_colors, map_node_colors, plates, spot_color};
|
||||
use vectorcraft_doc::inks::{StopPlates, map_node_inks, stop_inks};
|
||||
use vectorcraft_doc::overprint::darken_overprints;
|
||||
use vectorcraft_doc::overprint::{DiscardWhite, darken_overprints};
|
||||
use vectorcraft_doc::{AppearanceItem, Document, ImageBlob, Node, NodeId, Shared};
|
||||
use vello_cpu::Pixmap;
|
||||
use vello_cpu::color::PremulRgba8;
|
||||
@@ -398,7 +398,7 @@ pub(crate) struct Prepared {
|
||||
/// What [`prepare`] reads besides the art.
|
||||
#[derive(PartialEq)]
|
||||
struct Inputs {
|
||||
discard_white: bool,
|
||||
discard_white: DiscardWhite,
|
||||
plates: Option<Plates>,
|
||||
}
|
||||
|
||||
@@ -429,21 +429,21 @@ impl PartialEq for Plates {
|
||||
/// print it ([`plate_color`]).
|
||||
struct How<'a> {
|
||||
doc: &'a Document,
|
||||
discard_white: bool,
|
||||
discard_white: DiscardWhite,
|
||||
/// Separations Preview: the color settings, the proof setup and the visible plates.
|
||||
plates: Option<(&'a Cms, &'a ProofSetup, &'a [String])>,
|
||||
}
|
||||
|
||||
impl How<'_> {
|
||||
/// Whether [`Self::apply`] can change `n`: with Separations Preview any node, else a node with
|
||||
/// an overprinting fill or stroke.
|
||||
/// an overprinting fill or stroke, or a colorized image whose color overprints.
|
||||
fn changes(&self, n: &Node) -> bool {
|
||||
self.plates.is_some() || n.appearance.items.iter().any(|i| i.overprint())
|
||||
self.plates.is_some() || n.appearance.items.iter().any(|i| i.overprint()) || n.colorize_overprints()
|
||||
}
|
||||
|
||||
/// Change the fills, strokes and other colors of node `a`, which holds no members.
|
||||
fn apply(&self, a: &mut Arc<Node>) {
|
||||
darken_overprints(a, self.discard_white);
|
||||
darken_overprints(a, &self.discard_white);
|
||||
if let Some((c, proof, visible)) = self.plates {
|
||||
map_node_inks(Arc::make_mut(a), &mut |col, sw, plates| plate_color(self.doc, c, proof, visible, col, sw, plates));
|
||||
}
|
||||
@@ -462,7 +462,7 @@ pub(crate) fn prepare<'a>(doc: &'a Document, opts: &RenderOptions, kept: &mut Op
|
||||
let seps = opts.proof.as_ref().and_then(|p| p.separations.as_ref().map(|s| (p, s)));
|
||||
let c = cms::active();
|
||||
let inputs = Inputs {
|
||||
discard_white: doc.setup.discard_white_overprint,
|
||||
discard_white: DiscardWhite::of(doc),
|
||||
plates: seps.map(|(proof, _)| Plates {
|
||||
proof: proof.clone(),
|
||||
swatches: doc.swatches.clone(),
|
||||
@@ -473,7 +473,7 @@ pub(crate) fn prepare<'a>(doc: &'a Document, opts: &RenderOptions, kept: &mut Op
|
||||
}),
|
||||
};
|
||||
let earlier = kept.take().filter(|k| k.inputs == inputs);
|
||||
let how = How { doc, discard_white: inputs.discard_white, plates: seps.map(|(proof, visible)| (&*c, proof, visible.as_slice())) };
|
||||
let how = How { doc, discard_white: inputs.discard_white.clone(), plates: seps.map(|(proof, visible)| (&*c, proof, visible.as_slice())) };
|
||||
let none = (vec![], vec![]);
|
||||
let (layers, art) = earlier.as_ref().map_or((&none, &none), |k| (&k.layers, &k.art));
|
||||
let made_layers = prepare_list(&doc.layers, &layers.0, &layers.1, &how);
|
||||
|
||||
@@ -318,6 +318,46 @@ fn separations_preview_shows_the_image_on_its_spot_plate() {
|
||||
assert!(off[..3].iter().all(|v| *v >= 250), "the process plates show paper, got {off:?}");
|
||||
}
|
||||
|
||||
/// A spot-colorized image over a cyan square knocks the cyan out where it is dark, unless its
|
||||
/// color overprints: then Separations Preview's Cyan plate keeps the square under it, its Ink
|
||||
/// plate still shows the image, and Overprint Preview darkens the two together.
|
||||
#[test]
|
||||
fn an_overprinting_colorized_image_keeps_the_ink_below_in_the_previews() {
|
||||
let ink = Color::cmyk(0.0, 1.0, 1.0, 0.0);
|
||||
let shown = |overprint: bool, plates: Option<&[&str]>| {
|
||||
let mut d = Document::new_with_mode(40.0, 20.0, vectorcraft_doc::ColorMode::Cmyk);
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: "Ink".into(), paint: Paint::solid(ink), global: true, spot: true });
|
||||
let square = Node::path(
|
||||
d.alloc_id(),
|
||||
shapes::rectangle(Rect::new(0.0, 0.0, 40.0, 20.0)),
|
||||
Appearance::basic(Paint::solid(Color::cmyk(1.0, 0.0, 0.0, 0.0)), Paint::None, 0.0),
|
||||
);
|
||||
d.insert(Some(d.layers[0].id), 0, square).unwrap();
|
||||
d.images.insert("pic".into(), ImageBlob::new("image/png", gray_png()));
|
||||
let im =
|
||||
ImageObject { key: "pic".into(), width: 2, height: 1, xf: Affine::scale(20.0), link: None, placement: Default::default(), pixels: None };
|
||||
let mut n = Node::new(d.alloc_id(), NodeKind::Image(Box::new(im)));
|
||||
n.extras_mut().colorize = Some(Box::new(Paint::Solid { color: ink, swatch: Some("Ink".into()), tint: 1.0 }));
|
||||
n.extras_mut().colorize_overprint = overprint;
|
||||
d.insert(Some(d.layers[0].id), 1, n).unwrap();
|
||||
let opts = match plates {
|
||||
Some(plates) => separations(plates),
|
||||
None => RenderOptions { overprint_preview: true, smooth_images: false, ..Default::default() },
|
||||
};
|
||||
Renderer::new().render(&d, 40, 20, Affine::IDENTITY, &opts).pixel(10, 10)
|
||||
};
|
||||
let knocked = shown(false, Some(&["Cyan"]));
|
||||
assert!(knocked[..3].iter().all(|v| *v >= 250), "knocking out, the Cyan plate is paper under the image, got {knocked:?}");
|
||||
let kept = shown(true, Some(&["Cyan"]));
|
||||
assert!(kept[..3].iter().all(|v| *v < 128), "overprinting, the Cyan plate keeps the square, got {kept:?}");
|
||||
let on = shown(true, Some(&["Ink"]));
|
||||
assert!(on[..3].iter().all(|v| *v < 128), "the Ink plate shows the image, got {on:?}");
|
||||
// Overprint Preview alone: the red ink over cyan darkens to near black where it knocked out
|
||||
// to red.
|
||||
let (red, dark) = (shown(false, None), shown(true, None));
|
||||
assert!(red[0] > 128 && dark[0] < 128, "knocking out {red:?}, overprinting {dark:?}");
|
||||
}
|
||||
|
||||
/// Separations Preview shows an image placed from a DCS file through its own plates: its spot
|
||||
/// plate on that ink's plate only, its cyan plate on the cyan plate only. Without the preview it
|
||||
/// shows its composite, the spot ink mixed in.
|
||||
|
||||
+6
-3
@@ -5078,12 +5078,15 @@ on OK. Cancel restores the original artwork.
|
||||
|
||||
Each fill and stroke (and each character's fill and stroke) can overprint: its inks print over the inks below instead
|
||||
of knocking them out. `object.setOverprint {fill?, stroke?, item?, ids?}` sets it (groups set their contents, type its
|
||||
characters too; `item` aims at one appearance item) and `attributes.info {ids?}` reads it back (`null` where the
|
||||
characters too; `item` aims at one appearance item; without `item`, `fill` on a grayscale or 1-bit image colorized by
|
||||
`paint.setFill` sets whether its color overprints) and `attributes.info {ids?}` reads it back (`null` where the
|
||||
objects differ). Overprint Preview (`view.overprintPreview`) and Separations Preview show it; rendering approximates
|
||||
it by darkening (the stronger ink of each plate wins, so a colour overprinting itself stays that colour). Older files that listed Overprint Black objects in the document get the flags on load.
|
||||
PDF export writes them with `advanced.overprint: "preserve"` (the default): each overprinting fill and stroke sets a
|
||||
graphics state with `/OP true /op true /OPM 1` (`/OPM 0` in PDF/A). With `discardWhiteOverprint` (`document.setup`, on by
|
||||
default) white ones knock out instead; `"discard"` writes none.
|
||||
default) white ones knock out instead; `"discard"` writes none. EPS export (`overprints: "preserve"`, the default) turns
|
||||
overprinting on for each one, white ones aside with `discardWhiteOverprint`. The color of a spot swatch is an ink, so
|
||||
a white spot color keeps overprinting with `discardWhiteOverprint`, in both exports and in both previews.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"object.setOverprint","params":{"ids":[12],"stroke":true}}}
|
||||
@@ -15398,7 +15401,7 @@ document's inks for print, as one undo step:
|
||||
| `scope` | `selection`, `document` (the selection, or the document while nothing is selected) | What it fixes; `ids` stand for the selection |
|
||||
| `inkLimit` | total ink % 1…400, 0 off (off) | CMYK colours (solid, gradient stops, gradient meshes) with more ink than this are scaled down to it; colours of spot swatches and Registration stay |
|
||||
| `excludePureBlack` | bool (true) | Black-only CMYK and grey colours keep their ink |
|
||||
| `removeWhiteOverprint` | bool (false) | White fills and strokes, and characters', stop overprinting |
|
||||
| `removeWhiteOverprint` | bool (false) | White fills and strokes, characters' and the white color of a colorized image stop overprinting |
|
||||
| `overprintBlack` | black % 1…100, 0 off (off) | Black-only and grey fills and strokes this dark or darker overprint, as `edit.colors.overprintBlack` sets it (not spot-linked or rich blacks) |
|
||||
| `textOnly` | bool (false) | Overprint Black on type only |
|
||||
| `fill`, `stroke` | bool (true) | Which paints the fixes reach |
|
||||
|
||||
@@ -1994,6 +1994,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Colorized images (#1466):** a fill color applied to a selected grayscale or 1-bit image (`paint.setFill`) colorizes it with black, white, a process color or a spot color, and refuses a process color when the image has an alpha channel ([Convert color modes](https://web.archive.org/web/20251220223850/https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/convert-color-modes.html), "Colorize Grayscale or 1-bit images"); black and white are accepted there too. The canvas draws each pixel in the color as far as the pixel is dark, with white pixels transparent; PDF export writes the image in the color (a spot color as its ink, Registration in every ink) with the image as its soft mask; Separations Preview and printed separations show it on its color's plates; native files keep the color. SVG writes the fill color through a coverage mask (or a colorized PNG in Tiny 1.2); EPS writes binary coverage as an image mask in the color's ink, and a grayscale image as ink samples scaled by coverage, with white pixels left out at Level 3 and gray midtones written over white.
|
||||
The prompt for deleting several swatches and groups uses the interface language's plural form for the count. Evidence: `deleting_several_swatches_uses_each_count_form` in `crates/ui-egui/src/panels/swatches/tests.rs`.
|
||||
- **Colorized images (#1466):** a fill color applied to a selected grayscale or 1-bit image (`paint.setFill`) colorizes it with black, white, a process color or a spot color, and refuses a process color when the image has an alpha channel ([Convert color modes](https://web.archive.org/web/20251220223850/https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/convert-color-modes.html), "Colorize Grayscale or 1-bit images"); black and white are accepted there too. The canvas draws each pixel in the color as far as the pixel is dark, with white pixels transparent; PDF export writes the image in the color (a spot color as its ink, Registration in every ink) with the image as its soft mask; Separations Preview and printed separations show it on its color's plates; native files keep the color. EPS and SVG write the image's own pixels.
|
||||
- **Colorized images overprint:** Overprint Fill (`object.setOverprint {fill: true}`) on a colorized grayscale or 1-bit image makes its color print over the inks below instead of knocking them out, as raster art has an overprint setting of its own in the [scripting reference](https://ai-scripting.docsforadobe.dev/jsobjref/RasterItem/). `attributes.info` reports it, native files keep it, Overprint Preview, Separations Preview and printed separations show it, PDF export draws the image with an overprinting graphics state (a process color as an image of only the process inks it puts down, since the nonzero overprint mode does not apply to image samples, ISO 32000-1 §8.6.7), EPS export turns overprinting on for it, and a legacy `.ai` file writes it with the image mask's fill overprint and reads it back. EPS export now also leaves white fills, strokes and colorized images knocking out with Discard White Overprint on, as PDF export does; in both exports and both previews a white spot color is an ink and keeps overprinting. Edit › Edit Colors › Overprint Black and Print Ink Fixes' Remove White Overprint reach a colorized image's color as its fill. Evidence: engine `tests::colorize::overprint_fill_makes_a_colorized_images_color_overprint`, `tests::colorize::overprint_black_and_print_fixes_reach_a_colorized_images_color`, `tests::colorize::flattening_without_preserve_overprints_drops_a_colorized_images_overprint`, doc `overprint::tests::a_white_spot_ink_overprints_under_discard_white`, `overprint::tests::a_colorized_image_darkens_unless_its_rows_draw_an_effect`, `overprint::tests::overprint_black_takes_a_black_colorized_image`, render `tests::colorize::an_overprinting_colorized_image_keeps_the_ink_below_in_the_previews`, pdf `tests::colorize::an_overprinting_colorized_image_sets_overprint`, eps `tests::spot_colours_are_separations_and_overprints_are_kept_or_dropped`, doc `live::tests::mesh_warp_image_pieces_keep_an_overprinting_color`, effects `tests::an_image_under_a_geometry_effect_keeps_its_color_and_smoothing`.
|
||||
- **Missing library files:** a persistent swatch or graphic style library panel whose file is gone at startup reopens and stays in the preferences, showing the file's path with Locate Library… (`ui.libraryPanel.locate`), which reads the file from where it is now into the same panel.
|
||||
- **Swatch library and Recolor Artwork parameters:** the `swatch.library.*` commands, `swatch.resetDefaults`, the graphic style library save, load and add, the `recolor.*` commands and `color.harmony`'s `limitTo` refuse parameters of the wrong form, such as `names: "Grays"`, `limitTo: 5` or `includeImages: "false"`. Errors name the parameter, except that a `limitTo` that is not a string, such as `5`, gets an unknown-library error. A `null` counts as left out except for `recolor.apply`'s `model`, which must be a string when given.
|
||||
- **OKLCH Sliders (Color Wheel panel):** as VectorCraft's own addition, the Color Wheel panel's menu item OKLCH Sliders (`ui.colorWheel {sliders: "oklch"}`, kept with the preferences) shows L, C and H rows under the wheel or the box that edit the color by the OKLCH lightness (0 to 100 %), chroma (0 to 100 % of 0.4) and hue (0 to 360°) of its display sRGB, as CSS Color 4 defines them (https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch). Each track dims the colors outside sRGB, and a tick on the C track marks the largest chroma sRGB holds at the row's L and H; a color outside sRGB keeps L and H and takes the largest chroma that fits, and the C row keeps the chroma asked for. The rows take the arrow keys after a click and report their names, values, ranges and adjust actions to screen readers. While the active document's RGB space (its assigned profile, else the working RGB space of Edit › Color Settings) is not sRGB, the unchecked item is gray and `ui.colorWheel {sliders: "oklch"}` answers an error; rows shown before the space changed are gray, and the checked item still hides them. `color.convert {color, to: "oklch"}` answers the same L, C and H for a color inside sRGB. For a color outside sRGB, it clips the display RGB to 0 to 1 first, so its L, C and H can differ from the rows' values. Evidence: `crates/color/src/oklab.rs` tests; `convert_to_oklch_answers_lightness_chroma_and_hue` in `crates/engine/src/tests/colormgmt.rs`; the OKLCH tests in `crates/ui-egui/src/panels/tests_color_wheel.rs`, `the_oklch_tracks_dim_the_colors_outside_srgb_and_the_tick_marks_the_largest_chroma` and `oklch_sliders_are_gray_after_the_working_space_changes` among them. Scores and estimates are unchanged.
|
||||
|
||||
Reference in new issue
Block a user