From: Mikko Rasa Date: Wed, 28 Nov 2007 12:40:05 +0000 (+0200) Subject: Version 0.2.2 X-Git-Tag: 0.2.2 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b97ea76636a9ffe5dc1ce15dadabfe5d0e5ab1fa;p=ttf2png.git Version 0.2.2 --- diff --git a/Readme b/Readme index b9628ef..c6b8100 100644 --- a/Readme +++ b/Readme @@ -1,5 +1,5 @@ ttf2png - True Type Font to PNG converter -Copyright (c) 2004-2006 Mikko Rasa, Mikkosoft Productions +Copyright (c) 2004-2007 Mikko Rasa, Mikkosoft Productions Software requirements @@ -11,6 +11,10 @@ C compiler (preferably GCC) Changes +0.2.2 +- Write both X and Y offsets of glyphs to the definition file +- Output font ascent and descent to definition file + 0.2.1 - Don't create too large image with sequential mode if the range is sparse diff --git a/ttf2png.c b/ttf2png.c index bd84106..fe785e0 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -1,6 +1,6 @@ /* ttf2png - True Type Font to PNG converter -Copyright (c) 2004-2006 Mikkosoft Productions +Copyright (c) 2004-2007 Mikko Rasa This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,13 +29,14 @@ typedef struct sGlyphDef int code; int x,y; int w,h; - int ascent; + int offset_x; + int offset_y; int advance; } GlyphDef; unsigned round_to_pot(unsigned); void usage(); -int save_defs(const char *, const GlyphDef *, int, int, int, int); +int save_defs(const char *, const GlyphDef *, int, int, int, int, int, int); int save_png(const char *, const char *, int, int, char); char verbose=0; @@ -56,6 +57,7 @@ int main(int argc, char **argv) FT_Face face; int ch,cw; int ascent; + int descent; int err; int i; @@ -181,18 +183,20 @@ int main(int argc, char **argv) fprintf(stderr, "Couldn't set size\n"); return 1; } - ascent=(face->bbox.yMax*face->size->metrics.x_scale)>>16; + ascent=(face->bbox.yMax*face->size->metrics.y_scale)>>16; ascent=(ascent+63)/64; + descent=(face->bbox.yMin*face->size->metrics.y_scale)>>16; + descent=(ascent+63)/64; ch=((face->bbox.yMax-face->bbox.yMin)*face->size->metrics.y_scale)>>16; ch=(ch+63)/64; cw=((face->bbox.xMax-face->bbox.xMin)*face->size->metrics.x_scale)>>16; cw=(cw+63)/64; if(verbose) { - printf("Ascent %d\n",ascent); - printf("Descent %ld\n",(((face->bbox.yMin*face->size->metrics.y_scale)>>16)+63)/64); - printf("Max height %d\n",ch); - printf("Max width %d\n",cw); + printf("Ascent %d\n", ascent); + printf("Descent %d\n", descent); + printf("Max height %d\n", ch); + printf("Max width %d\n", cw); } if(verbose>=1 && (ch>cell || cw>cell)) fprintf(stderr,"Warning: character size exceeds cell size\n"); @@ -273,7 +277,8 @@ int main(int argc, char **argv) defs[count].y=cy; defs[count].w=bmp->width; defs[count].h=bmp->rows; - defs[count].ascent=face->glyph->bitmap_top-bmp->rows; + defs[count].offset_x=face->glyph->bitmap_left; + defs[count].offset_y=face->glyph->bitmap_top-bmp->rows; defs[count].advance=(int)(face->glyph->advance.x+32)/64; } @@ -284,7 +289,7 @@ int main(int argc, char **argv) h/=2; if(def_fn) - save_defs(def_fn, defs, count, w, h, size); + save_defs(def_fn, defs, count, w, h, size, ascent, descent); save_png(out_fn, data, w, h, alpha); if(verbose) printf("Converted %d glyphs\n", count); @@ -324,7 +329,7 @@ void usage() " -h Print this message\n"); } -int save_defs(const char *fn, const GlyphDef *defs, int count, int w, int h, int size) +int save_defs(const char *fn, const GlyphDef *defs, int count, int w, int h, int size, int ascent, int descent) { FILE *out; int i; @@ -336,11 +341,11 @@ int save_defs(const char *fn, const GlyphDef *defs, int count, int w, int h, int return -1; } - fprintf(out, "%d %d %d\n", w, h, size); + fprintf(out, "%d %d %d %d %d\n", w, h, size, ascent, descent); for(i=0; icode, d->x, d->y, d->w, d->h, d->ascent, d->advance); + fprintf(out, "%d %d %d %d %d %d %d %d\n", d->code, d->x, d->y, d->w, d->h, d->offset_x, d->offset_y, d->advance); } fclose(out);