+class InfoOutputDev: public OutputDev
+{
+ GHash* id2font;
+ FontInfo* currentfont;
+ public:
+ int x1,y1,x2,y2;
+ int num_links;
+ int num_images;
+ int num_fonts;
+
+ InfoOutputDev()
+ {
+ num_links = 0;
+ num_images = 0;
+ num_fonts = 0;
+ id2font = new GHash();
+ }
+ virtual ~InfoOutputDev()
+ {
+ delete id2font;
+ }
+ virtual GBool upsideDown() {return gTrue;}
+ virtual GBool useDrawChar() {return gTrue;}
+ virtual GBool interpretType3Chars() {return gTrue;}
+ virtual void startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
+ {
+ double x1,y1,x2,y2;
+ state->transform(crop_x1,crop_y1,&x1,&y1);
+ state->transform(crop_x2,crop_y2,&x2,&y2);
+ if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
+ if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
+ this->x1 = (int)x1;
+ this->y1 = (int)y1;
+ this->x2 = (int)x2;
+ this->y2 = (int)y2;
+ }
+ virtual void drawLink(Link *link, Catalog *catalog)
+ {
+ num_links++;
+ }
+ virtual double getMaximumFontSize(char*id)
+ {
+ FontInfo*info = (FontInfo*)id2font->lookup(id);
+ if(!info) {
+ msg("<error> Unknown font id: %s", id);
+ return 0.0;
+ }
+ return info->max_size;
+ }
+
+ virtual void updateFont(GfxState *state)
+ {
+ GfxFont*font = state->getFont();
+ if(!font)
+ return;
+ char*id = getFontID(font);
+
+ FontInfo*info = (FontInfo*)id2font->lookup(id);
+ if(!info) {
+ GString* idStr = new GString(id);
+ info = new FontInfo;
+ info->font = font;
+ info->max_size = 0;
+ id2font->add(idStr, (void*)info);
+ free(id);
+ num_fonts++;
+ }
+ currentfont = info;
+ }
+
+ virtual void drawChar(GfxState *state, double x, double y,
+ double dx, double dy,
+ double originX, double originY,
+ CharCode code, int nBytes, Unicode *u, int uLen)
+ {
+ int render = state->getRender();
+ if (render == 3)
+ return;
+ double m11,m21,m12,m22;
+ state->getFontTransMat(&m11, &m12, &m21, &m22);
+ m11 *= state->getHorizScaling();
+ m21 *= state->getHorizScaling();
+ double lenx = sqrt(m11*m11 + m12*m12);
+ double leny = sqrt(m21*m21 + m22*m22);
+ double len = lenx>leny?lenx:leny;
+ if(currentfont && currentfont->max_size < len) {
+ currentfont->max_size = len;
+ }
+ }
+ virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
+ int width, int height, GBool invert,
+ GBool inlineImg)
+ {
+ num_images++;
+ }
+ virtual void drawImage(GfxState *state, Object *ref, Stream *str,
+ int width, int height, GfxImageColorMap *colorMap,
+ int *maskColors, GBool inlineImg)
+ {
+ num_images++;
+ }
+};
+
+SWFOutputDev::SWFOutputDev(gfxdevice_t*output)
+{
+ this->output = output;
+ this->jpeginfo = 0;
+ this->textmodeinfo = 0;
+ this->ttfinfo = 0;
+ this->linkinfo = 0;
+ this->pbminfo = 0;
+ this->type3active = 0;
+ this->statepos = 0;
+ this->xref = 0;
+ this->substitutepos = 0;
+ this->type3Warning = 0;
+ this->user_movex = 0;
+ this->user_movey = 0;
+ this->user_clipx1 = 0;
+ this->user_clipy1 = 0;
+ this->user_clipx2 = 0;
+ this->user_clipy2 = 0;
+ this->current_text_stroke = 0;
+ this->current_text_clip = 0;
+ this->fontlist = 0;
+ this->outer_clip_box = 0;
+ this->pages = 0;
+ this->pagebuflen = 0;
+ this->pagepos = 0;
+
+ /* configure device */
+ parameter_t*p = device_config;
+ while(p) {
+ output->setparameter(output, p->name, p->value);
+ p = p->next;
+ }
+};
+
+void SWFOutputDev::setMove(int x,int y)
+{
+ this->user_movex = x;
+ this->user_movey = y;
+}
+
+void SWFOutputDev::setClip(int x1,int y1,int x2,int y2)
+{
+ if(x2<x1) {int x3=x1;x1=x2;x2=x3;}
+ if(y2<y1) {int y3=y1;y1=y2;y2=y3;}
+
+ this->user_clipx1 = x1;
+ this->user_clipy1 = y1;
+ this->user_clipx2 = x2;
+ this->user_clipy2 = y2;
+}
+
+static char*getFontID(GfxFont*font)
+{
+ Ref*ref = font->getID();
+ GString*gstr = font->getName();
+ char* fname = gstr==0?0:gstr->getCString();
+ char buf[128];
+ if(fname==0) {
+ sprintf(buf, "font-%d-%d", ref->num, ref->gen);
+ } else {
+ sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
+ }
+ return strdup(buf);
+}
+
+static char*getFontName(GfxFont*font)
+{
+ char*fontid;
+ GString*gstr = font->getName();
+ char* fname = gstr==0?0:gstr->getCString();
+ if(fname==0) {
+ char buf[32];
+ Ref*r=font->getID();
+ sprintf(buf, "UFONT%d", r->num);
+ fontid = strdup(buf);
+ }
+ fontid = strdup(fname);
+
+ char*fontname= 0;
+ char* plus = strchr(fontid, '+');
+ if(plus && plus < &fontid[strlen(fontid)-1]) {
+ fontname = strdup(plus+1);
+ } else {
+ fontname = strdup(fontid);
+ }
+ free(fontid);
+ return fontname;
+}
+
+static char mybuf[1024];
+static char* gfxstate2str(GfxState *state)