X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=db114bc2deba97b10af9091885c62932c188e38c;hb=9a82ed9f9c7189bc59a84a1326dc4a7e9d06ee0e;hp=8624e6c914e36394127488160e55c02708667845;hpb=05e5fc2fb31a0b5ed74e5e31d917150ad8335a9a;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index 8624e6c..db114bc 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) ; @@ -624,8 +624,6 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, double originX, double originY, CharCode c, Unicode *_u, int uLen) { - msg(" drawChar(%f,%f,%f,%f,'%c')\n",x,y,dx,dy,c); - // check for invisible text -- this is used by Acrobat Capture if ((state->getRender() & 3) == 3) return; @@ -640,13 +638,16 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, x1 = x; y1 = y; state->transform(x, y, &x1, &y1); + + Unicode u=0; + if(_u) + u = *_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; - Unicode u=0; char*name=0; - if(_u) - u = *_u; if(u) { int t; for(t=0;tgetName()->getCString(), - cfont->getType());*/ 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; @@ -700,18 +700,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 @@ -976,19 +986,6 @@ void SWFOutputDev::updateStrokeColor(GfxState *state) (char)(rgb.b*255), (char)(opaq*255)); } -static char* tempFile(char*filename) -{ - char*dir = getenv("TMP"); - if(!dir) dir = getenv("TEMP"); - if(!dir) dir = getenv("tmp"); - if(!dir) dir = getenv("temp"); - if(!dir) dir = "C:\\"; - static char buf[512]; - strcpy(buf, dir); - strcat(buf, filename); - return buf; -} - char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) { char*tmpFileName = NULL; @@ -996,14 +993,10 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) int c; char *fontBuf; int fontLen; - Type1CFontFile *cvt; Ref embRef; Object refObj, strObj; -#ifdef WIN32 - tmpFileName = tempFile("tmpfont"); -#else - tmpFileName = "/tmp/tmpfont"; -#endif + char namebuf[512]; + tmpFileName = mktmpname(namebuf); int ret; ret = font->getEmbeddedFontID(&embRef); @@ -1019,16 +1012,28 @@ 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"); return 0; } - cvt = new Type1CFontFile(fontBuf, fontLen); + Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen); cvt->convertToType1(f); delete cvt; gfree(fontBuf); + } else if(font->getType() == fontTrueType) { + msg(" writing font using TrueTypeFontFile::writeTTF"); + if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) { + fclose(f); + msg(" Couldn't read embedded font file"); + return 0; + } + TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen); + cvt->writeTTF(f); + delete cvt; + gfree(fontBuf); } else { font->getEmbeddedFontID(&embRef); refObj.initRef(embRef.num, embRef.gen); @@ -1072,25 +1077,25 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) msg(" File contains TrueType fonts"); ttfinfo = 1; } - char name2[80]; + char name2[512]; char*tmp; tmp = strdup(mktmpname((char*)name2)); sprintf(name2, "%s", tmp); - char*a[] = {"./ttf2pt1", "-W0", + char*a[] = {"./ttf2pt1", "-W", "0", #ifndef USE_FREETYPE - "-pttf", + "-p", "ttf", #else - "-pft", + "-p", "ft", #endif "-b", tmpFileName, name2}; - msg(" Invoking %s %s %s %s %s %s",a[0],a[1],a[2],a[3],a[4],a[5]); - ttf2pt1_main(6,a); + 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); sprintf(name2,"%s.pfb",tmp); tmpFileName = strdup(name2); } - return tmpFileName; + return strdup(tmpFileName); } char* gfxFontName(GfxFont* gfxFont) @@ -1297,9 +1302,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) { @@ -1321,6 +1328,7 @@ void SWFOutputDev::updateFont(GfxState *state) font directories */ int newt1id = searchT1Font(fontname); if(newt1id<0) { + msg(" Couldn't find any suitable replacement for %s",fontname); showFontError(gfxFont,0); fontname = substituteFont(gfxFont, fontname); } else @@ -1342,7 +1350,8 @@ void SWFOutputDev::updateFont(GfxState *state) } if(t1id<0) { - showFontError(gfxFont,0); + msg(" Current font's t1id is %d", t1id); + //showFontError(gfxFont,0); return; }