typography/font

Types

Segment = object
  at*: Vec2
  to*: Vec2
A math segment from point "at" to point "to"
PathCommandKind = enum
  Start, Move, Line, HLine, VLine, Cubic, SCurve, Quad, TQuad, End, RMove, RLine, RHLine,
  RVLine, RCubic, RSCurve, RQuad, RTQuad
Type of binary commands
PathCommand = object
  kind*: PathCommandKind
  numbers*: seq[float32]
Binary version of an SVG command
Glyph = ref object
  code*: string
  advance*: float32
  commands*: seq[PathCommand]
  shapes*: seq[seq[Segment]]   ## Shapes are made of lines.
  bboxMin*: Vec2
  bboxMax*: Vec2
  ready*: bool
  isEmpty*: bool
  numberOfContours*: int
  isComposite*: bool
  index*: int
  path*: string
Contains information about Glyphs or "letters" SVG Path, command buffer, and shapes of lines.
Typeface = ref object
  filename*: string
  name*: string
  bboxMin*: Vec2
  bboxMax*: Vec2
  advance*: float32
  ascent*: float32
  descent*: float32
  xHeight*: float32
  capHeight*: float32
  unitsPerEm*: float32
  lineGap*: float32
  glyphs*: Table[string, Glyph]
  kerning*: Table[(string, string), float32]
  glyphArr*: seq[Glyph]
  otf*: OtfFont
  stream*: Stream
Main font object contains font information and Glyphs
Font = ref object
  typeface*: Typeface
  size*: float32
  lineHeight*: float32
  weight*: float32
Contains size, weight and typeface.

Procs

proc sizePt(font: Font): float32 {...}{.raises: [], tags: [].}
Gets font size in Pt or Point units.
proc sizePt=(font: Font; sizePoints: float32) {...}{.raises: [], tags: [].}
Sets font size in Pt or Point units.
proc sizeEm(font: Font): float32 {...}{.raises: [], tags: [].}
Gets font size in em units.
proc sizeEm=(font: Font; sizeEm: float32) {...}{.raises: [], tags: [].}
Gets font size in em units.
proc sizePr(font: Font): float32 {...}{.raises: [], tags: [].}
Gets font size in % or Percent units.
proc sizePr=(font: Font; sizePercent: float32) {...}{.raises: [], tags: [].}
Gets font size in % or Percent units.
proc scale(font: Font): float32 {...}{.raises: [], tags: [].}
Gets the internal scaling of font units to pixles.
proc letterHeight(font: Font): float32 {...}{.raises: [], tags: [].}
Gets the current letter height based on ascent and descent and the current size and lineheight.
proc baseline(font: Font): float32 {...}{.raises: [], tags: [].}
Gets the baseline of the font based on current size and lineheight.
proc capline(font: Font): float32 {...}{.raises: [], tags: [].}
Gets the current capline of the font based on current size and lineheight.
proc intersects(a, b: Segment; at: var Vec2): bool {...}{.raises: [], tags: [].}
Checks if the a segment intersects b segment. If it returns true, at will have point of intersection
proc glyphPathToCommands(glyph: Glyph) {...}{.raises: [ValueError], tags: [].}
Converts a glyph into lines-shape
proc commandsToShapes(glyph: Glyph) {...}{.raises: [ValueError], tags: [].}
Converts SVG-like commands to shape made out of lines