Implement XeTeX OpenType slant and transformed PDF text positioning

This commit is contained in:
gloamxun committed 2026-11-26 10:43:04 +08:00
1 parent 330ecdd03c
commit 45ea5d4297
6 files changed
+152 -44

No files matched your search

+18 -5
View File
@@ -565,12 +565,25 @@ impl DisplayList {
let x = *x as f64 / 65536.;
let y = *y as f64 / 65536.;
let scale = *size as f64 / (65536. * f64::from(face.units_per_em()));
let horizontal = scale * font.paint_horizontal_scale();
if !path.is_empty() {
out.push_str(&format!(
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5}) scale({horizontal:.9} -{scale:.9})\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/></g>\n",
escape(&font.name), escape(text), fill[0], fill[1], fill[2]
));
use std::fmt::Write as _;
let [extend, slant] = font.paint_transform();
let horizontal = scale * extend;
write!(
out,
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5}) ",
escape(&font.name), escape(text),
).unwrap();
if slant == 0. {
write!(out, "scale({horizontal:.9} -{scale:.9})").unwrap();
} else {
let shear = scale * slant;
write!(out, "matrix({horizontal:.9} 0 {shear:.9} -{scale:.9} 0 0)").unwrap();
}
writeln!(
out, "\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/></g>",
fill[0], fill[1], fill[2],
).unwrap();
}
}
DisplayItem::MathGlyph {