typography/layout

Types

Span = object
  font: Font
  fontSize: float32
  text: string
Represents a run of litter of same size and font.
GlyphPosition = object
  font*: Font
  fontSize*: float32
  subPixelShift*: float32
  rect*: Rect
  selectRect*: Rect
  character*: string
  rune*: Rune
  count*: int
  index*: int
Represents a glyph position after typesetting.
HAlignMode = enum
  Left, Center, Right
Horizontal alignment mode.
VAlignMode = enum
  Top, Middle, Bottom
Vertical alignment mode.

Consts

normalLineHeight = 0
Default line height of font.size * 1.2

Procs

proc kerningAdjustment(font: Font; prev, c: string): float32 {...}{.raises: [KeyError],
    tags: [].}
Get Kerning Adjustment between two letters.
proc typeset(font: Font; runes: seq[Rune]; pos: Vec2 = vec2(0, 0);
            size: Vec2 = vec2(0, 0); hAlign: HAlignMode = Left; vAlign: VAlignMode = Top;
            clip = true; tabWidth: float32 = 0.0; boundsMin: var Vec2; boundsMax: var Vec2): seq[
    GlyphPosition] {...}{.raises: [KeyError, Defect, IOError, OSError, ValueError, Exception],
                    tags: [ReadIOEffect, RootEffect].}
Typeset runes and return glyph positions that is ready to draw.
proc typeset(font: Font; text: string; pos: Vec2 = vec2(0, 0); size: Vec2 = vec2(0, 0);
            hAlign: HAlignMode = Left; vAlign: VAlignMode = Top; clip = true;
            tabWidth: float32 = 0.0): seq[GlyphPosition] {...}{.
    raises: [KeyError, Defect, IOError, OSError, ValueError, Exception],
    tags: [ReadIOEffect, RootEffect].}
Typeset string and return glyph positions that is ready to draw.
proc drawText(image: Image; layout: seq[GlyphPosition]) {...}{.
    raises: [KeyError, Defect, IOError, OSError, ValueError, Exception],
    tags: [ReadIOEffect, RootEffect].}
Draws layout.
proc drawText(font: Font; image: Image; pos: Vec2; text: string) {...}{.
    raises: [KeyError, Defect, IOError, OSError, ValueError, Exception],
    tags: [ReadIOEffect, RootEffect].}
Draw text string
proc getSelection(layout: seq[GlyphPosition]; start, stop: int): seq[Rect] {...}{.
    raises: [], tags: [].}
Given a layout gives selection from start to stop in glyph positions. If start == stop returns [].
proc pickGlyphAt(layout: seq[GlyphPosition]; pos: Vec2): GlyphPosition {...}{.raises: [],
    tags: [].}
Given X,Y coordinate, return the GlyphPosition picked. If direct click not happened finds closest to the right.
proc textBounds(layout: seq[GlyphPosition]): Vec2 {...}{.raises: [], tags: [].}
Given a layout, return the bounding rectangle. You can use this to get text width or height.
proc textBounds(font: Font; text: string): Vec2 {...}{.
    raises: [KeyError, Defect, IOError, OSError, ValueError, Exception],
    tags: [ReadIOEffect, RootEffect].}
Given a font and text, return the bounding rectangle. You can use this to get text width or height.