pixie/fonts

Types

Typeface = ref object
  opentype: OpenType
  svgFont: SvgFont
  filePath*: string
  fallbacks*: seq[Typeface]
  Source Edit
Font = ref object
  typeface*: Typeface
  size*: float32             ## Font size in pixels.
  lineHeight*: float32       ## The line height in pixels or autoLineHeight for the font's default line height.
  paints*: seq[Paint]
  textCase*: TextCase
  underline*: bool           ## Apply an underline.
  strikethrough*: bool       ## Apply a strikethrough.
  noKerningAdjustments*: bool ## Optionally disable kerning pair adjustments
  
  Source Edit
Span = ref object
  text*: string
  font*: Font
  Source Edit
Arrangement = ref object
  lines*: seq[(int, int)]    ## The (start, stop) of the lines of text.
  spans*: seq[(int, int)]    ## The (start, stop) of the spans in the text.
  fonts*: seq[Font]          ## The font for each span.
  runes*: seq[Rune]          ## The runes of the text.
  positions*: seq[Vec2]      ## The positions of the glyphs for each rune.
  selectionRects*: seq[Rect] ## The selection rects for each glyph.
  
  Source Edit
HorizontalAlignment = enum
  haLeft, haCenter, haRight
  Source Edit
VerticalAlignment = enum
  vaTop, vaMiddle, vaBottom
  Source Edit
TextCase = enum
  tcNormal, tcUpper, tcLower, tcTitle
  Source Edit

Consts

autoLineHeight: float32 = -1.0
Use default line height for the font size   Source Edit

Procs

proc scale(typeface: Typeface): float32 {...}{.inline, raises: [], tags: [].}
The scale factor to transform font units into pixels.   Source Edit
proc ascent(typeface: Typeface): float32 {...}{.raises: [], tags: [].}
The font ascender value in font units.   Source Edit
proc descent(typeface: Typeface): float32 {...}{.raises: [], tags: [].}
The font descender value in font units.   Source Edit
proc lineGap(typeface: Typeface): float32 {...}{.raises: [], tags: [].}
The font line gap value in font units.   Source Edit
proc lineHeight(typeface: Typeface): float32 {...}{.inline, raises: [], tags: [].}
The default line height in font units.   Source Edit
proc hasGlyph(typeface: Typeface; rune: Rune): bool {...}{.inline, raises: [],
    tags: [].}
Returns if there is a glyph for this rune.   Source Edit
proc fallbackTypeface(typeface: Typeface; rune: Rune): Typeface {...}{.raises: [],
    tags: [].}
Looks through fallback typefaces to find one that has the glyph.   Source Edit
proc getGlyphPath(typeface: Typeface; rune: Rune): Path {...}{.inline,
    raises: [PixieError], tags: [RootEffect].}
The glyph path for the rune.   Source Edit
proc getAdvance(typeface: Typeface; rune: Rune): float32 {...}{.inline, raises: [],
    tags: [].}
The advance for the rune in pixels.   Source Edit
proc getKerningAdjustment(typeface: Typeface; left, right: Rune): float32 {...}{.
    inline, raises: [], tags: [].}
The kerning adjustment for the rune pair, in pixels.   Source Edit
proc scale(font: Font): float32 {...}{.inline, raises: [], tags: [].}
The scale factor to transform font units into pixels.   Source Edit
proc defaultLineHeight(font: Font): float32 {...}{.inline, raises: [], tags: [].}
The default line height in pixels for the current font size.   Source Edit
proc paint(font: Font): Paint {...}{.inline, raises: [], tags: [].}
  Source Edit
proc paint=(font: Font; paint: Paint) {...}{.inline, raises: [], tags: [].}
  Source Edit
proc newFont(typeface: Typeface): Font {...}{.raises: [], tags: [].}
  Source Edit
