Discard duplicate destinations during native PDF execution
This commit is contained in:
1 parent
ba548ef05d
commit
0e71c15b01
9 files changed
+152
-7
No files matched your search
@@ -217,6 +217,7 @@ impl Executor {
|
||||
};
|
||||
DestinationView::Xyz(zoom)
|
||||
} else if self.keyword("fitr", files)? {
|
||||
self.optional_space(files)?;
|
||||
DestinationView::FitR(self.scan_pdf_rule(files)?)
|
||||
} else {
|
||||
let mut view = None;
|
||||
@@ -235,6 +236,18 @@ impl Executor {
|
||||
}
|
||||
view.ok_or_else(|| self.error("expected PDF destination view", span))?
|
||||
};
|
||||
if !matches!(view, DestinationView::FitR(_)) {
|
||||
self.optional_space(files)?;
|
||||
}
|
||||
if self.state.input_profile() == InputProfile::TeX8Bit {
|
||||
self.reads.insert(Dependency::PdfObjects);
|
||||
let id = self.pdf_destination_id(&destination);
|
||||
if self.state.pdf_objects.as_ref().is_some_and(|objects| {
|
||||
objects.destination_is_defined(id.clone(), structure.is_some())
|
||||
}) {
|
||||
return self.warn_pdf_duplicate_destination(&id, span, files);
|
||||
}
|
||||
}
|
||||
LinkNode::Destination { destination, view, structure }
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -245,6 +258,28 @@ impl Executor {
|
||||
})
|
||||
}
|
||||
|
||||
fn warn_pdf_duplicate_destination(
|
||||
&mut self,
|
||||
id: &DestinationId<String>,
|
||||
span: Span,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
if self.read_parameter(Parameter::Pdfsuppresswarningdupdest).width() > 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let id = crate::pdf::destination_identifier(id);
|
||||
let text = format!(
|
||||
"pdfTeX warning (ext4): destination with the same identifier ({id}) has been already used, duplicate ignored"
|
||||
);
|
||||
let context = self.diagnostic_context();
|
||||
let output = format!("{text}\n{}", context.text);
|
||||
self.reserve_diagnostic(output.len(), &context)?;
|
||||
files.observe_diagnostic(WriteDestination::TerminalAndLog, &output)
|
||||
.map_err(|error| self.error(error, span))?;
|
||||
self.events.push(Event::Message { text, span });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn register_pdf_link(&mut self, number: Option<u32>) -> Result<u32, Error> {
|
||||
self.reads.insert(Dependency::PdfObjects);
|
||||
self.state.pdf_objects.get_or_insert_with(Default::default)
|
||||
@@ -414,7 +449,11 @@ impl PdfLinkShipout {
|
||||
LinkNode::Destination { destination, view, structure } => {
|
||||
let destination = executor.pdf_destination_id(destination);
|
||||
let object_number = if self.numbered {
|
||||
executor.register_pdf_destination(destination.clone(), structure.is_some())?
|
||||
let Some(number) = executor.register_pdf_destination(destination.clone(), structure.is_some())? else {
|
||||
executor.warn_pdf_duplicate_destination(&destination, node.span, files)?;
|
||||
continue;
|
||||
};
|
||||
Some(number)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user