Use OpenType design sizes in native XeTeX

This commit is contained in:
gloamxun committed 2026-11-28 12:43:18 +08:00
1 parent b472f66d04
commit 115e1f0fe0
4 files changed
+136 -12

No files matched your search

@@ -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