Rebind native format TFM resources after project relocation

This commit is contained in:
gloamxun committed 2026-11-28 01:46:37 +08:00
1 parent 1ad9c4db82
commit 65204a7dae
9 files changed
+304 -35

No files matched your search

+22
View File
@@ -114,6 +114,28 @@ pub(crate) fn unexpanded(amount: &i32) -> bool {
}
impl NativeFont {
pub(crate) fn rebind_resource_path(
font: &mut Arc<Self>,
bindings: &BTreeMap<std::path::PathBuf, std::path::PathBuf>,
) -> bool {
let path = bindings.get(&font.resource.version.path);
let base = font.letter_spacing.as_ref().and_then(|spacing| {
let mut base = spacing.base.clone();
Self::rebind_resource_path(&mut base, bindings).then_some(base)
});
if path.is_none() && base.is_none() {
return false;
}
let font = Arc::make_mut(font);
if let Some(path) = path {
font.resource.version.path.clone_from(path);
}
if let Some(base) = base {
font.letter_spacing.as_mut().expect("relocated letterspace base").base = base;
}
true
}
pub fn metrics(&self) -> &TfmMetrics {
&self.metrics
}