Ship XDV document views and PDF outline navigation
This commit is contained in:
1 parent
8be7867b37
commit
515dbe6181
13 files changed
+743
-111
No files matched your search
@@ -461,7 +461,17 @@ impl Executor {
|
||||
shipout.xdv_color_steps.insert(graphics_step, program);
|
||||
}
|
||||
None
|
||||
} else if xdv && self.xdv_destination_special(&special, point, &mut shipout.pdf_links)? {
|
||||
} else if xdv && self.xdv_page_special(
|
||||
&special,
|
||||
crate::pdf_device::xdv_object::Position {
|
||||
page: self.shipped_pages + 1,
|
||||
coordinates: point,
|
||||
height: device.page_height,
|
||||
magnification: device.magnification,
|
||||
},
|
||||
&mut shipout.pdf_links,
|
||||
files,
|
||||
)? {
|
||||
None
|
||||
} else if xdv && let Some(image) = crate::pdf_device::xdv_image::ImageSpecial::parse(
|
||||
&special.bytes, device.magnification,
|
||||
|
||||
@@ -49,17 +49,18 @@ impl Executor {
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn xdv_destination_special(
|
||||
pub(super) fn xdv_page_special(
|
||||
&mut self,
|
||||
special: &ShipoutSpecial,
|
||||
point: [i64; 2],
|
||||
position: crate::pdf_device::xdv_object::Position,
|
||||
links: &mut crate::pdf_device::links::PageLinks,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<bool, Error> {
|
||||
use crate::pdf_device::xdv_destination::Destination;
|
||||
let data = special.bytes.trim_ascii_start();
|
||||
if let Some(body) = data.strip_prefix(b"pdf:").map(<[u8]>::trim_ascii_start) {
|
||||
if let Some(operands) = xdv_operand(body, b"dest").or_else(|| xdv_operand(body, b"destination")) {
|
||||
let destination = Destination::parse(operands, self.shipped_pages + 1, point)
|
||||
let destination = Destination::parse(operands, position.page, position.coordinates)
|
||||
.map_err(|error| self.error(error, special.span))?;
|
||||
links.xdv_destinations.push(destination);
|
||||
return Ok(true);
|
||||
@@ -73,6 +74,22 @@ impl Executor {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
let catalog = xdv_operand(body, b"docview");
|
||||
let outline = xdv_operand(body, b"outline").or_else(|| xdv_operand(body, b"out"));
|
||||
if let Some(operands) = catalog.or(outline) {
|
||||
self.reads.insert(Dependency::PdfCatalogState);
|
||||
let navigation = Arc::make_mut(self.state.xdv_navigation.get_or_insert_with(Default::default));
|
||||
let warnings = if catalog.is_some() {
|
||||
navigation.merge_catalog(operands, position, self.limits.tokens)
|
||||
} else {
|
||||
navigation.add_outline(operands, position, self.limits.tokens)
|
||||
}.map_err(|error| self.error(error, special.span))?;
|
||||
for warning in warnings {
|
||||
files.observe_diagnostic(WriteDestination::TerminalAndLog, &warning)
|
||||
.map_err(|error| self.error(error, special.span))?;
|
||||
}
|
||||
return Ok(true);
|
||||
}
|
||||
} else if let Some(body) = data.strip_prefix(b"dvipdfmx:").map(<[u8]>::trim_ascii_start)
|
||||
&& let Some(operands) = xdv_operand(body, b"config")
|
||||
{
|
||||
|
||||
@@ -751,6 +751,8 @@ pub struct State {
|
||||
#[serde(default, skip_serializing_if = "crate::pdf_device::xdv_destination::Setup::is_default")]
|
||||
pub(super) xdv_setup: crate::pdf_device::xdv_destination::Setup,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(super) xdv_navigation: Option<std::sync::Arc<crate::pdf_device::xdv_navigation::Navigation>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(super) pdf_catalog: Option<Box<crate::pdf_device::catalog::PdfCatalog>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(super) pdf_objects: Option<Box<crate::pdf_device::page_resources::PdfObjects>>,
|
||||
@@ -949,6 +951,7 @@ impl Default for State {
|
||||
output_mode_set: None,
|
||||
pdf_file_options: None,
|
||||
xdv_setup: Default::default(),
|
||||
xdv_navigation: None,
|
||||
pdf_catalog: None,
|
||||
pdf_objects: None,
|
||||
initial_random_seed: None,
|
||||
@@ -1587,6 +1590,7 @@ impl State {
|
||||
self.output_mode_set = None;
|
||||
self.pdf_file_options = None;
|
||||
self.xdv_setup = Default::default();
|
||||
self.xdv_navigation = None;
|
||||
self.pdf_catalog = None;
|
||||
if !self
|
||||
.pdf_objects
|
||||
@@ -1639,6 +1643,8 @@ impl State {
|
||||
fonts: &self.fonts,
|
||||
page_tree_attributes: &self.pdf_pages_attributes,
|
||||
xdv_keep_destinations: self.xdv_setup.keep_destinations,
|
||||
xdv_outline_open_depth: self.xdv_setup.outline_open_depth.unwrap_or_default(),
|
||||
xdv_navigation: self.xdv_navigation.as_deref(),
|
||||
catalog: self.pdf_catalog.as_deref(),
|
||||
objects: self.pdf_objects.as_deref(),
|
||||
info: crate::pdf_device::PdfInfo {
|
||||
|
||||
Reference in new issue
Block a user