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"
48 #include "GlobalParams.h"
53 #include "FoFiType1C.h"
54 #include "FoFiTrueType.h"
56 #include "SWFOutputDev.h"
58 //swftools header files
59 #include "swfoutput.h"
60 #include "../lib/log.h"
64 static PDFDoc*doc = 0;
65 static char* swffilename = 0;
67 static int currentpage;
69 typedef struct _fontfile
75 static fontfile_t fonts[2048];
76 static int fontnum = 0;
80 static int pagebuflen = 0;
81 static int pagepos = 0;
83 static double caplinewidth = 3.0;
84 static int zoom = 72; /* xpdf: 86 */
86 static void printInfoString(Dict *infoDict, char *key, char *fmt);
87 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
89 static double fontsizes[] =
91 0.833,0.833,0.889,0.889,
92 0.788,0.722,0.833,0.778,
93 0.600,0.600,0.600,0.600,
94 0.576,0.576,0.576,0.576,
97 static char*fontnames[]={
100 "Helvetica-BoldOblique",
108 "Courier-BoldOblique",
122 {"Times-Roman", "n021003l"},
123 {"Times-Italic", "n021023l"},
124 {"Times-Bold", "n021004l"},
125 {"Times-BoldItalic", "n021024l"},
126 {"Helvetica", "n019003l"},
127 {"Helvetica-Oblique", "n019023l"},
128 {"Helvetica-Bold", "n019004l"},
129 {"Helvetica-BoldOblique", "n019024l"},
130 {"Courier", "n022003l"},
131 {"Courier-Oblique", "n022023l"},
132 {"Courier-Bold", "n022004l"},
133 {"Courier-BoldOblique", "n022024l"},
134 {"Symbol", "s050000l"},
135 {"ZapfDingbats", "d050000l"}};
138 class GfxImageColorMap;
140 class SWFOutputDev: public OutputDev {
141 struct swfoutput output;
149 virtual ~SWFOutputDev() ;
151 //----- get info about output device
153 // Does this device use upside-down coordinates?
154 // (Upside-down means (0,0) is the top left corner of the page.)
155 virtual GBool upsideDown();
157 // Does this device use drawChar() or drawString()?
158 virtual GBool useDrawChar();
160 virtual GBool interpretType3Chars() {return gTrue;}
162 //----- initialization and control
164 void startDoc(XRef *xref);
167 virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
170 virtual void drawLink(Link *link, Catalog *catalog) ;
172 //----- save/restore graphics state
173 virtual void saveState(GfxState *state) ;
174 virtual void restoreState(GfxState *state) ;
176 //----- update graphics state
178 virtual void updateFont(GfxState *state);
179 virtual void updateFillColor(GfxState *state);
180 virtual void updateStrokeColor(GfxState *state);
181 virtual void updateLineWidth(GfxState *state);
182 virtual void updateLineJoin(GfxState *state);
183 virtual void updateLineCap(GfxState *state);
185 virtual void updateAll(GfxState *state)
188 updateFillColor(state);
189 updateStrokeColor(state);
190 updateLineWidth(state);
191 updateLineJoin(state);
192 updateLineCap(state);
195 //----- path painting
196 virtual void stroke(GfxState *state) ;
197 virtual void fill(GfxState *state) ;
198 virtual void eoFill(GfxState *state) ;
200 //----- path clipping
201 virtual void clip(GfxState *state) ;
202 virtual void eoClip(GfxState *state) ;
205 virtual void beginString(GfxState *state, GString *s) ;
206 virtual void endString(GfxState *state) ;
207 virtual void drawChar(GfxState *state, double x, double y,
208 double dx, double dy,
209 double originX, double originY,
210 CharCode code, Unicode *u, int uLen);
212 //----- image drawing
213 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
214 int width, int height, GBool invert,
216 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
217 int width, int height, GfxImageColorMap *colorMap,
218 int *maskColors, GBool inlineImg);
220 virtual GBool beginType3Char(GfxState *state,
221 CharCode code, Unicode *u, int uLen);
222 virtual void endType3Char(GfxState *state);
225 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
226 int width, int height, GfxImageColorMap*colorMap, GBool invert,
227 GBool inlineImg, int mask);
233 char* searchFont(char*name);
234 char* substituteFont(GfxFont*gfxFont, char*oldname);
235 char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
237 int jpeginfo; // did we write "File contains jpegs" yet?
238 int pbminfo; // did we write "File contains jpegs" yet?
239 int linkinfo; // did we write "File contains links" yet?
240 int ttfinfo; // did we write "File contains TrueType Fonts" yet?
242 int type3active; // are we between beginType3()/endType3()?
247 static char*getFontID(GfxFont*font)
249 GString*gstr = font->getName();
250 char* fontname = gstr==0?0:gstr->getCString();
254 sprintf(buf, "UFONT%d", r->num);
260 static char*getFontName(GfxFont*font)
262 char*fontname = getFontID(font);
263 char* plus = strchr(fontname, '+');
264 if(plus && plus < &fontname[strlen(fontname)-1])
270 char* gfxstate2str(GfxState *state)
274 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
281 if(state->getX1()!=0.0)
282 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
283 if(state->getY1()!=0.0)
284 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
285 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
286 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
287 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
288 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
289 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
290 state->getFillColor()->c[0], state->getFillColor()->c[1]);
291 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
292 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
293 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
294 state->getFillColor()->c[0], state->getFillColor()->c[1],
295 state->getFillColor()->c[2], state->getFillColor()->c[3],
296 state->getFillColor()->c[4], state->getFillColor()->c[5],
297 state->getFillColor()->c[6], state->getFillColor()->c[7]);
298 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
299 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
300 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
301 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
302 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
303 state->getFillRGB(&rgb);
304 if(rgb.r || rgb.g || rgb.b)
305 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
306 state->getStrokeRGB(&rgb);
307 if(rgb.r || rgb.g || rgb.b)
308 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
309 if(state->getFillColorSpace()->getNComps()>1)
310 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
311 if(state->getStrokeColorSpace()->getNComps()>1)
312 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
313 if(state->getFillPattern())
314 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
315 if(state->getStrokePattern())
316 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
318 if(state->getFillOpacity()!=1.0)
319 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
320 if(state->getStrokeOpacity()!=1.0)
321 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
323 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
328 state->getLineDash(&dash, &length, &start);
332 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
333 for(t=0;t<length;t++) {
334 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
336 bufpos+=sprintf(bufpos,"]");
339 if(state->getFlatness()!=1)
340 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
341 if(state->getLineJoin()!=0)
342 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
343 if(state->getLineJoin()!=0)
344 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
345 if(state->getLineJoin()!=0)
346 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
348 if(state->getFont() && getFontID(state->getFont()))
349 bufpos+=sprintf(bufpos,"F\"%s\" ",getFontID(state->getFont()));
350 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
351 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
352 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
353 if(state->getCharSpace())
354 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
355 if(state->getWordSpace())
356 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
357 if(state->getHorizScaling()!=1.0)
358 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
359 if(state->getLeading())
360 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
362 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
363 if(state->getRender())
364 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
365 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
366 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
367 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
368 if(state->getLineX())
369 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
370 if(state->getLineY())
371 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
372 bufpos+=sprintf(bufpos," ");
378 void dumpFontInfo(char*loglevel, GfxFont*font);
385 void showFontError(GfxFont*font, int nr)
389 for(t=0;t<lastdumppos;t++)
390 if(lastdumps[t] == r->num)
394 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
395 lastdumps[lastdumppos++] = r->num;
397 msg("<warning> The following font caused problems:");
399 msg("<warning> The following font caused problems (substituting):");
401 msg("<warning> The following Type 3 Font will be rendered as bitmap:");
402 dumpFontInfo("<warning>", font);
405 void dumpFontInfo(char*loglevel, GfxFont*font)
407 char* name = getFontID(font);
408 Ref* r=font->getID();
409 msg("%s=========== %s (ID:%d,%d) ==========\n", loglevel, getFontName(font), r->num,r->gen);
411 GString*gstr = font->getTag();
413 msg("%s| Tag: %s\n", loglevel, name);
415 if(font->isCIDFont()) msg("%s| is CID font\n", loglevel);
417 GfxFontType type=font->getType();
419 case fontUnknownType:
420 msg("%s| Type: unknown\n",loglevel);
423 msg("%s| Type: 1\n",loglevel);
426 msg("%s| Type: 1C\n",loglevel);
429 msg("%s| Type: 3\n",loglevel);
432 msg("%s| Type: TrueType\n",loglevel);
435 msg("%s| Type: CIDType0\n",loglevel);
438 msg("%s| Type: CIDType0C\n",loglevel);
441 msg("%s| Type: CIDType2\n",loglevel);
446 GBool embedded = font->getEmbeddedFontID(&embRef);
447 if(font->getEmbeddedFontName())
448 name = font->getEmbeddedFontName()->getCString();
450 msg("%s| Embedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
452 gstr = font->getExtFontFile();
454 msg("%s| External Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
456 // Get font descriptor flags.
457 if(font->isFixedWidth()) msg("%s| is fixed width\n", loglevel);
458 if(font->isSerif()) msg("%s| is serif\n", loglevel);
459 if(font->isSymbolic()) msg("%s| is symbolic\n", loglevel);
460 if(font->isItalic()) msg("%s| is italic\n", loglevel);
461 if(font->isBold()) msg("%s| is bold\n", loglevel);
464 //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");}
465 //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");}
467 SWFOutputDev::SWFOutputDev()
475 clipping[clippos] = 0;
478 // printf("SWFOutputDev::SWFOutputDev() \n");
481 SWF_OUTLINE* gfxPath_to_SWF_OUTLINE(GfxState*state, GfxPath*path)
483 int num = path->getNumSubpaths();
485 bezierpathsegment*start,*last=0;
486 bezierpathsegment*outline = start = new bezierpathsegment();
488 double lastx=0,lasty=0;
490 msg("<warning> empty path");
491 outline->type = SWF_PATHTYPE_MOVE;
495 return (SWF_OUTLINE*)outline;
497 for(t = 0; t < num; t++) {
498 GfxSubpath *subpath = path->getSubpath(t);
499 int subnum = subpath->getNumPoints();
501 for(s=0;s<subnum;s++) {
503 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
504 int x = (int)((nx-lastx)*0xffff);
505 int y = (int)((ny-lasty)*0xffff);
509 outline->type = SWF_PATHTYPE_MOVE;
512 outline->link = (SWF_OUTLINE*)new bezierpathsegment();
513 outline = (bezierpathsegment*)outline->link;
518 else if(subpath->getCurve(s) && !cpos)
524 else if(subpath->getCurve(s) && cpos)
535 outline->type = cpos?SWF_PATHTYPE_BEZIER:SWF_PATHTYPE_LINE;
537 outline->link = (SWF_OUTLINE*)new bezierpathsegment();
538 outline = (bezierpathsegment*)outline->link;
546 return (SWF_OUTLINE*)start;
548 /*----------------------------------------------------------------------------
549 * Primitive Graphic routines
550 *----------------------------------------------------------------------------*/
552 void SWFOutputDev::stroke(GfxState *state)
554 msg("<debug> stroke\n");
555 GfxPath * path = state->getPath();
556 int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square
557 int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel
558 double miterLimit = state->getMiterLimit();
559 double width = state->getTransformedLineWidth();
562 double opaq = state->getStrokeOpacity();
563 state->getStrokeRGB(&rgb);
565 m.m11 = 1; m.m21 = 0; m.m22 = 1;
566 m.m12 = 0; m.m13 = 0; m.m23 = 0;
567 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
569 lineJoin = 1; // other line joins are not yet supported by the swf encoder
570 // TODO: support bevel joints
572 if(((lineCap==1) && (lineJoin==1)) || width<=caplinewidth) {
573 /* FIXME- if the path is smaller than 2 segments, we could ignore
575 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
576 swfoutput_drawpath(&output, outline, &m);
578 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
579 (char)(rgb.b*255), (char)(opaq*255));
581 //swfoutput_setlinewidth(&output, 1.0); //only for debugging
582 //swfoutput_setstrokecolor(&output, 0, 255, 0, 255); //likewise, see below
583 //swfoutput_setfillcolor(&output, 255, 0, 0, 255); //likewise, see below
585 swfoutput_drawpath2poly(&output, outline, &m, lineJoin, lineCap, width, miterLimit);
586 updateLineWidth(state); //reset
587 updateStrokeColor(state); //reset
588 updateFillColor(state); //reset
591 void SWFOutputDev::fill(GfxState *state)
593 msg("<debug> fill\n");
594 GfxPath * path = state->getPath();
596 m.m11 = 1; m.m21 = 0; m.m22 = 1;
597 m.m12 = 0; m.m13 = 0; m.m23 = 0;
598 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
599 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
600 swfoutput_drawpath(&output, outline, &m);
602 void SWFOutputDev::eoFill(GfxState *state)
604 msg("<debug> eofill\n");
605 GfxPath * path = state->getPath();
607 m.m11 = 1; m.m21 = 0; m.m22 = 1;
608 m.m12 = 0; m.m13 = 0; m.m23 = 0;
609 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
610 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
611 swfoutput_drawpath(&output, outline, &m);
613 void SWFOutputDev::clip(GfxState *state)
615 msg("<debug> clip\n");
616 GfxPath * path = state->getPath();
618 m.m11 = 1; m.m22 = 1;
619 m.m12 = 0; m.m21 = 0;
620 m.m13 = 0; m.m23 = 0;
621 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
622 swfoutput_startclip(&output, outline, &m);
623 clipping[clippos] ++;
625 void SWFOutputDev::eoClip(GfxState *state)
627 msg("<debug> eoclip\n");
628 GfxPath * path = state->getPath();
630 m.m11 = 1; m.m21 = 0; m.m22 = 1;
631 m.m12 = 0; m.m13 = 0; m.m23 = 0;
632 SWF_OUTLINE*outline = gfxPath_to_SWF_OUTLINE(state, path);
633 swfoutput_startclip(&output, outline, &m);
634 clipping[clippos] ++;
637 SWFOutputDev::~SWFOutputDev()
639 swfoutput_destroy(&output);
642 GBool SWFOutputDev::upsideDown()
644 msg("<debug> upsidedown? yes");
647 GBool SWFOutputDev::useDrawChar()
652 void SWFOutputDev::beginString(GfxState *state, GString *s)
654 double m11,m21,m12,m22;
655 // msg("<debug> %s beginstring \"%s\"\n", gfxstate2str(state), s->getCString());
656 state->getFontTransMat(&m11, &m12, &m21, &m22);
657 m11 *= state->getHorizScaling();
658 m21 *= state->getHorizScaling();
659 swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
662 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
663 double dx, double dy,
664 double originX, double originY,
665 CharCode c, Unicode *_u, int uLen)
667 // check for invisible text -- this is used by Acrobat Capture
668 if ((state->getRender() & 3) == 3)
671 GfxFont*font = state->getFont();
673 if(font->getType() == fontType3) {
674 /* type 3 chars are passed as graphics */
680 state->transform(x, y, &x1, &y1);
686 /* find out the character name */
688 if(font->isCIDFont() && u) {
689 GfxCIDFont*cfont = (GfxCIDFont*)font;
691 for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
692 /* todo: should be precomputed */
693 if(nameToUnicodeTab[t].u == u) {
694 name = nameToUnicodeTab[t].name;
700 font8 = (Gfx8BitFont*)font;
701 char**enc=font8->getEncoding();
706 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));
708 /*x1 = (int)(x1+0.5);
709 y1 = (int)(y1+0.5);*/
711 int ret = swfoutput_drawchar(&output, x1, y1, name, c, u);
714 void SWFOutputDev::endString(GfxState *state) {
718 GBool SWFOutputDev::beginType3Char(GfxState *state,
719 CharCode code, Unicode *u, int uLen)
721 msg("<debug> beginType3Char %d, %08x, %d", code, *u, uLen);
723 /* the character itself is going to be passed using
725 return gFalse; /* gTrue= is_in_cache? */
728 void SWFOutputDev::endType3Char(GfxState *state)
731 msg("<debug> endType3Char");
734 void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
737 int rot = doc->getPageRotate(1);
739 msg("<verbose> startPage %d (%f,%f,%f,%f)\n", pageNum, crop_x1, crop_y1, crop_x2, crop_y2);
741 msg("<verbose> page is rotated %d degrees\n", rot);
743 msg("<notice> processing page %d", pageNum);
745 /* state->transform(state->getX1(),state->getY1(),&x1,&y1);
746 state->transform(state->getX2(),state->getY2(),&x2,&y2);
747 Use CropBox, not MediaBox, as page size
754 state->transform(crop_x1,crop_y1,&x1,&y1);
755 state->transform(crop_x2,crop_y2,&x2,&y2);
757 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
758 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
761 msg("<verbose> Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2);
762 swfoutput_init(&output, swffilename,(int)x1,(int)y1,(int)x2,(int)y2);
766 swfoutput_newpage(&output);
769 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
771 msg("<debug> drawlink\n");
772 double x1, y1, x2, y2, w;
778 link->getBorder(&x1, &y1, &x2, &y2, &w);
780 link->getRect(&x1, &y1, &x2, &y2);
787 cvtUserToDev(x1, y1, &x, &y);
788 points[0].x = points[4].x = (int)x;
789 points[0].y = points[4].y = (int)y;
790 cvtUserToDev(x2, y1, &x, &y);
791 points[1].x = (int)x;
792 points[1].y = (int)y;
793 cvtUserToDev(x2, y2, &x, &y);
794 points[2].x = (int)x;
795 points[2].y = (int)y;
796 cvtUserToDev(x1, y2, &x, &y);
797 points[3].x = (int)x;
798 points[3].y = (int)y;
800 LinkAction*action=link->getAction();
807 switch(action->getKind())
811 LinkGoTo *ha=(LinkGoTo *)link->getAction();
813 if (ha->getDest()==NULL)
814 dest=catalog->findDest(ha->getNamedDest());
815 else dest=ha->getDest();
817 if (dest->isPageRef()){
818 Ref pageref=dest->getPageRef();
819 page=catalog->findPage(pageref.num,pageref.gen);
821 else page=dest->getPageNum();
822 sprintf(buf, "%d", page);
829 LinkGoToR*l = (LinkGoToR*)action;
830 GString*g = l->getNamedDest();
837 LinkNamed*l = (LinkNamed*)action;
838 GString*name = l->getName();
840 s = name->lowerCase()->getCString();
841 named = name->getCString();
844 if(strstr(s, "next") || strstr(s, "forward"))
846 page = currentpage + 1;
848 else if(strstr(s, "prev") || strstr(s, "back"))
850 page = currentpage - 1;
852 else if(strstr(s, "last") || strstr(s, "end"))
854 page = pages[pagepos-1]; //:)
856 else if(strstr(s, "first") || strstr(s, "top"))
866 LinkLaunch*l = (LinkLaunch*)action;
867 GString * str = new GString(l->getFileName());
868 str->append(l->getParams());
869 s = str->getCString();
874 LinkURI*l = (LinkURI*)action;
875 GString*g = l->getURI();
877 url = g->getCString();
882 case actionUnknown: {
884 LinkUnknown*l = (LinkUnknown*)action;
889 msg("<error> Unknown link type!\n");
893 if(!linkinfo && (page || url))
895 msg("<notice> File contains links");
901 for(t=0;t<pagepos;t++)
905 swfoutput_linktopage(&output, t, points);
909 swfoutput_linktourl(&output, url, points);
913 swfoutput_namedlink(&output, named, points);
915 msg("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
919 void SWFOutputDev::saveState(GfxState *state) {
920 msg("<debug> saveState\n");
925 msg("<error> Too many nested states in pdf.");
926 clipping[clippos] = 0;
929 void SWFOutputDev::restoreState(GfxState *state) {
930 msg("<debug> restoreState\n");
932 while(clipping[clippos]) {
933 swfoutput_endclip(&output);
941 char* SWFOutputDev::searchFont(char*name)
945 int is_standard_font = 0;
947 msg("<verbose> SearchFont(%s)", name);
949 /* see if it is a pdf standard font */
950 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
952 if(!strcmp(name, pdf2t1map[i].pdffont))
954 name = pdf2t1map[i].filename;
955 is_standard_font = 1;
959 /* look in all font files */
960 for(i=0;i<fontnum;i++)
962 if(strstr(fonts[i].filename, name))
967 if(!is_standard_font)
968 msg("<notice> Using %s for %s", fonts[i].filename, name);
970 return fonts[i].filename;
976 void SWFOutputDev::updateLineWidth(GfxState *state)
978 double width = state->getTransformedLineWidth();
979 swfoutput_setlinewidth(&output, width);
982 void SWFOutputDev::updateLineCap(GfxState *state)
984 int c = state->getLineCap();
987 void SWFOutputDev::updateLineJoin(GfxState *state)
989 int j = state->getLineJoin();
992 void SWFOutputDev::updateFillColor(GfxState *state)
995 double opaq = state->getFillOpacity();
996 state->getFillRGB(&rgb);
998 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
999 (char)(rgb.b*255), (char)(opaq*255));
1002 void SWFOutputDev::updateStrokeColor(GfxState *state)
1005 double opaq = state->getStrokeOpacity();
1006 state->getStrokeRGB(&rgb);
1008 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
1009 (char)(rgb.b*255), (char)(opaq*255));
1012 void FoFiWrite(void *stream, char *data, int len)
1014 fwrite(data, len, 1, (FILE*)stream);
1017 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
1019 char*tmpFileName = NULL;
1025 Object refObj, strObj;
1027 tmpFileName = mktmpname(namebuf);
1030 ret = font->getEmbeddedFontID(&embRef);
1032 msg("<verbose> Didn't get embedded font id");
1033 /* not embedded- the caller should now search the font
1034 directories for this font */
1038 f = fopen(tmpFileName, "wb");
1040 msg("<error> Couldn't create temporary Type 1 font file");
1044 /*if(font->isCIDFont()) {
1045 GfxCIDFont* cidFont = (GfxCIDFont *)font;
1046 GString c = cidFont->getCollection();
1047 msg("<notice> Collection: %s", c.getCString());
1050 if (font->getType() == fontType1C ||
1051 font->getType() == fontCIDType0C) {
1052 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1054 msg("<error> Couldn't read embedded font file");
1058 Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
1059 cvt->convertToType1(f);
1061 FoFiType1C *cvt = FoFiType1C::make(fontBuf, fontLen);
1062 cvt->convertToType1(NULL, gTrue, FoFiWrite, f);
1064 //cvt->convertToCIDType0("test", f);
1065 //cvt->convertToType0("test", f);
1068 } else if(font->getType() == fontTrueType) {
1069 msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
1070 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1072 msg("<error> Couldn't read embedded font file");
1076 TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
1079 FoFiTrueType *cvt = FoFiTrueType::make(fontBuf, fontLen);
1080 cvt->writeTTF(FoFiWrite, f);
1085 font->getEmbeddedFontID(&embRef);
1086 refObj.initRef(embRef.num, embRef.gen);
1087 refObj.fetch(ref, &strObj);
1089 strObj.streamReset();
1094 f4[t] = strObj.streamGetChar();
1095 f4c[t] = (char)f4[t];
1100 if(!strncmp(f4c, "true", 4)) {
1101 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1102 Change this on the fly */
1103 f4[0] = f4[2] = f4[3] = 0;
1111 while ((c = strObj.streamGetChar()) != EOF) {
1115 strObj.streamClose();
1120 return strdup(tmpFileName);
1124 char* substitutetarget[256];
1125 char* substitutesource[256];
1126 int substitutepos = 0;
1128 char* searchForSuitableFont(GfxFont*gfxFont)
1130 char*name = getFontName(gfxFont);
1134 #ifdef HAVE_FONTCONFIG
1135 FcPattern *pattern, *match;
1139 // call init ony once
1140 static int fcinitcalled = false;
1141 if (!fcinitcalled) {
1142 fcinitcalled = true;
1146 pattern = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, name, NULL);
1147 if (gfxFont->isItalic()) // check for italic
1148 FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1149 if (gfxFont->isBold()) // check for bold
1150 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1152 // configure and match using the original font name
1153 FcConfigSubstitute(0, pattern, FcMatchPattern);
1154 FcDefaultSubstitute(pattern);
1155 match = FcFontMatch(0, pattern, &result);
1157 if (FcPatternGetString(match, "family", 0, &v) == FcResultMatch) {
1158 // if we get an exact match
1159 if (strcmp((char *)v, name) == 0) {
1160 if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
1161 filename = strdup((char*)v);
1162 char *nfn = strrchr(filename, '/');
1163 if(nfn) fontname = strdup(nfn+1);
1164 else fontname = filename;
1167 // initialize patterns
1168 FcPatternDestroy(pattern);
1169 FcPatternDestroy(match);
1171 // now match against serif etc.
1172 if (gfxFont->isSerif()) {
1173 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "serif", NULL);
1174 } else if (gfxFont->isFixedWidth()) {
1175 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "monospace", NULL);
1177 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "sans", NULL);
1181 if (gfxFont->isItalic()) {
1182 int bb = FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1185 if (gfxFont->isBold()) {
1186 int bb = FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1189 // configure and match using serif etc
1190 FcConfigSubstitute (0, pattern, FcMatchPattern);
1191 FcDefaultSubstitute (pattern);
1192 match = FcFontMatch (0, pattern, &result);
1194 if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
1195 filename = strdup((char*)v);
1196 char *nfn = strrchr(filename, '/');
1197 if(nfn) fontname = strdup(nfn+1);
1198 else fontname = filename;
1203 //printf("FONTCONFIG: pattern");
1204 //FcPatternPrint(pattern);
1205 //printf("FONTCONFIG: match");
1206 //FcPatternPrint(match);
1208 FcPatternDestroy(pattern);
1209 FcPatternDestroy(match);
1211 pdfswf_addfont(filename);
1218 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1220 char*fontname = 0, *filename = 0;
1221 msg("<notice> subsituteFont(%s)", oldname);
1223 if(!(fontname = searchForSuitableFont(gfxFont))) {
1224 fontname = "Times-Roman";
1226 filename = searchFont(fontname);
1228 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1229 msg("<fatal> Too many fonts in file.");
1233 substitutesource[substitutepos] = oldname;
1234 substitutetarget[substitutepos] = fontname;
1235 msg("<notice> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1241 void unlinkfont(char* filename)
1248 if(!strncmp(&filename[l-4],".afm",4)) {
1249 memcpy(&filename[l-4],".pfb",4);
1251 memcpy(&filename[l-4],".pfa",4);
1253 memcpy(&filename[l-4],".afm",4);
1256 if(!strncmp(&filename[l-4],".pfa",4)) {
1257 memcpy(&filename[l-4],".afm",4);
1259 memcpy(&filename[l-4],".pfa",4);
1262 if(!strncmp(&filename[l-4],".pfb",4)) {
1263 memcpy(&filename[l-4],".afm",4);
1265 memcpy(&filename[l-4],".pfb",4);
1270 void SWFOutputDev::startDoc(XRef *xref)
1276 void SWFOutputDev::updateFont(GfxState *state)
1278 GfxFont*gfxFont = state->getFont();
1283 char * fontid = getFontID(gfxFont);
1286 /* first, look if we substituted this font before-
1287 this way, we don't initialize the T1 Fonts
1289 for(t=0;t<substitutepos;t++) {
1290 if(!strcmp(fontid, substitutesource[t])) {
1291 fontid = substitutetarget[t];
1296 /* second, see if swfoutput already has this font
1297 cached- if so, we are done */
1298 if(swfoutput_queryfont(&output, fontid))
1300 swfoutput_setfont(&output, fontid, 0);
1302 msg("<debug> updateFont(%s) [cached]", fontid);
1306 // look for Type 3 font
1307 if (gfxFont->getType() == fontType3) {
1309 type3Warning = gTrue;
1310 showFontError(gfxFont, 2);
1315 /* now either load the font, or find a substitution */
1318 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1323 (gfxFont->getType() == fontType1 ||
1324 gfxFont->getType() == fontType1C ||
1325 //gfxFont->getType() == fontCIDType0C ||
1326 gfxFont->getType() == fontTrueType ||
1327 gfxFont->getType() == fontCIDType2
1330 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1331 if(!fileName) showFontError(gfxFont,0);
1334 char * fontname = getFontName(gfxFont);
1335 fileName = searchFont(fontname);
1336 if(!fileName) showFontError(gfxFont,0);
1339 char * fontname = getFontName(gfxFont);
1340 msg("<warning> Font %s %scould not be loaded.", fontname, embedded?"":"(not embedded) ");
1341 msg("<warning> Try putting a TTF version of that font (named \"%s.ttf\") into /swftools/fonts", fontname);
1342 fileName = substituteFont(gfxFont, fontid);
1343 if(fontid) { fontid = substitutetarget[substitutepos-1]; /*ugly hack*/};
1344 msg("<notice> Font is now %s (%s)", fontid, fileName);
1348 msg("<error> Couldn't set font %s\n", fontid);
1352 msg("<verbose> updateFont(%s) -> %s", fontid, fileName);
1353 dumpFontInfo("<verbose>", gfxFont);
1355 swfoutput_setfont(&output, fontid, fileName);
1358 unlinkfont(fileName);
1364 int pic_width[1024];
1365 int pic_height[1024];
1369 #define SQR(x) ((x)*(x))
1371 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1373 if((newwidth<2 || newheight<2) ||
1374 (width<=newwidth || height<=newheight))
1376 unsigned char*newdata;
1378 newdata= (unsigned char*)malloc(newwidth*newheight);
1380 double fx = (double)(width)/newwidth;
1381 double fy = (double)(height)/newheight;
1383 int blocksize = (int)(8192/(fx*fy));
1384 int r = 8192*256/palettesize;
1385 for(x=0;x<newwidth;x++) {
1386 double ex = px + fx;
1387 int fromx = (int)px;
1389 int xweight1 = (int)(((fromx+1)-px)*256);
1390 int xweight2 = (int)((ex-tox)*256);
1392 for(y=0;y<newheight;y++) {
1393 double ey = py + fy;
1394 int fromy = (int)py;
1396 int yweight1 = (int)(((fromy+1)-py)*256);
1397 int yweight2 = (int)((ey-toy)*256);
1400 for(xx=fromx;xx<=tox;xx++)
1401 for(yy=fromy;yy<=toy;yy++) {
1402 int b = 1-data[width*yy+xx];
1404 if(xx==fromx) weight = (weight*xweight1)/256;
1405 if(xx==tox) weight = (weight*xweight2)/256;
1406 if(yy==fromy) weight = (weight*yweight1)/256;
1407 if(yy==toy) weight = (weight*yweight2)/256;
1410 //if(a) a=(palettesize-1)*r/blocksize;
1411 newdata[y*newwidth+x] = (a*blocksize)/r;
1419 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1420 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1421 GBool inlineImg, int mask)
1426 double x1,y1,x2,y2,x3,y3,x4,y4;
1427 ImageStream *imgStr;
1434 ncomps = colorMap->getNumPixelComps();
1435 bits = colorMap->getBits();
1437 imgStr = new ImageStream(str, width, ncomps,bits);
1440 if(!width || !height || (height<=1 && width<=1))
1442 msg("<verbose> Ignoring %d by %d image", width, height);
1443 unsigned char buf[8];
1445 for (y = 0; y < height; ++y)
1446 for (x = 0; x < width; ++x) {
1447 imgStr->getPixel(buf);
1453 state->transform(0, 1, &x1, &y1);
1454 state->transform(0, 0, &x2, &y2);
1455 state->transform(1, 0, &x3, &y3);
1456 state->transform(1, 1, &x4, &y4);
1458 if(!pbminfo && !(str->getKind()==strDCT)) {
1460 msg("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1464 msg("<verbose> drawing %d by %d masked picture\n", width, height);
1466 if(!jpeginfo && (str->getKind()==strDCT)) {
1467 msg("<notice> file contains jpeg pictures");
1473 unsigned char buf[8];
1477 unsigned char*pic = new unsigned char[width*height];
1480 state->getFillRGB(&rgb);
1481 memset(pal,255,sizeof(pal));
1482 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1483 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1484 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1486 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1487 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1488 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1489 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1490 for (y = 0; y < height; ++y)
1491 for (x = 0; x < width; ++x)
1493 imgStr->getPixel(buf);
1496 pic[width*y+x] = buf[0];
1501 /* the size of the drawn image is added to the identifier
1502 as the same image may require different bitmaps if displayed
1503 at different sizes (due to antialiasing): */
1509 for(t=0;t<picpos;t++)
1511 if(pic_xids[t] == xid &&
1512 pic_yids[t] == yid) {
1513 /* if the image was antialiased, the size has changed: */
1514 width = pic_width[t];
1515 height = pic_height[t];
1522 unsigned char*pic2 = 0;
1524 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1528 height = realheight;
1531 /* make a black/white palette */
1538 float r = 255/(numpalette-1);
1539 for(t=0;t<numpalette;t++) {
1540 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1541 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1542 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1544 pal[t].r = (U8)(255*rgb.r);
1545 pal[t].g = (U8)(255*rgb.g);
1546 pal[t].b = (U8)(255*rgb.b);
1547 pal[t].a = (U8)(t*r);
1551 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1552 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1553 pic_xids[picpos] = xid;
1554 pic_yids[picpos] = yid;
1555 pic_width[picpos] = width;
1556 pic_height[picpos] = height;
1560 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1561 x1,y1,x2,y2,x3,y3,x4,y4);
1570 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1572 RGBA*pic=new RGBA[width*height];
1575 for (y = 0; y < height; ++y) {
1576 for (x = 0; x < width; ++x) {
1578 imgStr->getPixel(pixBuf);
1579 colorMap->getRGB(pixBuf, &rgb);
1580 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1581 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1582 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1583 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1584 xid += x*r+x*b*3+x*g*7+x*a*11;
1585 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1589 for(t=0;t<picpos;t++)
1591 if(pic_xids[t] == xid &&
1592 pic_yids[t] == yid) {
1597 if(str->getKind()==strDCT)
1598 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1599 x1,y1,x2,y2,x3,y3,x4,y4);
1601 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1602 x1,y1,x2,y2,x3,y3,x4,y4);
1603 pic_xids[picpos] = xid;
1604 pic_yids[picpos] = yid;
1605 pic_width[picpos] = width;
1606 pic_height[picpos] = height;
1610 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1611 x1,y1,x2,y2,x3,y3,x4,y4);
1619 U8*pic = new U8[width*height];
1627 colorMap->getRGB(pixBuf, &rgb);
1628 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1629 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1630 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1631 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1632 xid += t*r+t*b*3+t*g*7+t*a*11;
1633 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1635 for (y = 0; y < height; ++y) {
1636 for (x = 0; x < width; ++x) {
1637 imgStr->getPixel(pixBuf);
1638 pic[width*y+x] = pixBuf[0];
1639 xid += x*pixBuf[0]*7;
1640 yid += y*pixBuf[0]*3;
1644 for(t=0;t<picpos;t++)
1646 if(pic_xids[t] == xid &&
1647 pic_yids[t] == yid) {
1652 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1653 x1,y1,x2,y2,x3,y3,x4,y4,256);
1654 pic_xids[picpos] = xid;
1655 pic_yids[picpos] = yid;
1656 pic_width[picpos] = width;
1657 pic_height[picpos] = height;
1661 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1662 x1,y1,x2,y2,x3,y3,x4,y4);
1670 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1671 int width, int height, GBool invert,
1674 msg("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1675 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1678 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1679 int width, int height, GfxImageColorMap *colorMap,
1680 int *maskColors, GBool inlineImg)
1682 msg("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1683 colorMap?"colorMap":"no colorMap",
1684 maskColors?"maskColors":"no maskColors",
1687 msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1688 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1689 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1692 SWFOutputDev*output = 0;
1694 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1699 if (infoDict->lookup(key, &obj)->isString()) {
1700 s1 = obj.getString();
1701 if ((s1->getChar(0) & 0xff) == 0xfe &&
1702 (s1->getChar(1) & 0xff) == 0xff) {
1704 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1705 if (s1->getChar(i) == '\0') {
1706 s2->append(s1->getChar(i+1));
1709 s2 = new GString("<unicode>");
1713 printf(fmt, s2->getCString());
1716 printf(fmt, s1->getCString());
1722 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1726 if (infoDict->lookup(key, &obj)->isString()) {
1727 s = obj.getString()->getCString();
1728 if (s[0] == 'D' && s[1] == ':') {
1736 void pdfswf_init(char*filename, char*userPassword)
1738 GString *fileName = new GString(filename);
1743 globalParams = new GlobalParams("");
1746 if (userPassword && userPassword[0]) {
1747 userPW = new GString(userPassword);
1751 doc = new PDFDoc(fileName, userPW);
1760 doc->getDocInfo(&info);
1761 if (info.isDict() &&
1762 (screenloglevel>=LOGLEVEL_NOTICE)) {
1763 printInfoString(info.getDict(), "Title", "Title: %s\n");
1764 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1765 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1766 printInfoString(info.getDict(), "Author", "Author: %s\n");
1767 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1768 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1769 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1770 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1771 printf("Pages: %d\n", doc->getNumPages());
1772 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1773 printf("Encrypted: ");
1774 if (doc->isEncrypted()) {
1775 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1776 doc->okToPrint() ? "yes" : "no",
1777 doc->okToCopy() ? "yes" : "no",
1778 doc->okToChange() ? "yes" : "no",
1779 doc->okToAddNotes() ? "yes" : "no");
1786 numpages = doc->getNumPages();
1787 if (doc->isEncrypted()) {
1788 if(!doc->okToCopy()) {
1789 printf("PDF disallows copying. Bailing out.\n");
1792 if(!doc->okToChange() || !doc->okToAddNotes())
1793 swfoutput_setprotected();
1796 output = new SWFOutputDev();
1797 output->startDoc(doc->getXRef());
1800 void pdfswf_setparameter(char*name, char*value)
1802 if(!strcmp(name, "outputfilename")) {
1803 swffilename = value;
1804 } else if(!strcmp(name, "caplinewidth")) {
1805 caplinewidth = atof(value);
1806 } else if(!strcmp(name, "zoom")) {
1809 swfoutput_setparameter(name, value);
1813 void pdfswf_addfont(char*filename)
1816 memset(&f, 0, sizeof(fontfile_t));
1817 f.filename = filename;
1818 fonts[fontnum++] = f;
1821 void pdfswf_setoutputfilename(char*_filename) { swffilename = _filename; }
1823 void pdfswf_convertpage(int page)
1827 pages = (int*)malloc(1024*sizeof(int));
1830 if(pagepos == pagebuflen)
1833 pages = (int*)realloc(pages, pagebuflen);
1836 pages[pagepos++] = page;
1839 void pdfswf_performconversion()
1842 for(t=0;t<pagepos;t++)
1844 currentpage = pages[t];
1846 doc->displayPage((OutputDev*)output, currentpage, /*zoom*/zoom, /*rotate*/0, /*doLinks*/(int)1);
1848 doc->displayPage((OutputDev*)output, currentpage, zoom, zoom, /*rotate*/0, true, /*doLinks*/(int)1);
1852 int pdfswf_numpages()
1854 return doc->getNumPages();
1859 msg("<debug> pdfswf.cc: pdfswf_close()");
1863 // check for memory leaks
1864 Object::memCheck(stderr);