pub struct TextStyle {
pub font_family: Option<String>,
pub font_size: f32,
pub color: Rgba,
pub line_height: f32,
pub letter_spacing: f32,
pub font_weight: u16,
pub align: TextAlign,
pub max_width: f32,
pub position: Vec2,
pub anchor: Vec2,
pub outline: Option<TextOutline>,
pub background: Option<TextBackground>,
}Expand description
How text looks and where it lies: a caption track’s cues, or a text
crate::Generator.
Sizes are resolution-independent: the font size is a fraction of the
canvas’s shorter side, as every other length is, the wrapping width a
fraction of the canvas width, and the outline and background padding
fractions of the font size. The engine draws with the fonts its host
registered: those of font_family first, then the rest in their
fallback order.
Fields§
§font_family: Option<String>The family the text draws in, as the font’s own name table gives it
(typographic family, else family), matched without regard to ASCII
case. Glyphs its fonts lack, and a family no registered font has,
draw from the other fonts in fallback order. None draws from the
fallback order alone. Non-empty, at most MAX_FONT_FAMILY_BYTES
bytes.
font_size: f32Font size as a fraction of the canvas’s shorter side: positive, at
most crate::MAX_CAPTION_FONT_SIZE on a caption track and
MAX_TEXT_GENERATOR_FONT_SIZE in a text generator.
color: RgbaText color.
line_height: f32Baseline-to-baseline distance in font sizes, in [0.5, 3]. Each
line’s em box, 0.8 of a font size above its baseline and 0.2 below,
is centred in its line when the line is taller than an em.
letter_spacing: f32Space after each character, as a fraction of the font size, in
[-0.5, 1], as CSS letter-spacing adds it: none after a line’s
last character, and none after a character of a cursive script
(Arabic, say), whose joins it would break. Not zero, it turns optional
ligatures off.
font_weight: u16The weight, in [1, 1000], a family’s faces are matched by, as CSS
Fonts 4 matches font-weight; a variable face draws at it, clamped
to its wght axis. No face is emboldened: a weight the family lacks
draws its nearest face.
align: TextAlignHow lines align within the text.
max_width: f32Width text wraps at, as a fraction of the canvas width, in (0, 1].
position: Vec2Where on the canvas the text’s anchor lies, (0, 0) top-left to
(1, 1) bottom-right.
anchor: Vec2The point of the text, background included, placed at
position: (0.5, 1) is its bottom centre.
outline: Option<TextOutline>A band around the glyphs.
background: Option<TextBackground>A box behind each line.