Class GlyphShape
A flattened glyph: its outer polygons, each with the holes inside it. What a triangulator takes.
public sealed class GlyphShape
- Inheritance
-
GlyphShape
Properties
IsEmpty
Whether there is nothing to fill.
public bool IsEmpty { get; }
Property Value
Polygons
The filled pieces of the glyph: one for an O, two for an i.
public IReadOnlyList<GlyphPolygon> Polygons { get; }
Property Value
Methods
FromContours(IReadOnlyList<Vector2[]>)
Sorts closed polygons into outsides and holes by how they nest: a contour inside no other is an outside, one inside exactly one is a hole of it, one inside two is an outside again (the dot inside a copyright sign), and so on. That is how fonts draw letters: nested contours that do not touch, each wound the other way from the one around it. Two filled contours that cross each other, which is how composite glyphs are often drawn (the cedilla through the C), are kept as two pieces that overlap, neither nested in the other.
public static GlyphShape FromContours(IReadOnlyList<Vector2[]> contours)
Parameters
contoursIReadOnlyList<Vector2[]>Closed polygons in either winding, without the first corner repeated.
Returns
- GlyphShape
The shape. Outsides come back counter-clockwise and holes clockwise, whatever they were.
Remarks
Whether one contour lies inside another is decided by a vote of three of its points, so two contours that touch at a corner still sort correctly. Contours with fewer than three corners or no area are ignored. Fonts fill by the nonzero rule, under which two filled pieces that overlap merge into one; this does not merge them, and a solid built from the pieces is two solids through each other, which looks the same from outside. Which of two crossing contours is the outside cannot be told, so both are taken as filled: the stroke of a Ⱥ runs through the letter's hole as a piece of its own, and a hole that strays across its outside, which no font should have, is filled.
Exceptions
- ArgumentNullException
The contours are null.
- InvalidDataException
A contour crosses itself, or a contour nested inside another is wound the same way as it: shapes no fill rule this follows makes sense of. Some variable fonts have them; a reader that does should say which glyph.