diff --git a/crates/texrra-tex-core/src/execution/engine.rs b/crates/texrra-tex-core/src/execution/engine.rs index 322e166..a91aa91 100644 --- a/crates/texrra-tex-core/src/execution/engine.rs +++ b/crates/texrra-tex-core/src/execution/engine.rs @@ -2596,7 +2596,14 @@ impl Executor { self.unread(first) } fn filename(&mut self, files: &mut impl SourceProvider) -> Result { + self.filename_with_quoting(files).map(|(name, _)| name) + } + fn filename_with_quoting( + &mut self, + files: &mut impl SourceProvider, + ) -> Result<(String, bool), Error> { let first = self.expanded_non_space(files)?; + let mut used_quotes = false; let mut name = std::string::String::new(); if first.token.kind.begin_group() { loop { @@ -2614,7 +2621,10 @@ impl Executor { let mut quoted = false; while let Some(token) = next { match token.token.kind { - TokenKind::Character('"', CatCode::Other) => quoted = !quoted, + TokenKind::Character('"', CatCode::Other) => { + quoted = !quoted; + used_quotes = true; + } TokenKind::Character(' ', CatCode::Space) if quoted => name.push(' '), TokenKind::Character(_, CatCode::Space) => break, TokenKind::Character(c, CatCode::Letter | CatCode::Other) => name.push(c), @@ -2632,7 +2642,7 @@ impl Executor { if name.is_empty() { return self.fail("empty filename"); } - self.decode_filename(name) + self.decode_filename(name).map(|name| (name, used_quotes)) } fn decode_filename(&self, name: String) -> Result { if self.state.input_profile() == super::InputProfile::TeX8Bit { diff --git a/crates/texrra-tex-core/src/execution/engine/paragraphs.rs b/crates/texrra-tex-core/src/execution/engine/paragraphs.rs index 7c0d23d..516c3d6 100644 --- a/crates/texrra-tex-core/src/execution/engine/paragraphs.rs +++ b/crates/texrra-tex-core/src/execution/engine/paragraphs.rs @@ -658,7 +658,7 @@ impl Executor { let name = self.command(files)?; self.define_traced(name.clone(), Meaning::Font(FontId::NULL), global, files)?; self.optional_equals(files)?; - let file = self.filename(files)?; + let (file, quoted) = self.filename_with_quoting(files)?; let size = if self.keyword("at", files)? { crate::tfm::FontSize::At(self.dimension(false, false, files)?.amount as i64) } else if self.keyword("scaled", files)? { @@ -676,18 +676,41 @@ impl Executor { }; let suppress = self.state.input_profile() == super::super::InputProfile::XeTeX && self.read_parameter(Parameter::Suppressfontnotfounderror).width() != 0; + use super::super::font_catalog::FontLoadError; + let load_named = |catalog: &mut super::super::FontCatalog, files: &mut _| { + let Some(request) = crate::opentype::NamedRequest::parse(&file) else { + return Ok(None); + }; + let Some(font) = SourceProvider::named_font(files, request.name, request.style, &from)? else { + return Ok(None); + }; + let (spec, selected) = request.request(&font)?; + catalog.load_opentype( + files, &spec, selected, &from, size, name.clone(), defaults, suppress, Some(font.resource), + ).map(Some) + }; let font = if let Some(request) = request { self.state.fonts.load_opentype( - files, &file, request, &from, size, name.clone(), defaults, suppress, + files, &file, request, &from, size, name.clone(), defaults, suppress, None, ) + } else if self.state.input_profile() == super::super::InputProfile::XeTeX { + if quoted { + load_named(&mut self.state.fonts, files).and_then(|named| match named { + Some(font) => Ok(font), + None => self.state.fonts.load_tfm(files, &file, &from, size, name.clone(), defaults, true), + }) + } else { + match self.state.fonts.load_tfm(files, &file, &from, size, name.clone(), defaults, true) { + Err(missing @ FontLoadError::Missing(_)) => load_named(&mut self.state.fonts, files).and_then(|font| font.ok_or(missing)), + result => result, + } + } } else { - self.state.fonts.load_tfm( - files, &file, &from, size, name.clone(), defaults, suppress, - ) + self.state.fonts.load_tfm(files, &file, &from, size, name.clone(), defaults, false) }; match font { Ok(font) => self.define_traced(name, Meaning::Font(font), global, files), - Err(super::super::font_catalog::FontLoadError::Rejected(_)) if suppress => Ok(()), + Err(FontLoadError::Rejected(_) | FontLoadError::Missing(_)) if suppress => Ok(()), Err(error) => Err(self.error(error.message(), self.current)), } } diff --git a/crates/texrra-tex-core/src/execution/font_catalog.rs b/crates/texrra-tex-core/src/execution/font_catalog.rs index 9d4e0e1..c38a3c9 100644 --- a/crates/texrra-tex-core/src/execution/font_catalog.rs +++ b/crates/texrra-tex-core/src/execution/font_catalog.rs @@ -13,6 +13,7 @@ use std::{collections::BTreeMap, sync::Arc}; /// Rejected font candidates can produce nullfont in a XeTeX existence /// probe. Host, resource-integrity and engine errors remain distinct. pub(super) enum FontLoadError { + Missing(String), Rejected(String), Fatal(String), } @@ -20,7 +21,7 @@ pub(super) enum FontLoadError { impl FontLoadError { pub(super) fn message(self) -> String { match self { - Self::Rejected(message) | Self::Fatal(message) => message, + Self::Missing(message) | Self::Rejected(message) | Self::Fatal(message) => message, } } } @@ -373,12 +374,14 @@ impl FontCatalog { selector: CommandName, defaults: FontIntegers, optional: bool, + resolved: Option, ) -> Result { size.validate()?; for (index, instance) in self.fonts.iter_mut().enumerate() { if let Some(font) = &instance.opentype && instance.name == spec && font.requested_size(size) == font.size + && resolved.as_ref().is_none_or(|file| file.version == font.resource.version) { instance.selector = selector; return Ok(FontId(index as u32)); @@ -389,7 +392,9 @@ impl FontCatalog { return Err(FontLoadError::Fatal("native font parameter capacity exceeded".into())); } let names = request.resource_names(); - let loaded = if let [(kind, name)] = &names[..] { + let loaded = if let Some(resolved) = resolved { + resolved + } else if let [(kind, name)] = &names[..] { Self::font_file(files, *kind, name, from, optional)? } else { let mut selected = None; @@ -547,7 +552,7 @@ impl FontCatalog { ) -> Result { if optional { return files.optional_font_file(kind, name, from)?.ok_or_else(|| { - FontLoadError::Rejected(format!("native {kind:?} resource {name} not found from {from}")) + FontLoadError::Missing(format!("native {kind:?} resource {name} not found from {from}")) }); } Ok(files.resource(kind, name, from)?) diff --git a/crates/texrra-tex-core/src/execution/mod.rs b/crates/texrra-tex-core/src/execution/mod.rs index 9d684c6..60b5bb6 100644 --- a/crates/texrra-tex-core/src/execution/mod.rs +++ b/crates/texrra-tex-core/src/execution/mod.rs @@ -253,6 +253,15 @@ pub trait SourceProvider { ) -> Result, String> { Ok(None) } + /// Look up a real named outline face in the host's resource namespace. + fn named_font( + &mut self, + _name: &str, + _style: crate::resources::FontStyle, + _from: &str, + ) -> Result, String> { + Ok(None) + } /// An exact lookup that can report a missing font file before trying another format. fn optional_font_file( &mut self, kind: crate::resources::ResourceKind, name: &str, from: &str, diff --git a/crates/texrra-tex-core/src/opentype.rs b/crates/texrra-tex-core/src/opentype.rs index be1ee09..1ddf991 100644 --- a/crates/texrra-tex-core/src/opentype.rs +++ b/crates/texrra-tex-core/src/opentype.rs @@ -57,6 +57,10 @@ impl Request { if file.is_empty() { return Err("missing OpenType filename".into()); } + Self::with_options(file, index, options).map(Some) + } + + pub(crate) fn with_options(file: &str, index: u32, options: &str) -> Result { let options = options.strip_prefix("/OT").unwrap_or(options); let features = if options.is_empty() { "" @@ -98,7 +102,7 @@ impl Request { request.features.push(feature.to_owned()); } } - Ok(Some(request)) + Ok(request) } pub(crate) fn resource_names(&self) -> Vec<(ResourceKind, String)> { @@ -123,6 +127,45 @@ impl Request { } } +pub(crate) struct NamedRequest<'a> { + pub name: &'a str, + pub style: crate::resources::FontStyle, + options: String, +} + +impl<'a> NamedRequest<'a> { + pub(crate) fn parse(spec: &'a str) -> Option { + let (base, features) = spec.split_once(':').map_or((spec, ""), |(base, features)| (base, features)); + let mut parts = base.split('/'); + let name = parts.next()?; + if name.is_empty() || name.contains('\\') { + return None; + } + let mut style = crate::resources::FontStyle::default(); + let mut options = String::new(); + for part in parts { + match part { + "OT" | "ICU" => options.push_str("/OT"), + "B" => style.bold = true, + "I" => style.italic = true, + "BI" | "IB" => style = crate::resources::FontStyle { bold: true, italic: true }, + _ => return None, + } + } + if !features.is_empty() { + options.push(':'); + options.push_str(features); + } + Some(Self { name, style, options }) + } + + pub(crate) fn request(&self, font: &crate::resources::NamedFont) -> Result<(String, Request), String> { + let path = font.resource.version.path.to_str().ok_or("named font path is not UTF-8")?; + let spec = format!(r#""{}{}""#, font.full_name, self.options); + Ok((spec, Request::with_options(path, font.index, &self.options)?)) + } +} + #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct OpenTypeFont { pub id: FontId, diff --git a/crates/texrra-tex-core/src/resources.rs b/crates/texrra-tex-core/src/resources.rs index c8276f8..adf8011 100644 --- a/crates/texrra-tex-core/src/resources.rs +++ b/crates/texrra-tex-core/src/resources.rs @@ -1,5 +1,7 @@ //! Native filesystem resource lookup. No external TeX/kpathsea subprocess. mod deferred; +mod named_fonts; +pub use named_fonts::{FontStyle, NamedFont}; mod project; pub use deferred::{ DeferredProbe, DirectoryAbsence, GeneratedLookup, GeneratedLookupOrigin, GeneratedLookupRole, @@ -359,6 +361,8 @@ pub struct InputSnapshot { // Older captures only probed the supplied name when it had a suffix. #[serde(default)] tex_suffix_fallback: bool, + #[serde(default, skip_serializing_if = "Option::is_none")] + system_fonts: Option, String>>, } /// 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. @@ -429,6 +433,15 @@ impl InputSnapshot { if self.schema != 1 || !self.config.cwd.is_absolute() { return Err("incompatible native input snapshot".into()); } + if self.project.is_some() && self.system_fonts.is_some() { + return Err("atomic project cannot import a live system font catalogue".into()); + } + if let Some(Ok(faces)) = &self.system_fonts + && (faces.len() > self.config.max_index_entries + || faces.iter().any(|face| !face.valid_capture())) + { + return Err("invalid captured font catalogue".into()); + } if let Some(project) = &self.project { project.validate()?; if project.configuration() != self.config { @@ -534,6 +547,8 @@ pub struct FileWorld { protected_paths: BTreeSet, replay_gaps: Vec, project: Option>, + system_fonts: Option, String>>, + project_named_fonts: Option>, } impl FileWorld { pub fn default_pk_resolution(&self) -> i32 { @@ -669,6 +684,8 @@ impl FileWorld { protected_paths: BTreeSet::new(), replay_gaps: Vec::new(), project: None, + system_fonts: None, + project_named_fonts: None, }) } pub fn capture_inputs(&mut self) { @@ -710,6 +727,8 @@ impl FileWorld { protected_paths: BTreeSet::new(), replay_gaps: Vec::new(), project: Some(project), + system_fonts: None, + project_named_fonts: None, }) } pub fn project(&self) -> Option<&Arc> { @@ -796,6 +815,8 @@ impl FileWorld { protected_paths: BTreeSet::new(), replay_gaps: Vec::new(), project: snapshot.project.clone(), + system_fonts: snapshot.system_fonts.clone(), + project_named_fonts: None, }) } pub fn input_snapshot(&self) -> Arc { @@ -816,6 +837,7 @@ impl FileWorld { lookups: self.trace.lookups.clone(), replay_gaps: gaps, project: self.project.clone(), + system_fonts: self.system_fonts.clone(), }) } /// Only the authorized host may mark its generated-file paths live. These diff --git a/crates/texrra-tex-core/src/resources/named_fonts.rs b/crates/texrra-tex-core/src/resources/named_fonts.rs new file mode 100644 index 0000000..dcf5406 --- /dev/null +++ b/crates/texrra-tex-core/src/resources/named_fonts.rs @@ -0,0 +1,329 @@ +//! Named OpenType faces from the host catalogue or an atomic project. +use super::*; +use rustybuzz::ttf_parser::{self, name_id}; + +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct FontStyle { + pub bold: bool, + pub italic: bool, +} + +pub struct NamedFont { + pub resource: LoadedResource, + pub index: u32, + pub full_name: String, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub(super) struct NamedFace { + path: PathBuf, + index: u32, + full_name: String, + family: String, + style: String, + postscript: String, + bold: bool, + italic: bool, + regular: bool, +} + +impl NamedFace { + fn at(path: &Path, data: &[u8], index: u32) -> Option { + let face = ttf_parser::Face::parse(data, index).ok()?; + let name = |id| { + face.names() + .into_iter() + .filter(|name| name.name_id == id) + .find_map(|name| name.to_string()) + }; + let postscript = name(name_id::POST_SCRIPT_NAME)?; + Some(Self { + path: path.to_path_buf(), + index, + full_name: name(name_id::FULL_NAME).unwrap_or_else(|| postscript.clone()), + family: name(name_id::TYPOGRAPHIC_FAMILY) + .or_else(|| name(name_id::FAMILY)) + .unwrap_or_default(), + style: name(name_id::TYPOGRAPHIC_SUBFAMILY) + .or_else(|| name(name_id::SUBFAMILY)) + .unwrap_or_default(), + postscript, + bold: face.is_bold(), + italic: face.is_italic() || face.is_oblique(), + regular: face.is_regular(), + }) + } + + pub(super) fn valid_capture(&self) -> bool { + self.path.is_absolute() && is_outline(&self.path) && self.index <= u32::from(u16::MAX) + } + + fn name_priority(&self, name: &str) -> Option { + if self.full_name == name { + Some(0) + } else if name.split_once('-') == Some((&self.family, &self.style)) { + Some(1) + } else if self.postscript == name { + Some(2) + } else if self.family == name { + Some(3) + } else { + None + } + } + + fn regular_priority(&self) -> u8 { + match self.style.as_str() { + "Regular" => 0, + "Plain" => 1, + "Normal" => 2, + "Roman" => 3, + _ if self.regular => 4, + _ if !self.bold && !self.italic => 5, + _ => 6, + } + } +} + +fn is_outline(path: &Path) -> bool { + path.extension() + .and_then(|ext| ext.to_str()) + .is_some_and(|ext| { + ["otf", "ttf", "otc", "ttc"] + .iter() + .any(|kind| ext.eq_ignore_ascii_case(kind)) + }) +} + +#[cfg(target_os = "linux")] +fn system_faces(limit: usize) -> Result, String> { + let output = match std::process::Command::new("fc-list").args([ + "--format", "%{file}\\t%{index}\\t%{fullname[0]}\\t%{family[0]}\\t%{style[0]}\\t%{postscriptname[0]}\\t%{weight[0]}\\t%{slant[0]}\\n", + ]).output() { + Ok(output) => output, + Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()), + Err(error) => return Err(format!("Fontconfig font catalogue: {error}")), + }; + if !output.status.success() { + return Err(format!( + "Fontconfig font catalogue exited with {}", + output.status + )); + } + let mut faces = Vec::new(); + let text = + String::from_utf8(output.stdout).map_err(|_| "Fontconfig font catalogue is not UTF-8")?; + for line in text.lines() { + let mut fields = line.split('\t'); + let ( + Some(path), + Some(index), + Some(full), + Some(family), + Some(style), + Some(postscript), + Some(weight), + Some(slant), + ) = ( + fields.next(), + fields.next(), + fields.next(), + fields.next(), + fields.next(), + fields.next(), + fields.next(), + fields.next(), + ) + else { + return Err("invalid Fontconfig font catalogue record".into()); + }; + let path = PathBuf::from(path); + if !path.is_absolute() || !is_outline(&path) { + continue; + } + let index: u32 = index.parse().map_err(|_| "invalid Fontconfig face index")?; + // Fontconfig encodes variable named instances in the high bits. The + // OpenType loader currently takes a face index, not axis coordinates. + if index > u32::from(u16::MAX) { + continue; + } + let weight = weight.parse::().unwrap_or(80); + let italic = slant != "0" && !slant.is_empty(); + if faces.len() >= limit { + return Err("Fontconfig font catalogue capacity exceeded".into()); + } + faces.push(NamedFace { + path, + index, + full_name: if full.is_empty() { postscript } else { full }.into(), + family: family.into(), + style: style.into(), + postscript: postscript.into(), + bold: weight >= 180, + italic, + regular: weight == 80 && !italic, + }); + } + Ok(faces) +} + +#[cfg(not(target_os = "linux"))] +fn system_faces(_limit: usize) -> Result, String> { + Ok(Vec::new()) +} + +impl FileWorld { + pub fn read_named_font( + &mut self, + name: &str, + style: FontStyle, + from: &Path, + ) -> Result, String> { + let mut candidates = Vec::new(); + let result = self.select_named_face(name, style, from, &mut candidates); + self.trace.lookups.push(ResourceLookup { + kind: ResourceKind::OpenType, + name: name.into(), + from: from.into(), + candidates, + resolved: result + .as_ref() + .ok() + .and_then(|result| result.as_ref()) + .map(|font| font.resource.version.path.clone()), + error: result.as_ref().err().cloned(), + }); + result + } + + fn select_named_face( + &mut self, + name: &str, + style: FontStyle, + from: &Path, + candidates: &mut Vec, + ) -> Result, String> { + let scoped = if let Some(project) = &self.project { + if self.project_named_fonts.is_none() { + let paths: Vec<_> = self + .paths(ResourceKind::OpenType, from) + .into_iter() + .chain(self.paths(ResourceKind::TrueType, from)) + .collect(); + let mut all = Vec::new(); + let mut remaining = self.config.max_index_entries; + for (path, file) in project.files() { + if !is_outline(path) + || !paths.iter().any(|scope| self.font_path_in(scope, path)) + { + continue; + } + let count = if let Some(count) = ttf_parser::fonts_in_collection(&file.data) { + if count as usize > file.data.len().saturating_sub(12) / 4 { + continue; // The collection's face directory is truncated. + } + count + } else { + 1 + }; + remaining = remaining + .checked_sub(count as usize) + .ok_or("project font catalogue capacity exceeded")?; + all.extend( + (0..count).filter_map(|index| NamedFace::at(path, &file.data, index)), + ); + } + self.project_named_fonts = Some(all); + } + self.project_named_fonts.as_deref().unwrap_or_default() + } else { + if self.system_fonts.is_none() && !self.replay { + self.system_fonts = Some(system_faces(self.config.max_index_entries)); + } + match &self.system_fonts { + Some(Ok(faces)) => faces, + Some(Err(error)) => return Err(error.clone()), + None => return Ok(None), // Older captures had no host named-font lookup. + } + }; + let mut matches: Vec<_> = scoped + .iter() + .filter_map(|face| { + Some(( + face.name_priority(name)?, + face.regular_priority(), + &face.path, + face.index, + face, + )) + }) + .collect(); + matches.sort_by(|a, b| (a.0, a.1, a.2, a.3).cmp(&(b.0, b.1, b.2, b.3))); + candidates.extend(matches.iter().map(|(_, _, path, _, _)| (*path).clone())); + let Some((_, _, _, _, base)) = matches.first() else { + return Ok(None); + }; + let face = if style.bold || style.italic { + let bold = style.bold || base.bold; + let italic = style.italic || base.italic; + scoped + .iter() + .filter(|face| { + face.family == base.family && face.bold == bold && face.italic == italic + }) + .min_by_key(|face| (&face.style, &face.path, face.index)) + .unwrap_or(base) + } else { + base + }; + let face = (*face).clone(); + if !candidates.contains(&face.path) { + candidates.push(face.path.clone()); + } + let Some(path) = self.probe(&face.path)? else { + return Ok(None); + }; + let resource = self.read_path(path)?; + let actual = + NamedFace::at(&resource.version.path, &resource.data, face.index).ok_or_else(|| { + format!( + "named font has no valid face {} in {}", + face.index, + resource.version.path.display() + ) + })?; + if !face.postscript.is_empty() && face.postscript != actual.postscript { + return Err(format!( + "named font catalogue changed for {}", + resource.version.path.display() + )); + } + Ok(Some(NamedFont { + resource, + index: face.index, + full_name: actual.full_name, + })) + } + + fn font_path_in(&self, scope: &SearchPath, candidate: &Path) -> bool { + let SearchPath::Directory { + path, + recursive, + suffix, + } = scope + else { + return false; + }; + let root = self.config.cwd.join(path); + let Some(parent) = candidate.parent() else { + return false; + }; + if *recursive { + parent + .strip_prefix(root) + .is_ok_and(|relative| relative.ends_with(suffix)) + } else { + parent == root.join(suffix) + } + } +} diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index 90ff15c..3f7bd1a 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -2175,6 +2175,37 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。 全量编译一致。incremental-receipt.json 的 SHA-256 为 bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。 +### XeTeX 系统字体名称与版本化查找 + +XeTeX 记录 \font 扫描时是否使用引号。带引号的名称先尝试查找 +OpenType 字体,未加引号的名称先按原有路径尝试 TFM。Linux 的 +实时世界枚举真实 Fontconfig 字体目录,按全名、家族和样式、 +PostScript 名称或家族默认样式选取实际 face。原子项目在搜索 +路径内从已捕获的 OpenType 文件读取实际名称表和样式。两条路径 +都走正常资源读取流程,保存原始字体路径、face 索引和字节指纹。 +[XeTeX 名称与样式选择](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/xetexdir/XeTeXFontMgr.cpp) +[Fontconfig 配置和目录](https://fontconfig.pages.freedesktop.org/fontconfig/fontconfig-user.html) + +同一个真实 CTAN STIX Two Math 字体在原语对照中得到类型 2、 +alpha 字形 885 和 STIX Two Math Regular。家族名与 PostScript +别名合并成同一实际字号实例。STIX Two Text 四个样式的实际 +face 和家族加样式名称也与 XeTeX 一致。13 行定向诊断与 30 项 +现有字体和资源回归通过。原样 fontspec 和 unicode-math 使用 +STIX Two Math 名称,复用同一 schema67。两端都生成一页,30 个 +字形、3 条规则、aux 和 144 dpi 光栅一致。日志、同源原稿、 +字体哈希及格式身份在 target/p3-xetex-named-font/receipt.json。 + +实时世界记录名称命中及缺失。序列化后,卸下独立测试目录的 +Fontconfig 设置并临时移走字体文件,回放仍匹配首次观察的名称、 +face 索引和文件哈希。原始捕获与比较在 +target/p3-xetex-named-font/replay。 + +三页原子项目使 \font 位于检查点之前。新增真实 OTF 会使 +已缓存的失败查找失效,删除时按实际文件身份失效。只改第二页 +文字时,同一名字和字体版本通过回放并复用 102 步。三次编辑 +均只更新第 2 页,PDF、SVG 和来源映射与同修订独立全量一致。 +证据位于 target/p3-xetex-named-font/revisions/receipt.json。 + ### XeTeX 数学脚标字距与分数当前字体 OpenType 脚标字距从基础和脚标的实际字形读取四角 MATH 表, diff --git a/src/native_checkpoint_probe.rs b/src/native_checkpoint_probe.rs index a9e6f9b..b7e449e 100644 --- a/src/native_checkpoint_probe.rs +++ b/src/native_checkpoint_probe.rs @@ -131,6 +131,19 @@ impl SourceProvider for RecordingHost<'_> { .map_err(Clone::clone) }) } + fn named_font( + &mut self, + name: &str, + style: texrra_tex_core::resources::FontStyle, + from: &str, + ) -> Result, String> { + let (name, from) = (name.to_owned(), from.to_owned()); + call!(self, named_font(&name, style, &from); |result| { + result.as_ref().map(|result| result.as_ref().map(|font| { + (font.resource.version.clone(), font.index, font.full_name.clone()) + })).map_err(Clone::clone) + }) + } fn optional_font_file(&mut self, kind: ResourceKind, name: &str, from: &str) -> Result, String> { let (name, from) = (name.to_owned(), from.to_owned()); call!(self, optional_font_file(kind, &name, &from); |result| { diff --git a/src/native_job.rs b/src/native_job.rs index e17e665..61b7581 100644 --- a/src/native_job.rs +++ b/src/native_job.rs @@ -1563,6 +1563,22 @@ impl SourceProvider for Files { } Ok(resource) } + fn named_font( + &mut self, + name: &str, + style: texrra_tex_core::resources::FontStyle, + from: &str, + ) -> Result, String> { + let selected = self.world.read_named_font(name, style, Path::new(from))?; + if let Some(font) = &selected { + let kind = match font.resource.version.path.extension().and_then(|ext| ext.to_str()) { + Some(ext) if ext.eq_ignore_ascii_case("ttf") || ext.eq_ignore_ascii_case("ttc") => ResourceKind::TrueType, + _ => ResourceKind::OpenType, + }; + self.observe_resource(kind, &font.resource); + } + Ok(selected) + } fn optional_font_file(&mut self, kind: ResourceKind, name: &str, from: &str) -> Result, String> { let resource = self.world.read_optional(kind, name, Path::new(from))?; if let Some(resource) = &resource {