2 implements a pdf output device (OutputDev).
4 This file is part of swftools.
6 Swftools is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Swftools is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with swftools; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25 #include "../config.h"
40 #include "OutputDev.h"
43 #include "CharCodeToUnicode.h"
44 #include "NameToUnicodeTable.h"
46 #include "GlobalParams.h"
47 //swftools header files
48 #include "swfoutput.h"
49 #include "../lib/log.h"
53 static PDFDoc*doc = 0;
54 static char* swffilename = 0;
56 static int currentpage;
58 typedef struct _fontfile
64 static fontfile_t fonts[2048];
65 static int fontnum = 0;
69 static int pagebuflen = 0;
70 static int pagepos = 0;
72 static double caplinewidth = 3.0;
74 static void printInfoString(Dict *infoDict, char *key, char *fmt);
75 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
77 static double fontsizes[] =
79 0.833,0.833,0.889,0.889,
80 0.788,0.722,0.833,0.778,
81 0.600,0.600,0.600,0.600,
82 0.576,0.576,0.576,0.576,
85 static char*fontnames[]={
88 "Helvetica-BoldOblique",
96 "Courier-BoldOblique",
110 {"Times-Roman", "n021003l"},
111 {"Times-Italic", "n021023l"},
112 {"Times-Bold", "n021004l"},
113 {"Times-BoldItalic", "n021024l"},
114 {"Helvetica", "n019003l"},
115 {"Helvetica-Oblique", "n019023l"},
116 {"Helvetica-Bold", "n019004l"},
117 {"Helvetica-BoldOblique", "n019024l"},
118 {"Courier", "n022003l"},
119 {"Courier-Oblique", "n022023l"},
120 {"Courier-Bold", "n022004l"},
121 {"Courier-BoldOblique", "n022024l"},
122 {"Symbol", "s050000l"},
123 {"ZapfDingbats", "d050000l"}};
126 class GfxImageColorMap;
128 class SWFOutputDev: public OutputDev {
129 struct swfoutput output;
137 virtual ~SWFOutputDev() ;
139 //----- get info about output device
141 // Does this device use upside-down coordinates?
142 // (Upside-down means (0,0) is the top left corner of the page.)
143 virtual GBool upsideDown();
145 // Does this device use drawChar() or drawString()?
146 virtual GBool useDrawChar();
148 virtual GBool interpretType3Chars() {return gTrue;}
150 //----- initialization and control
152 void startDoc(XRef *xref);
155 virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
158 virtual void drawLink(Link *link, Catalog *catalog) ;
160 //----- save/restore graphics state
161 virtual void saveState(GfxState *state) ;
162 virtual void restoreState(GfxState *state) ;
164 //----- update graphics state
166 virtual void updateFont(GfxState *state);
167 virtual void updateFillColor(GfxState *state);
168 virtual void updateStrokeColor(GfxState *state);
169 virtual void updateLineWidth(GfxState *state);
170 virtual void updateLineJoin(GfxState *state);
171 virtual void updateLineCap(GfxState *state);
173 virtual void updateAll(GfxState *state)
176 updateFillColor(state);
177 updateStrokeColor(state);
178 updateLineWidth(state);
179 updateLineJoin(state);
180 updateLineCap(state);
183 //----- path painting
184 virtual void stroke(GfxState *state) ;
185 virtual void fill(GfxState *state) ;
186 virtual void eoFill(GfxState *state) ;
188 //----- path clipping
189 virtual void clip(GfxState *state) ;
190 virtual void eoClip(GfxState *state) ;
193 virtual void beginString(GfxState *state, GString *s) ;
194 virtual void endString(GfxState *state) ;
195 virtual void drawChar(GfxState *state, double x, double y,
196 double dx, double dy,
197 double originX, double originY,
198 CharCode code, Unicode *u, int uLen);
200 //----- image drawing
201 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
202 int width, int height, GBool invert,
204 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
205 int width, int height, GfxImageColorMap *colorMap,
206 int *maskColors, GBool inlineImg);
208 virtual GBool beginType3Char(GfxState *state,
209 CharCode code, Unicode *u, int uLen);
210 virtual void endType3Char(GfxState *state);
213 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
214 int width, int height, GfxImageColorMap*colorMap, GBool invert,
215 GBool inlineImg, int mask);
221 char* searchFont(char*name);
222 char* substituteFont(GfxFont*gfxFont, char*oldname);
223 char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
225 int jpeginfo; // did we write "File contains jpegs" yet?
226 int pbminfo; // did we write "File contains jpegs" yet?
227 int linkinfo; // did we write "File contains links" yet?
228 int ttfinfo; // did we write "File contains TrueType Fonts" yet?
230 int type3active; // are we between beginType3()/endType3()?
235 static char*getFontID(GfxFont*font)
237 GString*gstr = font->getName();
238 char* fontname = gstr==0?0:gstr->getCString();
242 sprintf(buf, "UFONT%d", r->num);
248 static char*getFontName(GfxFont*font)
250 char*fontname = getFontID(font);
251 char* plus = strchr(fontname, '+');
252 if(plus && plus < &fontname[strlen(fontname)-1])
258 char* gfxstate2str(GfxState *state)
262 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
269 if(state->getX1()!=0.0)
270 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
271 if(state->getY1()!=0.0)
272 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
273 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
274 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
275 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
276 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
277 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
278 state->getFillColor()->c[0], state->getFillColor()->c[1]);
279 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
280 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
281 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
282 state->getFillColor()->c[0], state->getFillColor()->c[1],
283 state->getFillColor()->c[2], state->getFillColor()->c[3],
284 state->getFillColor()->c[4], state->getFillColor()->c[5],
285 state->getFillColor()->c[6], state->getFillColor()->c[7]);
286 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
287 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
288 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
289 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
290 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
291 state->getFillRGB(&rgb);
292 if(rgb.r || rgb.g || rgb.b)
293 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
294 state->getStrokeRGB(&rgb);
295 if(rgb.r || rgb.g || rgb.b)
296 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
297 if(state->getFillColorSpace()->getNComps()>1)
298 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
299 if(state->getStrokeColorSpace()->getNComps()>1)
300 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
301 if(state->getFillPattern())
302 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
303 if(state->getStrokePattern())
304 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
306 if(state->getFillOpacity()!=1.0)
307 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
308 if(state->getStrokeOpacity()!=1.0)
309 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
311 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
316 state->getLineDash(&dash, &length, &start);
320 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
321 for(t=0;t<length;t++) {
322 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
324 bufpos+=sprintf(bufpos,"]");
327 if(state->getFlatness()!=1)
328 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
329 if(state->getLineJoin()!=0)
330 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
331 if(state->getLineJoin()!=0)
332 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
333 if(state->getLineJoin()!=0)
334 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
336 if(state->getFont() && getFontID(state->getFont()))
337 bufpos+=sprintf(bufpos,"F\"%s\" ",getFontID(state->getFont()));
338 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
339 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
340 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
341 if(state->getCharSpace())
342 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
343 if(state->getWordSpace())
344 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
345 if(state->getHorizScaling()!=1.0)
346 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
347 if(state->getLeading())
348 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
350 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
351 if(state->getRender())
352 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
353 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
354 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
355 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
356 if(state->getLineX())
357 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
358 if(state->getLineY())
359 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
360 bufpos+=sprintf(bufpos," ");
366 void dumpFontInfo(char*loglevel, GfxFont*font);
373 void showFontError(GfxFont*font, int nr)
377 for(t=0;t<lastdumppos;t++)
378 if(lastdumps[t] == r->num)
382 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
383 lastdumps[lastdumppos++] = r->num;
385 msg("<warning> The following font caused problems:");
387 msg("<warning> The following font caused problems (substituting):");
389 msg("<warning> The following Type 3 Font will be rendered as bitmap:");
390 dumpFontInfo("<warning>", font);
393 void dumpFontInfo(char*loglevel, GfxFont*font)
395 char* name = getFontID(font);
396 Ref* r=font->getID();
397 msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, getFontName(font), r->num,r->gen);
399 GString*gstr = font->getTag();
401 msg("%s| Tag: %s\n", loglevel, name);
403 if(font->isCIDFont()) msg("%s| is CID font\n", loglevel);
405 GfxFontType type=font->getType();
407 case fontUnknownType:
408 msg("%s| Type: unknown\n",loglevel);
411 msg("%s| Type: 1\n",loglevel);
414 msg("%s| Type: 1C\n",loglevel);
417 msg("%s| Type: 3\n",loglevel);
420 msg("%s| Type: TrueType\n",loglevel);
423 msg("%s| Type: CIDType0\n",loglevel);
426 msg("%s| Type: CIDType0C\n",loglevel);
429 msg("%s| Type: CIDType2\n",loglevel);
434 GBool embedded = font->getEmbeddedFontID(&embRef);
435 if(font->getEmbeddedFontName())
436 name = font->getEmbeddedFontName()->getCString();
438 msg("%s| Embedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
440 gstr = font->getExtFontFile();
442 msg("%s| External Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
444 // Get font descriptor flags.
445 if(font->isFixedWidth()) msg("%s| is fixed width\n", loglevel);
446 if(font->isSerif()) msg("%s| is serif\n", loglevel);
447 if(font->isSymbolic()) msg("%s| is symbolic\n", loglevel);
448 if(font->isItalic()) msg("%s| is italic\n", loglevel);
449 if(font->isBold()) msg("%s| is bold\n", loglevel);
452 //void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) {printf("void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) \n");}
453 //void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool inlineImg) {printf("void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool inlineImg) \n");}
455 SWFOutputDev::SWFOutputDev()
463 clipping[clippos] = 0;
466 // printf("SWFOutputDev::SWFOutputDev() \n");
469 SWF_OUTLINE* gfxPath_to_SWF_OUTLINE(GfxState*state, GfxPath*path)
471 int num = path->getNumSubpaths();
473 bezierpathsegment*start,*last=0;
474 bezierpathsegment*outline = start = new bezierpathsegment();
476 double lastx=0,lasty=0;
478 msg("<warning> empty path");
479 outline->type = SWF_PATHTYPE_MOVE;
483 return (SWF_OUTLINE*)outline;
485 for(t = 0; t < num; t++) {
486 GfxSubpath *subpath = path->getSubpath(t);
487 int subnum = subpath->getNumPoints();
489 for(s=0;s<subnum;s++) {
491 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
492 int x = (int)((nx-lastx)*0xffff);
493 int y = (int)((ny-lasty)*0xffff);
497 outline->type = SWF_PATHTYPE_MOVE;
500 outline->link = (SWF_OUTLINE*)new bezierpathsegment();
501 outline = (bezierpathsegment*)outline->link;
506 else if(subpath->getCurve(s) && !cpos)
512 else if(subpath->getCurve(s) && cpos)
523 outline->type = cpos?SWF_PATHTYPE_BEZIER:SWF_PATHTYPE_LINE;
525 outline->link = (SWF_OUTLINE*)new bezierpathsegment();
526 outline = (bezierpathsegment*)outline->link;
534 return (SWF_OUTLINE*)start;
536 /*----------------------------------------------------------------------------
537 * Primitive Graphic routines
538 *----------------------------------------------------------------------------*/
540 void SWFOutputDev::stroke(GfxState *state)
542 msg("<debug> stroke\n");
543 GfxPath * path = state->getPath();
544 int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square
545 int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel
546 double miterLimit = state->getMiterLimit();
547 double width = state->getTransformedLineWidth();
550 double opaq = state->getStrokeOpacity();
551 state->getStrokeRGB(&rgb);
553 m.m11 = 1; m.m21 = 0; m.m22 = 1;
554 m.m12 = 0; m.m13 = 0; m.m23 = 0;
555 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
557 lineJoin = 1; // other line joins are not yet supported by the swf encoder
558 // TODO: support bevel joints
560 if(((lineCap==1) && (lineJoin==1)) || width<=caplinewidth) {
561 /* FIXME- if the path is smaller than 2 segments, we could ignore
563 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
564 swfoutput_drawpath(&output, outline, &m);
566 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
567 (char)(rgb.b*255), (char)(opaq*255));
569 //swfoutput_setlinewidth(&output, 1.0); //only for debugging
570 //swfoutput_setstrokecolor(&output, 0, 255, 0, 255); //likewise, see below
571 //swfoutput_setfillcolor(&output, 255, 0, 0, 255); //likewise, see below
573 swfoutput_drawpath2poly(&output, outline, &m, lineJoin, lineCap, width, miterLimit);
574 updateLineWidth(state); //reset
575 updateStrokeColor(state); //reset
576 updateFillColor(state); //reset
579 void SWFOutputDev::fill(GfxState *state)
581 msg("<debug> fill\n");
582 GfxPath * path = state->getPath();
584 m.m11 = 1; m.m21 = 0; m.m22 = 1;
585 m.m12 = 0; m.m13 = 0; m.m23 = 0;
586 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
587 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
588 swfoutput_drawpath(&output, outline, &m);
590 void SWFOutputDev::eoFill(GfxState *state)
592 msg("<debug> eofill\n");
593 GfxPath * path = state->getPath();
595 m.m11 = 1; m.m21 = 0; m.m22 = 1;
596 m.m12 = 0; m.m13 = 0; m.m23 = 0;
597 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
598 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
599 swfoutput_drawpath(&output, outline, &m);
601 void SWFOutputDev::clip(GfxState *state)
603 msg("<debug> clip\n");
604 GfxPath * path = state->getPath();
606 m.m11 = 1; m.m22 = 1;
607 m.m12 = 0; m.m21 = 0;
608 m.m13 = 0; m.m23 = 0;
609 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
610 swfoutput_startclip(&output, outline, &m);
611 clipping[clippos] ++;
613 void SWFOutputDev::eoClip(GfxState *state)
615 msg("<debug> eoclip\n");
616 GfxPath * path = state->getPath();
618 m.m11 = 1; m.m21 = 0; m.m22 = 1;
619 m.m12 = 0; m.m13 = 0; m.m23 = 0;
620 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
621 swfoutput_startclip(&output, outline, &m);
622 clipping[clippos] ++;
625 SWFOutputDev::~SWFOutputDev()
627 swfoutput_destroy(&output);
630 GBool SWFOutputDev::upsideDown()
632 msg("<debug> upsidedown? yes");
635 GBool SWFOutputDev::useDrawChar()
640 void SWFOutputDev::beginString(GfxState *state, GString *s)
642 double m11,m21,m12,m22;
643 // msg("<debug> %s beginstring \"%s\"\n", gfxstate2str(state), s->getCString());
644 state->getFontTransMat(&m11, &m12, &m21, &m22);
645 m11 *= state->getHorizScaling();
646 m21 *= state->getHorizScaling();
647 swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
650 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
651 double dx, double dy,
652 double originX, double originY,
653 CharCode c, Unicode *_u, int uLen)
655 // check for invisible text -- this is used by Acrobat Capture
656 if ((state->getRender() & 3) == 3)
659 GfxFont*font = state->getFont();
661 if(font->getType() == fontType3) {
662 /* type 3 chars are passed as graphics */
668 state->transform(x, y, &x1, &y1);
674 /* find out the character name */
676 if(font->isCIDFont() && u) {
677 GfxCIDFont*cfont = (GfxCIDFont*)font;
679 for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
680 /* todo: should be precomputed */
681 if(nameToUnicodeTab[t].u == u) {
682 name = nameToUnicodeTab[t].name;
688 font8 = (Gfx8BitFont*)font;
689 char**enc=font8->getEncoding();
694 msg("<debug> 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));
696 int ret = swfoutput_drawchar(&output, x1, y1, name, c, u);
699 void SWFOutputDev::endString(GfxState *state) {
703 GBool SWFOutputDev::beginType3Char(GfxState *state,
704 CharCode code, Unicode *u, int uLen)
706 msg("<debug> beginType3Char %d, %08x, %d", code, *u, uLen);
708 /* the character itself is going to be passed using
710 return gFalse; /* gTrue= is_in_cache? */
713 void SWFOutputDev::endType3Char(GfxState *state)
716 msg("<debug> endType3Char");
719 void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
722 int rot = doc->getPageRotate(1);
724 msg("<verbose> startPage %d (%f,%f,%f,%f)\n", pageNum, crop_x1, crop_y1, crop_x2, crop_y2);
726 msg("<verbose> page is rotated %d degrees\n", rot);
728 msg("<notice> processing page %d", pageNum);
730 /* state->transform(state->getX1(),state->getY1(),&x1,&y1);
731 state->transform(state->getX2(),state->getY2(),&x2,&y2);
732 Use CropBox, not MediaBox, as page size
739 state->transform(crop_x1,crop_y1,&x1,&y1);
740 state->transform(crop_x2,crop_y2,&x2,&y2);
742 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
743 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
746 msg("<verbose> Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2);
747 swfoutput_init(&output, swffilename,(int)x1,(int)y1,(int)x2,(int)y2);
751 swfoutput_newpage(&output);
754 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
756 msg("<debug> drawlink\n");
757 double x1, y1, x2, y2, w;
762 link->getBorder(&x1, &y1, &x2, &y2, &w);
768 cvtUserToDev(x1, y1, &x, &y);
769 points[0].x = points[4].x = (int)x;
770 points[0].y = points[4].y = (int)y;
771 cvtUserToDev(x2, y1, &x, &y);
772 points[1].x = (int)x;
773 points[1].y = (int)y;
774 cvtUserToDev(x2, y2, &x, &y);
775 points[2].x = (int)x;
776 points[2].y = (int)y;
777 cvtUserToDev(x1, y2, &x, &y);
778 points[3].x = (int)x;
779 points[3].y = (int)y;
781 LinkAction*action=link->getAction();
788 switch(action->getKind())
792 LinkGoTo *ha=(LinkGoTo *)link->getAction();
794 if (ha->getDest()==NULL)
795 dest=catalog->findDest(ha->getNamedDest());
796 else dest=ha->getDest();
798 if (dest->isPageRef()){
799 Ref pageref=dest->getPageRef();
800 page=catalog->findPage(pageref.num,pageref.gen);
802 else page=dest->getPageNum();
803 sprintf(buf, "%d", page);
810 LinkGoToR*l = (LinkGoToR*)action;
811 GString*g = l->getNamedDest();
818 LinkNamed*l = (LinkNamed*)action;
819 GString*name = l->getName();
821 s = name->lowerCase()->getCString();
822 named = name->getCString();
825 if(strstr(s, "next") || strstr(s, "forward"))
827 page = currentpage + 1;
829 else if(strstr(s, "prev") || strstr(s, "back"))
831 page = currentpage - 1;
833 else if(strstr(s, "last") || strstr(s, "end"))
835 page = pages[pagepos-1]; //:)
837 else if(strstr(s, "first") || strstr(s, "top"))
847 LinkLaunch*l = (LinkLaunch*)action;
848 GString * str = new GString(l->getFileName());
849 str->append(l->getParams());
850 s = str->getCString();
855 LinkURI*l = (LinkURI*)action;
856 GString*g = l->getURI();
858 url = g->getCString();
863 case actionUnknown: {
865 LinkUnknown*l = (LinkUnknown*)action;
870 msg("<error> Unknown link type!\n");
874 if(!linkinfo && (page || url))
876 msg("<notice> File contains links");
882 for(t=0;t<pagepos;t++)
886 swfoutput_linktopage(&output, t, points);
890 swfoutput_linktourl(&output, url, points);
894 swfoutput_namedlink(&output, named, points);
896 msg("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
900 void SWFOutputDev::saveState(GfxState *state) {
901 msg("<debug> saveState\n");
906 msg("<error> Too many nested states in pdf.");
907 clipping[clippos] = 0;
910 void SWFOutputDev::restoreState(GfxState *state) {
911 msg("<debug> restoreState\n");
913 while(clipping[clippos]) {
914 swfoutput_endclip(&output);
922 char* SWFOutputDev::searchFont(char*name)
926 int is_standard_font = 0;
928 msg("<verbose> SearchFont(%s)", name);
930 /* see if it is a pdf standard font */
931 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
933 if(!strcmp(name, pdf2t1map[i].pdffont))
935 name = pdf2t1map[i].filename;
936 is_standard_font = 1;
940 /* look in all font files */
941 for(i=0;i<fontnum;i++)
943 if(strstr(fonts[i].filename, name))
948 if(!is_standard_font)
949 msg("<notice> Using %s for %s", fonts[i].filename, name);
951 return fonts[i].filename;
957 void SWFOutputDev::updateLineWidth(GfxState *state)
959 double width = state->getTransformedLineWidth();
960 swfoutput_setlinewidth(&output, width);
963 void SWFOutputDev::updateLineCap(GfxState *state)
965 int c = state->getLineCap();
968 void SWFOutputDev::updateLineJoin(GfxState *state)
970 int j = state->getLineJoin();
973 void SWFOutputDev::updateFillColor(GfxState *state)
976 double opaq = state->getFillOpacity();
977 state->getFillRGB(&rgb);
979 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
980 (char)(rgb.b*255), (char)(opaq*255));
983 void SWFOutputDev::updateStrokeColor(GfxState *state)
986 double opaq = state->getStrokeOpacity();
987 state->getStrokeRGB(&rgb);
989 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
990 (char)(rgb.b*255), (char)(opaq*255));
993 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
995 char*tmpFileName = NULL;
1001 Object refObj, strObj;
1003 tmpFileName = mktmpname(namebuf);
1006 ret = font->getEmbeddedFontID(&embRef);
1008 msg("<verbose> Didn't get embedded font id");
1009 /* not embedded- the caller should now search the font
1010 directories for this font */
1014 f = fopen(tmpFileName, "wb");
1016 msg("<error> Couldn't create temporary Type 1 font file");
1020 /*if(font->isCIDFont()) {
1021 GfxCIDFont* cidFont = (GfxCIDFont *)font;
1022 GString c = cidFont->getCollection();
1023 msg("<notice> Collection: %s", c.getCString());
1026 if (font->getType() == fontType1C ||
1027 font->getType() == fontCIDType0C) {
1028 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1030 msg("<error> Couldn't read embedded font file");
1033 Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
1034 cvt->convertToType1(f);
1035 //cvt->convertToCIDType0("test", f);
1036 //cvt->convertToType0("test", f);
1039 } else if(font->getType() == fontTrueType) {
1040 msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
1041 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1043 msg("<error> Couldn't read embedded font file");
1046 TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
1051 font->getEmbeddedFontID(&embRef);
1052 refObj.initRef(embRef.num, embRef.gen);
1053 refObj.fetch(ref, &strObj);
1055 strObj.streamReset();
1060 f4[t] = strObj.streamGetChar();
1061 f4c[t] = (char)f4[t];
1066 if(!strncmp(f4c, "true", 4)) {
1067 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1068 Change this on the fly */
1069 f4[0] = f4[2] = f4[3] = 0;
1077 while ((c = strObj.streamGetChar()) != EOF) {
1081 strObj.streamClose();
1086 return strdup(tmpFileName);
1090 char* substitutetarget[256];
1091 char* substitutesource[256];
1092 int substitutepos = 0;
1094 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1096 char*fontname = "Times-Roman";
1097 msg("<verbose> substituteFont(,%s)", FIXNULL(oldname));
1098 char*filename = searchFont(fontname);
1099 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1100 msg("<fatal> Too many fonts in file.");
1104 substitutesource[substitutepos] = oldname;
1105 substitutetarget[substitutepos] = fontname;
1106 msg("<notice> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1112 void unlinkfont(char* filename)
1119 if(!strncmp(&filename[l-4],".afm",4)) {
1120 memcpy(&filename[l-4],".pfb",4);
1122 memcpy(&filename[l-4],".pfa",4);
1124 memcpy(&filename[l-4],".afm",4);
1127 if(!strncmp(&filename[l-4],".pfa",4)) {
1128 memcpy(&filename[l-4],".afm",4);
1130 memcpy(&filename[l-4],".pfa",4);
1133 if(!strncmp(&filename[l-4],".pfb",4)) {
1134 memcpy(&filename[l-4],".afm",4);
1136 memcpy(&filename[l-4],".pfb",4);
1141 void SWFOutputDev::startDoc(XRef *xref)
1147 void SWFOutputDev::updateFont(GfxState *state)
1149 GfxFont*gfxFont = state->getFont();
1154 char * fontid = getFontID(gfxFont);
1157 /* first, look if we substituted this font before-
1158 this way, we don't initialize the T1 Fonts
1160 for(t=0;t<substitutepos;t++) {
1161 if(!strcmp(fontid, substitutesource[t])) {
1162 fontid = substitutetarget[t];
1167 /* second, see if swfoutput already has this font
1168 cached- if so, we are done */
1169 if(swfoutput_queryfont(&output, fontid))
1171 swfoutput_setfont(&output, fontid, 0);
1173 msg("<debug> updateFont(%s) [cached]", fontid);
1177 // look for Type 3 font
1178 if (gfxFont->getType() == fontType3) {
1180 type3Warning = gTrue;
1181 showFontError(gfxFont, 2);
1186 /* now either load the font, or find a substitution */
1189 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1194 (gfxFont->getType() == fontType1 ||
1195 gfxFont->getType() == fontType1C ||
1196 //gfxFont->getType() == fontCIDType0C ||
1197 gfxFont->getType() == fontTrueType ||
1198 gfxFont->getType() == fontCIDType2
1201 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1202 if(!fileName) showFontError(gfxFont,0);
1205 char * fontname = getFontName(gfxFont);
1206 fileName = searchFont(fontname);
1207 if(!fileName) showFontError(gfxFont,0);
1210 char * fontname = getFontName(gfxFont);
1211 msg("<warning> Font %s %scould not be loaded.", fontname, embedded?"":"(not embedded) ");
1212 msg("<warning> Try putting a TTF version of that font (named \"%s.ttf\") into /swftools/fonts", fontname);
1213 fileName = substituteFont(gfxFont, fontid);
1217 msg("<error> Couldn't set font %s\n", fontid);
1221 msg("<verbose> updateFont(%s) -> %s", fontid, fileName);
1222 dumpFontInfo("<verbose>", gfxFont);
1224 swfoutput_setfont(&output, fontid, fileName);
1227 unlinkfont(fileName);
1233 int pic_width[1024];
1234 int pic_height[1024];
1238 #define SQR(x) ((x)*(x))
1240 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1242 if((newwidth<2 || newheight<2) ||
1243 (width<=newwidth || height<=newheight))
1245 unsigned char*newdata;
1247 newdata= (unsigned char*)malloc(newwidth*newheight);
1249 double fx = (double)(width)/newwidth;
1250 double fy = (double)(height)/newheight;
1252 int blocksize = (int)(8192/(fx*fy));
1253 int r = 8192*256/palettesize;
1254 for(x=0;x<newwidth;x++) {
1255 double ex = px + fx;
1256 int fromx = (int)px;
1258 int xweight1 = (int)(((fromx+1)-px)*256);
1259 int xweight2 = (int)((ex-tox)*256);
1261 for(y=0;y<newheight;y++) {
1262 double ey = py + fy;
1263 int fromy = (int)py;
1265 int yweight1 = (int)(((fromy+1)-py)*256);
1266 int yweight2 = (int)((ey-toy)*256);
1269 for(xx=fromx;xx<=tox;xx++)
1270 for(yy=fromy;yy<=toy;yy++) {
1271 int b = 1-data[width*yy+xx];
1273 if(xx==fromx) weight = (weight*xweight1)/256;
1274 if(xx==tox) weight = (weight*xweight2)/256;
1275 if(yy==fromy) weight = (weight*yweight1)/256;
1276 if(yy==toy) weight = (weight*yweight2)/256;
1279 //if(a) a=(palettesize-1)*r/blocksize;
1280 newdata[y*newwidth+x] = (a*blocksize)/r;
1288 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1289 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1290 GBool inlineImg, int mask)
1295 double x1,y1,x2,y2,x3,y3,x4,y4;
1296 ImageStream *imgStr;
1303 ncomps = colorMap->getNumPixelComps();
1304 bits = colorMap->getBits();
1306 imgStr = new ImageStream(str, width, ncomps,bits);
1309 if(!width || !height || (height<=1 && width<=1))
1311 msg("<verbose> Ignoring %d by %d image", width, height);
1312 unsigned char buf[8];
1314 for (y = 0; y < height; ++y)
1315 for (x = 0; x < width; ++x) {
1316 imgStr->getPixel(buf);
1322 state->transform(0, 1, &x1, &y1);
1323 state->transform(0, 0, &x2, &y2);
1324 state->transform(1, 0, &x3, &y3);
1325 state->transform(1, 1, &x4, &y4);
1327 if(!pbminfo && !(str->getKind()==strDCT)) {
1329 msg("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1333 msg("<verbose> drawing %d by %d masked picture\n", width, height);
1335 if(!jpeginfo && (str->getKind()==strDCT)) {
1336 msg("<notice> file contains jpeg pictures");
1342 unsigned char buf[8];
1346 unsigned char*pic = new unsigned char[width*height];
1349 state->getFillRGB(&rgb);
1350 memset(pal,255,sizeof(pal));
1351 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1352 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1353 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1355 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1356 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1357 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1358 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1359 for (y = 0; y < height; ++y)
1360 for (x = 0; x < width; ++x)
1362 imgStr->getPixel(buf);
1365 pic[width*y+x] = buf[0];
1370 /* the size of the drawn image is added to the identifier
1371 as the same image may require different bitmaps if displayed
1372 at different sizes (due to antialiasing): */
1378 for(t=0;t<picpos;t++)
1380 if(pic_xids[t] == xid &&
1381 pic_yids[t] == yid) {
1382 /* if the image was antialiased, the size has changed: */
1383 width = pic_width[t];
1384 height = pic_height[t];
1391 unsigned char*pic2 = 0;
1393 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1397 height = realheight;
1400 /* make a black/white palette */
1407 float r = 255/(numpalette-1);
1408 for(t=0;t<numpalette;t++) {
1409 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1410 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1411 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1413 pal[t].r = (U8)(255*rgb.r);
1414 pal[t].g = (U8)(255*rgb.g);
1415 pal[t].b = (U8)(255*rgb.b);
1416 pal[t].a = (U8)(t*r);
1420 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1421 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1422 pic_xids[picpos] = xid;
1423 pic_yids[picpos] = yid;
1424 pic_width[picpos] = width;
1425 pic_height[picpos] = height;
1429 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1430 x1,y1,x2,y2,x3,y3,x4,y4);
1439 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1441 RGBA*pic=new RGBA[width*height];
1444 for (y = 0; y < height; ++y) {
1445 for (x = 0; x < width; ++x) {
1447 imgStr->getPixel(pixBuf);
1448 colorMap->getRGB(pixBuf, &rgb);
1449 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1450 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1451 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1452 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1453 xid += x*r+x*b*3+x*g*7+x*a*11;
1454 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1458 for(t=0;t<picpos;t++)
1460 if(pic_xids[t] == xid &&
1461 pic_yids[t] == yid) {
1466 if(str->getKind()==strDCT)
1467 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1468 x1,y1,x2,y2,x3,y3,x4,y4);
1470 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1471 x1,y1,x2,y2,x3,y3,x4,y4);
1472 pic_xids[picpos] = xid;
1473 pic_yids[picpos] = yid;
1474 pic_width[picpos] = width;
1475 pic_height[picpos] = height;
1479 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1480 x1,y1,x2,y2,x3,y3,x4,y4);
1488 U8*pic = new U8[width*height];
1496 colorMap->getRGB(pixBuf, &rgb);
1497 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1498 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1499 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1500 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1501 xid += t*r+t*b*3+t*g*7+t*a*11;
1502 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1504 for (y = 0; y < height; ++y) {
1505 for (x = 0; x < width; ++x) {
1506 imgStr->getPixel(pixBuf);
1507 pic[width*y+x] = pixBuf[0];
1508 xid += x*pixBuf[0]*7;
1509 yid += y*pixBuf[0]*3;
1513 for(t=0;t<picpos;t++)
1515 if(pic_xids[t] == xid &&
1516 pic_yids[t] == yid) {
1521 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1522 x1,y1,x2,y2,x3,y3,x4,y4,256);
1523 pic_xids[picpos] = xid;
1524 pic_yids[picpos] = yid;
1525 pic_width[picpos] = width;
1526 pic_height[picpos] = height;
1530 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1531 x1,y1,x2,y2,x3,y3,x4,y4);
1539 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1540 int width, int height, GBool invert,
1543 msg("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1544 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1547 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1548 int width, int height, GfxImageColorMap *colorMap,
1549 int *maskColors, GBool inlineImg)
1551 msg("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1552 colorMap?"colorMap":"no colorMap",
1553 maskColors?"maskColors":"no maskColors",
1556 msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1557 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1558 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1561 SWFOutputDev*output = 0;
1563 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1568 if (infoDict->lookup(key, &obj)->isString()) {
1569 s1 = obj.getString();
1570 if ((s1->getChar(0) & 0xff) == 0xfe &&
1571 (s1->getChar(1) & 0xff) == 0xff) {
1573 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1574 if (s1->getChar(i) == '\0') {
1575 s2->append(s1->getChar(i+1));
1578 s2 = new GString("<unicode>");
1582 printf(fmt, s2->getCString());
1585 printf(fmt, s1->getCString());
1591 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1595 if (infoDict->lookup(key, &obj)->isString()) {
1596 s = obj.getString()->getCString();
1597 if (s[0] == 'D' && s[1] == ':') {
1605 void pdfswf_init(char*filename, char*userPassword)
1607 GString *fileName = new GString(filename);
1612 globalParams = new GlobalParams("");
1615 if (userPassword && userPassword[0]) {
1616 userPW = new GString(userPassword);
1620 doc = new PDFDoc(fileName, userPW);
1629 doc->getDocInfo(&info);
1630 if (info.isDict() &&
1631 (screenloglevel>=LOGLEVEL_NOTICE)) {
1632 printInfoString(info.getDict(), "Title", "Title: %s\n");
1633 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1634 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1635 printInfoString(info.getDict(), "Author", "Author: %s\n");
1636 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1637 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1638 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1639 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1640 printf("Pages: %d\n", doc->getNumPages());
1641 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1642 printf("Encrypted: ");
1643 if (doc->isEncrypted()) {
1644 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1645 doc->okToPrint() ? "yes" : "no",
1646 doc->okToCopy() ? "yes" : "no",
1647 doc->okToChange() ? "yes" : "no",
1648 doc->okToAddNotes() ? "yes" : "no");
1655 numpages = doc->getNumPages();
1656 if (doc->isEncrypted()) {
1657 if(!doc->okToCopy()) {
1658 printf("PDF disallows copying. Bailing out.\n");
1661 if(!doc->okToChange() || !doc->okToAddNotes())
1662 swfoutput_setprotected();
1665 output = new SWFOutputDev();
1666 output->startDoc(doc->getXRef());
1669 void pdfswf_setparameter(char*name, char*value)
1671 if(!strcmp(name, "outputfilename")) {
1672 swffilename = value;
1673 } else if(!strcmp(name, "caplinewidth")) {
1674 caplinewidth = atof(value);
1676 swfoutput_setparameter(name, value);
1680 void pdfswf_addfont(char*filename)
1683 memset(&f, 0, sizeof(fontfile_t));
1684 f.filename = filename;
1685 fonts[fontnum++] = f;
1688 /* TODO: get rid of this */
1689 void pdfswf_drawonlyshapes() { pdfswf_setparameter("drawonlyshapes", "1"); }
1690 void pdfswf_ignoredraworder() { pdfswf_setparameter("ignoredraworder", "1"); }
1691 void pdfswf_linksopennewwindow() { pdfswf_setparameter("opennewwindow", "1"); }
1692 void pdfswf_storeallcharacters() { pdfswf_setparameter("storeallcharacters", "1"); }
1693 void pdfswf_enablezlib() { pdfswf_setparameter("enablezlib", "1"); }
1694 void pdfswf_setoutputfilename(char*_filename) { swffilename = _filename; }
1695 void pdfswf_insertstop() { pdfswf_setparameter("insertstoptag", "1"); }
1696 void pdfswf_jpegquality(int val) {
1698 sprintf(tmp, "%d", val);
1699 pdfswf_setparameter("jpegquality", tmp);
1701 void pdfswf_setversion(int n) {
1703 sprintf(tmp, "%d", n);
1704 pdfswf_setparameter("flashversion", tmp);
1709 void pdfswf_convertpage(int page)
1713 pages = (int*)malloc(1024*sizeof(int));
1716 if(pagepos == pagebuflen)
1719 pages = (int*)realloc(pages, pagebuflen);
1722 pages[pagepos++] = page;
1725 void pdfswf_performconversion()
1728 for(t=0;t<pagepos;t++)
1730 currentpage = pages[t];
1731 doc->displayPage((OutputDev*)output, currentpage, /*dpi*/72, /*rotate*/0, /*doLinks*/(int)1);
1734 int pdfswf_numpages()
1736 return doc->getNumPages();
1741 msg("<debug> pdfswf.cc: pdfswf_close()");
1745 // check for memory leaks
1746 Object::memCheck(stderr);