ElixirFontDiscovery (elixir_font_discovery v0.1.0)

Copy Markdown View Source

Resolves installed font families through the host operating system.

Linux uses Fontconfig, macOS uses CoreText, and Windows uses DirectWrite. Published releases download a verified precompiled native library, so callers do not need Rust or a native compiler.

Summary

Types

An installed font face and its standalone OpenType or TrueType bytes.

Why an installed font could not be returned.

A style requested from or reported by the operating system.

Functions

Resolves an installed regular face for family at CSS weight 400.

Resolves the closest installed face for a family, CSS weight, and style.

Types

font()

@type font() :: %{family: String.t(), weight: float(), style: style(), data: binary()}

An installed font face and its standalone OpenType or TrueType bytes.

reason()

@type reason() ::
  :invalid_family | :invalid_weight | :invalid_style | :not_found | :unavailable

Why an installed font could not be returned.

style()

@type style() :: :normal | :italic | :oblique

A style requested from or reported by the operating system.

Functions

resolve(family)

@spec resolve(String.t()) :: {:ok, font()} | {:error, reason()}

Resolves an installed regular face for family at CSS weight 400.

Generic families such as sans-serif, serif, and monospace are resolved by the operating system.

resolve(family, weight, style)

@spec resolve(String.t(), number(), style()) :: {:ok, font()} | {:error, reason()}

Resolves the closest installed face for a family, CSS weight, and style.

weight must be between 1 and 1000. The accepted styles are :normal, :italic, and :oblique. The returned family, weight, and style describe the face selected by the operating system, which can differ from the request.