From 17b96c26c5624aba41eb1d11cb5d2bf2d05982f5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 3 May 2018 12:24:14 +0300 Subject: [PATCH] Support monochrome bitmaps --- ttf2png.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ttf2png.c b/ttf2png.c index af9f56f..42125ad 100644 --- 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; yrows; ++y) { - for(x=0; xwidth; ++x) - dst[x] = src[x]; + if(bmp->pixel_mode==FT_PIXEL_MODE_MONO) + { + for(x=0; xwidth; ++x) + dst[x] = ((src[x/8]&(0x80>>(x%8))) ? 0xFF : 0x00); + } + else + { + for(x=0; xwidth; ++x) + dst[x] = src[x]; + } src += bmp->pitch; dst += image->w; -- 2.43.0