Resolve named XeTeX fonts through captured resource catalogues
This commit is contained in:
1 parent
a31de14eb2
commit
767c8ffced
10 files changed
+513
-12
No files matched your search
@@ -2596,7 +2596,14 @@ impl Executor {
|
||||
self.unread(first)
|
||||
}
|
||||
fn filename(&mut self, files: &mut impl SourceProvider) -> Result<std::string::String, Error> {
|
||||
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<String, Error> {
|
||||
if self.state.input_profile() == super::InputProfile::TeX8Bit {
|
||||
|
||||
@@ -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)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LoadedResource>,
|
||||
) -> Result<FontId, FontLoadError> {
|
||||
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<LoadedResource, FontLoadError> {
|
||||
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)?)
|
||||
|
||||
@@ -253,6 +253,15 @@ pub trait SourceProvider {
|
||||
) -> Result<Option<crate::resources::LoadedResource>, 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<Option<crate::resources::NamedFont>, 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,
|
||||
|
||||
Reference in new issue
Block a user