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
|
||||
};
|
||||
|
||||
@@ -16,9 +16,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 102;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 68] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, SCHEMA,
|
||||
const SCHEMA: u32 = 103;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 69] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -220,6 +220,9 @@ impl FormatImage {
|
||||
if image.schema < 102 {
|
||||
image.state.install_primitive_commands();
|
||||
}
|
||||
if image.schema < 103 {
|
||||
image.state.restore_legacy_pdf_parameters(&[Parameter::Pdfsuppresswarningdupdest]);
|
||||
}
|
||||
let pdf_objects = image.state.pdf_objects.as_deref();
|
||||
let mut numbered_images = 0;
|
||||
for (index, saved) in image.pdf_images.iter().enumerate() {
|
||||
|
||||
@@ -16,6 +16,7 @@ pub enum Parameter {
|
||||
Pdfinclusioncopyfonts,
|
||||
Pdfgentounicode,
|
||||
Pdfsuppresswarningdupmap,
|
||||
Pdfsuppresswarningdupdest,
|
||||
Pdfinfoomitdate,
|
||||
Pdfomitcharset,
|
||||
Pdfomitinfodict,
|
||||
@@ -170,6 +171,7 @@ impl Parameter {
|
||||
| Self::Pdfinclusioncopyfonts
|
||||
| Self::Pdfgentounicode
|
||||
| Self::Pdfsuppresswarningdupmap
|
||||
| Self::Pdfsuppresswarningdupdest
|
||||
| Self::Pdfinfoomitdate
|
||||
| Self::Pdfomitcharset
|
||||
| Self::Pdfomitinfodict
|
||||
@@ -219,6 +221,7 @@ impl Parameter {
|
||||
Self::Pdfinclusioncopyfonts,
|
||||
Self::Pdfgentounicode,
|
||||
Self::Pdfsuppresswarningdupmap,
|
||||
Self::Pdfsuppresswarningdupdest,
|
||||
Self::Pdfinfoomitdate,
|
||||
Self::Pdfomitcharset,
|
||||
Self::Pdfomitinfodict,
|
||||
|
||||
Reference in new issue
Block a user