/*
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
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;
FT_Face face;
int ch,cw;
int ascent;
+ int descent;
int err;
int i;
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");
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;
}
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);
" -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;
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; i<count; ++i)
{
const GlyphDef *d=defs+i;
- fprintf(out, "%d %d %d %d %d %d %d\n", d->code, 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);