small stuff
compiler warns that it is redefined on glibc
defines to enums
defines -> enum, more verbose variable name
use Viewport type instead of struct viewport
use Canvas type instead of struct canvas
use Window type instead of struct win
forward declarations for types make more sense in a separate file

it's easier to see what's going on, and it looks better included in
headers instead of explicitly put in
use Layer type instead of struct layer
port changes from upstream

Support non-BMP utf8 characters
fix typo, duh. Thanks to Jim Mahood for reporting this.
set fontx to null instead of 0 if the encoding is switched to non-utf8