vendor: port pdfcraft #2770 plate mode into hayro-interpret

Bring the vendored interpreter part of storytold/pdfcraft#2770 (Output
Preview, source commit 6fcf2a4aca29e943e28cb69017ff8f87d00656c6) onto
the ec0a965 snapshot. It applies without conflicts.

InterpreterSettings::plate draws one ink's separation: every paint
draws that ink's tint as a gray film, by the colour space's ink use and
tint. The graphics state reads OP, op and OPM, and an overprinting
paint that doesn't specify the plate's ink leaves the plate as it is
(ISO 32000-2 8.6.7). InterpreterSettings::ink_sink reports the spot
inks paints use, and color::CmykSimulation converts process colour to
an output intent's CMYK profile.

PdfCraft's separations.rs, Output Preview UI and automation are not
part of this port. The ledger in vendor/README.craft-reader.md names the
pull request, author and source commit.

Co-authored-by: Guillem Hermida <66697068+guillehr2@users.noreply.github.com>
This commit is contained in:
aionggandGuillem Hermida committed 2026-10-20 02:40:50 +00:00
1 parent b6f60f25b1
commit 2c8c3ad261
10 files changed
+1181 -44

No files matched your search

+7
View File
@@ -32,6 +32,13 @@ re-sync brings these PdfCraft changes:
PdfCraft's vendored `vello_common` patch (clip-intersection performance) is not part of this
reader snapshot.
Changes ported from PdfCraft pull requests that were open when they were ported, under the
same MIT OR Apache-2.0 licence. Code comments keep the pull request's patch numbers.
| PdfCraft PR | Author | Source commit | Files | Change |
|---|---|---|---|---|
| [#2770](https://github.com/storytold/pdfcraft/pull/2770) | Guillem Hermida (guillehr2) | [6fcf2a4](https://github.com/guillehr2/pdfcraft/commit/6fcf2a4aca29e943e28cb69017ff8f87d00656c6) | hayro-interpret `color.rs`, `interpret/mod.rs`, `interpret/path.rs`, `interpret/state.rs`, `pattern.rs`, `shading.rs`, `soft_mask.rs`, `x_object.rs` | Patches 35 and 36, plate mode: `InterpreterSettings::plate` draws one ink's separation as a gray film (`color::Plate`, `ColorSpace::ink_use`/`ink_tint`); the graphics state reads `OP`, `op` and `OPM` and an overprinting paint that doesn't specify the plate's ink leaves the plate as it is (ISO 32000-2 §8.6.7); `InterpreterSettings::ink_sink` reports spot inks; `color::CmykSimulation` converts process colour to an output intent's CMYK. Only the vendored interpreter part is ported; PdfCraft's `separations.rs` and Output Preview UI are not |
The shared snapshot adds immutable per-document ordinary decode limits, threaded through
initial xrefs, object streams, fallback and repair. Existing constructors retain their
previous default. Known-size image budgets and streaming content budgets remain distinct.
+8 -8
View File
@@ -182,7 +182,7 @@
"path": "src/color.rs",
"source_sha256": "799ce29bb5e59c8fc94db202873e48c2047dd35962e6f26efd215156c47158c1",
"source_git_blob": "56bb04f24c04ba33ab6bf99c02a24735670959ad",
"sha256": "149d5a6b1b9e6212d2b3e9d63e1803a6041eb1798bfb9231ef89fc6bfcb7b968"
"sha256": "784753b972d9a24167c8085f4e387ac7cc85007f4ab4ca83ab0c0aafe067c073"
},
{
"path": "src/context.rs",
@@ -362,19 +362,19 @@
"path": "src/interpret/mod.rs",
"source_sha256": "2b002323055bc19aa497e92c81ad8e06dc60ee03686cad89366df4ac7c7a06b2",
"source_git_blob": "fe08fc284ba7c914d1414b68a5a346674a6f910f",
"sha256": "1ed42a7777a6265f14efaaa5899dc96b93dc53aff85afacfcac60065e6e490d5"
"sha256": "2f50fcd65da262f4ef66c9611adcdb993015c57181bc2a51a551611152a59f5f"
},
{
"path": "src/interpret/path.rs",
"source_sha256": "a5defbc4b883b262662f7e7474a00ec1f97dbef8c03b8669859f624f5d02344b",
"source_git_blob": "838ea099f11d918d6e333e32503368be864689f8",
"sha256": "a5defbc4b883b262662f7e7474a00ec1f97dbef8c03b8669859f624f5d02344b"
"sha256": "eb42777dc3063794c21aa914b61e40a8547820de3e4d7b47924d169890f4fbb4"
},
{
"path": "src/interpret/state.rs",
"source_sha256": "dce778291b13f6df83c8c13aee22f60edd033ec9f7d89309ef148d46d3ba9814",
"source_git_blob": "95b773fb5cc434ab8db362d00e4e5180a8b740c9",
"sha256": "dce778291b13f6df83c8c13aee22f60edd033ec9f7d89309ef148d46d3ba9814"
"sha256": "393371ec56dccdc3c2fc20d61da39d87e3e8393bf69ddbd249417490f8f9923b"
},
{
"path": "src/interpret/text.rs",
@@ -404,19 +404,19 @@
"path": "src/pattern.rs",
"source_sha256": "17b49a465275c20e6645dea9443f2cb3a64c594925fd860e74b80b44d5344e37",
"source_git_blob": "9295f51709f8915951d7b9afca9411651d65a1f8",
"sha256": "24ac7a1cfd9a55b7d40d572120f52743bd390fab0007603aec64034ae7d2fd23"
"sha256": "ae362a5074b40482f2c5e16ea66a0398b27ec866a7b4adb8f45fe7221c960ae1"
},
{
"path": "src/shading.rs",
"source_sha256": "5d541a2d52f69c88e87a40580bf28afa4b8a6a2d62a3385009087264384ead32",
"source_git_blob": "2e619e47f2800d7fc7cbdae77c66c58f012c84c2",
"sha256": "5d541a2d52f69c88e87a40580bf28afa4b8a6a2d62a3385009087264384ead32"
"sha256": "6e80c039ab7ca38ede2b1778709f1b4258d8cf219d044d3298f4a5f6dd2c8f9a"
},
{
"path": "src/soft_mask.rs",
"source_sha256": "6cd9c59c0cff580879c1f06ff40f3537c04b719bdb3ea59008fa1ab7559db5dd",
"source_git_blob": "4d97d565b53c820fa927fbba8c3dda6acead7f34",
"sha256": "780ffbf73567a7ae33f2fb673676840e0a29cb6b59f1d8b625034f42c4d17a22"
"sha256": "0e3871896575006f194fb46242fcaa6e1026f459c6144c38da438f82ace95e50"
},
{
"path": "src/types.rs",
@@ -434,7 +434,7 @@
"path": "src/x_object.rs",
"source_sha256": "e1c51e96a335c32c122011b2d05c5020c36a33c2c73342ba173c28a3e2fe0219",
"source_git_blob": "21b134ce8cd9604399cd0776febf923d69c02673",
"sha256": "48d296abf28696c4a3e01e9d12169c754062b0840c9f2b93051435247aba9144"
"sha256": "20e9d2f4fcafd20e11d6255f2800c8732ea84e74e5061287c8d5fbcfb4ffe013"
}
],
"compatibility_reference": {
+983 -32
View File
File diff suppressed because it is too large. Load diff
+10
View File
@@ -120,6 +120,14 @@ pub struct InterpreterSettings {
/// costs a decode and a resample each for pixels nobody can see. Never set it for a final
/// render (tiles, whole pages, print, export).
pub preview: bool,
/// PdfCraft patch (35): draw one ink's separation instead of the composite page (see
/// [`Plate`](crate::color::Plate)). Soft masks still draw in colour: a mask's luminosity
/// comes from its group's colours, not from any plate. Patch 32: the plate's `simulation`
/// converts process colour to an output intent's CMYK.
pub plate: Option<crate::color::Plate>,
/// PdfCraft patch (35): told about each spot ink a paint uses (colours, images, shadings
/// and uncoloured patterns), whether or not `plate` is set.
pub ink_sink: Option<crate::color::InkSinkFn>,
}
impl Default for InterpreterSettings {
@@ -142,6 +150,8 @@ impl Default for InterpreterSettings {
ocg_overrides: Arc::new(Vec::new()),
cancelled: None,
preview: false,
plate: None,
ink_sink: None,
}
}
}
+56 -1
View File
@@ -1,6 +1,8 @@
use crate::color::{Color, ColorSpace};
use crate::color::{Color, ColorSpace, InkUse, Plate};
use crate::context::{Context, path_as_rect};
use crate::device::Device;
use crate::interpret::state::PaintData;
use crate::pattern::Pattern;
use crate::util::{BezPathExt, Float32Ext};
use crate::{FillRule, Paint, PathDrawMode, StrokeProps};
use kurbo::{BezPath, Cap, Join, PathEl};
@@ -153,6 +155,23 @@ pub(crate) fn get_paint<'a>(context: &Context<'a>, is_stroke: bool) -> Paint<'a>
context.get().non_stroke_data()
};
// PdfCraft patch (35): report spot inks, and draw separations.
if let Some(sink) = &context.settings.ink_sink {
data.color_space.report_spots(sink);
if let Some(Pattern::Shading(s)) = &data.pattern {
s.shading.color_space.report_spots(sink);
}
}
if let Some(plate) = &context.settings.plate {
let state = &context.get().graphics_state;
let overprint = if is_stroke {
state.overprint_stroke
} else {
state.overprint_fill
};
return plate_paint(context, data, plate, overprint, state.overprint_mode);
}
if data.color_space.is_pattern() || data.pattern.is_some() {
if let Some(mut pattern) = data.pattern {
if let Some(tf) = &data.transfer_function {
@@ -176,3 +195,39 @@ pub(crate) fn get_paint<'a>(context: &Context<'a>, is_stroke: bool) -> Paint<'a>
}
}
}
/// PdfCraft patch (35): the paint `data` as drawn on `plate`: a colour becomes its film, a
/// shading is converted through the plate, and a paint that leaves the plate as it is (an
/// overprinting paint that doesn't specify the plate's ink, or the `None` colorant) becomes
/// transparent. Transfer functions are left out: they act on device colorants, which the
/// film doesn't model.
fn plate_paint<'a>(
context: &Context<'a>,
data: PaintData<'a>,
plate: &Plate,
overprint: bool,
overprint_mode: u8,
) -> Paint<'a> {
let untouched = || Paint::Color(Color::film(0.0, 0.0));
if !(data.color_space.is_pattern() || data.pattern.is_some()) {
let color = Color::new(data.color_space, data.color, data.alpha);
return Paint::Color(color.for_plate(plate, overprint, overprint_mode));
}
let Some(mut pattern) = data.pattern else {
// Pattern was likely invalid, use transparent paint.
return untouched();
};
match &mut pattern {
Pattern::Shading(s) => {
match s.shading.color_space.ink_use(&plate.ink) {
InkUse::Nothing => return untouched(),
InkUse::Unspecified if plate.overprint && overprint => return untouched(),
InkUse::Paints | InkUse::Unspecified => {}
}
std::sync::Arc::make_mut(&mut s.shading).for_plate(plate);
}
Pattern::Tiling(t) => t.for_plate(plate, overprint, overprint_mode),
}
pattern.pre_concat_transform(context.root_transform());
Paint::Pattern(Box::new(pattern))
}
+24
View File
@@ -269,6 +269,12 @@ pub(crate) struct GraphicsState<'a> {
pub(crate) soft_mask: Option<SoftMask<'a>>,
pub(crate) transfer_function: Option<ActiveTransferFunction>,
pub(crate) blend_mode: BlendMode,
// PdfCraft patch (35): the overprint parameters (ISO 32000-2 §8.6.7, `OP`, `op` and `OPM`
// in a graphics state parameter dictionary). They only matter when drawing separations.
pub(crate) overprint_stroke: bool,
pub(crate) overprint_fill: bool,
pub(crate) overprint_mode: u8,
}
impl Default for GraphicsState<'_> {
@@ -286,6 +292,9 @@ impl Default for GraphicsState<'_> {
soft_mask: None,
transfer_function: None,
blend_mode: BlendMode::default(),
overprint_stroke: false,
overprint_fill: false,
overprint_mode: 0,
}
}
}
@@ -408,6 +417,21 @@ pub(crate) fn handle_gs_single<'a>(
.map(|n| if n == 0.0 { 0.01 } else { n })
.collect();
}
// PdfCraft patch (35): `OP` sets stroking overprint, and non-stroking overprint too when
// the dictionary has no `op` of its own; `OPM` is 0 or 1 (§8.6.7).
"OP" => {
let overprint = dict.get::<bool>(key)?;
let state = &mut context.get_mut().graphics_state;
state.overprint_stroke = overprint;
if !dict.contains_key("op") {
state.overprint_fill = overprint;
}
}
"op" => context.get_mut().graphics_state.overprint_fill = dict.get::<bool>(key)?,
"OPM" => {
let mode = dict.get::<u8>(key)?;
context.get_mut().graphics_state.overprint_mode = u8::from(mode == 1);
}
"Type" => {}
_ => {}
}
+25 -1
View File
@@ -1,7 +1,7 @@
//! PDF patterns.
use crate::cache::Cache;
use crate::color::{Color, ColorSpace};
use crate::color::{Color, ColorSpace, Plate};
use crate::context::{Context, InterpreterCache};
use crate::device::Device;
use crate::font::Glyph;
@@ -147,6 +147,30 @@ pub struct TilingPattern<'a> {
nesting_depth: u32,
}
impl TilingPattern<'_> {
/// PdfCraft patch (35): an uncoloured pattern draws its cell in the colour it is used
/// with, so on a plate it draws that colour's film. A coloured pattern's cell is separated
/// as it is drawn.
pub(crate) fn for_plate(&mut self, plate: &Plate, overprint: bool, overprint_mode: u8) {
if !self.is_color {
self.stroke_paint = self
.stroke_paint
.for_plate(plate, overprint, overprint_mode);
self.non_stroking_paint =
self.non_stroking_paint
.for_plate(plate, overprint, overprint_mode);
}
let simulation = plate.simulation.as_ref().map(|s| s.digest());
self.cache_key = hash128(&(
self.cache_key,
&plate.ink,
plate.overprint,
overprint,
simulation,
));
}
}
impl Debug for TilingPattern<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("TilingPattern")
+10
View File
@@ -139,6 +139,16 @@ pub struct Shading {
}
impl Shading {
/// PdfCraft patch (35): the shading drawn as `plate`'s plate, through its simulation
/// (patch 36).
pub(crate) fn for_plate(&mut self, plate: &crate::color::Plate) {
self.color_space = self
.color_space
.plate(plate.ink.clone(), plate.simulation.clone());
let simulation = plate.simulation.as_ref().map(|s| s.digest());
self.cache_key = crate::util::hash128(&(self.cache_key, &plate.ink, simulation));
}
pub(crate) fn new(dict: &Dict<'_>, stream: Option<&Stream<'_>>, cache: &Cache) -> Option<Self> {
let cache_key = dict.cache_key();
+7 -1
View File
@@ -169,7 +169,13 @@ impl<'a> SoftMask<'a> {
transfer_function,
bbox: context.bbox(),
interpreter_cache: context.interpreter_cache.clone(),
settings: context.settings.clone(),
// PdfCraft patch (35): a mask's luminosity comes from its group's colours, never
// from a plate, and the inks it uses are never printed.
settings: InterpreterSettings {
plate: None,
ink_sink: None,
..context.settings.clone()
},
xref: context.xref,
background,
parent_resources,
+51 -1
View File
@@ -1,5 +1,5 @@
use crate::cache::{Cache, DecodedImageCache, DecodedImageKey};
use crate::color::{ColorComponents, ColorSpace, ToRgb};
use crate::color::{ColorComponents, ColorSpace, InkUse, Plate, ToRgb};
use crate::context::Context;
use crate::device::Device;
use crate::function::{Function, interpolate};
@@ -227,6 +227,37 @@ pub(crate) fn draw_image_xobject<'a, 'b>(
return;
}
// PdfCraft patch (35): report the image's spot inks, and draw it on a plate. An image
// without a colour space takes one from its data (JPEG, JPEG 2000): gray, RGB or CMYK,
// all process colour. Images paint with the non-stroking overprint parameter.
let raster_cs = if x_object.is_mask {
None
} else {
x_object.color_space.as_ref()
};
if let (Some(sink), Some(cs)) = (&context.settings.ink_sink, raster_cs) {
cs.report_spots(sink);
}
let mut on_plate = None;
if let Some(plate) = &context.settings.plate
&& !x_object.is_mask
{
let ink_use = match raster_cs {
Some(cs) => cs.ink_use(&plate.ink),
None if plate.ink.process_index().is_some() => InkUse::Paints,
None => InkUse::Unspecified,
};
let overprint = plate.overprint && context.get().graphics_state.overprint_fill;
if ink_use == InkUse::Nothing || (ink_use == InkUse::Unspecified && overprint) {
if has_oc {
context.ocg_state.end_marked_content();
}
return;
}
on_plate = Some(x_object.for_plate(plate));
}
let x_object = on_plate.as_ref().unwrap_or(x_object);
let width = x_object.width as f64;
let height = x_object.height as f64;
@@ -308,9 +339,22 @@ pub(crate) struct ImageXObject<'a> {
stream: Stream<'a>,
transfer_function: Option<ActiveTransferFunction>,
warning_sink: WarningSinkFn,
/// PdfCraft patch (35): the plate the image is drawn on, if any.
plate: Option<Plate>,
}
impl<'a> ImageXObject<'a> {
/// PdfCraft patch (35): the image drawn on `plate`. Not cached (the cache holds colour
/// decodes), and without a transfer function (see `get_paint`).
fn for_plate(&self, plate: &Plate) -> Self {
Self {
plate: Some(plate.clone()),
decoded_cache: None,
transfer_function: None,
..self.clone()
}
}
pub(crate) fn new(
stream: &Stream<'a>,
resolve_cs: impl FnOnce(&Name<'_>) -> Option<ColorSpace>,
@@ -371,6 +415,7 @@ impl<'a> ImageXObject<'a> {
stream: stream.clone(),
is_mask,
is_stencil_mask,
plate: None,
})
}
@@ -594,6 +639,11 @@ fn decode_context<'a>(
})
})
.unwrap_or(ColorSpace::device_gray());
// PdfCraft patch (35): on a plate, every sample converts to the ink's film.
let color_space = match &obj.plate {
Some(plate) => color_space.plate(plate.ink.clone(), plate.simulation.clone()),
None => color_space,
};
let fallback_bpc = if obj.is_stencil_mask { 1 } else { 8 };