X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=ttf2png.c;fp=ttf2png.c;h=f8db322032d725f88b646b329b7cf42753c44fc4;hb=6c8c1afdbad505c04a251da05499658b7cc65825;hp=93576c1eb4daec90ec7db69f8ad3efac83060302;hpb=63abd0338f9d71caa40f8316c95b6e38216bdcc8;p=ttf2png.git diff --git a/ttf2png.c b/ttf2png.c index 93576c1..f8db322 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -29,6 +29,7 @@ typedef struct sImage { unsigned w, h; unsigned char *data; + unsigned border; } Image; typedef struct sGlyph @@ -44,8 +45,8 @@ typedef struct sGlyph typedef struct sKerning { - unsigned left_code; - unsigned right_code; + Glyph *left_glyph; + Glyph *right_glyph; int distance; } Kerning; @@ -494,6 +495,7 @@ int init_image(Image *image, size_t w, size_t h) image->w = w; image->h = h; image->data = NULL; + image->border = 0; if(!image->w || !image->h) return 0; @@ -560,8 +562,8 @@ 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->left_glyph = &font->glyphs[i]; + kern->right_glyph = &font->glyphs[j]; kern->distance = (kerning.x/scale+32)/64; } } @@ -748,6 +750,7 @@ int create_distance_field(const FT_Bitmap *bmp, Image *image, unsigned scale, un if(copy_bitmap(bmp, &base_image)) return -1; + image->border = margin; for(y=0; yh; ++y) for(x=0; xw; ++x) { int bx = (x-margin)*scale+scale/2; @@ -1021,19 +1024,38 @@ int save_defs(const char *fn, const Font *font) fprintf(out, "# Image/font info:\n"); fprintf(out, "# width height size ascent descent\n"); fprintf(out, "font %d %d %d %d %d\n", font->image.w, font->image.h, font->size, font->ascent, font->descent); + + fprintf(out, "\n# Code point mapping:\n"); + fprintf(out, "# code index\n"); + for(i=0; in_glyphs; ++i) + { + const Glyph *g = &font->glyphs[i]; + fprintf(out, "code %u %u\n", g->code, g->index); + } + + fprintf(out, "\n# Metrics info:\n"); + fprintf(out, "# index width height offset_x offset_y advance\n"); + for(i=0; in_glyphs; ++i) + { + const Glyph *g = &font->glyphs[i]; + int b = g->image.border; + fprintf(out, "metrics %u %u %u %d %d %d\n", g->index, g->image.w-2*b, g->image.h-2*b, g->offset_x+b, g->offset_y+b, g->advance); + } + fprintf(out, "\n# Glyph info:\n"); - fprintf(out, "# code x y width height offset_x offset_y advance\n"); + fprintf(out, "# index x y width height border\n"); for(i=0; in_glyphs; ++i) { const Glyph *g = &font->glyphs[i]; - fprintf(out, "glyph %u %u %u %u %u %d %d %d\n", g->code, g->x, g->y, g->image.w, g->image.h, g->offset_x, g->offset_y, g->advance); + fprintf(out, "glyph %u %u %u %u %u %u\n", g->index, g->x, g->y, g->image.w, g->image.h, g->image.border); } + fprintf(out, "\n# Kerning info:\n"); fprintf(out, "# left right distance\n"); for(i=0; in_kerning; ++i) { const Kerning *k = &font->kerning[i]; - fprintf(out, "kern %u %u %d\n", k->left_code, k->right_code, k->distance); + fprintf(out, "kern %u %u %d\n", k->left_glyph->index, k->right_glyph->index, k->distance); } fclose(out);