From d9b8d0e80ee7e2a19f0035db64b3fc1c2daa2496 Mon Sep 17 00:00:00 2001 From: kramm Date: Fri, 20 Aug 2004 16:43:32 +0000 Subject: [PATCH] added support for charmaps. --- lib/modules/swffont.c | 60 +++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/lib/modules/swffont.c b/lib/modules/swffont.c index 4a7596b..73fa7a3 100644 --- a/lib/modules/swffont.c +++ b/lib/modules/swffont.c @@ -109,6 +109,7 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) int*glyph2glyph; FT_Size size; int max_unicode = 0; + int charmap = -1; if(ftlibrary == 0) { if(FT_Init_FreeType(&ftlibrary)) { @@ -157,32 +158,47 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) if(name && *name) font->name = (U8*)strdup(name); -/* // Map Glyphs to Unicode, version 1 (quick and dirty): - int t; - for(t=0;t<65536;t++) { - int index = FT_Get_Char_Index(face, t); - if(index>=0 && indexnum_glyphs) { - if(font->glyph2ascii[index]<0) - font->glyph2ascii[index] = t; - } - }*/ - - // Map Glyphs to Unicode, version 2 (much nicer): - // (The third way would be the AGL algorithm, as proposed - // by Werner Lemberg on freetype@freetype.org) - - charcode = FT_Get_First_Char(face, &gindex); - while(gindex != 0) + while(1) { - if(gindex >= 0 && gindexnum_glyphs) { - if(!font->glyph2ascii[gindex]) { - font->glyph2ascii[gindex] = charcode; - if(charcode + 1 > font->maxascii) { - font->maxascii = charcode + 1; + /* // Map Glyphs to Unicode, version 1 (quick and dirty): + int t; + for(t=0;t<65536;t++) { + int index = FT_Get_Char_Index(face, t); + if(index>=0 && indexnum_glyphs) { + if(font->glyph2ascii[index]<0) + font->glyph2ascii[index] = t; + } + }*/ + + // Map Glyphs to Unicode, version 2 (much nicer): + // (The third way would be the AGL algorithm, as proposed + // by Werner Lemberg on freetype@freetype.org) + + charcode = FT_Get_First_Char(face, &gindex); + while(gindex != 0) + { + if(gindex >= 0 && gindexnum_glyphs) { + if(!font->glyph2ascii[gindex]) { + font->glyph2ascii[gindex] = charcode; + if(charcode + 1 > font->maxascii) { + font->maxascii = charcode + 1; + } } } + charcode = FT_Get_Next_Char(face, charcode, &gindex); } - charcode = FT_Get_Next_Char(face, charcode, &gindex); + + /* if we didn't find a single encoding character, try + the font's charmaps instead. That usually means that + the encoding is no longer unicode. + TODO: find a way to convert the encoding to unicode + */ + if(font->maxascii == 0 && charmap < face->num_charmaps - 1) { + charmap++; + FT_Set_Charmap(face, face->charmaps[charmap]); + font->encoding = 0;//anything but unicode FIXME + } else + break; } if(full_unicode) -- 1.7.10.4