@@ -360,6 +360,23 @@ fn rewrite_translation_once(
360360 }
361361 keep.insert(*id, reason.clone());
362362 }
363+ // Marks with no text (`●` in wasy) that no segment carries. They stay on
364+ // the source line, so a sentence reflowed over them paints through them.
365+ let in_segments: HashSet<u32> = report
366+ .segments
367+ .iter()
368+ .flat_map(|segment| segment.glyph_ids.iter().copied())
369+ .collect();
370+ let unmapped_marks: Vec<&Glyph> = extraction
371+ .glyphs
372+ .iter()
373+ .filter(|glyph| {
374+ glyph.unicode.trim().is_empty()
375+ && !glyph.invisible
376+ && !in_segments.contains(&glyph.id)
377+ && !glyph.font_name.to_ascii_uppercase().contains("CMEX")
378+ })
379+ .collect();
363380 let mut symbol_shards: HashSet<u32> = HashSet::default();
364381 let mut formula_leads: HashSet<u32> = HashSet::default();
365382 for (index, segment) in report.segments.iter().enumerate() {
@@ -465,7 +482,8 @@ fn rewrite_translation_once(
465482 // A display line inside a paragraph stays in the source glyphs. An
466483 // inline formula the holes did not cover keeps that sentence too.
467484 let display_ids = display_equation_line_ids(&segment_glyphs);
468- let unholed_ids = unholed_formula_line_ids(&segment_glyphs, &display_ids);
485+ let mut unholed_ids = unholed_formula_line_ids(&segment_glyphs, &display_ids);
486+ unholed_ids.extend(unmapped_mark_line_ids(&segment_glyphs, &display_ids, &unmapped_marks));
469487 if !unholed_ids.is_empty() {
470488 // Inline math the holes missed. Drawing the flattened sentence
471489 // paints Chinese through the source glyphs. Keep the line.
@@ -10780,14 +10798,14 @@ fn unholed_formula_line_ids(glyphs: &[&Glyph], display: &HashSet<u32>) -> HashSe
1078010798 // `for 𝑛 ≥ 1000, it is 1.6–3.5× slower … at 𝑛 = 10^4`: plain
1078110799 // relations and `×` are drawn as text in the translation. They are
1078210800 // not a formula the holes missed, and counting them kept the whole
10783- // Results paragraph in English.
10801+ // Results paragraph in English. Brackets are not operators either:
10802+ // `table p(x̄) [window a b] := add {θ}` is a sentence about code.
1078410803 let operators = loose
1078510804 .iter()
1078610805 .filter(|glyph| {
10787- !glyph
10788- .unicode
10789- .chars()
10790- .all(|ch| matches!(ch, '≥' | '≤' | '×'))
10806+ !glyph.unicode.chars().all(|ch| {
10807+ matches!(ch, '≥' | '≤' | '×' | '(' | ')' | '[' | ']' | '{' | '}')
10808+ })
1079110809 })
1079210810 .count();
1079310811 let equals = loose.iter().any(|glyph| glyph.unicode.contains('='))
@@ -10808,6 +10826,33 @@ fn unholed_formula_line_ids(glyphs: &[&Glyph], display: &HashSet<u32>) -> HashSe
1080810826 ids
1080910827}
1081010828
10829+ /// Lines of a sentence that pass over a textless mark no segment carries
10830+ /// (`●_{[a,b]} φ`). The mark stays where it is, so the line keeps its source.
10831+ fn unmapped_mark_line_ids(
10832+ glyphs: &[&Glyph],
10833+ display: &HashSet<u32>,
10834+ marks: &[&Glyph],
10835+ ) -> HashSet<u32> {
10836+ let mut ids = HashSet::default();
10837+ for mark in marks {
10838+ let line: Vec<&&Glyph> = glyphs
10839+ .iter()
10840+ .filter(|glyph| {
10841+ glyph.page_index == mark.page_index
10842+ && !display.contains(&glyph.id)
10843+ && (glyph.matrix[5] - mark.matrix[5]).abs() <= glyph.font_size.max(1.0) * 0.45
10844+ })
10845+ .collect();
10846+ let left = line.iter().map(|g| g.bbox[0].min(g.bbox[2])).fold(f32::MAX, f32::min);
10847+ let right = line.iter().map(|g| g.bbox[0].max(g.bbox[2])).fold(f32::MIN, f32::max);
10848+ let mid = (mark.bbox[0] + mark.bbox[2]) * 0.5;
10849+ if line.len() >= 2 && mid > left && mid < right {
10850+ ids.extend(line.iter().map(|g| g.id));
10851+ }
10852+ }
10853+ ids
10854+ }
10855+
1081110856/// A script hole that left `(m)` or `t,i` beside it. The base-plus-script
1081210857/// cannot be seated, so the sentence keeps its source line.
1081310858fn formula_script_near_hole(
0 commit comments