From: kramm Date: Mon, 15 Nov 2004 12:21:59 +0000 (+0000) Subject: fixed conversion for fonts with broken unicode indices. X-Git-Tag: release-0-6-3~171 X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=c1ca1cfeedba16d4db2f06bc875003658438244d;p=swftools.git fixed conversion for fonts with broken unicode indices. --- diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index dcba007..e2a85a5 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -1226,7 +1226,7 @@ int getCharID(SWFFONT *font, int charnr, char *charname, int u) } } - if(u>0) { + if(u>0 && font->encoding != 255) { /* try to use the unicode id */ if(u>=0 && umaxascii && font->ascii2glyph[u]>=0) { msg(" Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->ascii2glyph[u]); @@ -1292,6 +1292,27 @@ void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename) msg(" Couldn't load font %s (%s)", fontid, filename); swffont = swf_LoadFont(0); } + + if(swffont->glyph2ascii) { + int t; + int bad = 0; + /* check whether the Unicode indices look o.k. + If they don't, disable the unicode lookup by setting + the encoding to 255 */ + for(t=0;tnumchars;t++) { + int c = swffont->glyph2ascii[t]; + if(c && c < 32 && swffont->glyph[t].shape->bitlen > 16) { + // the character maps into the unicode control character range + // between 0001-001f. Yet it is not empty. Treat the one + // mapping as broken, and look how many of those we find. + bad ++; + } + } + if(bad>5) { + msg(" Font %s has bad unicode mapping", swffont->name); + swffont->encoding = 255; + } + } swf_FontSetID(swffont, ++i->currentswfid);