Merge native paragraph break candidates at the TeX line boundary

This commit is contained in:
gloamxun committed 2026-11-28 10:21:53 +08:00
1 parent 509f229a52
commit a864c6c5ca
3 files changed
+66 -9

No files matched your search

@@ -925,15 +925,20 @@ fn break_lines(
cost: 0,
path: Vec::new(),
}];
let special = if get(Parameter::Looseness) != 0 {
usize::MAX
} else if !shape.is_empty() {
(shape.len() - 1).saturating_sub(previous_lines)
let last_special_line = if !shape.is_empty() {
shape.len() - 1
} else if get(Parameter::Hangindent) == 0 {
0
} else {
get(Parameter::Hangafter).unsigned_abs() as usize
};
let merged_class = if get(Parameter::Looseness) == 0 {
// TeX defers flushing easy_line's minima until after all later lines.
// Its active line numbers start at prev_graf + 1, unlike Active::line.
last_special_line.saturating_sub(previous_lines.saturating_add(1))
} else {
usize::MAX
};
let threshold = if pass == 0 {
get(Parameter::Pretolerance)
} else {
@@ -1098,7 +1103,7 @@ fn break_lines(
cost: a.cost.saturating_add(demerits),
path,
};
let key = (a.line.min(special), 3 - fitness, b.hyphen);
let key = (a.line.min(merged_class), 3 - fitness, b.hyphen);
// TeX initializes each minimum to awful_bad (2^30-1).
// Costs beyond that bound are not feasible active nodes; this
// matters when the final pass must force an overfull line.
@@ -1148,7 +1153,7 @@ fn break_lines(
groups.entry(key.0).or_default().push(a);
}
for (class, group) in groups {
if class < special {
if class < merged_class {
let at = next
.iter()
.position(|a| a.line >= group[0].line)
@@ -127,6 +127,26 @@ fn real_passes_feasible_edges_passive_nodes_and_short_lists_match_tex() {
}
}
}
#[test]
fn ragged_shaped_paragraphs_preserve_pdftex_ties_at_the_last_special_line() {
for geometry in [
r"\hangindent=26pt\hangafter=1",
r"\hangindent=26pt\hangafter=-1",
r"\parshape=2 0pt 91pt 26pt 65pt",
r"\prevgraf=1\hangindent=26pt\hangafter=2",
] {
let source = format!(
r"{HEADER}\hsize=91pt\rightskip=0pt plus1fil\linepenalty=10\pretolerance=100\noindent {geometry} aaaa bbbb cccc dddd eeee ffff\par\end"
);
let execution = native(&source);
let reports = reports(&execution);
assert_eq!(reports.len(), 1);
assert_eq!(reports[0].text.trim_end(), reference(&source), "{geometry}");
assert_selected_path(reports[0], &execution);
}
}
fn assert_selected_path(r: &ParagraphTraceReport, e: &Execution) {
use std::collections::BTreeMap;
let mut active = BTreeMap::<usize, (usize, usize, usize, i64)>::new();
+35 -3
View File
@@ -819,6 +819,38 @@ letterspace-fresh.log 和 device-pdftex-spaced-moved.log。
[原版字距虚拟字体构造](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16400-L16492)
[原版格式所写字体字段](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L30627-L30696)
### 带段落形状的断行候选合并
用官方 BibLaTeX 索引 .ind 第 55 行保留首个断行差异。原版
article 类为索引条目设置悬挂缩进,单独排这一条就能复现。旧版
首行只排 De Anima dans,参考首行排到 grècque,。断行代价均为
200。旧版输出 66 条断行决策记录,参考为 42 条。
TeX 的 try_break 在 looseness=0 时把最后一个特殊行号的候选
与后续行号一起比较。各行按实际行宽计算代价,再按适应度保留
候选。原生搜索使用实际的 prev_graf + 1 换算行号,使同组候选
进入同一次比较。非零 looseness 继续按行号区分候选。
[TeX 段落形状和断行候选源码](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/tex.web#L15069-L15105)
15 项相关测试通过。新回归覆盖正负悬挂缩进、显式 \parshape 和
非零 \prevgraf,逐条对照实际 pdfTeX 轨迹及最终被选中的行。
发布版对单条索引的 42 条断行决策逐条匹配,首行与参考一致。
原样官方文档使用原生作业经 Biber、MakeIndex 得到的原有文件,
以同一已收敛的 aux 初态复编。九页的 2,907 个词及词框、144 DPI
灰度光栅逐项一致。aux、bcf、bbl、idx、ind、ilg、run.xml
均与参考逐字节一致。原始版面、失败对照和资源指纹保留。
回执 target/p3-index-paragraph-breaks/official-receipt.json 的 SHA-256
为 8f3c0948393ba4b606b1d5609c1f7fe43f2611184a7101c79101d75d0614550b。
三页会话在子文件中改变悬挂缩进,再恢复。两次均由自动检查点
复用 1,031 步,重放两次实际宿主调用,仅更新第 2 页。改变缩进
重新检查 14 条候选边,恢复时复用原来的 17 条候选边。每次的
PDF、测量页面、SVG 和来源映射与同版本独立全量一致。
固定位置的早期对照只观测到执行复用,原记录仍在同目录。
自动检查点回执 target/p3-index-paragraph-breaks/revision.log
的 SHA-256 为 981644e10e321f7819ae2b5384f5233c5e401b2aec1d8b98a128d0d49cddcb36。
### pdfTeX 字节输入与写出的 TCX 字符表
官方 BibLaTeX 20-indexing-single.tex 使用未修改的文档和文献库。
@@ -853,9 +885,9 @@ TeX 8-bit 作业可通过 --translate-file 指定实际 TCX 文件,
.idx、.aux 一致。全部 208 条索引直接用于 MakeIndex,得到与参考
字节相同的 .ind 和 .ilg。后续两轮原生 LaTeX 生成九页,逐轮
.aux、.bcf、.bbl、.idx 一致。最终前六页灰度光栅一致。
第 7–9 页的索引正文仍有断行差异,最早出现在第 7 页右栏,
la tradition grècque 的词落到不同的行。保留原页和词框,
下一步对照实际索引条目的段落参数、行宽及断行代价。
当时第 7–9 页的索引正文仍有断行差异,最早出现在第 7 页右栏,
la tradition grècque 的词落到不同的行。保留原页和词框。
最终复验见 [带段落形状的断行候选合并](#带段落形状的断行候选合并)。
首轮回执 target/p3-actual-biber/pass-1-audit.json 的 SHA-256
为 7d8d8c571746e6797ba3574e0a421ec7247981307f05352baba82124b029aa60。