pub struct Paragraph { /* private fields */ }Expand description
The retained paragraph, with Skia’s state tiers made explicit (SkParagraph’s kShaped/kWrapped/kFormatted ladder):
ParagraphBuilder::build()runs the EXPENSIVE tier once — fallback segmentation + harfrust shaping — and retains it.layout(width)re-wraps and places from the retained shaping (cheap; cached when the width doesn’t change).update_color(span, color)re-places only (no reshape, no rewrap) — the text-editing hot path.
Cloning duplicates the shaped and laid-out data (no re-shaping) — a cheap way for hosts to snapshot a layout before re-wrapping in place.
Implementations§
Source§impl Paragraph
impl Paragraph
Sourcepub fn layout(&mut self, max_width: f32)
pub fn layout(&mut self, max_width: f32)
Wrap and place against max_width (f32::INFINITY = never wrap).
Same width twice = cache hit; shaping is NEVER redone here.
Sourcepub fn update_color(&mut self, span: usize, color: Color)
pub fn update_color(&mut self, span: usize, color: Color)
The repaint tier: recolor one styled span and re-place — shaping and line breaks are untouched (color never moves a glyph).
Sourcepub fn advance(&self) -> f32
pub fn advance(&self) -> f32
How far the pen actually travelled — the widest line’s signed advance.
This is NOT Paragraph::width. A width is a layout box, so it has a
floor at zero: wrapping, alignment and bounds() are all defined on a
rectangle, and one narrower than nothing means nothing. An advance has
no such floor. Letter and word spacing tighter than the glyphs are wide
walks the pen backwards, and callers that report a pen position rather
than a box — Canvas2D’s TextMetrics.width — need the negative.
Sourcepub fn last_glyph_origin(&self) -> Option<f32>
pub fn last_glyph_origin(&self) -> Option<f32>
Paragraph-local pen x of the last glyph placed, or None when nothing
was placed at all. Distinct from the advance whenever that last glyph
carries one of its own.
pub fn height(&self) -> f32
Sourcepub fn ink_bounds(&self) -> Option<Rect>
pub fn ink_bounds(&self) -> Option<Rect>
Tight visible ink bounds in paragraph coordinates. Vector glyphs use Bézier extrema; color/bitmap glyphs use their non-transparent pixels. This deliberate slower query path is for Canvas-style text metrics; frame recording keeps using precomputed conservative run bounds.
Sourcepub fn primary_font(&self) -> Option<(&Font, f32)>
pub fn primary_font(&self) -> Option<(&Font, f32)>
Primary face and size even when the paragraph contains no glyphs.
pub fn bounds(&self) -> Rect
Sourcepub fn min_intrinsic_width(&self) -> f32
pub fn min_intrinsic_width(&self) -> f32
Widest unbreakable segment — the narrowest useful layout width.
Sourcepub fn max_intrinsic_width(&self) -> f32
pub fn max_intrinsic_width(&self) -> f32
Width when nothing wraps (widest hard-break line).
Sourcepub fn longest_line(&self) -> f32
pub fn longest_line(&self) -> f32
Widest laid-out line’s content width.
Source§impl Paragraph
impl Paragraph
pub fn text(&self) -> &str
Sourcepub fn demand(&self) -> &FontDemand
pub fn demand(&self) -> &FontDemand
What this paragraph could not resolve (families and codepoints no source answered) — a host fetches them and re-registers.
Sourcepub fn faces(&self) -> &FaceSet
pub fn faces(&self) -> &FaceSet
The faces this paragraph resolved (decoration metrics, glyph lookup at record time).
pub fn line_metrics(&self) -> Vec<LineMetrics>
Sourcepub fn caret_for_offset(&self, offset: usize) -> Rect
pub fn caret_for_offset(&self, offset: usize) -> Rect
The caret rectangle (zero width) for a byte offset — the leading
edge of the cluster at offset, or the trailing edge of the last
cluster before it.
Sourcepub fn glyph_position_at(&self, p: Point) -> PositionWithAffinity
pub fn glyph_position_at(&self, p: Point) -> PositionWithAffinity
The text position under a point (SkParagraph’s getGlyphPositionAtCoordinate): nearest line by y, nearest cluster edge by x.