From 572cec5dca60b9db90f4eaa4aa7c6cc1719eac79 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Fri, 6 Nov 2026 09:11:02 +0800 Subject: [PATCH] A markup's quads too far apart for a width keep its /Rect; StrikeOut and Squiggly in the test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/annot/src/appearance.rs | 4 +++- crates/annot/src/tests.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/annot/src/appearance.rs b/crates/annot/src/appearance.rs index bcacc27a70..7d5fde14d0 100644 --- a/crates/annot/src/appearance.rs +++ b/crates/annot/src/appearance.rs @@ -542,7 +542,9 @@ pub(crate) fn markup_reach(d: &Dict) -> Option<[f64; 4]> { for p in q.as_chunks::<2>().0 { out = [out[0].min(p[0]), out[1].min(p[1]), out[2].max(p[0]), out[3].max(p[1])]; } - (out != rect).then_some(out) + // Finite corners can still be too far apart for a width or height (`-1e308` to `1e308`). + let usable = (out[2] - out[0]).is_finite() && (out[3] - out[1]).is_finite(); + (usable && out != rect).then_some(out) } fn draw_body(context: &AppearanceContext<'_>, drawing: &mut AppearanceDrawing) -> Option<()> { diff --git a/crates/annot/src/tests.rs b/crates/annot/src/tests.rs index 4afd042481..8a6db33f94 100644 --- a/crates/annot/src/tests.rs +++ b/crates/annot/src/tests.rs @@ -2790,12 +2790,15 @@ fn text_markup_whose_quads_reach_past_its_rect_is_drawn_over_them() { let doc = document_of(&[ b"<< /Type /Catalog /Pages 2 0 R >>", b"<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 612 792] >>", - b"<< /Type /Page /Parent 2 0 R /Annots [4 0 R 5 0 R 6 0 R] >>", + b"<< /Type /Page /Parent 2 0 R /Annots [4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R] >>", b"<< /Type /Annot /Subtype /Highlight /Rect [335.1 370.83 324.6 471.78] /C [1 1 0] /QuadPoints [370 287 471 287 370 277 471 277] >>", b"<< /Type /Annot /Subtype /Underline /Rect [10 10 20 20] /C [0 0 1] /QuadPoints [100 120 200 120 100 100 200 100] >>", b"<< /Type /Annot /Subtype /Highlight /Rect [50 50 150 70] /C [1 1 0] /QuadPoints [60 68 140 68 60 52 140 52] >>", + b"<< /Type /Annot /Subtype /StrikeOut /Rect [10 10 20 20] /C [1 0 0] /QuadPoints [100 220 200 220 100 200 200 200] >>", + b"<< /Type /Annot /Subtype /Squiggly /Rect [10 10 20 20] /C [0 1 0] /QuadPoints [100 320 200 320 100 300 200 300] >>", + b"<< /Type /Annot /Subtype /Highlight /Rect [10 10 20 20] /C [1 1 0] /QuadPoints [-1e308 20 1e308 20 -1e308 10 1e308 10] >>", ]); - let display = with_missing_appearances(&doc).expect("three markups need an appearance"); + let display = with_missing_appearances(&doc).expect("the markups need an appearance"); let shown = list(&display, 0); let rect = |d: &Dict| nums_of(d, b"Rect"); let bbox = |d: &Dict| { @@ -2810,6 +2813,11 @@ fn text_markup_whose_quads_reach_past_its_rect_is_drawn_over_them() { assert_eq!(rect(&shown[1]), [10.0, 10.0, 200.0, 120.0], "an underline's too"); assert_eq!(bbox(&shown[1]), rect(&shown[1])); assert_eq!(rect(&shown[2]), [50.0, 50.0, 150.0, 70.0], "a /Rect that holds the quads stays as it is"); + assert_eq!(rect(&shown[3]), [10.0, 10.0, 200.0, 220.0], "a strikeout's too"); + assert_eq!(bbox(&shown[3]), rect(&shown[3])); + assert_eq!(rect(&shown[4]), [10.0, 10.0, 200.0, 320.0], "a squiggly's too"); + assert_eq!(bbox(&shown[4]), rect(&shown[4])); + assert_eq!(rect(&shown[5]), [10.0, 10.0, 20.0, 20.0], "quads too far apart for a width keep the /Rect"); assert_eq!(rect(&list(&doc, 0)[0]), [335.1, 370.83, 324.6, 471.78], "the source document is unchanged"); }