NativeElixirPdfUtilities.HtmlToPdf.Font (native_elixir_pdf_utilities v0.8.0)
View SourceFont loading, fallback resolution, text measurement, and PDF text encoding.
The renderer loads explicitly configured fonts, bundles DejaVu Sans fallback faces, and also discovers a small set of common system sans-serif fonts when they are available.
Summary
Functions
Encodes text for an embedded Type0 font content stream.
Returns configured and bundled fallback faces in family declaration order, ordering each family's faces by the closest weight and style.
Loads explicit TTF font options into a registry.
Returns the PDF resource key for a selected font face.
Resolves a CSS font-family value or fallback list to a supported font face.
Returns whether a font face can safely encode every codepoint in text.
Measures text in PDF points for the selected font and size.
Builds CID-to-Unicode mappings for all text shown with an embedded font.
Types
@type embedded_font() :: %{ type: :embedded, family: String.t(), weight: number(), style: font_style(), id: String.t(), pdf_name: String.t(), data: binary(), units_per_em: pos_integer(), widths: [non_neg_integer()], default_width: non_neg_integer(), cmap: %{optional(non_neg_integer()) => non_neg_integer()}, ascent: integer(), descent: integer(), bbox: {integer(), integer(), integer(), integer()} }
@type font_face() :: built_in_font() | embedded_font()
@type font_style() :: :normal | :italic
@type registry() :: %{embedded: [embedded_font()], fallback: [embedded_font()]}
Functions
@spec encode_embedded_text(String.t(), embedded_font()) :: String.t()
Encodes text for an embedded Type0 font content stream.
@spec fallback_faces(registry(), number(), font_style()) :: [embedded_font()]
Returns configured and bundled fallback faces in family declaration order, ordering each family's faces by the closest weight and style.
Loads explicit TTF font options into a registry.
Accepted font entries are maps, keyword lists, or {family, path} tuples. Map
and keyword entries must include :family and :path; :weight and :style
are optional.
Returns the PDF resource key for a selected font face.
@spec resolve(String.t() | [String.t()], number(), font_style(), registry()) :: {:ok, [String.t()], font_face()} | :error
Resolves a CSS font-family value or fallback list to a supported font face.
Returns whether a font face can safely encode every codepoint in text.
Built-in PDF fonts are limited to printable ASCII. Embedded fonts are checked against their Unicode character map.
Measures text in PDF points for the selected font and size.
@spec unicode_mappings([String.t()], embedded_font()) :: %{ optional(non_neg_integer()) => non_neg_integer() }
Builds CID-to-Unicode mappings for all text shown with an embedded font.