X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=dc5ddad4932391084e25ebf9a31bac7055faaf32;hb=bbcfffddca05b2a29c2beaf0ed48038e5147f0b2;hp=e2ced417f3e177657852fbe0a55c14e7e3cc1728;hpb=9f87d4fc88247a11fa58cfbdaaaf52d3fdfb10e4;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index e2ced41..dc5ddad 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -144,7 +144,7 @@ public: void startDoc(XRef *xref); // Start a page. - virtual void startPage(int pageNum, GfxState *state) ; + virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ; //----- link borders virtual void drawLink(Link *link, Catalog *catalog) ; @@ -224,6 +224,22 @@ public: GfxState *laststate; }; +char*getFontName(GfxFont*font) +{ + 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* plus = strchr(fontname, '+'); + if(plus && plus < &fontname[strlen(fontname)-1]) + fontname = plus+1; + return fontname; +} + char mybuf[1024]; char* gfxstate2str(GfxState *state) { @@ -303,8 +319,8 @@ char* gfxstate2str(GfxState *state) if(state->getLineJoin()!=0) bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit()); - if(state->getFont() && state->getFont()->getName() && state->getFont()->getName()->getCString()) - bufpos+=sprintf(bufpos,"F\"%s\" ",((state->getFont())->getName())->getCString()); + if(state->getFont() && getFontName(state->getFont())) + bufpos+=sprintf(bufpos,"F\"%s\" ",getFontName(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]); @@ -331,6 +347,8 @@ char* gfxstate2str(GfxState *state) return mybuf; } + + void dumpFontInfo(char*loglevel, GfxFont*font); int lastdumps[1024]; int lastdumppos = 0; @@ -360,15 +378,13 @@ void showFontError(GfxFont*font, int nr) void dumpFontInfo(char*loglevel, GfxFont*font) { - GString *gstr; - char*name = 0; - gstr = font->getName(); + char* name = getFontName(font); Ref* r=font->getID(); - msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, gstr?FIXNULL(gstr->getCString()):"(unknown font)", r->num,r->gen); + msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, name, r->num,r->gen); - gstr = font->getTag(); - if(gstr) - msg("%sTag: %s\n", loglevel, FIXNULL(gstr->getCString())); + GString*gstr = font->getTag(); + + msg("%sTag: %s\n", loglevel, name); if(font->isCIDFont()) msg("%sis CID font\n", loglevel); @@ -643,7 +659,7 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, if(_u) u = *_u; - msg(" drawChar(%f,%f,%f,%f,'%c',%d)\n",x,y,dx,dy,c,u); + msg(" drawChar(%f,%f,%f,%f,'%c',%d) CID=%d\n",x,y,dx,dy,c,u, font->isCIDFont()); if(font->isCIDFont()) { GfxCIDFont*cfont = (GfxCIDFont*)font; @@ -660,9 +676,10 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, if(name) swfoutput_drawchar(&output, x1, y1, name, c); - else + else { msg(" couldn't get name for CID character %02x from Encoding", c); swfoutput_drawchar(&output, x1, y1, "", c); + } } else { Gfx8BitFont*font8; font8 = (Gfx8BitFont*)font; @@ -699,18 +716,28 @@ void SWFOutputDev::endType3Char(GfxState *state) msg(" endType3Char"); } -void SWFOutputDev::startPage(int pageNum, GfxState *state) +void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) { double x1,y1,x2,y2; laststate = state; - msg(" startPage %d\n", pageNum); + msg(" startPage %d (%f,%f,%f,%f)\n", pageNum, crop_x1, crop_y1, crop_x2, crop_y2); msg(" processing page %d", pageNum); - state->transform(state->getX1(),state->getY1(),&x1,&y1); + /* state->transform(state->getX1(),state->getY1(),&x1,&y1); state->transform(state->getX2(),state->getY2(),&x2,&y2); + Use CropBox, not MediaBox, as page size + */ + x1 = crop_x1; + y1 = crop_y1; + x2 = crop_x2; + y2 = crop_y2; + + if(x2 Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2); - swfoutput_init(&output, swffilename, abs((int)(x2-x1)),abs((int)(y2-y1))); + swfoutput_init(&output, swffilename,(int)x1,(int)y1,(int)x2,(int)y2); outputstarted = 1; } else @@ -1001,7 +1028,8 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) msg(" Couldn't create temporary Type 1 font file"); return 0; } - if (font->getType() == fontType1C) { + if (font->getType() == fontType1C || + font->getType() == fontCIDType0C) { if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) { fclose(f); msg(" Couldn't read embedded font file"); @@ -1078,7 +1106,7 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) "-b", tmpFileName, name2}; msg(" Invoking %s %s %s %s %s %s %s %s",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]); ttf2pt1_main(8,a); - //unlink(tmpFileName); + unlink(tmpFileName); sprintf(name2,"%s.pfb",tmp); tmpFileName = strdup(name2); } @@ -1086,20 +1114,6 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) return strdup(tmpFileName); } -char* gfxFontName(GfxFont* gfxFont) -{ - GString *gstr; - gstr = gfxFont->getName(); - if(gstr) { - return gstr->getCString(); - } - else { - char buf[32]; - Ref*r=gfxFont->getID(); - sprintf(buf, "UFONT%d", r->num); - return strdup(buf); - } -} char* substitutetarget[256]; char* substitutesource[256]; @@ -1119,7 +1133,7 @@ char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname) if(oldname) { substitutesource[substitutepos] = oldname; substitutetarget[substitutepos] = fontname; - msg(" substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname)); + msg(" substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname)); substitutepos ++; } return fontname; @@ -1256,7 +1270,7 @@ void SWFOutputDev::updateFont(GfxState *state) if (!gfxFont) { return; } - char * fontname = gfxFontName(gfxFont); + char * fontname = getFontName(gfxFont); int t; /* first, look if we substituted this font before- @@ -1290,9 +1304,11 @@ void SWFOutputDev::updateFont(GfxState *state) GBool embedded = gfxFont->getEmbeddedFontID(&embRef); if(embedded) { if (gfxFont->getType() == fontType1 || + gfxFont->getType() == fontCIDType0C || gfxFont->getType() == fontType1C || gfxFont->getType() == fontTrueType || - gfxFont->getType() == fontCIDType2) + gfxFont->getType() == fontCIDType2 + ) { fileName = writeEmbeddedFontToFile(xref, gfxFont); if(!fileName) {