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: u16Implementations§
Source§impl<'a> CffFontRef<'a>
impl<'a> CffFontRef<'a>
Sourcepub fn new(
data: &'a [u8],
top_dict_index: u32,
upem: Option<i32>,
) -> Result<Self, Error>
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.
Sourcepub fn new_cff(
data: &'a [u8],
top_dict_index: u32,
upem: Option<i32>,
) -> Result<Self, Error>
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.
Sourcepub fn new_cff2(data: &'a [u8], upem: Option<i32>) -> Result<Self, Error>
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.
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>
Sourcepub fn metadata(&self) -> Option<Metadata<'a>>
pub fn metadata(&self) -> Option<Metadata<'a>>
Returns additional metadata such as font names and metrics.
Sourcepub fn global_subrs(&self) -> &Index<'a>
pub fn global_subrs(&self) -> &Index<'a>
Returns the global subroutine index.
Sourcepub fn num_glyphs(&self) -> u32
pub fn num_glyphs(&self) -> u32
Returns the number of glyphs in the CFF font.
Sourcepub fn charstrings(&self) -> &Index<'a>
pub fn charstrings(&self) -> &Index<'a>
Returns the charstring index.
Sourcepub fn string(&self, sid: Sid) -> Option<&'a [u8]>
pub fn string(&self, sid: Sid) -> Option<&'a [u8]>
Returns the string for the given identifier.
Sourcepub fn charset(&self) -> Option<Charset<'a>>
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.
Sourcepub fn encoding(&self) -> Option<Encoding<'a>>
pub fn encoding(&self) -> Option<Encoding<'a>>
Returns the mapping from character codes to glyph identifiers.
Sourcepub fn matrix(&self) -> Option<&ScaledFontMatrix>
pub fn matrix(&self) -> Option<&ScaledFontMatrix>
Returns the top level font matrix.
Sourcepub fn var_store(&self) -> Option<&ItemVariationStore<'a>>
pub fn var_store(&self) -> Option<&ItemVariationStore<'a>>
Returns the item variation store.
Only present for CFF2 variable fonts.
Sourcepub fn num_subfonts(&self) -> u16
pub fn num_subfonts(&self) -> u16
Returns the number of available subfonts.
Sourcepub fn subfont_index(&self, gid: GlyphId) -> Option<u16>
pub fn subfont_index(&self, gid: GlyphId) -> Option<u16>
Returns the subfont index for the given glyph.
Sourcepub fn subfont(&self, index: u16, coords: &[F2Dot14]) -> Result<Subfont, Error>
pub fn subfont(&self, index: u16, coords: &[F2Dot14]) -> Result<Subfont, Error>
Returns the subfont with the given index and normalized variation coordinates.
Sourcepub fn subfont_hinted(
&self,
index: u16,
coords: &[F2Dot14],
) -> Result<(Subfont, HintingParams), Error>
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.
Sourcepub fn transform(&self, subfont: &Subfont, ppem: Option<f32>) -> Transform
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.
Sourcepub fn evaluate_width(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
) -> Result<Option<Fixed>, Error>
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.
Sourcefn charstring_width(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
) -> Result<Option<Fixed>, Error>
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.
Sourcepub fn evaluate_charstring(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
sink: &mut impl CommandSink,
) -> Result<Option<Fixed>, Error>
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.
Sourcepub fn advance(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
ppem: Option<f32>,
) -> Result<Option<f32>, Error>
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.
Sourcepub fn evaluate_extents(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
) -> Result<Option<BoundingBox<Fixed>>, Error>
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.
Sourcepub fn extents(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
ppem: Option<f32>,
) -> Result<Option<BoundingBox<f32>>, Error>
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.
Sourcepub fn draw(
&self,
subfont: &Subfont,
gid: GlyphId,
coords: &[F2Dot14],
ppem: Option<f32>,
sink: &mut impl PathSink,
) -> Result<Option<f32>, Error>
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.
Sourcefn blend_state(
&self,
vs_index: u16,
coords: &'a [F2Dot14],
) -> Option<BlendState<'a>>
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>
impl<'a> Clone for CffFontRef<'a>
Source§fn clone(&self) -> CffFontRef<'a>
fn clone(&self) -> CffFontRef<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'yoke> Yokeable<'yoke> for CffFontRef<'static>
impl<'yoke> Yokeable<'yoke> for CffFontRef<'static>
Source§type Output = CffFontRef<'yoke>
type Output = CffFontRef<'yoke>
Self with the 'static replaced with 'a, i.e. Self<'a>