Blendend.Text.GlyphBuffer (blendend v0.3.0)

View Source

A glyph buffer holds input text (UTF-8) and, after shaping, the glyph IDs / clusters / positions produced by a font.

We normally don't draw directly from a GlyphBuffer; we turn it into a GlyphRun first.

Summary

Functions

Allocates an empty glyph buffer.

Same as new/0, but returns the glyph buffer directly.

Sets the UTF-8 text of the glyph buffer.

Same as set_utf8_text/2, but returns the glyph buffer directly.

Types

t()

@opaque t()

Functions

new()

@spec new() :: {:ok, t()} | {:error, term()}

Allocates an empty glyph buffer.

On success, returns {:ok, gb}, where gb is an opaque glyph-buffer resource.

On failure, returns {:error, reason}.

new!()

@spec new!() :: t()

Same as new/0, but returns the glyph buffer directly.

On success, returns the buffer.

On failure, raises Blendend.Error.

set_utf8_text(gb, text)

@spec set_utf8_text(t(), String.t()) :: :ok | {:error, term()}

Sets the UTF-8 text of the glyph buffer.

This only stores the text; it does not perform shaping. To shape the buffer we need to call Blendend.Text.Font.shape/2.

On success, returns :ok.

On failure, returns {:error, reason} (for example if the buffer is invalid or the text cannot be stored).

set_utf8_text!(gb, text)

@spec set_utf8_text!(t(), String.t()) :: t()

Same as set_utf8_text/2, but returns the glyph buffer directly.

On success, returns the same gb.

On failure, raises Blendend.Error.

Examples:

gb =
  GlyphBuffer.new!()
  |> GlyphBuffer.set_utf8_text!("Hello")
  |> Font.shape!(font)