Skip to main content

Font

Trait Font 

Source
pub trait Font {
    // Required method
    unsafe fn as_bytes(&self) -> &[u8];

    // Provided methods
    fn is_ascii(&self) -> bool { ... }
    fn line_width_ascii(&self, t: &str) -> u32 { ... }
    fn line_width_utf8(&self, t: &str) -> u32 { ... }
    fn char_width(&self) -> u8 { ... }
    fn char_height(&self) -> u8 { ... }
    fn baseline(&self) -> u8 { ... }
}
Expand description

A loaded font file.

Required Methods§

Source

unsafe fn as_bytes(&self) -> &[u8]

Get the raw font file representation.

§Safety

Don’t use it. The internal font representation might change in the future and so should not be relied upon.

Provided Methods§

Source

fn is_ascii(&self) -> bool

Check if the font encoding is ASCII.

Source

fn line_width_ascii(&self, t: &str) -> u32

Calculate width (in pixels) of the given ASCII text.

This function does not account for newlines.

Source

fn line_width_utf8(&self, t: &str) -> u32

Calculate width (in pixels) of the given UTF-8 text.

This function does not account for newlines.

Source

fn char_width(&self) -> u8

The width (in pixels) of one glyph bounding box.

Source

fn char_height(&self) -> u8

The height (in pixels) of one glyph (one line) bounding box.

Source

fn baseline(&self) -> u8

Offset from the top of the glyph bounding box to the baseline.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Font for FontBuf

Available on crate feature alloc only.
Source§

impl Font for FontRef<'_>