# Font drawing

The unit at [gr/font.fs] is an abstract interface for drawing font on a
[gr/buf].

It describes a structure which has the method you'll likely be interested in the
most, "drawglyph ( glyph font -- )", which draws the specified glyph index on
current pixbuf destination, with current background and foreground colors,
which must be in pixbuf's color encoding.

To obtain a font structure, you'll use a kind of "load" word that will be
implemented by specific font units, for example [gr/font/uf1].

## A glyph?

A glyph is a fancy name for a character. We just want to emphasis that a glyph
is in index in an array contained in a font. The vast majority of the time, the
glyph number corresponds to the ASCII character number. It's just that for
values over $7f and under $20, a few liberties can be taken by the font to pack
more stuff in it.

## Drawing glyphs

Before drawing a glyph, you'll first set your target pixbuf and coordinates
with "fonttarget!", then set the foreground and background colors with
"fontcolors!".

Then comes a series of calls to "drawglyph", which will advance target X by the
width of the glyph.

## Example usage

  needs gr/buf gr/font gr/font/uf1
  "data/font/atari8.uf1" loaduf1 const fnt
  0 0 screen fnt fonttarget!
  0 $ffff fnt fontcolors!
  'X' fnt drawglyph \ Draws a X at bottom left corner
  'Y' fnt drawglyph \ Draws a Y to the right of previous X

## API

### Struct

struct Font
  fields width height tgtbuf tgtx tgty bgcolor fgcolor
  method drawglyph ( g font -- )
endstruct

width   Width in pixels of glyphs
height  Height in pixels of glyphs
tgtbuf  Target pixbuf [gr/buf] for drawing
tgtx
tgty    Target coordinates for drawing
bgcolor Background color of drawn glyph
fgcolor Foreground color of drawn glyph

drawglyph ( glyph font -- )
  Draw glyph index "glyph" as described in "Drawing glyphs" above.

### Words

newfont ( width height draw-xt -- font )
  Allocate and initialize a font struct. All unspecified fields are zero.

fonttarget! ( x y pixbuf font -- )
  Set tgtbuf, tgtx and tgty.

fontcolors! ( bg fg font -- )
  Set bgcolor and fgcolor.

fontinvalidate ( font -- )
  Call "invalidate" on tgtbuf with the proper arguments.
