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 #define logf logarithmf // logf is also used by ../lib/log.h
57 static PDFDoc*doc = 0;
58 static char* swffilename = 0;
67 double caplinewidth = 3.0;
69 static void printInfoString(Dict *infoDict, char *key, char *fmt);
70 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
74 0.833,0.833,0.889,0.889,
75 0.788,0.722,0.833,0.778,
76 0.600,0.600,0.600,0.600,
77 0.576,0.576,0.576,0.576,
83 "Helvetica-BoldOblique",
91 "Courier-BoldOblique",
105 {"Times-Roman", "n021003l.pfb"},
106 {"Times-Italic", "n021023l.pfb"},
107 {"Times-Bold", "n021004l.pfb"},
108 {"Times-BoldItalic", "n021024l.pfb"},
109 {"Helvetica", "n019003l.pfb"},
110 {"Helvetica-Oblique", "n019023l.pfb"},
111 {"Helvetica-Bold", "n019004l.pfb"},
112 {"Helvetica-BoldOblique", "n019024l.pfb"},
113 {"Courier", "n022003l.pfb"},
114 {"Courier-Oblique", "n022023l.pfb"},
115 {"Courier-Bold", "n022004l.pfb"},
116 {"Courier-BoldOblique", "n022024l.pfb"},
117 {"Symbol", "s050000l.pfb"},
118 {"ZapfDingbats", "d050000l.pfb"}};
121 class GfxImageColorMap;
123 class SWFOutputDev: public OutputDev {
124 struct swfoutput output;
132 virtual ~SWFOutputDev() ;
134 //----- get info about output device
136 // Does this device use upside-down coordinates?
137 // (Upside-down means (0,0) is the top left corner of the page.)
138 virtual GBool upsideDown();
140 // Does this device use drawChar() or drawString()?
141 virtual GBool useDrawChar();
143 virtual GBool interpretType3Chars() {return gTrue;}
145 //----- initialization and control
147 void startDoc(XRef *xref);
150 virtual void startPage(int pageNum, GfxState *state) ;
153 virtual void drawLink(Link *link, Catalog *catalog) ;
155 //----- save/restore graphics state
156 virtual void saveState(GfxState *state) ;
157 virtual void restoreState(GfxState *state) ;
159 //----- update graphics state
161 virtual void updateFont(GfxState *state);
162 virtual void updateFillColor(GfxState *state);
163 virtual void updateStrokeColor(GfxState *state);
164 virtual void updateLineWidth(GfxState *state);
165 virtual void updateLineJoin(GfxState *state);
166 virtual void updateLineCap(GfxState *state);
168 virtual void updateAll(GfxState *state)
171 updateFillColor(state);
172 updateStrokeColor(state);
173 updateLineWidth(state);
174 updateLineJoin(state);
175 updateLineCap(state);
178 //----- path painting
179 virtual void stroke(GfxState *state) ;
180 virtual void fill(GfxState *state) ;
181 virtual void eoFill(GfxState *state) ;
183 //----- path clipping
184 virtual void clip(GfxState *state) ;
185 virtual void eoClip(GfxState *state) ;
188 virtual void beginString(GfxState *state, GString *s) ;
189 virtual void endString(GfxState *state) ;
190 virtual void drawChar(GfxState *state, double x, double y,
191 double dx, double dy,
192 double originX, double originY,
193 CharCode code, Unicode *u, int uLen);
195 //----- image drawing
196 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
197 int width, int height, GBool invert,
199 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
200 int width, int height, GfxImageColorMap *colorMap,
201 int *maskColors, GBool inlineImg);
203 virtual GBool beginType3Char(GfxState *state,
204 CharCode code, Unicode *u, int uLen);
205 virtual void endType3Char(GfxState *state);
208 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
209 int width, int height, GfxImageColorMap*colorMap, GBool invert,
210 GBool inlineImg, int mask);
216 int searchT1Font(char*name);
217 char* substituteFont(GfxFont*gfxFont, char*oldname);
218 char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
220 int jpeginfo; // did we write "File contains jpegs" yet?
221 int pbminfo; // did we write "File contains jpegs" yet?
222 int linkinfo; // did we write "File contains links" yet?
223 int ttfinfo; // did we write "File contains TrueType Fonts" yet?
225 int type3active; // are we between beginType3()/endType3()?
231 char* gfxstate2str(GfxState *state)
235 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
242 if(state->getX1()!=0.0)
243 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
244 if(state->getY1()!=0.0)
245 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
246 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
247 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
248 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
249 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
250 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
251 state->getFillColor()->c[0], state->getFillColor()->c[1]);
252 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
253 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
254 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
255 state->getFillColor()->c[0], state->getFillColor()->c[1],
256 state->getFillColor()->c[2], state->getFillColor()->c[3],
257 state->getFillColor()->c[4], state->getFillColor()->c[5],
258 state->getFillColor()->c[6], state->getFillColor()->c[7]);
259 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
260 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
261 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
262 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
263 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
264 state->getFillRGB(&rgb);
265 if(rgb.r || rgb.g || rgb.b)
266 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
267 state->getStrokeRGB(&rgb);
268 if(rgb.r || rgb.g || rgb.b)
269 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
270 if(state->getFillColorSpace()->getNComps()>1)
271 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
272 if(state->getStrokeColorSpace()->getNComps()>1)
273 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
274 if(state->getFillPattern())
275 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
276 if(state->getStrokePattern())
277 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
279 if(state->getFillOpacity()!=1.0)
280 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
281 if(state->getStrokeOpacity()!=1.0)
282 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
284 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
289 state->getLineDash(&dash, &length, &start);
293 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
294 for(t=0;t<length;t++) {
295 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
297 bufpos+=sprintf(bufpos,"]");
300 if(state->getFlatness()!=1)
301 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
302 if(state->getLineJoin()!=0)
303 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
304 if(state->getLineJoin()!=0)
305 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
306 if(state->getLineJoin()!=0)
307 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
309 if(state->getFont() && state->getFont()->getName() && state->getFont()->getName()->getCString())
310 bufpos+=sprintf(bufpos,"F\"%s\" ",((state->getFont())->getName())->getCString());
311 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
312 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
313 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
314 if(state->getCharSpace())
315 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
316 if(state->getWordSpace())
317 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
318 if(state->getHorizScaling()!=1.0)
319 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
320 if(state->getLeading())
321 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
323 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
324 if(state->getRender())
325 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
326 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
327 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
328 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
329 if(state->getLineX())
330 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
331 if(state->getLineY())
332 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
333 bufpos+=sprintf(bufpos," ");
337 void dumpFontInfo(char*loglevel, GfxFont*font);
344 void showFontError(GfxFont*font, int nr)
348 for(t=0;t<lastdumppos;t++)
349 if(lastdumps[t] == r->num)
353 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
354 lastdumps[lastdumppos++] = r->num;
356 logf("<warning> The following font caused problems:");
358 logf("<warning> The following font caused problems (substituting):");
360 logf("<warning> The following Type 3 Font will be rendered as bitmap:");
361 dumpFontInfo("<warning>", font);
364 void dumpFontInfo(char*loglevel, GfxFont*font)
368 gstr = font->getName();
369 Ref* r=font->getID();
370 logf("%s=========== %s (ID:%d,%d) ==========\n", loglevel, gstr?FIXNULL(gstr->getCString()):"(unknown font)", r->num,r->gen);
372 gstr = font->getTag();
374 logf("%sTag: %s\n", loglevel, FIXNULL(gstr->getCString()));
376 if(font->isCIDFont()) logf("%sis CID font\n", loglevel);
378 GfxFontType type=font->getType();
380 case fontUnknownType:
381 logf("%sType: unknown\n",loglevel);
384 logf("%sType: 1\n",loglevel);
387 logf("%sType: 1C\n",loglevel);
390 logf("%sType: 3\n",loglevel);
393 logf("%sType: TrueType\n",loglevel);
396 logf("%sType: CIDType0\n",loglevel);
399 logf("%sType: CIDType0C\n",loglevel);
402 logf("%sType: CIDType2\n",loglevel);
407 GBool embedded = font->getEmbeddedFontID(&embRef);
408 if(font->getEmbeddedFontName())
409 name = font->getEmbeddedFontName()->getCString();
411 logf("%sEmbedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
413 gstr = font->getExtFontFile();
415 logf("%sExternal Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
417 // Get font descriptor flags.
418 if(font->isFixedWidth()) logf("%sis fixed width\n", loglevel);
419 if(font->isSerif()) logf("%sis serif\n", loglevel);
420 if(font->isSymbolic()) logf("%sis symbolic\n", loglevel);
421 if(font->isItalic()) logf("%sis italic\n", loglevel);
422 if(font->isBold()) logf("%sis bold\n", loglevel);
425 //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");}
426 //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");}
428 SWFOutputDev::SWFOutputDev()
436 clipping[clippos] = 0;
439 // printf("SWFOutputDev::SWFOutputDev() \n");
442 T1_OUTLINE* gfxPath_to_T1_OUTLINE(GfxState*state, GfxPath*path)
444 int num = path->getNumSubpaths();
446 bezierpathsegment*start,*last=0;
447 bezierpathsegment*outline = start = new bezierpathsegment();
449 double lastx=0,lasty=0;
451 logf("<warning> empty path");
452 outline->type = T1_PATHTYPE_MOVE;
456 return (T1_OUTLINE*)outline;
458 for(t = 0; t < num; t++) {
459 GfxSubpath *subpath = path->getSubpath(t);
460 int subnum = subpath->getNumPoints();
462 for(s=0;s<subnum;s++) {
464 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
465 int x = (int)((nx-lastx)*0xffff);
466 int y = (int)((ny-lasty)*0xffff);
470 outline->type = T1_PATHTYPE_MOVE;
473 outline->link = (T1_OUTLINE*)new bezierpathsegment();
474 outline = (bezierpathsegment*)outline->link;
479 else if(subpath->getCurve(s) && !cpos)
485 else if(subpath->getCurve(s) && cpos)
496 outline->type = cpos?T1_PATHTYPE_BEZIER:T1_PATHTYPE_LINE;
498 outline->link = (T1_OUTLINE*)new bezierpathsegment();
499 outline = (bezierpathsegment*)outline->link;
507 return (T1_OUTLINE*)start;
509 /*----------------------------------------------------------------------------
510 * Primitive Graphic routines
511 *----------------------------------------------------------------------------*/
513 void SWFOutputDev::stroke(GfxState *state)
515 logf("<debug> stroke\n");
516 GfxPath * path = state->getPath();
517 int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square
518 int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel
519 double miterLimit = state->getMiterLimit();
520 double width = state->getTransformedLineWidth();
523 double opaq = state->getStrokeOpacity();
524 state->getStrokeRGB(&rgb);
526 m.m11 = 1; m.m21 = 0; m.m22 = 1;
527 m.m12 = 0; m.m13 = 0; m.m23 = 0;
528 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
530 lineJoin = 1; // other line joins are not yet supported by the swf encoder
531 // TODO: support bevel joints
533 if(((lineCap==1) && (lineJoin==1)) || width<=caplinewidth) {
534 /* FIXME- if the path is smaller than 2 segments, we could ignore
536 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
537 swfoutput_drawpath(&output, outline, &m);
539 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
540 (char)(rgb.b*255), (char)(opaq*255));
542 //swfoutput_setlinewidth(&output, 1.0); //only for debugging
543 //swfoutput_setstrokecolor(&output, 0, 255, 0, 255); //likewise, see below
544 //swfoutput_setfillcolor(&output, 255, 0, 0, 255); //likewise, see below
546 swfoutput_drawpath2poly(&output, outline, &m, lineJoin, lineCap, width, miterLimit);
547 updateLineWidth(state); //reset
548 updateStrokeColor(state); //reset
549 updateFillColor(state); //reset
552 void SWFOutputDev::fill(GfxState *state)
554 logf("<debug> fill\n");
555 GfxPath * path = state->getPath();
557 m.m11 = 1; m.m21 = 0; m.m22 = 1;
558 m.m12 = 0; m.m13 = 0; m.m23 = 0;
559 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
560 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
561 swfoutput_drawpath(&output, outline, &m);
563 void SWFOutputDev::eoFill(GfxState *state)
565 logf("<debug> eofill\n");
566 GfxPath * path = state->getPath();
568 m.m11 = 1; m.m21 = 0; m.m22 = 1;
569 m.m12 = 0; m.m13 = 0; m.m23 = 0;
570 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
571 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
572 swfoutput_drawpath(&output, outline, &m);
574 void SWFOutputDev::clip(GfxState *state)
576 logf("<debug> clip\n");
577 GfxPath * path = state->getPath();
579 m.m11 = 1; m.m22 = 1;
580 m.m12 = 0; m.m21 = 0;
581 m.m13 = 0; m.m23 = 0;
582 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
583 swfoutput_startclip(&output, outline, &m);
584 clipping[clippos] ++;
586 void SWFOutputDev::eoClip(GfxState *state)
588 logf("<debug> eoclip\n");
589 GfxPath * path = state->getPath();
591 m.m11 = 1; m.m21 = 0; m.m22 = 1;
592 m.m12 = 0; m.m13 = 0; m.m23 = 0;
593 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
594 swfoutput_startclip(&output, outline, &m);
595 clipping[clippos] ++;
598 SWFOutputDev::~SWFOutputDev()
600 swfoutput_destroy(&output);
603 GBool SWFOutputDev::upsideDown()
605 logf("<debug> upsidedown?");
608 GBool SWFOutputDev::useDrawChar()
610 logf("<debug> usedrawchar?");
614 void SWFOutputDev::beginString(GfxState *state, GString *s)
616 double m11,m21,m12,m22;
617 // logf("<debug> %s beginstring \"%s\"\n", gfxstate2str(state), s->getCString());
618 state->getFontTransMat(&m11, &m12, &m21, &m22);
619 m11 *= state->getHorizScaling();
620 m21 *= state->getHorizScaling();
621 swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
625 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
626 double dx, double dy,
627 double originX, double originY,
628 CharCode c, Unicode *_u, int uLen)
630 logf("<debug> drawChar(%f,%f,%f,%f,'%c')\n",x,y,dx,dy,c);
632 // check for invisible text -- this is used by Acrobat Capture
633 if ((state->getRender() & 3) == 3)
636 GfxFont*font = state->getFont();
638 if(font->getType() == fontType3) {
639 /* type 3 chars are passed primarily as graphics */
645 state->transform(x, y, &x1, &y1);
647 if(font->isCIDFont()) {
648 GfxCIDFont*cfont = (GfxCIDFont*)font;
655 for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++)
656 /* todo: should be precomputed */
657 if(nameToUnicodeTab[t].u == u) {
658 name = nameToUnicodeTab[t].name;
662 /* printf("%02x %04x/%04x-%d \"%s\" %s %d\n", c,u, *_u, uLen, name, cfont->getName()->getCString(),
666 swfoutput_drawchar(&output, x1, y1, name, c);
668 logf("<warning> couldn't get name for CID character %02x from Encoding", c);
671 font8 = (Gfx8BitFont*)font;
672 char**enc=font8->getEncoding();
675 swfoutput_drawchar(&output, x1, y1, enc[c], c);
677 logf("<warning> couldn't get name for character %02x from Encoding", c);
682 void SWFOutputDev::endString(GfxState *state)
684 logf("<debug> endstring\n");
688 GBool SWFOutputDev::beginType3Char(GfxState *state,
689 CharCode code, Unicode *u, int uLen)
691 logf("<debug> beginType3Char %d, %08x, %d", code, *u, uLen);
693 /* the character itself is going to be passed using
695 return gFalse; /* gTrue= is_in_cache? */
698 void SWFOutputDev::endType3Char(GfxState *state)
701 logf("<debug> endType3Char");
704 void SWFOutputDev::startPage(int pageNum, GfxState *state)
708 logf("<debug> startPage %d\n", pageNum);
709 logf("<notice> processing page %d", pageNum);
711 state->transform(state->getX1(),state->getY1(),&x1,&y1);
712 state->transform(state->getX2(),state->getY2(),&x2,&y2);
714 swfoutput_init(&output, swffilename, abs((int)(x2-x1)),abs((int)(y2-y1)));
718 swfoutput_newpage(&output);
721 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
723 logf("<debug> drawlink\n");
724 double x1, y1, x2, y2, w;
729 link->getBorder(&x1, &y1, &x2, &y2, &w);
735 cvtUserToDev(x1, y1, &x, &y);
736 points[0].x = points[4].x = (int)x;
737 points[0].y = points[4].y = (int)y;
738 cvtUserToDev(x2, y1, &x, &y);
739 points[1].x = (int)x;
740 points[1].y = (int)y;
741 cvtUserToDev(x2, y2, &x, &y);
742 points[2].x = (int)x;
743 points[2].y = (int)y;
744 cvtUserToDev(x1, y2, &x, &y);
745 points[3].x = (int)x;
746 points[3].y = (int)y;
748 LinkAction*action=link->getAction();
755 switch(action->getKind())
759 LinkGoTo *ha=(LinkGoTo *)link->getAction();
761 if (ha->getDest()==NULL)
762 dest=catalog->findDest(ha->getNamedDest());
763 else dest=ha->getDest();
765 if (dest->isPageRef()){
766 Ref pageref=dest->getPageRef();
767 page=catalog->findPage(pageref.num,pageref.gen);
769 else page=dest->getPageNum();
770 sprintf(buf, "%d", page);
777 LinkGoToR*l = (LinkGoToR*)action;
778 GString*g = l->getNamedDest();
785 LinkNamed*l = (LinkNamed*)action;
786 GString*name = l->getName();
788 s = name->lowerCase()->getCString();
789 named = name->getCString();
792 if(strstr(s, "next") || strstr(s, "forward"))
794 page = currentpage + 1;
796 else if(strstr(s, "prev") || strstr(s, "back"))
798 page = currentpage - 1;
800 else if(strstr(s, "last") || strstr(s, "end"))
802 page = pages[pagepos-1]; //:)
804 else if(strstr(s, "first") || strstr(s, "top"))
814 LinkLaunch*l = (LinkLaunch*)action;
815 GString * str = new GString(l->getFileName());
816 str->append(l->getParams());
817 s = str->getCString();
822 LinkURI*l = (LinkURI*)action;
823 GString*g = l->getURI();
825 url = g->getCString();
830 case actionUnknown: {
832 LinkUnknown*l = (LinkUnknown*)action;
837 logf("<error> Unknown link type!\n");
841 if(!linkinfo && (page || url))
843 logf("<notice> File contains links");
849 for(t=0;t<pagepos;t++)
853 swfoutput_linktopage(&output, t, points);
857 swfoutput_linktourl(&output, url, points);
861 swfoutput_namedlink(&output, named, points);
863 logf("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
867 void SWFOutputDev::saveState(GfxState *state) {
868 logf("<debug> saveState\n");
873 logf("<error> Too many nested states in pdf.");
874 clipping[clippos] = 0;
877 void SWFOutputDev::restoreState(GfxState *state) {
878 logf("<debug> restoreState\n");
880 while(clipping[clippos]) {
881 swfoutput_endclip(&output);
889 int SWFOutputDev::searchT1Font(char*name)
895 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
897 if(!strcmp(name, pdf2t1map[i].pdffont))
899 filename = pdf2t1map[i].filename;
904 for(i=0; i<T1_Get_no_fonts(); i++)
906 char*fontfilename = T1_GetFontFileName (i);
907 if(strstr(fontfilename, filename))
909 pdf2t1map[i].id = mapid;
914 for(i=0; i<T1_Get_no_fonts(); i++)
916 char*fontname = T1_GetFontName (i);
919 fontname = T1_GetFontName (i);
920 logf("<verbose> Loading extra font %s from %s\n", FIXNULL(fontname),
921 FIXNULL(T1_GetFontFileName(i)));
924 if(fontname && !strcmp(name, fontname)) {
925 logf("<notice> Extra font %d, \"%s\" is being used.\n", i, fontname);
928 fontname = T1_GetFontFileName(i);
929 if(strrchr(fontname,'/'))
930 fontname = strrchr(fontname,'/')+1;
932 if(strstr(fontname, name)) {
933 logf("<notice> Extra font %d, \"%s\" is being used.\n", i, fontname);
941 void SWFOutputDev::updateLineWidth(GfxState *state)
943 double width = state->getTransformedLineWidth();
944 swfoutput_setlinewidth(&output, width);
947 void SWFOutputDev::updateLineCap(GfxState *state)
949 int c = state->getLineCap();
952 void SWFOutputDev::updateLineJoin(GfxState *state)
954 int j = state->getLineJoin();
957 void SWFOutputDev::updateFillColor(GfxState *state)
960 double opaq = state->getFillOpacity();
961 state->getFillRGB(&rgb);
963 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
964 (char)(rgb.b*255), (char)(opaq*255));
967 void SWFOutputDev::updateStrokeColor(GfxState *state)
970 double opaq = state->getStrokeOpacity();
971 state->getStrokeRGB(&rgb);
973 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
974 (char)(rgb.b*255), (char)(opaq*255));
977 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
979 char*tmpFileName = NULL;
986 Object refObj, strObj;
987 tmpFileName = "/tmp/tmpfont";
990 ret = font->getEmbeddedFontID(&embRef);
992 logf("<verbose> Didn't get embedded font id");
993 /* not embedded- the caller should now search the font
994 directories for this font */
998 f = fopen(tmpFileName, "wb");
1000 logf("<error> Couldn't create temporary Type 1 font file");
1003 if (font->getType() == fontType1C) {
1004 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1006 logf("<error> Couldn't read embedded font file");
1009 cvt = new Type1CFontFile(fontBuf, fontLen);
1010 cvt->convertToType1(f);
1014 font->getEmbeddedFontID(&embRef);
1015 refObj.initRef(embRef.num, embRef.gen);
1016 refObj.fetch(ref, &strObj);
1018 strObj.streamReset();
1023 f4[t] = strObj.streamGetChar();
1024 f4c[t] = (char)f4[t];
1029 if(!strncmp(f4c, "true", 4)) {
1030 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1031 Change this on the fly */
1032 f4[0] = f4[2] = f4[3] = 0;
1040 while ((c = strObj.streamGetChar()) != EOF) {
1044 strObj.streamClose();
1049 if(font->getType() == fontTrueType ||
1050 font->getType() == fontCIDType2)
1053 logf("<notice> File contains TrueType fonts");
1058 tmp = strdup(mktmpname((char*)name2));
1059 sprintf(name2, "%s", tmp);
1060 char*a[] = {"./ttf2pt1",
1061 #ifndef USE_FREETYPE
1066 "-b", tmpFileName, name2};
1067 logf("<verbose> Invoking ttf2pt1...");
1069 unlink(tmpFileName);
1070 sprintf(name2,"%s.pfb",tmp);
1071 tmpFileName = strdup(name2);
1077 char* gfxFontName(GfxFont* gfxFont)
1080 gstr = gfxFont->getName();
1082 return gstr->getCString();
1086 Ref*r=gfxFont->getID();
1087 sprintf(buf, "UFONT%d", r->num);
1092 char* substitutetarget[256];
1093 char* substitutesource[256];
1094 int substitutepos = 0;
1096 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1098 /* ------------------------------ V1 */
1100 char*fontname = "Times-Roman";
1101 logf("<verbose> substituteFont(,%s)", FIXNULL(oldname));
1102 this->t1id = searchT1Font(fontname);
1103 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1104 logf("<fatal> Too many fonts in file.");
1108 substitutesource[substitutepos] = oldname;
1109 substitutetarget[substitutepos] = fontname;
1110 logf("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1115 /* ------------------------------ V2 */
1117 /* //substitute font
1119 double m11, m12, m21, m22;
1125 if(gfxFont->getName()) {
1126 fontname = gfxFont->getName()->getCString();
1129 // printf("%d %s\n", t, gfxFont->getCharName(t));
1130 showFontError(gfxFont, 1);
1131 if(1) { //if (!gfxFont->isCIDFont()) { FIXME: xpdf 1.01 does not have is16Bit()
1132 if(gfxFont->isSymbolic()) {
1133 if(fontname && (strstr(fontname,"ing"))) //Dingbats, Wingdings etc.
1137 } else if (gfxFont->isFixedWidth()) {
1139 } else if (gfxFont->isSerif()) {
1144 if (gfxFont->isBold() && index!=16)
1146 if (gfxFont->isItalic() && index!=16)
1148 fontname = fontnames[index];
1149 // get width of 'm' in real font and substituted font
1150 if ((code = gfxFont->getCharCode("m")) >= 0)
1151 w1 = gfxFont->getWidth(code);
1154 w2 = fontsizes[index];
1155 if (gfxFont->getType() == fontType3) {
1156 // This is a hack which makes it possible to substitute for some
1157 // Type 3 fonts. The problem is that it's impossible to know what
1158 // the base coordinate system used in the font is without actually
1159 // rendering the font. This code tries to guess by looking at the
1160 // width of the character 'm' (which breaks if the font is a
1161 // subset that doesn't contain 'm').
1162 if (w1 > 0 && (w1 > 1.1 * w2 || w1 < 0.9 * w2)) {
1169 fm = gfxFont->getFontMatrix();
1170 v = (fm[0] == 0) ? 1 : (fm[3] / fm[0]);
1173 } else if (!gfxFont->isSymbolic()) {
1174 // if real font is substantially narrower than substituted
1175 // font, reduce the font size accordingly
1176 if (w1 > 0.01 && w1 < 0.9 * w2) {
1189 this->t1id = searchT1Font(fontname);
1191 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1192 logf("<fatal> Too many fonts in file.");
1196 substitutesource[substitutepos] = oldname;
1197 substitutetarget[substitutepos] = fontname;
1198 logf("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1204 void unlinkfont(char* filename)
1211 if(!strncmp(&filename[l-4],".afm",4)) {
1212 memcpy(&filename[l-4],".pfb",4);
1214 memcpy(&filename[l-4],".pfa",4);
1216 memcpy(&filename[l-4],".afm",4);
1219 if(!strncmp(&filename[l-4],".pfa",4)) {
1220 memcpy(&filename[l-4],".afm",4);
1222 memcpy(&filename[l-4],".pfa",4);
1225 if(!strncmp(&filename[l-4],".pfb",4)) {
1226 memcpy(&filename[l-4],".afm",4);
1228 memcpy(&filename[l-4],".pfb",4);
1233 void SWFOutputDev::startDoc(XRef *xref)
1239 void SWFOutputDev::updateFont(GfxState *state)
1241 GfxFont*gfxFont = state->getFont();
1242 char * fileName = 0;
1247 char * fontname = gfxFontName(gfxFont);
1250 /* first, look if we substituted this font before-
1251 this way, we don't initialize the T1 Fonts
1253 for(t=0;t<substitutepos;t++) {
1254 if(!strcmp(fontname, substitutesource[t])) {
1255 fontname = substitutetarget[t];
1260 /* second, see if swfoutput already has this font
1261 cached- if so, we are done */
1263 if(swfoutput_queryfont(&output, fontname))
1265 swfoutput_setfont(&output, fontname, -1, 0);
1269 // look for Type 3 font
1270 if (!type3Warning && gfxFont->getType() == fontType3) {
1271 type3Warning = gTrue;
1272 showFontError(gfxFont, 2);
1275 /* now either load the font, or find a substitution */
1278 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1280 if (gfxFont->getType() == fontType1 ||
1281 gfxFont->getType() == fontType1C ||
1282 gfxFont->getType() == fontTrueType ||
1283 gfxFont->getType() == fontCIDType2)
1285 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1287 logf("<error> Couldn't write font to file");
1288 showFontError(gfxFont,0);
1291 this->t1id = T1_AddFont(fileName);
1293 logf("<error> Couldn't load font from file");
1294 showFontError(gfxFont,0);
1295 unlinkfont(fileName);
1300 /* in case the font is embedded, but has an
1301 unsupported format, we just look through the
1303 int newt1id = searchT1Font(fontname);
1305 showFontError(gfxFont,0);
1306 fontname = substituteFont(gfxFont, fontname);
1308 this->t1id = newt1id;
1312 int newt1id = searchT1Font(fontname);
1314 showFontError(gfxFont,1);
1315 fontname = substituteFont(gfxFont, fontname);
1317 this->t1id = newt1id;
1320 showFontError(gfxFont,1);
1321 fontname = substituteFont(gfxFont, fontname);
1326 showFontError(gfxFont,0);
1330 /* we may have done some substitutions here, so check
1331 again if this font is cached. */
1332 if(swfoutput_queryfont(&output, fontname))
1334 swfoutput_setfont(&output, fontname, -1, 0);
1338 logf("<verbose> Creating new SWF font: t1id: %d, filename: %s name:%s", this->t1id, FIXNULL(fileName), FIXNULL(fontname));
1339 swfoutput_setfont(&output, fontname, this->t1id, fileName);
1341 unlinkfont(fileName);
1347 int pic_width[1024];
1348 int pic_height[1024];
1352 #define SQR(x) ((x)*(x))
1354 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1356 if((newwidth<2 || newheight<2) ||
1357 (width<=newwidth || height<=newheight))
1359 unsigned char*newdata;
1361 newdata= (unsigned char*)malloc(newwidth*newheight);
1363 double fx = (double)(width)/newwidth;
1364 double fy = (double)(height)/newheight;
1366 int blocksize = (int)(8192/(fx*fy));
1367 int r = 8192*256/palettesize;
1368 for(x=0;x<newwidth;x++) {
1369 double ex = px + fx;
1370 int fromx = (int)px;
1372 int xweight1 = (int)(((fromx+1)-px)*256);
1373 int xweight2 = (int)((ex-tox)*256);
1375 for(y=0;y<newheight;y++) {
1376 double ey = py + fy;
1377 int fromy = (int)py;
1379 int yweight1 = (int)(((fromy+1)-py)*256);
1380 int yweight2 = (int)((ey-toy)*256);
1383 for(xx=fromx;xx<=tox;xx++)
1384 for(yy=fromy;yy<=toy;yy++) {
1385 int b = 1-data[width*yy+xx];
1387 if(xx==fromx) weight = (weight*xweight1)/256;
1388 if(xx==tox) weight = (weight*xweight2)/256;
1389 if(yy==fromy) weight = (weight*yweight1)/256;
1390 if(yy==toy) weight = (weight*yweight2)/256;
1393 //if(a) a=(palettesize-1)*r/blocksize;
1394 newdata[y*newwidth+x] = (a*blocksize)/r;
1402 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1403 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1404 GBool inlineImg, int mask)
1409 double x1,y1,x2,y2,x3,y3,x4,y4;
1410 ImageStream *imgStr;
1417 ncomps = colorMap->getNumPixelComps();
1418 bits = colorMap->getBits();
1420 imgStr = new ImageStream(str, width, ncomps,bits);
1423 if(!width || !height || (height<=1 && width<=1))
1425 logf("<verbose> Ignoring %d by %d image", width, height);
1426 unsigned char buf[8];
1428 for (y = 0; y < height; ++y)
1429 for (x = 0; x < width; ++x) {
1430 imgStr->getPixel(buf);
1436 state->transform(0, 1, &x1, &y1);
1437 state->transform(0, 0, &x2, &y2);
1438 state->transform(1, 0, &x3, &y3);
1439 state->transform(1, 1, &x4, &y4);
1441 if(!pbminfo && !(str->getKind()==strDCT)) {
1443 logf("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1447 logf("<verbose> drawing %d by %d masked picture\n", width, height);
1449 if(!jpeginfo && (str->getKind()==strDCT)) {
1450 logf("<notice> file contains jpeg pictures");
1456 unsigned char buf[8];
1460 unsigned char*pic = new unsigned char[width*height];
1463 state->getFillRGB(&rgb);
1464 memset(pal,255,sizeof(pal));
1465 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1466 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1467 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1469 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1470 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1471 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1472 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1473 for (y = 0; y < height; ++y)
1474 for (x = 0; x < width; ++x)
1476 imgStr->getPixel(buf);
1479 pic[width*y+x] = buf[0];
1484 /* the size of the drawn image is added to the identifier
1485 as the same image may require different bitmaps if displayed
1486 at different sizes (due to antialiasing): */
1492 for(t=0;t<picpos;t++)
1494 if(pic_xids[t] == xid &&
1495 pic_yids[t] == yid) {
1496 /* if the image was antialiased, the size has changed: */
1497 width = pic_width[t];
1498 height = pic_height[t];
1505 unsigned char*pic2 = 0;
1507 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1511 height = realheight;
1514 /* make a black/white palette */
1521 float r = 255/(numpalette-1);
1522 for(t=0;t<numpalette;t++) {
1523 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1524 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1525 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1527 pal[t].r = (U8)(255*rgb.r);
1528 pal[t].g = (U8)(255*rgb.g);
1529 pal[t].b = (U8)(255*rgb.b);
1530 pal[t].a = (U8)(t*r);
1534 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1535 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1536 pic_xids[picpos] = xid;
1537 pic_yids[picpos] = yid;
1538 pic_width[picpos] = width;
1539 pic_height[picpos] = height;
1543 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1544 x1,y1,x2,y2,x3,y3,x4,y4);
1553 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1555 RGBA*pic=new RGBA[width*height];
1558 for (y = 0; y < height; ++y) {
1559 for (x = 0; x < width; ++x) {
1561 imgStr->getPixel(pixBuf);
1562 colorMap->getRGB(pixBuf, &rgb);
1563 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1564 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1565 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1566 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1567 xid += x*r+x*b*3+x*g*7+x*a*11;
1568 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1572 for(t=0;t<picpos;t++)
1574 if(pic_xids[t] == xid &&
1575 pic_yids[t] == yid) {
1580 if(str->getKind()==strDCT)
1581 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1582 x1,y1,x2,y2,x3,y3,x4,y4);
1584 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1585 x1,y1,x2,y2,x3,y3,x4,y4);
1586 pic_xids[picpos] = xid;
1587 pic_yids[picpos] = yid;
1588 pic_width[picpos] = width;
1589 pic_height[picpos] = height;
1593 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1594 x1,y1,x2,y2,x3,y3,x4,y4);
1602 U8*pic = new U8[width*height];
1610 colorMap->getRGB(pixBuf, &rgb);
1611 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1612 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1613 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1614 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1615 xid += t*r+t*b*3+t*g*7+t*a*11;
1616 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1618 for (y = 0; y < height; ++y) {
1619 for (x = 0; x < width; ++x) {
1620 imgStr->getPixel(pixBuf);
1621 pic[width*y+x] = pixBuf[0];
1622 xid += x*pixBuf[0]*7;
1623 yid += y*pixBuf[0]*3;
1627 for(t=0;t<picpos;t++)
1629 if(pic_xids[t] == xid &&
1630 pic_yids[t] == yid) {
1635 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1636 x1,y1,x2,y2,x3,y3,x4,y4,256);
1637 pic_xids[picpos] = xid;
1638 pic_yids[picpos] = yid;
1639 pic_width[picpos] = width;
1640 pic_height[picpos] = height;
1644 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1645 x1,y1,x2,y2,x3,y3,x4,y4);
1653 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1654 int width, int height, GBool invert,
1657 logf("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1658 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1661 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1662 int width, int height, GfxImageColorMap *colorMap,
1663 int *maskColors, GBool inlineImg)
1665 logf("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1666 colorMap?"colorMap":"no colorMap",
1667 maskColors?"maskColors":"no maskColors",
1670 logf("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1671 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1672 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1675 SWFOutputDev*output = 0;
1677 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1682 if (infoDict->lookup(key, &obj)->isString()) {
1683 s1 = obj.getString();
1684 if ((s1->getChar(0) & 0xff) == 0xfe &&
1685 (s1->getChar(1) & 0xff) == 0xff) {
1687 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1688 if (s1->getChar(i) == '\0') {
1689 s2->append(s1->getChar(i+1));
1692 s2 = new GString("<unicode>");
1696 printf(fmt, s2->getCString());
1699 printf(fmt, s1->getCString());
1705 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1709 if (infoDict->lookup(key, &obj)->isString()) {
1710 s = obj.getString()->getCString();
1711 if (s[0] == 'D' && s[1] == ':') {
1719 void pdfswf_init(char*filename, char*userPassword)
1721 GString *fileName = new GString(filename);
1726 globalParams = new GlobalParams("");
1729 if (userPassword && userPassword[0]) {
1730 userPW = new GString(userPassword);
1734 doc = new PDFDoc(fileName, userPW);
1743 doc->getDocInfo(&info);
1744 if (info.isDict() &&
1745 (screenloglevel>=LOGLEVEL_NOTICE)) {
1746 printInfoString(info.getDict(), "Title", "Title: %s\n");
1747 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1748 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1749 printInfoString(info.getDict(), "Author", "Author: %s\n");
1750 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1751 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1752 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1753 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1754 printf("Pages: %d\n", doc->getNumPages());
1755 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1756 printf("Encrypted: ");
1757 if (doc->isEncrypted()) {
1758 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1759 doc->okToPrint() ? "yes" : "no",
1760 doc->okToCopy() ? "yes" : "no",
1761 doc->okToChange() ? "yes" : "no",
1762 doc->okToAddNotes() ? "yes" : "no");
1769 numpages = doc->getNumPages();
1770 if (doc->isEncrypted()) {
1771 /*ERROR: This pdf is encrypted, and disallows copying.
1772 Due to the DMCA, paragraph 1201, (2) A-C, circumventing
1773 a technological measure that efficively controls access to
1774 a protected work is violating American law.
1775 See www.eff.org for more information about DMCA issues.
1777 if(!doc->okToCopy()) {
1778 printf("PDF disallows copying. Bailing out.\n");
1781 if(!doc->okToChange() || !doc->okToAddNotes())
1782 swfoutput_setprotected();
1785 output = new SWFOutputDev();
1786 output->startDoc(doc->getXRef());
1789 void pdfswf_setparameter(char*name, char*value)
1791 if(!strcmp(name, "drawonlyshapes")) {
1792 drawonlyshapes = atoi(value);
1793 } else if(!strcmp(name, "ignoredraworder")) {
1794 ignoredraworder = atoi(value);
1795 } else if(!strcmp(name, "linksopennewwindow")) {
1796 opennewwindow = atoi(value);
1797 } else if(!strcmp(name, "storeallcharacters")) {
1798 storeallcharacters = atoi(value);
1799 } else if(!strcmp(name, "enablezlib")) {
1800 enablezlib = atoi(value);
1801 } else if(!strcmp(name, "insertstop")) {
1802 insertstoptag = atoi(value);
1803 } else if(!strcmp(name, "flashversion")) {
1804 flashversion = atoi(value);
1805 } else if(!strcmp(name, "jpegquality")) {
1806 int val = atoi(value);
1808 if(val>100) val=100;
1810 } else if(!strcmp(name, "outputfilename")) {
1811 swffilename = value;
1812 } else if(!strcmp(name, "caplinewidth")) {
1813 caplinewidth = atof(value);
1814 } else if(!strcmp(name, "splinequality")) {
1815 int v = atoi(value);
1816 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1819 } else if(!strcmp(name, "fontquality")) {
1820 int v = atoi(value);
1821 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1823 fontsplinemaxerror = v;
1825 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1829 void pdfswf_drawonlyshapes()
1834 void pdfswf_ignoredraworder()
1836 ignoredraworder = 1;
1839 void pdfswf_linksopennewwindow()
1844 void pdfswf_storeallcharacters()
1846 storeallcharacters = 1;
1849 void pdfswf_enablezlib()
1854 void pdfswf_jpegquality(int val)
1857 if(val>100) val=100;
1861 void pdfswf_setoutputfilename(char*_filename)
1863 swffilename = _filename;
1866 void pdfswf_insertstop()
1871 void pdfswf_setversion(int n)
1877 void pdfswf_convertpage(int page)
1881 pages = (int*)malloc(1024*sizeof(int));
1884 if(pagepos == pagebuflen)
1887 pages = (int*)realloc(pages, pagebuflen);
1890 pages[pagepos++] = page;
1893 void pdfswf_performconversion()
1896 for(t=0;t<pagepos;t++)
1898 currentpage = pages[t];
1899 doc->displayPage((OutputDev*)output, currentpage, /*dpi*/72, /*rotate*/0, /*doLinks*/(int)1);
1903 int pdfswf_numpages()
1905 return doc->getNumPages();
1910 logf("<debug> pdfswf.cc: pdfswf_close()");
1914 // check for memory leaks
1915 Object::memCheck(stderr);