pub struct Font {
pub name: String,
pub data: Vec<u8>,
pub format: FontFormat,
pub metrics: FontMetrics,
pub descriptor: FontDescriptor,
pub glyph_mapping: GlyphMapping,
}Expand description
Represents a loaded font ready for embedding
Fields§
§name: StringFont name as it will appear in the PDF
data: Vec<u8>Raw font data
format: FontFormatFont format (TTF or OTF)
metrics: FontMetricsFont metrics
descriptor: FontDescriptorFont descriptor
glyph_mapping: GlyphMappingCharacter to glyph mapping
Implementations§
Source§impl Font
impl Font
Sourcepub fn from_file(
name: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<Self>
pub fn from_file( name: impl Into<String>, path: impl AsRef<Path>, ) -> Result<Self>
Load a font from file path
Sourcepub fn from_bytes(name: impl Into<String>, data: Vec<u8>) -> Result<Self>
pub fn from_bytes(name: impl Into<String>, data: Vec<u8>) -> Result<Self>
Load a font from byte data
Sourcepub fn postscript_name(&self) -> &str
pub fn postscript_name(&self) -> &str
Get the PostScript name of the font
Sourcepub fn missing_glyphs(&self, text: &str) -> Vec<char>
pub fn missing_glyphs(&self, text: &str) -> Vec<char>
Characters in text the font has no glyph for, deduplicated and in
first-seen order. Control characters (newlines, tabs, …) are ignored
because they are never rendered.
Such characters render as .notdef (an empty box) — this is the
correct PDF behaviour when the embedded font genuinely lacks the glyph
(issue #287). Use this to detect coverage gaps before rendering rather
than discovering empty boxes in the output.
Sourcepub fn measure_text(&self, text: &str, font_size: f32) -> TextMeasurement
pub fn measure_text(&self, text: &str, font_size: f32) -> TextMeasurement
Measure text using this font at a specific size
Sourcepub fn line_height(&self, font_size: f32) -> f32
pub fn line_height(&self, font_size: f32) -> f32
Get the recommended line height for this font at a specific size