Struct BitmapFontMetrics

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

Validated, reusable font geometry. No atlas, text buffer or allocation is needed.

let font = ferravex_render::get_default_font();
let metrics = font.try_metrics(16, 0.5)?;
assert_eq!(metrics.pixel_size(), 1.0);
assert_eq!(metrics.glyph_advance(), 6.0);
assert_eq!(metrics.baseline(), 7.0);
assert_eq!(metrics.line_height(), 8.0);

Implementations§

Source§

impl BitmapFontMetrics

Source

pub fn pixel_size(self) -> f32

Side length of one bitmap pixel in logical drawing coordinates.

Source

pub fn glyph_advance(self) -> f32

Horizontal advance per Unicode scalar: five columns plus one spacing column.

Source

pub fn baseline(self) -> f32

Baseline offset from a line’s top: seven pixel rows, with no descenders. Pass top + baseline() as the Y argument to draw_text_ex.

Source

pub fn line_height(self) -> f32

Baseline-to-baseline distance: seven pixel rows plus one spacing row.

Source

pub fn measure_line( self, text: &str, ) -> Result<BitmapTextMetrics, FontMeasureError>

Measures one immediate-renderer line without allocation.

Every scalar advances, including unsupported controls such as LF, CR and tab. There is no Unicode case expansion, shaping or fallback substitution. Empty input has no lines, size or ink; spaces reserve size but have no ink. Returns an error if the resulting geometry is unrepresentable.

let metrics = ferravex_render::get_default_font().try_metrics(8, 1.0)?;
let text = metrics.measure_line("a☃ ")?;
assert_eq!(text.width, 18.0);
assert_eq!(text.unsupported_glyphs, 1);
assert_eq!(text.ink_bounds.unwrap().w, 5.0);
Source

pub fn measure_multiline( self, text: &str, ) -> Result<BitmapTextMetrics, FontMeasureError>

Measures explicit LF/CRLF-separated lines without allocation or wrapping.

Lines share a left edge and advance by line_height(). Blank and trailing lines reserve vertical space; bare CR remains an unsupported blank cell. draw_text_ex itself does not split lines: draw each line separately with successive baselines, removing CR from CRLF separators first. Returns an error if the resulting geometry is unrepresentable.

use ferravex_render::{TextParams, WHITE, draw_text_ex, get_default_font};
let metrics = get_default_font().try_metrics(16, 1.0)?;
let label = "LEVEL 1\nREADY";
let measured = metrics.measure_multiline(label)?;
assert_eq!((measured.width, measured.height), (84.0, 30.0));
let mut baseline = 20.0 + metrics.baseline();
for line in label.split('\n') {
    draw_text_ex(line, 10.0, baseline, TextParams {
        font_size: 16, font_scale: 1.0, color: WHITE,
    });
    baseline += metrics.line_height();
}

Trait Implementations§

Source§

impl Clone for BitmapFontMetrics

Source§

fn clone(&self) -> BitmapFontMetrics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BitmapFontMetrics

Source§

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

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

impl PartialEq for BitmapFontMetrics

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BitmapFontMetrics

Source§

impl StructuralPartialEq for BitmapFontMetrics

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