FormatParser.Font (format_parser v2.14.0)

Copy Markdown

A Font struct and functions.

The Font struct contains the fields format and nature.

Supported Formats

FormatExtensionDescription
:ttf.ttfTrueType Font
:otf.otfOpenType Font
:fon.fonWindows bitmap font
:woff.woffWeb Open Font Format
:woff2.woff2Web Open Font Format 2

Examples

iex> {:ok, file} = File.read("priv/test.ttf")
iex> FormatParser.parse(file)
%FormatParser.Font{format: :ttf, nature: :font}

Summary

Types

t()

A struct representing a parsed font file.

Functions

Parses a font file or result.

Types

t()

@type t() :: %FormatParser.Font{format: atom() | nil, nature: :font}

A struct representing a parsed font file.

Fields

  • :format - The font format as an atom (e.g., :ttf, :otf, :woff), or nil if unknown
  • :nature - Always :font for font files

Functions

parse(file)

@spec parse({:error, binary()} | binary() | any()) :: any()

Parses a font file or result.

  • If given a tuple {:error, file} where file is a binary, attempts to parse the font from the file.
  • If given a binary file, attempts to parse the font from the file.
  • For any other input, returns the input as-is (passthrough for parser chain).

Examples

iex> {:ok, file} = File.read("priv/test.ttf")
iex> FormatParser.Font.parse(file)
%FormatParser.Font{format: :ttf, nature: :font}

iex> FormatParser.Font.parse(%FormatParser.Image{})
%FormatParser.Image{}