Use OpenType design sizes in native XeTeX
This commit is contained in:
1 parent
b472f66d04
commit
115e1f0fe0
4 files changed
+136
-12
No files matched your search
@@ -308,6 +308,14 @@ impl Hash for OpenTypeFont {
|
||||
}
|
||||
}
|
||||
|
||||
fn requested_font_size(design_size: i64, size: FontSize) -> i64 {
|
||||
match size {
|
||||
FontSize::At(size) => size,
|
||||
FontSize::Design => design_size,
|
||||
FontSize::Scaled(ratio) => design_size * i64::from(ratio) / 1000,
|
||||
}
|
||||
}
|
||||
|
||||
impl OpenTypeFont {
|
||||
pub(crate) fn new(
|
||||
id: FontId,
|
||||
@@ -328,13 +336,8 @@ impl OpenTypeFont {
|
||||
.filter(|name| name.name_id == ttf_parser::name_id::POST_SCRIPT_NAME)
|
||||
.find_map(|name| name.to_string())
|
||||
.ok_or("OpenType face has no PostScript name")?;
|
||||
// Native file fonts use 10pt unless they declare an optical design size.
|
||||
let design_size = 10 * 65_536;
|
||||
let size = match size {
|
||||
FontSize::At(size) => size,
|
||||
FontSize::Design => design_size,
|
||||
FontSize::Scaled(ratio) => design_size * i64::from(ratio) / 1000,
|
||||
};
|
||||
let design_size = font_info::design_size(&face);
|
||||
let size = requested_font_size(design_size, size);
|
||||
FontSize::At(size).validate()?;
|
||||
let letter_space = request.letter_space(size);
|
||||
if !letter_space.is_finite() || letter_space.abs() > 1_073_741_823. {
|
||||
@@ -399,11 +402,7 @@ impl OpenTypeFont {
|
||||
}
|
||||
|
||||
pub(crate) fn requested_size(&self, size: FontSize) -> i64 {
|
||||
match size {
|
||||
FontSize::At(size) => size,
|
||||
FontSize::Design => self.design_size,
|
||||
FontSize::Scaled(ratio) => self.design_size * i64::from(ratio) / 1000,
|
||||
}
|
||||
requested_font_size(self.design_size, size)
|
||||
}
|
||||
|
||||
pub(crate) fn face(&self) -> Result<ttf_parser::Face<'_>, String> {
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
//! XeTeX font inspection from the selected OpenType face.
|
||||
use super::{Tag, scale_units, ttf_parser};
|
||||
use read_fonts::{
|
||||
FontData, FontRead,
|
||||
tables::{gpos::Gpos, layout::FeatureParams},
|
||||
};
|
||||
|
||||
pub(super) fn design_size(face: &ttf_parser::Face<'_>) -> i64 {
|
||||
let optical_size = face
|
||||
.raw_face()
|
||||
.table(Tag::from_bytes(b"GPOS"))
|
||||
.and_then(optical_design_decipoints);
|
||||
optical_size.map_or(10 * 65_536, |size| {
|
||||
// The GPOS size feature uses tenths of a PostScript point.
|
||||
// XeTeX converts to TeX points and rounds to a scaled point.
|
||||
(i64::from(size) * 7_227 * 65_536 + 36_000) / 72_000
|
||||
})
|
||||
}
|
||||
|
||||
fn optical_design_decipoints(gpos: &[u8]) -> Option<u16> {
|
||||
let features = Gpos::read(FontData::new(gpos)).ok()?.feature_list().ok()?;
|
||||
features
|
||||
.feature_records()
|
||||
.iter()
|
||||
.filter(|record| record.feature_tag() == read_fonts::types::Tag::new(b"size"))
|
||||
.find_map(|record| {
|
||||
let feature = record.feature(features.offset_data()).ok()?;
|
||||
if feature.lookup_list_indices().len() != usize::from(feature.lookup_index_count()) {
|
||||
return None;
|
||||
}
|
||||
let FeatureParams::Size(params) = feature.feature_params()?.ok()? else {
|
||||
return None;
|
||||
};
|
||||
let size = params.design_size();
|
||||
let family = params.identifier();
|
||||
let name = params.name_entry();
|
||||
let start = params.range_start();
|
||||
let end = params.range_end();
|
||||
let design_only = [family, name, start, end] == [0; 4];
|
||||
let valid_range = (start..=end).contains(&size) && (256..=32767).contains(&name);
|
||||
(size != 0 && (design_only || valid_range)).then_some(size)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) struct LayoutTags<'a> {
|
||||
tables: &'a ttf_parser::FaceTables<'a>,
|
||||
|
||||
@@ -35,6 +35,55 @@ fn messages(result: &Execution) -> Vec<&str> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opentype_design_and_scaled_requests_share_actual_sized_instances() {
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
use texrra_tex_core::resources::{LoadedResource, ResourceKind, ResourceVersion};
|
||||
|
||||
struct PhysicalFont(LoadedResource);
|
||||
impl SourceProvider for PhysicalFont {
|
||||
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::OpenType, "lmroman10-regular.otf"));
|
||||
Ok(LoadedResource { version: self.0.version.clone(), data: self.0.data.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
let font = Command::new("kpsewhich").arg("lmroman10-regular.otf").output().unwrap();
|
||||
assert!(font.status.success(), "missing reference OpenType resource");
|
||||
let path = PathBuf::from(String::from_utf8(font.stdout).unwrap().trim());
|
||||
let data = fs::read(&path).unwrap();
|
||||
let mut provider = PhysicalFont(LoadedResource {
|
||||
version: ResourceVersion {
|
||||
path,
|
||||
sha256: format!("{:x}", Sha256::digest(&data)),
|
||||
bytes: data.len() as u64,
|
||||
},
|
||||
data,
|
||||
});
|
||||
let result = Executor::new(
|
||||
State::initex().with_etex().with_input_profile(InputProfile::XeTeX),
|
||||
Limits::default(),
|
||||
)
|
||||
.run(
|
||||
source(r#"\catcode123=1 \catcode125=2
|
||||
\font\design="[lmroman10-regular.otf]"
|
||||
\font\same="[lmroman10-regular.otf]" scaled1000
|
||||
\font\exact="[lmroman10-regular.otf]" at657818sp
|
||||
\font\scaled="[lmroman10-regular.otf]" scaled737
|
||||
\font\explicit="[lmroman10-regular.otf]" at10pt
|
||||
\message{\number\fontdimen6\design/\number\fontdimen6\scaled/\number\fontdimen6\explicit}
|
||||
\message{\ifx\design\same SAME\fi/\ifx\design\exact SAME\fi/\ifx\design\explicit SAME\else DIFFERENT\fi}
|
||||
\end"#),
|
||||
&mut provider,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(messages(&result), ["657818/484811/655360", "SAME/SAME/DIFFERENT"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xetex_primitives_follow_each_profiles_language_and_device() {
|
||||
let tex = r"\catcode123=1 \catcode125=2
|
||||
|
||||
@@ -18,6 +18,41 @@
|
||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||
|
||||
## 2026-11-28 XeTeX OpenType 设计字号
|
||||
|
||||
从已选字体面的真实 GPOS `size` 参数读取设计字号,沿用现有
|
||||
`read-fonts` 表解析。以十分之一 PostScript 点为单位的设计字号换算为 TeX 的缩放点并
|
||||
舍入,`scaled` 对该整数乘比例后截断,`at` 使用明确给定的尺寸。
|
||||
没有有效 `size` 的字体仍使用 10 pt。字体缓存与造型共用字号计算,
|
||||
默认字号、`scaled1000` 和同一尺寸的 `at` 指向同一实例。
|
||||
|
||||
真实 Latin Modern 10、12 的默认值分别为 657,818 和 789,381 sp,
|
||||
前者 `scaled737` 为 484,811 sp。实测覆盖现有 Noto Sans
|
||||
TrueType 的无设计字号分支。物理字体用例的 112 个字形、20 个词框
|
||||
及像素与 XeTeX 一致。上一阶段保留的两个原始断词用例省略字号
|
||||
复编,11 页的 45 个字形、17 个词框、跟踪与像素均一致。
|
||||
|
||||
旧格式和新格式均使用 schema99。XeTeX 与原生都拒绝转储已经
|
||||
装载 OpenType 的作业,保留了两个诊断。用实际可转储的宏定义
|
||||
和重载后的字体声明验证两份镜像,字号查询、实例身份和页面与参考一致。
|
||||
原样 ACL 在既有 schema71 下复编,PDF、布局清单及辅助文件保持一致。
|
||||
|
||||
连续三轮分别编辑子文件的缩放比例、替换同一路径的实际 OTF、恢复两者。
|
||||
每轮复用 1,022 步,只发出第 2 页。PDF、测量页面、SVG、稳定辅助文件
|
||||
及来源映射均和同版本独立全量一致,恢复后的 PDF 与初始字节一致。
|
||||
|
||||
另保留按名选择光学版本的差异。实际同时安装 LM Roman 10 和 12 时,
|
||||
用 `LMRoman10-Regular` 名称指定 `at13pt`,参考改选同组 LM Roman 12,
|
||||
原生仍选 LM Roman 10,二者请求字号均为 851,968 sp。`scaled1300`
|
||||
在参考中沿用原字体面并按其设计值缩放。下一项需要在实际字体查找
|
||||
和依赖记录中实现这样的光学版本选择。
|
||||
|
||||
13 项 XeTeX 定向测试通过。冻结输入、字形和页面对照及编辑回执
|
||||
保存在 `target/p3-xetex-design-size`,`receipt.json` 的 SHA-256 为
|
||||
`1a9fe6a6fab750ea41ad3e165f74b928c12b6e3422b11e4bc10e57a87fbc52c9`。
|
||||
[XeTeX 的 GPOS 设计字号读取](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/xetexdir/XeTeXFontMgr.cpp#L418-L454)
|
||||
· [XeTeX 装载字体的字号换算](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/xetexdir/XeTeX_ext.c)
|
||||
|
||||
## 2026-11-28 e-TeX 按语言保存断词代码
|
||||
|
||||
`\savinghyphcodes` 为正时,在 `\patterns` 读完后保存该语言当时的
|
||||
|
||||
Reference in new issue
Block a user