summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorY.D.X <73375426+YDX-2147483647@users.noreply.github.com>2024-02-20 21:15:42 +0800
committerGitHub <noreply@github.com>2024-02-20 13:15:42 +0000
commit72d324c5b4493ded209c62a8e0049dc570d9566c (patch)
tree6538f8e6d747e114a265c073e717711b3daf669e
parentee2128d115f640a72f658540262e1028038a9381 (diff)
`/Last` in PDF should refer to the last _immediate_ children (#3447)
-rw-r--r--crates/typst-pdf/src/outline.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/crates/typst-pdf/src/outline.rs b/crates/typst-pdf/src/outline.rs
index 23893873..adb0df2f 100644
--- a/crates/typst-pdf/src/outline.rs
+++ b/crates/typst-pdf/src/outline.rs
@@ -97,7 +97,9 @@ pub(crate) fn write_outline(ctx: &mut PdfContext) -> Option<Ref> {
ctx.pdf
.outline(root_id)
.first(start_ref)
- .last(Ref::new(ctx.alloc.get() - 1))
+ .last(Ref::new(
+ ctx.alloc.get() - tree.last().map(|child| child.len() as i32).unwrap_or(1),
+ ))
.count(tree.len() as i32);
Some(root_id)
@@ -152,10 +154,9 @@ fn write_outline_item(
outline.prev(prev_rev);
}
- if !node.children.is_empty() {
- let current_child = Ref::new(id.get() + 1);
- outline.first(current_child);
- outline.last(Ref::new(next_ref.get() - 1));
+ if let Some(last_immediate_child) = node.children.last() {
+ outline.first(Ref::new(id.get() + 1));
+ outline.last(Ref::new(next_ref.get() - last_immediate_child.len() as i32));
outline.count(-(node.children.len() as i32));
}