Support XeTeX OpenType vertical shaping and PDF writing mode

This commit is contained in:
gloamxun committed 2026-11-28 05:24:33 +08:00
1 parent 23ec506fa3
commit e2af618e65
9 files changed
+481 -44

No files matched your search

+67
View File
@@ -707,6 +707,73 @@ fn font_mapping_changes_recover_and_update_the_page_that_used_the_resource() {
fs::remove_dir_all(p).unwrap();
}
#[test]
fn xetex_vertical_font_uses_tex_box_metrics_and_pdf_writing_mode() {
use texrra_tex_core::execution::{Event, InputProfile};
let root = directory("xetex-vertical-font");
fs::write(
root.join("face.ttf"),
include_bytes!("../assets/fonts-subset/LiberationSerif-Regular.ttf"),
)
.unwrap();
fs::write(
root.join("main.tex"),
br#"\catcode123=1 \catcode125=2
\font\turned="[face.ttf]:vertical" at 12pt
\XeTeXuseglyphmetrics=1
\setbox0=\hbox{\turned AbCd Xyz}
\message{VBOX=\number\wd0,\number\ht0,\number\dp0}
\message{VSPACE=\number\fontdimen2\turned}
\shipout\box0
\end"#,
)
.unwrap();
let mut job = request(&root);
job.world = WorldConfig::new(&root);
job.input_profile = InputProfile::XeTeX;
let result = NativeCompiler::default().compile(job).unwrap();
// Exact values from XeTeX INITEX with the same Liberation Serif face.
let messages: Vec<_> = result
.execution
.execution
.events
.iter()
.filter_map(|event| match event {
Event::Message { text, .. } => Some(text.as_str()),
_ => None,
})
.collect();
assert_eq!(messages, ["VBOX=5720064,545664,169727", "VSPACE=715008"]);
let pdf = lopdf::Document::load_mem(result.pdf.as_deref().unwrap()).unwrap();
let font = pdf
.objects
.values()
.filter_map(|object| object.as_dict().ok())
.find(|font| {
font.get(b"Encoding").and_then(lopdf::Object::as_name).ok()
== Some(b"Identity-V".as_slice())
})
.unwrap();
let descendant = font.get(b"DescendantFonts").unwrap().as_array().unwrap()[0]
.as_reference()
.unwrap();
let metrics = pdf
.get_dictionary(descendant)
.unwrap()
.get(b"DW2")
.unwrap()
.as_array()
.unwrap();
let metrics: Vec<_> = metrics.iter().map(|value| value.as_i64().unwrap()).collect();
assert_eq!(metrics, [693, -909]);
let content = pdf.get_page_content(pdf.get_pages()[&1]).unwrap();
assert!(String::from_utf8(content).unwrap().contains("0 1 -1 0 "));
fs::remove_dir_all(root).unwrap();
}
#[test]
fn xetex_glyph_bounds_and_dash_breaks_follow_revision_local_parameters() {
use texrra_tex_core::execution::{Event, InputProfile};