Blendend.Text.Face (blendend v0.2.0)

View Source

A face represents a loaded font family from a TTF/OTF file. Typical workflow looks like:

  • load a face from disk,

  • create a Blendend.Text.Font from it for actual drawing.

  • inspect its metadata / metrics / coverage. Example:

    alias Blendend.Text.{Face, Font}

    face = Face.load!("priv/fonts/Alegreya-Regular.otf") info = Face.info!(face) names = Face.names!(face)

    font = Font.create!(face, 48.0)

Summary

Functions

Returns design-space metrics for the face.

Same as design_metrics/1, but returns the metrics map directly.

Returns the list of OpenType feature tags supported by this face.

Same as feature_tags/1, but returns the tag list directly.

Loads a font face from path.

Same as load/1, but raises on failure.

Types

t()

@opaque t()

Functions

design_metrics(face)

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

Returns design-space metrics for the face.

On success, returns {:ok, map}.

On failure, returns {:error, reason}.

Examples:

alias Blendend.Text.Face
{:ok, face}  = Face.load("priv/fonts/Alegreya-Regular.otf")
Face.design_metrics!(face)
> %{
  "ascent" => 1016,
  "cap_height" => 637,
  "descent" => 345,
  "h_min_lsb" => -395,
  "h_min_tsb" => -214,
  "line_gap" => 0,
  "units_per_em" => 1000,
  "v_ascent" => 1016,
  "v_descent" => 345,
  "x_height" => 452
  }

design_metrics!(face)

@spec design_metrics!(t()) :: map()

Same as design_metrics/1, but returns the metrics map directly.

On success, returns map.

On failure, raises Blendend.Error.

feature_tags(face)

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

Returns the list of OpenType feature tags supported by this face.

Each tag is a 4-character string (e.g. "kern", "liga").

On success, returns {:ok, tags}.

On failure, returns {:error, reason}.

feature_tags!(face)

@spec feature_tags!(t()) :: list()

Same as feature_tags/1, but returns the tag list directly.

On success, returns tags.

On failure, raises Blendend.Error.

Examples:

face = Face.load!("priv/fonts/Alegreya-Regular.otf") Face.feature_tags!(face) ["tnum", "sups", "subs", ...]

load(path)

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

Loads a font face from path.

On success, returns {:ok, face}, where face is an opaque NIF resource.

On failure, returns {:error, reason}.

load!(path)

@spec load!(binary()) :: t()

Same as load/1, but raises on failure.

On success, returns the face.

On failure, raises Blendend.Error.