mirror of
https://github.com/typst/typst
synced 2025-05-17 02:25:27 +08:00
Add idx
field to Run
This commit is contained in:
parent
58b4bdb811
commit
662bccc42d
@ -7,6 +7,7 @@ use super::*;
|
||||
pub struct Run<'a> {
|
||||
pub item: Item<'a>,
|
||||
pub range: Range,
|
||||
pub idx: usize,
|
||||
}
|
||||
|
||||
/// A representation in which children are already layouted and text is already
|
||||
@ -79,6 +80,7 @@ pub fn prepare<'a>(
|
||||
|
||||
let mut cursor = 0;
|
||||
let mut items = Vec::with_capacity(segments.len());
|
||||
let mut next_idx = 0;
|
||||
|
||||
// Shape the text to finalize the items.
|
||||
for segment in segments {
|
||||
@ -88,9 +90,20 @@ pub fn prepare<'a>(
|
||||
|
||||
match segment {
|
||||
Segment::Text(_, styles) => {
|
||||
shape_range(&mut items, engine, text, &bidi, range, styles);
|
||||
shape_range(
|
||||
&mut items,
|
||||
engine,
|
||||
text,
|
||||
&bidi,
|
||||
range,
|
||||
styles,
|
||||
&mut next_idx,
|
||||
);
|
||||
}
|
||||
Segment::Item(item) => {
|
||||
items.push(Run { range, item, idx: next_idx });
|
||||
next_idx += 1;
|
||||
}
|
||||
Segment::Item(item) => items.push(Run { range, item }),
|
||||
}
|
||||
|
||||
cursor = end;
|
||||
@ -105,6 +118,7 @@ pub fn prepare<'a>(
|
||||
if config.cjk_latin_spacing {
|
||||
add_cjk_latin_spacing(&mut items);
|
||||
}
|
||||
dbg!(&items);
|
||||
|
||||
Ok(Preparation {
|
||||
config,
|
||||
|
@ -599,6 +599,7 @@ pub fn shape_range<'a>(
|
||||
bidi: &BidiInfo<'a>,
|
||||
range: Range,
|
||||
styles: StyleChain<'a>,
|
||||
next_idx: &mut usize,
|
||||
) {
|
||||
let script = TextElem::script_in(styles);
|
||||
let lang = TextElem::lang_in(styles);
|
||||
@ -607,7 +608,8 @@ pub fn shape_range<'a>(
|
||||
let dir = if level.is_ltr() { Dir::LTR } else { Dir::RTL };
|
||||
let shaped =
|
||||
shape(engine, range.start, &text[range.clone()], styles, dir, lang, region);
|
||||
items.push(Run { range, item: Item::Text(shaped) });
|
||||
items.push(Run { range, item: Item::Text(shaped), idx: *next_idx });
|
||||
*next_idx += 1;
|
||||
};
|
||||
|
||||
let mut prev_level = BidiLevel::ltr();
|
||||
|
Loading…
x
Reference in New Issue
Block a user