X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=ttf2png.c;h=e890e33643084f7784c8d23e280555c425e8fec4;hb=2bd053c9c2207a7c0afa2defee10568fde2e7c50;hp=af9f56f443d84585b8400cf80849582955be39e5;hpb=cb68acf15406a683e2d722b3a52c4d3b8b2df70d;p=ttf2png.git diff --git a/ttf2png.c b/ttf2png.c index af9f56f..e890e33 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct sImage { unsigned w, h; - char *data; + unsigned char *data; } Image; typedef struct sGlyph @@ -265,6 +265,7 @@ int main(int argc, char **argv) free(font.glyphs); free(font.kerning); free(font.image.data); + free(ranges); FT_Done_Face(face); FT_Done_FreeType(freetype); @@ -501,8 +502,8 @@ int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, unsigned i, j; unsigned size = 0; - font->ascent = (face->size->metrics.ascender+63)>>6; - font->descent = (face->size->metrics.descender+63)>>6; + font->ascent = (face->size->metrics.ascender+63)/64; + font->descent = (face->size->metrics.descender-63)/64; if(verbose>=1) { @@ -542,7 +543,7 @@ int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, kern = &font->kerning[font->n_kerning++]; kern->left_code = font->glyphs[i].code; kern->right_code = font->glyphs[j].code; - kern->distance = kerning.x/64; + kern->distance = (kerning.x+32)/64; } } @@ -594,9 +595,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; } @@ -627,7 +628,7 @@ int copy_bitmap(const FT_Bitmap *bmp, Image *image) { unsigned x, y; unsigned char *src; - char *dst; + unsigned char *dst; image->w = bmp->width; image->h = bmp->rows; @@ -637,7 +638,7 @@ int copy_bitmap(const FT_Bitmap *bmp, Image *image) return 0; } - image->data = (char *)malloc(image->w*image->h); + image->data = (unsigned char *)malloc(image->w*image->h); if(!image->data) { fprintf(stderr, "Cannot allocate %d bytes of memory for glyph\n", image->w*image->h); @@ -652,8 +653,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; @@ -736,7 +745,7 @@ int render_grid(Font *font, unsigned cellw, unsigned cellh, unsigned cpl, bool s if(!npot) font->image.h = round_to_pot(font->image.h); - font->image.data = (char *)alloc_image_data(font->image.w, font->image.h); + font->image.data = (unsigned char *)alloc_image_data(font->image.w, font->image.h); if(!font->image.data) return -1; memset(font->image.data, 255, font->image.w*font->image.h); @@ -813,7 +822,7 @@ int render_packed(Font *font, unsigned margin, unsigned padding, bool npot) glyphs. Since glyphs are rectangular and the image is filled starting from the top, it's enough to track the number of used pixels at the top of each column. */ - font->image.data = (char *)alloc_image_data(font->image.w, font->image.h); + font->image.data = (unsigned char *)alloc_image_data(font->image.w, font->image.h); if(!font->image.data) return -1; memset(font->image.data, 255, font->image.w*font->image.h);