Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal of new WriteChar function with a bugfix #14

Open
cosmolabs-ru opened this issue Feb 29, 2024 · 1 comment
Open

Proposal of new WriteChar function with a bugfix #14

cosmolabs-ru opened this issue Feb 29, 2024 · 1 comment

Comments

@cosmolabs-ru
Copy link

Hello!
I used MatrixFont to make Cyrillic fonts for use with your library.
Somehow, I encountered a bug: with some fonts, WriteChar() adds a big margin (up to 30% width) on the left of a glyph, and crops off as much on the right.
I checked MatrixFont's output, and found it suitable for use with this lib. But somehow, built in fonts work, third-party-generated ones don't.

So i rewrote WriteChar() to display third-party fonts without aberrations.
Check it out.

void ST7735_WriteChar(uint16_t x, uint16_t y, char ch, FontDef font, uint16_t color, uint16_t bgcolor) {
    ST7735_SetAddressWindow(x, y, x+font.width-1, y+font.height-1);
    uint16_t glyph_start = (ch-32)*font.height;
    for(uint16_t row = 0; row < font.height; row++) {
        for(uint16_t col = 0; col < font.width; col++) {
            if( font.data[glyph_start+row] & (1<<col) )  {/*pixel is ON*/
                uint8_t data[] = { color >> 8, color & 0xFF };
                ST7735_WriteData(data, sizeof(data));
            } else {
                uint8_t data[] = { bgcolor >> 8, bgcolor & 0xFF };
                ST7735_WriteData(data, sizeof(data));
            }
        }
    }
}
@afiskon
Copy link
Owner

afiskon commented Mar 3, 2024

Looks reasonable. To clarify: does it work with the fonts built-in into the library? Did you try to replace WriteChar with your implementation and execute the example code: https://github.com/afiskon/stm32-st7735/blob/master/Src/main.c ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants