X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=43f106fee8bb2b793d06fa5cc6b64674fefa8696;hb=33ad8406854ea77f18f849ab77f1efdf7ceafc7f;hp=fd753d5515bc490eb406ce07cf3bdbe4b4da4040;hpb=480131039d71c83b6ce63e85f4d285b2ee1770eb;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index fd753d5..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 @@ -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() { @@ -973,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) @@ -990,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()"); } @@ -1598,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) { @@ -1622,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); @@ -1683,6 +1747,10 @@ void SWFOutputDev::updateFont(GfxState *state) dumpFontInfo("", gfxFont); swfoutput_setfont(&output, fontid, fileName); + + if(!setGfxFont(fontid, 0)) { + setGfxFont(fontid, fileName); + } if(fileName && del) unlinkfont(fileName);