Skip to main content

Module text

Module text 

Source
Expand description

Text paragraphs, rich styles and grapheme-aware stateless part animation.

use motion_content::prelude::*;
use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
use motion_render::{Composition, RenderPrepare, RenderOptions, BackendKind, render_still};
let mut fonts = FontLibrary::new();
fonts.load_file("assets/project.ttf")?;
let resources = Assets::new(".")?.with_fonts(fonts);
let text = Text::rich([
    TextSpan::new("Hello, ").fill(Color::WHITE),
    TextSpan::new("motion-rs").weight(FontWeight::BOLD),
])
.size(28.0)
.max_width(300.0);
let frame = Composition::new(320, 120, motion_render::FrameClock::new(fps!(30), 150))
    .configure(|options| options.resources(resources))
    .render_frame(0, Size::new(320.0, 120.0), |_| text.clone().into())?;
assert_eq!(frame.size().width, 320);

Re-exports§

pub use crate::TextAlignment;
pub use crate::TextSplit;

Structs§

FontWeight
Specifies the weight of glyphs in the font, their degree of blackness or stroke thickness.
ParagraphLayout
Immutable paragraph geometry; color/part transforms do not reshape it.
ParagraphStyle
Paragraph description: rich text, base style, width, alignment and optional fonts.
PartStyle
Per-part transform evaluated without changing paragraph layout.
Text
Multi-line Unicode text: a ParagraphStyle shaped into a ParagraphLayout, plus ink and one optional reveal effect. cosmic-text is the sole paragraph shaper, and unhinted skrifa outlines enter the ordinary shared fill pipeline. Static drawing, handwriting and part animation all read the same layout.
TextGlyph
Public glyph provenance and logical ink/hit bounds from one paragraph layout.
TextPart
One logical part with original source range, layout bounds and delayed time.
TextSpan
span style; unset properties inherit paragraph defaults.