# TextLayout

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/text_formatting/struct-textlayout/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct TextLayout
```

Represents a multi line text layout.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L75)

## Members

- [`new`](#function-new)
- [`new_with_paragraph_styles`](#function-new_with_paragraph_styles)
- [`from_utf16`](#function-from_utf16)
- [`from_utf16_with_paragraph_styles`](#function-from_utf16_with_paragraph_styles)
- [`from_text_source`](#function-from_text_source)
- [`from_text_source_with_paragraph_styles`](#function-from_text_source_with_paragraph_styles)
- [`shared_plain`](#function-shared_plain)
- [`is_shared`](#function-is_shared)
- [`line_height`](#function-line_height)
- [`max_width`](#function-max_width)
- [`max_height`](#function-max_height)
- [`max_lines`](#function-max_lines)
- [`letter_spacing`](#function-letter_spacing)
- [`text_lines`](#function-text_lines)
- [`line_origin`](#function-line_origin)
- [`line_flow_direction`](#function-line_flow_direction)
- [`height`](#function-height)
- [`extent`](#function-extent)
- [`baseline`](#function-baseline)
- [`overhang_after`](#function-overhang_after)
- [`overhang_leading`](#function-overhang_leading)
- [`overhang_trailing`](#function-overhang_trailing)
- [`width`](#function-width)
- [`width_including_trailing_whitespace`](#function-width_including_trailing_whitespace)
- [`width_hold`](#function-width_hold)
- [`is_truncated_by_height`](#function-is_truncated_by_height)
- [`is_truncated_by_max_lines`](#function-is_truncated_by_max_lines)
- [`has_collapsed_lines`](#function-has_collapsed_lines)
- [`holds_width`](#function-holds_width)
- [`draw`](#function-draw)
- [`build_geometry`](#function-build_geometry)
- [`try_build_geometry`](#function-try_build_geometry)
- [`hit_test_text_position`](#function-hit_test_text_position)
- [`hit_test_text_range`](#function-hit_test_text_range)
- [`hit_test_point`](#function-hit_test_point)
- [`get_line_index_from_character_index`](#function-get_line_index_from_character_index)
- [`dispose`](#function-dispose)

<a id="function-new"></a>

### new

```rust
fn new(text: &str, typeface: Typeface, options: TextLayoutOptions) -> Self
```

Initializes a new instance of the `TextLayout` class.

* `text` — the text.
* `typeface` — the typeface.
* `options` — the remaining (optional) parameters.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L115)

<a id="function-new_with_paragraph_styles"></a>

### new_with_paragraph_styles

```rust
fn new_with_paragraph_styles(text: &str, typeface: Typeface, options: TextLayoutOptions, styles: Option<TextParagraphStyles>) -> Self
```

Formats independent paragraphs without changing the existing options or
constructor contract. Style ranges use UTF-16 positions, including a
paragraph's terminator. Caret, range geometry and drawing share the same
line origins, including first-line indentation and paragraph spacing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L123)

<a id="function-from_utf16"></a>

### from_utf16

```rust
fn from_utf16(text: ReadOnlyMemory<u16>, typeface: Typeface, options: TextLayoutOptions) -> Self
```

Initializes a new instance of the `TextLayout` class from UTF-16 text
(no transcoding).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L131)

<a id="function-from_utf16_with_paragraph_styles"></a>

### from_utf16_with_paragraph_styles

```rust
fn from_utf16_with_paragraph_styles(text: ReadOnlyMemory<u16>, typeface: Typeface, options: TextLayoutOptions, styles: Option<TextParagraphStyles>) -> Self
```

UTF-16 variant of `Self::new_with_paragraph_styles`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L136)

<a id="function-from_text_source"></a>

### from_text_source

```rust
fn from_text_source(text_source: Rc<dyn ITextSource>, paragraph_properties: Rc<dyn TextParagraphProperties>, text_trimming: Option<Rc<dyn TextTrimming>>, max_width: f64, max_height: f64, max_lines: i32, text_run_cache: Option<Rc<TextRunCache>>) -> Self
```

Initializes a new instance of the `TextLayout` class.

* `text_source` — the text source.
* `paragraph_properties` — the default text paragraph properties.
* `text_trimming` — the text trimming (upstream default: `None`).
* `max_width` — the maximum width (upstream default: positive infinity).
* `max_height` — the maximum height (upstream default: positive infinity).
* `max_lines` — the maximum number of text lines (upstream default: 0).
* `text_run_cache` — an optional cache for shaped text runs to avoid redundant shaping.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L180)

<a id="function-from_text_source_with_paragraph_styles"></a>

### from_text_source_with_paragraph_styles

```rust
fn from_text_source_with_paragraph_styles(text_source: Rc<dyn ITextSource>, paragraph_properties: Rc<dyn TextParagraphProperties>, text_trimming: Option<Rc<dyn TextTrimming>>, max_width: f64, max_height: f64, max_lines: i32, text_run_cache: Option<Rc<TextRunCache>>, paragraph_styles: Option<TextParagraphStyles>) -> Self
```

Formats a custom text source with paragraph overrides. A style is chosen
at each required line break, never at a soft wrap.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L196)

<a id="function-shared_plain"></a>

### shared_plain

```rust
fn shared_plain(text: &str, text_source: impl FnOnce() -> Rc<dyn ITextSource>, paragraph_properties: &Rc<dyn TextParagraphProperties>, text_trimming: &Rc<dyn TextTrimming>, max_width: f64, max_height: f64, max_lines: i32, text_run_cache: Option<Rc<TextRunCache>>) -> Rc<Self>
```

The layout of the plain text `text`: one run of the default run properties of
`paragraph_properties`. A text that was laid out before with the same properties,
trimming and constraint gets the layout that was made then, which every asker holds
(a FerroUI addition, docs/porting/desktop-performance.md, section 9.29).

`text_source` is asked for the source when the layout has to be made; it gives exactly
`text` in runs of the default run properties. `text_run_cache` is used while the layout
is made.

The font manager of the thread keeps the layout, so `dispose` leaves
it alone (`is_shared`). A long text, a text with decorations or font
features and a paragraph with tab stops get a layout of their own, as
`from_text_source` makes it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L243)

<a id="function-is_shared"></a>

### is_shared

```rust
fn is_shared(self: &Self) -> bool
```

Whether the font manager keeps this layout for the next use of its text
(`shared_plain`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L284)

<a id="function-line_height"></a>

### line_height

```rust
fn line_height(self: &Self) -> f64
```

Gets the height of each line of text.

A value of NaN (equivalent to an attribute value of "Auto") indicates
that the line height is determined automatically from the current font
characteristics. The default is NaN.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L308)

<a id="function-max_width"></a>

### max_width

```rust
fn max_width(self: &Self) -> f64
```

Gets the maximum width.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L313)

<a id="function-max_height"></a>

### max_height

```rust
fn max_height(self: &Self) -> f64
```

Gets the maximum height.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L318)

<a id="function-max_lines"></a>

### max_lines

```rust
fn max_lines(self: &Self) -> i32
```

Gets the maximum number of text lines.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L323)

<a id="function-letter_spacing"></a>

### letter_spacing

```rust
fn letter_spacing(self: &Self) -> f64
```

Gets the text spacing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L328)

<a id="function-text_lines"></a>

### text_lines

```rust
fn text_lines(self: &Self) -> &[Rc<dyn TextLine>]
```

Gets the text lines.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L333)

<a id="function-line_origin"></a>

### line_origin

```rust
fn line_origin(self: &Self, index: usize) -> Point
```

The actual line origin used for drawing, hit testing and native carets.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L338)

<a id="function-line_flow_direction"></a>

### line_flow_direction

```rust
fn line_flow_direction(self: &Self, index: usize) -> FlowDirection
```

The base flow direction of the paragraph containing this line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L343)

<a id="function-height"></a>

### height

```rust
fn height(self: &Self) -> f64
```

The distance from the top of the first line to the bottom of the last line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L349)

<a id="function-extent"></a>

### extent

```rust
fn extent(self: &Self) -> f64
```

The distance from the topmost black pixel of the first line to the
bottommost black pixel of the last line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L355)

<a id="function-baseline"></a>

### baseline

```rust
fn baseline(self: &Self) -> f64
```

The distance from the top of the first line to the baseline of the first line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L360)

<a id="function-overhang_after"></a>

### overhang_after

```rust
fn overhang_after(self: &Self) -> f64
```

The distance from the bottom of the last line to the extent bottom.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L365)

<a id="function-overhang_leading"></a>

### overhang_leading

```rust
fn overhang_leading(self: &Self) -> f64
```

The maximum distance from the leading black pixel to the leading alignment point of a line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L370)

<a id="function-overhang_trailing"></a>

### overhang_trailing

```rust
fn overhang_trailing(self: &Self) -> f64
```

The maximum distance from the trailing black pixel to the trailing alignment point of a line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L375)

<a id="function-width"></a>

### width

```rust
fn width(self: &Self) -> f64
```

The maximum advance width between the leading and trailing alignment
points of a line, excluding the width of whitespace characters at the
end of the line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L382)

<a id="function-width_including_trailing_whitespace"></a>

### width_including_trailing_whitespace

```rust
fn width_including_trailing_whitespace(self: &Self) -> f64
```

The maximum advance width between the leading and trailing alignment
points of a line, including the width of whitespace characters at the
end of the line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L389)

<a id="function-width_hold"></a>

### width_hold

```rust
fn width_hold(self: &Self) -> Option<(f64, f64)>
```

The range of maximum widths `[low, high)` over which a layout of the same text with the
same properties makes the same lines as this one, or `None` when it is not known (the
layout is then only known to hold at its own maximum width). An addition (FerroUI
deviation, desktop-performance.md section 9.12): a text block keeps its layout for any
width inside the range.

Wrapping is greedy: a line ends at the last break opportunity whose text (without the
white space after it) fits the width. The lines stay the same while every line still fits,
from the width of the widest line without its trailing white space (with it for the last
line and a line that ends at a required break, which have no break after it), and while no line
can take the first word of the next one, up to the width of a line with its trailing white
space and that word. The range is known for left-to-right text that wraps without
letter spacing, tabs or paragraph styles, and that left no line out for the maximum
height (the same lines have the same height) or the line limit, whose lines are one
shaped run each and end at break opportunities (no line was broken inside a word).
Trimming and a line limit that changed nothing do not narrow it (section 9.27): a line is
trimmed only when it does not fit the width or when lines after it are left out, and
inside the range every line fits and the lines, so their count, are the same.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L411)

<a id="function-is_truncated_by_height"></a>

### is_truncated_by_height

```rust
fn is_truncated_by_height(self: &Self) -> bool
```

Whether lines of the text were left out because they did not fit the maximum height. An
addition: a layout that left nothing out has the lines a layout with a larger maximum
height has (desktop-performance.md section 9.12).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L423)

<a id="function-is_truncated_by_max_lines"></a>

### is_truncated_by_max_lines

```rust
fn is_truncated_by_max_lines(self: &Self) -> bool
```

Whether lines with text were left out because of the line limit. An addition: a layout
that left nothing out is the layout without a line limit (desktop-performance.md section
9.27).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L430)

<a id="function-has_collapsed_lines"></a>

### has_collapsed_lines

```rust
fn has_collapsed_lines(self: &Self) -> bool
```

Whether a line was collapsed: trimmed because it did not fit the width, or because lines
after it were left out. An addition: a layout without one is the layout without trimming
(desktop-performance.md section 9.27).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L437)

<a id="function-holds_width"></a>

### holds_width

```rust
fn holds_width(self: &Self, width: f64) -> bool
```

Whether `width` is inside `TextLayout::width_hold`. Stops at the first line that shows
it is not, without computing the whole hold.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L443)

<a id="function-draw"></a>

### draw

```rust
fn draw(self: &Self, context: &mut dyn ITextDrawingSink, origin: Point)
```

Draws the text layout.

* `context` — the drawing context.
* `origin` — the origin.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L560)

<a id="function-build_geometry"></a>

### build_geometry

```rust
fn build_geometry(self: &Self, origin: Point) -> crate::Ref<crate::media::Geometry>
```

Obtains the scalable contours of this already shaped layout at `origin`.

The geometry follows the same line positions, bidi ordering, style runs,
letter spacing and decoration strokes as `Self::draw`, without shaping
or measuring the text again. An empty layout produces an empty geometry.
Glyph paints are not retained; callers can fill or stroke the returned
geometry. Bitmap-only glyphs contribute no contours, and colour glyphs
contribute only outlines exposed by the platform glyph-run contract.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L579)

<a id="function-try_build_geometry"></a>

### try_build_geometry

```rust
fn try_build_geometry(self: &Self, origin: Point) -> Option<crate::Ref<crate::media::Geometry>>
```

Obtains all contours at `origin` without accepting a partial glyph
outline. Positions and decorations are the same as `build_geometry`.

Returns `None` when the platform cannot verify completeness or any run
contains bitmap or colour-font glyphs. Glyph paints are not represented
by geometry; callers must preserve or validate those separately before
replacing text with a path. An empty layout succeeds with empty geometry.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L592)

<a id="function-hit_test_text_position"></a>

### hit_test_text_position

```rust
fn hit_test_text_position(self: &Self, text_position: i32) -> Rect
```

Get the pixel location relative to the top-left of the layout box given the text position.

* `text_position` — the text position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L601)

<a id="function-hit_test_text_range"></a>

### hit_test_text_range

```rust
fn hit_test_text_range(self: &Self, start: i32, length: i32) -> Vec<Rect>
```

Gets the bounding rectangles of a range of text, relative to the
top-left of the layout box.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L634)

<a id="function-hit_test_point"></a>

### hit_test_point

```rust
fn hit_test_point(self: &Self, point: Point) -> TextHitTestResult
```

Gets the character hit of a point relative to the top-left of the layout box.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L682)

<a id="function-get_line_index_from_character_index"></a>

### get_line_index_from_character_index

```rust
fn get_line_index_from_character_index(self: &Self, char_index: i32, trailing_edge: bool) -> i32
```

Gets the index of the line that contains a character index.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L697)

<a id="function-dispose"></a>

### dispose

```rust
fn dispose(self: &Self)
```

Releases the text lines. A layout its font manager keeps
(`is_shared`) is released by the font manager, when nothing holds it
any more.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/text_layout.rs#L1033)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
