Match XeTeX math script kerning and fraction font selection

This commit is contained in:
gloamxun committed 2026-11-21 15:33:05 +08:00
1 parent 821631778e
commit a31de14eb2
9 files changed
+255 -12

No files matched your search

@@ -9,12 +9,14 @@ impl Converter<'_> {
let mut n = original.clone();
let mut accent = n.accent.take().unwrap();
let font = self.family_font(accent.family, style)?;
self.current_math_font.set(font);
let accent_font = self.state.fonts.font(font)?;
let opentype = accent_font.opentype();
let bottom = n.accent_style.bottom();
let mut skew = 0;
if let MathField::Char(c) = n.nucleus {
let base_font = self.family_font(c.family, style)?;
self.current_math_font.set(base_font);
if !self.has_math_char(base_font, c.slot)? {
self.missing.borrow_mut().push((base_font, c.slot));
n.nucleus = MathField::Empty;
@@ -60,6 +62,7 @@ impl Converter<'_> {
.operator
.clone()
.derived(crate::provenance::Derivation::Accent);
let nucleus_font = self.current_math_font.get();
let (mark, x) = if let Some(face) = opentype {
let (mut glyph, italic) = self.glyph(accent, style, &source)?;
glyph.metrics.width -= italic;
@@ -113,6 +116,9 @@ impl Converter<'_> {
let x = skew + (width - mark.metrics.width + 1).div_euclid(2);
(mark, x)
};
// Drawing the already fetched accent does not replace the font left
// by clean_box on the nucleus.
self.current_math_font.set(nucleus_font);
let y = if bottom {
base.metrics.depth + mark.metrics.height
} else {
@@ -148,6 +154,7 @@ impl Converter<'_> {
.as_ref()
.map(|f| self.field(f, style.sub(), &n.source.sub))
.transpose()?;
self.current_math_font.set(nucleus_font);
Ok(place_scripts(
result,
upper,
@@ -187,7 +194,10 @@ impl Converter<'_> {
let Some(face) = font.opentype() else {
return Ok(None);
};
let (geometry, _) = self.glyph(base, style, &source.paint)?;
let Some(character) = char::from_u32(base.slot) else {
return Ok(None);
};
let (geometry, _) = opentype::math_glyph(face, character, &source.paint)?;
opentype::single_glyph(&geometry)
.map(|glyph| opentype::accent_attachment(face, glyph))
.transpose()