Skip to content

A fast, helpful, and open-source document parser

Merge branch 'main' into logan/layout-markdown-fixes

Logan9d6274458503
diff --cc crates/liteparse/src/extract.rs
index dbbd18b,2b06483..5f74865
--- a/crates/liteparse/src/extract.rs
+++ b/crates/liteparse/src/extract.rs
@@@ -3368,12 -3283,9 +3411,15 @@@ struct SegmentBuilder
emit_words: bool,
// When false, source-code/trailing-space metadata is not accumulated.
extract_text_metadata: bool,
+ // Set on a run split off at a size step into smaller raised / lowered type: the host
+ // segment's (top, bottom), which the item takes as its band (see `TextItem::script_geom`).
+ host_band: Option<(f32, f32)>,
+ // The last run that took a host band: (top, bottom, right edge), so a later small-type
+ // segment continuing it ("LC" "50" ... "(mg/L)", other cells drawn in between) takes it too.
+ last_script: Option<(f32, f32, f32)>,
+ // Right-to-left letters of the segment as (byte end in `text`, loose left, loose right), so
+ // a combining mark drawn over an earlier letter can be placed after it (see `push_char`).
+ rtl_spans: Vec<(usize, f32, f32)>,
}
impl SegmentBuilder {
@@@ -3421,8 -3333,7 +3467,9 @@@
word_has: false,
emit_words,
extract_text_metadata,
+ host_band: None,
+ last_script: None,
+ rtl_spans: Vec::new(),
}
}
@@@ -3538,28 -3449,13 +3585,33 @@@
page_rotation: i32,
meta: &ObjTextMeta,
) {
+ // a run in smaller raised / lowered type keeps its host's band past a space or other
+ // break while it stays in that type on that line; full-size type ends it
+ let small_inside = |top: f32, bottom: f32| {
+ // line-box (loose) heights on both sides: a full-size `(` has less ink than the
+ // host's box, but the same box
+ let mid = (vp_loose.top + vp_loose.bottom) * 0.5;
+ mid > top
+ && mid < bottom
+ && (vp_loose.bottom - vp_loose.top).abs() < 0.85 * (bottom - top).abs()
+ };
+ self.host_band = self
+ .host_band
+ .filter(|&(top, bottom)| small_inside(top, bottom))
+ .or_else(|| {
+ self.last_script.and_then(|(top, bottom, right)| {
+ let near = vp_loose.left >= right - 1.0
+ && vp_loose.left - right < 2.0 * (bottom - top).abs();
+ (near && small_inside(top, bottom)).then_some((top, bottom))
+ })
+ });
self.text.clear();
self.text.push(c);
+ self.rtl_spans.clear();
+ if crate::bidi::is_rtl_char(c) {
+ self.rtl_spans
+ .push((self.text.len(), vp_loose.left, vp_loose.right));
+ }
self.vp_left = vp_loose.left;
self.vp_right = vp_loose.right;
self.vp_top = vp_loose.top;