Write native XDV PDF versions and compact object streams
This commit is contained in:
1 parent
48d42052b8
commit
b37856eeb0
7 files changed
+102
-20
No files matched your search
@@ -101,10 +101,12 @@ impl Executor {
|
||||
if self.state.output_mode_set != Some(mode) {
|
||||
return self.fail("native pdfoutput cannot change after output has started");
|
||||
}
|
||||
let major = self.read_parameter(Parameter::Pdfmajorversion).width();
|
||||
let minor = self.read_parameter(Parameter::Pdfminorversion).width();
|
||||
if options.major != major || i32::from(options.minor) != minor {
|
||||
return self.fail("native PDF version cannot change after output has started");
|
||||
if self.state.input_profile() != InputProfile::XeTeX {
|
||||
let major = self.read_parameter(Parameter::Pdfmajorversion).width();
|
||||
let minor = self.read_parameter(Parameter::Pdfminorversion).width();
|
||||
if options.major != major || i32::from(options.minor) != minor {
|
||||
return self.fail("native PDF version cannot change after output has started");
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -243,6 +245,15 @@ impl Executor {
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<PdfHeaderOptions, Error> {
|
||||
self.reads.insert(Dependency::PdfFileState);
|
||||
if self.state.input_profile() == InputProfile::XeTeX {
|
||||
// The first XDV page can override these driver defaults through its specials.
|
||||
return Ok(*self.state.pdf_header_options.get_or_insert(PdfHeaderOptions {
|
||||
major: 1,
|
||||
minor: 5,
|
||||
object_compression: 3,
|
||||
draft_mode: false,
|
||||
}));
|
||||
}
|
||||
if self.state.input_profile() == InputProfile::TeX8Bit {
|
||||
self.pdf_copy_imported_fonts();
|
||||
}
|
||||
@@ -349,7 +360,7 @@ impl Executor {
|
||||
let omit_procset = if driver == PdfDriver::PdfTeX {
|
||||
self.read_parameter(Parameter::Pdfomitprocset).width()
|
||||
} else {
|
||||
self.state.xdv_setup.apply_version(&mut file);
|
||||
self.state.xdv_setup.apply_file_options(&mut file);
|
||||
0
|
||||
};
|
||||
Ok(Some(PdfPageData {
|
||||
|
||||
@@ -973,7 +973,7 @@ impl Executor {
|
||||
if shipout.pdf_background.as_ref().is_some_and(|program| !program.xdv_resources.is_empty()) {
|
||||
self.reads.insert(Dependency::PdfCatalogState);
|
||||
}
|
||||
self.state.xdv_setup.apply_version(&mut pdf.file);
|
||||
self.state.xdv_setup.apply_file_options(&mut pdf.file);
|
||||
}
|
||||
self.current = current;
|
||||
Ok((shipout, pdf_forms, probed_page))
|
||||
|
||||
@@ -3826,7 +3826,9 @@ fn write_pdf(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return objects::serialize(&objects, info, &device.file, level.clamp(0, 9) as u8, packing);
|
||||
return objects::serialize(
|
||||
&objects, info, &device.file, device.driver, level.clamp(0, 9) as u8, packing,
|
||||
);
|
||||
}
|
||||
|
||||
let info_ref = match metadata_object(metadata) {
|
||||
|
||||
@@ -11,6 +11,8 @@ pub(crate) struct Setup {
|
||||
major: Option<i32>,
|
||||
minor: Option<u8>,
|
||||
pub(crate) keep_destinations: bool,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
no_object_streams: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) outline_open_depth: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "super::xdv_paper::Paper::is_default")]
|
||||
@@ -76,23 +78,28 @@ impl Setup {
|
||||
};
|
||||
let flags =
|
||||
u32::from_str_radix(digits, radix).map_err(|_| "invalid XDV configuration flags")?;
|
||||
if flags & !0x10 != 0 {
|
||||
const KEEP_DESTINATIONS: u32 = 0x10;
|
||||
const NO_OBJECT_STREAMS: u32 = 0x40;
|
||||
if flags & !(KEEP_DESTINATIONS | NO_OBJECT_STREAMS) != 0 {
|
||||
return Err("unsupported XDV configuration flags".into());
|
||||
}
|
||||
if (sign < 0 && flags != 0) || flags & 0x10 != 0 {
|
||||
self.keep_destinations = flags & 0x10 != 0;
|
||||
if sign < 0 && flags != 0 {
|
||||
self.keep_destinations = false;
|
||||
self.no_object_streams = false;
|
||||
}
|
||||
self.keep_destinations |= flags & KEEP_DESTINATIONS != 0;
|
||||
self.no_object_streams |= flags & NO_OBJECT_STREAMS != 0;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn apply_version(&self, options: &mut PdfFileOptions) {
|
||||
pub(crate) fn apply_file_options(&self, options: &mut PdfFileOptions) {
|
||||
if let Some(value) = self.major {
|
||||
options.major = value;
|
||||
}
|
||||
if let Some(value) = self.minor {
|
||||
options.minor = value;
|
||||
}
|
||||
if options.major == 1 && options.minor < 5 {
|
||||
if self.no_object_streams || (options.major == 1 && options.minor < 5) {
|
||||
options.object_compression = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
//! PDF streams, object streams and cross-reference serialization.
|
||||
use crate::pdf_device::{PdfFileOptions, page_resources::OBJECT_STREAM_CAPACITY};
|
||||
use crate::pdf_device::{PdfDriver, PdfFileOptions, page_resources::OBJECT_STREAM_CAPACITY};
|
||||
use std::io::Write;
|
||||
|
||||
const XDV_OBJECT_STREAM_CAPACITY: usize = 200;
|
||||
|
||||
pub(crate) fn stream(extra: &str, data: &[u8], level: u8) -> Vec<u8> {
|
||||
stream_bytes(extra.as_bytes(), data, level)
|
||||
}
|
||||
@@ -40,10 +42,20 @@ pub(super) fn serialize(
|
||||
objects: &[Vec<u8>],
|
||||
info: Option<usize>,
|
||||
options: &PdfFileOptions,
|
||||
driver: PdfDriver,
|
||||
compression: u8,
|
||||
packing: Option<ObjectPacking>,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let xdv = driver == PdfDriver::Xdv;
|
||||
let stream_capacity = if xdv {
|
||||
XDV_OBJECT_STREAM_CAPACITY
|
||||
} else {
|
||||
OBJECT_STREAM_CAPACITY
|
||||
};
|
||||
let mut pdf = format!("%PDF-{}.{}\n", options.major, options.minor).into_bytes();
|
||||
if xdv {
|
||||
pdf.extend_from_slice(b"%\xe4\xf0\xed\xf8\n");
|
||||
}
|
||||
let mut packed = vec![None; objects.len() + 1];
|
||||
let mut stream_slots = vec![false; objects.len() + 1];
|
||||
let mut next_stream = objects.len() + 1;
|
||||
@@ -52,7 +64,7 @@ pub(super) fn serialize(
|
||||
for (id, members) in &groups {
|
||||
if *id == 0 || *id > objects.len() || !objects[*id - 1].is_empty()
|
||||
|| std::mem::replace(&mut stream_slots[*id], true)
|
||||
|| members.is_empty() || members.len() > OBJECT_STREAM_CAPACITY
|
||||
|| members.is_empty() || members.len() > stream_capacity
|
||||
|| options.object_compression == 0
|
||||
{
|
||||
return Err("invalid native PDF object stream slot".into());
|
||||
@@ -94,7 +106,7 @@ pub(super) fn serialize(
|
||||
if options.object_compression < level {
|
||||
continue;
|
||||
}
|
||||
if groups.last().is_none_or(|(_, members)| members.len() == OBJECT_STREAM_CAPACITY) {
|
||||
if groups.last().is_none_or(|(_, members)| members.len() == stream_capacity) {
|
||||
groups.push((next_stream, Vec::new()));
|
||||
next_stream += 1;
|
||||
}
|
||||
@@ -165,7 +177,16 @@ pub(super) fn serialize(
|
||||
} else {
|
||||
let id = offsets.len();
|
||||
offsets.push(xref as u64);
|
||||
let mut entries = Vec::new();
|
||||
let offset_width = if xdv {
|
||||
let last_stream = next_stream - 1;
|
||||
let largest_field = (xref as u64).max(last_stream as u64);
|
||||
let bits = u64::BITS - largest_field.leading_zeros();
|
||||
bits.div_ceil(8).max(1) as usize
|
||||
} else {
|
||||
8
|
||||
};
|
||||
let generation_width = if xdv { 2 } else { 4 };
|
||||
let mut entries = Vec::with_capacity(offsets.len() * (1 + offset_width + generation_width));
|
||||
for (obj, offset) in offsets.iter().enumerate() {
|
||||
let (kind, a, b) = if let Some(Some(next)) = free.get(obj) {
|
||||
(0u8, *next as u64, if obj == 0 { 65535 } else { 0 })
|
||||
@@ -175,13 +196,17 @@ pub(super) fn serialize(
|
||||
(1, *offset, 0)
|
||||
};
|
||||
entries.push(kind);
|
||||
entries.extend_from_slice(&a.to_be_bytes());
|
||||
entries.extend_from_slice(&b.to_be_bytes());
|
||||
entries.extend_from_slice(&a.to_be_bytes()[8 - offset_width..]);
|
||||
entries.extend_from_slice(&b.to_be_bytes()[4 - generation_width..]);
|
||||
}
|
||||
let index = if xdv {
|
||||
String::new() // A single contiguous section uses the default Index.
|
||||
} else {
|
||||
format!(" /Index [0 {}]", offsets.len())
|
||||
};
|
||||
let object = stream(
|
||||
&format!(
|
||||
"/Type /XRef /Size {} /W [1 8 4] /Index [0 {}] /Root 1 0 R{info_ref}",
|
||||
offsets.len(),
|
||||
"/Type /XRef /Size {} /W [1 {offset_width} {generation_width}]{index} /Root 1 0 R{info_ref}",
|
||||
offsets.len()
|
||||
),
|
||||
&entries,
|
||||
|
||||
@@ -682,6 +682,10 @@ fn xdv_destinations_use_shipped_page_ids_and_pdf_string_keys() {
|
||||
shipout_lists_to_native_pdf_document(&pages, result.state.pdf_final_options()).unwrap();
|
||||
let pdf = Document::load_mem(&output.bytes).unwrap();
|
||||
assert_eq!(pdf.version, "1.7");
|
||||
let catalog_number = pdf.trailer.get(b"Root").unwrap().as_reference().unwrap().0;
|
||||
let info_number = pdf.trailer.get(b"Info").unwrap().as_reference().unwrap().0;
|
||||
assert!(pdf.reference_table.get(catalog_number).unwrap().is_compressed());
|
||||
assert!(pdf.reference_table.get(info_number).unwrap().is_compressed());
|
||||
let names = pdf.catalog().unwrap().get(b"Names").unwrap().as_dict().unwrap();
|
||||
let id = names.get(b"Dests").unwrap().as_reference().unwrap();
|
||||
let destinations = pdf.get_object(id).unwrap().as_dict().unwrap()
|
||||
|
||||
@@ -18,6 +18,39 @@
|
||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||
|
||||
## 2026-11-29 XDV 文件版本与对象流
|
||||
|
||||
XeTeX 设备默认写出 PDF 1.5。首页的版本设置决定文档头,
|
||||
首页 dvipdfmx:config C 0x40 可关闭对象流。正值组合标志,
|
||||
负值替换标志,后页继续沿用首页设置。对象流按每组最多
|
||||
200 项写出,交叉引用流按实际偏移选取字段宽度,并记录型别、
|
||||
物理位置及流内索引。PDF 1.4 与禁用对象流的文件写传统交叉引用表。
|
||||
[驱动首页设置](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/dvipdfmx.c#L1138-L1148) · [对象流选择](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/dvipdfmx.c#L1205-L1214) · [交叉引用流](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/pdfobj.c#L606-L648)
|
||||
|
||||
十项真实原版对照覆盖无显式设置、PDF 1.4 和 2.0、后页设置、
|
||||
关闭对象流和标志组合。逐项解析可用的交叉引用、目录和 Info,
|
||||
并核对所有压缩对象的流内位置。210 页文档的候选两组分别包含
|
||||
200 和 13 项。参考把页资源独立编号,因此三组为 200、200 和
|
||||
107 项。物理对象分配仍有差异。页数和选取的首尾页光栅均符合
|
||||
原版。pdfTeX 压缩对照 PDF 与上一版逐字节相同,两项定向回归通过。
|
||||
|
||||
原样 xeCJK 使用压缩的 PDF 1.5。六页的 999 个词、词框、
|
||||
144 DPI 光栅及 aux 匹配参考,SimSun、SimHei 的字形槽、
|
||||
轮廓、提示表和 CIDSet 继续一致。原样 NeurIPS 使用压缩的
|
||||
PDF 1.7,编辑与故障恢复均只转换及发布第 3 页,PDF、SVG、
|
||||
来源、资源与 aux/out 等均与各自独立全量一致。
|
||||
|
||||
三页 XeTeX 项目通过依赖文件在 PDF 1.5 对象流、传统交叉
|
||||
引用及 PDF 2.0 之间切换。1.5 的两种输出保留相同 CIDSet,
|
||||
2.0 省略。切换后改第二页字形只更新第二页并复用 203 个执行步。
|
||||
各版本的版面、PDF、来源映射、预览和辅助文件与全量匹配。
|
||||
首轮 XeTeX 默认值触发了旧的 pdfTeX 收尾校验。修正 XeTeX
|
||||
设备初始化和收尾后,全套定向验证通过,原失败日志保留。
|
||||
|
||||
证据在 target/p3-xdv-object-streams/。SHA256SUMS 指纹为
|
||||
e1e99d965f6c2a5d93f7e202a611b2ebf0b3dede7a1ddcb8c870ee7a20687668。
|
||||
同版出版矩阵与浏览器可见预算继续按原门禁验收。
|
||||
|
||||
## 2026-11-29 字符扫描中的类别查询
|
||||
|
||||
物理输入读取和控制序列前瞻直接返回本次扫描已解析的类别。
|
||||
|
||||
Reference in new issue
Block a user