Separate format font metrics from live expansion links

This commit is contained in:
gloamxun committed 2026-11-21 08:43:02 +08:00
1 parent 9b80a782cf
commit b008c0693a
11 files changed
+389 -84

No files matched your search

@@ -0,0 +1,64 @@
//! Format schema 53 stored device faces in boxes. Rebind them to the original
//! logical font slots before a restored job changes any active expansion links.
use super::*;
use crate::{math_engine_tex::MathItem, native_font::NativeFont};
use std::{collections::BTreeMap, sync::Arc};
type Replacements = BTreeMap<(FontId, i32), Arc<NativeFont>>;
impl NativeBox {
pub(in crate::execution) fn rebind_legacy_expansion_fonts(&mut self, fonts: &Replacements) {
match &mut self.content {
BoxContent::Horizontal(nodes) => rebind_horizontal(nodes, fonts),
BoxContent::Vertical(nodes) => rebind_vertical(nodes, fonts),
}
}
}
fn rebind_horizontal(nodes: &mut [TextNode], fonts: &Replacements) {
for node in nodes {
match node {
TextNode::Glyph { glyph, .. } | TextNode::Box(glyph) | TextNode::MathChar(glyph) => {
if let Some(b) = &mut glyph.native_box {
b.rebind_legacy_expansion_fonts(fonts);
}
if let Some(geometry) = &mut glyph.math_geometry {
for item in &mut geometry.items {
if let MathItem::NativeGlyph { font, .. } = &mut item.item
&& let Some(logical) = fonts.get(&(font.id, font.expansion))
{
*font = logical.clone();
}
}
}
}
TextNode::Discretionary { pre_break, post_break, .. } => {
rebind_horizontal(pre_break, fonts);
rebind_horizontal(post_break, fonts);
}
TextNode::Adjustment(value) => rebind_vertical(&mut value.nodes, fonts),
TextNode::Insertion(value) => rebind_vertical(&mut value.nodes, fonts),
TextNode::Leaders(leader) => rebind_leader(leader, fonts),
_ => {}
}
}
}
fn rebind_vertical(nodes: &mut [NativeVerticalNode], fonts: &Replacements) {
for node in nodes {
match node {
NativeVerticalNode::Box(b) | NativeVerticalNode::Line(b) => {
b.rebind_legacy_expansion_fonts(fonts);
}
NativeVerticalNode::Insertion(value) => rebind_vertical(&mut value.nodes, fonts),
NativeVerticalNode::Leaders(leader) => rebind_leader(leader, fonts),
_ => {}
}
}
}
fn rebind_leader(leader: &mut LeaderGlue, fonts: &Replacements) {
if let LeaderPattern::Box(b) = &mut leader.pattern {
b.rebind_legacy_expansion_fonts(fonts);
}
}