@@ -23512,11 +23512,11 @@ fn cap_upward_shift(
2351223512 continue;
2351323513 }
2351423514 let gy = glyph.matrix[5];
23515+ let gx0 = glyph.bbox[0].min(glyph.bbox[2]);
23516+ let gx1 = glyph.bbox[0].max(glyph.bbox[2]);
2351523517 if gy <= block.top + size * 0.35 {
2351623518 continue;
2351723519 }
23518- let gx0 = glyph.bbox[0].min(glyph.bbox[2]);
23519- let gx1 = glyph.bbox[0].max(glyph.bbox[2]);
2352023520 let overlap = block.right.min(gx1) - block.left.max(gx0);
2352123521 if overlap < size * 0.3 {
2352223522 continue;
@@ -23860,7 +23860,13 @@ fn claim_orphan_scripts(
2386023860 // Each page's equation letters, gathered once. Scanning the whole
2386123861 // document for every small glyph took minutes on a long article.
2386223862 let mut bases: HashMap<u32, Vec<&Glyph>> = HashMap::default();
23863- for base in extraction.glyphs.iter().filter(|base| formula_base(base)) {
23863+ // A base inside a translated line was redrawn as text (`φ` in `在 C 处重写
23864+ // φ`); its source script no longer sits on anything and must be seated.
23865+ for base in extraction
23866+ .glyphs
23867+ .iter()
23868+ .filter(|base| formula_base(base) && !claimed.contains(&base.id))
23869+ {
2386423870 bases.entry(base.page_index).or_default().push(base);
2386523871 }
2386623872 // `10^{−4}`: the seated `−` and the `4` after it are one exponent.
@@ -24004,7 +24010,11 @@ fn seat_orphan_script(
2400424010 && glyph.matrix[4] + size * 0.2 >= right
2400524011 })
2400624012 .max_by(|left, right| glyph_ink_right(left).total_cmp(&glyph_ink_right(right)))?;
24007- if !anchor.unicode.chars().all(|ch| ch.is_ascii_alphanumeric()) {
24013+ // `φ^♭` and `C^S`: a Greek or math-italic base seats a script as well
24014+ // as `10`. Only ASCII bases were tried, so `♭` stayed at its source x
24015+ // on top of `产生`.
24016+ let token_char = |ch: char| ch.is_alphanumeric() && !is_han_char(ch);
24017+ if !anchor.unicode.chars().all(token_char) {
2400824018 return None;
2400924019 }
2401024020 let mut token: Vec<&Glyph> = vec![anchor];
@@ -24022,7 +24032,10 @@ fn seat_orphan_script(
2402224032 break;
2402324033 };
2402424034 let gap = left_edge - glyph_ink_right(prev);
24025- let word = prev.unicode.chars().all(|ch| ch.is_ascii_alphanumeric());
24035+ // `rewrites 𝜑`: an italic math letter does not join the word
24036+ // before it, so the token stays `𝜑`.
24037+ let math = |item: &Glyph| item.unicode.chars().any(|ch| math_plain(ch).is_some());
24038+ let word = prev.unicode.chars().all(token_char) && math(prev) == math(anchor);
2402624039 if !word || gap < -size * 0.1 || gap > size * 0.45 {
2402724040 break;
2402824041 }
@@ -24038,7 +24051,13 @@ fn seat_orphan_script(
2403824051 .iter()
2403924052 .map(|item| glyph_ink_right(item))
2404024053 .fold(f32::MIN, f32::max);
24041- let end = unique_token_end(&line.text, &word)?;
24054+ // The line may draw `𝜑` as the plain `φ` the CJK face covers.
24055+ let plain: String = word
24056+ .chars()
24057+ .map(|ch| math_plain(ch).unwrap_or(ch))
24058+ .collect();
24059+ let end =
24060+ unique_token_end(&line.text, &word).or_else(|| unique_token_end(&line.text, &plain))?;
2404224061 let chars: Vec<char> = line.text.chars().collect();
2404324062 let drawn_right = char_origin(line, &chars, end);
2404424063 let gap = glyph.matrix[4] - source_right;
@@ -24076,6 +24095,12 @@ fn reserve_script_clearance(drawn: &mut [Drawn], seats: &[(usize, usize, f32)])
2407624095 if token_end == 0 || token_end >= chars.len() || item.widths.len() != chars.len() {
2407724096 continue;
2407824097 }
24098+ // `重写 φ♭,… 实现(Γ, C)是`: kept ink already seated in a hole
24099+ // later on the line does not move with the widened gap, so the text
24100+ // after it would slide under `(Γ, C)`. Leave such a line alone.
24101+ if chars[token_end..].contains(&'\u{3000}') {
24102+ continue;
24103+ }
2407924104 let origin = char_origin(item, &chars, token_end);
2408024105 let extra = right - origin;
2408124106 if extra <= 0.4 {
0 commit comments