From 47d65db168776ac77c30fe8a6b0a214c2f857ddd Mon Sep 17 00:00:00 2001 From: Markus Wanner Date: Tue, 24 Jan 2023 00:24:42 +0100 Subject: [PATCH] Fix issue #164: adjust example names to dump array based reference --- pdf/examples/names.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pdf/examples/names.rs b/pdf/examples/names.rs index 4a8dbad8..221dfff1 100644 --- a/pdf/examples/names.rs +++ b/pdf/examples/names.rs @@ -5,7 +5,7 @@ use std::fmt; use std::collections::HashMap; use pdf::file::File; use pdf::object::*; -use pdf::primitive::PdfString; +use pdf::primitive::{Primitive, PdfString}; struct Indent(usize); impl fmt::Display for Indent { @@ -24,9 +24,21 @@ fn walk_outline(r: &impl Resolve, mut node: RcRef, name_map: &impl println!("{}title: {:?}", indent, title.to_string_lossy()); } if let Some(ref dest) = node.dest { - let name = dest.to_string_lossy().unwrap(); - let page_nr = name_map(&name); - println!("{}dest: {:?} -> page nr. {:?}", indent, name, page_nr); + match dest { + Primitive::String(ref s) => { + let name = s.to_string_lossy().unwrap(); + let page_nr = name_map(&name); + println!("{}dest: {:?} -> page nr. {:?}", indent, name, page_nr); + } + Primitive::Array(ref a) => match a[0] { + Primitive::Reference(r) => { + let page_nr = page_map(r); + println!("{}dest: {:?} -> page nr. {:?}", indent, a, page_nr); + } + _ => unimplemented!("invalid reference in array"), + } + _ => unimplemented!("invalid dest"), + } } if let Some(Action::Goto(MaybeNamedDest::Direct(Dest { page: Some(page), ..}))) = node.action { let page_nr = page_map(page.get_inner());