Write per-page pdfTeX ProcSet from shipped resources
This commit is contained in:
1 parent
de481fd762
commit
1fe0ac9dd5
10 files changed
+162
-15
No files matched your search
@@ -298,13 +298,17 @@ impl Executor {
|
||||
InputProfile::UnicodeScalar | InputProfile::XeTeX => PdfDriver::Xdv,
|
||||
};
|
||||
let mut file = self.state.pdf_file_options.clone().unwrap();
|
||||
if driver == PdfDriver::Xdv {
|
||||
let omit_procset = if driver == PdfDriver::PdfTeX {
|
||||
self.read_parameter(Parameter::Pdfomitprocset).width()
|
||||
} else {
|
||||
self.state.xdv_setup.apply_version(&mut file);
|
||||
}
|
||||
0
|
||||
};
|
||||
Ok(Some(PdfPageData {
|
||||
driver,
|
||||
file,
|
||||
stream_compression: level.max(0) as u8,
|
||||
omit_procset,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 79;
|
||||
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, 78, SCHEMA,
|
||||
const SCHEMA: u32 = 80;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 47] = [
|
||||
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, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -137,7 +137,13 @@ impl FormatImage {
|
||||
image.state.restore_legacy_mathcodes()?;
|
||||
}
|
||||
if image.schema < 79 {
|
||||
image.state.restore_legacy_pdf_omission_parameters();
|
||||
image.state.restore_legacy_pdf_parameters(&[
|
||||
Parameter::Pdfomitcharset,
|
||||
Parameter::Pdfomitinfodict,
|
||||
]);
|
||||
}
|
||||
if image.schema < 80 {
|
||||
image.state.restore_legacy_pdf_parameters(&[Parameter::Pdfomitprocset]);
|
||||
}
|
||||
image.schema = SCHEMA;
|
||||
Ok(image)
|
||||
|
||||
@@ -19,6 +19,7 @@ pub enum Parameter {
|
||||
Pdfinfoomitdate,
|
||||
Pdfomitcharset,
|
||||
Pdfomitinfodict,
|
||||
Pdfomitprocset,
|
||||
Tracingcommands,
|
||||
Tracingrestores,
|
||||
Tracingassigns,
|
||||
@@ -158,6 +159,7 @@ impl Parameter {
|
||||
| Self::Pdfinfoomitdate
|
||||
| Self::Pdfomitcharset
|
||||
| Self::Pdfomitinfodict
|
||||
| Self::Pdfomitprocset
|
||||
| Self::Pdfhorigin
|
||||
| Self::Pdfvorigin
|
||||
| Self::Pdflinkmargin
|
||||
@@ -198,6 +200,7 @@ impl Parameter {
|
||||
Self::Pdfinfoomitdate,
|
||||
Self::Pdfomitcharset,
|
||||
Self::Pdfomitinfodict,
|
||||
Self::Pdfomitprocset,
|
||||
Self::Tracingcommands,
|
||||
Self::Tracingrestores,
|
||||
Self::Tracingassigns,
|
||||
|
||||
@@ -1676,12 +1676,10 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn restore_legacy_pdf_omission_parameters(&mut self) {
|
||||
pub(super) fn restore_legacy_pdf_parameters(&mut self, parameters: &[Parameter]) {
|
||||
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));
|
||||
for ¶meter in parameters {
|
||||
self.update_profile_command(¶meter.name(), Meaning::Parameter(parameter), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -655,6 +655,39 @@ impl PageContent {
|
||||
}
|
||||
}
|
||||
|
||||
fn append_page_procset(output: &mut Vec<u8>, page: &DisplayList, has_rgb_image: bool) {
|
||||
use crate::pdf_image::RasterProcSet;
|
||||
let mut text = page.pdf_space_plan.as_ref().is_some_and(|plan| plan.dedicated.is_some());
|
||||
let mut gray = false;
|
||||
let mut color = has_rgb_image;
|
||||
let mut indexed = false;
|
||||
for item in &page.items {
|
||||
match item {
|
||||
DisplayItem::NativeGlyph { .. } | DisplayItem::OpenTypeGlyph { .. }
|
||||
| DisplayItem::MathGlyph { .. } | DisplayItem::Text { .. } => text = true,
|
||||
DisplayItem::PdfImage { image, .. } => match image.image.raster_procset() {
|
||||
Some(RasterProcSet::Gray) => gray = true,
|
||||
Some(RasterProcSet::Color) => color = true,
|
||||
Some(RasterProcSet::Indexed) => indexed = true,
|
||||
None => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
output.extend_from_slice(b" /ProcSet [/PDF");
|
||||
for (used, name) in [
|
||||
(text, b" /Text".as_slice()),
|
||||
(gray, b" /ImageB"),
|
||||
(color || indexed, b" /ImageC"),
|
||||
(indexed, b" /ImageI"),
|
||||
] {
|
||||
if used {
|
||||
output.extend_from_slice(name);
|
||||
}
|
||||
}
|
||||
output.push(b']');
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_text_spaces(
|
||||
pages: &mut [DisplayList],
|
||||
mut resolve: impl FnMut(
|
||||
@@ -2539,11 +2572,15 @@ fn write_pdf(
|
||||
page.extend_from_slice(format!(" /MediaBox [0 0 {} {}]", physical(width), physical(height)).as_bytes());
|
||||
}
|
||||
page.extend_from_slice(b" /Resources ");
|
||||
if let Some(additional) = remapped.as_ref().map(|resources| &resources.pages[page_index])
|
||||
&& !additional.is_empty()
|
||||
{
|
||||
let additional = remapped.as_ref().map(|resources| resources.pages[page_index].as_slice())
|
||||
.unwrap_or_default();
|
||||
let writes_procset = list.pdf.as_ref().is_some_and(|pdf| pdf.writes_procset());
|
||||
if !additional.is_empty() || writes_procset {
|
||||
page.extend_from_slice(&resources.as_bytes()[..resources.len() - 2]);
|
||||
page.extend_from_slice(additional);
|
||||
if writes_procset {
|
||||
append_page_procset(&mut page, list, !used.is_empty());
|
||||
}
|
||||
page.extend_from_slice(b" >>");
|
||||
} else {
|
||||
page.extend_from_slice(resources.as_bytes());
|
||||
|
||||
@@ -32,6 +32,19 @@ pub struct PdfPageData {
|
||||
pub driver: PdfDriver,
|
||||
pub file: PdfFileOptions,
|
||||
pub stream_compression: u8,
|
||||
#[serde(default, skip_serializing_if = "is_zero")]
|
||||
pub omit_procset: i32,
|
||||
}
|
||||
|
||||
fn is_zero(value: &i32) -> bool {
|
||||
*value == 0
|
||||
}
|
||||
|
||||
impl PdfPageData {
|
||||
pub(crate) fn writes_procset(&self) -> bool {
|
||||
self.driver == PdfDriver::PdfTeX
|
||||
&& (self.omit_procset < 0 || (self.omit_procset == 0 && self.file.major < 2))
|
||||
}
|
||||
}
|
||||
|
||||
/// TeX round_xn_over_d, including signed halfway cases.
|
||||
|
||||
@@ -326,6 +326,8 @@ enum Part {
|
||||
Jpeg {
|
||||
size: [u16; 2],
|
||||
precision: u8,
|
||||
#[serde(default)]
|
||||
components: u8,
|
||||
bytes: Vec<u8>,
|
||||
},
|
||||
Png(png::SampledImage),
|
||||
@@ -334,6 +336,12 @@ enum Part {
|
||||
MappedType1(Arc<ImportedType1Use>),
|
||||
}
|
||||
|
||||
pub(crate) enum RasterProcSet {
|
||||
Gray,
|
||||
Color,
|
||||
Indexed,
|
||||
}
|
||||
|
||||
pub(crate) fn real(value: f64) -> String {
|
||||
let body = format!("{value:.15}");
|
||||
body.trim_end_matches('0').trim_end_matches('.').to_owned()
|
||||
@@ -425,6 +433,7 @@ impl PdfImage {
|
||||
parts.push(Part::Jpeg {
|
||||
size: header.size,
|
||||
precision: header.precision,
|
||||
components: header.components,
|
||||
bytes: resource.data,
|
||||
});
|
||||
parts.push(Part::Bytes(b"\nendstream".to_vec()));
|
||||
@@ -516,6 +525,21 @@ impl PdfImage {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn raster_procset(&self) -> Option<RasterProcSet> {
|
||||
self.objects.first()?.iter().find_map(|part| match part {
|
||||
Part::Jpeg { components, bytes, .. } => {
|
||||
let components = if *components == 0 {
|
||||
jpeg::read(bytes).ok()?.components
|
||||
} else {
|
||||
*components
|
||||
};
|
||||
Some(if components == 1 { RasterProcSet::Gray } else { RasterProcSet::Color })
|
||||
}
|
||||
Part::Png(samples) => Some(samples.procset()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn sampled_image(&self) -> Option<&png::SampledImage> {
|
||||
match self.objects.first()?.as_slice() {
|
||||
[Part::Png(samples) | Part::Bmp(samples)] => Some(samples),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Decode PNG samples for native PDF image XObjects.
|
||||
use super::{Part, PdfImage};
|
||||
use super::{Part, PdfImage, RasterProcSet};
|
||||
use crate::{pdf::objects, resources::LoadedResource};
|
||||
use ::png::{ColorType, Decoder, PixelDimensions, Transformations, Unit};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -18,6 +18,8 @@ enum ColorSpace {
|
||||
pub(super) struct SampledImage {
|
||||
pub(super) size: [u32; 2],
|
||||
pub(super) source_depth: u8,
|
||||
#[serde(default)]
|
||||
source_indexed: bool,
|
||||
depth: u8,
|
||||
color: ColorSpace,
|
||||
samples: Vec<u8>,
|
||||
@@ -34,6 +36,7 @@ pub(super) fn decode(bytes: &[u8]) -> Result<(SampledImage, Option<PixelDimensio
|
||||
let mut reader = read_info(Transformations::IDENTITY)?;
|
||||
let [width, height] = [reader.info().width, reader.info().height];
|
||||
let source_depth = reader.info().bit_depth as u8;
|
||||
let source_indexed = reader.info().color_type == ColorType::Indexed;
|
||||
// Preserve packed grayscale and palettes unless tRNS needs an alpha channel.
|
||||
if reader.info().trns.is_some() {
|
||||
reader = read_info(Transformations::EXPAND)?;
|
||||
@@ -90,6 +93,7 @@ pub(super) fn decode(bytes: &[u8]) -> Result<(SampledImage, Option<PixelDimensio
|
||||
SampledImage {
|
||||
size: [width, height],
|
||||
source_depth,
|
||||
source_indexed,
|
||||
depth,
|
||||
color,
|
||||
samples: buf,
|
||||
@@ -147,6 +151,7 @@ impl SampledImage {
|
||||
Self {
|
||||
size,
|
||||
source_depth: 8,
|
||||
source_indexed: false,
|
||||
depth: 8,
|
||||
color: ColorSpace::Rgb,
|
||||
samples,
|
||||
@@ -154,6 +159,17 @@ impl SampledImage {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn procset(&self) -> RasterProcSet {
|
||||
// Expanding a PNG transparency table may change the decoded colors.
|
||||
if self.source_indexed || matches!(self.color, ColorSpace::Indexed(_)) {
|
||||
RasterProcSet::Indexed
|
||||
} else if matches!(self.color, ColorSpace::Gray) {
|
||||
RasterProcSet::Gray
|
||||
} else {
|
||||
RasterProcSet::Color
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn has_alpha(&self, pdf_version: (i32, i32)) -> bool {
|
||||
pdf_version >= (1, 4) && !self.alpha.is_empty()
|
||||
}
|
||||
|
||||
@@ -2175,6 +2175,44 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### pdfTeX 每页 ProcSet 与实际使用的资源
|
||||
|
||||
\pdfomitprocset 是受作用域管理的整数。出页时记录有效值。负值
|
||||
在所有 PDF 版本生成 ProcSet,零值在 PDF 1.x 生成,正值省去
|
||||
自动生成的条目。用户资源仍参与输出,自动生成项最后写入,
|
||||
与参考的同名资源行为相符。
|
||||
[pdfTeX 页面资源写出顺序与 ProcSet](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L19290-L19386)
|
||||
|
||||
页面资源取实际使用的文字、假空格字体及放置的光栅图。JPEG
|
||||
以分量分类。PNG 在透明度展开前保存索引类型,带透明色表的
|
||||
索引 PNG 同时记入 ImageC 与 ImageI。导入 PDF 的资源留在
|
||||
各自的表单内。已有 Type 3 字体的内部资源由其设备写出路径处理。
|
||||
[参考 PNG 的原始色表类型](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/writepng.c#L56-L72)
|
||||
|
||||
九个定向用例的 23 页资源数组和两个导入表单的资源与参考相同,
|
||||
覆盖规则、空白页、实际文字、未放置图像、灰度与彩色图、逐页
|
||||
分组、负值与 PDF 2.0。显式假空格进入 Text。其 PdfTeX-Space
|
||||
物理字体的子集和编码差异也存在于前版,单独保留对照。旧
|
||||
schema79 已加载新参数,schema80 保存并恢复参数值。XeTeX 的
|
||||
profile 文本检查通过。另保留带装箱 PNG 的 INITEX 对照,
|
||||
参考可 dump 后重载图像,原生此前已明确拒绝该格式内容。
|
||||
|
||||
四次只编辑第二页局部设置的跨文件修订各复用 109 步、重放四次
|
||||
文件调用。三页中只有第二页的 PDF 资源声明变化,预览替换零页。
|
||||
各次的 PDF、SVG、来源图和 aux 均与同初态独立全量一致。
|
||||
原样 Elsevier CAS 双栏经过三轮 LaTeX 与实际 BibTeX,六页的
|
||||
ProcSet、10372 个字形、1889 个词框、144 DPI 灰度图以及逐轮
|
||||
aux 和 bbl 与冻结参考一致。
|
||||
|
||||
回执 target/p3-pdf-page-procsets/receipt.json 的 SHA-256 为
|
||||
12337474673542c51c00a8dbe20c59f5b36b2e39ba0fe523d53cc4cbb2c9869f。
|
||||
下一项为导入 PDF 版本检查及 \pdfinclusionerrorlevel。参考端已
|
||||
固定警告、拒绝、安静处理、PDF 2.0 文件头及 Catalog Version 的
|
||||
实际边界。原生此前接受新版文件时漏警告,正值场景报告参数未
|
||||
定义,检查版本改变的错误位置也滞后。原始证据在同目录
|
||||
next-inclusion-version。
|
||||
[参考导入版本检查](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftoepdf.cc#L725-L743)
|
||||
|
||||
### pdfTeX 作业末尾的字形表和文档信息开关
|
||||
|
||||
\pdfomitcharset 和 \pdfomitinfodict 通过普通整数参数进入 TeX
|
||||
|
||||
@@ -977,6 +977,14 @@ LuaLaTex、languages 和 argues 的断行与冻结参考一致。PDF 提取的
|
||||
字形提取仍待对照,当前整页版面门禁保持未通过。
|
||||
阶段回执 `target/p3-xetex-native-hyphenation/receipt.json`。
|
||||
|
||||
### Elsevier CAS 双栏逐页资源
|
||||
|
||||
原样 CAS 双栏的 30 项交付、schema51、实际字体映射和冻结参考
|
||||
用同一配置。三轮 LaTeX 和实际 BibTeX 的 aux 及 bbl 一致。
|
||||
六页的 ProcSet 与参考一致,10372 个原始字形位置、1889 个
|
||||
词框与 144 DPI 灰度图也一致。
|
||||
[阶段记录](P2_M1_PROGRESS.md#pdftex-每页-procset-与实际使用的资源)
|
||||
|
||||
### 文档级字体共享后的 arXiv 与 Elsevier CAS 双栏
|
||||
|
||||
两份原样交付在同一原生可执行文件上各运行三轮 LaTeX 和一次实际
|
||||
|
||||
Reference in new issue
Block a user