pub struct TextStyle {Show 14 fields
pub font_family: Option<String>,
pub font_size: f32,
pub fill: Paint,
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 strokes: Vec<TextStroke>,
pub shadows: Vec<TextShadow>,
pub background: Option<TextBackground>,
pub animators: Vec<TextAnimator>,
}Expand description
How text looks and where it lies, for caption cues or a text crate::Generator.
The font size is a fraction of the canvas’s shorter side, the wrapping width a fraction
of the canvas width, and strokes, shadows and padding fractions of the font size. The
engine draws with its host’s registered fonts, font_family first, then the rest in
fallback order.
Painting is bottom to top as in CSS: background boxes, shadows (last listed lowest), strokes (outermost lowest), fill, then color glyphs.
Fields§
§font_family: Option<String>The family, as the font’s name table gives it (typographic family, else family), matched
ASCII case-insensitively. Missing glyphs and unknown families fall back to the other fonts
in order; None uses 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.
fill: PaintWhat paints the glyphs; a color reads as a solid paint. Gradient positions are in the
text’s layout box, (0, 0) top-left to (1, 1) bottom-right, and a radial radius is a
fraction of the box’s shorter side. Default solid white.
line_height: f32Baseline-to-baseline distance in font sizes, in [0.5, 3]. Each line’s em box (0.8 font
sizes above the baseline, 0.2 below) is centred in a taller line.
letter_spacing: f32Space after each character, as a fraction of the font size, in [-0.5, 1], added as CSS
letter-spacing does: none after a line’s last character or within cursive scripts such
as Arabic. A non-zero value turns optional ligatures off.
font_weight: u16The weight in [1, 1000] used to match a family’s faces, as CSS Fonts 4 matches
font-weight. Variable faces draw at it, clamped to their wght axis; no face is
synthetically emboldened.
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.
strokes: Vec<TextStroke>Bands around the glyphs, innermost first, each outside the one before. At most
MAX_TEXT_STROKES, widths summing to at most MAX_TEXT_STROKE_EXTENT.
shadows: Vec<TextShadow>Shadows of the glyphs and strokes, the first on top, as CSS text-shadow lists them. At
most MAX_TEXT_SHADOWS.
background: Option<TextBackground>A box behind each line.
animators: Vec<TextAnimator>Per-character motion and color, applied in order, at most crate::MAX_TEXT_ANIMATORS.
Keyframes are in the holder’s time (since a caption cue’s start, or a text generator’s
picture time). They never change line layout.