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 struct Run<'a> {
|
||||||
pub item: Item<'a>,
|
pub item: Item<'a>,
|
||||||
pub range: Range,
|
pub range: Range,
|
||||||
|
pub idx: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A representation in which children are already layouted and text is already
|
/// 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 cursor = 0;
|
||||||
let mut items = Vec::with_capacity(segments.len());
|
let mut items = Vec::with_capacity(segments.len());
|
||||||
|
let mut next_idx = 0;
|
||||||
|
|
||||||
// Shape the text to finalize the items.
|
// Shape the text to finalize the items.
|
||||||
for segment in segments {
|
for segment in segments {
|
||||||
@ -88,9 +90,20 @@ pub fn prepare<'a>(
|
|||||||
|
|
||||||
match segment {
|
match segment {
|
||||||
Segment::Text(_, styles) => {
|
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;
|
cursor = end;
|
||||||
@ -105,6 +118,7 @@ pub fn prepare<'a>(
|
|||||||
if config.cjk_latin_spacing {
|
if config.cjk_latin_spacing {
|
||||||
add_cjk_latin_spacing(&mut items);
|
add_cjk_latin_spacing(&mut items);
|
||||||
}
|
}
|
||||||
|
dbg!(&items);
|
||||||
|
|
||||||
Ok(Preparation {
|
Ok(Preparation {
|
||||||
config,
|
config,
|
||||||
|
@ -599,6 +599,7 @@ pub fn shape_range<'a>(
|
|||||||
bidi: &BidiInfo<'a>,
|
bidi: &BidiInfo<'a>,
|
||||||
range: Range,
|
range: Range,
|
||||||
styles: StyleChain<'a>,
|
styles: StyleChain<'a>,
|
||||||
|
next_idx: &mut usize,
|
||||||
) {
|
) {
|
||||||
let script = TextElem::script_in(styles);
|
let script = TextElem::script_in(styles);
|
||||||
let lang = TextElem::lang_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 dir = if level.is_ltr() { Dir::LTR } else { Dir::RTL };
|
||||||
let shaped =
|
let shaped =
|
||||||
shape(engine, range.start, &text[range.clone()], styles, dir, lang, region);
|
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();
|
let mut prev_level = BidiLevel::ltr();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user