From cec81c81f335628bd5b92bce9ae01c811b29c137 Mon Sep 17 00:00:00 2001 From: HassanKhan Date: Mon, 16 Nov 2026 12:00:35 +0500 Subject: [PATCH] PDF import: a stroke of another glyph never joins the glyph just filled (#8015) --- crates/pdf/src/import_text.rs | 13 ++++++++----- crates/pdf/src/tests/textstroke.rs | 9 +++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/pdf/src/import_text.rs b/crates/pdf/src/import_text.rs index 1570219259..295f2ae3c2 100644 --- a/crates/pdf/src/import_text.rs +++ b/crates/pdf/src/import_text.rs @@ -626,7 +626,7 @@ impl TextLine { // glyphs filled before it, so no stroke looks through them again. self.stroked = self.filled.len(); // Nor does a stroke at another opacity join the glyph just filled: the line has one. - return opacity == self.opacity && self.stroke_last(font, at, stroke, overprint); + return opacity == self.opacity && self.stroke_last(font, at, text, stroke, overprint); }; let continues = self .pending @@ -728,19 +728,22 @@ impl TextLine { } } - /// A stroke over the glyph just drawn at `at` in `font`, which `overprint`s or not: that glyph - /// is stroked. `false`: it isn't that glyph. + /// A stroke over glyph `glyph` just drawn at `at` in `font`, which `overprint`s or not: that + /// glyph is stroked. `false`: it isn't that glyph (another place, font or text). /// /// A filled glyph joins a run of the same fill whatever its stroke ([`Look::takes`]), so the /// run can hold glyphs before it that are stroked otherwise or not at all: then the glyph's /// text becomes a run of its own with this stroke, and the glyphs before it keep theirs /// (#7741). The line's text is the same either way, so the characters' slots, gaps and /// authored flags, kept along the whole line, still line up. - fn stroke_last(&mut self, font: u128, at: Placement, stroke: TypeStroke, overprint: bool) -> bool { + fn stroke_last(&mut self, font: u128, at: Placement, glyph: &str, stroke: TypeStroke, overprint: bool) -> bool { self.flush_stroke(); let start = self.last_start; let last_at = self.last_at; - let Some((look, shift, text)) = self.runs.last_mut().filter(|(l, ..)| l.font == font && last_at.same_as(&at)) else { + // The glyph just filled, in the same font and placement, with the same text. + let Some((look, shift, text)) = + self.runs.last_mut().filter(|(l, _, t)| l.font == font && last_at.same_as(&at) && t.get(start..) == Some(glyph)) + else { return false; }; let same = look.stroke.as_ref() == Some(&stroke) && look.overprint_stroke == overprint; diff --git a/crates/pdf/src/tests/textstroke.rs b/crates/pdf/src/tests/textstroke.rs index c89496fcea..1b3713d7f6 100644 --- a/crates/pdf/src/tests/textstroke.rs +++ b/crates/pdf/src/tests/textstroke.rs @@ -266,3 +266,12 @@ fn a_glyph_stroked_at_another_opacity_than_its_fill_stays_its_own_type() { assert_eq!(texts, want, "{content}"); } } + +/// A stroke goes only over a glyph filled with the same text: "AB" filled, its "A" stroked, then +/// an "X" stroked where the "B" stands is type of its own, and the "B" stays unstroked (#8015). +#[test] +fn a_stroke_of_another_glyph_where_one_was_filled_stays_its_own_type() { + let content = "0 0 0 RG 1 1 0.8 rg 3 w BT /F1 60 Tf 1 0 0 1 40 110 Tm (AB) Tj 1 Tr 1 0 0 1 40 110 Tm (A) Tj (X) Tj 0 Tr ET"; + let want = [("A".to_string(), 60.0, true, true), ("B".to_string(), 60.0, true, false), ("X".to_string(), 60.0, false, true)]; + assert_eq!(word_runs(content), want, "{content}"); +}