# ShapedBuffer

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

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

```rust
struct ShapedBuffer
```

A buffer of shaped glyphs: the output of the text shaper for one run.

Buffers produced by `ShapedBuffer::split` and
`ShapedBuffer::with_bidi_level` share the glyph storage of their source.

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

## Members

- [`new`](#function-new)
- [`UNSAFE_TO_BREAK`](#assoc_const-unsafe_to_break)
- [`UNSAFE_TO_CONCAT`](#assoc_const-unsafe_to_concat)
- [`set_concat_flags`](#function-set_concat_flags)
- [`concat_flags`](#function-concat_flags)
- [`length`](#function-length)
- [`glyph_infos`](#function-glyph_infos)
- [`glyph_indices`](#function-glyph_indices)
- [`glyph_typeface`](#function-glyph_typeface)
- [`font_rendering_em_size`](#function-font_rendering_em_size)
- [`bidi_level`](#function-bidi_level)
- [`is_left_to_right`](#function-is_left_to_right)
- [`text`](#function-text)
- [`dispose`](#function-dispose)
- [`get`](#function-get)
- [`set`](#function-set)
- [`is_cluster_cache_simple`](#function-is_cluster_cache_simple)
- [`total_glyph_advance`](#function-total_glyph_advance)
- [`first_cluster_char_length`](#function-first_cluster_char_length)
- [`cluster_prefix`](#function-cluster_prefix)
- [`with_bidi_level`](#function-with_bidi_level)
- [`split`](#function-split)
- [`get_char_range_width`](#function-get_char_range_width)
- [`find_leading_char_count_within_width`](#function-find_leading_char_count_within_width)
- [`find_trailing_char_count_within_width`](#function-find_trailing_char_count_within_width)

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

### new

```rust
fn new(text: ReadOnlyMemory<u16>, buffer_length: usize, glyph_typeface: Rc<GlyphTypeface>, font_rendering_em_size: f64, bidi_level: i8) -> Rc<Self>
```

Creates a buffer with room for `buffer_length` glyphs; the shaper fills
it with `ShapedBuffer::set`.

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

<a id="assoc_const-unsafe_to_break"></a>

### UNSAFE_TO_BREAK

```rust
const UNSAFE_TO_BREAK: u8
```

The flag of a glyph whose cluster the text may not be cut at, with the two sides shaped
apart (HarfBuzz's `HB_GLYPH_FLAG_UNSAFE_TO_BREAK`).

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

<a id="assoc_const-unsafe_to_concat"></a>

### UNSAFE_TO_CONCAT

```rust
const UNSAFE_TO_CONCAT: u8
```

The flag of a glyph at whose cluster the text may not be changed on one side without
changing the shaping of the other (HarfBuzz's `HB_GLYPH_FLAG_UNSAFE_TO_CONCAT`).

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

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

### set_concat_flags

```rust
fn set_concat_flags(self: &Self, flags: Rc<[u8]>)
```

Records the concatenation flags of the glyphs, one byte a glyph (`Self::UNSAFE_TO_BREAK`,
`Self::UNSAFE_TO_CONCAT`): a shaper that was asked for them
(`TextShaperOptions::produce_concat_flags`) sets them once it filled the buffer.

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

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

### concat_flags

```rust
fn concat_flags(self: &Self) -> Option<Rc<[u8]>>
```

The concatenation flags of the glyphs, when the shaper recorded them.

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

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

### length

```rust
fn length(self: &Self) -> usize
```



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

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

### glyph_infos

```rust
fn glyph_infos(self: &Self) -> Ref<'_, [GlyphInfo]>
```

Borrows the glyphs. Do not hold the borrow across a call to `ShapedBuffer::set`.

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

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

### glyph_indices

```rust
fn glyph_indices(self: &Self) -> Ref<'_, [u16]>
```

The glyph ids of the buffer in glyph order — a contiguous view that
mirrors `glyph_infos()[i].glyph_index`, kept in sync by the setter.

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

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

### glyph_typeface

```rust
fn glyph_typeface(self: &Self) -> &Rc<GlyphTypeface>
```

The buffer's glyph typeface.

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

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

### font_rendering_em_size

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

The buffer's font rendering em size.

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

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

### bidi_level

```rust
fn bidi_level(self: &Self) -> i8
```

The buffer's bidi level.

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

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

### is_left_to_right

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

The buffer's reading direction.

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

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

### text

```rust
fn text(self: &Self) -> &ReadOnlyMemory<u16>
```

The text that is represented by this buffer.

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

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

### dispose

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

Releases the buffer. Idempotent. Afterwards the buffer has no glyphs
(`length()` is zero); the glyph storage itself is freed when the last
buffer sharing it is dropped.

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

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

### get

```rust
fn get(self: &Self, index: usize) -> GlyphInfo
```

Reads the glyph at `index`.

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

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

### set

```rust
fn set(self: &Self, index: usize, value: GlyphInfo)
```

Writes the glyph at `index`.

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

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

### is_cluster_cache_simple

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

True when the cluster cache is in "simple" mode (every cluster is one
character wide).

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

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

### total_glyph_advance

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

Sum of all glyph advances in this buffer (cached).

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

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

### first_cluster_char_length

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

Number of text characters covered by this buffer's first cluster, in
logical order. Zero for an empty buffer.

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

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

### cluster_prefix

```rust
fn cluster_prefix(self: &Self) -> Option<Rc<[f64]>>
```

The shared prefix sum array of the cluster cache, when built.

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

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

### with_bidi_level

```rust
fn with_bidi_level(self: &Rc<Self>, paragraph_embedding_level: i8) -> Rc<ShapedBuffer>
```

An alias of this buffer with a different bidi level, sharing the glyph
storage and (when built) the cluster cache.

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

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

### split

```rust
fn split(self: &Rc<Self>, text_length: i32) -> SplitResult<Rc<ShapedBuffer>>
```

Splits the buffer at the specified text length (UTF-16 code units).

Both halves share this buffer's glyph storage and cluster cache.

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

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

### get_char_range_width

```rust
fn get_char_range_width(self: &Self, start_char: i32, end_char: i32) -> f64
```

Sum of cluster advances over the half-open character range
`[start_char, end_char)` relative to this buffer's text. Snaps both
boundaries down to the largest cluster start at or before the given
character offset.

Internal upstream; public so that the Skia unit tests reach it.

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

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

### find_leading_char_count_within_width

```rust
fn find_leading_char_count_within_width(self: &Self, available_width: f64) -> i32
```

The largest count of leading characters (in logical order) whose
cumulative cluster advance fits within `available_width`, or 0 if not
even the first cluster fits.

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

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

### find_trailing_char_count_within_width

```rust
fn find_trailing_char_count_within_width(self: &Self, available_width: f64) -> (i32, f64)
```

The largest count of trailing characters (in logical order) whose
cumulative cluster advance fits within `available_width`, together with
the consumed width. `(0, 0.0)` if not even the last cluster fits.

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

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