Order native PDF link continuations with shipout effects
This commit is contained in:
1 parent
e95d1264da
commit
af19a26c23
5 files changed
+274
-140
No files matched your search
@@ -39,6 +39,7 @@ pub(super) struct PdfSpaceProbe {
|
||||
|
||||
struct ShipoutFontUse {
|
||||
before_output: usize,
|
||||
before_paint: usize,
|
||||
font: Arc<NativeFont>,
|
||||
slot: u8,
|
||||
}
|
||||
@@ -48,11 +49,11 @@ fn shipout_font_uses(
|
||||
) -> Result<Vec<ShipoutFontUse>, String> {
|
||||
let mut uses = Vec::new();
|
||||
let mut seen = BTreeSet::new();
|
||||
b.visit_shipout_font_uses(|before_output, font, slot| {
|
||||
b.visit_shipout_font_uses(|before_output, before_paint, font, slot| {
|
||||
if (!programs.is_known_physical(font.id) || fonts.automatic_origin(font.id).is_some())
|
||||
&& seen.insert((font.id, slot))
|
||||
{
|
||||
uses.push(ShipoutFontUse { before_output, font: font.clone(), slot });
|
||||
uses.push(ShipoutFontUse { before_output, before_paint, font: font.clone(), slot });
|
||||
}
|
||||
})?;
|
||||
Ok(uses)
|
||||
@@ -455,9 +456,10 @@ impl Executor {
|
||||
if let Some(effects) = &leader_effects {
|
||||
outputs = effects.outputs.iter().collect();
|
||||
}
|
||||
let mut navigation_numbers = (Vec::new(), Vec::new());
|
||||
let mut link_depth = self.pdf_link_stack.len();
|
||||
let has_link_material = link_depth != 0 || outputs.iter().any(|node| node.is_pdf_link());
|
||||
let output_count = outputs.len();
|
||||
let has_link_material = !self.pdf_link_stack.is_empty() || outputs.iter().any(|node| node.is_pdf_link());
|
||||
let mut pdf_link_shipout = (has_link_material && !for_form && device.pdf.is_some())
|
||||
.then(|| self.begin_pdf_link_shipout(b, device));
|
||||
let mut output_positions = if let Some(effects) = &leader_effects {
|
||||
effects.output_positions.clone().into_iter()
|
||||
} else if outputs.iter().any(|node| node.needs_shipout_position()) {
|
||||
@@ -483,12 +485,17 @@ impl Executor {
|
||||
let mut reopened_images = false;
|
||||
let mut xdv_paper_specials = Vec::new();
|
||||
let mut xdv_navigation = Vec::new();
|
||||
for (index, output) in outputs.into_iter().enumerate() {
|
||||
for (index, output) in outputs.iter().copied().enumerate() {
|
||||
while font_uses.peek().is_some_and(|usage| usage.before_output == index) {
|
||||
let usage = font_uses.next().unwrap();
|
||||
if let Some(layout) = &mut pdf_link_shipout {
|
||||
layout.advance(self, (index, usage.before_paint), &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
}
|
||||
self.current = current;
|
||||
self.prepare_virtual_glyph(
|
||||
shipout.virtual_glyphs.as_mut().unwrap(), font_uses.next().unwrap(), files,
|
||||
)?;
|
||||
self.prepare_virtual_glyph(shipout.virtual_glyphs.as_mut().unwrap(), usage, files)?;
|
||||
}
|
||||
if let Some(layout) = &mut pdf_link_shipout {
|
||||
layout.advance(self, (index, usize::MAX), &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
}
|
||||
if self.pdf_loaded_space_font.is_none()
|
||||
&& (uses_automatic_spaces || has_explicit_space)
|
||||
@@ -665,32 +672,12 @@ impl Executor {
|
||||
} else {
|
||||
has_explicit_space = true;
|
||||
}
|
||||
} else if let OutputOperation::PdfLink(link) = &output.operation {
|
||||
use crate::pdf_device::links::LinkNode;
|
||||
} else if let OutputOperation::PdfLink(_) = &output.operation {
|
||||
self.current = output.span;
|
||||
self.tick()?;
|
||||
if device.pdf.is_none() {
|
||||
return self.fail("cannot ship a PDF link operation to DVI");
|
||||
}
|
||||
match link {
|
||||
LinkNode::Start(_) if link_depth == 10 => {
|
||||
return self.fail("PDF link stack capacity exceeded");
|
||||
}
|
||||
LinkNode::Start(layout) => {
|
||||
link_depth += 1;
|
||||
if !unicode_pages && !for_form {
|
||||
navigation_numbers.0.push(self.register_pdf_link(layout.object_number)?);
|
||||
}
|
||||
}
|
||||
LinkNode::End if link_depth == 0 => {
|
||||
return self.fail("\\pdfendlink used without \\pdfstartlink");
|
||||
}
|
||||
LinkNode::End => link_depth -= 1,
|
||||
LinkNode::Destination { destination, structure, .. } if !unicode_pages && !for_form => {
|
||||
navigation_numbers.1.push(self.register_pdf_destination(destination, structure.is_some())?);
|
||||
}
|
||||
LinkNode::Running(_) | LinkNode::Destination { .. } => {}
|
||||
}
|
||||
} else {
|
||||
if let OutputOperation::PdfImage { image, .. } = &output.operation {
|
||||
reopened_images |= image.xdv.is_some() && image.image.is_metadata_only();
|
||||
@@ -714,9 +701,20 @@ impl Executor {
|
||||
));
|
||||
}
|
||||
self.current = current;
|
||||
if has_link_material && for_form {
|
||||
return self.fail("PDF page links and destinations require a page shipout");
|
||||
}
|
||||
for usage in font_uses {
|
||||
if let Some(layout) = &mut pdf_link_shipout {
|
||||
layout.advance(self, (output_count, usage.before_paint), &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
}
|
||||
self.prepare_virtual_glyph(shipout.virtual_glyphs.as_mut().unwrap(), usage, files)?;
|
||||
}
|
||||
if let Some(layout) = pdf_link_shipout {
|
||||
let mut links = layout.finish(self, &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
links.xdv_destinations = std::mem::take(&mut shipout.pdf_links.xdv_destinations);
|
||||
shipout.pdf_links = links;
|
||||
}
|
||||
shipout.pdf_font_bindings = self.pdf_virtual_fonts.captured_font_bindings();
|
||||
let has_space_settings = has_space_nodes || automatic_spaces_at_start;
|
||||
let probed_page = (uses_automatic_spaces || has_explicit_space)
|
||||
@@ -730,16 +728,6 @@ impl Executor {
|
||||
shipout.pdf_text_spaces.as_mut().unwrap().dedicated_font =
|
||||
self.pdf_loaded_space_font.clone();
|
||||
}
|
||||
if has_link_material {
|
||||
if for_form {
|
||||
return self.fail("PDF page links and destinations require a page shipout");
|
||||
}
|
||||
let mut links = self.ship_pdf_link_material(
|
||||
b, device, &shipout.pdf_graphics_steps, navigation_numbers, files,
|
||||
)?;
|
||||
links.xdv_destinations = std::mem::take(&mut shipout.pdf_links.xdv_destinations);
|
||||
shipout.pdf_links = links;
|
||||
}
|
||||
if let Some(objects) = &mut shipout.pdf_objects {
|
||||
let limit = self.limits.tokens;
|
||||
let compression = device.pdf.as_ref().unwrap().file.object_compression;
|
||||
|
||||
Reference in new issue
Block a user