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 */
39 #include "OutputDev.h"
43 //swftools header files
44 #include "swfoutput.h"
46 #include "../lib/log.h"
49 static char* swffilename = 0;
51 static void printInfoString(Dict *infoDict, char *key, char *fmt);
52 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
54 static char userPassword[33] = "";
55 static GBool printVersion = gFalse;
56 static GBool printHelp = gFalse;
60 0.833,0.833,0.889,0.889,0.788,0.722,0.833,0.778,0.600,0.600,0.600,0.600,0.576,0.576,0.576,0.576
65 "Helvetica-BoldOblique",
73 "Courier-BoldOblique",
87 {"Times-Roman", "n021003l.pfb"},
88 {"Times-Italic", "n021023l.pfb"},
89 {"Times-Bold", "n021004l.pfb"},
90 {"Times-BoldItalic", "n021024l.pfb"},
91 {"Helvetica", "n019003l.pfb"},
92 {"Helvetica-Oblique", "n019023l.pfb"},
93 {"Helvetica-Bold", "n019004l.pfb"},
94 {"Helvetica-BoldOblique", "n019024l.pfb"},
95 {"Courier", "n022003l.pfb"},
96 {"Courier-Oblique", "n022023l.pfb"},
97 {"Courier-Bold", "n022004l.pfb"},
98 {"Courier-BoldOblique", "n022024l.pfb"},
99 {"Symbol", "s050000l.pfb"},
100 {"ZapfDingbats", "d050000l.pfb"}};
102 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
107 if (infoDict->lookup(key, &obj)->isString()) {
108 s1 = obj.getString();
109 if ((s1->getChar(0) & 0xff) == 0xfe &&
110 (s1->getChar(1) & 0xff) == 0xff) {
112 for (i = 2; i < obj.getString()->getLength(); i += 2) {
113 if (s1->getChar(i) == '\0') {
114 s2->append(s1->getChar(i+1));
117 s2 = new GString("<unicode>");
121 printf(fmt, s2->getCString());
124 printf(fmt, s1->getCString());
130 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
134 if (infoDict->lookup(key, &obj)->isString()) {
135 s = obj.getString()->getCString();
136 if (s[0] == 'D' && s[1] == ':') {
145 class GfxImageColorMap;
147 class SWFOutputDev: public OutputDev {
148 struct swfoutput output;
156 virtual ~SWFOutputDev() ;
158 //----- get info about output device
160 // Does this device use upside-down coordinates?
161 // (Upside-down means (0,0) is the top left corner of the page.)
162 virtual GBool upsideDown();
164 // Does this device use drawChar() or drawString()?
165 virtual GBool useDrawChar();
167 //----- initialization and control
170 virtual void startPage(int pageNum, GfxState *state) ;
173 virtual void drawLink(Link *link, Catalog *catalog) ;
175 //----- save/restore graphics state
176 virtual void saveState(GfxState *state) ;
177 virtual void restoreState(GfxState *state) ;
179 //----- update graphics state
181 virtual void updateFont(GfxState *state);
182 virtual void updateFillColor(GfxState *state);
183 virtual void updateStrokeColor(GfxState *state);
184 virtual void updateLineWidth(GfxState *state);
186 virtual void updateAll(GfxState *state)
189 updateFillColor(state);
190 updateStrokeColor(state);
191 updateLineWidth(state);
194 //----- path painting
195 virtual void stroke(GfxState *state) ;
196 virtual void fill(GfxState *state) ;
197 virtual void eoFill(GfxState *state) ;
199 //----- path clipping
200 virtual void clip(GfxState *state) ;
201 virtual void eoClip(GfxState *state) ;
204 virtual void beginString(GfxState *state, GString *s) ;
205 virtual void endString(GfxState *state) ;
206 virtual void drawChar(GfxState *state, double x, double y,
207 double dx, double dy, Guchar c) ;
208 virtual void drawChar16(GfxState *state, double x, double y,
209 double dx, double dy, int c) ;
211 //----- image drawing
212 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
213 int width, int height, GBool invert,
215 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
216 int width, int height, GfxImageColorMap *colorMap,
220 void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
221 int width, int height, GfxImageColorMap*colorMap, GBool invert,
222 GBool inlineImg, int mask);
226 int setT1Font(char*name,FontEncoding*enc);
228 int jpeginfo; // did we write "Page contains jpegs" yet?
229 int pbminfo; // did we write "Page contains jpegs" yet?
233 char* gfxstate2str(GfxState *state)
237 bufpos+=sprintf(bufpos,"CTM[%.3f/%.3f/%.3f/%.3f/%.3f/%.3f] ",
244 if(state->getX1()!=0.0)
245 bufpos+=sprintf(bufpos,"X1-%.1f ",state->getX1());
246 if(state->getY1()!=0.0)
247 bufpos+=sprintf(bufpos,"Y1-%.1f ",state->getY1());
248 bufpos+=sprintf(bufpos,"X2-%.1f ",state->getX2());
249 bufpos+=sprintf(bufpos,"Y2-%.1f ",state->getY2());
250 bufpos+=sprintf(bufpos,"PW%.1f ",state->getPageWidth());
251 bufpos+=sprintf(bufpos,"PH%.1f ",state->getPageHeight());
252 /*bufpos+=sprintf(bufpos,"FC[%.1f/%.1f] ",
253 state->getFillColor()->c[0], state->getFillColor()->c[1]);
254 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f] ",
255 state->getStrokeColor()->c[0], state->getFillColor()->c[1]);*/
256 /* bufpos+=sprintf(bufpos,"FC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
257 state->getFillColor()->c[0], state->getFillColor()->c[1],
258 state->getFillColor()->c[2], state->getFillColor()->c[3],
259 state->getFillColor()->c[4], state->getFillColor()->c[5],
260 state->getFillColor()->c[6], state->getFillColor()->c[7]);
261 bufpos+=sprintf(bufpos,"SC[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f/%.1f]",
262 state->getStrokeColor()->c[0], state->getFillColor()->c[1],
263 state->getStrokeColor()->c[2], state->getFillColor()->c[3],
264 state->getStrokeColor()->c[4], state->getFillColor()->c[5],
265 state->getStrokeColor()->c[6], state->getFillColor()->c[7]);*/
266 state->getFillRGB(&rgb);
267 if(rgb.r || rgb.g || rgb.b)
268 bufpos+=sprintf(bufpos,"FR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
269 state->getStrokeRGB(&rgb);
270 if(rgb.r || rgb.g || rgb.b)
271 bufpos+=sprintf(bufpos,"SR[%.1f/%.1f/%.1f] ", rgb.r,rgb.g,rgb.b);
272 if(state->getFillColorSpace()->getNComps()>1)
273 bufpos+=sprintf(bufpos,"CS[[%d]] ",state->getFillColorSpace()->getNComps());
274 if(state->getStrokeColorSpace()->getNComps()>1)
275 bufpos+=sprintf(bufpos,"SS[[%d]] ",state->getStrokeColorSpace()->getNComps());
276 if(state->getFillPattern())
277 bufpos+=sprintf(bufpos,"FP%08x ", state->getFillPattern());
278 if(state->getStrokePattern())
279 bufpos+=sprintf(bufpos,"SP%08x ", state->getStrokePattern());
281 if(state->getFillOpacity()!=1.0)
282 bufpos+=sprintf(bufpos,"FO%.1f ", state->getFillOpacity());
283 if(state->getStrokeOpacity()!=1.0)
284 bufpos+=sprintf(bufpos,"SO%.1f ", state->getStrokeOpacity());
286 bufpos+=sprintf(bufpos,"LW%.1f ", state->getLineWidth());
291 state->getLineDash(&dash, &length, &start);
295 bufpos+=sprintf(bufpos,"DASH%.1f[",start);
296 for(t=0;t<length;t++) {
297 bufpos+=sprintf(bufpos,"D%.1f",dash[t]);
299 bufpos+=sprintf(bufpos,"]");
302 if(state->getFlatness()!=1)
303 bufpos+=sprintf(bufpos,"F%d ", state->getFlatness());
304 if(state->getLineJoin()!=0)
305 bufpos+=sprintf(bufpos,"J%d ", state->getLineJoin());
306 if(state->getLineJoin()!=0)
307 bufpos+=sprintf(bufpos,"C%d ", state->getLineCap());
308 if(state->getLineJoin()!=0)
309 bufpos+=sprintf(bufpos,"ML%d ", state->getMiterLimit());
311 if(state->getFont() && state->getFont()->getName() && state->getFont()->getName()->getCString())
312 bufpos+=sprintf(bufpos,"F\"%s\" ",((state->getFont())->getName())->getCString());
313 bufpos+=sprintf(bufpos,"FS%.1f ", state->getFontSize());
314 bufpos+=sprintf(bufpos,"MAT[%.1f/%.1f/%.1f/%.1f/%.1f/%.1f] ", state->getTextMat()[0],state->getTextMat()[1],state->getTextMat()[2],
315 state->getTextMat()[3],state->getTextMat()[4],state->getTextMat()[5]);
316 if(state->getCharSpace())
317 bufpos+=sprintf(bufpos,"CS%.5f ", state->getCharSpace());
318 if(state->getWordSpace())
319 bufpos+=sprintf(bufpos,"WS%.5f ", state->getWordSpace());
320 if(state->getHorizScaling()!=1.0)
321 bufpos+=sprintf(bufpos,"SC%.1f ", state->getHorizScaling());
322 if(state->getLeading())
323 bufpos+=sprintf(bufpos,"L%.1f ", state->getLeading());
325 bufpos+=sprintf(bufpos,"R%.1f ", state->getRise());
326 if(state->getRender())
327 bufpos+=sprintf(bufpos,"R%d ", state->getRender());
328 bufpos+=sprintf(bufpos,"P%08x ", state->getPath());
329 bufpos+=sprintf(bufpos,"CX%.1f ", state->getCurX());
330 bufpos+=sprintf(bufpos,"CY%.1f ", state->getCurY());
331 if(state->getLineX())
332 bufpos+=sprintf(bufpos,"LX%.1f ", state->getLineX());
333 if(state->getLineY())
334 bufpos+=sprintf(bufpos,"LY%.1f ", state->getLineY());
335 bufpos+=sprintf(bufpos," ");
339 void dumpFontInfo(char*loglevel, GfxFont*font);
346 void showFontError(GfxFont*font, int nr)
350 for(t=0;t<lastdumppos;t++)
351 if(lastdumps[t] == r.num)
355 if(lastdumppos<sizeof(lastdumps)/sizeof(int))
356 lastdumps[lastdumppos++] = r.num;
358 logf("<error> The following font caused problems:");
360 logf("<error> The following font caused problems (substituting):");
362 logf("<error> This document contains Type 3 Fonts: (some text may be incorrectly displayed)");
364 dumpFontInfo("<error>", font);
367 void dumpFontInfo(char*loglevel, GfxFont*font)
371 gstr = font->getName();
373 logf("%s=========== %s (ID:%d,%d) ==========\n", loglevel, gstr?gstr->getCString():"(unknown font)", r.num,r.gen);
375 gstr = font->getTag();
377 logf("%sTag: %s\n", loglevel, gstr->getCString());
378 if(font->is16Bit()) logf("%sis 16 bit\n", loglevel);
380 GfxFontType type=font->getType();
382 case fontUnknownType:
383 logf("%sType: unknown\n",loglevel);
386 logf("%sType: 0\n",loglevel);
389 logf("%sType: 1\n",loglevel);
392 logf("%sType: 1C\n",loglevel);
395 logf("%sType: 3\n",loglevel);
398 logf("%sType: TrueType\n",loglevel);
403 GBool embedded = font->getEmbeddedFontID(&embRef);
404 name = font->getEmbeddedFontName();
406 logf("%sEmbedded name: %s id: %d\n",loglevel, name, embRef.num);
408 gstr = font->getExtFontFile();
410 logf("%sExternal Font file: %s\n", loglevel, gstr->getCString());
412 // Get font descriptor flags.
413 if(font->isFixedWidth()) logf("%sis fixed width\n", loglevel);
414 if(font->isSerif()) logf("%sis serif\n", loglevel);
415 if(font->isSymbolic()) logf("%sis symbolic\n", loglevel);
416 if(font->isItalic()) logf("%sis italic\n", loglevel);
417 if(font->isBold()) logf("%sis bold\n", loglevel);
420 //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");}
421 //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");}
423 SWFOutputDev::SWFOutputDev()
426 clipping[clippos] = 0;
428 // printf("SWFOutputDev::SWFOutputDev() \n");
431 T1_OUTLINE* gfxPath_to_T1_OUTLINE(GfxState*state, GfxPath*path)
433 int num = path->getNumSubpaths();
435 bezierpathsegment*start,*last;
436 bezierpathsegment*outline = start = new bezierpathsegment();
438 double lastx=0,lasty=0;
439 for(t = 0; t < num; t++) {
440 GfxSubpath *subpath = path->getSubpath(t);
441 int subnum = subpath->getNumPoints();
443 for(s=0;s<subnum;s++) {
445 state->transform(subpath->getX(s),subpath->getY(s),&nx,&ny);
446 int x = (int)((nx-lastx)*0xffff);
447 int y = (int)((ny-lasty)*0xffff);
451 outline->type = T1_PATHTYPE_MOVE;
454 outline->link = (T1_OUTLINE*)new bezierpathsegment();
455 outline = (bezierpathsegment*)outline->link;
460 else if(subpath->getCurve(s) && !cpos)
466 else if(subpath->getCurve(s) && cpos)
477 outline->type = cpos?T1_PATHTYPE_BEZIER:T1_PATHTYPE_LINE;
479 outline->link = (T1_OUTLINE*)new bezierpathsegment();
480 outline = (bezierpathsegment*)outline->link;
488 return (T1_OUTLINE*)start;
490 /*----------------------------------------------------------------------------
491 * Primitive Graphic routines
492 *----------------------------------------------------------------------------*/
494 void SWFOutputDev::stroke(GfxState *state)
496 logf("<debug> stroke\n");
497 GfxPath * path = state->getPath();
499 m.m11 = 1; m.m21 = 0; m.m22 = 1;
500 m.m21 = 0; m.m13 = 0; m.m23 = 0;
501 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
502 swfoutput_setdrawmode(&output, DRAWMODE_STROKE);
503 swfoutput_drawpath(&output, outline, &m);
505 void SWFOutputDev::fill(GfxState *state)
507 logf("<debug> fill\n");
508 GfxPath * path = state->getPath();
510 m.m11 = 1; m.m21 = 0; m.m22 = 1;
511 m.m21 = 0; m.m13 = 0; m.m23 = 0;
512 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
513 swfoutput_setdrawmode(&output, DRAWMODE_FILL);
514 swfoutput_drawpath(&output, outline, &m);
516 void SWFOutputDev::eoFill(GfxState *state)
518 logf("<debug> eofill\n");
519 GfxPath * path = state->getPath();
521 m.m11 = 1; m.m21 = 0; m.m22 = 1;
522 m.m21 = 0; m.m13 = 0; m.m23 = 0;
523 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
524 swfoutput_setdrawmode(&output, DRAWMODE_EOFILL);
525 swfoutput_drawpath(&output, outline, &m);
527 void SWFOutputDev::clip(GfxState *state)
529 logf("<debug> clip\n");
530 GfxPath * path = state->getPath();
532 m.m11 = 1; m.m21 = 0; m.m22 = 1;
533 m.m21 = 0; m.m13 = 0; m.m23 = 0;
534 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
535 swfoutput_startclip(&output, outline, &m);
536 clipping[clippos] = 1;
538 void SWFOutputDev::eoClip(GfxState *state)
540 logf("<debug> eoclip\n");
541 GfxPath * path = state->getPath();
543 m.m11 = 1; m.m21 = 0; m.m22 = 1;
544 m.m21 = 0; m.m13 = 0; m.m23 = 0;
545 T1_OUTLINE*outline = gfxPath_to_T1_OUTLINE(state, path);
546 swfoutput_startclip(&output, outline, &m);
547 clipping[clippos] = 1;
550 SWFOutputDev::~SWFOutputDev()
552 swfoutput_destroy(&output);
555 GBool SWFOutputDev::upsideDown()
557 logf("<debug> upsidedown?");
560 GBool SWFOutputDev::useDrawChar()
562 logf("<debug> usedrawchar?");
566 void SWFOutputDev::beginString(GfxState *state, GString *s)
568 double m11,m21,m12,m22;
569 logf("<debug> beginstring \"%s\"\n", s->getCString());
570 state->getFontTransMat(&m11, &m12, &m21, &m22);
571 m11 *= state->getHorizScaling();
572 m21 *= state->getHorizScaling();
573 swfoutput_setfontmatrix(&output, m11, -m12, m21, -m22);
577 void SWFOutputDev::drawChar(GfxState *state, double x, double y, double dx, double dy, Guchar c)
579 logf("<debug> drawChar(%f,%f,%f,%f,'%c')\n",x,y,dx,dy,c);
580 // check for invisible text -- this is used by Acrobat Capture
581 if ((state->getRender() & 3) != 3)
583 FontEncoding*enc=state->getFont()->getEncoding();
588 state->transform(x, y, &x1, &y1);
590 swfoutput_drawchar(&output, x1, y1, enc->getCharName(c));
594 void SWFOutputDev::drawChar16(GfxState *state, double x, double y, double dx, double dy, int c)
596 printf("<error> drawChar16(%f,%f,%f,%f,%08x)\n",x,y,dx,dy,c);
600 void SWFOutputDev::endString(GfxState *state)
602 logf("<debug> endstring\n");
605 void SWFOutputDev::startPage(int pageNum, GfxState *state)
608 logf("<debug> startPage %d\n", pageNum);
609 logf("<notice> processing page %d", pageNum);
613 state->transform(state->getX1(),state->getY1(),&x1,&y1);
614 state->transform(state->getX2(),state->getY2(),&x2,&y2);
616 swfoutput_init(&output, swffilename, abs((int)(x2-x1)),abs((int)(y2-y1)));
620 swfoutput_newpage(&output);
623 void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
625 logf("<debug> drawlink\n");
626 double x1, y1, x2, y2, w;
631 link->getBorder(&x1, &y1, &x2, &y2, &w);
636 cvtUserToDev(x1, y1, &x, &y);
637 points[0].x = points[4].x = x;
638 points[0].y = points[4].y = y;
639 cvtUserToDev(x2, y1, &x, &y);
642 cvtUserToDev(x2, y2, &x, &y);
645 cvtUserToDev(x1, y2, &x, &y);
649 LinkAction*action=link->getAction();
651 switch(action->getKind())
654 LinkGoTo*l = (LinkGoTo*)action;
655 s = l->getNamedDest()->getCString();
659 LinkGoToR*l = (LinkGoToR*)action;
660 s = l->getNamedDest()->getCString();
664 LinkLaunch*l = (LinkLaunch*)action;
665 GString * str = new GString(l->getFileName());
666 str->append(l->getParams());
667 s = str->getCString();
671 LinkURI*l = (LinkURI*)action;
672 s = l->getURI()->getCString();
676 LinkNamed*l = (LinkNamed*)action;
677 s = l->getName()->getCString();
680 case actionUnknown: {
681 LinkUnknown*l = (LinkUnknown*)action;
686 logf("<verbose> link to \"%s\"\n", s);
690 void SWFOutputDev::saveState(GfxState *state) {
691 logf("<debug> saveState\n");
694 clipping[clippos] = 0;
697 void SWFOutputDev::restoreState(GfxState *state) {
698 logf("<debug> restoreState\n");
700 if(clipping[clippos])
701 swfoutput_endclip(&output);
707 int SWFOutputDev::setT1Font(char*name, FontEncoding*encoding)
714 for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
716 if(!strcmp(name, pdf2t1map[i].pdffont))
718 filename = pdf2t1map[i].filename;
723 for(i=0; i<T1_Get_no_fonts(); i++)
725 char*fontfilename = T1_GetFontFileName (i);
726 if(strstr(fontfilename, filename))
729 pdf2t1map[i].id = mapid;
738 void SWFOutputDev::updateLineWidth(GfxState *state)
740 double width = state->getLineWidth();
741 swfoutput_setlinewidth(&output, width);
744 void SWFOutputDev::updateFillColor(GfxState *state)
747 double opaq = state->getFillOpacity();
748 state->getFillRGB(&rgb);
750 swfoutput_setfillcolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
751 (char)(rgb.b*255), (char)(opaq*255));
754 void SWFOutputDev::updateStrokeColor(GfxState *state)
757 double opaq = state->getStrokeOpacity();
758 state->getStrokeRGB(&rgb);
760 swfoutput_setstrokecolor(&output, (char)(rgb.r*255), (char)(rgb.g*255),
761 (char)(rgb.b*255), (char)(opaq*255));
764 char*writeEmbeddedFontToFile(GfxFont*font)
766 char*tmpFileName = NULL;
767 char*fileName = NULL;
772 Type1CFontConverter *cvt;
774 Object refObj, strObj;
775 tmpFileName = "/tmp/tmpfont";
776 font->getEmbeddedFontID(&embRef);
778 f = fopen(tmpFileName, "wb");
780 logf("<error> Couldn't create temporary Type 1 font file");
783 if (font->getType() == fontType1C) {
784 if (!(fontBuf = font->readEmbFontFile(&fontLen))) {
786 logf("<error> Couldn't read embedded font file");
789 cvt = new Type1CFontConverter(fontBuf, fontLen, f);
794 font->getEmbeddedFontID(&embRef);
795 refObj.initRef(embRef.num, embRef.gen);
796 refObj.fetch(&strObj);
798 strObj.streamReset();
799 while ((c = strObj.streamGetChar()) != EOF) {
802 strObj.streamClose();
806 fileName = tmpFileName;
808 logf("<error> Embedded font writer didn't create a file");
814 char* gfxFontName(GfxFont* gfxFont)
817 gstr = gfxFont->getName();
819 return gstr->getCString();
823 Ref r=gfxFont->getID();
824 sprintf(buf, "UFONT%d", r.num);
829 void SWFOutputDev::updateFont(GfxState *state)
831 double m11, m12, m21, m22;
833 GfxFont*gfxFont = state->getFont();
840 if(swfoutput_queryfont(&output, gfxFontName(gfxFont)))
842 swfoutput_setfont(&output, gfxFontName(gfxFont), -1, 0);
846 // look for Type 3 font
847 if (!type3Warning && gfxFont->getType() == fontType3) {
848 type3Warning = gTrue;
849 showFontError(gfxFont, 2);
851 //dumpFontInfo ("<notice>", gfxFont);
854 GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
856 if (!gfxFont->is16Bit() &&
857 (gfxFont->getType() == fontType1 ||
858 gfxFont->getType() == fontType1C)) {
860 fileName = writeEmbeddedFontToFile(gfxFont);
865 showFontError(gfxFont,0);
869 t1id = T1_AddFont(fileName);
872 if(gfxFont->getName()) {
873 fontname = gfxFont->getName()->getCString();
874 //logf("<notice> Processing font %s", fontname);
876 if(!fontname || !setT1Font(state->getFont()->getName()->getCString(), gfxFont->getEncoding()))
883 showFontError(gfxFont, 1);
884 if (!gfxFont->is16Bit()) {
885 if (gfxFont->isFixedWidth()) {
887 } else if (gfxFont->isSerif()) {
892 if (gfxFont->isBold())
894 if (gfxFont->isItalic())
896 fontname = fontnames[index];
897 // get width of 'm' in real font and substituted font
898 if ((code = gfxFont->getCharCode("m")) >= 0)
899 w1 = gfxFont->getWidth(code);
902 w2 = fontsizes[index];
903 if (gfxFont->getType() == fontType3) {
904 // This is a hack which makes it possible to substitute for some
905 // Type 3 fonts. The problem is that it's impossible to know what
906 // the base coordinate system used in the font is without actually
907 // rendering the font. This code tries to guess by looking at the
908 // width of the character 'm' (which breaks if the font is a
909 // subset that doesn't contain 'm').
910 if (w1 > 0 && (w1 > 1.1 * w2 || w1 < 0.9 * w2)) {
917 fm = gfxFont->getFontMatrix();
918 v = (fm[0] == 0) ? 1 : (fm[3] / fm[0]);
921 } else if (!gfxFont->isSymbolic()) {
922 // if real font is substantially narrower than substituted
923 // font, reduce the font size accordingly
924 if (w1 > 0.01 && w1 < 0.9 * w2) {
937 setT1Font(fontname, gfxFont->getEncoding());
941 swfoutput_setfont(&output,gfxFontName(gfxFont),t1id, fileName);
946 void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
947 int width, int height, GfxImageColorMap*colorMap, GBool invert,
948 GBool inlineImg, int mask)
953 double x1,y1,x2,y2,x3,y3,x4,y4;
954 state->transform(0, 1, &x1, &y1);
955 state->transform(0, 0, &x2, &y2);
956 state->transform(1, 0, &x3, &y3);
957 state->transform(1, 1, &x4, &y4);
959 if (str->getKind() == strDCT &&
960 (colorMap->getNumPixelComps() == 3 || !mask) )
962 sprintf(fileName, "/tmp/tmp%08x.jpg",lrand48());
963 logf("<verbose> Found jpeg. Temporary storage is %s", fileName);
966 logf("<notice> Page contains jpeg pictures");
969 if (!(fi = fopen(fileName, "wb"))) {
970 logf("<error> Couldn't open temporary image file '%s'", fileName);
973 str = ((DCTStream *)str)->getRawStream();
975 while ((c = str->getChar()) != EOF)
978 swfoutput_drawimagefile(&output, fileName, width, height, x1,y1,x2,y2,x3,y3,x4,y4);
983 logf("<notice> Page contains pbm pictures");
989 void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
990 int width, int height, GBool invert,
993 drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1);
996 void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
997 int width, int height,
998 GfxImageColorMap *colorMap, GBool inlineImg)
1000 drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0);
1004 SWFOutputDev*output = 0;
1006 void pdfswf_init(char*filename, char*userPassword)
1008 GString *fileName = new GString(filename);
1015 initParams(xpdfConfigFile);
1019 if (userPassword && userPassword[0]) {
1020 userPW = new GString(userPassword);
1024 doc = new PDFDoc(fileName, userPW);
1033 doc->getDocInfo(&info);
1034 if (info.isDict()) {
1035 printInfoString(info.getDict(), "Title", "Title: %s\n");
1036 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
1037 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
1038 printInfoString(info.getDict(), "Author", "Author: %s\n");
1039 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
1040 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
1041 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
1042 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
1047 printf("Pages: %d\n", doc->getNumPages());
1049 // print linearization info
1050 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
1052 // print encryption info
1053 printf("Encrypted: ");
1054 if (doc->isEncrypted()) {
1055 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
1056 doc->okToPrint() ? "yes" : "no",
1057 doc->okToCopy() ? "yes" : "no",
1058 doc->okToChange() ? "yes" : "no",
1059 doc->okToAddNotes() ? "yes" : "no");
1060 /*ERROR: This pdf is encrypted, and disallows copying.
1061 Due to the DMCA, paragraph 1201, (2) A-C, circumventing
1062 a technological measure that efficively controls access to
1063 a protected work is violating American law.
1064 See www.eff.org for more information about DMCA issues.
1066 if(!doc->okToCopy()) {
1067 printf("PDF disallows copying. Bailing out.\n");
1070 if(!doc->okToChange() || !doc->okToAddNotes())
1071 swfoutput_setprotected();
1078 output = new SWFOutputDev();
1081 void pdfswf_drawonlyshapes()
1086 void pdfswf_ignoredraworder()
1088 ignoredraworder = 1;
1091 void pdfswf_jpegquality(int val)
1094 if(val>100) val=100;
1098 void pdfswf_setoutputfilename(char*_filename)
1100 swffilename = _filename;
1103 void pdfswf_convertpage(int page)
1105 doc->displayPage((OutputDev*)output, page, /*zoom*/100, /*rotate*/0, /*doLinks*/(int)1);
1108 int pdfswf_numpages()
1110 return doc->getNumPages();
1116 logf("<debug> pdfswf.cc: pdfswf_close()");
1120 // check for memory leaks
1121 Object::memCheck(stderr);