Elixir Font Discovery
Elixir Font Discovery resolves installed fonts through the host operating system and returns standalone OpenType or TrueType font bytes.
- Linux uses Fontconfig.
- macOS uses CoreText.
- Windows uses DirectWrite.
- Published releases use verified precompiled NIFs. Applications that depend on the library do not need Rust or a native compiler.
Installation
Add elixir_font_discovery to your dependencies:
def deps do
[
{:elixir_font_discovery, "~> 0.2.0"}
]
end
Usage
Resolve the operating system's regular sans-serif face:
{:ok, font} = ElixirFontDiscovery.resolve("sans-serif")
font.family
font.weight
font.style
font.data
Request the closest installed bold italic face:
{:ok, font} = ElixirFontDiscovery.resolve("Inter", 700, :italic)
Named families return {:error, :not_found} when the operating system cannot
resolve them. Generic names supported by the library are sans-serif,
system-ui, serif, and monospace.
Platform service, font loading, file access, and malformed installed-font
failures return {:error, :unavailable} rather than reporting the family as
missing.
system-ui tries platform user-interface families before the generic
sans-serif fallback. This includes Segoe UI on Windows, Apple system families
such as Helvetica Neue on macOS, and the standard Fontconfig UI candidates on
Linux.
The returned data always describes a static font face. Variable OpenType fonts
return {:error, :unsupported_font} because copying their underlying file does
not apply the variation coordinates selected by the operating system.
Developing the native adapter
Library users do not need Rust. Maintainers working on the native adapter can force a local source build:
mise install
ELIXIR_FONT_DISCOVERY_BUILD=true mix deps.get
ELIXIR_FONT_DISCOVERY_BUILD=true mix test
The Rust crate requires Rust 1.77 or newer. Linux source builds also require Fontconfig and FreeType development headers.
cargo test --manifest-path native/elixir_font_discovery/Cargo.toml
cargo fmt --manifest-path native/elixir_font_discovery/Cargo.toml -- --check
cargo clippy --manifest-path native/elixir_font_discovery/Cargo.toml --all-targets -- -D warnings
Releasing
Update the version in
mix.exs, the Rust crate, andCHANGELOG.md.Commit and push the release.
Tag it as
vVERSIONand push the tag.Wait for the precompiled-NIF workflow to attach every target to the GitHub release.
Generate the checksum manifest:
mix rustler_precompiled.download ElixirFontDiscovery.Native --all --printCommit
checksum-Elixir.ElixirFontDiscovery.Native.exs.Confirm the package contents with
mix hex.build --unpack.Publish to Hex with
mix hex.publish.
Licence
Elixir Font Discovery is released under the MIT License.