90 lines
2.5 KiB
Rust
90 lines
2.5 KiB
Rust
//! Native font state and TFM-only character construction.
|
|
use super::*;
|
|
use crate::{
|
|
HorizontalBox,
|
|
math::MathBox,
|
|
math_engine_tex::{MathGeometry, MathItem, PositionedItem},
|
|
};
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
|
pub struct FontIntegers {
|
|
pub hyphen: i32,
|
|
pub skew: i32,
|
|
}
|
|
impl State {
|
|
pub fn fonts(&self) -> &FontCatalog {
|
|
&self.fonts
|
|
}
|
|
pub fn font_integers(&self, font: FontId) -> FontIntegers {
|
|
self.fonts
|
|
.font(font)
|
|
.expect("loaded font identity")
|
|
.integers()
|
|
}
|
|
pub(super) fn hyphen_character(&self, font: FontId) -> Option<char> {
|
|
u8::try_from(self.font_integers(font).hyphen)
|
|
.ok()
|
|
.map(char::from)
|
|
}
|
|
pub(super) fn font_has_slot(&self, font: FontId, slot: u8) -> bool {
|
|
self.fonts
|
|
.font(font)
|
|
.expect("loaded font identity")
|
|
.metrics()
|
|
.is_some_and(|m| m.has_slot(slot))
|
|
}
|
|
}
|
|
pub(super) fn text_glyph(
|
|
state: &State,
|
|
font: FontId,
|
|
slot: u8,
|
|
source: crate::provenance::PaintSource,
|
|
) -> HorizontalBox {
|
|
let face = state.fonts.glyph_font(font).expect("validated font");
|
|
text_glyph_from_font(face, slot, source)
|
|
}
|
|
pub(super) fn text_glyph_from_font(
|
|
face: &std::sync::Arc<crate::native_font::NativeFont>,
|
|
slot: u8,
|
|
source: crate::provenance::PaintSource,
|
|
) -> HorizontalBox {
|
|
let f = face.metrics();
|
|
let c = char::from(slot);
|
|
let (width, height, depth, italic) = (face.advance(slot), f.height(c), f.depth(c), f.italic(c));
|
|
HorizontalBox {
|
|
width,
|
|
height,
|
|
depth,
|
|
italic,
|
|
character: Some(c),
|
|
size: Some(f.size_sp()),
|
|
math_geometry: Some(Box::new(MathGeometry {
|
|
metrics: MathBox {
|
|
width,
|
|
height,
|
|
depth,
|
|
},
|
|
items: vec![PositionedItem {
|
|
source,
|
|
x: 0,
|
|
y: 0,
|
|
item: MathItem::NativeGlyph {
|
|
character: c,
|
|
font: face.clone(),
|
|
slot,
|
|
size: f.size_sp(),
|
|
},
|
|
}],
|
|
})),
|
|
..HorizontalBox::default()
|
|
}
|
|
}
|
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
pub struct MissingGlyph {
|
|
pub font: FontId,
|
|
pub slot: u32,
|
|
pub tracing: i32,
|
|
pub destination: Option<WriteDestination>,
|
|
pub message: Option<String>,
|
|
pub span: Span,
|
|
}
|