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 /* state->transform(state->getX1(),state->getY1(),&x1,&y1);
744 state->transform(state->getX2(),state->getY2(),&x2,&y2);
745 Use CropBox, not MediaBox, as page size
752 state->transform(crop_x1,crop_y1,&x1,&y1);
753 state->transform(crop_x2,crop_y2,&x2,&y2);
755 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
756 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
759 msg("<verbose> Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2);
760 swfoutput_init(&output, swffilename);
764 swfoutput_newpage(&output, pageNum, (int)x1, (int)y1, (int)x2, (int)y2);
767 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
769 msg("<debug> drawlink\n");
770 double x1, y1, x2, y2, w;
776 link->getBorder(&x1, &y1, &x2, &y2, &w);
778 link->getRect(&x1, &y1, &x2, &y2);
785 cvtUserToDev(x1, y1, &x, &y);
786 points[0].x = points[4].x = (int)x;
787 points[0].y = points[4].y = (int)y;
788 cvtUserToDev(x2, y1, &x, &y);
789 points[1].x = (int)x;
790 points[1].y = (int)y;
791 cvtUserToDev(x2, y2, &x, &y);
792 points[2].x = (int)x;
793 points[2].y = (int)y;
794 cvtUserToDev(x1, y2, &x, &y);
795 points[3].x = (int)x;
796 points[3].y = (int)y;
798 LinkAction*action=link->getAction();
805 switch(action->getKind())
809 LinkGoTo *ha=(LinkGoTo *)link->getAction();
811 if (ha->getDest()==NULL)
812 dest=catalog->findDest(ha->getNamedDest());
813 else dest=ha->getDest();
815 if (dest->isPageRef()){
816 Ref pageref=dest->getPageRef();
817 page=catalog->findPage(pageref.num,pageref.gen);
819 else page=dest->getPageNum();
820 sprintf(buf, "%d", page);
827 LinkGoToR*l = (LinkGoToR*)action;
828 GString*g = l->getNamedDest();
835 LinkNamed*l = (LinkNamed*)action;
836 GString*name = l->getName();
838 s = name->lowerCase()->getCString();
839 named = name->getCString();
842 if(strstr(s, "next") || strstr(s, "forward"))
844 page = currentpage + 1;
846 else if(strstr(s, "prev") || strstr(s, "back"))
848 page = currentpage - 1;
850 else if(strstr(s, "last") || strstr(s, "end"))
852 page = pages[pagepos-1]; //:)
854 else if(strstr(s, "first") || strstr(s, "top"))
864 LinkLaunch*l = (LinkLaunch*)action;
865 GString * str = new GString(l->getFileName());
866 str->append(l->getParams());
867 s = str->getCString();
872 LinkURI*l = (LinkURI*)action;
873 GString*g = l->getURI();
875 url = g->getCString();
880 case actionUnknown: {
882 LinkUnknown*l = (LinkUnknown*)action;
887 msg("<error> Unknown link type!\n");
891 if(!linkinfo && (page || url))
893 msg("<notice> File contains links");
899 for(t=0;t<pagepos;t++)
903 swfoutput_linktopage(&output, t, points);
907 swfoutput_linktourl(&output, url, points);
911 swfoutput_namedlink(&output, named, points);
913 msg("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
917 void SWFOutputDev::saveState(GfxState *state) {
918 msg("<debug> saveState\n");
923 msg("<error> Too many nested states in pdf.");
924 clipping[clippos] = 0;
927 void SWFOutputDev::restoreState(GfxState *state) {
928 msg("<debug> restoreState\n");
930 while(clipping[clippos]) {
931 swfoutput_endclip(&output);
939 char* SWFOutputDev::searchFont(char*name)
943 int is_standard_font = 0;
945 msg("<verbose> SearchFont(%s)", name);
947 /* see if it is a pdf standard font */
948 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
950 if(!strcmp(name, pdf2t1map[i].pdffont))
952 name = pdf2t1map[i].filename;
953 is_standard_font = 1;
957 /* look in all font files */
958 for(i=0;i<fontnum;i++)
960 if(strstr(fonts[i].filename, name))
965 if(!is_standard_font)
966 msg("<notice> Using %s for %s", fonts[i].filename, name);
968 return fonts[i].filename;
974 void SWFOutputDev::updateLineWidth(GfxState *state)
976 double width = state->getTransformedLineWidth();
977 swfoutput_setlinewidth(&output, width);
980 void SWFOutputDev::updateLineCap(GfxState *state)
982 int c = state->getLineCap();
985 void SWFOutputDev::updateLineJoin(GfxState *state)
987 int j = state->getLineJoin();
990 void SWFOutputDev::updateFillColor(GfxState *state)
993 double opaq = state->getFillOpacity();
994 state->getFillRGB(&rgb);
996 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
997 (char)(rgb.b*255), (char)(opaq*255));
1000 void SWFOutputDev::updateStrokeColor(GfxState *state)
1003 double opaq = state->getStrokeOpacity();
1004 state->getStrokeRGB(&rgb);
1006 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
1007 (char)(rgb.b*255), (char)(opaq*255));
1010 void FoFiWrite(void *stream, char *data, int len)
1012 fwrite(data, len, 1, (FILE*)stream);
1015 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
1017 char*tmpFileName = NULL;
1023 Object refObj, strObj;
1025 tmpFileName = mktmpname(namebuf);
1028 ret = font->getEmbeddedFontID(&embRef);
1030 msg("<verbose> Didn't get embedded font id");
1031 /* not embedded- the caller should now search the font
1032 directories for this font */
1036 f = fopen(tmpFileName, "wb");
1038 msg("<error> Couldn't create temporary Type 1 font file");
1042 /*if(font->isCIDFont()) {
1043 GfxCIDFont* cidFont = (GfxCIDFont *)font;
1044 GString c = cidFont->getCollection();
1045 msg("<notice> Collection: %s", c.getCString());
1048 if (font->getType() == fontType1C ||
1049 font->getType() == fontCIDType0C) {
1050 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1052 msg("<error> Couldn't read embedded font file");
1056 Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
1057 cvt->convertToType1(f);
1059 FoFiType1C *cvt = FoFiType1C::make(fontBuf, fontLen);
1060 cvt->convertToType1(NULL, gTrue, FoFiWrite, f);
1062 //cvt->convertToCIDType0("test", f);
1063 //cvt->convertToType0("test", f);
1066 } else if(font->getType() == fontTrueType) {
1067 msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
1068 if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
1070 msg("<error> Couldn't read embedded font file");
1074 TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
1077 FoFiTrueType *cvt = FoFiTrueType::make(fontBuf, fontLen);
1078 cvt->writeTTF(FoFiWrite, f);
1083 font->getEmbeddedFontID(&embRef);
1084 refObj.initRef(embRef.num, embRef.gen);
1085 refObj.fetch(ref, &strObj);
1087 strObj.streamReset();
1092 f4[t] = strObj.streamGetChar();
1093 f4c[t] = (char)f4[t];
1098 if(!strncmp(f4c, "true", 4)) {
1099 /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
1100 Change this on the fly */
1101 f4[0] = f4[2] = f4[3] = 0;
1109 while ((c = strObj.streamGetChar()) != EOF) {
1113 strObj.streamClose();
1118 return strdup(tmpFileName);
1122 char* substitutetarget[256];
1123 char* substitutesource[256];
1124 int substitutepos = 0;
1126 char* searchForSuitableFont(GfxFont*gfxFont)
1128 char*name = getFontName(gfxFont);
1132 #ifdef HAVE_FONTCONFIG
1133 FcPattern *pattern, *match;
1137 // call init ony once
1138 static int fcinitcalled = false;
1139 if (!fcinitcalled) {
1140 fcinitcalled = true;
1144 pattern = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, name, NULL);
1145 if (gfxFont->isItalic()) // check for italic
1146 FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1147 if (gfxFont->isBold()) // check for bold
1148 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1150 // configure and match using the original font name
1151 FcConfigSubstitute(0, pattern, FcMatchPattern);
1152 FcDefaultSubstitute(pattern);
1153 match = FcFontMatch(0, pattern, &result);
1155 if (FcPatternGetString(match, "family", 0, &v) == FcResultMatch) {
1156 // if we get an exact match
1157 if (strcmp((char *)v, name) == 0) {
1158 if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
1159 filename = strdup((char*)v);
1160 char *nfn = strrchr(filename, '/');
1161 if(nfn) fontname = strdup(nfn+1);
1162 else fontname = filename;
1165 // initialize patterns
1166 FcPatternDestroy(pattern);
1167 FcPatternDestroy(match);
1169 // now match against serif etc.
1170 if (gfxFont->isSerif()) {
1171 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "serif", NULL);
1172 } else if (gfxFont->isFixedWidth()) {
1173 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "monospace", NULL);
1175 pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "sans", NULL);
1179 if (gfxFont->isItalic()) {
1180 int bb = FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1183 if (gfxFont->isBold()) {
1184 int bb = FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1187 // configure and match using serif etc
1188 FcConfigSubstitute (0, pattern, FcMatchPattern);
1189 FcDefaultSubstitute (pattern);
1190 match = FcFontMatch (0, pattern, &result);
1192 if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
1193 filename = strdup((char*)v);
1194 char *nfn = strrchr(filename, '/');
1195 if(nfn) fontname = strdup(nfn+1);
1196 else fontname = filename;
1201 //printf("FONTCONFIG: pattern");
1202 //FcPatternPrint(pattern);
1203 //printf("FONTCONFIG: match");
1204 //FcPatternPrint(match);
1206 FcPatternDestroy(pattern);
1207 FcPatternDestroy(match);
1209 pdfswf_addfont(filename);
1216 char* SWFOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
1218 char*fontname = 0, *filename = 0;
1219 msg("<notice> subsituteFont(%s)", oldname);
1221 if(!(fontname = searchForSuitableFont(gfxFont))) {
1222 fontname = "Times-Roman";
1224 filename = searchFont(fontname);
1226 if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
1227 msg("<fatal> Too many fonts in file.");
1231 substitutesource[substitutepos] = oldname;
1232 substitutetarget[substitutepos] = fontname;
1233 msg("<notice> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
1239 void unlinkfont(char* filename)
1246 if(!strncmp(&filename[l-4],".afm",4)) {
1247 memcpy(&filename[l-4],".pfb",4);
1249 memcpy(&filename[l-4],".pfa",4);
1251 memcpy(&filename[l-4],".afm",4);
1254 if(!strncmp(&filename[l-4],".pfa",4)) {
1255 memcpy(&filename[l-4],".afm",4);
1257 memcpy(&filename[l-4],".pfa",4);
1260 if(!strncmp(&filename[l-4],".pfb",4)) {
1261 memcpy(&filename[l-4],".afm",4);
1263 memcpy(&filename[l-4],".pfb",4);
1268 void SWFOutputDev::startDoc(XRef *xref)
1274 void SWFOutputDev::updateFont(GfxState *state)
1276 GfxFont*gfxFont = state->getFont();
1281 char * fontid = getFontID(gfxFont);
1284 /* first, look if we substituted this font before-
1285 this way, we don't initialize the T1 Fonts
1287 for(t=0;t<substitutepos;t++) {
1288 if(!strcmp(fontid, substitutesource[t])) {
1289 fontid = substitutetarget[t];
1294 /* second, see if swfoutput already has this font
1295 cached- if so, we are done */
1296 if(swfoutput_queryfont(&output, fontid))
1298 swfoutput_setfont(&output, fontid, 0);
1300 msg("<debug> updateFont(%s) [cached]", fontid);
1304 // look for Type 3 font
1305 if (gfxFont->getType() == fontType3) {
1307 type3Warning = gTrue;
1308 showFontError(gfxFont, 2);
1313 /* now either load the font, or find a substitution */
1316 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
1321 (gfxFont->getType() == fontType1 ||
1322 gfxFont->getType() == fontType1C ||
1323 //gfxFont->getType() == fontCIDType0C ||
1324 gfxFont->getType() == fontTrueType ||
1325 gfxFont->getType() == fontCIDType2
1328 fileName = writeEmbeddedFontToFile(xref, gfxFont);
1329 if(!fileName) showFontError(gfxFont,0);
1332 char * fontname = getFontName(gfxFont);
1333 fileName = searchFont(fontname);
1334 if(!fileName) showFontError(gfxFont,0);
1337 char * fontname = getFontName(gfxFont);
1338 msg("<warning> Font %s %scould not be loaded.", fontname, embedded?"":"(not embedded) ");
1339 msg("<warning> Try putting a TTF version of that font (named \"%s.ttf\") into /swftools/fonts", fontname);
1340 fileName = substituteFont(gfxFont, fontid);
1341 if(fontid) { fontid = substitutetarget[substitutepos-1]; /*ugly hack*/};
1342 msg("<notice> Font is now %s (%s)", fontid, fileName);
1346 msg("<error> Couldn't set font %s\n", fontid);
1350 msg("<verbose> updateFont(%s) -> %s", fontid, fileName);
1351 dumpFontInfo("<verbose>", gfxFont);
1353 swfoutput_setfont(&output, fontid, fileName);
1356 unlinkfont(fileName);
1362 int pic_width[1024];
1363 int pic_height[1024];
1367 #define SQR(x) ((x)*(x))
1369 unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize)
1371 if((newwidth<2 || newheight<2) ||
1372 (width<=newwidth || height<=newheight))
1374 unsigned char*newdata;
1376 newdata= (unsigned char*)malloc(newwidth*newheight);
1378 double fx = (double)(width)/newwidth;
1379 double fy = (double)(height)/newheight;
1381 int blocksize = (int)(8192/(fx*fy));
1382 int r = 8192*256/palettesize;
1383 for(x=0;x<newwidth;x++) {
1384 double ex = px + fx;
1385 int fromx = (int)px;
1387 int xweight1 = (int)(((fromx+1)-px)*256);
1388 int xweight2 = (int)((ex-tox)*256);
1390 for(y=0;y<newheight;y++) {
1391 double ey = py + fy;
1392 int fromy = (int)py;
1394 int yweight1 = (int)(((fromy+1)-py)*256);
1395 int yweight2 = (int)((ey-toy)*256);
1398 for(xx=fromx;xx<=tox;xx++)
1399 for(yy=fromy;yy<=toy;yy++) {
1400 int b = 1-data[width*yy+xx];
1402 if(xx==fromx) weight = (weight*xweight1)/256;
1403 if(xx==tox) weight = (weight*xweight2)/256;
1404 if(yy==fromy) weight = (weight*yweight1)/256;
1405 if(yy==toy) weight = (weight*yweight2)/256;
1408 //if(a) a=(palettesize-1)*r/blocksize;
1409 newdata[y*newwidth+x] = (a*blocksize)/r;
1417 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
1418 int width, int height, GfxImageColorMap*colorMap, GBool invert,
1419 GBool inlineImg, int mask)
1424 double x1,y1,x2,y2,x3,y3,x4,y4;
1425 ImageStream *imgStr;
1432 ncomps = colorMap->getNumPixelComps();
1433 bits = colorMap->getBits();
1435 imgStr = new ImageStream(str, width, ncomps,bits);
1438 if(!width || !height || (height<=1 && width<=1))
1440 msg("<verbose> Ignoring %d by %d image", width, height);
1441 unsigned char buf[8];
1443 for (y = 0; y < height; ++y)
1444 for (x = 0; x < width; ++x) {
1445 imgStr->getPixel(buf);
1451 state->transform(0, 1, &x1, &y1);
1452 state->transform(0, 0, &x2, &y2);
1453 state->transform(1, 0, &x3, &y3);
1454 state->transform(1, 1, &x4, &y4);
1456 if(!pbminfo && !(str->getKind()==strDCT)) {
1458 msg("<notice> file contains pbm pictures %s",mask?"(masked)":"");
1462 msg("<verbose> drawing %d by %d masked picture\n", width, height);
1464 if(!jpeginfo && (str->getKind()==strDCT)) {
1465 msg("<notice> file contains jpeg pictures");
1471 unsigned char buf[8];
1475 unsigned char*pic = new unsigned char[width*height];
1478 state->getFillRGB(&rgb);
1479 memset(pal,255,sizeof(pal));
1480 pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255);
1481 pal[0].b = (int)(rgb.b*255); pal[0].a = 255;
1482 pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0;
1484 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1485 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1486 int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3));
1487 int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2));
1488 for (y = 0; y < height; ++y)
1489 for (x = 0; x < width; ++x)
1491 imgStr->getPixel(buf);
1494 pic[width*y+x] = buf[0];
1499 /* the size of the drawn image is added to the identifier
1500 as the same image may require different bitmaps if displayed
1501 at different sizes (due to antialiasing): */
1507 for(t=0;t<picpos;t++)
1509 if(pic_xids[t] == xid &&
1510 pic_yids[t] == yid) {
1511 /* if the image was antialiased, the size has changed: */
1512 width = pic_width[t];
1513 height = pic_height[t];
1520 unsigned char*pic2 = 0;
1522 pic2 = antialize(pic,width,height,realwidth,realheight, numpalette);
1526 height = realheight;
1529 /* make a black/white palette */
1536 float r = 255/(numpalette-1);
1537 for(t=0;t<numpalette;t++) {
1538 /*pal[t].r = (U8)(t*r*rgb.r+(numpalette-1-t)*r*rgb2.r);
1539 pal[t].g = (U8)(t*r*rgb.g+(numpalette-1-t)*r*rgb2.g);
1540 pal[t].b = (U8)(t*r*rgb.b+(numpalette-1-t)*r*rgb2.b);
1542 pal[t].r = (U8)(255*rgb.r);
1543 pal[t].g = (U8)(255*rgb.g);
1544 pal[t].b = (U8)(255*rgb.b);
1545 pal[t].a = (U8)(t*r);
1549 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1550 x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1551 pic_xids[picpos] = xid;
1552 pic_yids[picpos] = yid;
1553 pic_width[picpos] = width;
1554 pic_height[picpos] = height;
1558 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1559 x1,y1,x2,y2,x3,y3,x4,y4);
1568 if(colorMap->getNumPixelComps()!=1 || str->getKind()==strDCT)
1570 RGBA*pic=new RGBA[width*height];
1573 for (y = 0; y < height; ++y) {
1574 for (x = 0; x < width; ++x) {
1576 imgStr->getPixel(pixBuf);
1577 colorMap->getRGB(pixBuf, &rgb);
1578 pic[width*y+x].r = r = (U8)(rgb.r * 255 + 0.5);
1579 pic[width*y+x].g = g = (U8)(rgb.g * 255 + 0.5);
1580 pic[width*y+x].b = b = (U8)(rgb.b * 255 + 0.5);
1581 pic[width*y+x].a = a = 255;//(U8)(rgb.a * 255 + 0.5);
1582 xid += x*r+x*b*3+x*g*7+x*a*11;
1583 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1587 for(t=0;t<picpos;t++)
1589 if(pic_xids[t] == xid &&
1590 pic_yids[t] == yid) {
1595 if(str->getKind()==strDCT)
1596 pic_ids[picpos] = swfoutput_drawimagejpeg(&output, pic, width, height,
1597 x1,y1,x2,y2,x3,y3,x4,y4);
1599 pic_ids[picpos] = swfoutput_drawimagelossless(&output, pic, width, height,
1600 x1,y1,x2,y2,x3,y3,x4,y4);
1601 pic_xids[picpos] = xid;
1602 pic_yids[picpos] = yid;
1603 pic_width[picpos] = width;
1604 pic_height[picpos] = height;
1608 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1609 x1,y1,x2,y2,x3,y3,x4,y4);
1617 U8*pic = new U8[width*height];
1625 colorMap->getRGB(pixBuf, &rgb);
1626 pal[t].r = r = (U8)(rgb.r * 255 + 0.5);
1627 pal[t].g = g = (U8)(rgb.g * 255 + 0.5);
1628 pal[t].b = b = (U8)(rgb.b * 255 + 0.5);
1629 pal[t].a = a = 255;//(U8)(rgb.b * 255 + 0.5);
1630 xid += t*r+t*b*3+t*g*7+t*a*11;
1631 xid += (~t)*r+t*b*3+t*g*7+t*a*11;
1633 for (y = 0; y < height; ++y) {
1634 for (x = 0; x < width; ++x) {
1635 imgStr->getPixel(pixBuf);
1636 pic[width*y+x] = pixBuf[0];
1637 xid += x*pixBuf[0]*7;
1638 yid += y*pixBuf[0]*3;
1642 for(t=0;t<picpos;t++)
1644 if(pic_xids[t] == xid &&
1645 pic_yids[t] == yid) {
1650 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height,
1651 x1,y1,x2,y2,x3,y3,x4,y4,256);
1652 pic_xids[picpos] = xid;
1653 pic_yids[picpos] = yid;
1654 pic_width[picpos] = width;
1655 pic_height[picpos] = height;
1659 swfoutput_drawimageagain(&output, pic_ids[found], width, height,
1660 x1,y1,x2,y2,x3,y3,x4,y4);
1668 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1669 int width, int height, GBool invert,
1672 msg("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
1673 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
1676 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1677 int width, int height, GfxImageColorMap *colorMap,
1678 int *maskColors, GBool inlineImg)
1680 msg("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
1681 colorMap?"colorMap":"no colorMap",
1682 maskColors?"maskColors":"no maskColors",
1685 msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
1686 colorMap->getBits(),colorMap->getColorSpace()->getMode());
1687 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1690 SWFOutputDev*output = 0;
1692 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
1697 if (infoDict->lookup(key, &obj)->isString()) {
1698 s1 = obj.getString();
1699 if ((s1->getChar(0) & 0xff) == 0xfe &&
1700 (s1->getChar(1) & 0xff) == 0xff) {
1702 for (i = 2; i < obj.getString()->getLength(); i += 2) {
1703 if (s1->getChar(i) == '\0') {
1704 s2->append(s1->getChar(i+1));
1707 s2 = new GString("<unicode>");
1711 printf(fmt, s2->getCString());
1714 printf(fmt, s1->getCString());
1720 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
1724 if (infoDict->lookup(key, &obj)->isString()) {
1725 s = obj.getString()->getCString();
1726 if (s[0] == 'D' && s[1] == ':') {
1734 void pdfswf_init(char*filename, char*userPassword)
1736 GString *fileName = new GString(filename);
1741 globalParams = new GlobalParams("");
1744 if (userPassword && userPassword[0]) {
1745 userPW = new GString(userPassword);
1749 doc = new PDFDoc(fileName, userPW);
1758 doc->getDocInfo(&info);
1759 if (info.isDict() &&
1760 (screenloglevel>=LOGLEVEL_NOTICE)) {
1761 printInfoString(info.getDict(), "Title", "Title: %s\n");
1762 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1763 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1764 printInfoString(info.getDict(), "Author", "Author: %s\n");
1765 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1766 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1767 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1768 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1769 printf("Pages: %d\n", doc->getNumPages());
1770 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1771 printf("Encrypted: ");
1772 if (doc->isEncrypted()) {
1773 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1774 doc->okToPrint() ? "yes" : "no",
1775 doc->okToCopy() ? "yes" : "no",
1776 doc->okToChange() ? "yes" : "no",
1777 doc->okToAddNotes() ? "yes" : "no");
1784 numpages = doc->getNumPages();
1785 if (doc->isEncrypted()) {
1786 if(!doc->okToCopy()) {
1787 printf("PDF disallows copying. Bailing out.\n");
1790 if(!doc->okToChange() || !doc->okToAddNotes())
1791 swfoutput_setprotected();
1794 output = new SWFOutputDev();
1795 output->startDoc(doc->getXRef());
1798 void pdfswf_setparameter(char*name, char*value)
1800 if(!strcmp(name, "outputfilename")) {
1801 swffilename = value;
1802 } else if(!strcmp(name, "caplinewidth")) {
1803 caplinewidth = atof(value);
1804 } else if(!strcmp(name, "zoom")) {
1807 swfoutput_setparameter(name, value);
1811 void pdfswf_addfont(char*filename)
1814 memset(&f, 0, sizeof(fontfile_t));
1815 f.filename = filename;
1816 fonts[fontnum++] = f;
1819 void pdfswf_setoutputfilename(char*_filename) { swffilename = _filename; }
1821 void pdfswf_convertpage(int page)
1825 pages = (int*)malloc(1024*sizeof(int));
1828 if(pagepos == pagebuflen)
1831 pages = (int*)realloc(pages, pagebuflen);
1834 pages[pagepos++] = page;
1837 void pdfswf_performconversion()
1840 for(t=0;t<pagepos;t++)
1842 currentpage = pages[t];
1844 doc->displayPage((OutputDev*)output, currentpage, /*zoom*/zoom, /*rotate*/0, /*doLinks*/(int)1);
1846 doc->displayPage((OutputDev*)output, currentpage, zoom, zoom, /*rotate*/0, true, /*doLinks*/(int)1);
1850 int pdfswf_numpages()
1852 return doc->getNumPages();
1857 msg("<debug> pdfswf.cc: pdfswf_close()");
1861 // check for memory leaks
1862 Object::memCheck(stderr);