PDF import: a stroke of another glyph never joins the glyph just filled (#8015)

This commit is contained in:
HassanKhan
2026-11-16 12:00:35 +05:00
parent 6f35a12cc7
commit cec81c81f3
2 changed files with 17 additions and 5 deletions
+8 -5
View File
@@ -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;
+9
View File
@@ -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}");
}