Skip to main content

Typeface

Struct Typeface 

Source
pub struct Typeface(/* private fields */);
Expand description

A font loaded for text at one location in its design space, with the family names, weight and style text chooses it by: Compose’s Typeface. Clones share one load; two typefaces are equal when they draw the same glyphs, from the same bytes at the same axis positions.

Implementations§

Source§

impl Typeface

Source

pub fn from_bytes(bytes: impl Into<FontBytes>) -> Result<Self, TypefaceError>

Reads bytes as a typeface no family was declared for: its weight, style and family names come from the font.

Source

pub fn from_registered( family: &FontFamily, weight: FontWeight, style: FontStyle, bytes: impl Into<FontBytes>, variations: &[([u8; 4], f32)], ) -> Result<Self, TypefaceError>

Reads bytes as a typeface an app registered under family, declaring weight and style for it, as a Compose Font(resId, weight, style) entry does: the declaration wins over the font’s own values, and a variable font is instanced on its wght, ital and slnt axes, so one file backs a whole family. The explicit variations then win over the declared positions; a variation of an axis the font lacks, or outside that axis’s range, fails.

Source

pub fn family_names(&self) -> &[String]

The family names the font’s name table gives it, typographic family first.

Source

pub fn registered_family(&self) -> Option<FontFamilyKey>

The family the typeface was registered under, None for one read with Typeface::from_bytes.

Source

pub fn weight(&self) -> FontWeight

The weight text chooses the typeface by.

Source

pub fn style(&self) -> FontStyle

The style text chooses the typeface by.

Source

pub fn is_color(&self) -> bool

Whether the font draws glyphs in color (a COLR, CBDT, sbix or SVG table), as emoji fonts do.

Source

pub fn synthesis( &self, weight: FontWeight, style: FontStyle, synthesis: FontSynthesis, ) -> Synthesis

What Compose synthesizes for text in weight and style drawn with this typeface, as synthesis allows: a bold for a weight of 600 or more when the typeface draws none that heavy, and an italic when it draws none.

Source

pub fn variations(&self) -> &[([u8; 4], f32)]

The axis positions the typeface is instanced at, sorted by tag.

Source

pub fn content_hash(&self) -> u64

A hash of the font’s bytes and its axis positions: equal for two loads of one instance.

Source

pub fn units_per_em(&self) -> u16

The font’s design units in an em.

Source

pub fn line_metrics(&self) -> LineMetrics

The font’s line metrics at the instance, in design units: the typographic line when the font asks for it with USE_TYPO_METRICS, otherwise the hhea line, as Skia and FreeType read them.

Source

pub fn decoration_metrics(&self) -> DecorationMetrics

Where the font draws an underline and a line through its text, in design units: its post underline and OS/2 strikeout, or Skia’s defaults for a font without them.

Source

pub fn glyph(&self, ch: char) -> Option<GlyphId>

The glyph the font maps ch to, None when it has none.

Source

pub fn covers(&self, ch: char) -> bool

Whether the font maps ch to a glyph.

Source

pub fn advance(&self, glyph: GlyphId) -> f32

The horizontal advance of glyph at the instance, in design units.

Trait Implementations§

Source§

impl Clone for Typeface

Source§

fn clone(&self) -> Self

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 Debug for Typeface

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Typeface

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.