Skip to main content

Paragraph

Struct Paragraph 

Source
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

Source

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.

Source

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).

Source

pub fn lines(&self) -> &[Line]

Placed lines of the most recent layout (empty before one).

Source

pub fn width(&self) -> f32

Widest line’s content width after layout.

Source

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.

Source

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.

Source

pub fn height(&self) -> f32

Source

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.

Source

pub fn primary_font(&self) -> Option<(&Font, f32)>

Primary face and size even when the paragraph contains no glyphs.

Source

pub fn bounds(&self) -> Rect

Source

pub fn truncated(&self) -> bool

max_lines dropped content (what an ellipsis marks).

Source

pub fn min_intrinsic_width(&self) -> f32

Widest unbreakable segment — the narrowest useful layout width.

Source

pub fn max_intrinsic_width(&self) -> f32

Width when nothing wraps (widest hard-break line).

Source

pub fn longest_line(&self) -> f32

Widest laid-out line’s content width.

Source§

impl Paragraph

Source

pub fn text(&self) -> &str

Source

pub fn demand(&self) -> &FontDemand

What this paragraph could not resolve (families and codepoints no source answered) — a host fetches them and re-registers.

Source

pub fn faces(&self) -> &FaceSet

The faces this paragraph resolved (decoration metrics, glyph lookup at record time).

Source

pub fn line_metrics(&self) -> Vec<LineMetrics>

Source

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.

Source

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.

Source

pub fn rects_for_range(&self, range: Range<usize>) -> Vec<Rect>

Selection boxes for a byte range: one rect per (line, run) span — bidi ranges yield multiple boxes naturally, like SkParagraph’s getRectsForRange.

Source

pub fn word_boundary(&self, offset: usize) -> Range<usize>

The word containing offset (UAX #29 word boundaries).

Trait Implementations§

Source§

impl Clone for Paragraph

Source§

fn clone(&self) -> Paragraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.