Support bitmap (1 bpp) fonts. Patch courtesy of Jaakko Hyvätti.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/FTGlyph/FTPixmapGlyph.cpp b/src/FTGlyph/FTPixmapGlyph.cpp
index c27523d..d380ef3 100644
--- a/src/FTGlyph/FTPixmapGlyph.cpp
+++ b/src/FTGlyph/FTPixmapGlyph.cpp
@@ -91,14 +91,32 @@ FTPixmapGlyphImpl::FTPixmapGlyphImpl(FT_GlyphSlot glyph)
unsigned char* dest = data + ((destHeight - 1) * destWidth * 2);
size_t destStep = destWidth * 2 * 2;
- for(int y = 0; y < srcHeight; ++y)
+ if (FT_PIXEL_MODE_MONO == bitmap.pixel_mode)
{
- for(int x = 0; x < srcWidth; ++x)
+ // Convert the 1 bpp bitmap to 8 bpp
+ for(int y = 0; y < srcHeight; ++y)
{
- *dest++ = static_cast<unsigned char>(255);
- *dest++ = *src++;
+ for(int x = 0; x < srcWidth; ++x)
+ {
+ *dest++ = static_cast<unsigned char>(255);
+ // Store 255 if bit (x % 8) is set, store 0 otherwise
+ *dest++ = static_cast<unsigned char>(static_cast<signed char>(src[static_cast<unsigned int>(x) >> 3] << (x & 7)) >> 7);
+ }
+ dest -= destStep;
+ src += bitmap.pitch;
+ }
+ }
+ else
+ {
+ for(int y = 0; y < srcHeight; ++y)
+ {
+ for(int x = 0; x < srcWidth; ++x)
+ {
+ *dest++ = static_cast<unsigned char>(255);
+ *dest++ = *src++;
+ }
+ dest -= destStep;
}
- dest -= destStep;
}
destHeight = srcHeight;