proc newSpan(text: string; font: Font): Span {...}{.raises: [], tags: [].}
Creates a span, associating a font with the text.   Source Edit
proc typeset(spans: seq[Span]; bounds = vec2(0, 0); hAlign = haLeft;
             vAlign = vaTop; wrap = true): Arrangement {...}{.raises: [], tags: [].}
Lays out the character glyphs and returns the arrangement. Optional parameters: bounds: width determines wrapping and hAlign, height for vAlign hAlign: horizontal alignment of the text vAlign: vertical alignment of the text wrap: enable/disable text wrapping   Source Edit
proc typeset(font: Font; text: string; bounds = vec2(0, 0); hAlign = haLeft;
             vAlign = vaTop; wrap = true): Arrangement {...}{.inline, raises: [],
    tags: [].}
Lays out the character glyphs and returns the arrangement. Optional parameters: bounds: width determines wrapping and hAlign, height for vAlign hAlign: horizontal alignment of the text vAlign: vertical alignment of the text wrap: enable/disable text wrapping   Source Edit
proc computeBounds(arrangement: Arrangement): Vec2 {...}{.raises: [], tags: [].}
Computes the width and height of the arrangement in pixels.   Source Edit
proc computeBounds(font: Font; text: string): Vec2 {...}{.inline, raises: [],
    tags: [].}
Computes the width and height of the text in pixels.   Source Edit
proc computeBounds(spans: seq[Span]): Vec2 {...}{.inline, raises: [], tags: [].}
Computes the width and height of the spans in pixels.   Source Edit
proc parseOtf(buf: string): Typeface {...}{.raises: [PixieError], tags: [].}
  Source Edit
proc parseTtf(buf: string): Typeface {...}{.raises: [PixieError], tags: [].}
  Source Edit
proc parseSvgFont(buf: string): Typeface {...}{.raises: [PixieError],
    tags: [ReadIOEffect, RootEffect, WriteIOEffect].}
  Source Edit
proc fillText(target: Image | Mask; arrangement: Arrangement; transform = mat3()) {...}{.
    inline, raises: [PixieError].}
Fills the text arrangement.   Source Edit
proc fillText(target: Image | Mask; font: Font; text: string;
              transform = mat3(); bounds = vec2(0, 0); hAlign = haLeft;
              vAlign = vaTop) {...}{.inline, raises: [PixieError].}
Typesets and fills the text. Optional parameters: transform: translation or matrix to apply bounds: width determines wrapping and hAlign, height for vAlign hAlign: horizontal alignment of the text vAlign: vertical alignment of the text   Source Edit
proc strokeText(target: Image | Mask; arrangement: Arrangement;
                transform = mat3(); strokeWidth: float32 = 1.0;
                lineCap = lcButt; lineJoin = ljMiter;
                miterLimit = defaultMiterLimit; dashes: seq[float32] = @[]) {...}{.
    inline, raises: [PixieError].}
Strokes the text arrangement.   Source Edit
proc strokeText(target: Image | Mask; font: Font; text: string;
                transform = mat3(); strokeWidth: float32 = 1.0;
                bounds = vec2(0, 0); hAlign = haLeft; vAlign = vaTop;
                lineCap = lcButt; lineJoin = ljMiter;
                miterLimit = defaultMiterLimit; dashes: seq[float32] = @[]) {...}{.
    inline, raises: [PixieError].}
Typesets and strokes the text. Optional parameters: transform: translation or matrix to apply bounds: width determines wrapping and hAlign, height for vAlign hAlign: horizontal alignment of the text vAlign: vertical alignment of the text lineCap: stroke line cap shape lineJoin: stroke line join shape   Source Edit
proc readTypeface(filePath: string): Typeface {...}{.raises: [PixieError],
    tags: [ReadIOEffect, RootEffect, WriteIOEffect].}
Loads a typeface from a file.   Source Edit
proc readFont(filePath: string): Font {...}{.raises: [PixieError], tags: [
    ReadIOEffect, RootEffect, WriteIOEffect].}
Loads a font from a file.   Source Edit