mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-09 13:05:56 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
96b96c53da
commit
572cec5dca
@@ -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<()> {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user