Skip to main content

Font

Struct Font 

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

A pixel font: glyphs of one height, with a baseline and a line height.

Implementations§

Source§

impl Font

Source

pub fn name(&self) -> &str

Source

pub fn height(&self) -> u32

Rows of every glyph’s grid.

Source

pub fn baseline(&self) -> u32

Rows of the grid above the baseline; the rest descend below it.

Source

pub fn line_height(&self) -> u32

Pixels from one baseline to the next.

Source

pub fn glyphs(&self) -> &[Glyph]

The glyphs, in the order written; a space is added when none is written.

Source

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

Source

pub fn kerning(&self) -> &[KernPair]

Authored kerning pairs, ordered by left and right character.

Source

pub fn kern(&self, left: char, right: char) -> i32

Pixel adjustment before right when it follows left.

Source

pub fn measure(&self, text: &str) -> (u32, u32)

The size of text drawn by Font::render, in pixels.

Source

pub fn render(&self, text: &str, color: Color) -> Result<Image>

Draws text in color on a transparent image, within the default Limits. \n starts a new line; characters without a glyph are drawn as ?, or left out when the font has no ?.

Source

pub fn render_with( &self, text: &str, color: Color, limits: &Limits, ) -> Result<Image>

Font::render within limits.

Source

pub fn to_ttf(&self, options: &TtfOptions) -> Result<Vec<u8>>

The font as a TrueType file. Each glyph’s outline is its pixels as squares, merged where they touch. See TtfOptions.

Source

pub fn outline(&self, ch: char) -> Option<Vec<Vec<(i32, i32)>>>

The outline of ch’s glyph, in pixels: closed contours of corner points, x right and y up from the baseline. Outer contours run clockwise and holes counter-clockwise, so ink is always on the right; pixels that touch only at a corner make separate contours. TrueType export scales these by Font::units_per_pixel.

Source

pub fn units_per_pixel(&self) -> u32

Font units per pixel in TrueType export: 128, or fewer when the font is taller than 128 pixels or has glyphs wider than 250, so that the em, which is the glyph height, stays within 16384 units and every coordinate within 32000.

Source§

impl Font

Source

pub fn sprite( &self, text: &str, palette: &Palette, key: char, options: &TextOptions, ) -> Result<Sprite>

Draw text into a palette-key sprite, rejecting characters without glyphs.

Source

pub fn sprite_with( &self, text: &str, palette: &Palette, key: char, options: &TextOptions, limits: &Limits, ) -> Result<Sprite>

Font::sprite with explicit limits. Wrapping happens at spaces; an overlong word is an error. Explicit leading spaces remain in each line.

Source

pub fn sprite_runs( &self, runs: &[(char, &str)], palette: &Palette, options: &TextOptions, ) -> Result<Sprite>

Draw text in several colors: each run is a palette key and the text drawn in it, in order. Glyph positions, kerning, wrapping and alignment are those of the same text in one color.

Source

pub fn sprite_runs_with( &self, runs: &[(char, &str)], palette: &Palette, options: &TextOptions, limits: &Limits, ) -> Result<Sprite>

Font::sprite_runs with explicit limits.

Trait Implementations§

Source§

impl Clone for Font

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 Font

Source§

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

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

impl Eq for Font

Source§

impl PartialEq for Font

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
Source§

impl StructuralPartialEq for Font

Auto Trait Implementations§

§

impl Freeze for Font

§

impl RefUnwindSafe for Font

§

impl Send for Font

§

impl Sync for Font

§

impl Unpin for Font

§

impl UnsafeUnpin for Font

§

impl UnwindSafe for Font

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 = !

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.