X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=2728dcb24d87889f252dc3e0a713b89bdbfbef2e;hb=eea310f329b7409684f825c92a58dcc22b1de506;hp=75d19e6bcf619dd99504ccd70e024488d42344cd;hpb=6db19c6950178d441f3a1ac99cda7cbf76d994a8;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index 75d19e6..2728dcb 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -88,6 +88,7 @@ static int pagepos = 0; /* config */ static double caplinewidth = 3.0; static int zoom = 72; /* xpdf: 86 */ +static int forceType0Fonts = 0; static void printInfoString(Dict *infoDict, char *key, char *fmt); static void printInfoDate(Dict *infoDict, char *key, char *fmt); @@ -126,6 +127,8 @@ public: void setClip(int x1,int y1,int x2,int y2); int save(char*filename); + void pagefeed(); + void* getSWF(); void getDimensions(int*x1,int*y1,int*x2,int*y2); @@ -353,10 +356,7 @@ void SWFOutputDev::setClip(int x1,int y1,int x2,int y2) } void SWFOutputDev::getDimensions(int*x1,int*y1,int*x2,int*y2) { - if(x1) *x1 = output.swf.movieSize.xmin/20; - if(y1) *y1 = output.swf.movieSize.ymin/20; - if(x2) *x2 = output.swf.movieSize.xmax/20; - if(y2) *y2 = output.swf.movieSize.ymax/20; + return swfoutput_getdimensions(&output, x1,y1,x2,y2); } static char*getFontID(GfxFont*font) @@ -799,10 +799,20 @@ void SWFOutputDev::eoClip(GfxState *state) clipping[clippos] ++; free_outline(outline); } + +/* pass through functions for swf_output */ int SWFOutputDev::save(char*filename) { return swfoutput_save(&output, filename); } +void SWFOutputDev::pagefeed() +{ + swfoutput_pagefeed(&output); +} +void* SWFOutputDev::getSWF() +{ + return (void*)swfoutput_get(&output); +} SWFOutputDev::~SWFOutputDev() { @@ -846,7 +856,7 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, // check for invisible text -- this is used by Acrobat Capture if ((state->getRender() & 3) == 3) return; - + Gushort *CIDToGIDMap = 0; GfxFont*font = state->getFont(); if(font->getType() == fontType3) { @@ -859,20 +869,29 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, state->transform(x, y, &x1, &y1); Unicode u=0; - if(_u && uLen) + 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() && u) { + if(font->isCIDFont()) { GfxCIDFont*cfont = (GfxCIDFont*)font; - int t; - for(t=0;tgetType() == fontCIDType2) { + CIDToGIDMap = cfont->getCIDToGID(); } } else { Gfx8BitFont*font8; @@ -881,13 +900,14 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, if(enc && enc[c]) name = enc[c]; } - - 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)); - - /*x1 = (int)(x1+0.5); - y1 = (int)(y1+0.5);*/ - - int ret = swfoutput_drawchar(&output, x1, y1, name, c, u); + + if (CIDToGIDMap) { + msg(" drawChar(%f, %f, c='%c' (%d), GID=%d, u=%d <%d>) CID=%d name=\"%s\"\n", x, y, (c&127)>=32?c:'?', c, CIDToGIDMap[c], u, uLen, font->isCIDFont(), FIXNULL(name)); + swfoutput_drawchar(&output, x1, y1, name, CIDToGIDMap[c], u); + } else { + 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)); + swfoutput_drawchar(&output, x1, y1, name, c, u); + } } void SWFOutputDev::endString(GfxState *state) { @@ -937,10 +957,10 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl /* apply user clip box */ if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) { - if(user_clipx1 > x1) x1 = user_clipx1; - if(user_clipx2 < x2) x2 = user_clipx2; - if(user_clipy1 > y1) y1 = user_clipy1; - if(user_clipy2 < y2) y2 = user_clipy2; + /*if(user_clipx1 > x1)*/ x1 = user_clipx1; + /*if(user_clipx2 < x2)*/ x2 = user_clipx2; + /*if(user_clipy1 > y1)*/ y1 = user_clipy1; + /*if(user_clipy2 < y2)*/ y2 = user_clipy2; } if(!outputstarted) { @@ -1241,9 +1261,11 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) } #ifdef XPDF_101 Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen); + if(!cvt) return 0; cvt->convertToType1(f); #else FoFiType1C *cvt = FoFiType1C::make(fontBuf, fontLen); + if(!cvt) return 0; cvt->convertToType1(NULL, gTrue, FoFiWrite, f); #endif //cvt->convertToCIDType0("test", f); @@ -1429,6 +1451,10 @@ char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname) fontname = "Times-Roman"; } filename = searchFont(fontname); + if(!filename) { + msg(" Couldn't find font %s- did you install the default fonts?"); + return 0; + } if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) { msg(" Too many fonts in file."); @@ -1528,7 +1554,7 @@ void SWFOutputDev::updateFont(GfxState *state) if(embedded && (gfxFont->getType() == fontType1 || gfxFont->getType() == fontType1C || - //gfxFont->getType() == fontCIDType0C || + (gfxFont->getType() == fontCIDType0C && forceType0Fonts) || gfxFont->getType() == fontTrueType || gfxFont->getType() == fontCIDType2 )) @@ -1940,6 +1966,8 @@ void pdfswf_setparameter(char*name, char*value) caplinewidth = atof(value); } else if(!strcmp(name, "zoom")) { zoom = atoi(value); + } else if(!strcmp(name, "forceType0Fonts")) { + forceType0Fonts = atoi(value); } else if(!strcmp(name, "fontdir")) { pdfswf_addfontdir(value); } else if(!strcmp(name, "languagedir")) { @@ -2203,6 +2231,13 @@ void swf_output_setparameter(swf_output_t*swf_output, char*name, char*value) pdfswf_setparameter(name, value); } +void swf_output_pagefeed(swf_output_t*swf) +{ + swf_output_internal_t*i= (swf_output_internal_t*)swf->internal; + i->outputDev->pagefeed(); + i->outputDev->getDimensions(&swf->x1, &swf->y1, &swf->x2, &swf->y2); +} + int swf_output_save(swf_output_t*swf, char*filename) { swf_output_internal_t*i= (swf_output_internal_t*)swf->internal; @@ -2211,6 +2246,14 @@ int swf_output_save(swf_output_t*swf, char*filename) return ret; } +void* swf_output_get(swf_output_t*swf) +{ + swf_output_internal_t*i= (swf_output_internal_t*)swf->internal; + void* ret = i->outputDev->getSWF(); + i->outputDev->getDimensions(&swf->x1, &swf->y1, &swf->x2, &swf->y2); + return ret; +} + void swf_output_destroy(swf_output_t*output) { swf_output_internal_t*i = (swf_output_internal_t*)output->internal;