# `Expresso.Element.Diagram.Font`
[🔗](https://github.com/rellen/expresso/blob/main/lib/expresso/element/diagram/font.ex#L1)

The font that a tool gets for the text of a graph

Each tool measures a text with the font that it gets, and it calculates the
size of each box from that measure. Therefore the render gives the font of
the slide to the tool, and the browser shows the text in the same font.

The built-in theme uses Atkinson Hyperlegible. The document holds that font
as WOFF2 files, and the tools read TTF files, so `assets/fonts/` also holds
the four TTF files of the font. This module reads them at compile time, as
`Expresso.Font` reads the WOFF2 files, so a release does not need the
`assets/` directory.

The `font` option of a diagram gives a directory with the TTF files of a
different font. `read!/1` takes the family and the style of each file from
the `name` table of the file. A style that the directory does not have takes
the regular file.

# `t`

```elixir
@type t() :: %{
  family: String.t(),
  regular: binary(),
  bold: binary(),
  italic: binary(),
  bold_italic: binary()
}
```

A font: its family, and the bytes of the TTF file of each style

# `advances`

```elixir
@spec advances(t(), String.t()) :: %{
  required(String.t()) =&gt; %{required(String.t()) =&gt; float()}
}
```

The advance width of each character of `text` in each style of a font

The width is a part of the size of the font, such as `0.55` for a character
that is a little more than half of an em wide. The keys of the result are
the styles of Pele: `0` regular, `1` bold, `2` italic and `3` bold italic.
Each style maps the code point of a character to its width. A character that
the font does not have is not in the map, and a measurer gives it a default
width. The widths ignore kerning.

`Expresso.Element.Diagram.Pele` gives the widths to its measurer, so Pele
sizes each box for the text in the font of the slide.

# `builtin`

```elixir
@spec builtin() :: t()
```

The font of the built-in theme, Atkinson Hyperlegible

# `files`

```elixir
@spec files(t()) :: [{String.t(), binary()}]
```

The files of a font, with a name for each style

A tool reads them from its private directory.

# `names`

```elixir
@spec names(binary()) :: {String.t(), String.t()}
```

The family and the style of a TTF file, from its `name` table

The family is the name with the id 1, and the style is the name with the id
2, such as `{"Atkinson Hyperlegible", "Bold"}`. The function prefers the
names for Windows, in UTF-16, and it takes the names for the Mac when the
file has no other.

# `read!`

```elixir
@spec read!(Path.t()) :: t()
```

Read the TTF files of a directory

The function raises an `ArgumentError` for a directory without a TTF file
with the style Regular, and for files of more than one family.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
