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

+21 -5
View File
@@ -150,6 +150,14 @@ pub struct MathParams {
pub big_op_spacing: [i64; 5],
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ScriptBounds {
pub subscript_top_max: i64,
pub superscript_bottom_min: i64,
pub paired_gap: i64,
pub paired_superscript_bottom: i64,
}
impl MathParams {
pub fn for_style(style: MathStyle) -> Self {
Self::from_metrics(
@@ -523,6 +531,7 @@ pub(crate) fn place_scripts(
drop,
style,
script_space,
None,
)
.0
}
@@ -541,8 +550,15 @@ pub(crate) fn place_scripts_with_layout(
drop: MathParams,
style: MathStyle,
script_space: i64,
script_bounds: Option<ScriptBounds>,
) -> (MathGeometry, ScriptPlacement) {
let has_sub = lower.is_some();
let bounds = script_bounds.unwrap_or(ScriptBounds {
subscript_top_max: 4 * params.x_height.abs() / 5,
superscript_bottom_min: params.x_height.abs() / 4,
paired_gap: 4 * params.rule_thickness,
paired_superscript_bottom: 4 * params.x_height.abs() / 5,
});
let mut up = if single {
0
} else {
@@ -563,22 +579,22 @@ pub(crate) fn place_scripts_with_layout(
};
up = up
.max(min)
.max(upper.metrics.depth + params.x_height.abs() / 4);
.max(upper.metrics.depth + bounds.superscript_bottom_min);
}
if let Some(lower) = &lower {
if let Some(upper) = &upper {
down = down.max(params.sub2);
let gap = up - upper.metrics.depth - lower.metrics.height + down;
if gap < 4 * params.rule_thickness {
down += 4 * params.rule_thickness - gap;
let lift = (4 * params.x_height.abs() / 5 - (up - upper.metrics.depth)).max(0);
if gap < bounds.paired_gap {
down += bounds.paired_gap - gap;
let lift = (bounds.paired_superscript_bottom - (up - upper.metrics.depth)).max(0);
up += lift;
down -= lift;
}
} else {
down = down
.max(params.sub1)
.max(lower.metrics.height - 4 * params.x_height.abs() / 5);
.max(lower.metrics.height - bounds.subscript_top_max);
}
}
let start = body.metrics.width;