From 7e04741c29d747c56000b78e4847b4be5d39ac13 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 7 Aug 2019 22:31:45 +0000 Subject: [PATCH] Correct the rendering backend glyph API, and add a missing #include For some reason, FT_BITMAP's 'width' member specifies subpixels, not pixels as the documentation says. --- src/Backends/Rendering/Software.cpp | 3 ++- src/Font.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 46321577..541019ba 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "SDL.h" @@ -386,7 +387,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l case FONT_PIXEL_MODE_LCD: for (unsigned int iy = MAX(-y, 0); y + iy < MIN(y + glyph->height, surface->height); ++iy) { - for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width / 3, surface->width); ++ix) + for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width, surface->width); ++ix) { const double *font_pixel = (double*)glyph->pixels + (iy * glyph->width + ix) * 3; diff --git a/src/Font.cpp b/src/Font.cpp index 64ab31f8..73a55402 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1757,7 +1757,7 @@ static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicod break; } - glyph->backend = Backend_LoadGlyph(bitmap.buffer, bitmap.width, bitmap.rows, bitmap.pitch, bitmap.num_grays, pixel_mode); + glyph->backend = Backend_LoadGlyph(bitmap.buffer, pixel_mode == FONT_PIXEL_MODE_LCD ? bitmap.width / 3 : bitmap.width, bitmap.rows, bitmap.pitch, bitmap.num_grays, pixel_mode); FT_Bitmap_Done(font_object->library, &bitmap); }