pub struct EmbeddedFont {
pub name: String,
pub ascender: i32,
pub descender: i32,
pub cap_height: i32,
pub x_height: i32,
pub bbox: (i32, i32, i32, i32),
pub flags: u32,
pub stem_v: i16,
pub italic_angle: f32,
/* private fields */
}Expand description
Embedded TrueType font for PDF generation.
Contains parsed font data, subsetter, and encoder for generating CIDFont dictionaries and ToUnicode CMaps.
Fields§
§name: StringFont name (PostScript name or user-provided)
ascender: i32Font ascender value
descender: i32Font descender value
cap_height: i32Cap height (height of capital letters)
x_height: i32x-height (height of lowercase x)
bbox: (i32, i32, i32, i32)Font bounding box (llx, lly, urx, ury)
flags: u32Font flags for PDF
stem_v: i16Stem vertical width
italic_angle: f32Italic angle in degrees
Implementations§
Source§impl EmbeddedFont
impl EmbeddedFont
Sourcepub fn from_data(name: Option<String>, data: Vec<u8>) -> Result<Self, String>
pub fn from_data(name: Option<String>, data: Vec<u8>) -> Result<Self, String>
Create an embedded font from raw TTF/OTF data.
§Arguments
name- Font name to use (if None, uses PostScript name from font)data- Raw TTF/OTF file data
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, String>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, String>
Load an embedded font from a file.
Sourcepub fn glyph_id(&self, codepoint: u32) -> Option<u16>
pub fn glyph_id(&self, codepoint: u32) -> Option<u16>
Get the glyph ID for a Unicode codepoint.
Sourcepub fn glyph_width(&self, gid: u16) -> u16
pub fn glyph_width(&self, gid: u16) -> u16
Get the width of a glyph in 1/1000 em units.
Sourcepub fn char_width(&self, codepoint: u32) -> u16
pub fn char_width(&self, codepoint: u32) -> u16
Get the width of a character in 1/1000 em units.
Sourcepub fn text_width(&self, text: &str, font_size: f32) -> f32
pub fn text_width(&self, text: &str, font_size: f32) -> f32
Calculate text width in points at the given font size.
Sourcepub fn use_string(&mut self, text: &str)
pub fn use_string(&mut self, text: &str)
Record that a string is being used (for subsetting).
Sourcepub fn encode_string(&mut self, text: &str) -> String
pub fn encode_string(&mut self, text: &str) -> String
Encode a string for use in PDF content stream (Identity-H encoding).
Returns a hex string like “<00410042>” where each 4-digit hex is a glyph ID.
Sourcepub fn subset_name(&mut self) -> &str
pub fn subset_name(&mut self) -> &str
Get the subset font name (generates tag if needed).
Sourcepub fn subset_stats(&self) -> (usize, usize)
pub fn subset_stats(&self) -> (usize, usize)
Get subset statistics.
Sourcepub fn generate_widths_array(&self) -> String
pub fn generate_widths_array(&self) -> String
Generate the CID widths array for the W entry.
Sourcepub fn generate_tounicode_cmap(&self) -> String
pub fn generate_tounicode_cmap(&self) -> String
Generate the ToUnicode CMap for text extraction.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmbeddedFont
impl RefUnwindSafe for EmbeddedFont
impl Send for EmbeddedFont
impl Sync for EmbeddedFont
impl Unpin for EmbeddedFont
impl UnsafeUnpin for EmbeddedFont
impl UnwindSafe for EmbeddedFont
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more