Rebind native format TFM resources after project relocation
This commit is contained in:
1 parent
1ad9c4db82
commit
65204a7dae
9 files changed
+304
-35
No files matched your search
+28
-26
@@ -1,64 +1,66 @@
|
||||
//! 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.
|
||||
//! Visit the font instances retained by packed glyphs in a format.
|
||||
use super::*;
|
||||
use crate::{math_engine_tex::MathItem, native_font::NativeFont};
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
type Replacements = BTreeMap<(FontId, i32), Arc<NativeFont>>;
|
||||
use std::sync::Arc;
|
||||
|
||||
impl NativeBox {
|
||||
pub(in crate::execution) fn rebind_legacy_expansion_fonts(&mut self, fonts: &Replacements) {
|
||||
pub(in crate::execution) fn visit_format_fonts_mut(
|
||||
&mut self,
|
||||
visit: &mut impl FnMut(&mut Arc<NativeFont>),
|
||||
) {
|
||||
match &mut self.content {
|
||||
BoxContent::Horizontal(nodes) => rebind_horizontal(nodes, fonts),
|
||||
BoxContent::Vertical(nodes) => rebind_vertical(nodes, fonts),
|
||||
BoxContent::Horizontal(nodes) => rebind_horizontal(nodes, visit),
|
||||
BoxContent::Vertical(nodes) => rebind_vertical(nodes, visit),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rebind_horizontal(nodes: &mut [TextNode], fonts: &Replacements) {
|
||||
fn rebind_horizontal(nodes: &mut [TextNode], visit: &mut impl FnMut(&mut Arc<NativeFont>)) {
|
||||
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);
|
||||
b.visit_format_fonts_mut(visit);
|
||||
}
|
||||
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();
|
||||
if let MathItem::NativeGlyph { font, .. } = &mut item.item {
|
||||
visit(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TextNode::Discretionary { pre_break, post_break, .. } => {
|
||||
rebind_horizontal(pre_break, fonts);
|
||||
rebind_horizontal(post_break, fonts);
|
||||
TextNode::Discretionary {
|
||||
pre_break,
|
||||
post_break,
|
||||
..
|
||||
} => {
|
||||
rebind_horizontal(pre_break, visit);
|
||||
rebind_horizontal(post_break, visit);
|
||||
}
|
||||
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),
|
||||
TextNode::Adjustment(value) => rebind_vertical(&mut value.nodes, visit),
|
||||
TextNode::Insertion(value) => rebind_vertical(&mut value.nodes, visit),
|
||||
TextNode::Leaders(leader) => rebind_leader(leader, visit),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rebind_vertical(nodes: &mut [NativeVerticalNode], fonts: &Replacements) {
|
||||
fn rebind_vertical(nodes: &mut [NativeVerticalNode], visit: &mut impl FnMut(&mut Arc<NativeFont>)) {
|
||||
for node in nodes {
|
||||
match node {
|
||||
NativeVerticalNode::Box(b) | NativeVerticalNode::Line(b) => {
|
||||
b.rebind_legacy_expansion_fonts(fonts);
|
||||
b.visit_format_fonts_mut(visit);
|
||||
}
|
||||
NativeVerticalNode::Insertion(value) => rebind_vertical(&mut value.nodes, fonts),
|
||||
NativeVerticalNode::Leaders(leader) => rebind_leader(leader, fonts),
|
||||
NativeVerticalNode::Insertion(value) => rebind_vertical(&mut value.nodes, visit),
|
||||
NativeVerticalNode::Leaders(leader) => rebind_leader(leader, visit),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rebind_leader(leader: &mut LeaderGlue, fonts: &Replacements) {
|
||||
fn rebind_leader(leader: &mut LeaderGlue, visit: &mut impl FnMut(&mut Arc<NativeFont>)) {
|
||||
if let LeaderPattern::Box(b) = &mut leader.pattern {
|
||||
b.rebind_legacy_expansion_fonts(fonts);
|
||||
b.visit_format_fonts_mut(visit);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user