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"
54 static PDFDoc*doc = 0;
55 static char* swffilename = 0;
64 double caplinewidth = 3.0;
66 static void printInfoString(Dict *infoDict, char *key, char *fmt);
67 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
71 0.833,0.833,0.889,0.889,
72 0.788,0.722,0.833,0.778,
73 0.600,0.600,0.600,0.600,
74 0.576,0.576,0.576,0.576,
80 "Helvetica-BoldOblique",
88 "Courier-BoldOblique",
102 {"Times-Roman", "n021003l.pfb"},
103 {"Times-Italic", "n021023l.pfb"},
104 {"Times-Bold", "n021004l.pfb"},
105 {"Times-BoldItalic", "n021024l.pfb"},
106 {"Helvetica", "n019003l.pfb"},
107 {"Helvetica-Oblique", "n019023l.pfb"},
108 {"Helvetica-Bold", "n019004l.pfb"},
109 {"Helvetica-BoldOblique", "n019024l.pfb"},
110 {"Courier", "n022003l.pfb"},
111 {"Courier-Oblique", "n022023l.pfb"},
112 {"Courier-Bold", "n022004l.pfb"},
113 {"Courier-BoldOblique", "n022024l.pfb"},
114 {"Symbol", "s050000l.pfb"},
115 {"ZapfDingbats", "d050000l.pfb"}};
118 class GfxImageColorMap;
120 class SWFOutputDev: public OutputDev {
121 struct swfoutput output;
129 virtual ~SWFOutputDev() ;
131 //----- get info about output device
133 // Does this device use upside-down coordinates?
134 // (Upside-down means (0,0) is the top left corner of the page.)
135 virtual GBool upsideDown();
137 // Does this device use drawChar() or drawString()?
138 virtual GBool useDrawChar();
140 virtual GBool interpretType3Chars() {return gTrue;}
142 //----- initialization and control
144 void startDoc(XRef *xref);
147 virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
150 virtual void drawLink(Link *link, Catalog *catalog) ;
152 //----- save/restore graphics state
153 virtual void saveState(GfxState *state) ;
154 virtual void restoreState(GfxState *state) ;
156 //----- update graphics state
158 virtual void updateFont(GfxState *state);
159 virtual void updateFillColor(GfxState *state);
160 virtual void updateStrokeColor(GfxState *state);
161 virtual void updateLineWidth(GfxState *state);
162 virtual void updateLineJoin(GfxState *state);
163 virtual void updateLineCap(GfxState *state);
165 virtual void updateAll(GfxState *state)
168 updateFillColor(state);
169 updateStrokeColor(state);
170 updateLineWidth(state);
171 updateLineJoin(state);
172 updateLineCap(state);
175 //----- path painting
176 virtual void stroke(GfxState *state) ;
177 virtual void fill(GfxState *state) ;
178 virtual void eoFill(GfxState *state) ;
180 //----- path clipping
181 virtual void clip(GfxState *state) ;
182 virtual void eoClip(GfxState *state) ;
185 virtual void beginString(GfxState *state, GString *s) ;
186 virtual void endString(GfxState *state) ;
187 virtual void drawChar(GfxState *state, double x, double y,
188 double dx, double dy,
189 double originX, double originY,
190 CharCode code, Unicode *u, int uLen);
192 //----- image drawing
193 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
194 int width, int height, GBool invert,
196 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
197 int width, int height, GfxImageColorMap *colorMap,
198 int *maskColors, GBool inlineImg);
200 virtual GBool beginType3Char(GfxState *state,
201 CharCode code, Unicode *u, int uLen);
202 virtual void endType3Char(GfxState *state);
205 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
206 int width, int height, GfxImageColorMap*colorMap, GBool invert,
207 GBool inlineImg, int mask);
213 int searchT1Font(char*name);
214 char* substituteFont(GfxFont*gfxFont, char*oldname);
215 char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
217 int jpeginfo; // did we write "File contains jpegs" yet?
218 int pbminfo; // did we write "File contains jpegs" yet?
219 int linkinfo; // did we write "File contains links" yet?
220 int ttfinfo; // did we write "File contains TrueType Fonts" yet?
222 int type3active; // are we between beginType3()/endType3()?
228 char* gfxstate2str(GfxState *state)
232 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
239 if(state->getX1()!=0.0)
240 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
241 if(state->getY1()!=0.0)
242 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
243 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
244 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
245 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
246 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
247 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
248 state->getFillColor()->c[0], state->getFillColor()->c[1]);
249 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
250 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
251 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
252 state->getFillColor()->c[0], state->getFillColor()->c[1],
253 state->getFillColor()->c[2], state->getFillColor()->c[3],
254 state->getFillColor()->c[4], state->getFillColor()->c[5],
255 state->getFillColor()->c[6], state->getFillColor()->c[7]);
256 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
257 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
258 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
259 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
260 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
261 state->getFillRGB(&rgb);
262 if(rgb.r || rgb.g || rgb.b)
263 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
264 state->getStrokeRGB(&rgb);
265 if(rgb.r || rgb.g || rgb.b)
266 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
267 if(state->getFillColorSpace()->getNComps()>1)
268 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
269 if(state->getStrokeColorSpace()->getNComps()>1)
270 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
271 if(state->getFillPattern())
272 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
273 if(state->getStrokePattern())
274 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
276 if(state->getFillOpacity()!=1.0)
277 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
278 if(state->getStrokeOpacity()!=1.0)
279 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
281 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
286 state->getLineDash(&dash, &length, &start);
290 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
291 for(t=0;t<length;t++) {
292 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
294 bufpos+=sprintf(bufpos,"]");
297 if(state->getFlatness()!=1)
298 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
299 if(state->getLineJoin()!=0)
300 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
301 if(state->getLineJoin()!=0)
302 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
303 if(state->getLineJoin()!=0)
304 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
306 if(state->getFont() && state->getFont()->getName() && state->getFont()->getName()->getCString())
307 bufpos+=sprintf(bufpos,"F\"%s\" ",((state->getFont())->getName())->getCString());
308 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
309 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
310 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
311 if(state->getCharSpace())
312 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
313 if(state->getWordSpace())
314 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
315 if(state->getHorizScaling()!=1.0)
316 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
317 if(state->getLeading())
318 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
320 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
321 if(state->getRender())
322 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
323 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
324 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
325 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
326 if(state->getLineX())
327 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
328 if(state->getLineY())
329 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
330 bufpos+=sprintf(bufpos," ");
334 void dumpFontInfo(char*loglevel, GfxFont*font);
341 void showFontError(GfxFont*font, int nr)
345 for(t=0;t<lastdumppos;t++)
346 if(lastdumps[t] == r->num)
350 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
351 lastdumps[lastdumppos++] = r->num;
353 msg("<warning> The following font caused problems:");
355 msg("<warning> The following font caused problems (substituting):");
357 msg("<warning> The following Type 3 Font will be rendered as bitmap:");
358 dumpFontInfo("<warning>", font);
361 void dumpFontInfo(char*loglevel, GfxFont*font)
365 gstr = font->getName();
366 Ref* r=font->getID();
367 msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, gstr?FIXNULL(gstr->getCString()):"(unknown font)", r->num,r->gen);
369 gstr = font->getTag();
371 msg("%sTag: %s\n", loglevel, FIXNULL(gstr->getCString()));
373 if(font->isCIDFont()) msg("%sis CID font\n", loglevel);
375 GfxFontType type=font->getType();
377 case fontUnknownType:
378 msg("%sType: unknown\n",loglevel);
381 msg("%sType: 1\n",loglevel);
384 msg("%sType: 1C\n",loglevel);
387 msg("%sType: 3\n",loglevel);
390 msg("%sType: TrueType\n",loglevel);
393 msg("%sType: CIDType0\n",loglevel);
396 msg("%sType: CIDType0C\n",loglevel);
399 msg("%sType: CIDType2\n",loglevel);
404 GBool embedded = font->getEmbeddedFontID(&embRef);
405 if(font->getEmbeddedFontName())
406 name = font->getEmbeddedFontName()->getCString();
408 msg("%sEmbedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
410 gstr = font->getExtFontFile();
412 msg("%sExternal Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
414 // Get font descriptor flags.
415 if(font->isFixedWidth()) msg("%sis fixed width\n", loglevel);
416 if(font->isSerif()) msg("%sis serif\n", loglevel);
417 if(font->isSymbolic()) msg("%sis symbolic\n", loglevel);
418 if(font->isItalic()) msg("%sis italic\n", loglevel);
419 if(font->isBold()) msg("%sis bold\n", loglevel);
422 //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");}
423 //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");}
425 SWFOutputDev::SWFOutputDev()
433 clipping[clippos] = 0;
436 // printf("SWFOutputDev::SWFOutputDev() \n");
439 T1_OUTLINE* gfxPath_to_T1_OUTLINE(GfxState*state, GfxPath*path)
441 int num = path->getNumSubpaths();
443 bezierpathsegment*start,*last=0;
444 bezierpathsegment*outline = start = new bezierpathsegment();
446 double lastx=0,lasty=0;
448 msg("<warning> empty path");
449 outline->type = T1_PATHTYPE_MOVE;
453 return (T1_OUTLINE*)outline;
455 for(t = 0; t < num; t++) {
456 GfxSubpath *subpath = path->getSubpath(t);
457 int subnum = subpath->getNumPoints();
459 for(s=0;s<subnum;s++) {
461 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
462 int x = (int)((nx-lastx)*0xffff);
463 int y = (int)((ny-lasty)*0xffff);
467 outline->type = T1_PATHTYPE_MOVE;
470 outline->link = (T1_OUTLINE*)new bezierpathsegment();
471 outline = (bezierpathsegment*)outline->link;
476 else if(subpath->getCurve(s) && !cpos)
482 else if(subpath->getCurve(s) && cpos)
493 outline->type = cpos?T1_PATHTYPE_BEZIER:T1_PATHTYPE_LINE;
495 outline->link = (T1_OUTLINE*)new bezierpathsegment();
496 outline = (bezierpathsegment*)outline->link;
504 return (T1_OUTLINE*)start;
506 /*----------------------------------------------------------------------------
507 * Primitive Graphic routines
508 *----------------------------------------------------------------------------*/
510 void SWFOutputDev::stroke(GfxState *state)
512 msg("<debug> stroke\n");
513 GfxPath * path = state->getPath();
514 int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square
515 int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel
516 double miterLimit = state->getMiterLimit();
517 double width = state->getTransformedLineWidth();
520 double opaq = state->getStrokeOpacity();
521 state->getStrokeRGB(&rgb);
523 m.m11 = 1; m.m21 = 0; m.m22 = 1;
524 m.m12 = 0; m.m13 = 0; m.m23 = 0;
525 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
527 lineJoin = 1; // other line joins are not yet supported by the swf encoder
528 // TODO: support bevel joints
530 if(((lineCap==1) && (lineJoin==1)) || width<=caplinewidth) {
531 /* FIXME- if the path is smaller than 2 segments, we could ignore
533 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
534 swfoutput_drawpath(&output, outline, &m);
536 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
537 (char)(rgb.b*255), (char)(opaq*255));
539 //swfoutput_setlinewidth(&output, 1.0); //only for debugging
540 //swfoutput_setstrokecolor(&output, 0, 255, 0, 255); //likewise, see below
541 //swfoutput_setfillcolor(&output, 255, 0, 0, 255); //likewise, see below
543 swfoutput_drawpath2poly(&output, outline, &m, lineJoin, lineCap, width, miterLimit);
544 updateLineWidth(state); //reset
545 updateStrokeColor(state); //reset
546 updateFillColor(state); //reset
549 void SWFOutputDev::fill(GfxState *state)
551 msg("<debug> fill\n");
552 GfxPath * path = state->getPath();
554 m.m11 = 1; m.m21 = 0; m.m22 = 1;
555 m.m12 = 0; m.m13 = 0; m.m23 = 0;
556 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
557 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
558 swfoutput_drawpath(&output, outline, &m);
560 void SWFOutputDev::eoFill(GfxState *state)
562 msg("<debug> eofill\n");
563 GfxPath * path = state->getPath();
565 m.m11 = 1; m.m21 = 0; m.m22 = 1;
566 m.m12 = 0; m.m13 = 0; m.m23 = 0;
567 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
568 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
569 swfoutput_drawpath(&output, outline, &m);
571 void SWFOutputDev::clip(GfxState *state)
573 msg("<debug> clip\n");
574 GfxPath * path = state->getPath();
576 m.m11 = 1; m.m22 = 1;
577 m.m12 = 0; m.m21 = 0;
578 m.m13 = 0; m.m23 = 0;
579 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
580 swfoutput_startclip(&output, outline, &m);
581 clipping[clippos] ++;
583 void SWFOutputDev::eoClip(GfxState *state)
585 msg("<debug> eoclip\n");
586 GfxPath * path = state->getPath();
588 m.m11 = 1; m.m21 = 0; m.m22 = 1;
589 m.m12 = 0; m.m13 = 0; m.m23 = 0;
590 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
591 swfoutput_startclip(&output, outline, &m);
592 clipping[clippos] ++;
595 SWFOutputDev::~SWFOutputDev()
597 swfoutput_destroy(&output);
600 GBool SWFOutputDev::upsideDown()
602 msg("<debug> upsidedown?");
605 GBool SWFOutputDev::useDrawChar()
607 msg("<debug> usedrawchar?");
611 void SWFOutputDev::beginString(GfxState *state, GString *s)
613 double m11,m21,m12,m22;
614 // msg("<debug> %s beginstring \"%s\"\n", gfxstate2str(state), s->getCString());
615 state->getFontTransMat(&m11, &m12, &m21, &m22);
616 m11 *= state->getHorizScaling();
617 m21 *= state->getHorizScaling();
618 swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
622 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
623 double dx, double dy,
624 double originX, double originY,
625 CharCode c, Unicode *_u, int uLen)
627 // check for invisible text -- this is used by Acrobat Capture
628 if ((state->getRender() & 3) == 3)
631 GfxFont*font = state->getFont();
633 if(font->getType() == fontType3) {
634 /* type 3 chars are passed primarily as graphics */
640 state->transform(x, y, &x1, &y1);
646 msg("<debug> drawChar(%f,%f,%f,%f,'%c',%d) CID=%d\n",x,y,dx,dy,c,u, font->isCIDFont());
648 if(font->isCIDFont()) {
649 GfxCIDFont*cfont = (GfxCIDFont*)font;
653 for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++)
654 /* todo: should be precomputed */
655 if(nameToUnicodeTab[t].u == u) {
656 name = nameToUnicodeTab[t].name;
662 swfoutput_drawchar(&output, x1, y1, name, c);
664 msg("<warning> couldn't get name for CID character %02x from Encoding", c);
665 swfoutput_drawchar(&output, x1, y1, "<unknown>", c);
669 font8 = (Gfx8BitFont*)font;
670 char**enc=font8->getEncoding();
673 swfoutput_drawchar(&output, x1, y1, enc[c], c);
675 msg("<warning> couldn't get name for character %02x from Encoding", c);
676 swfoutput_drawchar(&output, x1, y1, "<unknown>", c);
681 void SWFOutputDev::endString(GfxState *state)
683 msg("<debug> endstring\n");
687 GBool SWFOutputDev::beginType3Char(GfxState *state,
688 CharCode code, Unicode *u, int uLen)
690 msg("<debug> beginType3Char %d, %08x, %d", code, *u, uLen);
692 /* the character itself is going to be passed using
694 return gFalse; /* gTrue= is_in_cache? */
697 void SWFOutputDev::endType3Char(GfxState *state)
700 msg("<debug> endType3Char");
703 void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
707 msg("<debug> startPage %d\n", pageNum);
708 msg("<notice> processing page %d", pageNum);
710 /*state->transform(state->getX1(),state->getY1(),&x1,&y1);
711 state->transform(state->getX2(),state->getY2(),&x2,&y2);
718 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
719 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
722 msg("<verbose> Bounding box is (%f,%f)-(%f,%f)", crop_x1,crop_y1,crop_x2,crop_y2);
723 swfoutput_init(&output, swffilename,(int)crop_x1,(int)crop_y1,(int)crop_y2,(int)crop_y2);
727 swfoutput_newpage(&output);
730 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
732 msg("<debug> drawlink\n");
733 double x1, y1, x2, y2, w;
738 link->getBorder(&x1, &y1, &x2, &y2, &w);
744 cvtUserToDev(x1, y1, &x, &y);
745 points[0].x = points[4].x = (int)x;
746 points[0].y = points[4].y = (int)y;
747 cvtUserToDev(x2, y1, &x, &y);
748 points[1].x = (int)x;
749 points[1].y = (int)y;
750 cvtUserToDev(x2, y2, &x, &y);
751 points[2].x = (int)x;
752 points[2].y = (int)y;
753 cvtUserToDev(x1, y2, &x, &y);
754 points[3].x = (int)x;
755 points[3].y = (int)y;
757 LinkAction*action=link->getAction();
764 switch(action->getKind())
768 LinkGoTo *ha=(LinkGoTo *)link->getAction();
770 if (ha->getDest()==NULL)
771 dest=catalog->findDest(ha->getNamedDest());
772 else dest=ha->getDest();
774 if (dest->isPageRef()){
775 Ref pageref=dest->getPageRef();
776 page=catalog->findPage(pageref.num,pageref.gen);
778 else page=dest->getPageNum();
779 sprintf(buf, "%d", page);
786 LinkGoToR*l = (LinkGoToR*)action;
787 GString*g = l->getNamedDest();
794 LinkNamed*l = (LinkNamed*)action;
795 GString*name = l->getName();
797 s = name->lowerCase()->getCString();
798 named = name->getCString();
801 if(strstr(s, "next") || strstr(s, "forward"))
803 page = currentpage + 1;
805 else if(strstr(s, "prev") || strstr(s, "back"))
807 page = currentpage - 1;
809 else if(strstr(s, "last") || strstr(s, "end"))
811 page = pages[pagepos-1]; //:)
813 else if(strstr(s, "first") || strstr(s, "top"))
823 LinkLaunch*l = (LinkLaunch*)action;
824 GString * str = new GString(l->getFileName());
825 str->append(l->getParams());
826 s = str->getCString();
831 LinkURI*l = (LinkURI*)action;
832 GString*g = l->getURI();
834 url = g->getCString();
839 case actionUnknown: {
841 LinkUnknown*l = (LinkUnknown*)action;
846 msg("<error> Unknown link type!\n");
850 if(!linkinfo && (page || url))
852 msg("<notice> File contains links");
858 for(t=0;t<pagepos;t++)
862 swfoutput_linktopage(&output, t, points);
866 swfoutput_linktourl(&output, url, points);
870 swfoutput_namedlink(&output, named, points);
872 msg("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
876 void SWFOutputDev::saveState(GfxState *state) {
877 msg("<debug> saveState\n");
882 msg("<error> Too many nested states in pdf.");
883 clipping[clippos] = 0;
886 void SWFOutputDev::restoreState(GfxState *state) {
887 msg("<debug> restoreState\n");
889 while(clipping[clippos]) {
890 swfoutput_endclip(&output);
898 int SWFOutputDev::searchT1Font(char*name)
904 msg("<verbose> SearchT1Font(%s)", name);
906 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
908 if(!strcmp(name, pdf2t1map[i].pdffont))
910 filename = pdf2t1map[i].filename;
915 for(i=0; i<T1_Get_no_fonts(); i++)
917 char*fontfilename = T1_GetFontFileName (i);
918 if(strstr(fontfilename, filename))
920 pdf2t1map[i].id = mapid;
925 for(i=0; i<T1_Get_no_fonts(); i++)
927 char*fontname = T1_GetFontName (i);
930 fontname = T1_GetFontName (i);
931 msg("<verbose> Loading extra font %s from %s\n", FIXNULL(fontname),
932 FIXNULL(T1_GetFontFileName(i)));
935 if(fontname && !strcmp(name, fontname)) {
936 msg("<notice> Extra font %d, \"%s\" is being used.\n", i, fontname);
939 fontname = T1_GetFontFileName(i);
940 if(strrchr(fontname,'/'))
941 fontname = strrchr(fontname,'/')+1;
943 if(strstr(fontname, name)) {
944 msg("<notice> Extra font %d, \"%s\" is being used.\n", i, fontname);
952 void SWFOutputDev::updateLineWidth(GfxState *state)
954 double width = state->getTransformedLineWidth();
955 swfoutput_setlinewidth(&output, width);
958 void SWFOutputDev::updateLineCap(GfxState *state)
960 int c = state->getLineCap();
963 void SWFOutputDev::updateLineJoin(GfxState *state)
965 int j = state->getLineJoin();
968 void SWFOutputDev::updateFillColor(GfxState *state)
971 double opaq = state->getFillOpacity();
972 state->getFillRGB(&rgb);
974 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
975 (char)(rgb.b*255), (char)(opaq*255));
978 void SWFOutputDev::updateStrokeColor(GfxState *state)
981 double opaq = state->getStrokeOpacity();
982 state->getStrokeRGB(&rgb);
984 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
985 (char)(rgb.b*255), (char)(opaq*255));
988 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
990 char*tmpFileName = NULL;
996 Object refObj, strObj;
998 tmpFileName = mktmpname(namebuf);
1001 ret = font->getEmbeddedFontID(&embRef);
1003 msg("<verbose> Didn't get embedded font id");
1004 /* not embedded- the caller should now search the font
1005 directories for this font */
1009 f = fopen(tmpFileName, "wb");
1011 msg("<error> Couldn't create temporary Type 1 font file");
1014 if (font->getType() == fontType1C ||
1015 font->getType() == fontCIDType0C) {
1016 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1018 msg("<error> Couldn't read embedded font file");
1021 Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
1022 cvt->convertToType1(f);
1025 } else if(font->getType() == fontTrueType) {
1026 msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
1027 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1029 msg("<error> Couldn't read embedded font file");
1032 TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
1037 font->getEmbeddedFontID(&embRef);
1038 refObj.initRef(embRef.num, embRef.gen);
1039 refObj.fetch(ref, &strObj);
1041 strObj.streamReset();
1046 f4[t] = strObj.streamGetChar();
1047 f4c[t] = (char)f4[t];
1052 if(!strncmp(f4c, "true", 4)) {
1053 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1054 Change this on the fly */
1055 f4[0] = f4[2] = f4[3] = 0;
1063 while ((c = strObj.streamGetChar()) != EOF) {
1067 strObj.streamClose();
1072 if(font->getType() == fontTrueType ||
1073 font->getType() == fontCIDType2)
1076 msg("<notice> File contains TrueType fonts");
1081 tmp = strdup(mktmpname((char*)name2));
1082 sprintf(name2, "%s", tmp);
1083 char*a[] = {"./ttf2pt1", "-W", "0",
1084 #ifndef USE_FREETYPE
1089 "-b", tmpFileName, name2};
1090 msg("<verbose> Invoking %s %s %s %s %s %s %s %s",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
1092 unlink(tmpFileName);
1093 sprintf(name2,"%s.pfb",tmp);
1094 tmpFileName = strdup(name2);
1097 return strdup(tmpFileName);
1100 char* gfxFontName(GfxFont* gfxFont)
1103 gstr = gfxFont->getName();
1105 return gstr->getCString();
1109 Ref*r=gfxFont->getID();
1110 sprintf(buf, "UFONT%d", r->num);
1115 char* substitutetarget[256];
1116 char* substitutesource[256];
1117 int substitutepos = 0;
1119 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1121 /* ------------------------------ V1 */
1123 char*fontname = "Times-Roman";
1124 msg("<verbose> substituteFont(,%s)", FIXNULL(oldname));
1125 this->t1id = searchT1Font(fontname);
1126 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1127 msg("<fatal> Too many fonts in file.");
1131 substitutesource[substitutepos] = oldname;
1132 substitutetarget[substitutepos] = fontname;
1133 msg("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1138 /* ------------------------------ V2 */
1140 /* //substitute font
1142 double m11, m12, m21, m22;
1148 if(gfxFont->getName()) {
1149 fontname = gfxFont->getName()->getCString();
1152 // printf("%d %s\n", t, gfxFont->getCharName(t));
1153 showFontError(gfxFont, 1);
1154 if(1) { //if (!gfxFont->isCIDFont()) { FIXME: xpdf 1.01 does not have is16Bit()
1155 if(gfxFont->isSymbolic()) {
1156 if(fontname && (strstr(fontname,"ing"))) //Dingbats, Wingdings etc.
1160 } else if (gfxFont->isFixedWidth()) {
1162 } else if (gfxFont->isSerif()) {
1167 if (gfxFont->isBold() && index!=16)
1169 if (gfxFont->isItalic() && index!=16)
1171 fontname = fontnames[index];
1172 // get width of 'm' in real font and substituted font
1173 if ((code = gfxFont->getCharCode("m")) >= 0)
1174 w1 = gfxFont->getWidth(code);
1177 w2 = fontsizes[index];
1178 if (gfxFont->getType() == fontType3) {
1179 // This is a hack which makes it possible to substitute for some
1180 // Type 3 fonts. The problem is that it's impossible to know what
1181 // the base coordinate system used in the font is without actually
1182 // rendering the font. This code tries to guess by looking at the
1183 // width of the character 'm' (which breaks if the font is a
1184 // subset that doesn't contain 'm').
1185 if (w1 > 0 && (w1 > 1.1 * w2 || w1 < 0.9 * w2)) {
1192 fm = gfxFont->getFontMatrix();
1193 v = (fm[0] == 0) ? 1 : (fm[3] / fm[0]);
1196 } else if (!gfxFont->isSymbolic()) {
1197 // if real font is substantially narrower than substituted
1198 // font, reduce the font size accordingly
1199 if (w1 > 0.01 && w1 < 0.9 * w2) {
1212 this->t1id = searchT1Font(fontname);
1214 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1215 msg("<fatal> Too many fonts in file.");
1219 substitutesource[substitutepos] = oldname;
1220 substitutetarget[substitutepos] = fontname;
1221 msg("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1227 void unlinkfont(char* filename)
1234 if(!strncmp(&filename[l-4],".afm",4)) {
1235 memcpy(&filename[l-4],".pfb",4);
1237 memcpy(&filename[l-4],".pfa",4);
1239 memcpy(&filename[l-4],".afm",4);
1242 if(!strncmp(&filename[l-4],".pfa",4)) {
1243 memcpy(&filename[l-4],".afm",4);
1245 memcpy(&filename[l-4],".pfa",4);
1248 if(!strncmp(&filename[l-4],".pfb",4)) {
1249 memcpy(&filename[l-4],".afm",4);
1251 memcpy(&filename[l-4],".pfb",4);
1256 void SWFOutputDev::startDoc(XRef *xref)
1262 void SWFOutputDev::updateFont(GfxState *state)
1264 GfxFont*gfxFont = state->getFont();
1265 char * fileName = 0;
1270 char * fontname = gfxFontName(gfxFont);
1273 /* first, look if we substituted this font before-
1274 this way, we don't initialize the T1 Fonts
1276 for(t=0;t<substitutepos;t++) {
1277 if(!strcmp(fontname, substitutesource[t])) {
1278 fontname = substitutetarget[t];
1283 /* second, see if swfoutput already has this font
1284 cached- if so, we are done */
1286 if(swfoutput_queryfont(&output, fontname))
1288 swfoutput_setfont(&output, fontname, -1, 0);
1292 // look for Type 3 font
1293 if (!type3Warning && gfxFont->getType() == fontType3) {
1294 type3Warning = gTrue;
1295 showFontError(gfxFont, 2);
1298 /* now either load the font, or find a substitution */
1301 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1303 if (gfxFont->getType() == fontType1 ||
1304 gfxFont->getType() == fontCIDType0C ||
1305 gfxFont->getType() == fontType1C ||
1306 gfxFont->getType() == fontTrueType ||
1307 gfxFont->getType() == fontCIDType2
1310 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1312 msg("<error> Couldn't write font to file");
1313 showFontError(gfxFont,0);
1316 this->t1id = T1_AddFont(fileName);
1318 msg("<error> Couldn't load font from file %s", fileName);
1319 showFontError(gfxFont,0);
1320 unlinkfont(fileName);
1325 /* in case the font is embedded, but has an
1326 unsupported format, we just look through the
1328 int newt1id = searchT1Font(fontname);
1330 msg("<error> Couldn't find any suitable replacement for %s",fontname);
1331 showFontError(gfxFont,0);
1332 fontname = substituteFont(gfxFont, fontname);
1334 this->t1id = newt1id;
1338 int newt1id = searchT1Font(fontname);
1340 showFontError(gfxFont,1);
1341 fontname = substituteFont(gfxFont, fontname);
1343 this->t1id = newt1id;
1346 showFontError(gfxFont,1);
1347 fontname = substituteFont(gfxFont, fontname);
1352 msg("<error> Current font's t1id is %d", t1id);
1353 //showFontError(gfxFont,0);
1357 /* we may have done some substitutions here, so check
1358 again if this font is cached. */
1359 if(swfoutput_queryfont(&output, fontname))
1361 swfoutput_setfont(&output, fontname, -1, 0);
1365 msg("<verbose> Creating new SWF font: t1id: %d, filename: %s name:%s", this->t1id, FIXNULL(fileName), FIXNULL(fontname));
1366 swfoutput_setfont(&output, fontname, this->t1id, fileName);
1368 unlinkfont(fileName);
1374 int pic_width[1024];
1375 int pic_height[1024];
1379 #define SQR(x) ((x)*(x))
1381 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1383 if((newwidth<2 || newheight<2) ||
1384 (width<=newwidth || height<=newheight))
1386 unsigned char*newdata;
1388 newdata= (unsigned char*)malloc(newwidth*newheight);
1390 double fx = (double)(width)/newwidth;
1391 double fy = (double)(height)/newheight;
1393 int blocksize = (int)(8192/(fx*fy));
1394 int r = 8192*256/palettesize;
1395 for(x=0;x<newwidth;x++) {
1396 double ex = px + fx;
1397 int fromx = (int)px;
1399 int xweight1 = (int)(((fromx+1)-px)*256);
1400 int xweight2 = (int)((ex-tox)*256);
1402 for(y=0;y<newheight;y++) {
1403 double ey = py + fy;
1404 int fromy = (int)py;
1406 int yweight1 = (int)(((fromy+1)-py)*256);
1407 int yweight2 = (int)((ey-toy)*256);
1410 for(xx=fromx;xx<=tox;xx++)
1411 for(yy=fromy;yy<=toy;yy++) {
1412 int b = 1-data[width*yy+xx];
1414 if(xx==fromx) weight = (weight*xweight1)/256;
1415 if(xx==tox) weight = (weight*xweight2)/256;
1416 if(yy==fromy) weight = (weight*yweight1)/256;
1417 if(yy==toy) weight = (weight*yweight2)/256;
1420 //if(a) a=(palettesize-1)*r/blocksize;
1421 newdata[y*newwidth+x] = (a*blocksize)/r;
1429 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1430 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1431 GBool inlineImg, int mask)
1436 double x1,y1,x2,y2,x3,y3,x4,y4;
1437 ImageStream *imgStr;
1444 ncomps = colorMap->getNumPixelComps();
1445 bits = colorMap->getBits();
1447 imgStr = new ImageStream(str, width, ncomps,bits);
1450 if(!width || !height || (height<=1 && width<=1))
1452 msg("<verbose> Ignoring %d by %d image", width, height);
1453 unsigned char buf[8];
1455 for (y = 0; y < height; ++y)
1456 for (x = 0; x < width; ++x) {
1457 imgStr->getPixel(buf);
1463 state->transform(0, 1, &x1, &y1);
1464 state->transform(0, 0, &x2, &y2);
1465 state->transform(1, 0, &x3, &y3);
1466 state->transform(1, 1, &x4, &y4);
1468 if(!pbminfo && !(str->getKind()==strDCT)) {
1470 msg("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1474 msg("<verbose> drawing %d by %d masked picture\n", width, height);
1476 if(!jpeginfo && (str->getKind()==strDCT)) {
1477 msg("<notice> file contains jpeg pictures");
1483 unsigned char buf[8];
1487 unsigned char*pic = new unsigned char[width*height];
1490 state->getFillRGB(&rgb);
1491 memset(pal,255,sizeof(pal));
1492 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1493 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1494 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1496 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1497 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1498 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1499 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1500 for (y = 0; y < height; ++y)
1501 for (x = 0; x < width; ++x)
1503 imgStr->getPixel(buf);
1506 pic[width*y+x] = buf[0];
1511 /* the size of the drawn image is added to the identifier
1512 as the same image may require different bitmaps if displayed
1513 at different sizes (due to antialiasing): */
1519 for(t=0;t<picpos;t++)
1521 if(pic_xids[t] == xid &&
1522 pic_yids[t] == yid) {
1523 /* if the image was antialiased, the size has changed: */
1524 width = pic_width[t];
1525 height = pic_height[t];
1532 unsigned char*pic2 = 0;
1534 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1538 height = realheight;
1541 /* make a black/white palette */
1548 float r = 255/(numpalette-1);
1549 for(t=0;t<numpalette;t++) {
1550 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1551 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1552 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1554 pal[t].r = (U8)(255*rgb.r);
1555 pal[t].g = (U8)(255*rgb.g);
1556 pal[t].b = (U8)(255*rgb.b);
1557 pal[t].a = (U8)(t*r);
1561 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1562 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1563 pic_xids[picpos] = xid;
1564 pic_yids[picpos] = yid;
1565 pic_width[picpos] = width;
1566 pic_height[picpos] = height;
1570 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1571 x1,y1,x2,y2,x3,y3,x4,y4);
1580 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1582 RGBA*pic=new RGBA[width*height];
1585 for (y = 0; y < height; ++y) {
1586 for (x = 0; x < width; ++x) {
1588 imgStr->getPixel(pixBuf);
1589 colorMap->getRGB(pixBuf, &rgb);
1590 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1591 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1592 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1593 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1594 xid += x*r+x*b*3+x*g*7+x*a*11;
1595 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1599 for(t=0;t<picpos;t++)
1601 if(pic_xids[t] == xid &&
1602 pic_yids[t] == yid) {
1607 if(str->getKind()==strDCT)
1608 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1609 x1,y1,x2,y2,x3,y3,x4,y4);
1611 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1612 x1,y1,x2,y2,x3,y3,x4,y4);
1613 pic_xids[picpos] = xid;
1614 pic_yids[picpos] = yid;
1615 pic_width[picpos] = width;
1616 pic_height[picpos] = height;
1620 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1621 x1,y1,x2,y2,x3,y3,x4,y4);
1629 U8*pic = new U8[width*height];
1637 colorMap->getRGB(pixBuf, &rgb);
1638 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1639 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1640 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1641 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1642 xid += t*r+t*b*3+t*g*7+t*a*11;
1643 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1645 for (y = 0; y < height; ++y) {
1646 for (x = 0; x < width; ++x) {
1647 imgStr->getPixel(pixBuf);
1648 pic[width*y+x] = pixBuf[0];
1649 xid += x*pixBuf[0]*7;
1650 yid += y*pixBuf[0]*3;
1654 for(t=0;t<picpos;t++)
1656 if(pic_xids[t] == xid &&
1657 pic_yids[t] == yid) {
1662 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1663 x1,y1,x2,y2,x3,y3,x4,y4,256);
1664 pic_xids[picpos] = xid;
1665 pic_yids[picpos] = yid;
1666 pic_width[picpos] = width;
1667 pic_height[picpos] = height;
1671 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1672 x1,y1,x2,y2,x3,y3,x4,y4);
1680 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1681 int width, int height, GBool invert,
1684 msg("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1685 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1688 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1689 int width, int height, GfxImageColorMap *colorMap,
1690 int *maskColors, GBool inlineImg)
1692 msg("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1693 colorMap?"colorMap":"no colorMap",
1694 maskColors?"maskColors":"no maskColors",
1697 msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1698 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1699 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1702 SWFOutputDev*output = 0;
1704 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1709 if (infoDict->lookup(key, &obj)->isString()) {
1710 s1 = obj.getString();
1711 if ((s1->getChar(0) & 0xff) == 0xfe &&
1712 (s1->getChar(1) & 0xff) == 0xff) {
1714 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1715 if (s1->getChar(i) == '\0') {
1716 s2->append(s1->getChar(i+1));
1719 s2 = new GString("<unicode>");
1723 printf(fmt, s2->getCString());
1726 printf(fmt, s1->getCString());
1732 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1736 if (infoDict->lookup(key, &obj)->isString()) {
1737 s = obj.getString()->getCString();
1738 if (s[0] == 'D' && s[1] == ':') {
1746 void pdfswf_init(char*filename, char*userPassword)
1748 GString *fileName = new GString(filename);
1753 globalParams = new GlobalParams("");
1756 if (userPassword && userPassword[0]) {
1757 userPW = new GString(userPassword);
1761 doc = new PDFDoc(fileName, userPW);
1770 doc->getDocInfo(&info);
1771 if (info.isDict() &&
1772 (screenloglevel>=LOGLEVEL_NOTICE)) {
1773 printInfoString(info.getDict(), "Title", "Title: %s\n");
1774 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1775 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1776 printInfoString(info.getDict(), "Author", "Author: %s\n");
1777 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1778 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1779 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1780 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1781 printf("Pages: %d\n", doc->getNumPages());
1782 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1783 printf("Encrypted: ");
1784 if (doc->isEncrypted()) {
1785 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1786 doc->okToPrint() ? "yes" : "no",
1787 doc->okToCopy() ? "yes" : "no",
1788 doc->okToChange() ? "yes" : "no",
1789 doc->okToAddNotes() ? "yes" : "no");
1796 numpages = doc->getNumPages();
1797 if (doc->isEncrypted()) {
1798 /*ERROR: This pdf is encrypted, and disallows copying.
1799 Due to the DMCA, paragraph 1201, (2) A-C, circumventing
1800 a technological measure that efficively controls access to
1801 a protected work is violating American law.
1802 See www.eff.org for more information about DMCA issues.
1804 if(!doc->okToCopy()) {
1805 printf("PDF disallows copying. Bailing out.\n");
1808 if(!doc->okToChange() || !doc->okToAddNotes())
1809 swfoutput_setprotected();
1812 output = new SWFOutputDev();
1813 output->startDoc(doc->getXRef());
1816 void pdfswf_setparameter(char*name, char*value)
1818 if(!strcmp(name, "drawonlyshapes")) {
1819 drawonlyshapes = atoi(value);
1820 } else if(!strcmp(name, "ignoredraworder")) {
1821 ignoredraworder = atoi(value);
1822 } else if(!strcmp(name, "linksopennewwindow")) {
1823 opennewwindow = atoi(value);
1824 } else if(!strcmp(name, "storeallcharacters")) {
1825 storeallcharacters = atoi(value);
1826 } else if(!strcmp(name, "enablezlib")) {
1827 enablezlib = atoi(value);
1828 } else if(!strcmp(name, "insertstop")) {
1829 insertstoptag = atoi(value);
1830 } else if(!strcmp(name, "flashversion")) {
1831 flashversion = atoi(value);
1832 } else if(!strcmp(name, "jpegquality")) {
1833 int val = atoi(value);
1835 if(val>100) val=100;
1837 } else if(!strcmp(name, "outputfilename")) {
1838 swffilename = value;
1839 } else if(!strcmp(name, "caplinewidth")) {
1840 caplinewidth = atof(value);
1841 } else if(!strcmp(name, "splinequality")) {
1842 int v = atoi(value);
1843 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1846 } else if(!strcmp(name, "fontquality")) {
1847 int v = atoi(value);
1848 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1850 fontsplinemaxerror = v;
1852 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1856 void pdfswf_drawonlyshapes()
1861 void pdfswf_ignoredraworder()
1863 ignoredraworder = 1;
1866 void pdfswf_linksopennewwindow()
1871 void pdfswf_storeallcharacters()
1873 storeallcharacters = 1;
1876 void pdfswf_enablezlib()
1881 void pdfswf_jpegquality(int val)
1884 if(val>100) val=100;
1888 void pdfswf_setoutputfilename(char*_filename)
1890 swffilename = _filename;
1893 void pdfswf_insertstop()
1898 void pdfswf_setversion(int n)
1904 void pdfswf_convertpage(int page)
1908 pages = (int*)malloc(1024*sizeof(int));
1911 if(pagepos == pagebuflen)
1914 pages = (int*)realloc(pages, pagebuflen);
1917 pages[pagepos++] = page;
1920 void pdfswf_performconversion()
1923 for(t=0;t<pagepos;t++)
1925 currentpage = pages[t];
1926 doc->displayPage((OutputDev*)output, currentpage, /*dpi*/72, /*rotate*/0, /*doLinks*/(int)1);
1930 int pdfswf_numpages()
1932 return doc->getNumPages();
1937 msg("<debug> pdfswf.cc: pdfswf_close()");
1941 // check for memory leaks
1942 Object::memCheck(stderr);