Expand description
Styled bitmap text: a modern mixed-case face, drop shadows, outlines, letter spacing, alignment, measurement and allocation-free word wrapping.
FontFace::Modern is a hand-authored proportional pixel face with
lowercase, descenders, punctuation, tabular digits, UI symbols
(• · × → ← ↑ ↓ ★ ♥ …) and Latin-1 accents. FontFace::Classic is the
original 5×7 uppercase face, so existing art direction can opt into shadows
and outlines without changing letterforms. The legacy
crate::draw_text_ex and ui text APIs are unchanged.
Sizes follow the legacy convention: one font pixel is size / 8 logical
units, so size: 16.0 draws two-unit pixels and both faces keep integer
crispness at multiples of 8. At the same size, the modern capital height
(8 font pixels) is one pixel taller than the classic one (7).
Geometry is one quad per horizontal run of lit pixels per row, merged across
neighbouring glyphs, written directly into the frame’s vertex stream with no
allocation. measure_text_styled uses exactly the advances that
draw_text_styled draws.
use ferravex_render::{Color, text::{TextAlign, TextStyle, draw_text_styled, measure_text_styled}};
let title = TextStyle::modern(24., Color::from_hex(0xfff4d6))
.with_shadow(Color::new(0., 0., 0., 0.6))
.with_align(TextAlign::Center);
let size = measure_text_styled("Level complete!", title);
draw_text_styled("Level complete!", 640., 120., title);
assert_eq!(size.line_count, 1);Structs§
- Face
Metrics - Font metrics of a face in font pixels.
- Text
Metrics - Measured size of styled text in logical units.
- Text
Style - Appearance of styled text. Construct with
TextStyle::modernorTextStyle::classicand refine with thewith_*methods. - Wrap
Lines - Iterator returned by
wrap_text.
Enums§
- Font
Face - Bitmap typeface for
TextStyle. - Text
Align - Horizontal anchoring of each line relative to the
xpassed to drawing.
Functions§
- draw_
text_ styled - Draws styled text.
yis the first line’s baseline (as withcrate::draw_text_ex) andxanchors each line perTextStyle::align. Lines split on\n. Returns the same value asmeasure_text_styled. - draw_
text_ wrapped - Draws
textword-wrapped tomax_widthstarting at baseliney;xanchors lines per the style’s alignment. Returns the wrapped block’s metrics. - measure_
text_ styled - Measures styled text exactly as
draw_text_styledlays it out. Invalid styles (non-finite or nonpositive size) measure as empty. - modern_
glyph - Look up a single glyph’s
(width, rows)in the built-inFontFace::Modernbitmap face (13 rows, baseline under row 10, bitwidth - 1 - collit). - modern_
kerning - Kerning adjustment in font pixels between two adjacent
FontFace::Modernglyphs. - text_
width - Width in logical units of a single line (no
\nhandling). - wrap_
text - Greedy word-wrapped lines of
textno wider thanmax_width(logical units). Explicit\nbreaks are kept; runs of spaces at a wrap are dropped; a word wider than the limit is split between characters. Borrowed slices, no allocation.