Honor final pdfTeX font charset and document info omission

This commit is contained in:
gloamxun committed 2026-11-26 16:48:27 +08:00
1 parent 38c567623a
commit de481fd762
8 files changed
+92 -26

No files matched your search

@@ -272,7 +272,9 @@ impl Executor {
} }
if !self.pdf_info_tokens.is_empty() { if !self.pdf_info_tokens.is_empty() {
let tokens = std::mem::take(&mut self.pdf_info_tokens); let tokens = std::mem::take(&mut self.pdf_info_tokens);
self.state.pdf_info = self.pdf_token_bytes(&tokens)?; if self.read_parameter(Parameter::Pdfomitinfodict).width() == 0 {
self.state.pdf_info = self.pdf_token_bytes(&tokens)?;
}
} }
Ok(()) Ok(())
} }
@@ -8,9 +8,9 @@ use std::{
sync::{Arc, Mutex, OnceLock, Weak}, sync::{Arc, Mutex, OnceLock, Weak},
}; };
const SCHEMA: u32 = 78; const SCHEMA: u32 = 79;
const COMPATIBLE_SCHEMAS: [u32; 45] = [ const COMPATIBLE_SCHEMAS: [u32; 46] = [
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, SCHEMA, 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, SCHEMA,
]; ];
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION")); const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
@@ -136,6 +136,9 @@ impl FormatImage {
if image.schema < 58 { if image.schema < 58 {
image.state.restore_legacy_mathcodes()?; image.state.restore_legacy_mathcodes()?;
} }
if image.schema < 79 {
image.state.restore_legacy_pdf_omission_parameters();
}
image.schema = SCHEMA; image.schema = SCHEMA;
Ok(image) Ok(image)
} }
@@ -17,6 +17,8 @@ pub enum Parameter {
Pdfgentounicode, Pdfgentounicode,
Pdfsuppresswarningdupmap, Pdfsuppresswarningdupmap,
Pdfinfoomitdate, Pdfinfoomitdate,
Pdfomitcharset,
Pdfomitinfodict,
Tracingcommands, Tracingcommands,
Tracingrestores, Tracingrestores,
Tracingassigns, Tracingassigns,
@@ -154,6 +156,8 @@ impl Parameter {
| Self::Pdfgentounicode | Self::Pdfgentounicode
| Self::Pdfsuppresswarningdupmap | Self::Pdfsuppresswarningdupmap
| Self::Pdfinfoomitdate | Self::Pdfinfoomitdate
| Self::Pdfomitcharset
| Self::Pdfomitinfodict
| Self::Pdfhorigin | Self::Pdfhorigin
| Self::Pdfvorigin | Self::Pdfvorigin
| Self::Pdflinkmargin | Self::Pdflinkmargin
@@ -192,6 +196,8 @@ impl Parameter {
Self::Pdfgentounicode, Self::Pdfgentounicode,
Self::Pdfsuppresswarningdupmap, Self::Pdfsuppresswarningdupmap,
Self::Pdfinfoomitdate, Self::Pdfinfoomitdate,
Self::Pdfomitcharset,
Self::Pdfomitinfodict,
Self::Tracingcommands, Self::Tracingcommands,
Self::Tracingrestores, Self::Tracingrestores,
Self::Tracingassigns, Self::Tracingassigns,
+13 -2
View File
@@ -1676,15 +1676,26 @@ impl State {
} }
} }
pub(super) fn restore_legacy_pdf_omission_parameters(&mut self) {
if self.input_profile != super::InputProfile::XeTeX {
for parameter in [Parameter::Pdfomitcharset, Parameter::Pdfomitinfodict] {
self.commands
.entry(CommandName::Control(parameter.name()))
.or_insert(Meaning::Parameter(parameter));
}
}
}
pub fn is_initex(&self) -> bool { pub fn is_initex(&self) -> bool {
self.initex self.initex
} }
/// Final font output uses the live table and parameters, not the values /// Final PDF output uses the live state after the last page ships out.
/// captured at a page's shipout. The table is global and survives a dump.
pub fn pdf_final_options(&self) -> crate::pdf_unicode::PdfFinalOptions<'_> { pub fn pdf_final_options(&self) -> crate::pdf_unicode::PdfFinalOptions<'_> {
crate::pdf_unicode::PdfFinalOptions { crate::pdf_unicode::PdfFinalOptions {
compression: self.parameter(Parameter::Pdfcompresslevel).width(), compression: self.parameter(Parameter::Pdfcompresslevel).width(),
generate_unicode: self.parameter(Parameter::Pdfgentounicode).width(), generate_unicode: self.parameter(Parameter::Pdfgentounicode).width(),
omit_charset: self.parameter(Parameter::Pdfomitcharset).width() != 0,
omit_info: self.parameter(Parameter::Pdfomitinfodict).width() != 0,
glyph_unicode: &self.glyph_unicode, glyph_unicode: &self.glyph_unicode,
fonts: &self.fonts, fonts: &self.fonts,
page_tree_attributes: &self.pdf_pages_attributes, page_tree_attributes: &self.pdf_pages_attributes,
+25 -19
View File
@@ -1507,7 +1507,7 @@ fn native_pdf(
let (catalog, info) = if raw_objects.is_some() { let (catalog, info) = if raw_objects.is_some() {
( (
unicode.and_then(|options| options.catalog).map(|catalog| catalog.entries.as_slice()), unicode.and_then(|options| options.catalog).map(|catalog| catalog.entries.as_slice()),
unicode.map(|options| options.info.entries), unicode.filter(|options| !options.omit_info).map(|options| options.info.entries),
) )
} else { } else {
(None, None) (None, None)
@@ -2176,7 +2176,8 @@ fn write_pdf(
type1_plans.paint(key, program, owner_paint.subset, type1_plans.paint(key, program, owner_paint.subset,
|| native_type1_parameters(program, owner_paint, owner.metrics()), glyphs); || native_type1_parameters(program, owner_paint, owner.metrics()), glyphs);
} }
let type1_references = type1_plans.write(&mut objects, compression)?; let omit_charset = unicode.is_some_and(|options| options.omit_charset);
let type1_references = type1_plans.write(&mut objects, compression, omit_charset)?;
let mut native_font_ids = BTreeMap::new(); let mut native_font_ids = BTreeMap::new();
for (&id, (face, paint, used)) in &native_used { for (&id, (face, paint, used)) in &native_used {
@@ -2936,25 +2937,30 @@ fn write_pdf(
if let Some(level) = final_compression { if let Some(level) = final_compression {
let device = pages[0].pdf.as_ref().expect("validated native PDF options"); let device = pages[0].pdf.as_ref().expect("validated native PDF options");
let info = match unicode { let info = if unicode.is_some_and(|options| options.omit_info) {
Some(options) => { None
let info = crate::pdf_device::PdfInfo { } else {
entries: remapped.as_ref().and_then(|resources| resources.info.as_deref()) let dictionary = match unicode {
.unwrap_or(options.info.entries), Some(options) => {
date: options.info.date, let info = crate::pdf_device::PdfInfo {
}; entries: remapped.as_ref().and_then(|resources| resources.info.as_deref())
if device.driver == crate::pdf_device::PdfDriver::Xdv { .unwrap_or(options.info.entries),
crate::pdf_device::xdv_document::information_dictionary(info, diagnostics)? date: options.info.date,
} else { };
native_information_dictionary(info) if device.driver == crate::pdf_device::PdfDriver::Xdv {
crate::pdf_device::xdv_document::information_dictionary(info, diagnostics)?
} else {
native_information_dictionary(info)
}
} }
} None => metadata_object(metadata)
None => metadata_object(metadata) .map(String::into_bytes)
.map(String::into_bytes) .unwrap_or_else(|| b"<< /Producer (texrra Route-D native) >>".to_vec()),
.unwrap_or_else(|| b"<< /Producer (texrra Route-D native) >>".to_vec()), };
objects.push(dictionary);
Some(objects.len())
}; };
objects.push(info); return Ok(objects::serialize(&objects, info, &device.file, level.clamp(0, 9) as u8));
return Ok(objects::serialize(&objects, Some(objects.len()), &device.file, level.max(0).min(9) as u8));
} }
let info_ref = match metadata_object(metadata) { let info_ref = match metadata_object(metadata) {
@@ -83,6 +83,7 @@ impl<'a> FontPlans<'a> {
self, self,
objects: &mut Vec<Vec<u8>>, objects: &mut Vec<Vec<u8>>,
compression: u8, compression: u8,
omit_charset: bool,
) -> Result<References<'a>, String> { ) -> Result<References<'a>, String> {
let mut plans: Vec<_> = self.0.into_iter().collect(); let mut plans: Vec<_> = self.0.into_iter().collect();
plans.sort_unstable_by(|((a, at), _), ((b, bt), _)| { plans.sort_unstable_by(|((a, at), _), ((b, bt), _)| {
@@ -109,7 +110,7 @@ impl<'a> FontPlans<'a> {
objects, objects,
&subset.name, &subset.name,
&plan.parameters, &plan.parameters,
Some(&subset.glyphs), (!omit_charset).then_some(&subset.glyphs),
&subset.program, &subset.program,
lengths, lengths,
compression, compression,
@@ -129,6 +129,8 @@ pub use crate::pdf::opentype_unicode::XdvGlyphNames;
pub struct PdfFinalOptions<'a> { pub struct PdfFinalOptions<'a> {
pub compression: i32, pub compression: i32,
pub generate_unicode: i32, pub generate_unicode: i32,
pub(crate) omit_charset: bool,
pub(crate) omit_info: bool,
pub glyph_unicode: &'a GlyphUnicodeMap, pub glyph_unicode: &'a GlyphUnicodeMap,
pub fonts: &'a crate::execution::FontCatalog, pub fonts: &'a crate::execution::FontCatalog,
pub page_tree_attributes: &'a [u8], pub page_tree_attributes: &'a [u8],
+35
View File
@@ -2175,6 +2175,41 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
全量编译一致。incremental-receipt.json 的 SHA-256 为 全量编译一致。incremental-receipt.json 的 SHA-256 为
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。 bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
### pdfTeX 作业末尾的字形表和文档信息开关
\pdfomitcharset 和 \pdfomitinfodict 通过普通整数参数进入 TeX
分组、赋值、别名和算术。最后一次出页之后的有效值参与 PDF
写出。非零的 \pdfomitcharset 省去本作业写出的 Type1 子集描述符
上的 CharSet,沿用实际字体程序和子集名。逐字复制的导入描述符
仍拥有自己的 CharSet。非零的 \pdfomitinfodict 省去实际文档信息
对象与交叉引用中的 Info,保留原有 \pdfinfo 参数扫描。
[参考 Type1 描述符写出](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/writefont.c#L478-L510)
[参考最终 Info 与交叉引用](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L19967-L19981)
十个定向用例核对默认值、分组恢复、全局别名赋值、负值、出页后
赋值、复制及重映射字体、普通与对象流交叉引用。提取的字体参数、
信息和对象引用与参考一致。三份候选输出的实际 CMR10 子集程序
逐字节相同。选取的五页词框和 144 DPI 灰度图一致。
schema78 已实测加载新增的直接参数。schema79 保存自定义整数值。
原样 pdflatex.ini 重新生成 schema79,实际 expl3 初始化绑定了
\tex_pdfomitcharset:D。新镜像加载后,该别名和 Info 开关实际
作用于 article 的一页输出,与参考相符。XeTeX 的命令表核对通过。
旧镜像上的原样 arXiv 运行三轮 LaTeX 与真实 BibTeX。三页 PDF
与前版逐字节一致,三轮 aux 和 bbl 与冻结参考逐字节一致。
只改末尾配置文件的四次成功修订各复用 183 步、重放四次文件
调用。每次与独立全量的 PDF、SVG、来源图、aux 相同。一次错误
保留最近发布的 PDF 和实际 aux。页面 SVG 字节保持一致。当前
预览在完整 PDF 字节修改后仍会重新渲染并交付第二页,第二页
包含导入 PDF。此复现留作实时复用的后续入口。
回执 target/p3-pdf-output-metadata/receipt.json 的 SHA-256 为
90f03fe7f8b7201127064dec64329e39ccbcf42984d09d04ce227bffd1104f1b。
下一输出缺口为 \pdfomitprocset。已冻结出页与局部分组、PDF 2.0
下的符号选择,以及原始灰度 JPEG 和透明索引 PNG 的实际页面
资源数组。原生目前缺少参数及相应生成。用例和首个失败在同目录
reference 和 candidate。
### pdfTeX 文档级 Type1 子集与描述符共享 ### pdfTeX 文档级 Type1 子集与描述符共享
PDF 写出时以实际 PFB 的已核验版本和字体变换为键,合并正文与各 PDF 写出时以实际 PFB 的已核验版本和字体变换为键,合并正文与各