Vivid.CFF.Glyph (vivid v1.0.0)

Copy Markdown View Source

A single glyph from a CFF font.

Like its TrueType counterpart, a glyph holds the charstring describing it rather than its parsed outline, and interprets on demand. It carries the whole parsed table because a charstring can call subroutines, which live alongside the charstrings rather than inside them.

Coordinates are in font units, and Vivid.Font.line/3 supplies the multiplier which turns them into pixels.

Summary

Functions

Returns how far the pen advances after drawing glyph, in font units.

Returns the contours of glyph as lists of points in font units, with any curves already flattened into line segments.

Initialize a glyph.

Converts glyph into a Vivid.Region in font units, one contour per contour.

Types

t()

@type t() :: %Vivid.CFF.Glyph{
  advance: number(),
  cff: Vivid.CFF.t(),
  index: non_neg_integer()
}

Functions

advance(glyph)

@spec advance(t()) :: number()

Returns how far the pen advances after drawing glyph, in font units.

Example

iex> Vivid.OpenType.load!(Path.join(:code.priv_dir(:vivid), "fonts/roboto-subset.otf"))
...> |> Vivid.Font.glyph(?A)
...> |> Vivid.CFF.Glyph.advance()
1336

contours(glyph)

@spec contours(t()) :: [[Vivid.Point.t()]]

Returns the contours of glyph as lists of points in font units, with any curves already flattened into line segments.

Example

o is two contours: the outside, and the counter inside it.

iex> Vivid.OpenType.load!(Path.join(:code.priv_dir(:vivid), "fonts/roboto-subset.otf"))
...> |> Vivid.Font.glyph(?o)
...> |> Vivid.CFF.Glyph.contours()
...> |> Enum.count()
2

init(index, advance, cff)

@spec init(non_neg_integer(), number(), Vivid.CFF.t()) :: t()

Initialize a glyph.

  • index this glyph's index in the font.
  • advance how far the pen moves after drawing it, in font units.
  • cff the font's parsed CFF table.

to_region(glyph)

@spec to_region(t()) :: Vivid.Region.t()

Converts glyph into a Vivid.Region in font units, one contour per contour.

Example

iex> Vivid.OpenType.load!(Path.join(:code.priv_dir(:vivid), "fonts/roboto-subset.otf"))
...> |> Vivid.Font.glyph(?B)
...> |> Vivid.CFF.Glyph.to_region()
...> |> Vivid.Region.contours()
...> |> Enum.count()
3