MingaEditor.UI.FontRegistry (Minga v0.1.0)

Copy Markdown View Source

Maps font family names to protocol font IDs (0-255).

Font ID 0 is always the primary font (configured via :font_family). IDs 1-255 are assigned on demand when a Face with a non-nil font_family is first rendered. The Emit stage sends register_font protocol commands for pending registrations so the GUI frontend can load the corresponding FontFace instances.

The registry is process-local state owned by MingaEditor.Renderer.Server. Render snapshots receive the current registry just before the pipeline runs, and the renderer stores the updated registry after emit. It resets when the renderer restarts or the font config changes.

Summary

Functions

Returns the render-local font registry, or the supplied fallback.

Returns the font_id for a font family, allocating a new ID if needed.

Returns the font_id for a family, or 0 if not registered.

Marks all pending font registrations as emitted.

Creates a new empty font registry.

Returns font registrations that have been allocated but not emitted yet.

Returns the active render-local font registry, if one is installed.

Stores the render-local font registry.

Runs a function with this registry installed for render-local font resolution.

Types

t()

@type t() :: %MingaEditor.UI.FontRegistry{
  families: %{required(String.t()) => non_neg_integer()},
  next_id: non_neg_integer(),
  pending: %{required(non_neg_integer()) => String.t()}
}

Functions

current_process_registry(fallback)

@spec current_process_registry(t()) :: t()

Returns the render-local font registry, or the supplied fallback.

get_or_register(reg, family)

@spec get_or_register(t(), String.t()) :: {non_neg_integer(), t(), boolean()}

Returns the font_id for a font family, allocating a new ID if needed.

Returns {font_id, updated_registry, new?} where new? is true if a new ID was allocated (caller should send register_font to the GUI).

The primary font (ID 0) is never registered here; it's set via set_font.

lookup(font_registry, family)

@spec lookup(t(), String.t()) :: non_neg_integer()

Returns the font_id for a family, or 0 if not registered.

mark_registered(registry)

@spec mark_registered(t()) :: t()

Marks all pending font registrations as emitted.

new()

@spec new() :: t()

Creates a new empty font registry.

pending_registrations(font_registry)

@spec pending_registrations(t()) :: [{non_neg_integer(), String.t()}]

Returns font registrations that have been allocated but not emitted yet.

process_registry()

@spec process_registry() :: t() | nil

Returns the active render-local font registry, if one is installed.

put_process_registry(registry)

@spec put_process_registry(t()) :: t()

Stores the render-local font registry.

with_process_registry(font_registry, fun)

@spec with_process_registry(t(), (-> result)) :: result when result: term()

Runs a function with this registry installed for render-local font resolution.