]> git.tdb.fi Git - ttf2png.git/commitdiff
Support monochrome bitmaps
authorMikko Rasa <tdb@tdb.fi>
Thu, 3 May 2018 09:24:14 +0000 (12:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 3 May 2018 11:11:35 +0000 (14:11 +0300)
ttf2png.c

index af9f56f443d84585b8400cf80849582955be39e5..42125adc91dbc1dee9af0237d8ef889500dc5b98 100644 (file)
--- a/ttf2png.c
+++ b/ttf2png.c
@@ -594,9 +594,9 @@ int init_glyphs(Font *font, FT_Face face, const Range *range, bool autohinter)
                        printf(": glyph %u, size %dx%d\n", n, bmp->width, bmp->rows);
                }
 
-               if(bmp->pixel_mode!=FT_PIXEL_MODE_GRAY)
+               if(bmp->pixel_mode!=FT_PIXEL_MODE_GRAY && bmp->pixel_mode!=FT_PIXEL_MODE_MONO)
                {
-                       fprintf(stderr, "Warning: Glyph %u skipped, not grayscale\n", n);
+                       fprintf(stderr, "Warning: Glyph %u skipped, incompatible pixel mode\n", n);
                        continue;
                }
 
@@ -652,8 +652,16 @@ int copy_bitmap(const FT_Bitmap *bmp, Image *image)
 
        for(y=0; y<bmp->rows; ++y)
        {
-               for(x=0; x<bmp->width; ++x)
-                       dst[x] = src[x];
+               if(bmp->pixel_mode==FT_PIXEL_MODE_MONO)
+               {
+                       for(x=0; x<bmp->width; ++x)
+                               dst[x] = ((src[x/8]&(0x80>>(x%8))) ? 0xFF : 0x00);
+               }
+               else
+               {
+                       for(x=0; x<bmp->width; ++x)
+                               dst[x] = src[x];
+               }
 
                src += bmp->pitch;
                dst += image->w;