8. Macfont Glyph

The main way to write a glyph (using macfont info).

<<funcdefs>>=
int macfont_glyph(btprnt_region *r,
                  macfont_info *info,
                  int xpos,
                  int ypos,
                  char c,
                  int color);
<<funcs>>=
int macfont_glyph(btprnt_region *r,
                  macfont_info *info,
                  int xpos,
                  int ypos,
                  char c,
                  int color)
{
    uint16_t ow;
    uint16_t width;
    uint16_t offset;
    uint16_t pos;
    uint16_t nextloc;
    uint16_t loc;
    uint16_t x, y;
    uint16_t w, h;
    uint16_t kern;

    pos = c - info->firstchar;
    ow = info->owtable[pos];
    ow = ((ow & 0xFF) << 8) | ow >> 8;

    if (ow == 0xFFFF) return 0;

    offset = (ow >> 8) & 0x00FF;
    width = ow & 0x00FF;

    loc = BIGINT(info->loctable[pos]);
    nextloc = BIGINT(info->loctable[pos + 1]);

    w = nextloc - loc;
    h = info->rectheight;
    kern = offset + info->kernmax;

    for (y = 0; y < h; y++) {
        for (x = 0; x < w; x++) {
            int pos = loc + x;
            uint8_t byte =
                info->bitmaps[(info->stride * y) + (pos / 8)];
            uint8_t val = (byte >> (7 - (pos % 8))) & 1;
            if (val) {
                btprnt_region_draw(r,
                                   xpos + x + kern,
                                   ypos + y,
                                   color);
            }
        }
    }

    return width;
}



prev | home | next