From: kramm Date: Thu, 12 Aug 2004 12:57:41 +0000 (+0000) Subject: fixed problem where the wrong fonts were searched for a character. X-Git-Tag: release-0-6-0~30 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=c719bed1f195a35d47372270214c528e4bb5430d fixed problem where the wrong fonts were searched for a character. --- diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index 8d564a7..fea0d24 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -226,7 +226,7 @@ public: GfxState *laststate; }; -char*getFontName(GfxFont*font) +static char*getFontID(GfxFont*font) { GString*gstr = font->getName(); char* fontname = gstr==0?0:gstr->getCString(); @@ -236,6 +236,12 @@ char*getFontName(GfxFont*font) sprintf(buf, "UFONT%d", r->num); return strdup(buf); } + return fontname; +} + +static char*getFontName(GfxFont*font) +{ + char*fontname = getFontID(font); char* plus = strchr(fontname, '+'); if(plus && plus < &fontname[strlen(fontname)-1]) fontname = plus+1; @@ -321,8 +327,8 @@ char* gfxstate2str(GfxState *state) if(state->getLineJoin()!=0) bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit()); - if(state->getFont() && getFontName(state->getFont())) - bufpos+=sprintf(bufpos,"F\"%s\" ",getFontName(state->getFont())); + if(state->getFont() && getFontID(state->getFont())) + bufpos+=sprintf(bufpos,"F\"%s\" ",getFontID(state->getFont())); bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize()); bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2], state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]); @@ -380,7 +386,7 @@ void showFontError(GfxFont*font, int nr) void dumpFontInfo(char*loglevel, GfxFont*font) { - char* name = getFontName(font); + char* name = getFontID(font); Ref* r=font->getID(); msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, name, r->num,r->gen); @@ -679,7 +685,7 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, name = enc[c]; } - msg(" drawChar(%f,%f,c='%c' (%d),u=%d <%d>) CID=%d name=\"%s\"\n",x1,y1,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name)); + msg(" drawChar(%f,%f,c='%c' (%d),u=%d <%d>) CID=%d name=\"%s\"\n",x,y,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name)); int ret = swfoutput_drawchar(&output, x1, y1, name, c, u); } @@ -996,6 +1002,13 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) msg(" Couldn't create temporary Type 1 font file"); return 0; } + + /*if(font->isCIDFont()) { + GfxCIDFont* cidFont = (GfxCIDFont *)font; + GString c = cidFont->getCollection(); + msg(" Collection: %s", c.getCString()); + }*/ + if (font->getType() == fontType1C || font->getType() == fontCIDType0C) { if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) { @@ -1005,6 +1018,8 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) } Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen); cvt->convertToType1(f); + //cvt->convertToCIDType0("test", f); + //cvt->convertToType0("test", f); delete cvt; gfree(fontBuf); } else if(font->getType() == fontTrueType) { @@ -1122,26 +1137,26 @@ void SWFOutputDev::updateFont(GfxState *state) if (!gfxFont) { return; } - char * fontname = getFontName(gfxFont); + char * fontid = getFontID(gfxFont); int t; /* first, look if we substituted this font before- this way, we don't initialize the T1 Fonts too often */ for(t=0;t updateFont(%s) [cached]", fontname); + msg(" updateFont(%s) [cached]", fontid); return; } @@ -1160,8 +1175,8 @@ void SWFOutputDev::updateFont(GfxState *state) int del = 0; if(embedded && (gfxFont->getType() == fontType1 || - //gfxFont->getType() == fontCIDType0C || gfxFont->getType() == fontType1C || + //gfxFont->getType() == fontCIDType0C || gfxFont->getType() == fontTrueType || gfxFont->getType() == fontCIDType2 )) @@ -1170,24 +1185,26 @@ 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); } if(!fileName) { + char * fontname = getFontName(gfxFont); msg(" Font %s could not be loaded.", fontname); msg(" Try putting a TTF version of that font (named \"%s.ttf\") into /swftools/fonts", fontname); - fileName = substituteFont(gfxFont, fontname); + fileName = substituteFont(gfxFont, fontid); } if(!fileName) { - msg(" Couldn't set font %s\n", fontname); + msg(" Couldn't set font %s\n", fontid); return; } - msg(" updateFont(%s) -> %s", fontname, fileName); + msg(" updateFont(%s) -> %s", fontid, fileName); dumpFontInfo("", gfxFont); - swfoutput_setfont(&output, fontname, fileName); + swfoutput_setfont(&output, fontid, fileName); if(fileName && del) unlinkfont(fileName);