X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=40d8847ad06f9b3a44fd40d5895a595b065750e2;hb=d80e59af5dbc89b3f2b764b31811b9f423d7f4f2;hp=b54f1e68188c9be824276153cb6e543958383372;hpb=d75a50399914f3d07f396401acca748c2f901b61;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index b54f1e6..40d8847 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -255,7 +255,7 @@ public: int width, int height, GfxImageColorMap*colorMap, GBool invert, GBool inlineImg, int mask, int *maskColors, Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap); - int SWFOutputDev::setGfxFont(char*id, char*filename, double quality); + int SWFOutputDev::setGfxFont(char*id, char*name, char*filename, double quality); void strokeGfxline(GfxState *state, gfxline_t*line); void clipToGfxLine(GfxState *state, gfxline_t*line); void fillGfxLine(GfxState *state, gfxline_t*line); @@ -526,20 +526,31 @@ void SWFOutputDev::setClip(int x1,int y1,int x2,int y2) static char*getFontID(GfxFont*font) { + Ref*ref = font->getID(); GString*gstr = font->getName(); - char* fontname = gstr==0?0:gstr->getCString(); - if(fontname==0) { - char buf[32]; - Ref*r=font->getID(); - sprintf(buf, "UFONT%d", r->num); - return strdup(buf); + char* fname = gstr==0?0:gstr->getCString(); + char buf[128]; + if(fname==0) { + sprintf(buf, "font-%d-%d", ref->num, ref->gen); + } else { + sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen); } - return strdup(fontname); + return strdup(buf); } static char*getFontName(GfxFont*font) { - char*fontid = getFontID(font); + char*fontid; + GString*gstr = font->getName(); + char* fname = gstr==0?0:gstr->getCString(); + if(fname==0) { + char buf[32]; + Ref*r=font->getID(); + sprintf(buf, "UFONT%d", r->num); + fontid = strdup(buf); + } + fontid = strdup(fname); + char*fontname= 0; char* plus = strchr(fontid, '+'); if(plus && plus < &fontid[strlen(fontid)-1]) { @@ -1119,8 +1130,22 @@ char* makeStringPrintable(char*str) int getGfxCharID(gfxfont_t*font, int charnr, char *charname, int u) { - int t; + char*uniname = 0; + if(u>0) { + int t; + /* find out char name from unicode index + TODO: should be precomputed + */ + for(t=0;tnum_glyphs;t++) { if(font->glyphs[t].name && !strcmp(font->glyphs[t].name,charname)) { msg(" Char [%d,>%s<,%d] maps to %d\n", charnr, charname, u, t); @@ -1137,17 +1162,30 @@ int getGfxCharID(gfxfont_t*font, int charnr, char *charname, int u) } } + if(uniname) { + int t; + for(t=0;tnum_glyphs;t++) { + if(font->glyphs[t].name && !strcmp(font->glyphs[t].name,uniname)) { + msg(" Char [%d,%s,>%d(%s)<] maps to %d\n", charnr, charname, u, uniname, t); + return t; + } + } + /* if we didn't find the character, maybe + we can find the capitalized version */ + for(t=0;tnum_glyphs;t++) { + if(font->glyphs[t].name && !strcasecmp(font->glyphs[t].name,uniname)) { + msg(" Char [%d,%s,>>%d(%s)<<] maps to %d\n", charnr, charname, u, uniname, t); + return t; + } + } + } + /* try to use the unicode id */ if(u>=0 && umax_unicode && font->unicode2glyph[u]>=0) { msg(" Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->unicode2glyph[u]); return font->unicode2glyph[u]; } - /* we don't need to "draw" space characters, so don't overdo the search - for a matching glyph */ - if(charname && !strcasecmp(charname, "space")) - return -1; - if(charnr>=0 && charnrnum_glyphs) { msg(" Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr); return charnr; @@ -1214,22 +1252,6 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, Unicode u=0; char*name=0; - if(_u && uLen) { - u = *_u; - if (u) { - int t; - /* find out char name from unicode index - TODO: should be precomputed - */ - for(t=0;tisCIDFont()) { GfxCIDFont*cfont = (GfxCIDFont*)font; @@ -1239,9 +1261,7 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, Gfx8BitFont*font8; font8 = (Gfx8BitFont*)font; char**enc=font8->getEncoding(); - if(enc && enc[c] && strcasecmp(enc[c], "space")) { - name = enc[c]; - } + name = enc[c]; } if (CIDToGIDMap) { msg(" drawChar(%f, %f, c='%c' (%d), GID=%d, u=%d <%d>) CID=%d name=\"%s\" render=%d\n", x, y, (c&127)>=32?c:'?', c, CIDToGIDMap[c], u, uLen, font->isCIDFont(), FIXNULL(name), render); @@ -1255,7 +1275,8 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, if(uLen<=1) { charid = getGfxCharID(current_gfxfont, c, name, u); } else { - charid = getGfxCharID(current_gfxfont, c, 0, -1); + charid = getGfxCharID(current_gfxfont, c, name, -1); + if(charid < 0) { /* multiple unicodes- should usually map to a ligature. if the ligature doesn't exist, we need to draw @@ -1268,12 +1289,9 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, return; } } - if(charid<0) { - if(!name || strcasecmp(name, "space")) { - msg(" Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)", - FIXNULL(name),c, u, FIXNULL((char*)current_font_id), current_gfxfont->num_glyphs); - } + msg(" Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)", + FIXNULL(name),c, u, FIXNULL((char*)current_font_id), current_gfxfont->num_glyphs); return; } @@ -1973,7 +1991,7 @@ void SWFOutputDev::setXRef(PDFDoc*doc, XRef *xref) this->xref = xref; } -int SWFOutputDev::setGfxFont(char*id, char*filename, double maxSize) +int SWFOutputDev::setGfxFont(char*id, char*name, char*filename, double maxSize) { gfxfont_t*font = 0; fontlist_t*last=0,*l = this->fontlist; @@ -2025,7 +2043,10 @@ void SWFOutputDev::updateFont(GfxState *state) if (!gfxFont) { return; } + char * fontid = getFontID(gfxFont); + char * fontname = getFontName(gfxFont); + double maxSize = 1.0; if(this->info) { @@ -2046,8 +2067,9 @@ void SWFOutputDev::updateFont(GfxState *state) /* second, see if this is a font which was used before- if so, we are done */ - if(setGfxFont(fontid, 0, 0)) { + if(setGfxFont(fontid, fontname, 0, 0)) { free(fontid); + free(fontname); return; } /* if(swfoutput_queryfont(&output, fontid)) @@ -2064,6 +2086,7 @@ void SWFOutputDev::updateFont(GfxState *state) showFontError(gfxFont, 2); } free(fontid); + free(fontname); return; } @@ -2086,10 +2109,8 @@ void SWFOutputDev::updateFont(GfxState *state) if(!fileName) showFontError(gfxFont,0); else del = 1; } else { - char * fontname = getFontName(gfxFont); fileName = searchFont(fontname); if(!fileName) showFontError(gfxFont,0); - free(fontname); } if(!fileName) { char * fontname = getFontName(gfxFont); @@ -2108,6 +2129,7 @@ void SWFOutputDev::updateFont(GfxState *state) if(!fileName) { msg(" Couldn't set font %s\n", fontid); free(fontid); + free(fontname); return; } @@ -2116,15 +2138,17 @@ void SWFOutputDev::updateFont(GfxState *state) //swfoutput_setfont(&output, fontid, fileName); - if(!setGfxFont(fontid, 0, 0)) { - setGfxFont(fontid, fileName, maxSize); + if(!setGfxFont(fontid, fontname, 0, 0)) { + setGfxFont(fontid, fontname, fileName, maxSize); } if(fileName && del) unlinkfont(fileName); + if(fileName) free(fileName); free(fontid); + free(fontname); msg(" |"); }