Ship XDV annotations from measured page ranges
This commit is contained in:
1 parent
515dbe6181
commit
20986b2fd5
16 files changed
+873
-54
No files matched your search
@@ -2295,6 +2295,7 @@ fn write_pdf(
|
||||
let mut kids = Vec::new();
|
||||
let mut navigation = PdfNavigation::default();
|
||||
let mut annotation_actions = Vec::new();
|
||||
let mut xdv_annotations = Vec::new();
|
||||
let pdf_version = pages
|
||||
.first()
|
||||
.and_then(|page| page.pdf.as_ref())
|
||||
@@ -2453,8 +2454,10 @@ fn write_pdf(
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let xdv_annotation_ids = next_annotation..next_annotation + list.pdf_links.xdv_annotations.len();
|
||||
let annotation_refs = (annotation_base..native_annotation_base)
|
||||
.chain(native_annotation_ids.iter().copied())
|
||||
.chain(xdv_annotation_ids.clone())
|
||||
.map(|id| format!("{id} 0 R"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
@@ -2590,6 +2593,11 @@ fn write_pdf(
|
||||
objects[id - 1] = body;
|
||||
}
|
||||
}
|
||||
for (id, annotation) in xdv_annotation_ids.zip(&list.pdf_links.xdv_annotations) {
|
||||
debug_assert_eq!(id, objects.len() + 1);
|
||||
xdv_annotations.push((id, annotation));
|
||||
objects.push(Vec::new());
|
||||
}
|
||||
for destination in &list.pdf_links.destinations {
|
||||
use crate::pdf_device::links::DestinationView;
|
||||
let x = physical(destination.point[0]);
|
||||
@@ -2755,15 +2763,26 @@ fn write_pdf(
|
||||
let xdv = unicode.and_then(|options| options.xdv_navigation);
|
||||
let keep_xdv_destinations = unicode.is_some_and(|options| options.xdv_keep_destinations);
|
||||
let mut xdv_names = BTreeMap::new();
|
||||
if !keep_xdv_destinations {
|
||||
let mut references: Vec<_> = xdv.into_iter().flat_map(|view| view.named_references())
|
||||
.chain(xdv_annotations.iter().filter_map(|(_, annotation)| annotation.named_reference()))
|
||||
.collect();
|
||||
references.sort_unstable_by_key(|(order, _)| *order);
|
||||
for (_, name) in references {
|
||||
let index = xdv_names.len();
|
||||
xdv_names.entry(name.to_vec()).or_insert_with(|| format!("{index:x}").into_bytes());
|
||||
}
|
||||
}
|
||||
for (id, annotation) in xdv_annotations {
|
||||
objects[id - 1] = annotation.pdf(&navigation.pages, &xdv_names)?;
|
||||
}
|
||||
if let Some(xdv) = xdv {
|
||||
let open_depth = unicode.unwrap().xdv_outline_open_depth;
|
||||
let (outlines, names) = xdv.write_outlines(
|
||||
&navigation.pages, &mut objects, keep_xdv_destinations, open_depth,
|
||||
)?;
|
||||
if let Some(outlines) = outlines {
|
||||
if let Some(outlines) = xdv.write_outlines(
|
||||
&navigation.pages, &mut objects, &xdv_names, open_depth,
|
||||
)? {
|
||||
catalog.push_str(&format!(" /Outlines {outlines} 0 R"));
|
||||
}
|
||||
xdv_names = names;
|
||||
}
|
||||
if !navigation.threads.is_empty() {
|
||||
let mut ids: Vec<_> = navigation.threads.into_values().collect();
|
||||
|
||||
Reference in new issue
Block a user