Render XeTeX OpenType math accents and stretch constructions

This commit is contained in:
gloamxun committed 2026-11-21 15:14:48 +08:00
1 parent 01b3931ae0
commit 821631778e
16 files changed
+825 -144

No files matched your search

+37 -16
View File
@@ -85,27 +85,48 @@ impl Converter<'_> {
None
};
let (mut body, italic) = if let MathField::Char(mut c) = n.nucleus {
let face = self.font(c.family, style)?;
let id = self.family_font(c.family, style)?;
let mut source = n.source.nucleus.clone();
let (mut b, italic) = if !self.has_math_char(face.id, c.slot)? {
self.missing.borrow_mut().push((face.id, c.slot));
let font = self.state.fonts.font(id)?;
let (mut b, italic) = if !self.has_math_char(id, c.slot)? {
self.missing.borrow_mut().push((id, c.slot));
(self.pack_field(Vec::new())?, 0)
} else if let Some(face) = font.opentype() {
use crate::opentype::{self, MathConstants, Stretch};
let (mut body, mut italic) = self.glyph(c, style, &source.paint)?;
body.metrics.width -= italic;
if style.display() && let Some(math) = MathConstants::read(face)? {
let min = crate::opentype::scale_units(
i64::from(math.values.display_operator_min_height()),
face.size, face.face()?.units_per_em(),
);
let target = min.max((body.metrics.height + body.metrics.depth) * 5 / 4);
let glyph = opentype::single_glyph(&body).ok_or("missing OpenType operator glyph")?;
let character = char::from_u32(c.slot).ok_or("invalid OpenType operator scalar")?;
let variant = opentype::stretch_glyph(
face, glyph, character,
&source.paint.clone().derived(crate::provenance::Derivation::MathVariant),
Stretch::Vertical, target,
self.delimiter_glyph_limit.saturating_sub(self.delimiter_glyphs.get()),
)?;
self.reserve_delimiter_glyphs(variant.geometry.items.len())?;
body = variant.geometry;
italic = variant.italic;
}
(self.pack_field(vec![TextNode::MathChar(super::math::math_box(body))])?, italic)
} else {
if style.display() {
if let Some(next) = face.metrics().next_larger(char::from(c.slot as u8)) {
if self.state.font_has_slot(face.id, next) {
c.slot = u32::from(next);
source.paint = source
.paint
.derived(crate::provenance::Derivation::MathVariant);
}
}
let face = self.font(c.family, style)?;
if style.display()
&& let Some(next) = face.metrics().next_larger(char::from(c.slot as u8))
&& self.state.font_has_slot(id, next)
{
c.slot = u32::from(next);
source.paint = source
.paint
.derived(crate::provenance::Derivation::MathVariant);
}
let italic = face.metrics().italic(char::from(c.slot as u8));
(
self.owned_field(&MathField::Char(c), style, &source)?,
italic,
)
(self.owned_field(&MathField::Char(c), style, &source)?, italic)
};
if n.sub.is_some() && !limits {
b.width -= italic;