Skip to main content

CffFontRef

Struct CffFontRef 

Source
pub struct CffFontRef<'a> {
    data: &'a [u8],
    is_cff2: bool,
    upem: i32,
    global_subrs: Index<'a>,
    top_dict: TopDict<'a>,
    top_dict_index: u16,
}
Expand description

A CFF or CFF2 font.

The source data may be a raw CFF blob as embedded in a PDF or the content of a CFF or CFF2 table in an OpenType font.

Fields§

§data: &'a [u8]§is_cff2: bool§upem: i32§global_subrs: Index<'a>§top_dict: TopDict<'a>§top_dict_index: u16

Implementations§

Source§

impl<'a> CffFontRef<'a>

Source

pub fn new( data: &'a [u8], top_dict_index: u32, upem: Option<i32>, ) -> Result<Self, Error>

Creates a new font for the given CFF or CFF2 data.

Tries to determine the CFF version by reading the first word of the header.

For CFF blobs embedded in an OpenType font, the upem should be taken from the head table. Otherwise, 1000 will be assumed.

Source

pub fn new_cff( data: &'a [u8], top_dict_index: u32, upem: Option<i32>, ) -> Result<Self, Error>

Creates a new font for the given CFF data.

For CFF blobs embedded in an OpenType font, the upem should be taken from the head table. Otherwise, 1000 will be assumed.

Source

pub fn new_cff2(data: &'a [u8], upem: Option<i32>) -> Result<Self, Error>

Creates a new font for the given CFF2 data.

For CFF blobs embedded in an OpenType font, the upem should be taken from the head table. Otherwise, 1000 will be assumed.

Source

fn new_impl( data: &'a [u8], is_cff2: bool, upem: Option<i32>, top_dict_data: &'a [u8], top_dict_index: u16, strings: Index<'a>, global_subrs: Index<'a>, ) -> Result<Self, Error>

Source

pub fn data(&self) -> &'a [u8]

Returns the raw CFF blob.

Source

pub fn version(&self) -> u16

Returns the CFF version (either 1 or 2).

Source

pub fn metadata(&self) -> Option<Metadata<'a>>

Returns additional metadata such as font names and metrics.

Source

pub fn is_cid(&self) -> bool

Returns true if this is a CID-keyed font.

Source

pub fn global_subrs(&self) -> &Index<'a>

Returns the global subroutine index.

Source

pub fn num_glyphs(&self) -> u32

Returns the number of glyphs in the CFF font.

Source

pub fn charstrings(&self) -> &Index<'a>

Returns the charstring index.

Source

pub fn strings(&self) -> Option<&Index<'a>>

Returns the string index.

Source

pub fn string(&self, sid: Sid) -> Option<&'a [u8]>

Returns the string for the given identifier.

Source

pub fn charset(&self) -> Option<Charset<'a>>

Returns the mapping for glyph identifiers.

For a CID font, this maps between CIDs and glyph identifiers. Otherwise maps between SIDs and glyph identifiers.

Source

pub fn encoding(&self) -> Option<Encoding<'a>>

Returns the mapping from character codes to glyph identifiers.

Source

pub fn matrix(&self) -> Option<&ScaledFontMatrix>

Returns the top level font matrix.

Source

pub fn upem(&self) -> i32

Returns the units per em.

Source

pub fn var_store(&self) -> Option<&ItemVariationStore<'a>>

Returns the item variation store.

Only present for CFF2 variable fonts.

Source

pub fn num_subfonts(&self) -> u16

Returns the number of available subfonts.

Source

pub fn subfont_index(&self, gid: GlyphId) -> Option<u16>

Returns the subfont index for the given glyph.

Source

pub fn subfont(&self, index: u16, coords: &[F2Dot14]) -> Result<Subfont, Error>

Returns the subfont with the given index and normalized variation coordinates.

Source

pub fn subfont_hinted( &self, index: u16, coords: &[F2Dot14], ) -> Result<(Subfont, HintingParams), Error>

Returns the subfont and hinting parameters for the given index and normalized variation coordinates.

Source

pub fn transform(&self, subfont: &Subfont, ppem: Option<f32>) -> Transform

Returns the effective transform for the given subfont and optional size in pixels per em.

Source

pub fn evaluate_charstring( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], sink: &mut impl CommandSink, ) -> Result<Option<Fixed>, Error>

Evaluates the charstring for the requested glyph and sends the results to the given sink.

Returns the advance with of the glyph in font units if the charstring provides one.

Source

pub fn draw( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], ppem: Option<f32>, pen: &mut impl OutlinePen, ) -> Result<Option<f32>, Error>

Draws the glyph with an optional size in ppem to the given pen.

Returns the advance width of the glyph if the charstring provides one.

Source

fn blend_state( &self, vs_index: u16, coords: &'a [F2Dot14], ) -> Option<BlendState<'a>>

Returns a blend state for the given variation store index and normalized coordinates.

Trait Implementations§

Source§

impl<'a> Clone for CffFontRef<'a>

Source§

fn clone(&self) -> CffFontRef<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CffFontRef<'a>

§

impl<'a> RefUnwindSafe for CffFontRef<'a>

§

impl<'a> Send for CffFontRef<'a>

§

impl<'a> Sync for CffFontRef<'a>

§

impl<'a> Unpin for CffFontRef<'a>

§

impl<'a> UnsafeUnpin for CffFontRef<'a>

§

impl<'a> UnwindSafe for CffFontRef<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.