Skip to main content

FontRegistry

Struct FontRegistry 

Source
pub struct FontRegistry { /* private fields */ }
Expand description

The registry: assigns font_ids, hands shaper access and metrics to the pipeline, and maps generic families to bundled faces.

Ids are dense and sequential from 0 — an id is an index.

Implementations§

Source§

impl FontRegistry

Source

pub fn new() -> Self

An empty registry.

Source

pub fn add(&mut self, source: FontSource) -> Result<Vec<u16>, FontError>

Registers a font file and returns the ids of the faces it yielded, in the order the file names them.

A variable file yields one face per named instance: the cuts the family says it has. Matching is then a lookup over faces with fixed slopes and weights, which is what lets the cascade resolve a face without a registry it may write to.

Decodes metrics eagerly: a font that can’t be parsed fails here, once, rather than at first shape.

Source

pub fn len(&self) -> usize

Number of registered faces. Ids are 0..len.

Source

pub fn is_empty(&self) -> bool

True when no face is registered.

Source

pub fn map_generic( &mut self, generic: GenericFamily, family: &str, ) -> Option<u16>

Binds a generic keyword to a registered family’s first face. The keyword must not already be bound.

Source

pub fn generic(&self, generic: GenericFamily) -> Option<u16>

The id a generic keyword resolves to.

Source

pub fn by_family(&self, family: &str) -> Option<u16>

The id of the first face whose family matches (case-insensitive compare against the lowercased registry key).

Source

pub fn select(&self, family: &str, want: FaceAttributes) -> Option<FaceMatch>

The face of family that best answers a slope and weight.

Matching follows CSS: slope decides first — a family with an italic cut never answers an italic request with the upright — and weight is then chosen by the desired-weight rules, which look up before they look down in the text range and away from it elsewhere. The match reports what it actually found, so a caller can say when the family had nothing at the slope asked for.

Source

pub fn font_ref(&self, id: u16) -> Option<&FontRefEntry>

Identity of a face, for the output font table.

Source

pub fn metrics(&self, id: u16) -> Option<FontMetricsTable>

Metrics of a face, in font units.

Source

pub fn has_small_caps(&self, id: u16) -> bool

Whether a face draws small capitals of its own. A face that does not has to have them synthesized from its capitals.

Source

pub fn has_feature(&self, id: u16, tag: [u8; 4]) -> bool

Whether a face carries one feature. A sheet that asks for a feature the face has nothing for gets the run set without it.

Source

pub fn bytes(&self, id: u16) -> Option<Arc<Vec<u8>>>

The raw bytes of a face, for embedding at write time.

Shared: the faces a variable file yielded are one file, and a painter embeds one copy of it however many cuts it draws.

Source

pub fn variations(&self, id: u16) -> Option<&[AxisSetting]>

Where on its file’s axes a face sits, in user space. Empty for a static face and for a variable one at its default location.

Source

pub fn advance_width(&self, id: u16, glyph: u32) -> Option<u16>

Advance width of one glyph, in font units.

Source

pub fn advance_widths(&self, id: u16, glyphs: &[u32]) -> Option<Vec<u16>>

The advance widths of a run of glyphs, in font units.

Shaped output is glyph ids; measuring them must not re-decode the font per glyph, so this batches.

Source

pub fn char_glyph(&self, id: u16, ch: char) -> Option<u32>

Maps one character to its nominal glyph, in font units.

Source

pub fn shape(&self, id: u16, text: &str) -> Option<Vec<ShapedGlyph>>

Shapes a string with a registered face, in font units.

Returns per-glyph ShapedGlyph — the raw material of line layout. Clusters index the shaped string, so callers can map text offsets (break opportunities) back to glyphs; offsets data stays in the shaper’s buffer.

Source

pub fn shape_with( &self, id: u16, text: &str, features: &Features, ) -> Option<Vec<ShapedGlyph>>

The same, with the features a style asked for turned on.

Trait Implementations§

Source§

impl Default for FontRegistry

Source§

fn default() -> FontRegistry

Returns the “default value” for a type. 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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
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.

§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

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.