Honor XeLaTeX page dictionaries and named rectangle coordinates
This commit is contained in:
1 parent
e14361fec6
commit
e20acc3eb9
10 files changed
+403
-71
No files matched your search
@@ -3510,41 +3510,6 @@ fn write_pdf(
|
||||
xdv_names.entry(name.to_vec()).or_insert_with(|| format!("{index:x}").into_bytes());
|
||||
}
|
||||
}
|
||||
let empty_xdv = crate::pdf_device::xdv_navigation::Navigation::default();
|
||||
let xdv_objects = xdv.unwrap_or(&empty_xdv);
|
||||
let mut pending = Vec::new();
|
||||
xdv_objects.collect_references(&mut pending);
|
||||
for (_, annotation) in &xdv_annotations {
|
||||
annotation.collect_references(&mut pending);
|
||||
}
|
||||
let named_objects = xdv_objects.reserve_objects(pending, &mut objects)?;
|
||||
let references = crate::pdf_device::xdv_object::References {
|
||||
pages: &navigation.pages,
|
||||
named: &named_objects,
|
||||
};
|
||||
let compression = pages[0].pdf.as_ref().map_or(0, |pdf| pdf.stream_compression);
|
||||
xdv_objects.write_objects(&references, &mut objects, compression, diagnostics)?;
|
||||
for (id, annotation) in xdv_annotations {
|
||||
objects[id - 1] = annotation.pdf(&references, &xdv_names)?;
|
||||
}
|
||||
if let Some(xdv) = xdv {
|
||||
let open_depth = unicode.unwrap().xdv_outline_open_depth;
|
||||
if let Some(outlines) = xdv.write_outlines(
|
||||
&references, &mut objects, &xdv_names, open_depth,
|
||||
)? {
|
||||
catalog.push_str(&format!(" /Outlines {outlines} 0 R"));
|
||||
}
|
||||
}
|
||||
if !navigation.threads.is_empty() {
|
||||
let mut ids: Vec<_> = navigation.threads.into_values().collect();
|
||||
ids.sort_unstable_by(|left, right| right.cmp(left));
|
||||
let references: Vec<_> = ids.iter().map(|id| format!("{id} 0 R")).collect();
|
||||
let slot = registry.and_then(|registry| registry.thread_array())
|
||||
.map(|number| device_objects[&number] as usize);
|
||||
let id = write_destination(&mut objects, slot, format!("[{}]", references.join(" ")));
|
||||
catalog.push_str(&format!(" /Threads {id} 0 R"));
|
||||
}
|
||||
let destinations = navigation.named;
|
||||
let mut xdv_destinations = BTreeMap::new();
|
||||
for list in pages {
|
||||
for destination in &list.pdf_links.xdv_destinations {
|
||||
@@ -3566,6 +3531,49 @@ fn write_pdf(
|
||||
String::from_utf8_lossy(name)));
|
||||
}
|
||||
}
|
||||
let empty_xdv = crate::pdf_device::xdv_navigation::Navigation::default();
|
||||
let xdv_objects = xdv.unwrap_or(&empty_xdv);
|
||||
let mut pending = Vec::new();
|
||||
xdv_objects.collect_references(&mut pending);
|
||||
for (_, annotation) in &xdv_annotations {
|
||||
annotation.collect_references(&mut pending);
|
||||
}
|
||||
for (&name, (destination, _, _)) in &xdv_destinations {
|
||||
if keep_xdv_destinations || xdv_names.contains_key(name) {
|
||||
destination.collect_references(&mut pending);
|
||||
}
|
||||
}
|
||||
let named_objects = xdv_objects.reserve_objects(pending, &mut objects)?;
|
||||
let references = crate::pdf_device::xdv_object::References {
|
||||
pages: &navigation.pages,
|
||||
named: &named_objects,
|
||||
};
|
||||
let compression = pages[0].pdf.as_ref().map_or(0, |pdf| pdf.stream_compression);
|
||||
xdv_objects.write_objects(&references, &mut objects, compression, diagnostics)?;
|
||||
if let Some(xdv) = xdv {
|
||||
xdv.write_page_dictionaries(pages, &references, &mut objects)?;
|
||||
}
|
||||
for (id, annotation) in xdv_annotations {
|
||||
objects[id - 1] = annotation.pdf(&references, &xdv_names)?;
|
||||
}
|
||||
if let Some(xdv) = xdv {
|
||||
let open_depth = unicode.unwrap().xdv_outline_open_depth;
|
||||
if let Some(outlines) = xdv.write_outlines(
|
||||
&references, &mut objects, &xdv_names, open_depth,
|
||||
)? {
|
||||
catalog.push_str(&format!(" /Outlines {outlines} 0 R"));
|
||||
}
|
||||
}
|
||||
if !navigation.threads.is_empty() {
|
||||
let mut ids: Vec<_> = navigation.threads.into_values().collect();
|
||||
ids.sort_unstable_by(|left, right| right.cmp(left));
|
||||
let references: Vec<_> = ids.iter().map(|id| format!("{id} 0 R")).collect();
|
||||
let slot = registry.and_then(|registry| registry.thread_array())
|
||||
.map(|number| device_objects[&number] as usize);
|
||||
let id = write_destination(&mut objects, slot, format!("[{}]", references.join(" ")));
|
||||
catalog.push_str(&format!(" /Threads {id} 0 R"));
|
||||
}
|
||||
let destinations = navigation.named;
|
||||
let mut retained = BTreeMap::new();
|
||||
for (name, (destination, height, magnification)) in xdv_destinations {
|
||||
let name = if keep_xdv_destinations {
|
||||
@@ -3577,7 +3585,7 @@ fn write_pdf(
|
||||
};
|
||||
let page_object = navigation.pages.get(destination.page - 1)
|
||||
.ok_or_else(|| format!("XDV destination refers to nonexistent page {}", destination.page))?;
|
||||
retained.insert(name, destination.array(*page_object, height, magnification));
|
||||
retained.insert(name, destination.array(*page_object, height, magnification, &references)?);
|
||||
}
|
||||
if !retained.is_empty() {
|
||||
let entries: Vec<_> = retained.into_iter().map(|(name, value)| {
|
||||
|
||||
Reference in new issue
Block a user