From 8d123b19cacd007f340644ede80468ced474ac7b Mon Sep 17 00:00:00 2001 From: 00xJ0 <56056764+00xJ0@users.noreply.github.com> Date: Sun, 18 Oct 2026 16:06:24 -0700 Subject: [PATCH] Test: check which text the PDF import keeps beside invisible text (#2675 review) The visible line's text comes in as type and the invisible line's doesn't; as type or outlines, all the art kept lies on the visible line's baseline, none on the invisible one's. --- crates/pdf/src/tests_reader_compat.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/pdf/src/tests_reader_compat.rs b/crates/pdf/src/tests_reader_compat.rs index 9c93e44cf..0707263d6 100644 --- a/crates/pdf/src/tests_reader_compat.rs +++ b/crates/pdf/src/tests_reader_compat.rs @@ -188,9 +188,24 @@ fn invisible_text_is_reported_when_left_out() { for text_as in [TextAs::Text, TextAs::Outlines] { let r = open(invisible, text_as); assert!(r.warnings.iter().any(|w| w == crate::INVISIBLE_TEXT_NOTE), "{text_as:?}: {:?}", r.warnings); - let mut kept = 0; - r.document.walk(|n| kept += usize::from(matches!(n.kind, NodeKind::Text(_) | NodeKind::Path { .. } | NodeKind::Compound { .. }))); - assert!(kept >= 1, "{text_as:?}: the visible line still comes in"); + // What came in: the type's text, and where the art lies. On the 60 pt page the visible + // line (baseline 10 pt up) lies 35–50 pt down, the invisible one (40 pt up) 5–20 pt down. + let (mut text, mut tops) = (String::new(), vec![]); + r.document.walk(|n| { + if let NodeKind::Text(t) = &n.kind { + text.push_str(&t.plain_text()); + } + if matches!(n.kind, NodeKind::Text(_) | NodeKind::Path { .. } | NodeKind::Compound { .. }) + && let Some(b) = n.visual_bounds() + { + tops.push(b.y0); + } + }); + if text_as == TextAs::Text { + assert!(text.contains("CA") && !text.contains("AB"), "{text_as:?}: {text:?}"); + } + assert!(!tops.is_empty(), "{text_as:?}: the visible line still comes in"); + assert!(tops.iter().all(|y| *y > 25.0), "{text_as:?}: only the visible line's art, tops at {tops:?}"); let visible = open("BT /F1 20 Tf 1 0 0 1 10 10 Tm (CA) Tj ET", text_as); assert!(!visible.warnings.iter().any(|w| w == crate::INVISIBLE_TEXT_NOTE), "{text_as:?}: {:?}", visible.warnings); }