Track pdfTeX expanded text with its active PDF matrix
This commit is contained in:
1 parent
bd840df538
commit
9ae7c6a6df
3 files changed
+106
-32
No files matched your search
@@ -16,6 +16,7 @@ pub(super) struct NativeText {
|
||||
font: Option<FontId>,
|
||||
effective_size: i64,
|
||||
expansion: i32,
|
||||
xdv: bool,
|
||||
v: i64,
|
||||
start_h: i64,
|
||||
delta_h: i64,
|
||||
@@ -50,6 +51,7 @@ impl NativeText {
|
||||
font: None,
|
||||
effective_size: 0,
|
||||
expansion: 0,
|
||||
xdv: xdv_origin.is_some(),
|
||||
v: xdv_origin.unwrap_or(height),
|
||||
start_h: xdv_origin.unwrap_or(0),
|
||||
delta_h: 0,
|
||||
@@ -59,7 +61,7 @@ impl NativeText {
|
||||
if space == Some(SpaceUse::InFont) {
|
||||
out.push_str("<20>");
|
||||
let (_, size) = divide_scaled(font.size_sp(), 6_578_176, 6);
|
||||
state.delta_h += Self::char_advance(font, paint, b' ', size);
|
||||
state.delta_h += state.char_advance(font, paint, b' ', size);
|
||||
}
|
||||
if space == Some(SpaceUse::Dedicated) {
|
||||
let dedicated = dedicated.expect("resolved PDF space font");
|
||||
@@ -67,7 +69,8 @@ impl NativeText {
|
||||
out.push_str("( ) Tj\n");
|
||||
}
|
||||
state.select_font(out, font);
|
||||
if state.expansion != font.expansion {
|
||||
let expansion_changed = state.expansion != font.expansion;
|
||||
if state.xdv && expansion_changed {
|
||||
state.close_string(out);
|
||||
state.expansion = font.expansion;
|
||||
if !out.measuring {
|
||||
@@ -77,20 +80,38 @@ impl NativeText {
|
||||
));
|
||||
}
|
||||
}
|
||||
let (mut shift, shift_out) = state.horizontal_move(x, state.effective_size, font.expansion);
|
||||
let (mut shift, shift_out) = state.horizontal_move(x, state.effective_size);
|
||||
let (v, v_out) = state.vertical_move(y, digits);
|
||||
if first || v != 0 || shift.abs() >= 32768 || space == Some(SpaceUse::Dedicated) {
|
||||
if first || v != 0 || shift.abs() >= 32768 || space == Some(SpaceUse::Dedicated)
|
||||
|| (!state.xdv && expansion_changed)
|
||||
{
|
||||
state.close_string(out);
|
||||
let (h, h_out) = divide_scaled(x - state.start_h, 6_578_176, digits + 2);
|
||||
if !out.measuring {
|
||||
out.push_str(&format!(
|
||||
"{} {} Td\n",
|
||||
print_decimal(h, digits),
|
||||
print_decimal(v, digits)
|
||||
));
|
||||
if !state.xdv && (font.expansion != 0 || state.expansion != 0) {
|
||||
let (h, h_out) = divide_scaled(x, 6_578_176, digits + 2);
|
||||
let (v, v_out) = divide_scaled(height - y, 6_578_176, digits + 2);
|
||||
if !out.measuring {
|
||||
out.push_str(&format!(
|
||||
"{} 0 0 1 {} {} Tm\n",
|
||||
print_decimal(i64::from(1000 + font.expansion), 3),
|
||||
print_decimal(h, digits),
|
||||
print_decimal(v, digits),
|
||||
));
|
||||
}
|
||||
state.start_h = h_out;
|
||||
state.v = height - v_out;
|
||||
state.expansion = font.expansion;
|
||||
} else {
|
||||
let (h, h_out) = divide_scaled(x - state.start_h, 6_578_176, digits + 2);
|
||||
if !out.measuring {
|
||||
out.push_str(&format!(
|
||||
"{} {} Td\n",
|
||||
print_decimal(h, digits),
|
||||
print_decimal(v, digits),
|
||||
));
|
||||
}
|
||||
state.start_h += h_out;
|
||||
state.v -= v_out;
|
||||
}
|
||||
state.start_h += h_out;
|
||||
state.v -= v_out;
|
||||
state.delta_h = 0;
|
||||
shift = 0;
|
||||
}
|
||||
@@ -107,7 +128,7 @@ impl NativeText {
|
||||
if !out.measuring {
|
||||
out.push_str(&format!("<{slot:02X}>"));
|
||||
}
|
||||
state.delta_h += Self::char_advance(font, paint, slot, state.effective_size);
|
||||
state.delta_h += state.char_advance(font, paint, slot, state.effective_size);
|
||||
}
|
||||
|
||||
fn select_font(&mut self, out: &mut PageContent, font: &NativeFont) {
|
||||
@@ -127,37 +148,46 @@ impl NativeText {
|
||||
}
|
||||
|
||||
fn char_advance(
|
||||
&self,
|
||||
font: &NativeFont,
|
||||
paint: &crate::native_font::NativeFontPaint,
|
||||
slot: u8,
|
||||
size: i64,
|
||||
) -> i64 {
|
||||
let expansion = if self.xdv { font.expansion } else { self.expansion };
|
||||
let advance = match &paint.program {
|
||||
crate::native_font::NativeFontProgram::Pk(pk) => pk.advances[&slot],
|
||||
crate::native_font::NativeFontProgram::Type1(_) => {
|
||||
let width = if font.layout_metrics.is_some() {
|
||||
let width = font.advance(slot);
|
||||
let factor = i64::from(1000 + font.expansion);
|
||||
width.signum() * ((1000 * width.abs() + factor / 2) / factor)
|
||||
let factor = i64::from(1000 + expansion);
|
||||
let width = if !self.xdv || font.layout_metrics.is_some() {
|
||||
Self::round_scale(font.advance(slot), 1000, factor)
|
||||
} else {
|
||||
font.metrics().width(char::from(slot))
|
||||
};
|
||||
divide_scaled(width, size, 4).1
|
||||
let (units, advance) = divide_scaled(width, size, 4);
|
||||
if expansion != 0 && !self.xdv {
|
||||
Self::round_scale(size * units, 1, 10_000)
|
||||
} else {
|
||||
advance
|
||||
}
|
||||
}
|
||||
};
|
||||
if font.expansion == 0 {
|
||||
advance
|
||||
} else {
|
||||
crate::pdf_device::magnify(advance, 1000 + font.expansion)
|
||||
}
|
||||
crate::pdf_device::magnify(advance, 1000 + expansion)
|
||||
}
|
||||
|
||||
fn horizontal_move(&self, x: i64, size: i64, expansion: i32) -> (i64, i64) {
|
||||
divide_scaled(
|
||||
x - self.start_h - self.delta_h,
|
||||
Self::expanded_size(size, expansion),
|
||||
3,
|
||||
)
|
||||
fn horizontal_move(&self, x: i64, size: i64) -> (i64, i64) {
|
||||
let delta = x - self.start_h - self.delta_h;
|
||||
if self.expansion == 0 || self.xdv {
|
||||
return divide_scaled(delta, Self::expanded_size(size, self.expansion), 3);
|
||||
}
|
||||
let unscaled = Self::round_scale(delta, 1000, i64::from(1000 + self.expansion));
|
||||
let (units, _) = divide_scaled(unscaled, size, 3);
|
||||
let advance = Self::round_scale(size * units, 1, 1000);
|
||||
(units, crate::pdf_device::magnify(advance, 1000 + self.expansion))
|
||||
}
|
||||
|
||||
fn round_scale(value: i64, multiplier: i64, denominator: i64) -> i64 {
|
||||
value.signum() * ((value.abs() * multiplier + denominator / 2) / denominator)
|
||||
}
|
||||
|
||||
fn expanded_size(size: i64, expansion: i32) -> i64 {
|
||||
@@ -218,7 +248,7 @@ impl NativeText {
|
||||
pub(super) fn finish(text: &mut Option<Self>, out: &mut PageContent) {
|
||||
if let Some(mut text) = text.take() {
|
||||
text.close_string(out);
|
||||
if text.expansion != 0 {
|
||||
if text.xdv && text.expansion != 0 {
|
||||
out.push_str("100 Tz\n");
|
||||
}
|
||||
out.push_str("ET\n");
|
||||
@@ -344,7 +374,7 @@ pub(crate) fn plan_spaces(
|
||||
});
|
||||
let prior_size = NativeText::expanded_size(size, cursor.expansion);
|
||||
let movement = if prior_size > 0 {
|
||||
cursor.horizontal_move(*x, size, cursor.expansion).1
|
||||
cursor.horizontal_move(*x, size).1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
@@ -2175,6 +2175,37 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### 原样 arXiv 三轮收敛与 pdfTeX 伸缩文字定位
|
||||
|
||||
原样 `pdflatex.ini` 重建 schema78,用时189.3秒。核验实际入口、
|
||||
kernel、firstaid、冻结参考格式、字体映射和六项原样工程输入。旧
|
||||
schema39 可以编译,但缺少格式初始化后加入的 `\pdflastlink`,
|
||||
hyperref 因而少写两条 aux 注册记录。用当前格式后,原生和参考
|
||||
各完成三轮 LaTeX 和一次独立 BibTeX,逐轮 aux 和 bbl 与参考
|
||||
逐字节一致,终轮无未定义引用。
|
||||
|
||||
原生 pdfTeX 的自动字宽伸缩使用实际文字矩阵。切换伸缩量或移动到
|
||||
新行时重建绝对文字位置,按活动矩阵比例计算相对位移。字符前进和
|
||||
字距分别使用四位和三位字体单位的整数网格,并按对应顺序恢复到
|
||||
TeX sp。XDV 路径沿用其设备坐标。
|
||||
[参考字符前进](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L15887-L15934)
|
||||
[参考文字矩阵](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16057-L16088)
|
||||
[参考字距及取整](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16237-L16294)
|
||||
|
||||
同一 schema78 的修正前后,三页原生共有6918个原始字形和16条规则,
|
||||
坐标、画序和页面尺寸一致。修正后与参考的1221个词条同序,三页
|
||||
144 DPI 灰度差分别从10398、15324、949降至8579、15230、949。
|
||||
词框最大差仍为0.071900 bp。独立的 Times 混合字体小样第三页少
|
||||
33个像素差,另两页保持486和583个差异。固定极限小样的三页差异
|
||||
保持不变。两个既有未伸缩 pdfTeX 和混合 XDV PDF 小样各自前后
|
||||
字节一致。样稿内仍有段落伸缩量差异,例如参考 +19‰、原生 +18‰。
|
||||
|
||||
三次跨文件改动真实装盒宽度,各复用99步,仅第二页变化。检查实际
|
||||
伸缩字形及来源命中,PDF、SVG、来源图和实际 aux 与同初始状态的
|
||||
独立全量一致。保留最早 aux 差异、独立样例的类型扫描过程和项目
|
||||
资源边界的初次失败。回执 `target/p3-arxiv-current-drivers/receipt.json`
|
||||
SHA-256 为 `7846698f7a74d8f75128d05563a7621ba8e55b3e981f7cf316e666c7baafe37f`。
|
||||
|
||||
### XDV 的 PDF 文字游标与 Type 1 字体度量
|
||||
|
||||
XDV 的 OpenType 字距累计保留起点坐标取整后的余量。真实文字游标继续
|
||||
|
||||
@@ -476,6 +476,19 @@ schema37 优化版使用冻结输入耗时197.5秒生成原样格式,LaTeX 自
|
||||
- `target/p3-margin-kern-query-native/format/receipt.json` 为 `a9484ec1c83d7f1f420028003f5f422a0e45b5bd7c06f62eb4c98252dc3cdf6d`。
|
||||
- `target/p3-margin-kern-query-native/arxiv/receipt.json` 为 `85b2ee927455fae5f72d4aeb8373ffd27d6452d21c8c8fceadbd4a3be3a0f9a2`。
|
||||
|
||||
### 原样 arXiv 三轮作业与 PDF 文字定位
|
||||
|
||||
用六项原样输入、冻结参考格式和字体映射继续至稳定输出。当前原样
|
||||
`pdflatex.ini` 生成 schema78。参考和原生各独立执行一次 BibTeX
|
||||
及三轮 LaTeX,三轮 aux、实际 bbl 均逐字节一致,终轮无未定义
|
||||
引用。旧 schema39 的两条 hyperref aux 注册差异保留在原对照。
|
||||
|
||||
原生文字矩阵修正后,三页的1221个提取词与参考同序。144 DPI 灰度
|
||||
像素差从26671降至24758,最大词框差仍为0.071900 bp。两版原生
|
||||
6918个原始字形的位置和16条规则的顺序一致。实际段落的剩余伸缩
|
||||
比例与整页墨迹继续对照。
|
||||
[阶段记录](P2_M1_PROGRESS.md#原样-arxiv-三轮收敛与-pdftex-伸缩文字定位)
|
||||
|
||||
### Elsevier CAS 双栏首轮输出
|
||||
|
||||
通用展开调度改动通过了实际图像高度与 LaTeX 浮点公式的差分。
|
||||
|
||||
Reference in new issue
Block a user