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"
50 #include "../lib/log.h"
54 #define logf logarithmf // logf is also used by ../lib/log.h
58 static PDFDoc*doc = 0;
59 static char* swffilename = 0;
68 double caplinewidth = 1.0;
70 static void printInfoString(Dict *infoDict, char *key, char *fmt);
71 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
75 0.833,0.833,0.889,0.889,
76 0.788,0.722,0.833,0.778,
77 0.600,0.600,0.600,0.600,
78 0.576,0.576,0.576,0.576,
84 "Helvetica-BoldOblique",
92 "Courier-BoldOblique",
106 {"Times-Roman", "n021003l.pfb"},
107 {"Times-Italic", "n021023l.pfb"},
108 {"Times-Bold", "n021004l.pfb"},
109 {"Times-BoldItalic", "n021024l.pfb"},
110 {"Helvetica", "n019003l.pfb"},
111 {"Helvetica-Oblique", "n019023l.pfb"},
112 {"Helvetica-Bold", "n019004l.pfb"},
113 {"Helvetica-BoldOblique", "n019024l.pfb"},
114 {"Courier", "n022003l.pfb"},
115 {"Courier-Oblique", "n022023l.pfb"},
116 {"Courier-Bold", "n022004l.pfb"},
117 {"Courier-BoldOblique", "n022024l.pfb"},
118 {"Symbol", "s050000l.pfb"},
119 {"ZapfDingbats", "d050000l.pfb"}};
122 class GfxImageColorMap;
124 class SWFOutputDev: public OutputDev {
125 struct swfoutput output;
133 virtual ~SWFOutputDev() ;
135 //----- get info about output device
137 // Does this device use upside-down coordinates?
138 // (Upside-down means (0,0) is the top left corner of the page.)
139 virtual GBool upsideDown();
141 // Does this device use drawChar() or drawString()?
142 virtual GBool useDrawChar();
144 virtual GBool interpretType3Chars() {return gTrue;}
146 //----- initialization and control
148 void startDoc(XRef *xref);
151 virtual void startPage(int pageNum, GfxState *state) ;
154 virtual void drawLink(Link *link, Catalog *catalog) ;
156 //----- save/restore graphics state
157 virtual void saveState(GfxState *state) ;
158 virtual void restoreState(GfxState *state) ;
160 //----- update graphics state
162 virtual void updateFont(GfxState *state);
163 virtual void updateFillColor(GfxState *state);
164 virtual void updateStrokeColor(GfxState *state);
165 virtual void updateLineWidth(GfxState *state);
166 virtual void updateLineJoin(GfxState *state);
167 virtual void updateLineCap(GfxState *state);
169 virtual void updateAll(GfxState *state)
172 updateFillColor(state);
173 updateStrokeColor(state);
174 updateLineWidth(state);
175 updateLineJoin(state);
176 updateLineCap(state);
179 //----- path painting
180 virtual void stroke(GfxState *state) ;
181 virtual void fill(GfxState *state) ;
182 virtual void eoFill(GfxState *state) ;
184 //----- path clipping
185 virtual void clip(GfxState *state) ;
186 virtual void eoClip(GfxState *state) ;
189 virtual void beginString(GfxState *state, GString *s) ;
190 virtual void endString(GfxState *state) ;
191 virtual void drawChar(GfxState *state, double x, double y,
192 double dx, double dy,
193 double originX, double originY,
194 CharCode code, Unicode *u, int uLen);
196 //----- image drawing
197 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
198 int width, int height, GBool invert,
200 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
201 int width, int height, GfxImageColorMap *colorMap,
202 int *maskColors, GBool inlineImg);
204 virtual GBool beginType3Char(GfxState *state,
205 CharCode code, Unicode *u, int uLen);
206 virtual void endType3Char(GfxState *state);
209 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
210 int width, int height, GfxImageColorMap*colorMap, GBool invert,
211 GBool inlineImg, int mask);
217 int searchT1Font(char*name);
218 char* substituteFont(GfxFont*gfxFont, char*oldname);
219 char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
221 int jpeginfo; // did we write "File contains jpegs" yet?
222 int pbminfo; // did we write "File contains jpegs" yet?
223 int linkinfo; // did we write "File contains links" yet?
224 int ttfinfo; // did we write "File contains TrueType Fonts" yet?
226 int type3active; // are we between beginType3()/endType3()?
232 char* gfxstate2str(GfxState *state)
236 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
243 if(state->getX1()!=0.0)
244 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
245 if(state->getY1()!=0.0)
246 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
247 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
248 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
249 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
250 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
251 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
252 state->getFillColor()->c[0], state->getFillColor()->c[1]);
253 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
254 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
255 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
256 state->getFillColor()->c[0], state->getFillColor()->c[1],
257 state->getFillColor()->c[2], state->getFillColor()->c[3],
258 state->getFillColor()->c[4], state->getFillColor()->c[5],
259 state->getFillColor()->c[6], state->getFillColor()->c[7]);
260 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
261 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
262 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
263 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
264 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
265 state->getFillRGB(&rgb);
266 if(rgb.r || rgb.g || rgb.b)
267 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
268 state->getStrokeRGB(&rgb);
269 if(rgb.r || rgb.g || rgb.b)
270 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
271 if(state->getFillColorSpace()->getNComps()>1)
272 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
273 if(state->getStrokeColorSpace()->getNComps()>1)
274 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
275 if(state->getFillPattern())
276 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
277 if(state->getStrokePattern())
278 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
280 if(state->getFillOpacity()!=1.0)
281 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
282 if(state->getStrokeOpacity()!=1.0)
283 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
285 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
290 state->getLineDash(&dash, &length, &start);
294 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
295 for(t=0;t<length;t++) {
296 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
298 bufpos+=sprintf(bufpos,"]");
301 if(state->getFlatness()!=1)
302 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
303 if(state->getLineJoin()!=0)
304 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
305 if(state->getLineJoin()!=0)
306 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
307 if(state->getLineJoin()!=0)
308 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
310 if(state->getFont() && state->getFont()->getName() && state->getFont()->getName()->getCString())
311 bufpos+=sprintf(bufpos,"F\"%s\" ",((state->getFont())->getName())->getCString());
312 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
313 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
314 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
315 if(state->getCharSpace())
316 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
317 if(state->getWordSpace())
318 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
319 if(state->getHorizScaling()!=1.0)
320 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
321 if(state->getLeading())
322 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
324 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
325 if(state->getRender())
326 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
327 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
328 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
329 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
330 if(state->getLineX())
331 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
332 if(state->getLineY())
333 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
334 bufpos+=sprintf(bufpos," ");
338 void dumpFontInfo(char*loglevel, GfxFont*font);
345 void showFontError(GfxFont*font, int nr)
349 for(t=0;t<lastdumppos;t++)
350 if(lastdumps[t] == r->num)
354 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
355 lastdumps[lastdumppos++] = r->num;
357 logf("<warning> The following font caused problems:");
359 logf("<warning> The following font caused problems (substituting):");
361 logf("<warning> The following Type 3 Font will be rendered as bitmap:");
362 dumpFontInfo("<warning>", font);
365 void dumpFontInfo(char*loglevel, GfxFont*font)
369 gstr = font->getName();
370 Ref* r=font->getID();
371 logf("%s=========== %s (ID:%d,%d) ==========\n", loglevel, gstr?FIXNULL(gstr->getCString()):"(unknown font)", r->num,r->gen);
373 gstr = font->getTag();
375 logf("%sTag: %s\n", loglevel, FIXNULL(gstr->getCString()));
377 if(font->isCIDFont()) logf("%sis CID font\n", loglevel);
379 GfxFontType type=font->getType();
381 case fontUnknownType:
382 logf("%sType: unknown\n",loglevel);
385 logf("%sType: 1\n",loglevel);
388 logf("%sType: 1C\n",loglevel);
391 logf("%sType: 3\n",loglevel);
394 logf("%sType: TrueType\n",loglevel);
397 logf("%sType: CIDType0\n",loglevel);
400 logf("%sType: CIDType0C\n",loglevel);
403 logf("%sType: CIDType2\n",loglevel);
408 GBool embedded = font->getEmbeddedFontID(&embRef);
409 if(font->getEmbeddedFontName())
410 name = font->getEmbeddedFontName()->getCString();
412 logf("%sEmbedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
414 gstr = font->getExtFontFile();
416 logf("%sExternal Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
418 // Get font descriptor flags.
419 if(font->isFixedWidth()) logf("%sis fixed width\n", loglevel);
420 if(font->isSerif()) logf("%sis serif\n", loglevel);
421 if(font->isSymbolic()) logf("%sis symbolic\n", loglevel);
422 if(font->isItalic()) logf("%sis italic\n", loglevel);
423 if(font->isBold()) logf("%sis bold\n", loglevel);
426 //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");}
427 //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");}
429 SWFOutputDev::SWFOutputDev()
437 clipping[clippos] = 0;
440 // printf("SWFOutputDev::SWFOutputDev() \n");
443 T1_OUTLINE* gfxPath_to_T1_OUTLINE(GfxState*state, GfxPath*path)
445 int num = path->getNumSubpaths();
447 bezierpathsegment*start,*last=0;
448 bezierpathsegment*outline = start = new bezierpathsegment();
450 double lastx=0,lasty=0;
452 logf("<warning> empty path");
453 outline->type = T1_PATHTYPE_MOVE;
457 return (T1_OUTLINE*)outline;
459 for(t = 0; t < num; t++) {
460 GfxSubpath *subpath = path->getSubpath(t);
461 int subnum = subpath->getNumPoints();
463 for(s=0;s<subnum;s++) {
465 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
466 int x = (int)((nx-lastx)*0xffff);
467 int y = (int)((ny-lasty)*0xffff);
471 outline->type = T1_PATHTYPE_MOVE;
474 outline->link = (T1_OUTLINE*)new bezierpathsegment();
475 outline = (bezierpathsegment*)outline->link;
480 else if(subpath->getCurve(s) && !cpos)
486 else if(subpath->getCurve(s) && cpos)
497 outline->type = cpos?T1_PATHTYPE_BEZIER:T1_PATHTYPE_LINE;
499 outline->link = (T1_OUTLINE*)new bezierpathsegment();
500 outline = (bezierpathsegment*)outline->link;
508 return (T1_OUTLINE*)start;
510 /*----------------------------------------------------------------------------
511 * Primitive Graphic routines
512 *----------------------------------------------------------------------------*/
514 void SWFOutputDev::stroke(GfxState *state)
516 logf("<debug> stroke\n");
517 GfxPath * path = state->getPath();
518 int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square
519 int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel
520 double miterLimit = state->getMiterLimit();
521 double width = state->getTransformedLineWidth();
524 double opaq = state->getStrokeOpacity();
525 state->getStrokeRGB(&rgb);
527 m.m11 = 1; m.m21 = 0; m.m22 = 1;
528 m.m12 = 0; m.m13 = 0; m.m23 = 0;
529 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
531 lineJoin = 1; // other line joins are not yet supported by the swf encoder
532 // TODO: support bevel joints
534 if(((lineCap==1) && (lineJoin==1)) || width<=caplinewidth) {
535 /* FIXME- if the path is smaller than 2 segments, we could ignore
537 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
538 swfoutput_drawpath(&output, outline, &m);
540 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
541 (char)(rgb.b*255), (char)(opaq*255));
543 //swfoutput_setlinewidth(&output, 1.0); //only for debugging
544 //swfoutput_setstrokecolor(&output, 0, 255, 0, 255); //likewise, see below
545 //swfoutput_setfillcolor(&output, 255, 0, 0, 255); //likewise, see below
547 swfoutput_drawpath2poly(&output, outline, &m, lineJoin, lineCap, width, miterLimit);
548 updateLineWidth(state); //reset
549 updateStrokeColor(state); //reset
550 updateFillColor(state); //reset
553 void SWFOutputDev::fill(GfxState *state)
555 logf("<debug> fill\n");
556 GfxPath * path = state->getPath();
558 m.m11 = 1; m.m21 = 0; m.m22 = 1;
559 m.m12 = 0; m.m13 = 0; m.m23 = 0;
560 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
561 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
562 swfoutput_drawpath(&output, outline, &m);
564 void SWFOutputDev::eoFill(GfxState *state)
566 logf("<debug> eofill\n");
567 GfxPath * path = state->getPath();
569 m.m11 = 1; m.m21 = 0; m.m22 = 1;
570 m.m12 = 0; m.m13 = 0; m.m23 = 0;
571 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
572 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
573 swfoutput_drawpath(&output, outline, &m);
575 void SWFOutputDev::clip(GfxState *state)
577 logf("<debug> clip\n");
578 GfxPath * path = state->getPath();
580 m.m11 = 1; m.m22 = 1;
581 m.m12 = 0; m.m21 = 0;
582 m.m13 = 0; m.m23 = 0;
583 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
584 swfoutput_startclip(&output, outline, &m);
585 clipping[clippos] ++;
587 void SWFOutputDev::eoClip(GfxState *state)
589 logf("<debug> eoclip\n");
590 GfxPath * path = state->getPath();
592 m.m11 = 1; m.m21 = 0; m.m22 = 1;
593 m.m12 = 0; m.m13 = 0; m.m23 = 0;
594 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
595 swfoutput_startclip(&output, outline, &m);
596 clipping[clippos] ++;
599 SWFOutputDev::~SWFOutputDev()
601 swfoutput_destroy(&output);
604 GBool SWFOutputDev::upsideDown()
606 logf("<debug> upsidedown?");
609 GBool SWFOutputDev::useDrawChar()
611 logf("<debug> usedrawchar?");
615 void SWFOutputDev::beginString(GfxState *state, GString *s)
617 double m11,m21,m12,m22;
618 // logf("<debug> %s beginstring \"%s\"\n", gfxstate2str(state), s->getCString());
619 state->getFontTransMat(&m11, &m12, &m21, &m22);
620 m11 *= state->getHorizScaling();
621 m21 *= state->getHorizScaling();
622 swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
626 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
627 double dx, double dy,
628 double originX, double originY,
629 CharCode c, Unicode *_u, int uLen)
631 logf("<debug> drawChar(%f,%f,%f,%f,'%c')\n",x,y,dx,dy,c);
633 // check for invisible text -- this is used by Acrobat Capture
634 if ((state->getRender() & 3) == 3)
637 GfxFont*font = state->getFont();
639 if(font->getType() == fontType3) {
640 /* type 3 chars are passed primarily as graphics */
646 state->transform(x, y, &x1, &y1);
648 if(font->isCIDFont()) {
649 GfxCIDFont*cfont = (GfxCIDFont*)font;
656 for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++)
657 /* todo: should be precomputed */
658 if(nameToUnicodeTab[t].u == u) {
659 name = nameToUnicodeTab[t].name;
663 /* printf("%02x %04x/%04x-%d \"%s\" %s %d\n", c,u, *_u, uLen, name, cfont->getName()->getCString(),
667 swfoutput_drawchar(&output, x1, y1, name, c);
669 logf("<warning> couldn't get name for CID character %02x from Encoding", c);
672 font8 = (Gfx8BitFont*)font;
673 char**enc=font8->getEncoding();
676 swfoutput_drawchar(&output, x1, y1, enc[c], c);
678 logf("<warning> couldn't get name for character %02x from Encoding", c);
683 void SWFOutputDev::endString(GfxState *state)
685 logf("<debug> endstring\n");
689 GBool SWFOutputDev::beginType3Char(GfxState *state,
690 CharCode code, Unicode *u, int uLen)
692 logf("<debug> beginType3Char %d, %08x, %d", code, *u, uLen);
694 /* the character itself is going to be passed using
696 return gFalse; /* gTrue= is_in_cache? */
699 void SWFOutputDev::endType3Char(GfxState *state)
702 logf("<debug> endType3Char");
705 void SWFOutputDev::startPage(int pageNum, GfxState *state)
709 logf("<debug> startPage %d\n", pageNum);
710 logf("<notice> processing page %d", pageNum);
712 state->transform(state->getX1(),state->getY1(),&x1,&y1);
713 state->transform(state->getX2(),state->getY2(),&x2,&y2);
715 swfoutput_init(&output, swffilename, abs((int)(x2-x1)),abs((int)(y2-y1)));
719 swfoutput_newpage(&output);
722 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
724 logf("<debug> drawlink\n");
725 double x1, y1, x2, y2, w;
730 link->getBorder(&x1, &y1, &x2, &y2, &w);
736 cvtUserToDev(x1, y1, &x, &y);
737 points[0].x = points[4].x = (int)x;
738 points[0].y = points[4].y = (int)y;
739 cvtUserToDev(x2, y1, &x, &y);
740 points[1].x = (int)x;
741 points[1].y = (int)y;
742 cvtUserToDev(x2, y2, &x, &y);
743 points[2].x = (int)x;
744 points[2].y = (int)y;
745 cvtUserToDev(x1, y2, &x, &y);
746 points[3].x = (int)x;
747 points[3].y = (int)y;
749 LinkAction*action=link->getAction();
756 switch(action->getKind())
760 LinkGoTo *ha=(LinkGoTo *)link->getAction();
762 if (ha->getDest()==NULL)
763 dest=catalog->findDest(ha->getNamedDest());
764 else dest=ha->getDest();
766 if (dest->isPageRef()){
767 Ref pageref=dest->getPageRef();
768 page=catalog->findPage(pageref.num,pageref.gen);
770 else page=dest->getPageNum();
771 sprintf(buf, "%d", page);
778 LinkGoToR*l = (LinkGoToR*)action;
779 GString*g = l->getNamedDest();
786 LinkNamed*l = (LinkNamed*)action;
787 GString*name = l->getName();
789 s = name->lowerCase()->getCString();
790 named = name->getCString();
793 if(strstr(s, "next") || strstr(s, "forward"))
795 page = currentpage + 1;
797 else if(strstr(s, "prev") || strstr(s, "back"))
799 page = currentpage - 1;
801 else if(strstr(s, "last") || strstr(s, "end"))
803 page = pages[pagepos-1]; //:)
805 else if(strstr(s, "first") || strstr(s, "top"))
815 LinkLaunch*l = (LinkLaunch*)action;
816 GString * str = new GString(l->getFileName());
817 str->append(l->getParams());
818 s = str->getCString();
823 LinkURI*l = (LinkURI*)action;
824 GString*g = l->getURI();
826 url = g->getCString();
831 case actionUnknown: {
833 LinkUnknown*l = (LinkUnknown*)action;
838 logf("<error> Unknown link type!\n");
842 if(!linkinfo && (page || url))
844 logf("<notice> File contains links");
850 for(t=0;t<pagepos;t++)
854 swfoutput_linktopage(&output, t, points);
858 swfoutput_linktourl(&output, url, points);
862 swfoutput_namedlink(&output, named, points);
864 logf("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
868 void SWFOutputDev::saveState(GfxState *state) {
869 logf("<debug> saveState\n");
874 logf("<error> Too many nested states in pdf.");
875 clipping[clippos] = 0;
878 void SWFOutputDev::restoreState(GfxState *state) {
879 logf("<debug> restoreState\n");
881 while(clipping[clippos]) {
882 swfoutput_endclip(&output);
890 int SWFOutputDev::searchT1Font(char*name)
896 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
898 if(!strcmp(name, pdf2t1map[i].pdffont))
900 filename = pdf2t1map[i].filename;
905 for(i=0; i<T1_Get_no_fonts(); i++)
907 char*fontfilename = T1_GetFontFileName (i);
908 if(strstr(fontfilename, filename))
910 pdf2t1map[i].id = mapid;
915 for(i=0; i<T1_Get_no_fonts(); i++)
917 char*fontname = T1_GetFontName (i);
920 fontname = T1_GetFontName (i);
921 logf("<verbose> Loading extra font %s from %s\n", FIXNULL(fontname),
922 FIXNULL(T1_GetFontFileName(i)));
925 if(fontname && !strcmp(name, fontname)) {
926 logf("<notice> Extra font %d, \"%s\" is being used.\n", i, fontname);
929 fontname = T1_GetFontFileName(i);
930 if(strrchr(fontname,'/'))
931 fontname = strrchr(fontname,'/')+1;
933 if(strstr(fontname, name)) {
934 logf("<notice> Extra font %d, \"%s\" is being used.\n", i, fontname);
942 void SWFOutputDev::updateLineWidth(GfxState *state)
944 double width = state->getTransformedLineWidth();
945 swfoutput_setlinewidth(&output, width);
948 void SWFOutputDev::updateLineCap(GfxState *state)
950 int c = state->getLineCap();
953 void SWFOutputDev::updateLineJoin(GfxState *state)
955 int j = state->getLineJoin();
958 void SWFOutputDev::updateFillColor(GfxState *state)
961 double opaq = state->getFillOpacity();
962 state->getFillRGB(&rgb);
964 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
965 (char)(rgb.b*255), (char)(opaq*255));
968 void SWFOutputDev::updateStrokeColor(GfxState *state)
971 double opaq = state->getStrokeOpacity();
972 state->getStrokeRGB(&rgb);
974 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
975 (char)(rgb.b*255), (char)(opaq*255));
978 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
980 char*tmpFileName = NULL;
987 Object refObj, strObj;
988 tmpFileName = "/tmp/tmpfont";
991 ret = font->getEmbeddedFontID(&embRef);
993 logf("<verbose> Didn't get embedded font id");
994 /* not embedded- the caller should now search the font
995 directories for this font */
999 f = fopen(tmpFileName, "wb");
1001 logf("<error> Couldn't create temporary Type 1 font file");
1004 if (font->getType() == fontType1C) {
1005 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1007 logf("<error> Couldn't read embedded font file");
1010 cvt = new Type1CFontFile(fontBuf, fontLen);
1011 cvt->convertToType1(f);
1015 font->getEmbeddedFontID(&embRef);
1016 refObj.initRef(embRef.num, embRef.gen);
1017 refObj.fetch(ref, &strObj);
1019 strObj.streamReset();
1024 f4[t] = strObj.streamGetChar();
1025 f4c[t] = (char)f4[t];
1030 if(!strncmp(f4c, "true", 4)) {
1031 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1032 Change this on the fly */
1033 f4[0] = f4[2] = f4[3] = 0;
1041 while ((c = strObj.streamGetChar()) != EOF) {
1045 strObj.streamClose();
1050 if(font->getType() == fontTrueType ||
1051 font->getType() == fontCIDType2)
1054 logf("<notice> File contains TrueType fonts");
1059 tmp = strdup(mktmpname((char*)name2));
1060 sprintf(name2, "%s", tmp);
1061 char*a[] = {"./ttf2pt1","-pttf","-b", tmpFileName, name2};
1062 logf("<verbose> Invoking ttf2pt1...");
1064 unlink(tmpFileName);
1065 sprintf(name2,"%s.pfb",tmp);
1066 tmpFileName = strdup(name2);
1072 char* gfxFontName(GfxFont* gfxFont)
1075 gstr = gfxFont->getName();
1077 return gstr->getCString();
1081 Ref*r=gfxFont->getID();
1082 sprintf(buf, "UFONT%d", r->num);
1087 char* substitutetarget[256];
1088 char* substitutesource[256];
1089 int substitutepos = 0;
1091 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1093 /* ------------------------------ V1 */
1095 char*fontname = "Times-Roman";
1096 logf("<verbose> substituteFont(,%s)", FIXNULL(oldname));
1097 this->t1id = searchT1Font(fontname);
1098 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1099 logf("<fatal> Too many fonts in file.");
1103 substitutesource[substitutepos] = oldname;
1104 substitutetarget[substitutepos] = fontname;
1105 logf("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1110 /* ------------------------------ V2 */
1112 /* //substitute font
1114 double m11, m12, m21, m22;
1120 if(gfxFont->getName()) {
1121 fontname = gfxFont->getName()->getCString();
1124 // printf("%d %s\n", t, gfxFont->getCharName(t));
1125 showFontError(gfxFont, 1);
1126 if(1) { //if (!gfxFont->isCIDFont()) { FIXME: xpdf 1.01 does not have is16Bit()
1127 if(gfxFont->isSymbolic()) {
1128 if(fontname && (strstr(fontname,"ing"))) //Dingbats, Wingdings etc.
1132 } else if (gfxFont->isFixedWidth()) {
1134 } else if (gfxFont->isSerif()) {
1139 if (gfxFont->isBold() && index!=16)
1141 if (gfxFont->isItalic() && index!=16)
1143 fontname = fontnames[index];
1144 // get width of 'm' in real font and substituted font
1145 if ((code = gfxFont->getCharCode("m")) >= 0)
1146 w1 = gfxFont->getWidth(code);
1149 w2 = fontsizes[index];
1150 if (gfxFont->getType() == fontType3) {
1151 // This is a hack which makes it possible to substitute for some
1152 // Type 3 fonts. The problem is that it's impossible to know what
1153 // the base coordinate system used in the font is without actually
1154 // rendering the font. This code tries to guess by looking at the
1155 // width of the character 'm' (which breaks if the font is a
1156 // subset that doesn't contain 'm').
1157 if (w1 > 0 && (w1 > 1.1 * w2 || w1 < 0.9 * w2)) {
1164 fm = gfxFont->getFontMatrix();
1165 v = (fm[0] == 0) ? 1 : (fm[3] / fm[0]);
1168 } else if (!gfxFont->isSymbolic()) {
1169 // if real font is substantially narrower than substituted
1170 // font, reduce the font size accordingly
1171 if (w1 > 0.01 && w1 < 0.9 * w2) {
1184 this->t1id = searchT1Font(fontname);
1186 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1187 logf("<fatal> Too many fonts in file.");
1191 substitutesource[substitutepos] = oldname;
1192 substitutetarget[substitutepos] = fontname;
1193 logf("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1199 void unlinkfont(char* filename)
1206 if(!strncmp(&filename[l-4],".afm",4)) {
1207 memcpy(&filename[l-4],".pfb",4);
1209 memcpy(&filename[l-4],".pfa",4);
1211 memcpy(&filename[l-4],".afm",4);
1214 if(!strncmp(&filename[l-4],".pfa",4)) {
1215 memcpy(&filename[l-4],".afm",4);
1217 memcpy(&filename[l-4],".pfa",4);
1220 if(!strncmp(&filename[l-4],".pfb",4)) {
1221 memcpy(&filename[l-4],".afm",4);
1223 memcpy(&filename[l-4],".pfb",4);
1228 void SWFOutputDev::startDoc(XRef *xref)
1234 void SWFOutputDev::updateFont(GfxState *state)
1236 GfxFont*gfxFont = state->getFont();
1237 char * fileName = 0;
1242 char * fontname = gfxFontName(gfxFont);
1245 /* first, look if we substituted this font before-
1246 this way, we don't initialize the T1 Fonts
1248 for(t=0;t<substitutepos;t++) {
1249 if(!strcmp(fontname, substitutesource[t])) {
1250 fontname = substitutetarget[t];
1255 /* second, see if swfoutput already has this font
1256 cached- if so, we are done */
1258 if(swfoutput_queryfont(&output, fontname))
1260 swfoutput_setfont(&output, fontname, -1, 0);
1264 // look for Type 3 font
1265 if (!type3Warning && gfxFont->getType() == fontType3) {
1266 type3Warning = gTrue;
1267 showFontError(gfxFont, 2);
1270 /* now either load the font, or find a substitution */
1273 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1275 if (gfxFont->getType() == fontType1 ||
1276 gfxFont->getType() == fontType1C ||
1277 gfxFont->getType() == fontTrueType ||
1278 gfxFont->getType() == fontCIDType2)
1280 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1282 logf("<error> Couldn't write font to file");
1283 showFontError(gfxFont,0);
1286 this->t1id = T1_AddFont(fileName);
1288 logf("<error> Couldn't load font from file");
1289 showFontError(gfxFont,0);
1290 unlinkfont(fileName);
1295 /* in case the font is embedded, but has an
1296 unsupported format, we just look through the
1298 int newt1id = searchT1Font(fontname);
1300 showFontError(gfxFont,0);
1301 fontname = substituteFont(gfxFont, fontname);
1303 this->t1id = newt1id;
1307 int newt1id = searchT1Font(fontname);
1309 showFontError(gfxFont,1);
1310 fontname = substituteFont(gfxFont, fontname);
1312 this->t1id = newt1id;
1315 showFontError(gfxFont,1);
1316 fontname = substituteFont(gfxFont, fontname);
1321 showFontError(gfxFont,0);
1325 /* we may have done some substitutions here, so check
1326 again if this font is cached. */
1327 if(swfoutput_queryfont(&output, fontname))
1329 swfoutput_setfont(&output, fontname, -1, 0);
1333 logf("<verbose> Creating new SWF font: t1id: %d, filename: %s name:%s", this->t1id, FIXNULL(fileName), FIXNULL(fontname));
1334 swfoutput_setfont(&output, fontname, this->t1id, fileName);
1336 unlinkfont(fileName);
1342 int pic_width[1024];
1343 int pic_height[1024];
1347 #define SQR(x) ((x)*(x))
1349 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1351 if((newwidth<2 || newheight<2) ||
1352 (width<=newwidth || height<=newheight))
1354 unsigned char*newdata;
1356 newdata= (unsigned char*)malloc(newwidth*newheight);
1358 double fx = (double)(width)/newwidth;
1359 double fy = (double)(height)/newheight;
1361 int blocksize = (int)(8192/(fx*fy));
1362 int r = 8192*256/palettesize;
1363 for(x=0;x<newwidth;x++) {
1364 double ex = px + fx;
1365 int fromx = (int)px;
1367 int xweight1 = (int)(((fromx+1)-px)*256);
1368 int xweight2 = (int)((ex-tox)*256);
1370 for(y=0;y<newheight;y++) {
1371 double ey = py + fy;
1372 int fromy = (int)py;
1374 int yweight1 = (int)(((fromy+1)-py)*256);
1375 int yweight2 = (int)((ey-toy)*256);
1378 for(xx=fromx;xx<=tox;xx++)
1379 for(yy=fromy;yy<=toy;yy++) {
1380 int b = 1-data[width*yy+xx];
1382 if(xx==fromx) weight = (weight*xweight1)/256;
1383 if(xx==tox) weight = (weight*xweight2)/256;
1384 if(yy==fromy) weight = (weight*yweight1)/256;
1385 if(yy==toy) weight = (weight*yweight2)/256;
1388 //if(a) a=(palettesize-1)*r/blocksize;
1389 newdata[y*newwidth+x] = (a*blocksize)/r;
1397 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1398 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1399 GBool inlineImg, int mask)
1404 double x1,y1,x2,y2,x3,y3,x4,y4;
1405 ImageStream *imgStr;
1412 ncomps = colorMap->getNumPixelComps();
1413 bits = colorMap->getBits();
1415 imgStr = new ImageStream(str, width, ncomps,bits);
1418 if(!width || !height || (height<=1 && width<=1))
1420 logf("<verbose> Ignoring %d by %d image", width, height);
1421 unsigned char buf[8];
1423 for (y = 0; y < height; ++y)
1424 for (x = 0; x < width; ++x) {
1425 imgStr->getPixel(buf);
1431 state->transform(0, 1, &x1, &y1);
1432 state->transform(0, 0, &x2, &y2);
1433 state->transform(1, 0, &x3, &y3);
1434 state->transform(1, 1, &x4, &y4);
1436 if(!pbminfo && !(str->getKind()==strDCT)) {
1438 logf("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1442 logf("<verbose> drawing %d by %d masked picture\n", width, height);
1444 if(!jpeginfo && (str->getKind()==strDCT)) {
1445 logf("<notice> file contains jpeg pictures");
1451 unsigned char buf[8];
1455 unsigned char*pic = new unsigned char[width*height];
1458 state->getFillRGB(&rgb);
1459 memset(pal,255,sizeof(pal));
1460 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1461 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1462 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1464 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1465 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1466 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1467 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1468 for (y = 0; y < height; ++y)
1469 for (x = 0; x < width; ++x)
1471 imgStr->getPixel(buf);
1474 pic[width*y+x] = buf[0];
1479 /* the size of the drawn image is added to the identifier
1480 as the same image may require different bitmaps if displayed
1481 at different sizes (due to antialiasing): */
1487 for(t=0;t<picpos;t++)
1489 if(pic_xids[t] == xid &&
1490 pic_yids[t] == yid) {
1491 /* if the image was antialiased, the size has changed: */
1492 width = pic_width[t];
1493 height = pic_height[t];
1500 unsigned char*pic2 = 0;
1502 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1506 height = realheight;
1509 /* make a black/white palette */
1516 float r = 255/(numpalette-1);
1517 for(t=0;t<numpalette;t++) {
1518 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1519 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1520 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1522 pal[t].r = (U8)(255*rgb.r);
1523 pal[t].g = (U8)(255*rgb.g);
1524 pal[t].b = (U8)(255*rgb.b);
1525 pal[t].a = (U8)(t*r);
1529 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1530 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1531 pic_xids[picpos] = xid;
1532 pic_yids[picpos] = yid;
1533 pic_width[picpos] = width;
1534 pic_height[picpos] = height;
1538 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1539 x1,y1,x2,y2,x3,y3,x4,y4);
1548 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1550 RGBA*pic=new RGBA[width*height];
1553 for (y = 0; y < height; ++y) {
1554 for (x = 0; x < width; ++x) {
1556 imgStr->getPixel(pixBuf);
1557 colorMap->getRGB(pixBuf, &rgb);
1558 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1559 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1560 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1561 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1562 xid += x*r+x*b*3+x*g*7+x*a*11;
1563 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1567 for(t=0;t<picpos;t++)
1569 if(pic_xids[t] == xid &&
1570 pic_yids[t] == yid) {
1575 if(str->getKind()==strDCT)
1576 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1577 x1,y1,x2,y2,x3,y3,x4,y4);
1579 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1580 x1,y1,x2,y2,x3,y3,x4,y4);
1581 pic_xids[picpos] = xid;
1582 pic_yids[picpos] = yid;
1583 pic_width[picpos] = width;
1584 pic_height[picpos] = height;
1588 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1589 x1,y1,x2,y2,x3,y3,x4,y4);
1597 U8*pic = new U8[width*height];
1605 colorMap->getRGB(pixBuf, &rgb);
1606 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1607 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1608 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1609 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1610 xid += t*r+t*b*3+t*g*7+t*a*11;
1611 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1613 for (y = 0; y < height; ++y) {
1614 for (x = 0; x < width; ++x) {
1615 imgStr->getPixel(pixBuf);
1616 pic[width*y+x] = pixBuf[0];
1617 xid += x*pixBuf[0]*7;
1618 yid += y*pixBuf[0]*3;
1622 for(t=0;t<picpos;t++)
1624 if(pic_xids[t] == xid &&
1625 pic_yids[t] == yid) {
1630 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1631 x1,y1,x2,y2,x3,y3,x4,y4,256);
1632 pic_xids[picpos] = xid;
1633 pic_yids[picpos] = yid;
1634 pic_width[picpos] = width;
1635 pic_height[picpos] = height;
1639 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1640 x1,y1,x2,y2,x3,y3,x4,y4);
1648 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1649 int width, int height, GBool invert,
1652 logf("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1653 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1656 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1657 int width, int height, GfxImageColorMap *colorMap,
1658 int *maskColors, GBool inlineImg)
1660 logf("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1661 colorMap?"colorMap":"no colorMap",
1662 maskColors?"maskColors":"no maskColors",
1665 logf("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1666 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1667 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1670 SWFOutputDev*output = 0;
1672 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1677 if (infoDict->lookup(key, &obj)->isString()) {
1678 s1 = obj.getString();
1679 if ((s1->getChar(0) & 0xff) == 0xfe &&
1680 (s1->getChar(1) & 0xff) == 0xff) {
1682 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1683 if (s1->getChar(i) == '\0') {
1684 s2->append(s1->getChar(i+1));
1687 s2 = new GString("<unicode>");
1691 printf(fmt, s2->getCString());
1694 printf(fmt, s1->getCString());
1700 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1704 if (infoDict->lookup(key, &obj)->isString()) {
1705 s = obj.getString()->getCString();
1706 if (s[0] == 'D' && s[1] == ':') {
1714 void pdfswf_init(char*filename, char*userPassword)
1716 GString *fileName = new GString(filename);
1721 globalParams = new GlobalParams("");
1724 if (userPassword && userPassword[0]) {
1725 userPW = new GString(userPassword);
1729 doc = new PDFDoc(fileName, userPW);
1738 doc->getDocInfo(&info);
1739 if (info.isDict() &&
1740 (screenloglevel>=LOGLEVEL_NOTICE)) {
1741 printInfoString(info.getDict(), "Title", "Title: %s\n");
1742 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1743 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1744 printInfoString(info.getDict(), "Author", "Author: %s\n");
1745 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1746 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1747 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1748 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1749 printf("Pages: %d\n", doc->getNumPages());
1750 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1751 printf("Encrypted: ");
1752 if (doc->isEncrypted()) {
1753 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1754 doc->okToPrint() ? "yes" : "no",
1755 doc->okToCopy() ? "yes" : "no",
1756 doc->okToChange() ? "yes" : "no",
1757 doc->okToAddNotes() ? "yes" : "no");
1764 numpages = doc->getNumPages();
1765 if (doc->isEncrypted()) {
1766 /*ERROR: This pdf is encrypted, and disallows copying.
1767 Due to the DMCA, paragraph 1201, (2) A-C, circumventing
1768 a technological measure that efficively controls access to
1769 a protected work is violating American law.
1770 See www.eff.org for more information about DMCA issues.
1772 if(!doc->okToCopy()) {
1773 printf("PDF disallows copying. Bailing out.\n");
1776 if(!doc->okToChange() || !doc->okToAddNotes())
1777 swfoutput_setprotected();
1780 output = new SWFOutputDev();
1781 output->startDoc(doc->getXRef());
1784 void pdfswf_setparameter(char*name, char*value)
1786 if(!strcmp(name, "drawonlyshapes")) {
1787 drawonlyshapes = atoi(value);
1788 } else if(!strcmp(name, "ignoredraworder")) {
1789 ignoredraworder = atoi(value);
1790 } else if(!strcmp(name, "linksopennewwindow")) {
1791 opennewwindow = atoi(value);
1792 } else if(!strcmp(name, "storeallcharacters")) {
1793 storeallcharacters = atoi(value);
1794 } else if(!strcmp(name, "enablezlib")) {
1795 enablezlib = atoi(value);
1796 } else if(!strcmp(name, "insertstop")) {
1797 insertstoptag = atoi(value);
1798 } else if(!strcmp(name, "flashversion")) {
1799 flashversion = atoi(value);
1800 } else if(!strcmp(name, "jpegquality")) {
1801 int val = atoi(value);
1803 if(val>100) val=100;
1805 } else if(!strcmp(name, "outputfilename")) {
1806 swffilename = value;
1807 } else if(!strcmp(name, "caplinewidth")) {
1808 caplinewidth = atof(value);
1809 } else if(!strcmp(name, "splinequality")) {
1810 int v = atoi(value);
1811 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1814 } else if(!strcmp(name, "fontquality")) {
1815 int v = atoi(value);
1816 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1818 fontsplinemaxerror = v;
1820 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1824 void pdfswf_drawonlyshapes()
1829 void pdfswf_ignoredraworder()
1831 ignoredraworder = 1;
1834 void pdfswf_linksopennewwindow()
1839 void pdfswf_storeallcharacters()
1841 storeallcharacters = 1;
1844 void pdfswf_enablezlib()
1849 void pdfswf_jpegquality(int val)
1852 if(val>100) val=100;
1856 void pdfswf_setoutputfilename(char*_filename)
1858 swffilename = _filename;
1861 void pdfswf_insertstop()
1866 void pdfswf_setversion(int n)
1872 void pdfswf_convertpage(int page)
1876 pages = (int*)malloc(1024*sizeof(int));
1879 if(pagepos == pagebuflen)
1882 pages = (int*)realloc(pages, pagebuflen);
1885 pages[pagepos++] = page;
1888 void pdfswf_performconversion()
1891 for(t=0;t<pagepos;t++)
1893 currentpage = pages[t];
1894 doc->displayPage((OutputDev*)output, currentpage, /*dpi*/72, /*rotate*/0, /*doLinks*/(int)1);
1898 int pdfswf_numpages()
1900 return doc->getNumPages();
1905 logf("<debug> pdfswf.cc: pdfswf_close()");
1909 // check for memory leaks
1910 Object::memCheck(stderr);