Skip to main content

EmbeddedFont

Struct EmbeddedFont 

Source
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: String

Font name (PostScript name or user-provided)

§ascender: i32

Font ascender value

§descender: i32

Font descender value

§cap_height: i32

Cap height (height of capital letters)

§x_height: i32

x-height (height of lowercase x)

§bbox: (i32, i32, i32, i32)

Font bounding box (llx, lly, urx, ury)

§flags: u32

Font flags for PDF

§stem_v: i16

Stem vertical width

§italic_angle: f32

Italic angle in degrees

Implementations§

Source§

impl EmbeddedFont

Source

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
Source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self, String>

Load an embedded font from a file.

Source

pub fn glyph_id(&self, codepoint: u32) -> Option<u16>

Get the glyph ID for a Unicode codepoint.

Source

pub fn glyph_width(&self, gid: u16) -> u16

Get the width of a glyph in 1/1000 em units.

Source

pub fn char_width(&self, codepoint: u32) -> u16

Get the width of a character in 1/1000 em units.

Source

pub fn text_width(&self, text: &str, font_size: f32) -> f32

Calculate text width in points at the given font size.

Source

pub fn use_string(&mut self, text: &str)

Record that a string is being used (for subsetting).

Source

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.

Source

pub fn subset_name(&mut self) -> &str

Get the subset font name (generates tag if needed).

Source

pub fn font_data(&self) -> &[u8]

Get the raw font data for embedding.

Source

pub fn subset_stats(&self) -> (usize, usize)

Get subset statistics.

Source

pub fn is_used(&self) -> bool

Check if any text has been used with this font.

Source

pub fn generate_widths_array(&self) -> String

Generate the CID widths array for the W entry.

Source

pub fn generate_tounicode_cmap(&self) -> String

Generate the ToUnicode CMap for text extraction.

Trait Implementations§

Source§

impl Debug for EmbeddedFont

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,