pub struct EmbeddedFont { /* private fields */ }Expand description
A parsed TrueType/OpenType font ready for embedding.
Holds the raw font data and provides access to font metrics.
Call subset to produce a SubsetFont containing
only the glyphs needed for specific text.
Implementations§
Source§impl EmbeddedFont
impl EmbeddedFont
Sourcepub fn from_otf(data: &[u8]) -> PdfResult<Self>
pub fn from_otf(data: &[u8]) -> PdfResult<Self>
Parses an OpenType CFF (.otf) font from raw bytes.
Sourcepub fn from_ttf_with_axes(data: &[u8], axes: &[(&str, f32)]) -> PdfResult<Self>
pub fn from_ttf_with_axes(data: &[u8], axes: &[(&str, f32)]) -> PdfResult<Self>
Parses a TrueType variable font at specific axis settings.
Each axis is a (tag, value) pair, e.g., ("wght", 700.0) for bold.
The font metrics and glyph widths are computed at the specified instance.
Sourcepub fn units_per_em(&self) -> u16
pub fn units_per_em(&self) -> u16
Returns the units per em.
Sourcepub fn measure_text(&self, text: &str, size: f64) -> PdfResult<f64>
pub fn measure_text(&self, text: &str, size: f64) -> PdfResult<f64>
Measures the width of a string in points at the given font size.
Sourcepub fn subset(&self, chars: &[char]) -> PdfResult<SubsetFont>
pub fn subset(&self, chars: &[char]) -> PdfResult<SubsetFont>
Subsets the font to only include glyphs needed for the given characters.
Returns a SubsetFont that can generate PDF dictionaries and streams.
§Errors
Returns PdfError::InvalidFont if the subset exceeds 256 glyphs,
which is the limit for simple (single-byte) PDF fonts. For larger
glyph sets (CJK, mixed scripts), use the CIDFont API instead.
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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