Query actual XeTeX glyph bounds and names in native jobs
This commit is contained in:
1 parent
b88283f493
commit
fc6d704edf
8 files changed
+109
-6
No files matched your search
@@ -68,6 +68,9 @@ impl Executor {
|
||||
.fontdimen(font, n)
|
||||
.map_err(|e| self.error(e, self.current));
|
||||
}
|
||||
if p == Primitive::XeTeXglyphbounds {
|
||||
return self.xetex_glyph_bounds(files);
|
||||
}
|
||||
let font = self.font_identifier(files)?;
|
||||
let slot = self.integer(files)?;
|
||||
let instance = self.state.fonts.font(font).map_err(|e| self.error(e, self.current))?;
|
||||
@@ -98,6 +101,40 @@ impl Executor {
|
||||
_ => unreachable!(),
|
||||
} as i32)
|
||||
}
|
||||
fn xetex_glyph_bounds(&mut self, files: &mut impl SourceProvider) -> Result<i32, Error> {
|
||||
self.reads.insert(Dependency::TextFont);
|
||||
self.reads.insert(Dependency::FontResources);
|
||||
let font = self.state.fonts.font(self.state.text_font())
|
||||
.map_err(|error| self.error(error, self.current))?
|
||||
.opentype()
|
||||
.cloned()
|
||||
.ok_or_else(|| self.error(r"\XeTeXglyphbounds requires a native font", self.current))?;
|
||||
let edge = self.integer(files)?;
|
||||
if !(1..=4).contains(&edge) {
|
||||
return self.fail(format!(r"\XeTeXglyphbounds requires an edge index from 1 to 4 (got {edge})"));
|
||||
}
|
||||
// XeTeX passes the operand to its 16-bit native glyph interface.
|
||||
let glyph = self.integer(files)? as u16;
|
||||
let edges = font.glyph_bounds(glyph)
|
||||
.map_err(|error| self.error(error, self.current))?;
|
||||
i32::try_from(edges[edge as usize - 1])
|
||||
.map_err(|_| self.error("XeTeX glyph bound exceeds the dimension range", self.current))
|
||||
}
|
||||
|
||||
pub(super) fn xetex_glyph_name(
|
||||
&mut self, files: &mut impl SourceProvider,
|
||||
) -> Result<String, Error> {
|
||||
let id = self.font_identifier(files)?;
|
||||
let font = self.state.fonts.font(id).map_err(|error| self.error(error, self.current))?
|
||||
.opentype()
|
||||
.cloned()
|
||||
.ok_or_else(|| self.error(r"\XeTeXglyphname requires a native font", self.current))?;
|
||||
let glyph = self.integer(files)? as u16;
|
||||
let face = font.face().map_err(|error| self.error(error, self.current))?;
|
||||
let name = face.glyph_name(rustybuzz::ttf_parser::GlyphId(glyph));
|
||||
Ok(name.unwrap_or_default().to_owned())
|
||||
}
|
||||
|
||||
pub(super) fn protrusion_target(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
|
||||
@@ -141,7 +141,8 @@ impl Executor {
|
||||
| Primitive::Fontcharwd
|
||||
| Primitive::Fontcharht
|
||||
| Primitive::Fontchardp
|
||||
| Primitive::Fontcharic),
|
||||
| Primitive::Fontcharic
|
||||
| Primitive::XeTeXglyphbounds),
|
||||
) => Ok(Some(Target::Value(self.font_dimension(p, files)?))),
|
||||
Meaning::Primitive(
|
||||
p @ (Primitive::Dimexpr | Primitive::Glueexpr | Primitive::Muexpr),
|
||||
|
||||
Reference in new issue
Block a user