Skip to content

Commit aa2887b

Browse files
committed
Seat sunk subscripts on their letter after the line reflows, and keep a digit already seated under its host
1 parent 9f14002 commit aa2887b

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎crates/rpt-core/src/rewrite.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28928,6 +28928,7 @@ fn sink_math_subscripts(lines: &mut Vec<Drawn>, glyphs: &[&Glyph], font: &Subset
2892828928
continue;
2892928929
}
2893028930
let sink_set: HashSet<usize> = sink.iter().copied().collect();
28931+
let first_extra = extra.len();
2893128932
for index in &sink {
2893228933
let sub_size = (line.size * 0.62).max(0.5);
2893328934
let text = chars[*index].to_string();
@@ -29013,6 +29014,22 @@ fn sink_math_subscripts(lines: &mut Vec<Drawn>, glyphs: &[&Glyph], font: &Subset
2901329014
vec![false; kept.len()]
2901429015
};
2901529016
line.gaps = gaps;
29017+
// Each earlier digit left the line, so the letters after it moved
29018+
// left. `f4` was tucked at the x it had before, and the digit landed
29019+
// on `和`. Seat every digit on its letter where that letter is now.
29020+
let drawn_chars: Vec<char> = line.text.chars().collect();
29021+
for (offset, index) in sink.iter().enumerate() {
29022+
let Some(letter) = kept.iter().position(|kept| *kept + 1 == *index) else {
29023+
continue;
29024+
};
29025+
if line.widths.len() != drawn_chars.len() {
29026+
continue;
29027+
}
29028+
let letter_right = char_origin(line, &drawn_chars, letter) + line.widths[letter];
29029+
let script = &mut extra[first_extra + offset];
29030+
let sub_w = script.widths.first().copied().unwrap_or(0.0);
29031+
script.x = (letter_right - sub_w * 0.55).max(line.x);
29032+
}
2901629033
}
2901729034
lines.extend(extra);
2901829035
}
@@ -29036,6 +29053,23 @@ fn raise_sunk_subscripts(lines: &mut [Drawn]) {
2903629053
let y = lines[index].y;
2903729054
let size = lines[index].size.max(0.5);
2903829055
let ids = &lines[index].glyph_ids;
29056+
// `f3 和 f5` wrapped onto the next line, and the digit already sits
29057+
// a script drop under its own `f` there. Lifting it to the line
29058+
// above put `3` on `性`.
29059+
let seated = lines.iter().enumerate().any(|(other, host)| {
29060+
let dy = host.y - y;
29061+
other != index
29062+
&& host.page == page
29063+
&& host.size >= size * 1.2
29064+
&& ids.iter().any(|id| host.glyph_ids.contains(id))
29065+
&& dy > host.size * 0.12
29066+
&& dy <= host.size * 0.30
29067+
&& x >= host.x - 1.0
29068+
&& x <= line_ink_right(host) + 1.0
29069+
});
29070+
if seated {
29071+
continue;
29072+
}
2903929073
let mut best: Option<(f32, f32, f32)> = None;
2904029074
for (other, host) in lines.iter().enumerate() {
2904129075
if other == index || host.page != page || host.size < size * 1.2 {

0 commit comments

Comments
 (0)