From 7707cd9b09c20d4a37f7c484dc8e58890e9940a2 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Sat, 28 Nov 2026 16:39:02 +0800 Subject: [PATCH] Expose active insertion height to pdfTeX macros --- .../texrra-tex-core/src/execution/engine.rs | 1 + .../src/execution/engine/page.rs | 15 ++++++++ .../src/execution/format_image.rs | 9 +++-- .../src/execution/insertions.rs | 4 +++ crates/texrra-tex-core/src/execution/state.rs | 8 +++++ .../fixtures/insertions/split-and-defer.tex | 2 +- docs/P2_M1_PROGRESS.md | 35 +++++++++++++++++++ 7 files changed, 70 insertions(+), 4 deletions(-) diff --git a/crates/texrra-tex-core/src/execution/engine.rs b/crates/texrra-tex-core/src/execution/engine.rs index 0420213..274ad07 100644 --- a/crates/texrra-tex-core/src/execution/engine.rs +++ b/crates/texrra-tex-core/src/execution/engine.rs @@ -1033,6 +1033,7 @@ impl Executor { } } Pdfximagebbox => self.expand_pdf_image_bbox(token, files)?, + Pdfinsertht => self.expand_pdf_insertion_height(token, files)?, Pdfstrcmp => { let left = self.scan_expanded_group(files)?; let left = self.token_list_text(&left); diff --git a/crates/texrra-tex-core/src/execution/engine/page.rs b/crates/texrra-tex-core/src/execution/engine/page.rs index 478b602..7c3eec1 100644 --- a/crates/texrra-tex-core/src/execution/engine/page.rs +++ b/crates/texrra-tex-core/src/execution/engine/page.rs @@ -77,6 +77,21 @@ impl Executor { .dimension(p.page_dimension().unwrap()); i32::try_from(value).map_err(|_| self.error("native page dimension overflow", self.current)) } + pub(super) fn expand_pdf_insertion_height( + &mut self, token: &Token, files: &mut impl SourceProvider, + ) -> Result<(), Error> { + let index = self.register_index(files)?; + self.reads.insert(Dependency::PageState); + let height = u8::try_from(index).ok().and_then(|class| { + self.native_page.as_ref()?.insertions.height(class) + }); + let value = height.map_or_else( + || "0pt".to_owned(), + |size| format!("{}pt", super::super::registers::print_scaled_wide(size)), + ); + self.print_tokens(&value, token) + } + pub(super) fn request_page(&mut self) { if self.outer_vertical() { if let Some(page) = self.native_page.as_mut() { diff --git a/crates/texrra-tex-core/src/execution/format_image.rs b/crates/texrra-tex-core/src/execution/format_image.rs index 4074f9e..305952f 100644 --- a/crates/texrra-tex-core/src/execution/format_image.rs +++ b/crates/texrra-tex-core/src/execution/format_image.rs @@ -16,9 +16,9 @@ use std::{ sync::{Arc, Mutex, OnceLock, Weak}, }; -const SCHEMA: u32 = 106; -const COMPATIBLE_SCHEMAS: [u32; 72] = [ - 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, 103, 104, 105, SCHEMA, +const SCHEMA: u32 = 107; +const COMPATIBLE_SCHEMAS: [u32; 73] = [ + 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, 103, 104, 105, 106, SCHEMA, ]; const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION")); @@ -232,6 +232,9 @@ impl FormatImage { if image.schema < 106 { image.state.install_pdf_image_query_command(); } + if image.schema < 107 { + image.state.install_pdf_insertion_query_command(); + } let pdf_objects = image.state.pdf_objects.as_deref(); let mut numbered_images = 0; for (index, saved) in image.pdf_images.iter().enumerate() { diff --git a/crates/texrra-tex-core/src/execution/insertions.rs b/crates/texrra-tex-core/src/execution/insertions.rs index 5a86ac2..92cbd80 100644 --- a/crates/texrra-tex-core/src/execution/insertions.rs +++ b/crates/texrra-tex-core/src/execution/insertions.rs @@ -52,6 +52,10 @@ fn scale(size: i64, factor: i64) -> i64 { } impl PageInsertions { + pub(super) fn height(&self, class: u8) -> Option { + self.classes.get(&class).map(|entry| entry.size) + } + pub(super) fn activity<'a>( &'a self, state: &'a State, diff --git a/crates/texrra-tex-core/src/execution/state.rs b/crates/texrra-tex-core/src/execution/state.rs index 5e0dd39..9cbd130 100644 --- a/crates/texrra-tex-core/src/execution/state.rs +++ b/crates/texrra-tex-core/src/execution/state.rs @@ -103,6 +103,7 @@ pub enum Primitive { Pdfrefximage, Pdflastximage, Pdfximagebbox, + Pdfinsertht, Pdflastximagepages, Pdflastximagecolordepth, Jobname, @@ -533,6 +534,7 @@ impl Primitive { | XeTeXselectorname | Pdfstrcmp | Pdfximagebbox + | Pdfinsertht | Pdfmatch | Pdflastmatch | Pdfuniformdeviate @@ -952,6 +954,7 @@ const PDFTEX_ONLY_PRIMITIVES: &[(&str, Primitive)] = { ("pdfrefximage", Pdfrefximage), ("pdflastximage", Pdflastximage), ("pdfximagebbox", Pdfximagebbox), + ("pdfinsertht", Pdfinsertht), ("pdflastximagepages", Pdflastximagepages), ("pdflastximagecolordepth", Pdflastximagecolordepth), ("pdfcreationdate", Pdfcreationdate), @@ -2015,6 +2018,11 @@ impl State { self.update_profile_command("pdfximagebbox", Meaning::Primitive(Primitive::Pdfximagebbox), enabled); } + pub(super) fn install_pdf_insertion_query_command(&mut self) { + let enabled = self.input_profile != super::InputProfile::XeTeX; + self.update_profile_command("pdfinsertht", Meaning::Primitive(Primitive::Pdfinsertht), enabled); + } + fn install_pdftex_primitives(&mut self) { let enabled = self.input_profile != super::InputProfile::XeTeX; for &(name, primitive) in PDFTEX_ONLY_PRIMITIVES { diff --git a/crates/texrra-tex-core/tests/fixtures/insertions/split-and-defer.tex b/crates/texrra-tex-core/tests/fixtures/insertions/split-and-defer.tex index 02f4d1c..b1e6335 100644 --- a/crates/texrra-tex-core/tests/fixtures/insertions/split-and-defer.tex +++ b/crates/texrra-tex-core/tests/fixtures/insertions/split-and-defer.tex @@ -19,4 +19,4 @@ \binoppenalty=700 \relpenalty=500 \hsize=100pt \baselineskip=12pt \parfillskip=0pt plus1fil \hbadness=10000 \vbadness=10000 \boxmaxdepth=100pt -\pdfoutput=0\showboxbreadth=1000\showboxdepth=100\overfullrule=0pt \vsize=64pt \topskip=10pt \maxdepth=2pt \splitmaxdepth=1pt \splittopskip=8pt \tracingpages=1 \count42=1000 \dimen42=56pt \skip42=3pt plus1pt \output={\message{[output:\the\insertpenalties,\the\pagetotal,\the\pagegoal]}\ifvoid42\message{[insert:void]}\else\message{[insert:\the\ht42,\the\dp42]}\fi \setbox0=\vbox{\unvbox255\ifvoid42\else\kern1pt\box42\fi}\showbox0\shipout\box0}\dimen42=13pt \floatingpenalty=11 \noindent A\insert42{\hbox{I}\penalty0\hbox{J}\penalty0\hbox{K}}B\par\noindent C\par\end +\pdfoutput=0\showboxbreadth=1000\showboxdepth=100\overfullrule=0pt \vsize=64pt \topskip=10pt \maxdepth=2pt \splitmaxdepth=1pt \splittopskip=8pt \tracingpages=1 \count42=1000 \dimen42=56pt \skip42=3pt plus1pt \output={\message{[output:\the\insertpenalties,\the\pagetotal,\the\pagegoal]}\message{[insert:output-height=\pdfinsertht42]}\ifvoid42\message{[insert:void]}\else\message{[insert:\the\ht42,\the\dp42]}\fi \setbox0=\vbox{\unvbox255\ifvoid42\else\kern1pt\box42\fi}\showbox0\shipout\box0}\dimen42=13pt \floatingpenalty=11 \message{[insert:absent=\pdfinsertht42]} \noindent A\insert42{\hbox{I}\penalty0\hbox{J}\penalty0\hbox{K}}B\par\message{[insert:split-height=\pdfinsertht42]}\noindent C\par\end diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index 52c5c3d..28c31e6 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -18,6 +18,41 @@ | W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 | | W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 | +## 2026-11-28 活动页面的插入高度和原样项目核查 + +pdfTeX 模式的可展开 \pdfinsertht 直接读取页构建中实际插入类 +的未缩放尺寸,跟随当前页的正常计入、拆分、暂留和输出例程。 +原版没有活动类时返回 0pt。schema107 保存该原语的别名,旧 +schema106 的同名用户宏仍保留。 +[pdfTeX 的展开与活动插入表](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L11405-L11414) + +原版三页对照的查询依次为 0、10、14、14 pt,输出例程中归零。 +页目标与三页 144 DPI 灰度图也一致。真实双栏 article 中, +左右栏脚注分别为 9.54001 和 28.54001 pt。依尺寸排出的规则、 +整页光栅和 aux 与参考一致。既有插入套件的七页盒列表、分页和 +DVI 合格,且覆盖新增查询。发布构建通过。 + +三页会话的检查点包含已经进入当前页的 10 pt 插入材料。两次 +编辑各复用 1,326 步。第二页的插入高度更新到 19 pt 后恢复 +为 15 pt,仅替换该页。PDF、预览、来源映射、日志和 aux 与 +同修订独立全量一致。回执保留第一次空辅助文件导致零复用的 +记录,复用对照固定实际生成文件初态。 + +基线 2fa11fb 复验原样六页 xeCJK-example-CJKfntef.tex。 +六页词序、词框、144 DPI 灰度图和 aux 与参考一致。两端都 +有十个字体条目,SimSun 合为同一子集,LASY6 为 Type 1C。 +字体名、嵌入类型和 Unicode 标志的这组记录继续保留。完整 +字体对象等价和双 profile 统一门禁单独验收。 + +根据用户对推进速度的反馈,后续按真实项目的阻塞链和 A4 热编辑 +链路合并实现。开发用已有最小对照定位首处差异,发布构建与项目 +回归按实现批次执行。下一批优先做 A4 主文件从检查点恢复到可见 +页面的执行与布局复用。100 ms 预算和其他原有退出条件保持。 + +回执在 target/p3-native-insertion-height,receipt.json 的 SHA-256 为 +be132ac806c3da49a48f37e2dfbba11f0965a3d9dcfc05805bbe2d0fd22af32e。 +原样 xeCJK 主线记录在 target/p3-xecjk-current-batch。 + ## 2026-11-28 原生 PDF 图像页框查询 pdfTeX 模式执行可展开的 \pdfximagebbox。通过实际图像对象编号