Custom/brand font loading for measurement and rasterization.
Configure font sources once:
config :open_fresco,
font_dirs: ["/app/priv/fonts"],
font_files: ["/app/priv/fonts/Inter-Bold.ttf"],
skip_system_fonts: falseor per call via the :font_dirs / :font_files / :skip_system_fonts
options on OpenFresco.render/3 (per-call options win over config).
How the fonts reach each backend
- resvg NIF — fonts load into a warm, reusable fontdb built via
Resvg.init_fontdb/1and cached in:persistent_term, so directory scanning is paid once per configuration, not per render. The same fontdb backs text measurement (OpenFresco.Measure), so wrap points are computed with the same brand fonts that paint. - resvg CLI — passed as
--use-fonts-dir/--use-font-fileflags per invocation. - rsvg-convert / ImageMagick — no per-call font API; they use the system fontconfig. Install brand fonts system-wide on such hosts, or prefer the NIF/CLI backends.
digest/1 folds the font configuration (paths + mtime + size) into a
stable hash for render manifests, so caches key on the actual fonts that
produced the pixels.
Summary
Functions
CLI flags for the resvg CLI backend (--use-fonts-dir / --use-font-file).
A stable digest of the font configuration (each file's path, mtime and
size) — a render-manifest component, so cached output invalidates when
the fonts that produced it change. Returns "system" when no custom
fonts are configured (system-font changes are outside our visibility;
the manifest documents that honestly).
A warm, reusable resvg fontdb for the given font sources — built once
per configuration and cached in :persistent_term (no supervision tree
required; safe under concurrency — worst case is one duplicate build).
Configured + per-call font sources, normalized.
Functions
CLI flags for the resvg CLI backend (--use-fonts-dir / --use-font-file).
A stable digest of the font configuration (each file's path, mtime and
size) — a render-manifest component, so cached output invalidates when
the fonts that produced it change. Returns "system" when no custom
fonts are configured (system-font changes are outside our visibility;
the manifest documents that honestly).
A warm, reusable resvg fontdb for the given font sources — built once
per configuration and cached in :persistent_term (no supervision tree
required; safe under concurrency — worst case is one duplicate build).
Returns {:ok, fontdb_ref}, or :none when the resvg NIF is absent,
the configuration lists no custom fonts (the system database is the
default anyway), or the build fails.
@spec sources(keyword()) :: %{ font_dirs: [String.t()], font_files: [String.t()], skip_system_fonts: boolean() }
Configured + per-call font sources, normalized.