Implement native automatic font expansion for paragraphs

This commit is contained in:
gloamxun committed 2026-11-20 23:29:37 +08:00
1 parent 1dd745afcb
commit ebbc9e2c17
24 files changed
+632 -34

No files matched your search

@@ -7,6 +7,8 @@ pub enum DiagnosticNode {
Character {
font: FontId,
slot: u8,
#[serde(default, skip_serializing_if = "crate::native_font::unexpanded")]
expansion: i32,
ligature: Option<String>,
},
Box(DiagnosticBox),
@@ -151,6 +153,7 @@ pub(super) fn text_nodes(nodes: &[TextNode]) -> Vec<DiagnosticNode> {
TextNode::Language(l) => DiagnosticNode::Language(*l),
TextNode::Glyph {
font,
glyph,
slot,
original,
ligature,
@@ -160,6 +163,13 @@ pub(super) fn text_nodes(nodes: &[TextNode]) -> Vec<DiagnosticNode> {
} => DiagnosticNode::Character {
font: *font,
slot: *slot,
expansion: glyph.math_geometry.as_ref()
.and_then(|geometry| geometry.items.first())
.and_then(|paint| match &paint.item {
crate::math_engine_tex::MathItem::NativeGlyph { font, .. } => Some(font.expansion),
_ => None,
})
.unwrap_or(0),
ligature: ligature.then(|| {
format!(
"{}{original}{}",
@@ -182,6 +192,7 @@ pub(super) fn text_nodes(nodes: &[TextNode]) -> Vec<DiagnosticNode> {
DiagnosticNode::Character {
font: font.id,
slot: *slot,
expansion: font.expansion,
ligature: None,
}
} else {
@@ -338,9 +349,12 @@ impl Printer<'_> {
self.flex(g.shrink.amount, g.shrink.order);
}
}
fn character(&mut self, font: FontId, slot: u8) -> Result<(), String> {
fn character(&mut self, font: FontId, slot: u8, expansion: i32) -> Result<(), String> {
let name = self.state.fonts.font(font)?.identifier_text();
self.command(&name);
if expansion != 0 {
self.literal(&format!(" ({expansion:+})"));
}
self.literal(" ");
self.ascii(slot);
Ok(())
@@ -443,9 +457,10 @@ impl Printer<'_> {
DiagnosticNode::Character {
font,
slot,
expansion,
ligature,
} => {
self.character(*font, *slot)?;
self.character(*font, *slot, *expansion)?;
if let Some(s) = ligature {
self.literal(" (ligature ");
for c in s.chars() {