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
@type t() :: %Vivid.CFF.Glyph{ advance: number(), cff: Vivid.CFF.t(), index: non_neg_integer() }
Functions
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
@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
@spec init(non_neg_integer(), number(), Vivid.CFF.t()) :: t()
Initialize a glyph.
indexthis glyph's index in the font.advancehow far the pen moves after drawing it, in font units.cffthe font's parsed CFF table.
@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