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
impl BitmapFontMetrics
Sourcepub fn pixel_size(self) -> f32
pub fn pixel_size(self) -> f32
Side length of one bitmap pixel in logical drawing coordinates.
Sourcepub fn glyph_advance(self) -> f32
pub fn glyph_advance(self) -> f32
Horizontal advance per Unicode scalar: five columns plus one spacing column.
Sourcepub fn baseline(self) -> f32
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.
Sourcepub fn line_height(self) -> f32
pub fn line_height(self) -> f32
Baseline-to-baseline distance: seven pixel rows plus one spacing row.
Sourcepub fn measure_line(
self,
text: &str,
) -> Result<BitmapTextMetrics, FontMeasureError>
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);Sourcepub fn measure_multiline(
self,
text: &str,
) -> Result<BitmapTextMetrics, FontMeasureError>
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
impl Clone for BitmapFontMetrics
Source§fn clone(&self) -> BitmapFontMetrics
fn clone(&self) -> BitmapFontMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more