# TextFormatter

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

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

```rust
trait TextFormatter: 'static
```

Represents a base class for text formatting.

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

## Members

- [`format_line`](#function-format_line)
- [`format_line_with_cache`](#function-format_line_with_cache)

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

### format_line

```rust
fn format_line(self: &Self, text_source: &dyn ITextSource, first_text_source_index: i32, paragraph_width: f64, paragraph_properties: &Rc<dyn TextParagraphProperties>, previous_line_break: Option<&Rc<TextLineBreak>>) -> Option<Rc<dyn TextLine>>
```

Formats a text line.

* `text_source` — the text source.
* `first_text_source_index` — the first character index to start the text line from.
* `paragraph_width` — a value that specifies the width of the paragraph that the line fills.
* `paragraph_properties` — properties that control paragraph features such as text
  flow direction, text alignment, or indentation.
* `previous_line_break` — the state of the previous line break.

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

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

### format_line_with_cache

```rust
fn format_line_with_cache(self: &Self, text_source: &dyn ITextSource, first_text_source_index: i32, paragraph_width: f64, paragraph_properties: &Rc<dyn TextParagraphProperties>, previous_line_break: Option<&Rc<TextLineBreak>>, text_run_cache: Option<&TextRunCache>) -> Option<Rc<dyn TextLine>>
```

Formats a text line, optionally using a `TextRunCache` to avoid redundant shaping.

When a cache is provided, shaped runs from a previous call with the same
`first_text_source_index` are reused, skipping shaping and bidi processing.
This is useful when formatting the same text at different paragraph widths.

* `text_source` — the text source.
* `first_text_source_index` — the first character index to start the text line from.
* `paragraph_width` — a value that specifies the width of the paragraph that the line fills.
* `paragraph_properties` — properties that control paragraph features such as text
  flow direction, text alignment, or indentation.
* `previous_line_break` — the state of the previous line break.
* `text_run_cache` — an optional cache for shaped text runs.

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

## Trait implementations

- [`TextFormatter`](/docs/0.5.0/api/ferroui-base/media/text_formatting/trait-textformatter/)

## Availability

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