5. Lowlevel Glyph

<<funcdefs>>=
int macfont_glyph_lowlevel(btprnt_region *r,
                           uint8_t *font,
                           int xpos,
                           int ypos,
                           char c);

I want more words to explain this eventually. For now, just a mad scramble to place pixels.

<<funcs>>=
int macfont_glyph_lowlevel(btprnt_region *r,
                           uint8_t *font,
                           int xpos,
                           int ypos,
                           char c)
{
    uint8_t *bitmaps;
    uint16_t *loctable;
    uint16_t *owtable;
    uint16_t off;
    uint16_t nchars;
    uint16_t ow;
    uint16_t width;
    uint16_t offset;
    uint16_t pos;
    uint16_t nextloc;
    uint16_t loc;
    uint16_t stride;
    uint16_t x, y;
    uint16_t w, h;
    uint16_t kern;

    bitmaps = BITMAPS(font);
    off = ROWWORDS(font) * RECTHEIGHT(font);

    loctable = (uint16_t *) (bitmaps + (2 * off));

    nchars = LASTCHAR(font) - FIRSTCHAR(font) + 1;

    owtable = loctable + (nchars + 2);

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

    if (ow == 0xFFFF) return 0;

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

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

    stride = ROWWORDS(font) * 2;

    w = nextloc - loc;
    h = RECTHEIGHT(font);
    kern = offset + KERNMAX(font);

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

    return width;
}



prev | home | next