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_width( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], ) -> Result<Option<Fixed>, Error>

Evaluates the charstring for the requested glyph far enough to read its advance width, without drawing it.

A Type 2 charstring states its width, where it states one at all, as an optional extra argument on the first operator that clears the stack, so evaluation stops there. Where the charstring states none, the subfont’s default width applies.

The font matrix is applied and no size is, so the width is exact and in the units the rest of the font is measured in. advance applies a size as well and reports what draw does.

Unlike evaluate_charstring, the matrix is applied here rather than left to a caller. That one withholds it so a hinter can be slotted in ahead of it; nothing hints a width.

Source

fn charstring_width( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], ) -> Result<Option<Fixed>, Error>

The width the charstring itself gives, before any transform.

Where it gives none the subfont’s default applies, as it does when the glyph is drawn.

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 width the charstring states, in the charstring’s own space: neither the font matrix nor a size is applied, to the width or to the commands. draw applies both.

Source

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

Returns the advance width of the glyph with an optional size in ppem, without drawing it.

This is the width draw reports, arrived at without the drawing.

Source

pub fn evaluate_extents( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], ) -> Result<Option<BoundingBox<Fixed>>, Error>

Measures the box the glyph’s drawing stays within, in design units.

A control box: a curve counts through its control points rather than the path they describe, so one bulging inside its hull measures larger than it draws. HarfBuzz reports a charstring’s extents the same way.

The font matrix is applied and no size is, so the box is exact and in the units the rest of the font is measured in. extents applies a size as well and answers in what a caller laying out text works in.

Unlike evaluate_charstring, the matrix is applied here rather than left to a caller. That one withholds it so a hinter can be slotted in before it; nothing hints a box, and a box cannot be brought through a matrix afterwards anyway, because turning a box turns its corners and a matrix that shears tilts the drawing inside a box that has to grow to hold them.

None where the glyph draws nothing.

Source

pub fn extents( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], ppem: Option<f32>, ) -> Result<Option<BoundingBox<f32>>, Error>

Returns the box the glyph’s drawing stays within, with an optional size in ppem.

The box draw would stay within, measured as evaluate_extents measures it and scaled by the size as well.

A size can be applied to a finished box, being one scale in both directions; it is applied here so the answer matches draw at that size without a caller doing the arithmetic. The matrix cannot, which is why neither of these leaves it out.

None where the glyph draws nothing.

Source

pub fn draw( &self, subfont: &Subfont, gid: GlyphId, coords: &[F2Dot14], ppem: Option<f32>, sink: &mut impl PathSink, ) -> 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 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'yoke> Yokeable<'yoke> for CffFontRef<'static>

Source§

type Output = CffFontRef<'yoke>

This type MUST be Self with the 'static replaced with 'a, i.e. Self<'a>
Source§

fn transform(&'yoke self) -> &'yoke Self::Output

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more
Source§

fn transform_owned(self) -> Self::Output

This method must cast self between Self<'static> and Self<'a>. Read more
Source§

unsafe fn make(from: Self::Output) -> Self

This method can be used to cast away Self<'a>’s lifetime. Read more
Source§

fn transform_mut<F>(&'yoke mut self, f: F)
where F: 'static + for<'_yoke> FnOnce(&'_yoke mut Self::Output),

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. 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> ErasedDestructor for T
where T: 'static,

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.