mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 15:26:12 +00:00
Print: keep faint overprint ink on PDF plates and follow inline graphics
- A PDF plate no longer drops an overprinting paint whose ink on that plate is under half a percent: it draws with Darken. PostScript plates, which have no blending modes, still draw such a paint as nothing. - With Overprint Black on, the art of a symbol that type shows as an inline graphic has its repainting instances placed too, so their own fill and stroke changes decide whether they overprint.
This commit is contained in:
+41
-7
@@ -218,15 +218,16 @@ fn separation_overprint_black(doc: &mut Document, set: &PrintSettings) {
|
||||
/// Replace each symbol instance in `doc`'s layers and patterns whose own fill or stroke changes
|
||||
/// ([`vectorcraft_doc::symbol_overrides::SymbolOverride`]) or fill stain repaint its symbol's art
|
||||
/// ([`repaints`]), or whose symbol's art holds such an instance at any depth, with that art as
|
||||
/// the instance prints it ([`Placing::instance`]). The symbols' own art stays as it is, and so do
|
||||
/// hidden objects and template layers. Once the layers and patterns, with the art placed for
|
||||
/// symbols already, hold [`vectorcraft_doc::MAX_SYMBOL_NODES`] objects, the remaining instances
|
||||
/// stay as they are, and so do instances whose art would draw deeper than
|
||||
/// [`vectorcraft_doc::depth::MAX_DRAWN_DEPTH`].
|
||||
/// the instance prints it ([`Placing::instance`]). Then the same is done inside the art of the
|
||||
/// symbols type shows as inline graphics ([`inline_symbols`]), which draw their symbol's art as it
|
||||
/// is; the other symbols' own art stays as it is, and so do hidden objects and template layers.
|
||||
/// Once the layers and patterns, with the art placed for symbols already, hold
|
||||
/// [`vectorcraft_doc::MAX_SYMBOL_NODES`] objects, the remaining instances stay as they are, and so
|
||||
/// do instances whose art would draw deeper than [`vectorcraft_doc::depth::MAX_DRAWN_DEPTH`].
|
||||
fn place_repainted_instances(doc: &mut Document) {
|
||||
let holders = repainting_symbols(doc);
|
||||
let art = || doc.layers.iter().chain(doc.patterns.iter().flat_map(|p| p.art.iter()));
|
||||
if !art().any(|n| holds_repaint(n, &holders)) {
|
||||
if holders.is_empty() && !art().any(|n| holds_repaint(n, &holders)) {
|
||||
return;
|
||||
}
|
||||
let held = art().map(|n| n.count_with_masks() as u64).fold(0u64, u64::saturating_add);
|
||||
@@ -250,12 +251,45 @@ fn place_repainted_instances(doc: &mut Document) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let inline = inline_symbols(doc);
|
||||
for _ in 0..=vectorcraft_doc::depth::MAX_DRAWN_DEPTH {
|
||||
let mut changed = false;
|
||||
for i in 0..doc.symbols.len() {
|
||||
if inline.contains(&doc.symbols[i].name)
|
||||
&& let Some(art) = placing.subtree(doc, &doc.symbols[i].art, 1)
|
||||
{
|
||||
doc.symbols[i].art = art;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The names of the symbols that type in `doc` shows as inline graphics, in its layers, symbols
|
||||
/// and patterns.
|
||||
fn inline_symbols(doc: &Document) -> HashSet<String> {
|
||||
fn visit(n: &Node, out: &mut HashSet<String>) {
|
||||
if let NodeKind::Text(t) = &n.kind {
|
||||
out.extend(t.runs.iter().filter_map(|r| r.inline.as_ref()).map(|i| i.symbol.clone()));
|
||||
}
|
||||
for c in n.children().into_iter().flatten() {
|
||||
visit(c, out);
|
||||
}
|
||||
}
|
||||
let mut out = HashSet::new();
|
||||
for n in doc.layers.iter().chain(doc.symbols.iter().map(|s| &s.art)).chain(doc.patterns.iter().flat_map(|p| p.art.iter())) {
|
||||
visit(n, &mut out);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Does symbol instance `n` repaint its symbol's art: with its own fill or stroke changes, or with
|
||||
/// its fill's stain?
|
||||
fn repaints(n: &Node) -> bool {
|
||||
@@ -574,7 +608,7 @@ pub fn plan<'a>(doc: &'a Document, opts: &PrintOptions) -> Result<PrintPlan<'a>,
|
||||
let job = Job::new(doc, set, opts.postscript)?;
|
||||
let title = opts.title.clone().unwrap_or_else(|| job.doc.title.clone());
|
||||
let created = opts.created.or_else(vectorcraft_doc::metadata::output_time);
|
||||
let sep = Separator::new(&job.doc, set);
|
||||
let sep = Separator::new(&job.doc, set, opts.postscript);
|
||||
let plates: Vec<Document> = (0..job.plates.len()).filter_map(|p| job.ink(Some(p))).map(|i| sep.plate(&i.name)).collect();
|
||||
let marks = set.marks.printer_marks();
|
||||
let sheets = job
|
||||
|
||||
@@ -78,11 +78,13 @@ pub(crate) struct Separator<'a> {
|
||||
pub doc: &'a Document,
|
||||
cms: Arc<Cms>,
|
||||
set: &'a PrintSettings,
|
||||
/// The plates are written as PostScript, which has no blending modes.
|
||||
postscript: bool,
|
||||
}
|
||||
|
||||
impl<'a> Separator<'a> {
|
||||
pub fn new(doc: &'a Document, set: &'a PrintSettings) -> Self {
|
||||
Self { doc, cms: separation_cms(doc, set), set }
|
||||
pub fn new(doc: &'a Document, set: &'a PrintSettings, postscript: bool) -> Self {
|
||||
Self { doc, cms: separation_cms(doc, set), set, postscript }
|
||||
}
|
||||
|
||||
/// How much of ink `plate` colour `c` (with swatch link `link`) prints, 0..1.
|
||||
@@ -131,19 +133,19 @@ impl<'a> Separator<'a> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Whether paint `p` puts none of ink `plate` down, to within half a percent (the other inks a
|
||||
/// black may carry and still count as black, [`vectorcraft_doc::overprint::is_black_ink`]): a
|
||||
/// solid color, a gradient whose every stop does, or a freeform gradient with color points
|
||||
/// whose every point does (points carry no swatch link).
|
||||
/// Whether paint `p` puts none of ink `plate` down: a solid color, a gradient whose every stop
|
||||
/// does, or a freeform gradient with color points whose every point does (points carry no
|
||||
/// swatch link). On PostScript plates, to within half a percent (the other inks a black may
|
||||
/// carry and still count as black, [`vectorcraft_doc::overprint::is_black_ink`]).
|
||||
fn no_ink(&self, plate: &str, p: &Paint) -> bool {
|
||||
const NONE: f32 = 0.005;
|
||||
let none = if self.postscript { 0.005 } else { 0.0 };
|
||||
match p {
|
||||
Paint::Solid { color, swatch, tint } => self.ink(plate, color, swatch.as_deref().map(|s| (s, *tint))) <= NONE,
|
||||
Paint::Solid { color, swatch, tint } => self.ink(plate, color, swatch.as_deref().map(|s| (s, *tint))) <= none,
|
||||
Paint::Gradient(g) => match g.freeform.as_ref().filter(|f| g.gradient.kind == GradientKind::Freeform && !f.points.is_empty()) {
|
||||
Some(f) => f.points.iter().all(|pt| self.ink(plate, &pt.color, None) <= NONE),
|
||||
Some(f) => f.points.iter().all(|pt| self.ink(plate, &pt.color, None) <= none),
|
||||
None => {
|
||||
!g.gradient.stops.is_empty()
|
||||
&& g.gradient.stops.iter().all(|s| self.stop_ink(plate, &s.color, s.swatch.as_deref().map(|n| (n, s.tint)), s.plates) <= NONE)
|
||||
&& g.gradient.stops.iter().all(|s| self.stop_ink(plate, &s.color, s.swatch.as_deref().map(|n| (n, s.tint)), s.plates) <= none)
|
||||
}
|
||||
},
|
||||
_ => false,
|
||||
|
||||
@@ -722,6 +722,29 @@ fn overprint_black_keeps_the_cyan_under_near_and_freeform_blacks_on_postscript_p
|
||||
assert_eq!((fills(&p.plates[0]), fills(&p.plates[3])), (1, 4), "the cyan plate, the Black plate");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_overprinting_fill_keeps_its_faint_ink_on_pdf_plates() {
|
||||
// 0.4% cyan beside 100% K, set to overprint: a PDF plate draws it with Darken, a PostScript
|
||||
// plate draws it as nothing (it has no blending modes).
|
||||
let mut square = Node::path(
|
||||
vectorcraft_doc::NodeId(0),
|
||||
shapes::rectangle(Rect::new(10.0, 15.0, 30.0, 35.0)),
|
||||
Appearance::basic(Paint::solid(Color::cmyk(0.004, 0.0, 0.0, 1.0)), Paint::None, 0.0),
|
||||
);
|
||||
if let Some(f) = square.appearance.fill_mut() {
|
||||
f.overprint = true;
|
||||
}
|
||||
let d = over_cyan(vec![square]);
|
||||
let fills = |postscript: bool| {
|
||||
let opts = PrintOptions { settings: settings(json!({"output": {"mode": "separations"}})), postscript, ..Default::default() };
|
||||
let p = plan(&d, &opts).unwrap();
|
||||
let mut count = 0;
|
||||
p.plates[0].walk(|n| count += usize::from(n.appearance.fill().is_some_and(|f| !f.paint.is_none())));
|
||||
count
|
||||
};
|
||||
assert_eq!((fills(false), fills(true)), (2, 1), "the cyan plate as PDF, as PostScript");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overprinting_type_leaves_the_inks_below_on_separations() {
|
||||
let style = vectorcraft_doc::CharStyle { fill: Paint::solid(Color::cmyk(0.0, 0.0, 0.0, 1.0)), ..Default::default() };
|
||||
@@ -782,6 +805,30 @@ fn overprint_black_follows_a_symbol_instances_own_fill_on_separations() {
|
||||
assert!(!d.symbols.iter().any(|s| s.art.has_overprint()), "the document keeps its own settings");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overprint_black_follows_instance_paints_in_inline_graphics() {
|
||||
use vectorcraft_doc::symbol_overrides::SymbolOverride;
|
||||
// Type shows symbol "Holder" inline; its art is an instance of a black symbol painted magenta.
|
||||
let k = Paint::solid(Color::cmyk(0.0, 0.0, 0.0, 1.0));
|
||||
let r = shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0));
|
||||
let mut inst = Node::new(vectorcraft_doc::NodeId(0), NodeKind::SymbolInstance { symbol: "Black".into(), xf: Default::default() });
|
||||
let magenta = Paint::solid(Color::cmyk(0.0, 1.0, 0.0, 0.0));
|
||||
inst.extras_mut().symbol_overrides = vec![SymbolOverride { path: vec![], fill: Some(magenta), ..Default::default() }];
|
||||
let mut text = vectorcraft_doc::TextObject::point(vectorcraft_geom::Point::new(20.0, 60.0), "Hi", Default::default());
|
||||
text.runs.push(vectorcraft_doc::TextRun::inline(vectorcraft_doc::InlineArt::new("Holder"), Default::default()));
|
||||
let mut d = over_cyan(vec![Node::new(vectorcraft_doc::NodeId(0), NodeKind::Text(Box::new(text)))]);
|
||||
let black = Arc::new(Node::path(vectorcraft_doc::NodeId(0), r, Appearance::basic(k, Paint::None, 0.0)));
|
||||
d.symbols.push(vectorcraft_doc::Symbol { dynamic: true, name: "Black".into(), art: black });
|
||||
d.symbols.push(vectorcraft_doc::Symbol { dynamic: false, name: "Holder".into(), art: Arc::new(inst) });
|
||||
let printed = printed_document(&d, &settings(json!({"output": {"mode": "separations", "overprintBlack": true}})));
|
||||
let holder = printed.symbols.iter().find(|s| s.name == "Holder").unwrap();
|
||||
let mut instances = 0;
|
||||
holder.art.walk(&mut |n: &Node| instances += usize::from(matches!(n.kind, NodeKind::SymbolInstance { .. })));
|
||||
assert_eq!(instances, 0, "the instance is placed as the art it prints");
|
||||
assert!(!holder.art.has_overprint(), "its magenta fill knocks out");
|
||||
assert!(matches!(d.symbols[1].art.kind, NodeKind::SymbolInstance { .. }), "the document keeps its art");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overprinting_type_in_an_opacity_mask_does_not_darken_on_separations() {
|
||||
// Mask art has no inks: an overprinting gray character in an inverted clipping mask keeps its
|
||||
|
||||
Reference in New Issue
Block a user