9 years, 6 months ago.

Font with more than 255 bytes / character

Hi Peter,

I just started learning mbed and came across your excellent LCD/font libraries. Thank you.

I was able to create several fonts using your instructions. However, it appeared that the font array is of char datatype so the limit is 255 bytes per character. I am interested in creating a large font which requires about 300 bytes per character. Do you have any tips as to how to change the font array from char to int data type?

Thanks again, samerpav

Question relating to:

Font to use with the SPI_TFT lib fonts, TFT

1 Answer

9 years, 6 months ago.

No idea why it returns anything currently, but this is what I use in a program where I need (way) bigger fonts, an adaptation of the original code:

// paint char out of font
int character(const unsigned char *font, int x, int y, int c)
{
    unsigned int hor,vert,offset,bpl,j,i,b,z;
    unsigned char* _char;

    // read font parameter from start of array
    offset = (font[0] << 8) + font[1];           // bytes / char
    hor = font[3];                       // get hor size of font
    vert = font[4];                      // get vert size of font
    bpl = font[2];                       // bytes per line

    _char = (unsigned char*)&font[(c * offset) + 5]; // start of char bitmap


    // construct the char into the buffer
    for (j=0; j<vert; j++) {  //  vert line
        for (i=0; i<hor; i++) {   //  horz line
            z =  _char[bpl * i + ((j & 0xF8) >> 3)+1];
            b = 1 << (j & 0x07);
            if (( z & b ) == 0x00) {
                epaper.pixel(x+i,y+j,0);
            } else {
                epaper.pixel(x+i,y+j,1);
            }

        }
    }

    return _char[0];
}

Where the character is:

const unsigned char Calibri39x53[] = {
        0x01, 0x12, 0x07, 0x27, 0x35,     //size in bytes MSB, size in bytes LSB, bytes per line, width, height

(Followed by the actual characters, in this case I limitted it manually to only those I actually required to show temperature).

Accepted Answer