Continue XeTeX text layout on missing legacy glyphs

This commit is contained in:
gloamxun committed 2026-11-29 00:28:09 +08:00
1 parent cb6525ffca
commit 90f174283e
5 files changed
+114 -15

No files matched your search

@@ -385,6 +385,7 @@ impl Executor {
files: &mut impl SourceProvider,
) -> Result<(), Error> {
let slot = slot.into();
let xetex = self.state.input_profile() == InputProfile::XeTeX;
let tracing = self.read_parameter(Parameter::Tracinglostchars).width();
let online = self.read_parameter(Parameter::Tracingonline).width();
let destination = if tracing <= 0 {
@@ -403,7 +404,8 @@ impl Executor {
match slot {
0..=31 => format!("^^{}", char::from(slot as u8 + 64)),
127 => "^^?".into(),
128..=255 => format!("^^{slot:02x}"),
128..=159 => format!("^^{slot:02x}"),
160..=255 if !xetex => format!("^^{slot:02x}"),
_ => char::from_u32(slot)
.map(|c| c.to_string())
.unwrap_or_else(|| format!("U+{slot:04X}")),
@@ -423,17 +425,14 @@ impl Executor {
} else {
"Missing character: There is no "
});
let tail = literal(&if tracing > 2 {
format!(
" (\"{slot:X}) in font {}.",
self.state.fonts.font(font).expect("loaded font").name()
)
let code = if xetex || tracing > 2 {
format!(" (\"{slot:X})")
} else {
format!(
" in font {}!",
self.state.fonts.font(font).expect("loaded font").name()
)
});
String::new()
};
let font = self.state.fonts.font(font).expect("loaded font").name();
let end = if tracing > 2 { '.' } else { '!' };
let tail = literal(&format!("{code} in font {font}{end}"));
format!("{head}{printed}{tail}")
});
self.events.push(Event::MissingGlyph(MissingGlyph {
@@ -442,19 +442,20 @@ impl Executor {
return Ok(());
}
let font = self.state.text_font();
let opentype = if self.state.input_profile() != super::super::InputProfile::TeX8Bit {
let profile = self.state.input_profile();
let opentype = if profile != InputProfile::TeX8Bit {
self.state.fonts.font(font).map_err(|e| self.error(e, token.span))?.opentype().cloned()
} else {
None
};
let slot = u8::try_from(c as u32).ok();
if slot.is_none() && opentype.is_none() {
if profile != InputProfile::XeTeX && slot.is_none() && opentype.is_none() {
return Err(self.error("native TFM text font requires an 8-bit character slot", token.span));
}
if self.paragraph.is_none() {
self.begin_paragraph(token.invocation.unwrap_or(token.span), true)?;
}
let space_factor = if slot.is_some() || self.state.input_profile() == InputProfile::XeTeX {
let space_factor = if slot.is_some() || profile == InputProfile::XeTeX {
self.read_space_factor_code(u32::from(c))
} else {
1000
@@ -478,7 +479,7 @@ impl Executor {
self.reads.insert(Dependency::FontResources);
self.reads.insert(Dependency::TextFont);
if let Some(font) = opentype {
if self.state.input_profile() == InputProfile::XeTeX {
if profile == InputProfile::XeTeX {
self.reads.insert(Dependency::Parameter(Parameter::XeTeXuseglyphmetrics));
self.reads.insert(Dependency::Parameter(Parameter::XeTeXgenerateactualtext));
self.reads.insert(Dependency::Parameter(Parameter::XeTeXinterwordspaceshaping));
@@ -495,6 +496,15 @@ impl Executor {
.opentype_character(c, TokenOrigin::from(token), &self.state, font)
.map_err(|e| self.error(e, token.invocation.unwrap_or(token.span)));
}
if slot.is_none() {
// The pending character saw this scalar as lookahead, so there
// is no right-boundary ligature and no new legacy character node.
let paragraph = self.paragraph.as_mut().unwrap();
paragraph.finish_text(false, &self.state)
.map_err(|e| self.error(e, token.invocation.unwrap_or(token.span)))?;
self.paragraph.as_mut().unwrap().cancel_boundary = false;
return self.missing_glyph(font, u32::from(c), token.invocation.unwrap_or(token.span), files);
}
let missing = self
.paragraph
.as_mut()
@@ -35,6 +35,60 @@ fn messages(result: &Execution) -> Vec<&str> {
.collect()
}
#[test]
fn xetex_legacy_font_reports_unicode_outside_its_slots() {
use sha2::{Digest, Sha256};
use texrra_tex_core::resources::{LoadedResource, ResourceKind, ResourceVersion};
struct LegacyFont;
impl SourceProvider for LegacyFont {
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
Err(format!("unexpected input {name}"))
}
fn resource(&mut self, kind: ResourceKind, name: &str, _: &str) -> Result<LoadedResource, String> {
assert_eq!((kind, name), (ResourceKind::Tfm, "cmr10.tfm"));
let data = include_bytes!("../assets/cmr10.tfm").to_vec();
Ok(LoadedResource {
version: ResourceVersion {
path: "cmr10.tfm".into(),
sha256: format!("{:x}", Sha256::digest(&data)),
bytes: data.len() as u64,
},
data,
})
}
}
let state = State::initex().with_etex().with_input_profile(InputProfile::XeTeX);
let result = Executor::new(state, Limits::default())
.run(source(r#"\catcode123=1 \catcode125=2
\font\probe=cmr10 \probe \tracinglostchars=2
\setbox0=\hbox{f–i}
\setbox1=\hbox{f\char"2013 i}
\chardef\absent="2013
\setbox2=\hbox{f\absent i}
\sfcode"2013=1732
\setbox3=\hbox{x–\message{\the\spacefactor}}
\setbox4=\hbox{\char200\char"1F312}
\message{\number\wd0,\number\wd1,\number\wd2}
\end"#), &mut LegacyFont)
.unwrap();
assert_eq!(messages(&result), ["1732", "382295,382295,382295"]);
let warnings: Vec<_> = result.events.iter().filter_map(|event| match event {
Event::MissingGlyph(glyph) => Some((glyph.slot, glyph.message.as_deref().unwrap())),
_ => None,
}).collect();
assert_eq!(warnings, [
(0x2013, "Missing character: There is no – (\"2013) in font cmr10!"),
(0x2013, "Missing character: There is no – (\"2013) in font cmr10!"),
(0x2013, "Missing character: There is no – (\"2013) in font cmr10!"),
(0x2013, "Missing character: There is no – (\"2013) in font cmr10!"),
(0xC8, "Missing character: There is no È (\"C8) in font cmr10!"),
(0x1F312, "Missing character: There is no 🌒 (\"1F312) in font cmr10!"),
]);
}
#[test]
fn opentype_design_and_scaled_requests_share_actual_sized_instances() {
use sha2::{Digest, Sha256};
+27
View File
@@ -18,6 +18,33 @@
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
## 2026-11-29 XeTeX 旧式字体缺字与原样 NeurIPS 多页编辑
原样 NeurIPS 2025 的 XeLaTeX 编译会在 ptmr8t 字体中遇到超出 TFM
槽范围的 Unicode 字符。原生此前在第 522 行终止。现在仍执行字符和空格
因子的更新,结束当前连字游标而不触发右边界程序,然后按 tracinglostchars
记录原 Unicode 标量。普通字符、显式字符命令、字符定义、非 BMP 字符和不同
诊断级别经真实 cmr10 对照。其中一页的 144 DPI 像素全部一致。定向的缺字
及既有字符间插回归通过。
[XeTeX 的字符节点和连字游标实现](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/web2c/xetexdir/xetex.web#L24632-L24736)
从空辅助文件开始,以冻结的三份官方交付、实际 XeLaTeX 镜像和字体编译。
两轮均生成 12 页,aux 和 out 逐轮与 XeTeX 参考一致。第二轮的 29,586 个
字形数量相同,10 页的原始字形及坐标逐项一致。第 3、9 页还有原始坐标差异,
导出后的词框和 144 DPI 像素仍有差异。
以原样项目的收敛辅助文件启动编辑会话。第 12 页正文编辑及恢复均只转换
并刷新该页,复用另外 11 页的绘制列表。正文编辑复用 19,162,561 个执行
步骤及 68 次断行计算。两次成功修订的 PDF、绘制列表、SVG、来源映射、
实际资源读取及辅助文件与同初态独立全量一致。引入未定义命令后保留已发布的
PDF、辅助文件和版本。
原始错误的终端与资源记录已归档。详细 JSON 故障清单还会因非字符串键
序列化失败。PDF 输出差异已缩减为最小标题用例。两端 36 个字形及原始
坐标一致,首个词间距的 TJ 值分别为 -249 和 -248。下一步核对 xdvipdfmx
的旧式字距游标与量化,再处理第 3、9 页的布局差异。
证据见 target/p4-neurips-xetex/。同版出版矩阵和正式实时性门禁继续按总目标执行。
## 2026-11-29 原样 XeLaTeX ACL 接入测试编辑器
测试编辑器通过 --input-profile xetex 选择 XeTeX profile。种子作业和
+9
View File
@@ -1277,6 +1277,15 @@ receipt.json 的 SHA-256 为 3f591a83c53dc505331cc248323e8dec538fee0bdf265800ddb
pass-3/comparison.json 为 64f656d0968bab4b26602bbf8690eabcbc365d094ec89a38a982a38fe116a91d。
[Type 1 编号与增量对照](P2_M1_PROGRESS.md#pdftex-替换导入-type-1-字体的间接对象)
### 2026-11-29 原样 NeurIPS 2025 的 XeLaTeX 复验
三份官方交付、实际字体和 XeLaTeX 格式身份均保留。原生旧式字体缺字
处理接通后,从空辅助文件开始的两轮都生成 12 页,逐轮 aux 和 out 与
同 profile 的原版相同。第二轮两端各有 29,586 个原始字形,10 页的字形
及坐标逐项一致。第 3、9 页布局、导出词框与光栅差异仍待闭合。
该版原样项目的第 12 页正文编辑、故障及恢复另以独立全量核对。
[官方模板压缩包](https://media.neurips.cc/Conferences/NeurIPS2025/Styles.zip) · [本轮阶段记录](P2_M1_PROGRESS.md#2026-11-29-xetex-旧式字体缺字与原样-neurips-多页编辑)
单纯生成 PDF 或 DVI 只说明编译路径可达。完整验收要在参考环境闭合后比较页数、
双栏位置及跨栏材料、实际字体/字形、图表浮动、引用收敛、词框及墨迹;测试源
与容差都不得为通过而替换。类 Typst 的编辑延迟另用同批原样项目分规模测量,