Merge PR #3116: fix(render): emit clip-only text (7 Tr) to devices for text extraction (#3109)

This commit is contained in:
aiongg
2026-10-22 01:44:50 +00:00
6 changed files with 135 additions and 2 deletions
+11
View File
@@ -51,3 +51,14 @@ black-point normalization is unchanged. `lab_bradford_tests` checks independent
D50/equal-energy neutral and chromatic oracles, D65 identity, and direct/Indexed
consistency (including an asymmetric chromatic Range), and zero/overflowing
cone-response fallback.
## Clipping-only text reporting (#3109 / #3116)
`hayro-interpret/src/interpret/text.rs` reports mode 7 glyphs after installing their
clip, and `hayro-interpret/src/types.rs` distinguishes `GlyphDrawMode::Clip` from
invisible OCR text. `hayro/src/renderer.rs` does not paint either mode directly.
This preserves clipping-only titles when `TextFilter.images` excludes invisible OCR.
Coverage: `text::tests::clipping_mode_filter_keeps_titles_and_excludes_ocr` (plain
and ActualText filtered extraction), and
`text::tests::clipping_mode_text_is_extracted_and_searchable_like_other_rendering_modes`
(extraction, search, glyph geometry, clip-through pixels and no-paint pixels).
+10
View File
@@ -126,6 +126,16 @@ pub(crate) fn show_glyph<'a>(
}
TextRenderingMode::Clip => {
clip_glyph(ctx, glyph, glyph_transform);
// PdfCraft patch: report clipping text separately from invisible OCR text.
// Extraction filters must retain text that is filled through its
// clipping path without rendering devices drawing it directly.
device.draw_glyph(
glyph,
ctx.get().ctm,
glyph_transform,
&get_paint(ctx, false),
&GlyphDrawMode::Clip,
);
}
TextRenderingMode::FillAndClip => {
clip_glyph(ctx, glyph, glyph_transform);
+2
View File
@@ -284,6 +284,8 @@ pub enum GlyphDrawMode {
Fill,
/// Draw using a stroke.
Stroke(StrokeProps),
/// PdfCraft patch: text that shapes a clip; report it without painting a glyph.
Clip,
/// Invisible text (for text extraction but not visual rendering).
Invisible,
}
+2 -2
View File
@@ -1738,8 +1738,8 @@ impl<'a> Device<'a> for Renderer {
GlyphDrawMode::Stroke(s) => {
Self::stroke_glyph(self, glyph, transform, glyph_transform, paint, s);
}
GlyphDrawMode::Invisible => {
// Don't render invisible text for visual output
GlyphDrawMode::Invisible | GlyphDrawMode::Clip => {
// PdfCraft patch: neither mode paints; clipping was installed by the interpreter.
}
}
}