Select XeTeX OpenType vertical metrics from the font tables
This commit is contained in:
1 parent
c97e0e7279
commit
2b82172bfb
3 files changed
+73
-3
No files matched your search
@@ -228,9 +228,7 @@ impl OpenTypeFont {
|
||||
};
|
||||
FontSize::At(size).validate()?;
|
||||
let scale = |value| scale_units(value, size, face.units_per_em());
|
||||
let hhea = face.tables().hhea;
|
||||
let ascent = scale(i64::from(hhea.ascender));
|
||||
let descent = -scale(i64::from(hhea.descender));
|
||||
let [ascent, descent] = sized_face_metrics(&face, size);
|
||||
let xheight = |reported: Option<i16>, letter: char, fallback: i64| {
|
||||
reported.map_or_else(
|
||||
|| {
|
||||
@@ -488,6 +486,34 @@ fn points_to_sp(points: f32) -> i64 {
|
||||
(f64::from(points) * 65536. + 0.5) as i64
|
||||
}
|
||||
|
||||
fn sized_face_metrics(face: &ttf_parser::Face<'_>, size: i64) -> [i64; 2] {
|
||||
let hhea = face.tables().hhea;
|
||||
let horizontal = (hhea.ascender, hhea.descender);
|
||||
let (ascent, descent) = match face.raw_face().table(Tag::from_bytes(b"OS/2")) {
|
||||
// FreeType checks the stored bit, including in versions before the
|
||||
// OpenType specification assigned USE_TYPO_METRICS to it.
|
||||
Some(table) if table.len() >= 78 && table[..2] != [0xff, 0xff] => {
|
||||
let field = |offset| i16::from_be_bytes([table[offset], table[offset + 1]]);
|
||||
let typographic = (field(68), field(70));
|
||||
if field(62) & 128 != 0 {
|
||||
typographic
|
||||
} else if horizontal != (0, 0) {
|
||||
horizontal
|
||||
} else if typographic != (0, 0) {
|
||||
typographic
|
||||
} else {
|
||||
(field(74), field(76).wrapping_neg())
|
||||
}
|
||||
}
|
||||
_ => horizontal,
|
||||
};
|
||||
let units = face.units_per_em();
|
||||
[
|
||||
scale_units(i64::from(ascent), size, units),
|
||||
-scale_units(i64::from(descent), size, units),
|
||||
]
|
||||
}
|
||||
|
||||
pub(crate) fn scale_units(value: i64, size: i64, units: u16) -> i64 {
|
||||
let points = (value as f32 * (size as f32 / 65536.)) / f32::from(units);
|
||||
// XeTeX converts the float point position by adding 0.5 and truncating.
|
||||
|
||||
@@ -2175,6 +2175,41 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### XeTeX OpenType 字体的垂直度量
|
||||
|
||||
OpenType 字体加载按同一字面数据选择 ascent 和 descent。置位
|
||||
USE_TYPO_METRICS 时使用 OS/2 的排版度量,否则采用 hhea。hhea
|
||||
的两个值都为零时,依次采用有效的 OS/2 排版度量和 Windows 度量。
|
||||
同一 scaled-point 转换用于实际盒子和段落。开启字形范围度量时
|
||||
继续按各字形实际外形组合。原 XeTeX 与原生 INITEX 均拒绝导出含有
|
||||
原生字体的镜像,因此沿用原格式镜像版本。
|
||||
[XeTeX 的字体度量入口](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/XeTeXFontInst.cpp#L329-L335)
|
||||
[FreeType 2.14.3 的度量选择](https://github.com/freetype/freetype/blob/VER-2-14-3/src/sfnt/sfobjs.c#L1369-L1412)
|
||||
|
||||
三组 11 页的字形编号、坐标和 8 个盒子的宽高深完全一致。沿用原印地语、
|
||||
阿拉伯语和两份实际字体,另用同源字体的三份度量表变体覆盖普通
|
||||
hhea 与两级备用度量。三页原样文字的 144 DPI 灰度差像素为 28、60、
|
||||
82,印地语页前版为 2190。12 项已有 XeTeX 定向测试通过。
|
||||
三页项目的四次修订分别切换及还原度量模式、替换及还原同名项目字体。
|
||||
每次复用 66 步、重放 2 次调用、只刷新第二页。PDF、SVG 与来源映射
|
||||
均与独立全量编译一致。
|
||||
回执 `target/p3-xetex-multilingual-shaping/receipt.json` 的 SHA-256 为
|
||||
`6123305e4400abd94ab776a2600fd7a03b5295046addb2e21448226c9a2b5d56`。
|
||||
|
||||
原样 ACL 用同一 schema71、十份源文件和既有生成文件复编。其 PDF
|
||||
与前版逐字节相同。原版 XDV 与原生首行标题的 43 个字形编号、字号、
|
||||
位置已一致,PDF 提取的词框仍差约 4.63 bp。实际字体描述符中,
|
||||
TeXGyreTermesX-Bold 的参考 Ascent/Descent 为 795/-205,原生为
|
||||
1118/-341。下一入口按 xdvipdfmx 的 OS/2 描述符规则继续,先以同一
|
||||
CFF/TrueType 实际字体对照布局与 PDF 中各自的度量。比较记录在同目录的
|
||||
`acl-title-geometry.json` 与 `acl-{reference,native}.font-descriptors.txt`。
|
||||
[xdvipdfmx 字体描述符](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/dvipdfm-x/tt_aux.c#L190-L225)
|
||||
|
||||
另存 `target/p3-xetex-actual-text`。使用同一印地语、阿拉伯语文字和字体,
|
||||
原版仅在开启 `\XeTeXgenerateactualtext` 的两页生成原生词级
|
||||
ActualText,出组后恢复。当前原生缺少该命令,原样 ACL 参考 PDF
|
||||
未使用该功能。此入口与 ACL 描述符核对分别推进。
|
||||
|
||||
### XeTeX OpenType 自动断词
|
||||
|
||||
原生断行的容差轮从实际胶、语言节点、字符小写码和字体整数选取
|
||||
|
||||
@@ -758,6 +758,15 @@ XDV 链接注释接入后,沿原样 ACL 的第二轮辅助文件和 BibTeX
|
||||
`target/p3-xdv-annotation/receipt.json`。
|
||||
[链接注释阶段记录](P2_M1_PROGRESS.md#xdv-链接注释与实际矩形)
|
||||
|
||||
#### OpenType 垂直度量复编
|
||||
|
||||
原样 ACL 的 schema71、十份源文件和 BibTeX 产物继续按原指纹复编。
|
||||
生成的一页 PDF 与前版逐字节相同,`.aux`、`.out`、`.bbl`
|
||||
均与参考一致。首行标题的 43 个字形在原版 XDV 和原生布局中的编号、
|
||||
字号、位置完全一致,PDF 词框约 4.63 bp 的垂直偏差可追至双方
|
||||
字体描述符的度量差。整页等价门禁保持未通过。
|
||||
回执 `target/p3-xetex-multilingual-shaping/receipt.json`。
|
||||
|
||||
#### OpenType 自动断词复编
|
||||
|
||||
同一 schema71 镜像和十份 ACL 源文件原样复编,使用已收敛的实际
|
||||
|
||||
Reference in new issue
Block a user