From 0d97c44e7f70eef1b199373ef7b586749eb409c8 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Wed, 17 Mar 2010 15:28:58 -0700 Subject: [PATCH] refactored ttf unicode mapping --- lib/gfxfont.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/gfxfont.c b/lib/gfxfont.c index 119f003..c1b82eb 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; @@ -666,30 +667,36 @@ ttf_t* gfxfont_to_ttf(gfxfont_t*font) 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;uunicode_size;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; } -- 1.7.10.4