Render vertical and CFF legacy XeLaTeX composite fonts

This commit is contained in:
gloamxun committed 2026-11-28 22:17:46 +08:00
1 parent bbeeca0317
commit ff52a9f66b
14 files changed
+877 -292

No files matched your search

+17 -2
View File
@@ -170,6 +170,7 @@ struct NativeSvgGlyph<'a> {
glyph: &'a str,
unicode: Option<&'a str>,
device_width: Option<u32>,
vertical_origin: Option<[i32; 2]>,
path: &'a str,
scalable: bool,
}
@@ -203,6 +204,8 @@ impl DisplayItem {
),
_ => format!("native SVG outline is not resolved for {} slot {slot}", font.name),
})?;
let composite = paint.legacy_cid_font();
let vertical = composite.and_then(|font| font.vertical_slot(*slot));
Ok(NativeSvgGlyph {
position: [*x, *y],
size: *size,
@@ -212,7 +215,8 @@ impl DisplayItem {
font: paint.program.name(),
glyph: &paint.encoding[usize::from(*slot)],
unicode: paint.mapped_text(*slot),
device_width: paint.legacy_cid_font().map(|font| font.advance(*slot)),
device_width: composite.map(|font| vertical.map_or_else(|| font.advance(*slot), |v| v[0] as u32)),
vertical_origin: vertical.map(|[_, x, y]| [(x * 2.0) as i32, y as i32]),
path,
scalable: !matches!(
paint.program,
@@ -562,6 +566,7 @@ impl DisplayList {
glyph,
unicode,
device_width,
vertical_origin,
path,
scalable,
} = item
@@ -595,7 +600,17 @@ impl DisplayList {
"<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"",
escape(font), escape(glyph), escape(&label), path,
).unwrap();
if xdv_matrix.is_identity() {
if let Some([vx2, vy]) = vertical_origin {
let vx = f64::from(vx2) / 2.0;
let vy = f64::from(vy);
let [extend, slant] = xdv_matrix.coefficients();
let a = slant * horizontal_scale;
let b = -horizontal_scale;
let c = -extend * scale;
let e = x - a * vx - c * vy;
let f = y - b * vx;
write!(out, "matrix({a:.8} {b:.8} {c:.8} 0 {e:.5} {f:.5})").unwrap();
} else if xdv_matrix.is_identity() {
write!(out, "translate({x:.5} {y:.5}) scale({horizontal_scale:.8} -{scale:.8})").unwrap();
} else {
let [extend, slant] = xdv_matrix.coefficients();