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

DrawChar doesn't consider proportional fonts while bounds checking #94

Closed
jorolf opened this issue Jan 29, 2025 · 2 comments · Fixed by #98
Closed

DrawChar doesn't consider proportional fonts while bounds checking #94

jorolf opened this issue Jan 29, 2025 · 2 comments · Fixed by #98

Comments

@jorolf
Copy link

jorolf commented Jan 29, 2025

Currently, DrawChar doesn't draw chars like "i" or "j", even though they fit, because only the "worst case" character width is considered:

// Check remaining space on current line
if (SSD1306_WIDTH < (SSD1306.CurrentX + Font.width) ||
SSD1306_HEIGHT < (SSD1306.CurrentY + Font.height))
{
// Not enough space on current line
return 0;
}

Maybe it could be replaced by code like this:

uint8_t width = Font.char_width ? Font.char_width[ch - 32] : Font.width;

// Check remaining space on current line
if (SSD1306_WIDTH < (SSD1306.CurrentX + width) ||
    SSD1306_HEIGHT < (SSD1306.CurrentY + Font.height))
{
  // Not enough space on current line
  return 0;
}

This could break fonts that are drawing outside of their char width to create overlapping characters. (consider "AW" or "ij")
Although I'm not sure if those fonts were supported in the first place.

@afiskon
Copy link
Owner

afiskon commented Jan 30, 2025

Yeah, that seems to be a bug introduced in #85 (cc: @kossnikita)

Personally I'm not extremely interested in proportional fonts to be honest, but your pull requests are most welcomed.

@kossnikita
Copy link
Contributor

Got it. I'll check it from my side

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

Successfully merging a pull request may close this issue.

3 participants