HarfbuzzEx (harfbuzz_ex v1.2.0)

Copy Markdown View Source

Elixir wrapper for Rust rustybuzz crate for OpenType shaping.

If I/O and memory are not concerns (the font file is small, or the task infrequent), use get/3 to access data from the shaped glyphs directly. This creates a shaper on a one-off basis.

If the font file-size is large and shaping is done frequently, explicitly use the new/1 to load the font into memory. Shaping with shape/2 is then CPU bound. Use stop/1 to release the memory.

Summary

Functions

Generates the child spec, automatically using the :name as the :id

Input a string, shape with the font, and return a list of shaped glyphs.

Starts a new Rust instance for the given font.

Same as new/2 but raises on error.

Shapes text using the given Shaper process, returning the full set of shaped instructions as a map of

Same as shape!/3 but returns an :ok tuple.

Same as shape/2 but raises on error.

Shapes text using the given Shaper process, returning only the requested parameter as a list. This is most useful for extracting a list of glyphnames by invoking shape!(pid, text, :name).

Starts a GenServer to hold the Rust instance. Accepts a keyword list of options for configuration

Stops the Shaper process. This drops the reference to the Rust resource, allowing the BEAM to garbage collect the memory (font data + parsed tables).

Functions

child_spec(init_arg)

Generates the child spec, automatically using the :name as the :id

get(font_path, string, data \\ :name)

get!(font_path, string, data \\ :name)

Input a string, shape with the font, and return a list of shaped glyphs.

Use :all for a list of %HarfbuzzEx.Glyph{} structs, or one of :name, :x_advance, :y_advance, :x_offset, :y_offset for a list of string (:name) or integers.

new(font_path, opts \\ [])

Starts a new Rust instance for the given font.

Returns {:ok, pid} on success.

new!(font_path, opts \\ [])

Same as new/2 but raises on error.

shape(server, text)

Shapes text using the given Shaper process, returning the full set of shaped instructions as a map of:

  • :name (glyph name)
  • :x_advance
  • :y_advance
  • :x_offset
  • :y_offset

shape(server, text, data)

Same as shape!/3 but returns an :ok tuple.

shape!(server, text)

Same as shape/2 but raises on error.

shape!(server, text, data)

Shapes text using the given Shaper process, returning only the requested parameter as a list. This is most useful for extracting a list of glyphnames by invoking shape!(pid, text, :name).

start_link(opts)

Starts a GenServer to hold the Rust instance. Accepts a keyword list of options for configuration:

  • :font_path: path to the font file (typically priv/fonts/your_font_file.ttf)
  • :name: the registered name for the GenServer

stop(server)

Stops the Shaper process. This drops the reference to the Rust resource, allowing the BEAM to garbage collect the memory (font data + parsed tables).