Blendend.Text (blendend v0.3.3)

Copy Markdown View Source

High-level text helpers for Blendend.

This module is surface over the lower-level text modules:

For the most direct "just draw this UTF-8 text" call, see Blendend.Canvas.Fill.utf8_text/6 and Blendend.Canvas.Stroke.utf8_text/6.

Summary

Functions

Computes text metrics for the given text and font.

Shapes text with the given font and returns a GlyphRun.

Types

face()

@opaque face()

font()

@opaque font()

glyph_run()

@opaque glyph_run()

Functions

metrics(font, text)

@spec metrics(font(), String.t()) :: {:ok, map()} | {:error, term()}

Computes text metrics for the given text and font.

Internally this uses a glyph buffer and Font.get_text_metrics/2.

Examples

 iex>Blendend.Text.metrics(font, "blendend")
    {:ok,
       %{
         "advance_x" => 183.264,
         "advance_y" => -0.0,
         "bbox_x0" => 1.104,
         "bbox_x1" => 183.264,
         "bbox_y0" => -0.0,
         "bbox_y1" => -0.0
        }}

shape(font, text)

@spec shape(font(), String.t()) :: glyph_run() | {:error, term()}

Shapes text with the given font and returns a GlyphRun.

Internally this:

  • allocates a GlyphBuffer
  • sets its UTF-8 text
  • calls the underlying shaping engine via Font.shape/2
  • returns the resulting GlyphRun

Use this when you want to inspect or reuse the shaped glyphs.

On success, returns a GlyphRun.

On failure, returns {:error, reason}.

Examples

gr = Blendend.Text.shape(font, "blendend!")
Blendend.Text.GlyphRun.fill!(canvas, font, 60, 245, gr, fill: rgb(60, 60, 60))