Discard duplicate destinations during native PDF execution

This commit is contained in:
gloamxun committed 2026-11-28 14:45:52 +08:00
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,
+1 -1
View File
@@ -2054,7 +2054,7 @@ fn write_destination(objects: &mut Vec<Vec<u8>>, slot: Option<usize>, body: Stri
}
}
fn destination_identifier(id: &DestinationId<String>) -> String {
pub(crate) fn destination_identifier(id: &DestinationId<String>) -> String {
match id {
DestinationId::Name(name) => format!("name{{{name}}}"),
DestinationId::Number(number) => format!("num{number}"),
@@ -404,6 +404,12 @@ impl PdfObjects {
Ok(number)
}
pub(crate) fn destination_is_defined(&self, id: DestinationId<String>, structure: bool) -> bool {
self.destination_numbers
.get(&(id, structure))
.is_some_and(|(_, defined)| *defined)
}
pub(crate) fn destination_number(
&mut self, id: DestinationId<String>, structure: bool, define: bool, limit: usize,
) -> Result<Option<u32>, String> {
@@ -662,3 +662,38 @@ fn outline_and_open_action_share_a_missing_numeric_destination() {
}
assert_eq!(messages.iter().filter(|text| text.contains("num23")).count(), 1);
}
#[test]
fn duplicate_destinations_are_discarded_after_the_first_definition() {
use texrra_tex_core::execution::Event;
let source = format!(
r"{SETUP}
\setbox0=\hbox{{\kern5pt\pdfdest name{{same}} xyz\kern3pt\pdfdest name{{same}} fit}}
\setbox1=\hbox{{\kern3pt\pdfdest num7 xyz\kern4pt\pdfdest num7 fith}}
\shipout\vbox{{\box0\box1}}
\setbox0=\hbox{{\kern1pt\pdfdest name{{same}} fit
\ifnum\lastnodetype=12 \else\errmessage{{duplicate named node retained}}\fi}}
{{\pdfsuppresswarningdupdest=1
\setbox1=\hbox{{\kern1pt\pdfdest num7 fit
\ifnum\lastnodetype=12 \else\errmessage{{duplicate numbered node retained}}\fi}}}}
\shipout\hbox{{\pdfdest name{{new}} fit\pdfdest name{{new}} xyz}}
\end"
);
let execution = run_native(&source).unwrap();
let warnings = execution.events.iter().filter_map(|event| match event {
Event::Message { text, .. } if text.contains("duplicate ignored") => Some(text.as_str()),
_ => None,
}).collect::<Vec<_>>();
assert_eq!(
warnings,
["name{same}", "num7", "name{same}", "name{new}"].map(|id| format!(
"pdfTeX warning (ext4): destination with the same identifier ({id}) has been already used, duplicate ignored"
))
);
let pages = execution.shipout_display_lists().unwrap();
assert_eq!(pages[0].pdf_links.destinations.len(), 2);
assert_eq!(pages[1].pdf_links.destinations.len(), 1);
assert!(export_native(&execution).diagnostics.is_empty());
}
+35
View File
@@ -18,6 +18,41 @@
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
## 2026-11-28 重复 PDF 目标与 Springer Nature
pdfTeX 模式在扫描及出页时按真实目标登记检查重复声明。已出页的
同类同名或同编号目标会在扫描时丢弃,仍在列表里的重复声明在出页
时忽略。首次出页保留目标类型、对象编号和位置。普通目标和结构
目标仍使用各自的登记。扫描还消费视图后的可选空格。
重复诊断在实际发生的阶段写入终端和日志。局部或全局赋值
\pdfsuppresswarningdupdest 只控制诊断。schema103 保存该参数和值
及别名,schema102 重载得到默认值 0。两页最小对照的四条诊断、
命名目标和列表查询均与参考一致。此前留在列表末尾的重复节点
返回类型 9,现在保留原来的 kern 并返回 12。23 项定向回归和
发布构建通过。
三页项目往返编辑第二页子文件的目标身份及规则宽度,两轮各复用
1,114 步,仅发出第二页。PDF、测量页面、SVG、日志、辅助文件及
来源映射与同修订独立全量一致。还原后重新获得重复目标诊断。
Springer Nature 同一冻结输入和 schema79 从空辅助文件运行实际
BibTeX 与三轮 LaTeX。原生候选 PDF 与本轮主线基线逐字节相同。
两端四条重复目标警告的名称和次数一致。12 页的全部字形、词框
与光栅一致,旋转表格的一个目标坐标仍有差异。
[原样项目对照](PUBLISHER_TEMPLATE_MATRIX.md#2026-11-28-springer-nature-主线复验)
最小实际旋转实例的 pdfdestmargin 为 1 pt。原版目标从无前置盒时
的 (71.004, 128.249) bp,变为此前丢弃高度为 4096 pt 的 fitr
节点时的 (-4009.694, 128.249) bp。原生两次均为 (72.000, 127.253)
bp。后续应继续核对活动变换下的坐标及边距,保留原版分配历史会
影响未初始化尺寸的证据。
[pdfTeX 扫描并检查重复目标](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L35031-L35140)
· [目标出页与变换](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L36700-L36752)
回执在 target/p3-pdf-destination-definition,receipt.json 的
SHA-256 为 93f99d9cf8ac18919b1b1260ff6cc5eab6f7af8f9128f958bf031723ddb60bf8。
## 2026-11-28 执行原始原语
pdfTeX 的 `\pdfprimitive` 与 XeTeX 的 `\primitive` 按当前兼容模式的
+24
View File
@@ -1002,6 +1002,30 @@ pdflatex.ini 生成且包含该原语的 schema79 复编后,三轮 aux 与
12 页 3357 个词的顺序一致,最大词框差 0.002395 bp。144 DPI 灰度差异为 216 个像素(第7页 90 个像素、第11页 126 个像素)。
[阶段记录](P2_M1_PROGRESS.md#pdftex-按命名目标导入实际-pdf-页面)
### 2026-11-28 Springer Nature 主线复验
用主线 ba548ef 从空辅助文件复编原样 16 项期刊交付。沿用冻结的
schema79、字体映射和原版 EPS 的实际转换件,运行真实 BibTeX 和三轮
LaTeX。三轮 aux 和 bbl 与参考逐字节相同,引用已收敛。12 页的
17,220 个字形及 3,357 个词框逐项一致,原有 216 个 144 DPI 灰度
差异像素已归零。18 条外部 URL 一致,86 个命名目标中仅旋转表格的
table.3 坐标仍有差异,两端均写在第 5 页。
冻结参考在该目标写出约 (218, 4298) bp,主线为 (219, 218) bp。
独立的原版最小用例表明,旋转后 xyz 目标的坐标会随之前已丢弃的
fitr 节点高度变化。保留原始导航输出和分配史对照作为后续入口。
主线编译证据在 target/p3-pdf-named-pages/springer-main-ba548ef。
receipt.json 的 SHA-256 为 bf8ee9dc952e55505f10444646a1452c1fbf76dbf4385756aeeeb3b9872b7092,
geometry/comparison.json 为 c84c1eaa0445805dd052b2da017e0a1fb5a0df3f1b860d394489a5acd5ec1761。
本轮重复目标候选再运行相同原样交付、实际 BibTeX 和三轮 LaTeX。
四条重复目标警告 table.1、table.2、figure.1 和 table.3 各出现一次,
与冻结参考一致。候选的 PDF 与本轮主线基线逐字节相同,三轮 aux、
bbl 及全部版面对照保持。旋转目标的已知差距保留。
候选验证在 target/p3-pdf-named-pages/springer-duplicate-candidate,
verification.json 的 SHA-256 为
87828d8f19c087c3755b341cc155ce616884b643f131a8b775d31fec5e373cee。
### Springer LNCS 的实际 PDF 导入复验
原样 Springer LNCS 会议样稿沿用冻结的格式、字体映射和官方
+2 -2
View File
@@ -365,7 +365,7 @@ fn local_structure_action_references_the_shipped_structure_and_later_page() {
}
#[test]
fn each_export_warning_starts_on_its_own_log_line() {
fn each_duplicate_destination_warning_starts_on_its_own_log_line() {
let root = std::env::temp_dir().join(format!("texrra-pdf-warning-lines-{}", std::process::id()));
let source = r"\catcode123=1 \catcode125=2
\pdfoutput=1 \pdfmajorversion=2 \pdfminorversion=0
@@ -384,7 +384,7 @@ fn each_export_warning_starts_on_its_own_log_line() {
let transcript = fs::read_to_string(root.join("native/probe.log")).unwrap();
let descriptions: Vec<_> = transcript
.lines()
.filter_map(|line| line.strip_prefix("native PDF warning: "))
.filter_map(|line| line.strip_prefix("pdfTeX warning (ext4): "))
.collect();
assert_eq!(descriptions.len(), 2, "{transcript}");
for (description, target) in descriptions.iter().zip(["first", "second"]) {