Resolve named XeTeX fonts from configured directories

This commit is contained in:
gloamxun committed 2026-11-28 06:53:16 +08:00
1 parent aae23d837e
commit 2846f7f1e7
3 files changed
+310 -78

No files matched your search

+27 -7
View File
@@ -383,6 +383,8 @@ pub struct InputSnapshot {
tex_suffix_fallback: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
system_fonts: Option<Result<Vec<named_fonts::NamedFace>, String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
named_font_directories: Option<Vec<named_fonts::FontDirectory>>,
}
/// A failed enumeration is not a complete namespace. Retain the usable prefix
/// only as evidence and replay its actual error, never as a successful index.
@@ -462,6 +464,15 @@ impl InputSnapshot {
{
return Err("invalid captured font catalogue".into());
}
if let Some(directories) = &self.named_font_directories
&& (self.project.is_some() && !directories.is_empty()
|| directories.iter().enumerate().any(|(i, directory)| {
!directory.valid_capture(self.config.max_index_entries)
|| directories[..i].iter().any(|prior| prior.scope == directory.scope)
}))
{
return Err("invalid captured named font directory".into());
}
if let Some(project) = &self.project {
project.validate()?;
if project.configuration() != self.config {
@@ -570,6 +581,7 @@ pub struct FileWorld {
project: Option<Arc<ProjectSnapshot>>,
system_fonts: Option<Result<Vec<named_fonts::NamedFace>, String>>,
project_named_fonts: Option<Vec<named_fonts::NamedFace>>,
named_font_directories: Option<Vec<named_fonts::FontDirectory>>,
}
impl FileWorld {
pub fn default_pk_resolution(&self) -> i32 {
@@ -709,6 +721,7 @@ impl FileWorld {
project: None,
system_fonts: None,
project_named_fonts: None,
named_font_directories: Some(Vec::new()),
})
}
pub fn capture_inputs(&mut self) {
@@ -758,6 +771,7 @@ impl FileWorld {
project: Some(project),
system_fonts: None,
project_named_fonts: None,
named_font_directories: Some(Vec::new()),
})
}
pub fn project(&self) -> Option<&Arc<ProjectSnapshot>> {
@@ -847,6 +861,7 @@ impl FileWorld {
project: snapshot.project.clone(),
system_fonts: snapshot.system_fonts.clone(),
project_named_fonts: None,
named_font_directories: snapshot.named_font_directories.clone(),
})
}
pub fn input_snapshot(&self) -> Arc<InputSnapshot> {
@@ -868,6 +883,7 @@ impl FileWorld {
replay_gaps: gaps,
project: self.project.clone(),
system_fonts: self.system_fonts.clone(),
named_font_directories: self.named_font_directories.clone(),
})
}
/// Only the authorized host may mark its generated-file paths live. These
@@ -1218,20 +1234,24 @@ impl FileWorld {
));
}
}
let value = fs::read(self.generated_storage(&path))
let value = self.read_input_from_disk(&path);
if self.pinned && !live {
self.input_files.insert(path, value.clone());
}
value
}
fn read_input_from_disk(&self, path: &Path) -> Result<SnapshotFile, String> {
fs::read(self.generated_storage(path))
.map(|data| SnapshotFile {
version: ResourceVersion {
path: path.clone(),
path: path.to_owned(),
sha256: format!("{:x}", Sha256::digest(&data)),
bytes: data.len() as u64,
},
data: Arc::from(data),
})
.map_err(|e| format!("resource {}: {e}", path.display()));
if self.pinned && !live {
self.input_files.insert(path, value.clone());
}
value
.map_err(|e| format!("resource {}: {e}", path.display()))
}
/// Pins bytes for an external stream without claiming that its whole
/// contents were delivered to TeX. Consumption remains in stream_reads.