Allocate native automatic font expansion instances
This commit is contained in:
1 parent
2d036b807e
commit
9b80a782cf
11 files changed
+288
-107
No files matched your search
@@ -37,7 +37,7 @@ pub struct FontInstance {
|
||||
area: String,
|
||||
resource: Option<usize>,
|
||||
glyph_font: Option<Arc<crate::native_font::NativeFont>>,
|
||||
parameters: Vec<i32>,
|
||||
parameters: Arc<Vec<i32>>,
|
||||
integers: FontIntegers,
|
||||
selector: CommandName,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -198,6 +198,8 @@ pub struct FontCatalog {
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
external_expansion: BTreeMap<FontId, ExternalExpansion>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
automatic_variants: BTreeMap<FontId, BTreeMap<i32, FontId>>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
expansion_codes: BTreeMap<FontId, BTreeMap<u8, u16>>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub(super) pdf_settings: BTreeMap<FontId, PdfFontSettings>,
|
||||
@@ -220,7 +222,7 @@ impl FontCatalog {
|
||||
area: String::new(),
|
||||
resource: None,
|
||||
glyph_font: None,
|
||||
parameters: vec![0; 7],
|
||||
parameters: Arc::new(vec![0; 7]),
|
||||
integers: FontIntegers {
|
||||
hyphen: 45,
|
||||
skew: -1,
|
||||
@@ -235,6 +237,7 @@ impl FontCatalog {
|
||||
auto_kern: BTreeMap::new(),
|
||||
expansion: BTreeMap::new(),
|
||||
external_expansion: BTreeMap::new(),
|
||||
automatic_variants: BTreeMap::new(),
|
||||
expansion_codes: BTreeMap::new(),
|
||||
pdf_settings: BTreeMap::new(),
|
||||
})
|
||||
@@ -245,6 +248,9 @@ impl FontCatalog {
|
||||
pub fn fonts(&self) -> &[FontInstance] {
|
||||
&self.fonts
|
||||
}
|
||||
pub(super) fn parameter_words(&self) -> usize {
|
||||
self.parameter_words
|
||||
}
|
||||
pub fn resources(&self) -> &[FontResource] {
|
||||
&self.resources
|
||||
}
|
||||
@@ -433,6 +439,7 @@ impl FontCatalog {
|
||||
metrics: Arc::new(metrics),
|
||||
resource: self.resources[resource].clone(),
|
||||
expansion: 0,
|
||||
layout_metrics: None,
|
||||
letter_spacing,
|
||||
pdf_space_font: false,
|
||||
});
|
||||
@@ -441,7 +448,7 @@ impl FontCatalog {
|
||||
area: area.into(),
|
||||
resource: Some(resource),
|
||||
glyph_font: Some(glyph_font),
|
||||
parameters,
|
||||
parameters: Arc::new(parameters),
|
||||
integers: defaults,
|
||||
selector,
|
||||
expansion_origin: None,
|
||||
@@ -467,7 +474,7 @@ impl FontCatalog {
|
||||
if added > self.limits.parameter_words - self.parameter_words {
|
||||
return Err("native font parameter capacity exceeded".into());
|
||||
}
|
||||
self.fonts[id.0 as usize].parameters.resize(number, 0);
|
||||
Arc::make_mut(&mut self.fonts[id.0 as usize].parameters).resize(number, 0);
|
||||
self.parameter_words += added;
|
||||
}
|
||||
Ok(number - 1)
|
||||
@@ -479,9 +486,44 @@ impl FontCatalog {
|
||||
}
|
||||
pub fn set_fontdimen(&mut self, id: FontId, number: i32, value: i32) -> Result<(), String> {
|
||||
let index = self.parameter_index(id, number)?;
|
||||
self.fonts[id.0 as usize].parameters[index] = value;
|
||||
// A synthesized font shares the sized parameters with its base.
|
||||
// Replace the shared snapshot on assignment so older job states and
|
||||
// checkpoints keep their original values.
|
||||
let owner = self.parameter_owner(id);
|
||||
if index >= self.fonts[owner.0 as usize].parameters.len() {
|
||||
Arc::make_mut(&mut self.fonts[id.0 as usize].parameters)[index] = value;
|
||||
return Ok(());
|
||||
}
|
||||
let parameters = &mut self.fonts[owner.0 as usize].parameters;
|
||||
Arc::make_mut(parameters)[index] = value;
|
||||
if let Some(variants) = self.automatic_variants.get(&owner) {
|
||||
let parameters = parameters.clone();
|
||||
for &variant in variants.values() {
|
||||
if self.parameter_owner(variant) == owner {
|
||||
let current = &mut self.fonts[variant.0 as usize].parameters;
|
||||
if current.len() == parameters.len() {
|
||||
*current = parameters.clone();
|
||||
} else {
|
||||
Arc::make_mut(current)[index] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parameter_owner(&self, id: FontId) -> FontId {
|
||||
let font = &self.fonts[id.0 as usize];
|
||||
match font.expansion_origin {
|
||||
Some((base, _))
|
||||
if font.glyph_font.as_ref().is_some_and(|glyph| glyph.expansion != 0) =>
|
||||
{
|
||||
base
|
||||
}
|
||||
_ => id,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn protrusion_code(&self, font: FontId, slot: u8, right: bool) -> i32 {
|
||||
self.protrusion.get(&font).and_then(|font| font.get(&slot))
|
||||
.map_or(0, |codes| i32::from(codes[usize::from(right)]))
|
||||
@@ -565,24 +607,27 @@ impl FontCatalog {
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if external {
|
||||
let mut variants = BTreeMap::new();
|
||||
// The extremes are read when declared; intermediate sizes only
|
||||
// when packing selects them for actual text.
|
||||
for amount in [stretch, -shrink].into_iter().filter(|n| *n != 0) {
|
||||
let variant = self.load_external_variant(font, amount, from, defaults, files)?;
|
||||
variants.insert(amount, variant);
|
||||
}
|
||||
let mut variants = BTreeMap::new();
|
||||
// The two extremes have font numbers as soon as declared. Other
|
||||
// quantized ratios are assigned when used by paragraph processing.
|
||||
for amount in [stretch, -shrink].into_iter().filter(|n| *n != 0) {
|
||||
let variant = self.load_expansion_variant(font, amount, automatic, from, defaults, files)?;
|
||||
variants.insert(amount, variant);
|
||||
}
|
||||
if automatic {
|
||||
self.automatic_variants.insert(font, variants);
|
||||
} else {
|
||||
self.external_expansion.insert(font, ExternalExpansion { from: from.into(), variants });
|
||||
}
|
||||
self.expansion.insert(font, config);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_external_variant(
|
||||
fn load_expansion_variant(
|
||||
&mut self,
|
||||
font: FontId,
|
||||
amount: i32,
|
||||
automatic: bool,
|
||||
from: &str,
|
||||
defaults: FontIntegers,
|
||||
files: &mut impl SourceProvider,
|
||||
@@ -594,6 +639,20 @@ impl FontCatalog {
|
||||
f.name == name && f.size_sp() == size && f.expansion_origin.is_none()
|
||||
}) {
|
||||
FontId(index as u32)
|
||||
} else if automatic {
|
||||
self.check_font_capacity()?;
|
||||
let variant = FontId(self.fonts.len() as u32);
|
||||
let glyph_font = Arc::new(NativeFont {
|
||||
expansion: amount,
|
||||
..self.glyph_font(font)?.as_ref().clone()
|
||||
});
|
||||
self.fonts.push(FontInstance {
|
||||
name,
|
||||
glyph_font: Some(glyph_font),
|
||||
expansion_origin: Some((font, amount)),
|
||||
..base.clone()
|
||||
});
|
||||
variant
|
||||
} else {
|
||||
self.check_font_capacity()?;
|
||||
let filename = format!("{name}.tfm");
|
||||
@@ -612,44 +671,63 @@ impl FontCatalog {
|
||||
Ok(variant)
|
||||
}
|
||||
|
||||
pub(super) fn external_variant(&self, font: FontId, amount: i32) -> Option<FontId> {
|
||||
self.external_expansion.get(&font)?.variants.get(&amount).copied()
|
||||
pub(super) fn expansion_variant(&self, font: FontId, amount: i32) -> Option<FontId> {
|
||||
let variants = match self.external_expansion.get(&font) {
|
||||
Some(expansion) => &expansion.variants,
|
||||
None => self.automatic_variants.get(&font)?,
|
||||
};
|
||||
variants.get(&amount).copied()
|
||||
}
|
||||
|
||||
pub(super) fn external_limit(
|
||||
&self,
|
||||
font: FontId,
|
||||
amount: i32,
|
||||
) -> Result<Option<&TfmMetrics>, String> {
|
||||
let Some(expansion) = self.external_expansion.get(&font) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let variant = expansion.variants.get(&amount).ok_or("missing external expansion limit")?;
|
||||
Ok(Some(self.glyph_font(*variant)?.metrics()))
|
||||
pub(super) fn expansion_limit(&self, font: FontId, amount: i32) -> Result<&NativeFont, String> {
|
||||
let variant = self.expansion_variant(font, amount).ok_or("missing font expansion limit")?;
|
||||
Ok(self.glyph_font(variant)?)
|
||||
}
|
||||
|
||||
pub(super) fn has_unrecorded_expansion_limits(&self) -> bool {
|
||||
self.expansion.keys().any(|font| {
|
||||
!self.external_expansion.contains_key(font) && !self.automatic_variants.contains_key(font)
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn expansion_face(
|
||||
&mut self,
|
||||
font: &Arc<NativeFont>,
|
||||
font: FontId,
|
||||
amount: i32,
|
||||
defaults: FontIntegers,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<Arc<NativeFont>, String> {
|
||||
let Some(external) = self.external_expansion.get(&font.id) else {
|
||||
return Ok(Arc::new(NativeFont {
|
||||
expansion: amount,
|
||||
..font.as_ref().clone()
|
||||
}));
|
||||
};
|
||||
let variant = if let Some(variant) = external.variants.get(&amount) {
|
||||
*variant
|
||||
) -> Result<(FontId, Arc<NativeFont>), String> {
|
||||
if let Some(external) = self.external_expansion.get(&font) {
|
||||
let variant = if let Some(variant) = external.variants.get(&amount) {
|
||||
*variant
|
||||
} else {
|
||||
let from = external.from.clone();
|
||||
let variant = self.load_expansion_variant(font, amount, false, &from, defaults, files)?;
|
||||
self.external_expansion.get_mut(&font).unwrap().variants.insert(amount, variant);
|
||||
variant
|
||||
};
|
||||
return Ok((variant, self.glyph_font(variant)?.clone()));
|
||||
}
|
||||
let variant = if let Some(variant) = self.expansion_variant(font, amount) {
|
||||
variant
|
||||
} else {
|
||||
let from = external.from.clone();
|
||||
let variant = self.load_external_variant(font.id, amount, &from, defaults, files)?;
|
||||
self.external_expansion.get_mut(&font.id).unwrap().variants.insert(amount, variant);
|
||||
let variant = self.load_expansion_variant(font, amount, true, "", defaults, files)?;
|
||||
self.automatic_variants.entry(font).or_default().insert(amount, variant);
|
||||
variant
|
||||
};
|
||||
Ok(self.glyph_font(variant)?.clone())
|
||||
let metrics = self.glyph_font(variant)?;
|
||||
// Logical font IDs belong to character lists. The PDF and SVG
|
||||
// device still use the base font program and one horizontal scale.
|
||||
let paint = if metrics.expansion != 0 {
|
||||
metrics.clone()
|
||||
} else {
|
||||
Arc::new(NativeFont {
|
||||
expansion: amount,
|
||||
layout_metrics: Some(metrics.metrics.clone()),
|
||||
..self.glyph_font(font)?.as_ref().clone()
|
||||
})
|
||||
};
|
||||
Ok((variant, paint))
|
||||
}
|
||||
|
||||
pub(super) fn diagnostic_font(&self, font: FontId, expansion: i32) -> Result<(String, i32), String> {
|
||||
@@ -661,10 +739,6 @@ impl FontCatalog {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn has_external_expansions(&self) -> bool {
|
||||
!self.external_expansion.is_empty()
|
||||
}
|
||||
|
||||
pub(super) fn has_external_expansion(&self, font: FontId) -> bool {
|
||||
self.external_expansion.contains_key(&font)
|
||||
}
|
||||
@@ -702,9 +776,10 @@ impl FontCatalog {
|
||||
Ok(())
|
||||
}
|
||||
pub fn character(&self, id: FontId, slot: u8) -> Result<Option<FontCharacter>, String> {
|
||||
let Some(m) = self.font(id)?.metrics() else {
|
||||
let Some(font) = &self.font(id)?.glyph_font else {
|
||||
return Ok(None);
|
||||
};
|
||||
let m = font.metrics();
|
||||
if !m.has_slot(slot) {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -713,10 +788,10 @@ impl FontCatalog {
|
||||
font: id,
|
||||
slot,
|
||||
size: m.size_sp(),
|
||||
width: m.width(c),
|
||||
width: font.advance(slot),
|
||||
height: m.height(c),
|
||||
depth: m.depth(c),
|
||||
italic: m.italic(c),
|
||||
italic: font.horizontal(m.italic(c)),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 52;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 21] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, SCHEMA,
|
||||
const SCHEMA: u32 = 53;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 22] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -124,6 +124,9 @@ impl FormatImage {
|
||||
{
|
||||
return Err("incompatible native format image".into());
|
||||
}
|
||||
if image.state.fonts.has_unrecorded_expansion_limits() {
|
||||
return Err("native format must be rebuilt to restore automatic expansion font identities".into());
|
||||
}
|
||||
Ok(image)
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ pub(super) fn solve(
|
||||
&& state.fonts.has_expansion())
|
||||
.then(|| expansion::Search::new(state, source))
|
||||
.transpose()?;
|
||||
let expand_margins = expansion.is_some() && state.fonts.has_external_expansions();
|
||||
let expand_margins = expansion.is_some();
|
||||
let mut margins = (parameters[&Parameter::Pdfprotrudechars].width() > 1)
|
||||
.then(|| protrusion::Search::new(state, source, expand_margins))
|
||||
.transpose()?;
|
||||
|
||||
@@ -67,12 +67,13 @@ impl Limits {
|
||||
|
||||
struct Character<'a> {
|
||||
font: &'a Arc<NativeFont>,
|
||||
id: FontId,
|
||||
slot: u8,
|
||||
width: i64,
|
||||
}
|
||||
|
||||
fn character(node: &TextNode) -> Option<Character<'_>> {
|
||||
let TextNode::Glyph { glyph, slot, .. } = node else {
|
||||
let TextNode::Glyph { font: id, glyph, slot, .. } = node else {
|
||||
return None;
|
||||
};
|
||||
let geometry = glyph.math_geometry.as_ref()?;
|
||||
@@ -81,6 +82,7 @@ fn character(node: &TextNode) -> Option<Character<'_>> {
|
||||
};
|
||||
Some(Character {
|
||||
font,
|
||||
id: *id,
|
||||
slot: *slot,
|
||||
width: glyph.width,
|
||||
})
|
||||
@@ -89,7 +91,7 @@ fn character(node: &TextNode) -> Option<Character<'_>> {
|
||||
fn pair(nodes: &[TextNode], at: usize) -> Option<(Character<'_>, Character<'_>)> {
|
||||
let left = character(nodes.get(at.checked_sub(1)?)?)?;
|
||||
let right = character(nodes.get(at + 1)?)?;
|
||||
(left.font.id == right.font.id && left.font.expansion == 0 && right.font.expansion == 0)
|
||||
(left.id == right.id && left.font.expansion == 0 && right.font.expansion == 0)
|
||||
.then_some((left, right))
|
||||
}
|
||||
|
||||
@@ -110,13 +112,10 @@ fn capacity(
|
||||
if amount == 0 {
|
||||
return Ok(width);
|
||||
}
|
||||
let Some(external) = state.fonts.external_limit(font.id, amount)? else {
|
||||
return Ok(pdf_device::magnify(width, 1000 + amount));
|
||||
};
|
||||
let left = char::from(slot);
|
||||
let variant = state.fonts.expansion_limit(font.id, amount)?;
|
||||
Ok(match right {
|
||||
Some(right) => external.kern(left, char::from(right)),
|
||||
None => external.width(left),
|
||||
Some(right) => variant.horizontal(variant.metrics().kern(char::from(slot), char::from(right))),
|
||||
None => variant.advance(slot),
|
||||
})
|
||||
};
|
||||
let code = state.fonts.expansion_code(font.id, slot);
|
||||
@@ -264,7 +263,7 @@ pub(super) enum MarginVariation {
|
||||
|
||||
impl MarginVariation {
|
||||
pub(super) fn project(state: &State, font: FontId, slot: u8) -> Result<Option<Self>, String> {
|
||||
if !state.fonts.has_external_expansion(font) {
|
||||
if state.fonts.expansion(font).is_none() {
|
||||
return Ok(None);
|
||||
}
|
||||
let face = state.fonts.glyph_font(font)?;
|
||||
@@ -279,7 +278,7 @@ impl MarginVariation {
|
||||
if amount == 0 {
|
||||
return Ok(Some(original));
|
||||
}
|
||||
let Some(variant) = state.fonts.external_variant(font, amount) else {
|
||||
let Some(variant) = state.fonts.expansion_variant(font, amount) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let quad = i64::from(state.fonts.font(variant)?.quad());
|
||||
@@ -303,14 +302,13 @@ impl MarginVariation {
|
||||
match *self {
|
||||
Self::Measured(capacity) => Ok(capacity),
|
||||
Self::Pending { amounts, code, original } => {
|
||||
let base = state.fonts.glyph_font(font)?.clone();
|
||||
let defaults = state.font_defaults();
|
||||
let mut selected = |amount| -> Result<i64, String> {
|
||||
if amount == 0 {
|
||||
return Ok(original);
|
||||
}
|
||||
let face = state.fonts.expansion_face(&base, amount, defaults, files)?;
|
||||
let quad = i64::from(state.fonts.font(face.id)?.quad());
|
||||
let (selected, _) = state.fonts.expansion_face(font, amount, defaults, files)?;
|
||||
let quad = i64::from(state.fonts.font(selected)?.quad());
|
||||
Ok(pdf_device::magnify(quad, code))
|
||||
};
|
||||
let capacity = Capacity {
|
||||
@@ -325,18 +323,18 @@ impl MarginVariation {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct PackingFonts(BTreeMap<(FontId, i32), Arc<NativeFont>>);
|
||||
struct PackingFonts(BTreeMap<(FontId, i32), (FontId, Arc<NativeFont>)>);
|
||||
|
||||
impl PackingFonts {
|
||||
fn select(
|
||||
&mut self,
|
||||
state: &mut State,
|
||||
font: &Arc<NativeFont>,
|
||||
font: FontId,
|
||||
amount: i32,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<Arc<NativeFont>, String> {
|
||||
) -> Result<(FontId, Arc<NativeFont>), String> {
|
||||
use std::collections::btree_map::Entry;
|
||||
let selected = match self.0.entry((font.id, amount)) {
|
||||
let selected = match self.0.entry((font, amount)) {
|
||||
Entry::Occupied(entry) => entry.into_mut(),
|
||||
Entry::Vacant(entry) => {
|
||||
let defaults = state.font_defaults();
|
||||
@@ -346,7 +344,7 @@ impl PackingFonts {
|
||||
Ok(selected.clone())
|
||||
}
|
||||
|
||||
fn external_margin(
|
||||
fn margin(
|
||||
&mut self,
|
||||
state: &mut State,
|
||||
font: FontId,
|
||||
@@ -355,7 +353,7 @@ impl PackingFonts {
|
||||
ratio: i32,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<Option<(i32, FontId)>, String> {
|
||||
if !state.fonts.has_external_expansion(font) {
|
||||
if state.fonts.expansion(font).is_none() {
|
||||
return Ok(None);
|
||||
}
|
||||
let base = state.fonts.glyph_font(font)?.clone();
|
||||
@@ -363,10 +361,10 @@ impl PackingFonts {
|
||||
if amount == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
let face = self.select(state, &base, amount, files)?;
|
||||
let (selected, _) = self.select(state, font, amount, files)?;
|
||||
let code = state.fonts.protrusion_code(font, slot, right);
|
||||
let quad = i64::from(state.fonts.font(face.id)?.quad());
|
||||
Ok(Some((-pdf_device::magnify(quad, code) as i32, face.id)))
|
||||
let quad = i64::from(state.fonts.font(selected)?.quad());
|
||||
Ok(Some((-pdf_device::magnify(quad, code) as i32, selected)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +378,7 @@ pub(super) fn pack(
|
||||
let shortfall = target - natural;
|
||||
let mut fonts = PackingFonts::default();
|
||||
let mut capacity = Capacity::default();
|
||||
if state.fonts.has_external_expansions() {
|
||||
if state.fonts.has_expansion() {
|
||||
// Measuring the actual margin assigns its extreme variants before
|
||||
// glue setting decides whether to perform any substitution.
|
||||
for node in material.iter() {
|
||||
@@ -388,7 +386,7 @@ pub(super) fn pack(
|
||||
continue;
|
||||
};
|
||||
for (ratio, limit) in [(1000, &mut capacity.stretch), (-1000, &mut capacity.shrink)] {
|
||||
if let Some((expanded, _)) = fonts.external_margin(state, font, slot, right, ratio, files)? {
|
||||
if let Some((expanded, _)) = fonts.margin(state, font, slot, right, ratio, files)? {
|
||||
*limit += i64::from(expanded) - i64::from(width);
|
||||
}
|
||||
}
|
||||
@@ -410,7 +408,7 @@ pub(super) fn pack(
|
||||
pdf_device::divide_scaled(shortfall.clamp(-available, available), available, 3).0 as i32;
|
||||
for i in 0..material.len() {
|
||||
if let TextNode::MarginKern { ref mut width, right, ref mut font, slot } = material[i] {
|
||||
if let Some((expanded, selected)) = fonts.external_margin(state, *font, slot, right, ratio, files)? {
|
||||
if let Some((expanded, selected)) = fonts.margin(state, *font, slot, right, ratio, files)? {
|
||||
*width = expanded;
|
||||
*font = selected;
|
||||
}
|
||||
@@ -423,16 +421,13 @@ pub(super) fn pack(
|
||||
if amount == 0 {
|
||||
continue;
|
||||
}
|
||||
let face = fonts.select(state, glyph.font, amount, files)?;
|
||||
let (selected, paint) = fonts.select(state, glyph.id, amount, files)?;
|
||||
let character = char::from(glyph.slot);
|
||||
let external = face.expansion == 0;
|
||||
if external && !face.has_slot(glyph.slot) {
|
||||
return Err(format!("expanded font {} has no TFM slot {}", face.name, glyph.slot));
|
||||
}
|
||||
// The external left font has already changed when pdfTeX checks
|
||||
// the pair for substitution. The two font identities differ, so
|
||||
// the original kern remains even though the limits affect capacity.
|
||||
if !external
|
||||
let metrics = state.fonts.character(selected, glyph.slot)?
|
||||
.ok_or_else(|| format!("expanded font has no TFM slot {}", glyph.slot))?;
|
||||
// Reuse the original pair for synthesized kern scaling. A loaded
|
||||
// TFM can affect capacity without replacing the original pair kern.
|
||||
if state.fonts.glyph_font(selected)?.expansion != 0
|
||||
&& let Some(TextNode::Kern { width, explicit: false }) = material.get(i + 1)
|
||||
&& let Some((left, right)) = pair(material, i + 1)
|
||||
{
|
||||
@@ -447,16 +442,11 @@ pub(super) fn pack(
|
||||
let TextNode::Glyph { font, glyph, .. } = &mut material[i] else {
|
||||
unreachable!()
|
||||
};
|
||||
*font = face.id;
|
||||
if external {
|
||||
glyph.width = face.metrics().width(character);
|
||||
glyph.height = face.metrics().height(character);
|
||||
glyph.depth = face.metrics().depth(character);
|
||||
glyph.italic = face.metrics().italic(character);
|
||||
} else {
|
||||
glyph.width = pdf_device::magnify(glyph.width, 1000 + amount);
|
||||
glyph.italic = pdf_device::magnify(glyph.italic, 1000 + amount);
|
||||
}
|
||||
*font = selected;
|
||||
glyph.width = metrics.width;
|
||||
glyph.height = metrics.height;
|
||||
glyph.depth = metrics.depth;
|
||||
glyph.italic = metrics.italic;
|
||||
let geometry = glyph.math_geometry.as_mut().expect("native character geometry");
|
||||
geometry.metrics.width = glyph.width;
|
||||
geometry.metrics.height = glyph.height;
|
||||
@@ -464,7 +454,7 @@ pub(super) fn pack(
|
||||
let MathItem::NativeGlyph { font, .. } = &mut geometry.items[0].item else {
|
||||
unreachable!()
|
||||
};
|
||||
*font = face;
|
||||
*font = paint;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1152,12 +1152,7 @@ impl State {
|
||||
+ self.mathfonts.len();
|
||||
c.usage.state.save_entries = self.groups.iter().map(|g| g.saved.len()).sum();
|
||||
c.usage.state.font_instances = self.fonts.fonts().len() - 1;
|
||||
c.usage.state.font_parameter_cells = self
|
||||
.fonts
|
||||
.fonts()
|
||||
.iter()
|
||||
.map(|f| f.parameters().len())
|
||||
.sum();
|
||||
c.usage.state.font_parameter_cells = self.fonts.parameter_words();
|
||||
c.usage.state.tfm_resources = self.fonts.resources().len();
|
||||
c.usage.state.tfm_resource_bytes =
|
||||
self.fonts.resources().iter().map(|r| r.version.bytes).sum();
|
||||
|
||||
Reference in new issue
Block a user