Module text

Source
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§

FaceMetrics
Font metrics of a face in font pixels.
TextMetrics
Measured size of styled text in logical units.
TextStyle
Appearance of styled text. Construct with TextStyle::modern or TextStyle::classic and refine with the with_* methods.
WrapLines
Iterator returned by wrap_text.

Enums§

FontFace
Bitmap typeface for TextStyle.
TextAlign
Horizontal anchoring of each line relative to the x passed to drawing.

Functions§

draw_text_styled
Draws styled text. y is the first line’s baseline (as with crate::draw_text_ex) and x anchors each line per TextStyle::align. Lines split on \n. Returns the same value as measure_text_styled.
draw_text_wrapped
Draws text word-wrapped to max_width starting at baseline y; x anchors lines per the style’s alignment. Returns the wrapped block’s metrics.
measure_text_styled
Measures styled text exactly as draw_text_styled lays 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-in FontFace::Modern bitmap face (13 rows, baseline under row 10, bit width - 1 - col lit).
modern_kerning
Kerning adjustment in font pixels between two adjacent FontFace::Modern glyphs.
text_width
Width in logical units of a single line (no \n handling).
wrap_text
Greedy word-wrapped lines of text no wider than max_width (logical units). Explicit \n breaks are kept; runs of spaces at a wrap are dropped; a word wider than the limit is split between characters. Borrowed slices, no allocation.