/Last in PDF should refer to the last _immediate_ children (#3447)

This commit is contained in:
Y.D.X 2024-02-20 21:15:42 +08:00 committed by GitHub
parent ee2128d115
commit 72d324c5b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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));
}