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
impl Font
pub fn name(&self) -> &str
Sourcepub fn line_height(&self) -> u32
pub fn line_height(&self) -> u32
Pixels from one baseline to the next.
Sourcepub fn glyphs(&self) -> &[Glyph]
pub fn glyphs(&self) -> &[Glyph]
The glyphs, in the order written; a space is added when none is written.
pub fn glyph(&self, ch: char) -> Option<&Glyph>
Sourcepub fn kerning(&self) -> &[KernPair]
pub fn kerning(&self) -> &[KernPair]
Authored kerning pairs, ordered by left and right character.
Sourcepub fn kern(&self, left: char, right: char) -> i32
pub fn kern(&self, left: char, right: char) -> i32
Pixel adjustment before right when it follows left.
Sourcepub fn measure(&self, text: &str) -> (u32, u32)
pub fn measure(&self, text: &str) -> (u32, u32)
The size of text drawn by Font::render, in pixels.
Sourcepub fn render(&self, text: &str, color: Color) -> Result<Image>
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 ?.
Sourcepub fn render_with(
&self,
text: &str,
color: Color,
limits: &Limits,
) -> Result<Image>
pub fn render_with( &self, text: &str, color: Color, limits: &Limits, ) -> Result<Image>
Font::render within limits.
Sourcepub fn to_ttf(&self, options: &TtfOptions) -> Result<Vec<u8>>
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.
Sourcepub fn outline(&self, ch: char) -> Option<Vec<Vec<(i32, i32)>>>
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.
Sourcepub fn units_per_pixel(&self) -> u32
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
impl Font
Sourcepub fn sprite(
&self,
text: &str,
palette: &Palette,
key: char,
options: &TextOptions,
) -> Result<Sprite>
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.
Sourcepub fn sprite_with(
&self,
text: &str,
palette: &Palette,
key: char,
options: &TextOptions,
limits: &Limits,
) -> Result<Sprite>
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.
Sourcepub fn sprite_runs(
&self,
runs: &[(char, &str)],
palette: &Palette,
options: &TextOptions,
) -> Result<Sprite>
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.
Sourcepub fn sprite_runs_with(
&self,
runs: &[(char, &str)],
palette: &Palette,
options: &TextOptions,
limits: &Limits,
) -> Result<Sprite>
pub fn sprite_runs_with( &self, runs: &[(char, &str)], palette: &Palette, options: &TextOptions, limits: &Limits, ) -> Result<Sprite>
Font::sprite_runs with explicit limits.