Rejoin XeTeX OpenType word fragments while packing horizontal boxes
This commit is contained in:
1 parent
fa27e0985f
commit
3e9a639f1d
6 files changed
+156
-4
No files matched your search
@@ -5,6 +5,7 @@ mod tail;
|
||||
pub(super) use tail::TailNodeRef;
|
||||
mod leaders;
|
||||
mod legacy_fonts;
|
||||
mod native_words;
|
||||
pub use leaders::{LeaderGlue, LeaderMode, LeaderPattern};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
@@ -617,7 +618,7 @@ pub(super) fn hpack(
|
||||
span: Span,
|
||||
state: &State,
|
||||
) -> Result<NativeBox, String> {
|
||||
hpack_with_direction_report(nodes, spec, span, state).map(|(packed, _)| packed)
|
||||
hpack_with_direction_report(nodes, spec, span, state, None).map(|(packed, _)| packed)
|
||||
}
|
||||
|
||||
pub(super) fn hpack_with_direction_report(
|
||||
@@ -625,7 +626,12 @@ pub(super) fn hpack_with_direction_report(
|
||||
spec: PackSpec,
|
||||
span: Span,
|
||||
state: &State,
|
||||
shaping_budget: Option<(&mut usize, usize)>,
|
||||
) -> Result<(NativeBox, (usize, usize)), String> {
|
||||
if state.input_profile() == InputProfile::XeTeX {
|
||||
let glyph_metrics = state.parameter(Parameter::XeTeXuseglyphmetrics).width() > 0;
|
||||
native_words::rejoin(&mut nodes, glyph_metrics, shaping_budget)?;
|
||||
}
|
||||
let direction_problems = super::direction::complete_box(&mut nodes);
|
||||
let (mut width, mut height, mut depth) = (0, 0, 0);
|
||||
let (mut stretch, mut shrink) = ([0; 4], [0; 4]);
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
//! Reassemble XeTeX native word fragments in the physical horizontal list.
|
||||
use super::TextNode;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(super) fn rejoin(
|
||||
nodes: &mut Vec<TextNode>,
|
||||
glyph_metrics: bool,
|
||||
mut shaping_budget: Option<(&mut usize, usize)>,
|
||||
) -> Result<(), String> {
|
||||
let mut index = 0;
|
||||
let mut replacement_left = 0;
|
||||
let mut edits = Vec::new();
|
||||
while let Some(node) = nodes.get(index) {
|
||||
let begin = index;
|
||||
index += 1;
|
||||
if let TextNode::Discretionary {
|
||||
replacement_count, ..
|
||||
} = node
|
||||
{
|
||||
replacement_left = *replacement_count;
|
||||
continue;
|
||||
}
|
||||
if replacement_left > 0 {
|
||||
replacement_left -= 1;
|
||||
continue;
|
||||
}
|
||||
let TextNode::OpenType(first) = node else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Each retained discretionary may bridge one pair of fragments.
|
||||
// Starting inside a live replacement would invalidate its node count.
|
||||
loop {
|
||||
let next = index
|
||||
+ usize::from(matches!(
|
||||
nodes.get(index),
|
||||
Some(TextNode::Discretionary { .. })
|
||||
));
|
||||
if !matches!(nodes.get(next), Some(TextNode::OpenType(run)) if run.font.id == first.font.id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
index = next + 1;
|
||||
}
|
||||
if index == begin + 1 {
|
||||
continue;
|
||||
}
|
||||
let mut text = String::new();
|
||||
let mut sources = Vec::new();
|
||||
let mut units = 0;
|
||||
for node in &nodes[begin..index] {
|
||||
if let TextNode::OpenType(run) = node {
|
||||
units += run.text.encode_utf16().count();
|
||||
if units > usize::from(u16::MAX) {
|
||||
return Err("native OpenType word capacity exceeded".into());
|
||||
}
|
||||
let offset = text.len();
|
||||
sources.extend(
|
||||
run.sources
|
||||
.iter()
|
||||
.map(|(at, source)| (offset + at, source.clone())),
|
||||
);
|
||||
text.push_str(&run.text);
|
||||
}
|
||||
}
|
||||
let word = first.font.shape_mapped(text, sources, glyph_metrics)?;
|
||||
if let Some((steps, limit)) = &mut shaping_budget {
|
||||
**steps = steps
|
||||
.checked_add(word.glyphs.len())
|
||||
.filter(|work| work <= limit)
|
||||
.ok_or("native OpenType packing step limit exceeded")?;
|
||||
}
|
||||
edits.push((begin, index, Arc::new(word)));
|
||||
}
|
||||
if !edits.is_empty() {
|
||||
let mut edits = edits.into_iter().peekable();
|
||||
let mut index = 0;
|
||||
let mut discard_until = 0;
|
||||
nodes.retain_mut(|node| {
|
||||
let at = index;
|
||||
index += 1;
|
||||
if at < discard_until {
|
||||
return false;
|
||||
}
|
||||
if let Some((_, end, word)) = edits.next_if(|(begin, _, _)| *begin == at) {
|
||||
*node = TextNode::OpenType(word);
|
||||
discard_until = end;
|
||||
}
|
||||
true
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -250,6 +250,7 @@ impl Executor {
|
||||
!matches!(
|
||||
n,
|
||||
TextNode::Glyph { .. }
|
||||
| TextNode::OpenType(_)
|
||||
| TextNode::Kern { .. }
|
||||
| TextNode::AccentKern(_)
|
||||
| TextNode::AutoKern(_)
|
||||
@@ -776,7 +777,13 @@ impl Executor {
|
||||
} else {
|
||||
b.nodes
|
||||
};
|
||||
boxes::hpack_with_direction_report(nodes, frame.spec, frame.span, &self.state)
|
||||
if self.state.input_profile() == InputProfile::XeTeX {
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXuseglyphmetrics));
|
||||
}
|
||||
boxes::hpack_with_direction_report(
|
||||
nodes, frame.spec, frame.span, &self.state,
|
||||
Some((&mut self.steps, self.limits.steps)),
|
||||
)
|
||||
} else {
|
||||
boxes::vpack(
|
||||
self.vertical.take_nodes(),
|
||||
|
||||
@@ -1082,6 +1082,7 @@ fn pack(
|
||||
direction_stack: &[super::direction::Region],
|
||||
state: &mut State,
|
||||
span: Span,
|
||||
shaping_budget: (&mut usize, usize),
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(Paragraph, NativeBox, super::marks::MigratingMaterial, bool), String> {
|
||||
let left = p[&Parameter::Leftskip].glue();
|
||||
@@ -1119,15 +1120,16 @@ fn pack(
|
||||
if p[&Parameter::Pdfadjustspacing].width() > 0 && state.fonts.has_expansion() {
|
||||
expansion::pack(state, &mut material, target, files)?;
|
||||
}
|
||||
let shrinking = material.iter().map(width).sum::<i64>() > target;
|
||||
let mut b = super::boxes::hpack(
|
||||
let (mut b, _) = super::boxes::hpack_with_direction_report(
|
||||
material,
|
||||
super::boxes::PackSpec::To(
|
||||
i32::try_from(target).map_err(|_| "native line width overflow")?,
|
||||
),
|
||||
span,
|
||||
state,
|
||||
Some(shaping_budget),
|
||||
)?;
|
||||
let shrinking = b.setting.sign < 0 || b.excess > 0;
|
||||
b.shift = indent;
|
||||
let paragraph = Paragraph {
|
||||
lines: vec![b.horizontal_items().unwrap()],
|
||||
@@ -1338,6 +1340,7 @@ pub(super) fn finish(
|
||||
&direction_stack,
|
||||
state,
|
||||
b.span,
|
||||
(steps, step_limit),
|
||||
files,
|
||||
)?;
|
||||
packed_diagnostic.push(line_box.diagnostic_eligible);
|
||||
|
||||
@@ -2175,6 +2175,41 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### XeTeX 横盒装箱重塑形
|
||||
|
||||
断行搜索保留原生词段和实际断点分支。选定每行的材料后,横盒装箱
|
||||
合并同字体的相邻词段和未使用的离散断点,再塑形并重算盒宽、胶和
|
||||
溢出诊断。活跃替换列表的节点计数、字体边界、显式 kern 和方向节点
|
||||
继续约束合并。已完成字体映射的文本直接进入塑形,按片段偏移恢复
|
||||
字形来源。显式 `\discretionary` 的三段可包含 XeTeX 原生字形。
|
||||
[XeTeX 装箱时合并词段](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/xetex.web#L30044-L30118)
|
||||
[原生字形作为显式断点材料](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/xetex.web#L26077-L26093)
|
||||
|
||||
两组同源共 13 页的字形编号、坐标和 8 个盒宽与 XeTeX 完全一致。
|
||||
包含未选和已选的自动断点、显式前后及替换材料、受保护的替换节点、
|
||||
解箱后的原生词段,以及连字、字体、kern 和方向边界。6 项既有
|
||||
discretionary 对照通过。三页项目的三次跨文件修订均复用 66 步、
|
||||
重放 2 次调用。增加未选中的断点时发页数为零,实际断行及还原
|
||||
各只发第二页。`ffi` 连字保留三个真实字符的来源。三次 PDF、
|
||||
SVG 和来源映射均与独立全量一致。
|
||||
回执 `target/p3-xetex-unbroken-word/receipt.json` 的 SHA-256 为
|
||||
`641827f640d460e3862f87199856f499f3996c97e52e6ff59a45fb9bcd79e77e`。
|
||||
|
||||
原样 ACL 用相同 schema71、十份原稿和实际 BibTeX 产物复编。
|
||||
原版 XDV 与原生按字形身份顺序配对的 585 个字形中,位置一致数
|
||||
由 448 增至 569。摘要等英语部分的横坐标差已消除,剩余配对字形
|
||||
的坐标差集中于 Lohit Devanagari。三份生成文件继续与参考一致,
|
||||
整页版面尚未对齐。
|
||||
|
||||
下一入口是从字体选项传入的真实 OpenType 脚本和语言标签。原样 ACL
|
||||
的参考日志记录 `script=dev2;language=HIN;mapping=tex-text;`。
|
||||
取同一 10.95 pt 字体、段中文字和映射文件冻结两页。`deva` 两边
|
||||
均产生 25 个相同字形,`dev2` 的参考仍为同样 25 个字形,原生
|
||||
为 27 个且位置不同。上游将 OpenType 脚本和语言标签转换给
|
||||
HarfBuzz 的缓冲区,再按实际语言塑形。证据
|
||||
`target/p3-xetex-opentype-script/comparison.json`。
|
||||
[XeTeX OpenType 标签进入塑形](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/XeTeXLayoutInterface.cpp#L698-L718)
|
||||
|
||||
### XeTeX OpenType 的 PDF 字体描述符
|
||||
|
||||
原生 PDF 取实际 OS/2 排版度量生成描述符,并按 xdvipdfmx 的规则
|
||||
|
||||
@@ -758,6 +758,14 @@ XDV 链接注释接入后,沿原样 ACL 的第二轮辅助文件和 BibTeX
|
||||
`target/p3-xdv-annotation/receipt.json`。
|
||||
[链接注释阶段记录](P2_M1_PROGRESS.md#xdv-链接注释与实际矩形)
|
||||
|
||||
#### OpenType 横盒装箱重塑形复编
|
||||
|
||||
同一 schema71 和原样 ACL 的一页 PDF 完成复编。原版 XDV 与原生布局
|
||||
按身份顺序配对的 585 个字形中,位置一致数从 448 增至 569,剩余
|
||||
坐标差均在印地语。三份生成文件仍与参考逐字节一致。印地语仍有
|
||||
字形序列差,同源样例已定位至 OpenType `dev2` 脚本选择。
|
||||
回执 `target/p3-xetex-unbroken-word/receipt.json`。
|
||||
|
||||
#### PDF OpenType 字体描述符复编
|
||||
|
||||
同一 schema71 和原样 ACL 的一页 PDF 完成复编。六种 OpenType 字体
|
||||
|
||||
Reference in new issue
Block a user