Resolve XeTeX font probes and expose real OpenType math parameters
This commit is contained in:
1 parent
01ef302fb0
commit
7070cc6b82
12 files changed
+428
-27
No files matched your search
@@ -2295,6 +2295,9 @@ impl Executor {
|
||||
Meaning::Primitive(Primitive::XeTeXpdfpagecount) => {
|
||||
self.xdv_pdf_page_count(&next.token, files)
|
||||
}
|
||||
Meaning::Primitive(p) if p.xetex_font_query_name().is_some() => {
|
||||
self.xetex_font_query(p, files)
|
||||
}
|
||||
Meaning::Primitive(Primitive::Pdfshellescape) => Ok(Self::SHELL_ESCAPE),
|
||||
Meaning::Primitive(Primitive::Pdfrandomseed) => {
|
||||
self.reads.insert(Dependency::PdfRandomState);
|
||||
@@ -3155,6 +3158,9 @@ impl Executor {
|
||||
Primitive::XeTeXpdffile => "XeTeXpdffile".into(),
|
||||
Primitive::XeTeXpicfile => "XeTeXpicfile".into(),
|
||||
Primitive::XeTeXpdfpagecount => "XeTeXpdfpagecount".into(),
|
||||
p if p.xetex_font_query_name().is_some() => {
|
||||
p.xetex_font_query_name().unwrap().into()
|
||||
}
|
||||
Primitive::Etexversion => "eTeXversion".into(),
|
||||
Primitive::Etexrevision => "eTeXrevision".into(),
|
||||
Primitive::Uchar => "Uchar".into(),
|
||||
|
||||
@@ -103,6 +103,76 @@ impl Executor {
|
||||
_ => unreachable!(),
|
||||
} as i32)
|
||||
}
|
||||
pub(super) fn xetex_font_query(
|
||||
&mut self,
|
||||
command: Primitive,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<i32, Error> {
|
||||
use Primitive::*;
|
||||
use rustybuzz::ttf_parser::Tag;
|
||||
|
||||
if matches!(command, XeTeXcharglyph | XeTeXglyphindex) {
|
||||
let id = self.state.text_font();
|
||||
self.reads.insert(Dependency::TextFont);
|
||||
self.reads.insert(Dependency::FontResources);
|
||||
let font = self.state.fonts.font(id).map_err(|error| self.error(error, self.current))?
|
||||
.opentype().cloned().ok_or_else(|| self.error(
|
||||
"XeTeX glyph query requires a native OpenType font", self.current,
|
||||
))?;
|
||||
let face = font.face().map_err(|error| self.error(error, self.current))?;
|
||||
let glyph = if command == XeTeXcharglyph {
|
||||
let slot = self.integer(files)?;
|
||||
u32::try_from(slot).ok().and_then(char::from_u32)
|
||||
.and_then(|character| face.glyph_index(character))
|
||||
} else {
|
||||
let name = self.filename(files)?;
|
||||
face.glyph_index_by_name(&name)
|
||||
};
|
||||
return Ok(glyph.map_or(0, |glyph| i32::from(glyph.0)));
|
||||
}
|
||||
|
||||
let id = self.font_identifier(files)?;
|
||||
let font = self.state.fonts.font(id).map_err(|error| self.error(error, self.current))?
|
||||
.opentype().cloned();
|
||||
if command == XeTeXfonttype {
|
||||
return Ok(if font.is_some() { 2 } else { 0 });
|
||||
}
|
||||
let Some(font) = font else {
|
||||
return match command {
|
||||
XeTeXcountglyphs | XeTeXOTcountscripts => Ok(0),
|
||||
_ => self.fail("XeTeX OpenType layout query requires a native OpenType font"),
|
||||
};
|
||||
};
|
||||
let face = font.face().map_err(|error| self.error(error, self.current))?;
|
||||
let tags = crate::opentype::LayoutTags::new(face.tables());
|
||||
if command == XeTeXcountglyphs {
|
||||
return Ok(i32::from(face.number_of_glyphs()));
|
||||
}
|
||||
if command == XeTeXOTcountscripts {
|
||||
return Ok(tags.script_count());
|
||||
}
|
||||
|
||||
let first = self.integer(files)?;
|
||||
if command == XeTeXOTscripttag {
|
||||
return Ok(tags.script_tag(first));
|
||||
}
|
||||
let script = Tag(first as u32);
|
||||
if command == XeTeXOTcountlanguages {
|
||||
return Ok(tags.language_count(script));
|
||||
}
|
||||
let second = self.integer(files)?;
|
||||
if command == XeTeXOTlanguagetag {
|
||||
return Ok(tags.language_tag(script, second));
|
||||
}
|
||||
let mut features = tags.features(script, Tag(second as u32));
|
||||
if command == XeTeXOTcountfeatures {
|
||||
return Ok(features.count() as i32);
|
||||
}
|
||||
let index = self.integer(files)?;
|
||||
Ok(usize::try_from(index).ok()
|
||||
.and_then(|index| features.nth(index)).map_or(0, |tag| tag.0 as i32))
|
||||
}
|
||||
|
||||
pub(super) fn font_identifier(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
|
||||
@@ -674,13 +674,22 @@ impl Executor {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let suppress = self.state.input_profile() == super::super::InputProfile::XeTeX
|
||||
&& self.read_parameter(Parameter::Suppressfontnotfounderror).width() != 0;
|
||||
let font = if let Some(request) = request {
|
||||
self.state.fonts.load_opentype(files, &file, request, &from, size, name.clone(), defaults)
|
||||
self.state.fonts.load_opentype(
|
||||
files, &file, request, &from, size, name.clone(), defaults, suppress,
|
||||
)
|
||||
} else {
|
||||
self.state.fonts.load(files, &file, &from, size, name.clone(), defaults)
|
||||
}.map_err(|e| self.error(e, self.current))?;
|
||||
self.define_traced(name, Meaning::Font(font), global, files)?;
|
||||
Ok(())
|
||||
self.state.fonts.load_tfm(
|
||||
files, &file, &from, size, name.clone(), defaults, suppress,
|
||||
)
|
||||
};
|
||||
match font {
|
||||
Ok(font) => self.define_traced(name, Meaning::Font(font), global, files),
|
||||
Err(super::super::font_catalog::FontLoadError::Rejected(_)) if suppress => Ok(()),
|
||||
Err(error) => Err(self.error(error.message(), self.current)),
|
||||
}
|
||||
}
|
||||
pub(super) fn hyphenation(&mut self, files: &mut impl SourceProvider) -> Result<(), Error> {
|
||||
let open = self.expanded_non_space(files)?.token;
|
||||
|
||||
@@ -179,6 +179,9 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
fn integer_operand(&mut self, token: &Token) -> bool {
|
||||
if matches!(self.meaning(token), Meaning::Primitive(p) if p.xetex_font_query_name().is_some()) {
|
||||
return true;
|
||||
}
|
||||
if matches!(self.meaning(token),Meaning::Primitive(p)if p.page_dimension().is_some()||matches!(p, Primitive::Deadcycles | Primitive::Insertpenalties))
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -10,6 +10,27 @@ use crate::{
|
||||
use sha2::{Digest, Sha256};
|
||||
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 {
|
||||
Rejected(String),
|
||||
Fatal(String),
|
||||
}
|
||||
|
||||
impl FontLoadError {
|
||||
pub(super) fn message(self) -> String {
|
||||
match self {
|
||||
Self::Rejected(message) | Self::Fatal(message) => message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for FontLoadError {
|
||||
fn from(message: String) -> Self {
|
||||
Self::Fatal(message)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
|
||||
)]
|
||||
@@ -295,8 +316,22 @@ impl FontCatalog {
|
||||
selector: CommandName,
|
||||
defaults: FontIntegers,
|
||||
) -> Result<FontId, String> {
|
||||
self.load_tfm(files, filename, from, size, selector, defaults, false)
|
||||
.map_err(FontLoadError::message)
|
||||
}
|
||||
|
||||
pub(super) fn load_tfm(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
filename: &str,
|
||||
from: &str,
|
||||
size: FontSize,
|
||||
selector: CommandName,
|
||||
defaults: FontIntegers,
|
||||
optional: bool,
|
||||
) -> Result<FontId, FontLoadError> {
|
||||
if matches!(selector, CommandName::Font(_) | CommandName::FrozenRelax) {
|
||||
return Err("frozen font identifiers cannot name font definitions".into());
|
||||
return Err(FontLoadError::Fatal("frozen font identifiers cannot name font definitions".into()));
|
||||
}
|
||||
size.validate()?;
|
||||
let (area, basename) = filename
|
||||
@@ -306,7 +341,7 @@ impl FontCatalog {
|
||||
// Unix/pdfTeX filename scanning uses the last dot in the basename.
|
||||
let name = basename.rsplit_once('.').map_or(basename, |(n, _)| n);
|
||||
if name.is_empty() {
|
||||
return Err("empty native font resource name".into());
|
||||
return Err(FontLoadError::Rejected("empty native font resource name".into()));
|
||||
}
|
||||
// TeX searches loaded name+area+size before touching the filesystem.
|
||||
// Canonical resource identity alone must not merge distinct names or
|
||||
@@ -322,8 +357,10 @@ impl FontCatalog {
|
||||
}
|
||||
}
|
||||
self.check_font_capacity()?;
|
||||
let (loaded, metrics) = Self::read_tfm(files, &format!("{area}{name}.tfm"), from, size)?;
|
||||
self.insert_font((name, area), loaded, metrics, selector, defaults, None)
|
||||
let filename = format!("{area}{name}.tfm");
|
||||
let loaded = Self::font_file(files, ResourceKind::Tfm, &filename, from, optional)?;
|
||||
let metrics = Self::tfm_metrics(&loaded, size)?;
|
||||
Ok(self.insert_font((name, area), loaded, metrics, selector, defaults, None)?)
|
||||
}
|
||||
|
||||
pub(super) fn load_opentype(
|
||||
@@ -335,7 +372,8 @@ impl FontCatalog {
|
||||
size: FontSize,
|
||||
selector: CommandName,
|
||||
defaults: FontIntegers,
|
||||
) -> Result<FontId, String> {
|
||||
optional: bool,
|
||||
) -> Result<FontId, FontLoadError> {
|
||||
size.validate()?;
|
||||
for (index, instance) in self.fonts.iter_mut().enumerate() {
|
||||
if let Some(font) = &instance.opentype
|
||||
@@ -348,11 +386,11 @@ impl FontCatalog {
|
||||
}
|
||||
self.check_font_capacity()?;
|
||||
if self.limits.parameter_words - self.parameter_words < 8 {
|
||||
return Err("native font parameter capacity exceeded".into());
|
||||
return Err(FontLoadError::Fatal("native font parameter capacity exceeded".into()));
|
||||
}
|
||||
let names = request.resource_names();
|
||||
let loaded = if let [(kind, name)] = &names[..] {
|
||||
files.resource(*kind, name, from)?
|
||||
Self::font_file(files, *kind, name, from, optional)?
|
||||
} else {
|
||||
let mut selected = None;
|
||||
for (kind, name) in &names {
|
||||
@@ -361,12 +399,14 @@ impl FontCatalog {
|
||||
break;
|
||||
}
|
||||
}
|
||||
selected.ok_or_else(|| format!("OpenType font file not found: {}", request.file))?
|
||||
selected.ok_or_else(|| FontLoadError::Rejected(
|
||||
format!("OpenType font file not found: {}", request.file)
|
||||
))?
|
||||
};
|
||||
if loaded.version.bytes != loaded.data.len() as u64
|
||||
|| loaded.version.sha256 != format!("{:x}", Sha256::digest(&loaded.data))
|
||||
{
|
||||
return Err("font resource version does not match its actual OpenType bytes".into());
|
||||
return Err(FontLoadError::Fatal("font resource version does not match its actual OpenType bytes".into()));
|
||||
}
|
||||
let resource = FontResource { version: loaded.version, data: Arc::new(loaded.data) };
|
||||
let mapping = if let Some(name) = &request.mapping {
|
||||
@@ -374,7 +414,7 @@ impl FontCatalog {
|
||||
if loaded.version.bytes != loaded.data.len() as u64
|
||||
|| loaded.version.sha256 != format!("{:x}", Sha256::digest(&loaded.data))
|
||||
{
|
||||
return Err("font resource version does not match its actual TECkit bytes".into());
|
||||
return Err(FontLoadError::Fatal("font resource version does not match its actual TECkit bytes".into()));
|
||||
}
|
||||
let existing = self.fonts.iter()
|
||||
.filter_map(|instance| instance.opentype()?.mapping())
|
||||
@@ -390,7 +430,12 @@ impl FontCatalog {
|
||||
None
|
||||
};
|
||||
let id = FontId(self.fonts.len() as u32);
|
||||
let (font, parameters) = OpenTypeFont::new(id, resource, request, mapping, size)?;
|
||||
let (font, parameters) = OpenTypeFont::new(id, resource, request, mapping, size)
|
||||
.map_err(FontLoadError::Rejected)?;
|
||||
let parameter_count = parameters.len();
|
||||
if self.limits.parameter_words - self.parameter_words < parameter_count {
|
||||
return Err(FontLoadError::Fatal("native font parameter capacity exceeded".into()));
|
||||
}
|
||||
let resource = self.intern_resource(font.resource.clone());
|
||||
self.fonts.push(FontInstance {
|
||||
name: spec.to_owned(),
|
||||
@@ -398,13 +443,13 @@ impl FontCatalog {
|
||||
resource: Some(resource),
|
||||
glyph_font: None,
|
||||
opentype: Some(Arc::new(font)),
|
||||
parameters: Arc::new(parameters.to_vec()),
|
||||
parameters: Arc::new(parameters),
|
||||
integers: defaults,
|
||||
selector,
|
||||
expansion_origin: None,
|
||||
automatic_expansion: false,
|
||||
});
|
||||
self.parameter_words += parameters.len();
|
||||
self.parameter_words += parameter_count;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
@@ -489,14 +534,35 @@ impl FontCatalog {
|
||||
size: FontSize,
|
||||
) -> Result<(LoadedResource, TfmMetrics), String> {
|
||||
let loaded = files.resource(ResourceKind::Tfm, name, from)?;
|
||||
let metrics = Self::tfm_metrics(&loaded, size).map_err(FontLoadError::message)?;
|
||||
Ok((loaded, metrics))
|
||||
}
|
||||
|
||||
fn font_file(
|
||||
files: &mut impl SourceProvider,
|
||||
kind: ResourceKind,
|
||||
name: &str,
|
||||
from: &str,
|
||||
optional: bool,
|
||||
) -> 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}"))
|
||||
});
|
||||
}
|
||||
Ok(files.resource(kind, name, from)?)
|
||||
}
|
||||
|
||||
fn tfm_metrics(loaded: &LoadedResource, size: FontSize) -> Result<TfmMetrics, FontLoadError> {
|
||||
if loaded.version.bytes != loaded.data.len() as u64
|
||||
|| loaded.version.sha256 != format!("{:x}", Sha256::digest(&loaded.data))
|
||||
{
|
||||
return Err("font resource version does not match its actual TFM bytes".into());
|
||||
return Err(FontLoadError::Fatal(
|
||||
"font resource version does not match its actual TFM bytes".into(),
|
||||
));
|
||||
}
|
||||
// Zero entries are validated after scaling at the requested size.
|
||||
let metrics = TfmMetrics::parse_at(&loaded.data, size)?;
|
||||
Ok((loaded, metrics))
|
||||
TfmMetrics::parse_at(&loaded.data, size).map_err(FontLoadError::Rejected)
|
||||
}
|
||||
|
||||
fn intern_resource(&mut self, resource: FontResource) -> usize {
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 64;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 31] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, SCHEMA,
|
||||
const SCHEMA: u32 = 65;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 32] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ pub enum Parameter {
|
||||
Partokencontext,
|
||||
XeTeXuseglyphmetrics,
|
||||
XeTeXdashbreakstate,
|
||||
Suppressfontnotfounderror,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ParameterValue {
|
||||
@@ -153,7 +154,11 @@ impl Parameter {
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) const XETEX: [Self; 2] = [Self::XeTeXuseglyphmetrics, Self::XeTeXdashbreakstate];
|
||||
pub(super) const XETEX: [Self; 3] = [
|
||||
Self::XeTeXuseglyphmetrics,
|
||||
Self::XeTeXdashbreakstate,
|
||||
Self::Suppressfontnotfounderror,
|
||||
];
|
||||
|
||||
pub const ALL: &'static [Self] = &[
|
||||
Self::Pdfoutput,
|
||||
@@ -272,6 +277,7 @@ impl Parameter {
|
||||
Self::Partokencontext,
|
||||
Self::XeTeXuseglyphmetrics,
|
||||
Self::XeTeXdashbreakstate,
|
||||
Self::Suppressfontnotfounderror,
|
||||
];
|
||||
pub fn name(self) -> String {
|
||||
match self {
|
||||
|
||||
@@ -366,9 +366,48 @@ pub enum Primitive {
|
||||
XeTeXpdffile,
|
||||
XeTeXpdfpagecount,
|
||||
XeTeXpicfile,
|
||||
XeTeXfonttype,
|
||||
XeTeXcountglyphs,
|
||||
XeTeXcharglyph,
|
||||
XeTeXglyphindex,
|
||||
XeTeXOTcountscripts,
|
||||
XeTeXOTscripttag,
|
||||
XeTeXOTcountlanguages,
|
||||
XeTeXOTlanguagetag,
|
||||
XeTeXOTcountfeatures,
|
||||
XeTeXOTfeaturetag,
|
||||
}
|
||||
|
||||
impl Primitive {
|
||||
const XETEX_FONT_QUERIES: [Self; 10] = [
|
||||
Self::XeTeXfonttype,
|
||||
Self::XeTeXcountglyphs,
|
||||
Self::XeTeXcharglyph,
|
||||
Self::XeTeXglyphindex,
|
||||
Self::XeTeXOTcountscripts,
|
||||
Self::XeTeXOTscripttag,
|
||||
Self::XeTeXOTcountlanguages,
|
||||
Self::XeTeXOTlanguagetag,
|
||||
Self::XeTeXOTcountfeatures,
|
||||
Self::XeTeXOTfeaturetag,
|
||||
];
|
||||
|
||||
pub(super) fn xetex_font_query_name(self) -> Option<&'static str> {
|
||||
Some(match self {
|
||||
Self::XeTeXfonttype => "XeTeXfonttype",
|
||||
Self::XeTeXcountglyphs => "XeTeXcountglyphs",
|
||||
Self::XeTeXcharglyph => "XeTeXcharglyph",
|
||||
Self::XeTeXglyphindex => "XeTeXglyphindex",
|
||||
Self::XeTeXOTcountscripts => "XeTeXOTcountscripts",
|
||||
Self::XeTeXOTscripttag => "XeTeXOTscripttag",
|
||||
Self::XeTeXOTcountlanguages => "XeTeXOTcountlanguages",
|
||||
Self::XeTeXOTlanguagetag => "XeTeXOTlanguagetag",
|
||||
Self::XeTeXOTcountfeatures => "XeTeXOTcountfeatures",
|
||||
Self::XeTeXOTfeaturetag => "XeTeXOTfeaturetag",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn page_dimension(self) -> Option<usize> {
|
||||
use Primitive::*;
|
||||
Some(match self {
|
||||
@@ -1643,6 +1682,13 @@ impl State {
|
||||
] {
|
||||
self.update_profile_command(name, Meaning::Primitive(primitive), enabled);
|
||||
}
|
||||
for primitive in Primitive::XETEX_FONT_QUERIES {
|
||||
self.update_profile_command(
|
||||
primitive.xetex_font_query_name().unwrap(),
|
||||
Meaning::Primitive(primitive),
|
||||
enabled,
|
||||
);
|
||||
}
|
||||
for parameter in Parameter::XETEX {
|
||||
self.update_profile_command(
|
||||
¶meter.name(),
|
||||
|
||||
@@ -17,6 +17,9 @@ use std::{
|
||||
};
|
||||
use unicode_bidi::BidiInfo;
|
||||
|
||||
mod font_info;
|
||||
pub(crate) use font_info::LayoutTags;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub(crate) struct Request {
|
||||
pub file: String,
|
||||
@@ -158,7 +161,7 @@ impl OpenTypeFont {
|
||||
request: Request,
|
||||
mapping: Option<Arc<FontMapping>>,
|
||||
size: FontSize,
|
||||
) -> Result<(Self, [i32; 8]), String> {
|
||||
) -> Result<(Self, Vec<i32>), String> {
|
||||
let face = ttf_parser::Face::parse(&resource.data, request.index).map_err(|error| {
|
||||
format!(
|
||||
"invalid OpenType face {}: {error}",
|
||||
@@ -200,7 +203,7 @@ impl OpenTypeFont {
|
||||
};
|
||||
let space = advance(' ');
|
||||
let slant = (-f64::from(face.italic_angle()).to_radians().tan() * 65536.).round() as i32;
|
||||
let params = [
|
||||
let mut params = vec![
|
||||
slant,
|
||||
space as i32,
|
||||
(space / 2) as i32,
|
||||
@@ -210,6 +213,7 @@ impl OpenTypeFont {
|
||||
(space / 3) as i32,
|
||||
xheight(face.capital_height(), 'X', ascent) as i32,
|
||||
];
|
||||
font_info::append_math_parameters(&face, size, &mut params);
|
||||
Ok((
|
||||
Self {
|
||||
id,
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
//! XeTeX font inspection from the selected OpenType face.
|
||||
use super::{Tag, scale_units, ttf_parser};
|
||||
|
||||
pub(crate) struct LayoutTags<'a> {
|
||||
tables: &'a ttf_parser::FaceTables<'a>,
|
||||
}
|
||||
|
||||
impl<'a> LayoutTags<'a> {
|
||||
pub(crate) fn new(tables: &'a ttf_parser::FaceTables<'a>) -> Self {
|
||||
Self { tables }
|
||||
}
|
||||
|
||||
pub(crate) fn script_count(&self) -> i32 {
|
||||
i32::from(self.tables.gsub.map_or(0, |table| table.scripts.len()))
|
||||
}
|
||||
|
||||
pub(crate) fn script_tag(&self, index: i32) -> i32 {
|
||||
u16::try_from(index)
|
||||
.ok()
|
||||
.and_then(|index| self.tables.gsub?.scripts.get(index))
|
||||
.map_or(0, |script| script.tag.0 as i32)
|
||||
}
|
||||
|
||||
fn languages(&self, script: Tag) -> [Option<ttf_parser::opentype_layout::Script<'a>>; 2] {
|
||||
let index = self
|
||||
.tables
|
||||
.gsub
|
||||
.and_then(|table| table.scripts.index(script));
|
||||
[self.tables.gsub, self.tables.gpos].map(|table| table?.scripts.get(index?))
|
||||
}
|
||||
|
||||
pub(crate) fn language_count(&self, script: Tag) -> i32 {
|
||||
self.languages(script)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|script| i32::from(script.languages.len()))
|
||||
.sum()
|
||||
}
|
||||
|
||||
pub(crate) fn language_tag(&self, script: Tag, index: i32) -> i32 {
|
||||
let Ok(index) = u16::try_from(index) else {
|
||||
return 0;
|
||||
};
|
||||
// XeTeX addresses both tables with the same script and language index.
|
||||
self.languages(script)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find_map(|script| script.languages.get(index))
|
||||
.map_or(0, |language| language.tag.0 as i32)
|
||||
}
|
||||
|
||||
pub(crate) fn features(
|
||||
&self,
|
||||
script_tag: Tag,
|
||||
language_tag: Tag,
|
||||
) -> impl Iterator<Item = Tag> + '_ {
|
||||
[self.tables.gsub, self.tables.gpos]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(move |table| {
|
||||
let script = table.scripts.find(script_tag)?;
|
||||
let language = if language_tag.0 == 0 {
|
||||
script.default_language
|
||||
} else {
|
||||
script.languages.find(language_tag)
|
||||
}?;
|
||||
Some((table, language))
|
||||
})
|
||||
.flat_map(|(table, language)| {
|
||||
language
|
||||
.feature_indices
|
||||
.into_iter()
|
||||
.filter_map(move |index| table.features.get(index).map(|feature| feature.tag))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// XeTeX exposes the OpenType MATH constants as fontdimens 10 to 65.
|
||||
pub(super) fn append_math_parameters(
|
||||
face: &ttf_parser::Face<'_>,
|
||||
size: i64,
|
||||
params: &mut Vec<i32>,
|
||||
) {
|
||||
let Some(constants) = math_constant_bytes(face) else {
|
||||
return;
|
||||
};
|
||||
params.push(65);
|
||||
for index in 0..56 {
|
||||
let offset = match index {
|
||||
0..=3 => index * 2,
|
||||
55 => 212,
|
||||
_ => 8 + (index - 4) * 4,
|
||||
};
|
||||
let value = [constants[offset], constants[offset + 1]];
|
||||
let value = if matches!(index, 2 | 3) {
|
||||
i64::from(u16::from_be_bytes(value))
|
||||
} else {
|
||||
i64::from(i16::from_be_bytes(value))
|
||||
};
|
||||
let value = match index {
|
||||
0 | 1 | 55 => value,
|
||||
_ => scale_units(value, size, face.units_per_em()),
|
||||
};
|
||||
params.push(value as i32);
|
||||
}
|
||||
}
|
||||
|
||||
fn math_constant_bytes<'a>(face: &ttf_parser::Face<'a>) -> Option<&'a [u8]> {
|
||||
let table = face.raw_face().table(Tag::from_bytes(b"MATH"))?;
|
||||
face.tables().math?.constants?;
|
||||
let offset = usize::from(u16::from_be_bytes(table.get(4..6)?.try_into().ok()?));
|
||||
table.get(offset..offset + 214)
|
||||
}
|
||||
@@ -92,6 +92,49 @@ fn xetex_primitives_follow_each_profiles_language_and_device() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suppressed_font_probe_restores_state_and_preserves_host_errors() {
|
||||
struct FontProbe {
|
||||
denied: bool,
|
||||
}
|
||||
impl SourceProvider for FontProbe {
|
||||
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
|
||||
Err(format!("unexpected input {name}"))
|
||||
}
|
||||
|
||||
fn optional_font_file(
|
||||
&mut self,
|
||||
_: texrra_tex_core::resources::ResourceKind,
|
||||
_: &str,
|
||||
_: &str,
|
||||
) -> Result<Option<texrra_tex_core::resources::LoadedResource>, String> {
|
||||
if self.denied {
|
||||
return Err("font lookup denied by host".into());
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
let state = State::initex().with_etex().with_input_profile(InputProfile::XeTeX);
|
||||
let tex = source(r"\catcode123=1 \catcode125=2
|
||||
\begingroup\suppressfontnotfounderror=-1
|
||||
\font\query=texrra-missing-stage65
|
||||
\message{\ifx\query\nullfont null\else selected\fi}
|
||||
\endgroup
|
||||
\message{\number\suppressfontnotfounderror/\ifx\query\undefined restored\fi}
|
||||
\end");
|
||||
let result = Executor::new(state.clone(), Limits::default())
|
||||
.run(tex.clone(), &mut FontProbe { denied: false })
|
||||
.unwrap();
|
||||
assert_eq!(messages(&result), ["null", "0/restored"]);
|
||||
|
||||
let error = Executor::new(state, Limits::default())
|
||||
.run(tex, &mut FontProbe { denied: true })
|
||||
.err()
|
||||
.expect("host denial must be surfaced");
|
||||
assert!(error.to_string().contains("font lookup denied by host"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xetex_format_preserves_internal_version_and_profile_identity() {
|
||||
let seed = r#"\catcode123=1 \catcode125=2
|
||||
|
||||
@@ -2175,6 +2175,41 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### XeTeX 字体探测与 OpenType MATH 参数
|
||||
|
||||
\suppressfontnotfounderror 作为 XeTeX 扩展整数进入正常赋值与分组。
|
||||
非零时,真实找不到或无法解析的候选维持该次 \font 已定义的
|
||||
\nullfont。实际加载成功的字体按原样绑定,宿主查找错误、资源
|
||||
指纹不一致和容量错误继续有各自的失败诊断。分组退出恢复查询
|
||||
开关和局部选择器,全局选择器按实际 \global 语义保留。
|
||||
|
||||
字体类型、字形数量、字符和名称到字形的映射来自选中的原始
|
||||
字体。脚本、语言与功能枚举读取实际的 GSUB、GPOS 条目。OpenType
|
||||
MATH 字体载入时将 57 个 fontdimen 数据写入 9–65 槽位,包括原始
|
||||
百分比和按实际尺寸缩放的常量。原样 Latin Modern Math 和 Latin
|
||||
Modern Roman 两组探测的 77 行诊断与 XeTeX 一致。退出分组后重试
|
||||
缺失字体,两边均真实失败。16 项定向测试通过。
|
||||
[XeTeX 字体读取](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/xetexdir/xetex.web#L13118-L13158)
|
||||
[XeTeX OpenType 查询](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/xetexdir/XeTeXLayoutInterface.cpp#L212-L380)
|
||||
[实际 MATH 常量的读取与缩放](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/xetexdir/XeTeXOTMath.cpp#L46-L66)
|
||||
|
||||
三页会话在同一实际路径验证缺失、损坏、有效和再次删除。有效
|
||||
字体使第二页从真实规则分支切换为 OpenType 文字,复用 636 步。
|
||||
加入和删除有效字体均只更新第 2 页,PDF、SVG 和来源映射与对应
|
||||
修订的独立全量一致。资源指纹、原样参考输入及日志位于
|
||||
target/p3-xetex-font-probe/receipt.json 和 revisions/receipt.json。
|
||||
|
||||
未修改的 xelatex.ini 已生成并重载 schema65。schema64 的实际
|
||||
格式也已重载,原 PDF 放置用例生成一页并匹配盒尺寸。schema65
|
||||
重载原样 unicode-math 后,fontspec 已建立真实 Latin Modern Math
|
||||
的 NFSS 字体族,随后 expl3 浮点展开触发递归深度限制。最小输入
|
||||
只计算 (10+70/100*10)/2,参考输出 8.5,原生触发数值扫描深度
|
||||
限制。原样 TeX、日志与参考结果位于 target/p3-xetex-font-probe
|
||||
的 math-native、fp-reference 和 fp-native。优先修复通用数值
|
||||
扫描和展开的递归边界。独立 OpenType 分数对照已生成参考 PDF,
|
||||
尺寸为 617546 × 733348 sp,深度 449577 sp。原生在数学家族 2
|
||||
尚未消费实际 MATH 参数。该用例位于同目录 reference/layout-next.tex。
|
||||
|
||||
### XeTeX 扩展 ^^ 字符输入
|
||||
|
||||
XeTeX profile 在字符与控制序列的扫描路径共用扩展字符转换。
|
||||
|
||||
Reference in new issue
Block a user