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

@@ -14,6 +14,12 @@ impl Converter<'_> {
) -> Result<NativeBox, String> {
let params = self.params(style)?;
let thickness = spec.thickness.map_or(params.rule_thickness, i64::from);
let extension = self.state.fonts.font(self.family_font(3, style)?)?;
let constants = extension
.opentype()
.map(|font| crate::opentype::MathConstants::read(font))
.transpose()?
.flatten();
let mut upper = self.pack_field(self.convert(numerator, style.numerator(), false)?.0)?;
let mut lower =
self.pack_field(self.convert(denominator, style.denominator(), false)?.0)?;
@@ -36,7 +42,15 @@ impl Converter<'_> {
};
let half = (thickness + 1).div_euclid(2);
if thickness == 0 {
let clearance = if style.display() { 7 } else { 3 } * params.rule_thickness;
let clearance = if let Some(math) = &constants {
math.measure(if style.display() {
math.values.stack_display_style_gap_min()
} else {
math.values.stack_gap_min()
})
} else {
(if style.display() { 7 } else { 3 }) * params.rule_thickness
};
let delta =
(clearance - ((up - upper.depth) - (lower.height - down)) + 1).div_euclid(2);
if delta > 0 {
@@ -44,13 +58,29 @@ impl Converter<'_> {
down += delta;
}
} else {
let clearance = if style.display() {
3 * thickness
let (above, below) = if let Some(math) = &constants {
let (above, below) = if style.display() {
(
math.values.fraction_num_display_style_gap_min(),
math.values.fraction_denom_display_style_gap_min(),
)
} else {
(
math.values.fraction_numerator_gap_min(),
math.values.fraction_denominator_gap_min(),
)
};
(math.measure(above), math.measure(below))
} else {
thickness
let clearance = if style.display() {
3 * thickness
} else {
thickness
};
(clearance, clearance)
};
up = up.max(upper.depth + params.axis_height + half + clearance);
down = down.max(lower.height - params.axis_height + half + clearance);
up = up.max(upper.depth + params.axis_height + half + above);
down = down.max(lower.height - params.axis_height + half + below);
}
let width = upper.width;
let height = up + upper.height;