Commit deffdbbaaaa7d6ad6664a13a7ccb857c33e206ee

sammy 2010-05-22T18:48:27

Support bitmap (1 bpp) fonts. Patch courtesy of Jaakko Hyvätti.

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;