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"
26 #ifdef HAVE_FONTCONFIG_H
27 #include <fontconfig.h>
43 #include "OutputDev.h"
46 #include "CharCodeToUnicode.h"
47 #include "NameToUnicodeTable.h"
49 #include "GlobalParams.h"
50 //swftools header files
51 #include "swfoutput.h"
52 #include "SWFOutputDev.h"
53 #include "../lib/log.h"
57 static PDFDoc*doc = 0;
58 static char* swffilename = 0;
60 static int currentpage;
62 typedef struct _fontfile
68 static fontfile_t fonts[2048];
69 static int fontnum = 0;
73 static int pagebuflen = 0;
74 static int pagepos = 0;
76 static double caplinewidth = 3.0;
77 static int zoom = 72; /* xpdf: 86 */
79 static void printInfoString(Dict *infoDict, char *key, char *fmt);
80 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
82 static double fontsizes[] =
84 0.833,0.833,0.889,0.889,
85 0.788,0.722,0.833,0.778,
86 0.600,0.600,0.600,0.600,
87 0.576,0.576,0.576,0.576,
90 static char*fontnames[]={
93 "Helvetica-BoldOblique",
101 "Courier-BoldOblique",
115 {"Times-Roman", "n021003l"},
116 {"Times-Italic", "n021023l"},
117 {"Times-Bold", "n021004l"},
118 {"Times-BoldItalic", "n021024l"},
119 {"Helvetica", "n019003l"},
120 {"Helvetica-Oblique", "n019023l"},
121 {"Helvetica-Bold", "n019004l"},
122 {"Helvetica-BoldOblique", "n019024l"},
123 {"Courier", "n022003l"},
124 {"Courier-Oblique", "n022023l"},
125 {"Courier-Bold", "n022004l"},
126 {"Courier-BoldOblique", "n022024l"},
127 {"Symbol", "s050000l"},
128 {"ZapfDingbats", "d050000l"}};
131 class GfxImageColorMap;
133 class SWFOutputDev: public OutputDev {
134 struct swfoutput output;
142 virtual ~SWFOutputDev() ;
144 //----- get info about output device
146 // Does this device use upside-down coordinates?
147 // (Upside-down means (0,0) is the top left corner of the page.)
148 virtual GBool upsideDown();
150 // Does this device use drawChar() or drawString()?
151 virtual GBool useDrawChar();
153 virtual GBool interpretType3Chars() {return gTrue;}
155 //----- initialization and control
157 void startDoc(XRef *xref);
160 virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
163 virtual void drawLink(Link *link, Catalog *catalog) ;
165 //----- save/restore graphics state
166 virtual void saveState(GfxState *state) ;
167 virtual void restoreState(GfxState *state) ;
169 //----- update graphics state
171 virtual void updateFont(GfxState *state);
172 virtual void updateFillColor(GfxState *state);
173 virtual void updateStrokeColor(GfxState *state);
174 virtual void updateLineWidth(GfxState *state);
175 virtual void updateLineJoin(GfxState *state);
176 virtual void updateLineCap(GfxState *state);
178 virtual void updateAll(GfxState *state)
181 updateFillColor(state);
182 updateStrokeColor(state);
183 updateLineWidth(state);
184 updateLineJoin(state);
185 updateLineCap(state);
188 //----- path painting
189 virtual void stroke(GfxState *state) ;
190 virtual void fill(GfxState *state) ;
191 virtual void eoFill(GfxState *state) ;
193 //----- path clipping
194 virtual void clip(GfxState *state) ;
195 virtual void eoClip(GfxState *state) ;
198 virtual void beginString(GfxState *state, GString *s) ;
199 virtual void endString(GfxState *state) ;
200 virtual void drawChar(GfxState *state, double x, double y,
201 double dx, double dy,
202 double originX, double originY,
203 CharCode code, Unicode *u, int uLen);
205 //----- image drawing
206 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
207 int width, int height, GBool invert,
209 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
210 int width, int height, GfxImageColorMap *colorMap,
211 int *maskColors, GBool inlineImg);
213 virtual GBool beginType3Char(GfxState *state,
214 CharCode code, Unicode *u, int uLen);
215 virtual void endType3Char(GfxState *state);
218 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
219 int width, int height, GfxImageColorMap*colorMap, GBool invert,
220 GBool inlineImg, int mask);
226 char* searchFont(char*name);
227 char* substituteFont(GfxFont*gfxFont, char*oldname);
228 char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
230 int jpeginfo; // did we write "File contains jpegs" yet?
231 int pbminfo; // did we write "File contains jpegs" yet?
232 int linkinfo; // did we write "File contains links" yet?
233 int ttfinfo; // did we write "File contains TrueType Fonts" yet?
235 int type3active; // are we between beginType3()/endType3()?
240 static char*getFontID(GfxFont*font)
242 GString*gstr = font->getName();
243 char* fontname = gstr==0?0:gstr->getCString();
247 sprintf(buf, "UFONT%d", r->num);
253 static char*getFontName(GfxFont*font)
255 char*fontname = getFontID(font);
256 char* plus = strchr(fontname, '+');
257 if(plus && plus < &fontname[strlen(fontname)-1])
263 char* gfxstate2str(GfxState *state)
267 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
274 if(state->getX1()!=0.0)
275 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
276 if(state->getY1()!=0.0)
277 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
278 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
279 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
280 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
281 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
282 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
283 state->getFillColor()->c[0], state->getFillColor()->c[1]);
284 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
285 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
286 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
287 state->getFillColor()->c[0], state->getFillColor()->c[1],
288 state->getFillColor()->c[2], state->getFillColor()->c[3],
289 state->getFillColor()->c[4], state->getFillColor()->c[5],
290 state->getFillColor()->c[6], state->getFillColor()->c[7]);
291 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
292 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
293 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
294 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
295 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
296 state->getFillRGB(&rgb);
297 if(rgb.r || rgb.g || rgb.b)
298 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
299 state->getStrokeRGB(&rgb);
300 if(rgb.r || rgb.g || rgb.b)
301 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
302 if(state->getFillColorSpace()->getNComps()>1)
303 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
304 if(state->getStrokeColorSpace()->getNComps()>1)
305 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
306 if(state->getFillPattern())
307 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
308 if(state->getStrokePattern())
309 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
311 if(state->getFillOpacity()!=1.0)
312 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
313 if(state->getStrokeOpacity()!=1.0)
314 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
316 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
321 state->getLineDash(&dash, &length, &start);
325 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
326 for(t=0;t<length;t++) {
327 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
329 bufpos+=sprintf(bufpos,"]");
332 if(state->getFlatness()!=1)
333 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
334 if(state->getLineJoin()!=0)
335 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
336 if(state->getLineJoin()!=0)
337 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
338 if(state->getLineJoin()!=0)
339 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
341 if(state->getFont() && getFontID(state->getFont()))
342 bufpos+=sprintf(bufpos,"F\"%s\" ",getFontID(state->getFont()));
343 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
344 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
345 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
346 if(state->getCharSpace())
347 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
348 if(state->getWordSpace())
349 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
350 if(state->getHorizScaling()!=1.0)
351 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
352 if(state->getLeading())
353 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
355 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
356 if(state->getRender())
357 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
358 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
359 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
360 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
361 if(state->getLineX())
362 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
363 if(state->getLineY())
364 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
365 bufpos+=sprintf(bufpos," ");
371 void dumpFontInfo(char*loglevel, GfxFont*font);
378 void showFontError(GfxFont*font, int nr)
382 for(t=0;t<lastdumppos;t++)
383 if(lastdumps[t] == r->num)
387 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
388 lastdumps[lastdumppos++] = r->num;
390 msg("<warning> The following font caused problems:");
392 msg("<warning> The following font caused problems (substituting):");
394 msg("<warning> The following Type 3 Font will be rendered as bitmap:");
395 dumpFontInfo("<warning>", font);
398 void dumpFontInfo(char*loglevel, GfxFont*font)
400 char* name = getFontID(font);
401 Ref* r=font->getID();
402 msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, getFontName(font), r->num,r->gen);
404 GString*gstr = font->getTag();
406 msg("%s| Tag: %s\n", loglevel, name);
408 if(font->isCIDFont()) msg("%s| is CID font\n", loglevel);
410 GfxFontType type=font->getType();
412 case fontUnknownType:
413 msg("%s| Type: unknown\n",loglevel);
416 msg("%s| Type: 1\n",loglevel);
419 msg("%s| Type: 1C\n",loglevel);
422 msg("%s| Type: 3\n",loglevel);
425 msg("%s| Type: TrueType\n",loglevel);
428 msg("%s| Type: CIDType0\n",loglevel);
431 msg("%s| Type: CIDType0C\n",loglevel);
434 msg("%s| Type: CIDType2\n",loglevel);
439 GBool embedded = font->getEmbeddedFontID(&embRef);
440 if(font->getEmbeddedFontName())
441 name = font->getEmbeddedFontName()->getCString();
443 msg("%s| Embedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
445 gstr = font->getExtFontFile();
447 msg("%s| External Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
449 // Get font descriptor flags.
450 if(font->isFixedWidth()) msg("%s| is fixed width\n", loglevel);
451 if(font->isSerif()) msg("%s| is serif\n", loglevel);
452 if(font->isSymbolic()) msg("%s| is symbolic\n", loglevel);
453 if(font->isItalic()) msg("%s| is italic\n", loglevel);
454 if(font->isBold()) msg("%s| is bold\n", loglevel);
457 //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");}
458 //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");}
460 SWFOutputDev::SWFOutputDev()
468 clipping[clippos] = 0;
471 // printf("SWFOutputDev::SWFOutputDev() \n");
474 SWF_OUTLINE* gfxPath_to_SWF_OUTLINE(GfxState*state, GfxPath*path)
476 int num = path->getNumSubpaths();
478 bezierpathsegment*start,*last=0;
479 bezierpathsegment*outline = start = new bezierpathsegment();
481 double lastx=0,lasty=0;
483 msg("<warning> empty path");
484 outline->type = SWF_PATHTYPE_MOVE;
488 return (SWF_OUTLINE*)outline;
490 for(t = 0; t < num; t++) {
491 GfxSubpath *subpath = path->getSubpath(t);
492 int subnum = subpath->getNumPoints();
494 for(s=0;s<subnum;s++) {
496 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
497 int x = (int)((nx-lastx)*0xffff);
498 int y = (int)((ny-lasty)*0xffff);
502 outline->type = SWF_PATHTYPE_MOVE;
505 outline->link = (SWF_OUTLINE*)new bezierpathsegment();
506 outline = (bezierpathsegment*)outline->link;
511 else if(subpath->getCurve(s) && !cpos)
517 else if(subpath->getCurve(s) && cpos)
528 outline->type = cpos?SWF_PATHTYPE_BEZIER:SWF_PATHTYPE_LINE;
530 outline->link = (SWF_OUTLINE*)new bezierpathsegment();
531 outline = (bezierpathsegment*)outline->link;
539 return (SWF_OUTLINE*)start;
541 /*----------------------------------------------------------------------------
542 * Primitive Graphic routines
543 *----------------------------------------------------------------------------*/
545 void SWFOutputDev::stroke(GfxState *state)
547 msg("<debug> stroke\n");
548 GfxPath * path = state->getPath();
549 int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square
550 int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel
551 double miterLimit = state->getMiterLimit();
552 double width = state->getTransformedLineWidth();
555 double opaq = state->getStrokeOpacity();
556 state->getStrokeRGB(&rgb);
558 m.m11 = 1; m.m21 = 0; m.m22 = 1;
559 m.m12 = 0; m.m13 = 0; m.m23 = 0;
560 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
562 lineJoin = 1; // other line joins are not yet supported by the swf encoder
563 // TODO: support bevel joints
565 if(((lineCap==1) && (lineJoin==1)) || width<=caplinewidth) {
566 /* FIXME- if the path is smaller than 2 segments, we could ignore
568 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
569 swfoutput_drawpath(&output, outline, &m);
571 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
572 (char)(rgb.b*255), (char)(opaq*255));
574 //swfoutput_setlinewidth(&output, 1.0); //only for debugging
575 //swfoutput_setstrokecolor(&output, 0, 255, 0, 255); //likewise, see below
576 //swfoutput_setfillcolor(&output, 255, 0, 0, 255); //likewise, see below
578 swfoutput_drawpath2poly(&output, outline, &m, lineJoin, lineCap, width, miterLimit);
579 updateLineWidth(state); //reset
580 updateStrokeColor(state); //reset
581 updateFillColor(state); //reset
584 void SWFOutputDev::fill(GfxState *state)
586 msg("<debug> fill\n");
587 GfxPath * path = state->getPath();
589 m.m11 = 1; m.m21 = 0; m.m22 = 1;
590 m.m12 = 0; m.m13 = 0; m.m23 = 0;
591 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
592 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
593 swfoutput_drawpath(&output, outline, &m);
595 void SWFOutputDev::eoFill(GfxState *state)
597 msg("<debug> eofill\n");
598 GfxPath * path = state->getPath();
600 m.m11 = 1; m.m21 = 0; m.m22 = 1;
601 m.m12 = 0; m.m13 = 0; m.m23 = 0;
602 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
603 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
604 swfoutput_drawpath(&output, outline, &m);
606 void SWFOutputDev::clip(GfxState *state)
608 msg("<debug> clip\n");
609 GfxPath * path = state->getPath();
611 m.m11 = 1; m.m22 = 1;
612 m.m12 = 0; m.m21 = 0;
613 m.m13 = 0; m.m23 = 0;
614 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
615 swfoutput_startclip(&output, outline, &m);
616 clipping[clippos] ++;
618 void SWFOutputDev::eoClip(GfxState *state)
620 msg("<debug> eoclip\n");
621 GfxPath * path = state->getPath();
623 m.m11 = 1; m.m21 = 0; m.m22 = 1;
624 m.m12 = 0; m.m13 = 0; m.m23 = 0;
625 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
626 swfoutput_startclip(&output, outline, &m);
627 clipping[clippos] ++;
630 SWFOutputDev::~SWFOutputDev()
632 swfoutput_destroy(&output);
635 GBool SWFOutputDev::upsideDown()
637 msg("<debug> upsidedown? yes");
640 GBool SWFOutputDev::useDrawChar()
645 void SWFOutputDev::beginString(GfxState *state, GString *s)
647 double m11,m21,m12,m22;
648 // msg("<debug> %s beginstring \"%s\"\n", gfxstate2str(state), s->getCString());
649 state->getFontTransMat(&m11, &m12, &m21, &m22);
650 m11 *= state->getHorizScaling();
651 m21 *= state->getHorizScaling();
652 swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
654 msg("<debug> fontmatrix %7.3f %7.3f\n", m11,-m21);
655 msg("<debug> fontmatrix %7.3f %7.3f\n", m12,-m22);
658 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
659 double dx, double dy,
660 double originX, double originY,
661 CharCode c, Unicode *_u, int uLen)
663 // check for invisible text -- this is used by Acrobat Capture
664 if ((state->getRender() & 3) == 3)
667 GfxFont*font = state->getFont();
669 if(font->getType() == fontType3) {
670 /* type 3 chars are passed as graphics */
676 state->transform(x, y, &x1, &y1);
682 /* find out the character name */
684 if(font->isCIDFont() && u) {
685 GfxCIDFont*cfont = (GfxCIDFont*)font;
687 for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
688 /* todo: should be precomputed */
689 if(nameToUnicodeTab[t].u == u) {
690 name = nameToUnicodeTab[t].name;
696 font8 = (Gfx8BitFont*)font;
697 char**enc=font8->getEncoding();
702 msg("<debug> drawChar(%f,%f,c='%c' (%d),u=%d <%d>) CID=%d name=\"%s\"\n",x,y,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name));
704 /*x1 = (int)(x1+0.5);
705 y1 = (int)(y1+0.5);*/
707 int ret = swfoutput_drawchar(&output, x1, y1, name, c, u);
710 void SWFOutputDev::endString(GfxState *state) {
714 GBool SWFOutputDev::beginType3Char(GfxState *state,
715 CharCode code, Unicode *u, int uLen)
717 msg("<debug> beginType3Char %d, %08x, %d", code, *u, uLen);
719 /* the character itself is going to be passed using
721 return gFalse; /* gTrue= is_in_cache? */
724 void SWFOutputDev::endType3Char(GfxState *state)
727 msg("<debug> endType3Char");
730 void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
733 int rot = doc->getPageRotate(1);
735 msg("<verbose> startPage %d (%f,%f,%f,%f)\n", pageNum, crop_x1, crop_y1, crop_x2, crop_y2);
737 msg("<verbose> page is rotated %d degrees\n", rot);
739 msg("<notice> processing page %d", pageNum);
741 /* state->transform(state->getX1(),state->getY1(),&x1,&y1);
742 state->transform(state->getX2(),state->getY2(),&x2,&y2);
743 Use CropBox, not MediaBox, as page size
750 state->transform(crop_x1,crop_y1,&x1,&y1);
751 state->transform(crop_x2,crop_y2,&x2,&y2);
753 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
754 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
757 msg("<verbose> Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2);
758 swfoutput_init(&output, swffilename,(int)x1,(int)y1,(int)x2,(int)y2);
762 swfoutput_newpage(&output);
765 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
767 msg("<debug> drawlink\n");
768 double x1, y1, x2, y2, w;
773 link->getBorder(&x1, &y1, &x2, &y2, &w);
779 cvtUserToDev(x1, y1, &x, &y);
780 points[0].x = points[4].x = (int)x;
781 points[0].y = points[4].y = (int)y;
782 cvtUserToDev(x2, y1, &x, &y);
783 points[1].x = (int)x;
784 points[1].y = (int)y;
785 cvtUserToDev(x2, y2, &x, &y);
786 points[2].x = (int)x;
787 points[2].y = (int)y;
788 cvtUserToDev(x1, y2, &x, &y);
789 points[3].x = (int)x;
790 points[3].y = (int)y;
792 LinkAction*action=link->getAction();
799 switch(action->getKind())
803 LinkGoTo *ha=(LinkGoTo *)link->getAction();
805 if (ha->getDest()==NULL)
806 dest=catalog->findDest(ha->getNamedDest());
807 else dest=ha->getDest();
809 if (dest->isPageRef()){
810 Ref pageref=dest->getPageRef();
811 page=catalog->findPage(pageref.num,pageref.gen);
813 else page=dest->getPageNum();
814 sprintf(buf, "%d", page);
821 LinkGoToR*l = (LinkGoToR*)action;
822 GString*g = l->getNamedDest();
829 LinkNamed*l = (LinkNamed*)action;
830 GString*name = l->getName();
832 s = name->lowerCase()->getCString();
833 named = name->getCString();
836 if(strstr(s, "next") || strstr(s, "forward"))
838 page = currentpage + 1;
840 else if(strstr(s, "prev") || strstr(s, "back"))
842 page = currentpage - 1;
844 else if(strstr(s, "last") || strstr(s, "end"))
846 page = pages[pagepos-1]; //:)
848 else if(strstr(s, "first") || strstr(s, "top"))
858 LinkLaunch*l = (LinkLaunch*)action;
859 GString * str = new GString(l->getFileName());
860 str->append(l->getParams());
861 s = str->getCString();
866 LinkURI*l = (LinkURI*)action;
867 GString*g = l->getURI();
869 url = g->getCString();
874 case actionUnknown: {
876 LinkUnknown*l = (LinkUnknown*)action;
881 msg("<error> Unknown link type!\n");
885 if(!linkinfo && (page || url))
887 msg("<notice> File contains links");
893 for(t=0;t<pagepos;t++)
897 swfoutput_linktopage(&output, t, points);
901 swfoutput_linktourl(&output, url, points);
905 swfoutput_namedlink(&output, named, points);
907 msg("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
911 void SWFOutputDev::saveState(GfxState *state) {
912 msg("<debug> saveState\n");
917 msg("<error> Too many nested states in pdf.");
918 clipping[clippos] = 0;
921 void SWFOutputDev::restoreState(GfxState *state) {
922 msg("<debug> restoreState\n");
924 while(clipping[clippos]) {
925 swfoutput_endclip(&output);
933 char* SWFOutputDev::searchFont(char*name)
937 int is_standard_font = 0;
939 msg("<verbose> SearchFont(%s)", name);
941 /* see if it is a pdf standard font */
942 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
944 if(!strcmp(name, pdf2t1map[i].pdffont))
946 name = pdf2t1map[i].filename;
947 is_standard_font = 1;
951 /* look in all font files */
952 for(i=0;i<fontnum;i++)
954 if(strstr(fonts[i].filename, name))
959 if(!is_standard_font)
960 msg("<notice> Using %s for %s", fonts[i].filename, name);
962 return fonts[i].filename;
968 void SWFOutputDev::updateLineWidth(GfxState *state)
970 double width = state->getTransformedLineWidth();
971 swfoutput_setlinewidth(&output, width);
974 void SWFOutputDev::updateLineCap(GfxState *state)
976 int c = state->getLineCap();
979 void SWFOutputDev::updateLineJoin(GfxState *state)
981 int j = state->getLineJoin();
984 void SWFOutputDev::updateFillColor(GfxState *state)
987 double opaq = state->getFillOpacity();
988 state->getFillRGB(&rgb);
990 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
991 (char)(rgb.b*255), (char)(opaq*255));
994 void SWFOutputDev::updateStrokeColor(GfxState *state)
997 double opaq = state->getStrokeOpacity();
998 state->getStrokeRGB(&rgb);
1000 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
1001 (char)(rgb.b*255), (char)(opaq*255));
1004 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
1006 char*tmpFileName = NULL;
1012 Object refObj, strObj;
1014 tmpFileName = mktmpname(namebuf);
1017 ret = font->getEmbeddedFontID(&embRef);
1019 msg("<verbose> Didn't get embedded font id");
1020 /* not embedded- the caller should now search the font
1021 directories for this font */
1025 f = fopen(tmpFileName, "wb");
1027 msg("<error> Couldn't create temporary Type 1 font file");
1031 /*if(font->isCIDFont()) {
1032 GfxCIDFont* cidFont = (GfxCIDFont *)font;
1033 GString c = cidFont->getCollection();
1034 msg("<notice> Collection: %s", c.getCString());
1037 if (font->getType() == fontType1C ||
1038 font->getType() == fontCIDType0C) {
1039 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1041 msg("<error> Couldn't read embedded font file");
1044 Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
1045 cvt->convertToType1(f);
1046 //cvt->convertToCIDType0("test", f);
1047 //cvt->convertToType0("test", f);
1050 } else if(font->getType() == fontTrueType) {
1051 msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
1052 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1054 msg("<error> Couldn't read embedded font file");
1057 TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
1062 font->getEmbeddedFontID(&embRef);
1063 refObj.initRef(embRef.num, embRef.gen);
1064 refObj.fetch(ref, &strObj);
1066 strObj.streamReset();
1071 f4[t] = strObj.streamGetChar();
1072 f4c[t] = (char)f4[t];
1077 if(!strncmp(f4c, "true", 4)) {
1078 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1079 Change this on the fly */
1080 f4[0] = f4[2] = f4[3] = 0;
1088 while ((c = strObj.streamGetChar()) != EOF) {
1092 strObj.streamClose();
1097 return strdup(tmpFileName);
1101 char* substitutetarget[256];
1102 char* substitutesource[256];
1103 int substitutepos = 0;
1105 char* searchForSuitableFont(GfxFont*gfxFont)
1107 char*name = getFontName(gfxFont);
1111 #ifdef HAVE_FONTCONFIG
1112 FcPattern *pattern, *match;
1116 // call init ony once
1117 static int fcinitcalled = false;
1118 if (!fcinitcalled) {
1119 fcinitcalled = true;
1123 pattern = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, name, NULL);
1124 if (gfxFont->isItalic()) // check for italic
1125 FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1126 if (gfxFont->isBold()) // check for bold
1127 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1129 // configure and match using the original font name
1130 FcConfigSubstitute(0, pattern, FcMatchPattern);
1131 FcDefaultSubstitute(pattern);
1132 match = FcFontMatch(0, pattern, &result);
1134 if (FcPatternGetString(match, "family", 0, &v) == FcResultMatch) {
1135 // if we get an exact match
1136 if (strcmp((char *)v, name) == 0) {
1137 if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
1138 filename = strdup((char*)v);
1139 char *nfn = strrchr(filename, '/');
1140 if(nfn) fontname = strdup(nfn+1);
1141 else fontname = filename;
1144 // initialize patterns
1145 FcPatternDestroy(pattern);
1146 FcPatternDestroy(match);
1148 // now match against serif etc.
1149 if (gfxFont->isSerif()) {
1150 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "serif", NULL);
1151 } else if (gfxFont->isFixedWidth()) {
1152 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "monospace", NULL);
1154 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "sans", NULL);
1158 if (gfxFont->isItalic()) {
1159 int bb = FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1162 if (gfxFont->isBold()) {
1163 int bb = FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1166 // configure and match using serif etc
1167 FcConfigSubstitute (0, pattern, FcMatchPattern);
1168 FcDefaultSubstitute (pattern);
1169 match = FcFontMatch (0, pattern, &result);
1171 if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
1172 filename = strdup((char*)v);
1173 char *nfn = strrchr(filename, '/');
1174 if(nfn) fontname = strdup(nfn+1);
1175 else fontname = filename;
1180 //printf("FONTCONFIG: pattern");
1181 //FcPatternPrint(pattern);
1182 //printf("FONTCONFIG: match");
1183 //FcPatternPrint(match);
1185 FcPatternDestroy(pattern);
1186 FcPatternDestroy(match);
1188 pdfswf_addfont(filename);
1195 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1197 char*fontname = 0, *filename = 0;
1198 msg("<notice> subsituteFont(%s)", oldname);
1200 if(!(fontname = searchForSuitableFont(gfxFont))) {
1201 fontname = "Times-Roman";
1203 filename = searchFont(fontname);
1205 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1206 msg("<fatal> Too many fonts in file.");
1210 substitutesource[substitutepos] = oldname;
1211 substitutetarget[substitutepos] = fontname;
1212 msg("<notice> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1218 void unlinkfont(char* filename)
1225 if(!strncmp(&filename[l-4],".afm",4)) {
1226 memcpy(&filename[l-4],".pfb",4);
1228 memcpy(&filename[l-4],".pfa",4);
1230 memcpy(&filename[l-4],".afm",4);
1233 if(!strncmp(&filename[l-4],".pfa",4)) {
1234 memcpy(&filename[l-4],".afm",4);
1236 memcpy(&filename[l-4],".pfa",4);
1239 if(!strncmp(&filename[l-4],".pfb",4)) {
1240 memcpy(&filename[l-4],".afm",4);
1242 memcpy(&filename[l-4],".pfb",4);
1247 void SWFOutputDev::startDoc(XRef *xref)
1253 void SWFOutputDev::updateFont(GfxState *state)
1255 GfxFont*gfxFont = state->getFont();
1260 char * fontid = getFontID(gfxFont);
1263 /* first, look if we substituted this font before-
1264 this way, we don't initialize the T1 Fonts
1266 for(t=0;t<substitutepos;t++) {
1267 if(!strcmp(fontid, substitutesource[t])) {
1268 fontid = substitutetarget[t];
1273 /* second, see if swfoutput already has this font
1274 cached- if so, we are done */
1275 if(swfoutput_queryfont(&output, fontid))
1277 swfoutput_setfont(&output, fontid, 0);
1279 msg("<debug> updateFont(%s) [cached]", fontid);
1283 // look for Type 3 font
1284 if (gfxFont->getType() == fontType3) {
1286 type3Warning = gTrue;
1287 showFontError(gfxFont, 2);
1292 /* now either load the font, or find a substitution */
1295 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1300 (gfxFont->getType() == fontType1 ||
1301 gfxFont->getType() == fontType1C ||
1302 //gfxFont->getType() == fontCIDType0C ||
1303 gfxFont->getType() == fontTrueType ||
1304 gfxFont->getType() == fontCIDType2
1307 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1308 if(!fileName) showFontError(gfxFont,0);
1311 char * fontname = getFontName(gfxFont);
1312 fileName = searchFont(fontname);
1313 if(!fileName) showFontError(gfxFont,0);
1316 char * fontname = getFontName(gfxFont);
1317 msg("<warning> Font %s %scould not be loaded.", fontname, embedded?"":"(not embedded) ");
1318 msg("<warning> Try putting a TTF version of that font (named \"%s.ttf\") into /swftools/fonts", fontname);
1319 fileName = substituteFont(gfxFont, fontid);
1320 if(fontid) { fontid = substitutetarget[substitutepos-1]; /*ugly hack*/};
1321 msg("<notice> Font is now %s (%s)", fontid, fileName);
1325 msg("<error> Couldn't set font %s\n", fontid);
1329 msg("<verbose> updateFont(%s) -> %s", fontid, fileName);
1330 dumpFontInfo("<verbose>", gfxFont);
1332 swfoutput_setfont(&output, fontid, fileName);
1335 unlinkfont(fileName);
1341 int pic_width[1024];
1342 int pic_height[1024];
1346 #define SQR(x) ((x)*(x))
1348 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1350 if((newwidth<2 || newheight<2) ||
1351 (width<=newwidth || height<=newheight))
1353 unsigned char*newdata;
1355 newdata= (unsigned char*)malloc(newwidth*newheight);
1357 double fx = (double)(width)/newwidth;
1358 double fy = (double)(height)/newheight;
1360 int blocksize = (int)(8192/(fx*fy));
1361 int r = 8192*256/palettesize;
1362 for(x=0;x<newwidth;x++) {
1363 double ex = px + fx;
1364 int fromx = (int)px;
1366 int xweight1 = (int)(((fromx+1)-px)*256);
1367 int xweight2 = (int)((ex-tox)*256);
1369 for(y=0;y<newheight;y++) {
1370 double ey = py + fy;
1371 int fromy = (int)py;
1373 int yweight1 = (int)(((fromy+1)-py)*256);
1374 int yweight2 = (int)((ey-toy)*256);
1377 for(xx=fromx;xx<=tox;xx++)
1378 for(yy=fromy;yy<=toy;yy++) {
1379 int b = 1-data[width*yy+xx];
1381 if(xx==fromx) weight = (weight*xweight1)/256;
1382 if(xx==tox) weight = (weight*xweight2)/256;
1383 if(yy==fromy) weight = (weight*yweight1)/256;
1384 if(yy==toy) weight = (weight*yweight2)/256;
1387 //if(a) a=(palettesize-1)*r/blocksize;
1388 newdata[y*newwidth+x] = (a*blocksize)/r;
1396 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1397 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1398 GBool inlineImg, int mask)
1403 double x1,y1,x2,y2,x3,y3,x4,y4;
1404 ImageStream *imgStr;
1411 ncomps = colorMap->getNumPixelComps();
1412 bits = colorMap->getBits();
1414 imgStr = new ImageStream(str, width, ncomps,bits);
1417 if(!width || !height || (height<=1 && width<=1))
1419 msg("<verbose> Ignoring %d by %d image", width, height);
1420 unsigned char buf[8];
1422 for (y = 0; y < height; ++y)
1423 for (x = 0; x < width; ++x) {
1424 imgStr->getPixel(buf);
1430 state->transform(0, 1, &x1, &y1);
1431 state->transform(0, 0, &x2, &y2);
1432 state->transform(1, 0, &x3, &y3);
1433 state->transform(1, 1, &x4, &y4);
1435 if(!pbminfo && !(str->getKind()==strDCT)) {
1437 msg("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1441 msg("<verbose> drawing %d by %d masked picture\n", width, height);
1443 if(!jpeginfo && (str->getKind()==strDCT)) {
1444 msg("<notice> file contains jpeg pictures");
1450 unsigned char buf[8];
1454 unsigned char*pic = new unsigned char[width*height];
1457 state->getFillRGB(&rgb);
1458 memset(pal,255,sizeof(pal));
1459 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1460 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1461 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1463 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1464 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1465 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1466 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1467 for (y = 0; y < height; ++y)
1468 for (x = 0; x < width; ++x)
1470 imgStr->getPixel(buf);
1473 pic[width*y+x] = buf[0];
1478 /* the size of the drawn image is added to the identifier
1479 as the same image may require different bitmaps if displayed
1480 at different sizes (due to antialiasing): */
1486 for(t=0;t<picpos;t++)
1488 if(pic_xids[t] == xid &&
1489 pic_yids[t] == yid) {
1490 /* if the image was antialiased, the size has changed: */
1491 width = pic_width[t];
1492 height = pic_height[t];
1499 unsigned char*pic2 = 0;
1501 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1505 height = realheight;
1508 /* make a black/white palette */
1515 float r = 255/(numpalette-1);
1516 for(t=0;t<numpalette;t++) {
1517 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1518 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1519 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1521 pal[t].r = (U8)(255*rgb.r);
1522 pal[t].g = (U8)(255*rgb.g);
1523 pal[t].b = (U8)(255*rgb.b);
1524 pal[t].a = (U8)(t*r);
1528 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1529 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1530 pic_xids[picpos] = xid;
1531 pic_yids[picpos] = yid;
1532 pic_width[picpos] = width;
1533 pic_height[picpos] = height;
1537 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1538 x1,y1,x2,y2,x3,y3,x4,y4);
1547 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1549 RGBA*pic=new RGBA[width*height];
1552 for (y = 0; y < height; ++y) {
1553 for (x = 0; x < width; ++x) {
1555 imgStr->getPixel(pixBuf);
1556 colorMap->getRGB(pixBuf, &rgb);
1557 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1558 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1559 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1560 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1561 xid += x*r+x*b*3+x*g*7+x*a*11;
1562 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1566 for(t=0;t<picpos;t++)
1568 if(pic_xids[t] == xid &&
1569 pic_yids[t] == yid) {
1574 if(str->getKind()==strDCT)
1575 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1576 x1,y1,x2,y2,x3,y3,x4,y4);
1578 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1579 x1,y1,x2,y2,x3,y3,x4,y4);
1580 pic_xids[picpos] = xid;
1581 pic_yids[picpos] = yid;
1582 pic_width[picpos] = width;
1583 pic_height[picpos] = height;
1587 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1588 x1,y1,x2,y2,x3,y3,x4,y4);
1596 U8*pic = new U8[width*height];
1604 colorMap->getRGB(pixBuf, &rgb);
1605 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1606 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1607 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1608 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1609 xid += t*r+t*b*3+t*g*7+t*a*11;
1610 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1612 for (y = 0; y < height; ++y) {
1613 for (x = 0; x < width; ++x) {
1614 imgStr->getPixel(pixBuf);
1615 pic[width*y+x] = pixBuf[0];
1616 xid += x*pixBuf[0]*7;
1617 yid += y*pixBuf[0]*3;
1621 for(t=0;t<picpos;t++)
1623 if(pic_xids[t] == xid &&
1624 pic_yids[t] == yid) {
1629 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1630 x1,y1,x2,y2,x3,y3,x4,y4,256);
1631 pic_xids[picpos] = xid;
1632 pic_yids[picpos] = yid;
1633 pic_width[picpos] = width;
1634 pic_height[picpos] = height;
1638 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1639 x1,y1,x2,y2,x3,y3,x4,y4);
1647 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1648 int width, int height, GBool invert,
1651 msg("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1652 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1655 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1656 int width, int height, GfxImageColorMap *colorMap,
1657 int *maskColors, GBool inlineImg)
1659 msg("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1660 colorMap?"colorMap":"no colorMap",
1661 maskColors?"maskColors":"no maskColors",
1664 msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1665 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1666 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1669 SWFOutputDev*output = 0;
1671 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1676 if (infoDict->lookup(key, &obj)->isString()) {
1677 s1 = obj.getString();
1678 if ((s1->getChar(0) & 0xff) == 0xfe &&
1679 (s1->getChar(1) & 0xff) == 0xff) {
1681 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1682 if (s1->getChar(i) == '\0') {
1683 s2->append(s1->getChar(i+1));
1686 s2 = new GString("<unicode>");
1690 printf(fmt, s2->getCString());
1693 printf(fmt, s1->getCString());
1699 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1703 if (infoDict->lookup(key, &obj)->isString()) {
1704 s = obj.getString()->getCString();
1705 if (s[0] == 'D' && s[1] == ':') {
1713 void pdfswf_init(char*filename, char*userPassword)
1715 GString *fileName = new GString(filename);
1720 globalParams = new GlobalParams("");
1723 if (userPassword && userPassword[0]) {
1724 userPW = new GString(userPassword);
1728 doc = new PDFDoc(fileName, userPW);
1737 doc->getDocInfo(&info);
1738 if (info.isDict() &&
1739 (screenloglevel>=LOGLEVEL_NOTICE)) {
1740 printInfoString(info.getDict(), "Title", "Title: %s\n");
1741 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1742 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1743 printInfoString(info.getDict(), "Author", "Author: %s\n");
1744 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1745 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1746 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1747 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1748 printf("Pages: %d\n", doc->getNumPages());
1749 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1750 printf("Encrypted: ");
1751 if (doc->isEncrypted()) {
1752 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1753 doc->okToPrint() ? "yes" : "no",
1754 doc->okToCopy() ? "yes" : "no",
1755 doc->okToChange() ? "yes" : "no",
1756 doc->okToAddNotes() ? "yes" : "no");
1763 numpages = doc->getNumPages();
1764 if (doc->isEncrypted()) {
1765 if(!doc->okToCopy()) {
1766 printf("PDF disallows copying. Bailing out.\n");
1769 if(!doc->okToChange() || !doc->okToAddNotes())
1770 swfoutput_setprotected();
1773 output = new SWFOutputDev();
1774 output->startDoc(doc->getXRef());
1777 void pdfswf_setparameter(char*name, char*value)
1779 if(!strcmp(name, "outputfilename")) {
1780 swffilename = value;
1781 } else if(!strcmp(name, "caplinewidth")) {
1782 caplinewidth = atof(value);
1783 } else if(!strcmp(name, "zoom")) {
1786 swfoutput_setparameter(name, value);
1790 void pdfswf_addfont(char*filename)
1793 memset(&f, 0, sizeof(fontfile_t));
1794 f.filename = filename;
1795 fonts[fontnum++] = f;
1798 void pdfswf_setoutputfilename(char*_filename) { swffilename = _filename; }
1800 void pdfswf_convertpage(int page)
1804 pages = (int*)malloc(1024*sizeof(int));
1807 if(pagepos == pagebuflen)
1810 pages = (int*)realloc(pages, pagebuflen);
1813 pages[pagepos++] = page;
1816 void pdfswf_performconversion()
1819 for(t=0;t<pagepos;t++)
1821 currentpage = pages[t];
1822 doc->displayPage((OutputDev*)output, currentpage, /*zoom*/zoom, /*rotate*/0, /*doLinks*/(int)1);
1825 int pdfswf_numpages()
1827 return doc->getNumPages();
1832 msg("<debug> pdfswf.cc: pdfswf_close()");
1836 // check for memory leaks
1837 Object::memCheck(stderr);