From ee30c5d47259908c0ec4ed1e941cc6a3c40f3e21 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Mon, 30 Nov 2026 14:50:00 -0800 Subject: [PATCH] PDF import: keep Type 3 glyph art inside empty ActualText spans --- crates/pdf/src/import/device.rs | 3 ++- crates/pdf/src/tests/text_placement.rs | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/pdf/src/import/device.rs b/crates/pdf/src/import/device.rs index cd40578cec..c717b45ce8 100644 --- a/crates/pdf/src/import/device.rs +++ b/crates/pdf/src/import/device.rs @@ -220,7 +220,8 @@ impl<'a> Device<'a> for Builder<'_> { } let scale = mean_scale(transform); let overprint = self.glyph_overprint(stroke.is_some()); - if self.type_type3_glyph(t3, transform * glyph_transform, scale, Some(paint), stroke.as_ref(), overprint) { + // Draw the glyph's artwork below when empty ActualText suppresses live text. + if !self.actual.textless() && self.type_type3_glyph(t3, transform * glyph_transform, scale, Some(paint), stroke.as_ref(), overprint) { return; } self.flush_glyphs(); diff --git a/crates/pdf/src/tests/text_placement.rs b/crates/pdf/src/tests/text_placement.rs index 31ea411840..45c73ef8a2 100644 --- a/crates/pdf/src/tests/text_placement.rs +++ b/crates/pdf/src/tests/text_placement.rs @@ -509,10 +509,13 @@ fn type3_with_actual_text() { assert_eq!(t.len(), 1, "Type 3 with ActualText should import as live text"); assert_eq!(t[0].plain_text(), "XYZ"); - // Empty ActualText suppresses mapped text - let d_empty = open_as(&page("/Span << /ActualText () >> BDC BT /T3U 20 Tf 20 50 Td (ab) Tj ET EMC", ""), TextAs::Text); - let t_empty = texts(&d_empty); - assert!(t_empty.is_empty(), "Empty ActualText should suppress text"); + // Empty ActualText suppresses mapped text while keeping both glyphs' artwork. + let empty = page("/Span << /ActualText () >> BDC BT /T3U 20 Tf 20 50 Td (ab) Tj ET EMC", ""); + let d_empty = open_as(&empty, TextAs::Text); + assert!(texts(&d_empty).is_empty(), "Empty ActualText should suppress text"); + let outline_contours = contours(&open_as(&empty, TextAs::Outlines)); + assert_eq!(outline_contours.len(), 2, "The fixture draws two glyph boxes"); + assert_eq!(contours(&d_empty), outline_contours, "Empty ActualText should keep both glyph drawings"); } /// A font that isn't embedded or installed is set in a stand-in: the line still starts where