X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=43f106fee8bb2b793d06fa5cc6b64674fefa8696;hb=33ad8406854ea77f18f849ab77f1efdf7ceafc7f;hp=384ca7547f08f7fc77378e3a0e1fcff9a4bc4447;hpb=87cb7adfdd62489ece9ebf4f17723608086e262d;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index 384ca75..43f106f 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -29,7 +29,7 @@ #ifdef HAVE_SYS_STAT_H #include #endif -#ifdef HAVE_FONTCONFIG_H +#ifdef HAVE_FONTCONFIG #include #endif //xpdf header files @@ -65,7 +65,8 @@ #include "swfoutput.h" #include "../lib/log.h" #include "../lib/gfxdevice.h" -#include "gfxtools.h" +#include "../lib/gfxtools.h" +#include "../lib/gfxfont.h" #include @@ -90,7 +91,7 @@ static int pagepos = 0; /* config */ static double caplinewidth = 3.0; static int zoom = 72; /* xpdf: 86 */ -static int forceType0Fonts = 0; +static int forceType0Fonts = 1; static void printInfoString(Dict *infoDict, char *key, char *fmt); static void printInfoDate(Dict *infoDict, char *key, char *fmt); @@ -124,6 +125,14 @@ class SWFOutputState { } }; +typedef struct _fontlist +{ + char*id; + char*filename; + gfxfont_t*font; + _fontlist*next; +} fontlist_t; + class SWFOutputDev: public OutputDev { int outputstarted; struct swfoutput output; @@ -227,6 +236,8 @@ public: void drawGeneralImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap*colorMap, GBool invert, GBool inlineImg, int mask, int *maskColors); + int SWFOutputDev::setGfxFont(char*id, char*filename); + SWFOutputState states[64]; int statepos; @@ -257,6 +268,11 @@ public: int user_movex,user_movey; int user_clipx1,user_clipx2,user_clipy1,user_clipy2; + + gfxline_t* current_text_stroke; + char* current_font_id; + gfxfont_t* current_gfxfont; + fontlist_t* fontlist; }; static char*getFontID(GfxFont*font); @@ -339,6 +355,8 @@ SWFOutputDev::SWFOutputDev() user_clipy1 = 0; user_clipx2 = 0; user_clipy2 = 0; + current_text_stroke = 0; + fontlist = 0; memset(&output, 0, sizeof(output)); // printf("SWFOutputDev::SWFOutputDev() \n"); }; @@ -839,6 +857,17 @@ SWFOutputDev::~SWFOutputDev() { swfoutput_destroy(&output); outputstarted = 0; + + fontlist_t*l = this->fontlist; + while(l) { + fontlist_t*next = l->next; + l->next = 0; + gfxfont_free(l->font); + free(l->id); + free(l->filename); + free(l); + l = next; + } }; GBool SWFOutputDev::upsideDown() { @@ -862,6 +891,32 @@ GBool SWFOutputDev::useGradients() char*renderModeDesc[]= {"fill", "stroke", "fill+stroke", "invisible", "clip+fill", "stroke+clip", "fill+stroke+clip", "clip"}; +static char tmp_printstr[4096]; +char* makeStringPrintable(char*str) +{ + int len = strlen(str); + int dots = 0; + if(len>=80) { + len = 80; + dots = 1; + } + int t; + for(t=0;t124) { + c = '.'; + } + tmp_printstr[t] = c; + } + if(dots) { + tmp_printstr[len++] = '.'; + tmp_printstr[len++] = '.'; + tmp_printstr[len++] = '.'; + } + tmp_printstr[len] = 0; + return tmp_printstr; +} + void SWFOutputDev::beginString(GfxState *state, GString *s) { int render = state->getRender(); @@ -873,7 +928,7 @@ void SWFOutputDev::beginString(GfxState *state, GString *s) m21 *= state->getHorizScaling(); swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22); if(render != 3 && render != 0) - msg(" Text rendering mode %d (%s) not fully supported yet (for text \"%s\")", render, renderModeDesc[render&7], s->getCString()); + msg(" Text rendering mode %d (%s) not fully supported yet (for text \"%s\")", render, renderModeDesc[render&7], makeStringPrintable(s->getCString())); states[statepos].textRender = render; } @@ -947,14 +1002,14 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, if(enc && 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); - swfoutput_drawchar(&output, x1, y1, name, CIDToGIDMap[c], u, &col); + c = CIDToGIDMap[c]; } else { msg(" drawChar(%f,%f,c='%c' (%d), u=%d <%d>) CID=%d name=\"%s\" render=%d\n",x,y,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name), render); - swfoutput_drawchar(&output, x1, y1, name, c, u, &col); } + + swfoutput_drawchar(&output, x1, y1, name, c, u, &col); } void SWFOutputDev::endString(GfxState *state) @@ -964,6 +1019,8 @@ void SWFOutputDev::endString(GfxState *state) void SWFOutputDev::endTextObject(GfxState *state) { + if(states[statepos].textRender != state->getRender()) + msg(" Internal error: drawChar.render!=beginString.render"); msg(" endTextObject()"); } @@ -1572,6 +1629,38 @@ void SWFOutputDev::setXRef(PDFDoc*doc, XRef *xref) this->xref = xref; } +int SWFOutputDev::setGfxFont(char*id, char*filename) +{ + gfxfont_t*font = 0; + fontlist_t*last=0,*l = this->fontlist; + + /* TODO: should this be part of the state? */ + while(l) { + last = l; + if(!strcmp(l->id, id)) { + current_font_id = l->id; + current_gfxfont = l->font; + font = l->font; + return 1; + } + l = l->next; + } + if(!filename) return 0; + font = gfxfont_load(filename); + l = new fontlist_t; + l->font = font; + l->filename = strdup(filename); + l->id = strdup(id); + l->next = 0; + current_font_id = l->id; + current_gfxfont = l->font; + if(last) { + last->next = l; + } else { + this->fontlist = l; + } + return 1; +} void SWFOutputDev::updateFont(GfxState *state) { @@ -1596,6 +1685,7 @@ void SWFOutputDev::updateFont(GfxState *state) /* second, see if swfoutput already has this font cached- if so, we are done */ + setGfxFont(fontid, 0); if(swfoutput_queryfont(&output, fontid)) { swfoutput_setfont(&output, fontid, 0); @@ -1657,9 +1747,13 @@ void SWFOutputDev::updateFont(GfxState *state) dumpFontInfo("", gfxFont); swfoutput_setfont(&output, fontid, fileName); + + if(!setGfxFont(fontid, 0)) { + setGfxFont(fontid, fileName); + } - /*if(fileName && del) - unlinkfont(fileName);*/ + if(fileName && del) + unlinkfont(fileName); if(fileName) free(fileName); free(fontid);