X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxfont.c;h=7c71ca75177b2d27cc40ada5cb15b54513e5c64e;hp=c0cbac2d5c265d3dd2a459137350373774cc0975;hb=e00b10147bcf64db3d6b052d911c9c2e76f98253;hpb=fdd99ebecfef4874ea12bc97839fa027a0e8ed2f diff --git a/lib/gfxfont.c b/lib/gfxfont.c index c0cbac2..7c71ca7 100644 --- a/lib/gfxfont.c +++ b/lib/gfxfont.c @@ -28,6 +28,7 @@ #include "gfxfont.h" #include "ttf.h" #include "mem.h" +#include "log.h" static int loadfont_scale = 64; static int full_unicode = 1; @@ -569,6 +570,7 @@ void gfxfont_fix_unicode(gfxfont_t*font) int u = font->glyphs[t].unicode; if(u>=0) { assert(font->unicode2glyph[u]<0); // we took care of duplicates, right? + assert(umax_unicode); font->unicode2glyph[u] = t; } } @@ -663,33 +665,52 @@ ttf_t* gfxfont_to_ttf(gfxfont_t*font) } } + /* make sure coordinates are always to the right of the origin */ + int xshift=0; + if(dest->xmin < 0) { + xshift = -dest->xmin; + for(s=0;spoints[s].x += xshift; + } + dest->xmin += xshift; + dest->xmax += xshift; + } + + dest->bearing = dest->xmin; + dest->xmin=0; dest->advance = src->advance*scale; int u = font->glyphs[t].unicode; - if(invalid_unicode(u)) { - u = 0xe000 + remap_pos++; - } if(u > max_unicode) max_unicode = u; } ttf->unicode_size = max_unicode+1; ttf->unicode = rfx_calloc(sizeof(unicode_t)*ttf->unicode_size); - remap_pos=0; - for(t=0;tnum_glyphs;t++) { - gfxglyph_t*src = &font->glyphs[t]; - int u = font->glyphs[t].unicode; - if(invalid_unicode(u)) { - u = 0xe000 + remap_pos++; + + if(!font->unicode2glyph) { + for(t=0;tnum_glyphs;t++) { + gfxglyph_t*src = &font->glyphs[t]; + int u = font->glyphs[t].unicode; + if(u<=0) + continue; + if(u<32) { + msg(" gfxfont_to_ttf: glyph %d has an invalid unicode (%d)", t, u); + continue; + } else if(ttf->unicode[u]) { + msg(" gfxfont_to_ttf: glyph %d has a duplicate unicode (%d)", t, u); + continue; + } + if(uunicode_size) + ttf->unicode[u] = t+offset; } - if(u>=0 && uunicode_size) - ttf->unicode[u] = t+offset; - } - int u; - if(font->unicode2glyph) { - for(u=0;uunicode_size;u++) { + } else { + int u; + for(u=1;umax_unicode;u++) { int g = font->unicode2glyph[u]; - if(invalid_unicode(u)) + if(g>=0 && u<32) { + msg(" gfxfont_to_ttf: Font contains an invalid unicode (%d)", u); continue; + } if(g>=0 && gnum_glyphs && !ttf->unicode[u]) { ttf->unicode[u] = g+offset; } @@ -697,8 +718,8 @@ ttf_t* gfxfont_to_ttf(gfxfont_t*font) } ttf->ascent = font->ascent; - ttf->descent = font->descent; - ttf->lineGap = font->ascent - font->descent; + ttf->descent = -font->descent; + ttf->lineGap = 0; ttf->full_name = strdup(font->id); ttf->family_name = strdup(font->id);