andygock / glcd

Graphic LCD Library for microcontrollers based embedded systems. Compatible with chipsets PCD854, ST7565R, NTD75451 and many AVR, LPC, PIC, STM32 devices.
Other
97 stars 47 forks source link

Problem drawing char with height multiple of 8 #4

Closed miguelmoreto closed 9 years ago

miguelmoreto commented 10 years ago

Hello,

thanks for this great library. I'm using it with a STM32 and a ST7565 based LCD. It works pretty well, but there is a problem when drawing a character in MIKRO format that have a height of an exact multiple of 8.

In text.c, line 118:

uint8_t bytes_high = font_current.height / 8 + 1;

If you have a font with height 16, the bytes_high will be 3, which is incorrect (should be 2). The drawing result is a mess, because the lib "thinks" that the char have 3 bytes in height.

I change that line with:

    uint8_t bytes_high;

    if ((font_current.height % 8) > 0){
        bytes_high = (font_current.height / 8) + 1;
    }
    else{
        bytes_high = (font_current.height / 8);
    }

Basically it just checks if the remainder is zero, if it is, it means that the height is a exact multiple of 8 and adding a 1 is not necessary.

With that modification I can use any font with 16, 24, 36, ... height pixels.

Thanks,

Miguel

andygock commented 9 years ago

A belated thanks for the fix Miguel!