X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2FGFXOutputDev.cc;h=4258a3747639d2594e9146dafb7f10aaff28d11c;hb=d86ad62fe446286296dd97226a1c7748ca40ddf2;hp=2c4149915a99af6de82bb3ffad203c4cdba204b7;hpb=6c3ab5574d31504d24710c2756899d49275c1a37;p=swftools.git diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index 2c41499..4258a37 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -80,11 +80,16 @@ typedef struct _fontfile { const char*filename; + int len; // basename length int used; + struct _fontfile*next; } fontfile_t; // for pdfswf_addfont -static fontfile_t fonts[2048]; + +static fontfile_t* global_fonts = 0; +static fontfile_t* global_fonts_next = 0; + static int fontnum = 0; /* config */ @@ -327,12 +332,24 @@ DisplayFontParam *GFXGlobalParams::getDisplayFont(GString *fontName) return dfp; } } - for(t=0;tt1.fileName = new GString(fonts[t].filename); - return dfp; - } + + int bestlen = 0x7fffffff; + const char*bestfilename = 0; + + fontfile_t*f = 0; + while(f) { + if(strstr(f->filename, name)) { + if(f->len < bestlen) { + bestlen = f->len; + bestfilename = f->filename; + } + } + f = f->next; + } + if(bestfilename) { + DisplayFontParam *dfp = new DisplayFontParam(new GString(fontName), displayFontT1); + dfp->t1.fileName = new GString(bestfilename); + return dfp; } return GlobalParams::getDisplayFont(fontName); } @@ -939,7 +956,7 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, CharCode charid, int nBytes, Unicode *_u, int uLen) { if(!current_fontinfo || (unsigned)charid >= current_fontinfo->num_glyphs || !current_fontinfo->glyphs[charid]) { - msg(" Invalid charid %d for font %s", charid, current_font_id); + msg(" Invalid charid %d for font (%d characters)", charid, current_fontinfo?current_fontinfo->num_glyphs:0); return; } @@ -1070,7 +1087,7 @@ GBool GFXOutputDev::beginType3Char(GfxState *state, double x, double y, double d m.ty += user_movey + clipmovey; if(!current_fontinfo || (unsigned)charid >= current_fontinfo->num_glyphs || !current_fontinfo->glyphs[charid]) { - msg(" Invalid charid %d for font %s", charid, current_font_id); + msg(" Invalid charid %d for font", charid); return gFalse; } gfxcolor_t col={0,0,0,0}; @@ -1520,7 +1537,7 @@ void GFXOutputDev::updateFont(GfxState *state) this->current_fontinfo = this->info->getFont(id); if(!this->current_fontinfo) { msg(" Internal Error: no fontinfo for font %s\n", id); - return; + return; } if(!this->current_fontinfo->seen) { dumpFontInfo("", gfxFont); @@ -2004,14 +2021,25 @@ static const char* dirseparator() void addGlobalFont(const char*filename) { - fontfile_t f; - memset(&f, 0, sizeof(fontfile_t)); - f.filename = filename; - if(fontnum < sizeof(fonts)/sizeof(fonts[0])) { - msg(" Adding font \"%s\".", filename); - fonts[fontnum++] = f; + fontfile_t* f = (fontfile_t*)malloc(sizeof(fontfile_t)); + memset(f, 0, sizeof(fontfile_t)); + f->filename = filename; + int len = strlen(filename); + char*r1 = strrchr(filename, '/'); + char*r2 = strrchr(filename, '\\'); + if(r2>r1) + r1 = r2; + if(r1) { + len = strlen(r1+1); + } + f->len = len; + + msg(" Adding font \"%s\".", filename); + if(global_fonts_next) { + global_fonts_next->next = f; + global_fonts_next = global_fonts_next->next; } else { - msg(" Too many external fonts. Not adding font file \"%s\".", filename); + global_fonts_next = global_fonts = f; } }