mirror of
https://github.com/typst/typst
synced 2025-05-18 02:55:28 +08:00
Sort frame items by logical index
This commit is contained in:
parent
fa76ea6310
commit
7e69ee0942
@ -501,16 +501,16 @@ pub fn commit(
|
|||||||
|
|
||||||
// Build the frames and determine the height and baseline.
|
// Build the frames and determine the height and baseline.
|
||||||
let mut frames = vec![];
|
let mut frames = vec![];
|
||||||
for item in line.items.iter() {
|
for item in line.items.indexed_iter() {
|
||||||
let mut push = |offset: &mut Abs, frame: Frame| {
|
let mut push = |offset: &mut Abs, frame: Frame, idx: usize| {
|
||||||
let width = frame.width();
|
let width = frame.width();
|
||||||
top.set_max(frame.baseline());
|
top.set_max(frame.baseline());
|
||||||
bottom.set_max(frame.size().y - frame.baseline());
|
bottom.set_max(frame.size().y - frame.baseline());
|
||||||
frames.push((*offset, frame));
|
frames.push((*offset, frame, idx));
|
||||||
*offset += width;
|
*offset += width;
|
||||||
};
|
};
|
||||||
|
|
||||||
match item {
|
match &*item.item {
|
||||||
Item::Absolute(v, _) => {
|
Item::Absolute(v, _) => {
|
||||||
offset += *v;
|
offset += *v;
|
||||||
}
|
}
|
||||||
@ -522,7 +522,7 @@ pub fn commit(
|
|||||||
layout_box(elem, engine, loc.relayout(), styles, region)
|
layout_box(elem, engine, loc.relayout(), styles, region)
|
||||||
})?;
|
})?;
|
||||||
apply_baseline_shift(&mut frame, *styles);
|
apply_baseline_shift(&mut frame, *styles);
|
||||||
push(&mut offset, frame);
|
push(&mut offset, frame, item.idx);
|
||||||
} else {
|
} else {
|
||||||
offset += amount;
|
offset += amount;
|
||||||
}
|
}
|
||||||
@ -534,15 +534,15 @@ pub fn commit(
|
|||||||
justification_ratio,
|
justification_ratio,
|
||||||
extra_justification,
|
extra_justification,
|
||||||
);
|
);
|
||||||
push(&mut offset, frame);
|
push(&mut offset, frame, item.idx);
|
||||||
}
|
}
|
||||||
Item::Frame(frame) => {
|
Item::Frame(frame) => {
|
||||||
push(&mut offset, frame.clone());
|
push(&mut offset, frame.clone(), item.idx);
|
||||||
}
|
}
|
||||||
Item::Tag(tag) => {
|
Item::Tag(tag) => {
|
||||||
let mut frame = Frame::soft(Size::zero());
|
let mut frame = Frame::soft(Size::zero());
|
||||||
frame.push(Point::zero(), FrameItem::Tag((*tag).clone()));
|
frame.push(Point::zero(), FrameItem::Tag((*tag).clone()));
|
||||||
frames.push((offset, frame));
|
frames.push((offset, frame, item.idx));
|
||||||
}
|
}
|
||||||
Item::Skip(_) => {}
|
Item::Skip(_) => {}
|
||||||
}
|
}
|
||||||
@ -561,8 +561,9 @@ pub fn commit(
|
|||||||
add_par_line_marker(&mut output, marker, engine, locator, top);
|
add_par_line_marker(&mut output, marker, engine, locator, top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frames.sort_by_key(|(_, _, idx)| *idx);
|
||||||
// Construct the line's frame.
|
// Construct the line's frame.
|
||||||
for (offset, frame) in frames {
|
for (offset, frame, _) in frames {
|
||||||
let x = offset + p.config.align.position(remaining);
|
let x = offset + p.config.align.position(remaining);
|
||||||
let y = top - frame.baseline();
|
let y = top - frame.baseline();
|
||||||
output.push_frame(Point::new(x, y), frame);
|
output.push_frame(Point::new(x, y), frame);
|
||||||
@ -647,6 +648,11 @@ impl<'a> Items<'a> {
|
|||||||
self.0.iter().map(|item| &*item.item)
|
self.0.iter().map(|item| &*item.item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterate over the items with indices
|
||||||
|
pub fn indexed_iter(&self) -> impl Iterator<Item = &IndexedItemEntry<'a>> {
|
||||||
|
self.0.iter()
|
||||||
|
}
|
||||||
|
|
||||||
/// Access the first item.
|
/// Access the first item.
|
||||||
pub fn first(&self) -> Option<&Item<'a>> {
|
pub fn first(&self) -> Option<&Item<'a>> {
|
||||||
self.0.first().map(|item| &*item.item)
|
self.0.first().map(|item| &*item.item)
|
||||||
|
BIN
tests/ref/issue-5775-cite-order-rtl.png
Normal file
BIN
tests/ref/issue-5775-cite-order-rtl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.0 KiB |
Loading…
x
Reference in New Issue
Block a user