From c2e1e64a60e9c1176e2f36dde33e813b909a20ca Mon Sep 17 00:00:00 2001 From: GloamXun Date: Sat, 28 Nov 2026 01:06:12 +0800 Subject: [PATCH] Retain XeTeX image lookup paths in native formats --- .../src/execution/engine/pdf_image.rs | 65 ++++++++++------- .../src/execution/format_image.rs | 16 +++-- .../src/execution/format_image/images.rs | 7 +- crates/texrra-tex-core/src/execution/mod.rs | 11 +++ crates/texrra-tex-core/src/resources.rs | 71 ++++++++++++++++--- .../src/resources/named_fonts.rs | 2 +- docs/P2_M1_PROGRESS.md | 32 +++++++++ src/native_checkpoint_probe.rs | 12 ++++ src/native_job.rs | 10 +++ tests/native_pdf_image.rs | 36 +++++++--- 10 files changed, 208 insertions(+), 54 deletions(-) diff --git a/crates/texrra-tex-core/src/execution/engine/pdf_image.rs b/crates/texrra-tex-core/src/execution/engine/pdf_image.rs index 1c84ec7..21e5e3e 100644 --- a/crates/texrra-tex-core/src/execution/engine/pdf_image.rs +++ b/crates/texrra-tex-core/src/execution/engine/pdf_image.rs @@ -10,7 +10,7 @@ pub(super) struct RegisteredImage { image: Arc, attributes: Option>, saved: Option, - pending_xdv: Option, + pending_xdv: Option<(FormatImageKind, std::path::PathBuf)>, } impl Executor { @@ -31,7 +31,9 @@ impl Executor { attributes: (!matches!(saved.kind, FormatImageKind::XdvShippedSpecial)) .then(|| saved.attributes.clone()), saved: None, - pending_xdv: (!saved.kind.reads_at_load()).then_some(saved.kind), + pending_xdv: (!saved.kind.reads_at_load()).then(|| { + (saved.kind, saved.xdv_file.as_deref().unwrap_or_else(|| saved.path()).into()) + }), } }).collect(); self.format_image_warnings = warnings; @@ -371,7 +373,7 @@ impl Executor { return self.fail("XeTeX image is illegal in math mode"); } let (name, from) = self.xdv_image_filename(token, files)?; - let (image, source_origin, page, format_kind) = if pdf { + let (page, format_kind) = if pdf { let page = if self.keyword("page", files)? { self.integer(files)? } else { @@ -390,17 +392,27 @@ impl Executor { break; } } + (page, FormatImageKind::XdvPdf { page_box: box_type }) + } else { + (0, FormatImageKind::XdvRaster) + }; + let (resource, format_path) = if self.state.is_initex() { + let (resource, path) = files + .resource_with_lookup_path(ResourceKind::PdfImage, &name, &from) + .map_err(|message| self.error(message, token.span))?; + (resource, Some(path)) + } else { let resource = files .resource(ResourceKind::PdfImage, &name, &from) .map_err(|message| self.error(message, token.span))?; - let (image, source_origin) = PdfImage::read_xdv(resource, page, box_type) + (resource, None) + }; + let (image, source_origin) = if let FormatImageKind::XdvPdf { page_box } = format_kind { + let (image, origin) = PdfImage::read_xdv(resource, page, page_box) .map_err(|message| self.error(message, token.span))?; - (Arc::new(image), source_origin, page, FormatImageKind::XdvPdf { page_box: box_type }) + (Arc::new(image), origin) } else { - ( - self.xdv_raster_source(&name, &from, token.span, files)?, - [0.0; 2], 0, FormatImageKind::XdvRaster, - ) + (self.decode_xdv_raster(resource, token.span)?, [0.0; 2]) }; let mut placement = XdvImagePlacement::new(&image, source_origin); loop { @@ -432,7 +444,11 @@ impl Executor { let image = PdfImageUse::new_xdv(self.pdf_images.len() + 1, image, placement, page) .map_err(|message| self.error(message, token.span))?; let image = Arc::new(image); - let saved = self.state.is_initex().then(|| FormatPdfImage::capture(&image, &[], format_kind)); + let saved = format_path.map(|path| { + let mut saved = FormatPdfImage::capture(&image, &[], format_kind); + saved.xdv_file = Some(path); + saved + }); self.pdf_images.push(RegisteredImage { image: image.clone(), attributes: Some(Vec::new()), @@ -442,16 +458,11 @@ impl Executor { self.defer_image(image, token) } - fn xdv_raster_source( + fn decode_xdv_raster( &self, - name: &str, - from: &str, + resource: crate::resources::LoadedResource, span: Span, - files: &mut impl SourceProvider, ) -> Result, Error> { - let resource = files - .resource(ResourceKind::PdfImage, name, from) - .map_err(|message| self.error(message, span))?; // A layout measurement and later shipout share the decoded pixels // only if the resource provider returns the same version. if let Some(registered) = self.pdf_images.iter().rev().find(|registered| { @@ -491,7 +502,10 @@ impl Executor { name: special.file.clone(), from: from.clone(), }); - let resource = self.xdv_raster_source(&special.file, &from, span, files)?; + let resource = files + .resource(ResourceKind::PdfImage, &special.file, &from) + .map_err(|message| self.error(message, span))?; + let resource = self.decode_xdv_raster(resource, span)?; let image = special.place(self.pdf_images.len() + 1, resource) .map_err(|error| self.error(error, span))?; let image = Arc::new(image); @@ -515,8 +529,8 @@ impl Executor { pub(super) fn declare_pdf_image( &mut self, id: usize, files: &mut impl SourceProvider, ) -> Result<(), Error> { - if let Some(kind) = self.pdf_images[id - 1].pending_xdv { - self.open_format_xdv_image(id, kind, files)?; + if self.pdf_images[id - 1].pending_xdv.is_some() { + self.open_format_xdv_image(id, files)?; } let registered = &mut self.pdf_images[id - 1]; let Some(tokens) = registered.attributes.take() else { @@ -595,20 +609,21 @@ impl Executor { fn open_format_xdv_image( &mut self, id: usize, - kind: FormatImageKind, files: &mut impl SourceProvider, ) -> Result<(), Error> { - let saved = &self.pdf_images[id - 1].image; - let path = saved.image.version.path.to_string_lossy(); + let registered = &self.pdf_images[id - 1]; + let (kind, path) = registered.pending_xdv.as_ref().expect("pending XDV image"); + let path = path.to_str().ok_or_else(|| self.error("XDV image path is not UTF-8", self.current))?; + let saved = ®istered.image; let from = self.source_name(self.current); self.reads.insert(Dependency::FileLookup { name: path.to_string(), from: from.clone(), }); - let resource = files.resource(ResourceKind::PdfImage, &path, &from) + let resource = files.resource(ResourceKind::PdfImage, path, &from) .map_err(|message| self.error(message, self.current))?; let page = saved.xdv.as_ref().expect("registered XDV placement").page_request; - let actual = match kind { + let actual = match *kind { FormatImageKind::XdvPdf { page_box } => { PdfImage::read_xdv(resource, page, page_box).map(|(image, _)| image) } diff --git a/crates/texrra-tex-core/src/execution/format_image.rs b/crates/texrra-tex-core/src/execution/format_image.rs index cc8291b..f0db472 100644 --- a/crates/texrra-tex-core/src/execution/format_image.rs +++ b/crates/texrra-tex-core/src/execution/format_image.rs @@ -14,9 +14,9 @@ use std::{ sync::{Arc, Mutex, OnceLock, Weak}, }; -const SCHEMA: u32 = 91; -const COMPATIBLE_SCHEMAS: [u32; 57] = [ - 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, SCHEMA, +const SCHEMA: u32 = 92; +const COMPATIBLE_SCHEMAS: [u32; 58] = [ + 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, SCHEMA, ]; const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION")); @@ -61,8 +61,8 @@ struct Envelope { } impl FormatImage { - /// The format reopens its declared images by resolved path in the new - /// job. Keep version checks for all other reads, including a path also + /// The format reopens its declared images in the new job. Keep version + /// checks for all other reads, including a path also /// used in some other role during the dump. pub fn from_dump_with_trace(execution: Execution, trace: &ResourceTrace) -> Result { let mut resources = trace.reads.clone(); @@ -221,9 +221,15 @@ impl FormatImage { image.schema >= 89 && saved.kind == FormatImageKind::Png && pdf_objects.is_some_and(|objects| objects.is_png_group(group)) }); + let valid_xdv_file = saved.xdv_file.as_ref().is_none_or(|path| { + image.schema >= 92 + && matches!(saved.kind, FormatImageKind::XdvPdf { .. } | FormatImageKind::XdvRaster) + && !path.as_os_str().is_empty() + }); if !valid_profile || !valid_number || !valid_group + || !valid_xdv_file || saved.image.id != index + 1 || saved.path().as_os_str().is_empty() { diff --git a/crates/texrra-tex-core/src/execution/format_image/images.rs b/crates/texrra-tex-core/src/execution/format_image/images.rs index b737b44..261e184 100644 --- a/crates/texrra-tex-core/src/execution/format_image/images.rs +++ b/crates/texrra-tex-core/src/execution/format_image/images.rs @@ -7,7 +7,7 @@ use crate::{ resources::{LoadedResource, ResourceVersion}, }; use serde::{Deserialize, Serialize}; -use std::{path::Path, sync::Arc}; +use std::{path::{Path, PathBuf}, sync::Arc}; #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub(in crate::execution) enum FormatImageKind { @@ -32,6 +32,8 @@ pub(in crate::execution) struct FormatPdfImage { pub image: Arc, pub attributes: Vec, pub kind: FormatImageKind, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub xdv_file: Option, } impl FormatPdfImage { @@ -47,10 +49,11 @@ impl FormatPdfImage { }), attributes: attributes.to_vec(), kind, + xdv_file: None, } } - pub(super) fn path(&self) -> &Path { + pub(in crate::execution) fn path(&self) -> &Path { &self.image.image.version.path } diff --git a/crates/texrra-tex-core/src/execution/mod.rs b/crates/texrra-tex-core/src/execution/mod.rs index 1dfc00b..8453360 100644 --- a/crates/texrra-tex-core/src/execution/mod.rs +++ b/crates/texrra-tex-core/src/execution/mod.rs @@ -249,6 +249,17 @@ pub trait SourceProvider { ) -> Result { Err("host binary resource lookup unavailable".into()) } + /// Retain the lookup spelling when a format defers reopening the resource. + fn resource_with_lookup_path( + &mut self, + kind: crate::resources::ResourceKind, + name: &str, + from: &str, + ) -> Result<(crate::resources::LoadedResource, std::path::PathBuf), String> { + let resource = self.resource(kind, name, from)?; + let path = resource.version.path.clone(); + Ok((resource, path)) + } /// A missing VF permits the physical font path. Lookup and read errors do not. fn virtual_font( &mut self, diff --git a/crates/texrra-tex-core/src/resources.rs b/crates/texrra-tex-core/src/resources.rs index 68887ea..adaec52 100644 --- a/crates/texrra-tex-core/src/resources.rs +++ b/crates/texrra-tex-core/src/resources.rs @@ -581,13 +581,14 @@ impl FileWorld { &format!("{name}@{density}dpi"), from, variants, + None, )? { return self.read_path(path); } } // A bare file may be explicitly supplied by a directory path. Never // recursively pick an arbitrary dpiNNN/name.pk from another density. - for entry in self.paths(ResourceKind::Pk, from) { + for (entry, _) in self.paths(ResourceKind::Pk, from) { if let SearchPath::Directory { path, suffix, .. } = entry { let candidate = self .config @@ -1238,19 +1239,22 @@ impl FileWorld { self.indexes.clear(); } } - fn paths(&self, kind: ResourceKind, from: &Path) -> Vec { + fn paths(&self, kind: ResourceKind, from: &Path) -> Vec<(SearchPath, bool)> { // Images use the TeX namespace and have their own dependency role. let kind = if kind == ResourceKind::PdfImage { ResourceKind::Tex } else { kind }; - let mut defaults = vec![SearchPath::directory(&self.config.cwd, false)]; + // Keep default job-relative paths distinct from explicitly configured + // absolute search entries, even when they name the same directory. + let mut defaults = vec![(SearchPath::directory(&self.config.cwd, false), true)]; if kind == ResourceKind::Tex && self.config.input_policy == InputPolicy::Project { if let Some(parent) = from.parent() { let path = self.config.cwd.join(parent); if path != self.config.cwd { - defaults.push(SearchPath::directory(path, false)); + let job_relative = path.starts_with(&self.config.cwd); + defaults.push((SearchPath::directory(path, false), job_relative)); } } } @@ -1264,7 +1268,7 @@ impl FileWorld { self.config .texmf_roots .iter() - .map(|r| SearchPath::directory(r.join(directory), true)), + .map(|r| (SearchPath::directory(r.join(directory), true), false)), ); } let mut paths = Vec::new(); @@ -1277,7 +1281,7 @@ impl FileWorld { { match entry { SearchPath::Defaults => paths.extend(defaults.clone()), - e => paths.push(e.clone()), + e => paths.push((e.clone(), false)), } } paths @@ -1442,7 +1446,7 @@ impl FileWorld { name: &str, from: &Path, ) -> Result, String> { - self.resolve_variants(kind, name, from, Self::variants(kind, name, false)) + self.resolve_variants(kind, name, from, Self::variants(kind, name, false), None) } /// Apply the TeX input scanner's default suffix alternatives. Raw host @@ -1450,7 +1454,7 @@ impl FileWorld { pub fn resolve_tex_input(&mut self, name: &str, from: &Path) -> Result, String> { let kind = ResourceKind::Tex; let fallback = self.config.input_policy == InputPolicy::Tex && self.tex_suffix_fallback; - self.resolve_variants(kind, name, from, Self::variants(kind, name, fallback)) + self.resolve_variants(kind, name, from, Self::variants(kind, name, fallback), None) } fn resolve_variants( @@ -1459,16 +1463,26 @@ impl FileWorld { name: &str, from: &Path, variants: Vec, + mut lookup_path: Option<&mut PathBuf>, ) -> Result, String> { let mut candidates = Vec::new(); let result = (|| { let paths = self.paths(kind, from); let mut found = None; - if Path::new(name).is_absolute() || name.starts_with("./") || name.starts_with("../") { + let requested = Path::new(name); + if requested.is_absolute() + || matches!( + requested.components().next(), + Some(std::path::Component::CurDir | std::path::Component::ParentDir) + ) + { for variant in &variants { let path = self.config.cwd.join(variant); candidates.push(path.clone()); if let Some(path) = self.probe(&path)? { + if let Some(lookup_path) = lookup_path.as_deref_mut() { + lookup_path.clone_from(variant); + } found = Some(path); break; } @@ -1477,7 +1491,7 @@ impl FileWorld { // TeX honors search-path priority before the suffix alternatives. // A recursive path is one entry: search all of it for .tex before // trying the bare name, rather than flattening it into directories. - 'paths: for entry in &paths { + 'paths: for (entry, job_relative) in &paths { let SearchPath::Directory { path, recursive, @@ -1487,10 +1501,24 @@ impl FileWorld { unreachable!() }; let root = self.config.cwd.join(path); + let lookup_name = |cwd: &Path, candidate: &Path| { + if *job_relative + && let Ok(relative) = candidate.strip_prefix(cwd) + { + return Path::new(".").join(relative); + } + if path.is_relative() && let Ok(relative) = candidate.strip_prefix(&root) { + return path.join(relative); + } + candidate.to_owned() + }; for variant in &variants { let direct = root.join(suffix).join(variant); candidates.push(direct.clone()); if let Some(path) = self.probe(&direct)? { + if let Some(lookup_path) = lookup_path.as_deref_mut() { + *lookup_path = lookup_name(&self.config.cwd, &direct); + } found = Some(path); break 'paths; } @@ -1545,6 +1573,9 @@ impl FileWorld { } candidates.push(candidate.clone()); if let Some(path) = self.probe(&candidate)? { + if let Some(lookup_path) = lookup_path.as_deref_mut() { + *lookup_path = lookup_name(&self.config.cwd, &candidate); + } found = Some(path); break 'paths; } @@ -1574,6 +1605,26 @@ impl FileWorld { self.read_shared(kind, name, from) .map(SnapshotFile::into_loaded) } + /// Read a resource and return the path spelling selected by the lookup. + /// Its version records the resolved identity independently. + pub fn read_with_lookup_path( + &mut self, + kind: ResourceKind, + name: &str, + from: &Path, + ) -> Result<(LoadedResource, PathBuf), String> { + let mut lookup_path = PathBuf::new(); + let path = self.resolve_variants( + kind, + name, + from, + Self::variants(kind, name, false), + Some(&mut lookup_path), + )?; + let resource = self.read_shared_resolved(kind, name, from, path)?; + Ok((resource.into_loaded(), lookup_path)) + } + /// Resolve and record a resource read while sharing the captured bytes. pub fn read_shared( &mut self, diff --git a/crates/texrra-tex-core/src/resources/named_fonts.rs b/crates/texrra-tex-core/src/resources/named_fonts.rs index dcf5406..68c6ce1 100644 --- a/crates/texrra-tex-core/src/resources/named_fonts.rs +++ b/crates/texrra-tex-core/src/resources/named_fonts.rs @@ -214,7 +214,7 @@ impl FileWorld { let mut remaining = self.config.max_index_entries; for (path, file) in project.files() { if !is_outline(path) - || !paths.iter().any(|scope| self.font_path_in(scope, path)) + || !paths.iter().any(|(scope, _)| self.font_path_in(scope, path)) { continue; } diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index 5748faa..5a949af 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -712,6 +712,38 @@ PDF、SVG 和逐页来源映射与独立全量相同。六项图像回归通过 回执 `target/p3-format-xdv-images/receipt.json` 的 SHA-256 为 `152fe604aefb4a47e52d41e556cb674e7e19e7388447f18338840898afc3495a`。 +### XeTeX 格式图像路径随项目移动 + +格式 schema92 分别保存图像查找命中的路径写法、当时实际读取的 +资源版本,以及装盒后的尺寸、页框和变换。发页时通过当前作业的 +宿主重新读取保存的图像路径。工作目录命中的 `./` 路径随作业目录 +移动,显式绝对路径和绝对搜索目录选中的路径保持绝对。相对搜索 +目录命中的路径保留目录前缀,并按发页作业的搜索规则重开。路径 +经别名命中时,读取追踪记录实际目标和字节版本。旧格式缺少路径 +写法时沿用已保存的解析路径。 +[原版图像查找](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/xetexdir/XeTeX_pic.c#L76-L95) +[原版 XDV 发页](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/xetexdir/xetex.web#L28042-L28076) +[驱动查找图像](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/dvipdfm-x/pdfximage.c#L371-L437) + +以同一 PDF、PNG、转储盒和文档输入对照 11 组路径案例。相对搜索、 +递归目录、绝对搜索、显式绝对路径和符号链接命中的路径写法与 +原版 XDV 一致。参考的 TEXPICTS 搜索目录用原生现有 TEXINPUTS +配置等价提供。8 组成功案例的 24 页在 144 DPI 下逐像素一致, +包含文末纸张指令产生的第三页。三组缺图在相同路径规则下失败。 +实际 schema91 镜像可继续重载,三页光栅与参考一致。 + +11 项图像回归通过。迁移后的项目快照替换一张 PNG 时,检查点 +恢复并只更新第 2 页。未发页的图片无实际读取。测量页面、PDF、 +完整 SVG 和来源映射与独立全量逐项一致,读取追踪记录新目录的 +实际文件版本。 + +证据在 target/p3-xetex-image-relocation。comparison.json 的 SHA-256 为 +1f0c30f3b547f1fbd4ee2b7e4e761b87609da96209ea0bf8efb32c10c726ecca。 +保留首次误将三页产物按两页比较,以及定向搜索配置下入口未显式 +限定路径的两次探测。将已转储的格式、图像和 seed.tex 一同移至 +新目录,原版生成三页,原生在校验转储输入时查找旧 seed.tex +并报告缺失。该复现及旧路径诊断在 next-format-source-location。 + ### XeTeX 纸张指令进入实际发页 XeTeX 每页隐式纸张设置与文档内的 `pdf:pagesize` 按发页顺序生效。 diff --git a/src/native_checkpoint_probe.rs b/src/native_checkpoint_probe.rs index 55b86b4..16eb091 100644 --- a/src/native_checkpoint_probe.rs +++ b/src/native_checkpoint_probe.rs @@ -124,6 +124,18 @@ impl SourceProvider for RecordingHost<'_> { result.as_ref().map(|resource| resource.version.clone()).map_err(Clone::clone) }) } + fn resource_with_lookup_path( + &mut self, + kind: ResourceKind, + name: &str, + from: &str, + ) -> Result<(LoadedResource, PathBuf), String> { + let (name, from) = (name.to_owned(), from.to_owned()); + call!(self, resource_with_lookup_path(kind, &name, &from); |result| { + result.as_ref().map(|(resource, path)| (resource.version.clone(), path.clone())) + .map_err(Clone::clone) + }) + } fn virtual_font(&mut self, name: &str, from: &str) -> Result, String> { let (name, from) = (name.to_owned(), from.to_owned()); call!(self, virtual_font(&name, &from); |result| { diff --git a/src/native_job.rs b/src/native_job.rs index d736583..a861a29 100644 --- a/src/native_job.rs +++ b/src/native_job.rs @@ -1641,6 +1641,16 @@ impl SourceProvider for Files { self.observe_resource(kind, &resource); Ok(resource) } + fn resource_with_lookup_path( + &mut self, + kind: ResourceKind, + name: &str, + from: &str, + ) -> Result<(LoadedResource, PathBuf), String> { + let (resource, path) = self.world.read_with_lookup_path(kind, name, Path::new(from))?; + self.observe_resource(kind, &resource); + Ok((resource, path)) + } fn virtual_font(&mut self, name: &str, from: &str) -> Result, String> { let resource = self .world diff --git a/tests/native_pdf_image.rs b/tests/native_pdf_image.rs index 354788f..cdaeac9 100644 --- a/tests/native_pdf_image.rs +++ b/tests/native_pdf_image.rs @@ -665,7 +665,7 @@ fn format_image_resource_edits_invalidate_checkpoints_and_update_the_picture_pag } #[test] -fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { +fn relocated_xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { use image::ImageEncoder; use texrra_engine::native::dump_format; use texrra_tex_core::{ @@ -676,11 +676,16 @@ fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { let root = std::env::temp_dir().join(format!("texrra-xdv-format-image-{}", std::process::id())); fs::create_dir(&root).unwrap(); let root = root.canonicalize().unwrap(); - let seed = root.join("seed.tex"); - let format = root.join("seed.tfx"); - let entry = root.join("entry.tex"); - let used = root.join("used.png"); - let unused = root.join("unused.png"); + let origin = root.join("format-origin"); + let project = root.join("relocated"); + fs::create_dir(&origin).unwrap(); + fs::create_dir(&project).unwrap(); + let seed = origin.join("seed.tex"); + let seed_format = origin.join("seed.tfx"); + let format = project.join("seed.tfx"); + let entry = project.join("entry.tex"); + let used = project.join("used.png"); + let unused = project.join("unused.png"); let encode = |w: u32, h: u32, color: u8| -> Arc<[u8]> { let mut bytes = Vec::new(); @@ -690,8 +695,8 @@ fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { bytes.into() }; let original = encode(2, 1, 35); - fs::write(&used, &original).unwrap(); - fs::write(&unused, &original).unwrap(); + fs::write(origin.join("used.png"), &original).unwrap(); + fs::write(origin.join("unused.png"), &original).unwrap(); fs::write( &seed, r#"\catcode123=1 \catcode125=2 @@ -701,15 +706,17 @@ fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { "#, ) .unwrap(); - let world = WorldConfig::new(&root); let time = JobTime::new(2026, 11, 27, 0).unwrap(); - let mut request = CompileRequest::new(world.clone(), &seed, &format, time); + let mut request = CompileRequest::new(WorldConfig::new(&origin), &seed, &seed_format, time); request.entry = Entry::Initex; request.input_profile = InputProfile::XeTeX; request.etex = true; dump_format(request, Cancellation::default()).unwrap(); - fs::remove_file(&unused).unwrap(); + fs::copy(&seed_format, &format).unwrap(); + fs::remove_file(origin.join("unused.png")).unwrap(); + fs::remove_file(origin.join("used.png")).unwrap(); + let world = WorldConfig::new(&project); let prefix = "\\shipout\\hbox{\\vrule width10pt height4pt}\n"; let padding = format!("{}\n", "\\relax ".repeat(32)).repeat(48); let source = format!("{prefix}{padding}\\shipout\\copy0\\end\n"); @@ -761,6 +768,11 @@ fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { for result in [&first, &next] { let reads = &result.resources.trace.reads; assert!(!reads.iter().any(|version| version.path == unused)); + assert!( + !reads.iter().any(|version| { + version.path == origin.join("used.png") || version.path == origin.join("unused.png") + }) + ); let image = result.pages[1] .items .iter() @@ -803,6 +815,8 @@ fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() { ); let full = NativeCompiler::default().compile(revised).unwrap(); assert_eq!(next.pdf, full.pdf); + assert_eq!(next.pages, full.pages); + assert_eq!(next.source_map.sources, full.source_map.sources); assert_eq!(next.source_map.pages, full.source_map.pages); assert_eq!( next.preview_since(None).unwrap().pages,