2247f5fdd005ad4948b940d9851cb1da90176254
[swftools.git] / lib / pdf / xpdf-changes.patch
1 Index: Gfx.cc
2 ===================================================================
3 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/Gfx.cc,v
4 retrieving revision 1.9
5 retrieving revision 1.10
6 diff -u -r1.9 -r1.10
7 --- Gfx.cc      3 Dec 2005 10:11:33 -0000       1.9
8 +++ Gfx.cc      3 Dec 2005 10:30:41 -0000       1.10
9 @@ -439,7 +439,11 @@
10    fontChanged = gFalse;
11    clip = clipNone;
12    ignoreUndef = 0;
13 -  out->startPage(pageNum, state);
14 +  if(cropBox) {
15 +      out->startPage(pageNum, state, cropBox->x1,cropBox->y1,cropBox->x2,cropBox->y2);
16 +  } else {
17 +      out->startPage(pageNum, state, 0,0,0,0);
18 +  }
19    out->setDefaultCTM(state->getCTM());
20    out->updateAll(state);
21    for (i = 0; i < 6; ++i) {
22 @@ -450,7 +450,8 @@
23    abortCheckCbkData = abortCheckCbkDataA;
24  
25    // set crop box
26 -  if (cropBox) {
27 +#ifdef XPDFEXE
28 +  if (cropBox) {
29      state->moveTo(cropBox->x1, cropBox->y1);
30      state->lineTo(cropBox->x2, cropBox->y1);
31      state->lineTo(cropBox->x2, cropBox->y2);
32 @@ -459,7 +460,8 @@
33      state->clip();
34      out->clip(state);
35      state->clearPath();
36 -  }
37 +  }
38 +#endif
39  }
40  
41  Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
42 @@ -3783,6 +3789,7 @@
43    pushResources(resDict);
44  
45    // save current graphics state
46 +  GfxState*mystate = state;
47    saveState();
48  
49    // kill any pre-existing path
50 @@ -3848,6 +3855,9 @@
51  
52    // restore graphics state
53    restoreState();
54 +  if(state!=mystate) {
55 +      fprintf(stderr, "Invalid state nesting in PDF file- file broken?\n");
56 +  }
57  
58    // pop resource stack
59    popResources();
60 Index: GfxFont.h
61 ===================================================================
62 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/GfxFont.h,v
63 retrieving revision 1.6
64 retrieving revision 1.7
65 diff -u -r1.6 -r1.7
66 --- GfxFont.h   3 Dec 2005 10:11:33 -0000       1.6
67 +++ GfxFont.h   3 Dec 2005 10:30:41 -0000       1.7
68 @@ -207,7 +207,7 @@
69    CharCodeToUnicode *getToUnicode();
70  
71    // Return the character name associated with <code>.
72 -  char *getCharName(int code) { return enc[code]; }
73 +  char *getCharName(int code) { return code>=256?0:enc[code]; }
74  
75    // Returns true if the PDF font specified an encoding.
76    GBool getHasEncoding() { return hasEncoding; }
77 Index: GfxState.cc
78 ===================================================================
79 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/GfxState.cc,v
80 retrieving revision 1.10
81 retrieving revision 1.12
82 diff -u -r1.10 -r1.12
83 --- GfxState.cc 3 Dec 2005 10:11:33 -0000       1.10
84 +++ GfxState.cc 3 Dec 2005 12:41:32 -0000       1.12
85 @@ -21,6 +21,7 @@
86  #include "Array.h"
87  #include "Page.h"
88  #include "GfxState.h"
89 +#include "cmyk.h"
90  
91  //------------------------------------------------------------------------
92  
93 @@ -468,6 +469,18 @@
94                                 - 0.11 * color->c[2] + 0.5));
95  }
96  
97 +/*void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
98 +    unsigned char r,g,b;
99 +    float c = color->c[0];
100 +    float m = color->c[1];
101 +    float y = color->c[2];
102 +    float k = color->c[3];
103 +    convert_cmyk2rgb(c,m,y,k, &r,&g,&b);
104 +    rgb->r = r/255.0;
105 +    rgb->g = g/255.0;
106 +    rgb->b = b/255.0;
107 +}*/
108 +
109  void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
110    double c, m, y, k, c1, m1, y1, k1, r, g, b, x;
111  
112 @@ -3099,6 +3112,7 @@
113    GfxIndexedColorSpace *indexedCS;
114    GfxSeparationColorSpace *sepCS;
115    int maxPixel, indexHigh;
116 +  int maxPixelForAlloc;
117    Guchar *lookup2;
118    Function *sepFunc;
119    Object obj;
120 @@ -3111,6 +3125,7 @@
121    // bits per component and color space
122    bits = bitsA;
123    maxPixel = (1 << bits) - 1;
124 +  maxPixelForAlloc = (1 << (bits>8?bits:8));
125    colorSpace = colorSpaceA;
126  
127    // get decode map
128 @@ -3163,7 +3178,7 @@
129      lookup2 = indexedCS->getLookup();
130      colorSpace2->getDefaultRanges(x, y, indexHigh);
131      for (k = 0; k < nComps2; ++k) {
132 -      lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
133 +      lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
134                                            sizeof(GfxColorComp));
135        for (i = 0; i <= maxPixel; ++i) {
136         j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
137 @@ -3182,7 +3197,7 @@
138      nComps2 = colorSpace2->getNComps();
139      sepFunc = sepCS->getFunc();
140      for (k = 0; k < nComps2; ++k) {
141 -      lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
142 +      lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
143                                            sizeof(GfxColorComp));
144        for (i = 0; i <= maxPixel; ++i) {
145         x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
146 @@ -3192,7 +3207,7 @@
147      }
148    } else {
149      for (k = 0; k < nComps; ++k) {
150 -      lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
151 +      lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
152                                            sizeof(GfxColorComp));
153        for (i = 0; i <= maxPixel; ++i) {
154         lookup[k][i] = dblToCol(decodeLow[k] +
155 @@ -3754,7 +3769,10 @@
156  }
157  
158  void GfxState::setPath(GfxPath *pathA) {
159 +  if(pathA) {
160 +      if(path)
161    delete path;
162 +  }
163    path = pathA;
164  }
165
166 Index: GlobalParams.cc
167 ===================================================================
168 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/GlobalParams.cc,v
169 retrieving revision 1.4
170 retrieving revision 1.7
171 diff -u -r1.4 -r1.7
172 --- GlobalParams.cc     3 Dec 2005 10:11:33 -0000       1.4
173 +++ GlobalParams.cc     18 Dec 2005 08:31:22 -0000      1.7
174 @@ -498,6 +498,29 @@
175    char buf[512];
176    FILE *f2;
177  
178 +  /* extract path */
179 +  if(fileName) {
180 +    char* cfgFileName = fileName->getCString();
181 +    char* pos1 = strrchr(cfgFileName, '/');
182 +    char* pos2 = strrchr(cfgFileName, '\\');
183 +    char* p = pos1>pos2?pos1:pos2;
184 +    int pos = p ? p-cfgFileName : -1;
185 +    GString*path = new GString(new GString(cfgFileName), 0, (pos < 0 ? strlen(cfgFileName): pos));
186 +    if(pos1>=0)
187 +       path->append('/');
188 +    else if(pos2>=0)
189 +       path->append('\\');
190 +    else
191 +#ifdef WIN32
192 +       path->append('\\');
193 +#else
194 +       path->append('/');
195 +#endif
196 +    this->path = path;
197 +  } else {
198 +    this->path = new GString();
199 +  }
200 +  
201    line = 1;
202    while (getLine(buf, sizeof(buf) - 1, f)) {
203  
204 @@ -1142,6 +1165,42 @@
205    deleteGList(tokens, GString);
206  }
207  
208 +static char is_absolute(char*filename)
209 +{
210 +    int l = strlen(filename);
211 +    if(filename[0] == '/' || filename[0] == '\\') 
212 +       return 1;
213 +    if(l>2 && filename[1]==':' && (filename[2]=='\\' || filename[2]=='/'))
214 +       return 1;
215 +    return 0;
216 +}
217 +
218 +static GString* qualify_filename(GString*path, GString*filename)
219 +{
220 +  GString*fullpath = 0;
221 +  char*prefix = "/usr/local/share/xpdf/";
222 +
223 +  if (!is_absolute(filename->getCString())) {
224 +    /* relative path */
225 +    fullpath = path->copy();
226 +    fullpath->append(filename);
227 +  } else if (!strncmp(filename->getCString(), prefix, strlen(prefix))) {
228 +    /* xpdf default path */
229 +    char*s = strchr(filename->getCString()+strlen(prefix), '/');
230 +    if(s) {
231 +       fullpath = path->copy();
232 +       fullpath->append(s+1);
233 +    } else {
234 +       fullpath = filename->copy();
235 +    }
236 +  } else {
237 +    /* absolute path */
238 +    fullpath = filename->copy();
239 +  }
240 +  //printf("%s -%s-> %s\n", filename->getCString(), path->getCString(), fullpath->getCString());
241 +  return fullpath;
242 +}
243 +
244  void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
245                                          int line) {
246    GString *name;
247 @@ -1156,10 +1215,10 @@
248           fileName->getCString(), line);
249      return;
250    }
251 -  name = (GString *)tokens->get(1);
252 +  name = qualify_filename(this->path, (GString *)tokens->get(1));
253    if (!(f = fopen(name->getCString(), "r"))) {
254 -    error(-1, "Couldn't open 'nameToUnicode' file '%s'",
255 -         name->getCString());
256 +    error(-1, "Couldn't open 'nameToUnicode' file '%s' using path '%s'",
257 +         name->getCString(), path->getCString());
258      return;
259    }
260    line2 = 1;
261 @@ -705,10 +754,12 @@
262    }
263    collection = (GString *)tokens->get(1);
264    name = (GString *)tokens->get(2);
265 +
266    if ((old = (GString *)cidToUnicodes->remove(collection))) {
267      delete old;
268    }
269 -  cidToUnicodes->add(collection->copy(), name->copy());
270 +
271 +  cidToUnicodes->add(collection->copy(), qualify_filename(this->path, name));
272  }
273  
274  void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
275 @@ -725,7 +776,8 @@
276    if ((old = (GString *)unicodeToUnicodes->remove(font))) {
277      delete old;
278    }
279 -  unicodeToUnicodes->add(font->copy(), file->copy());
280 +
281 +  unicodeToUnicodes->add(font->copy(), qualify_filename(this->path, file));
282  }
283  
284  void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
285 @@ -742,7 +794,8 @@
286    if ((old = (GString *)unicodeMaps->remove(encodingName))) {
287      delete old;
288    }
289 -  unicodeMaps->add(encodingName->copy(), name->copy());
290 +
291 +  unicodeMaps->add(encodingName->copy(), qualify_filename(this->path, name));
292  }
293  
294  void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
295 @@ -760,23 +813,30 @@
296      list = new GList();
297      cMapDirs->add(collection->copy(), list);
298    }
299 -  list->append(dir->copy());
300 +
301 +  list->append(qualify_filename(this->path, dir));
302  }
303  
304  void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
305                                      int line) {
306 +  GString *dir;
307 +
308    if (tokens->getLength() != 2) {
309      error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
310           fileName->getCString(), line);
311      return;
312    }
313 -  toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
314 +
315 +  dir = (GString *)tokens->get(1);
316 +
317 +  toUnicodeDirs->append(qualify_filename(this->path, dir));
318  }
319  
320  void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
321                                     DisplayFontParamKind kind,
322                                     GString *fileName, int line) {
323    DisplayFontParam *param, *old;
324 +  GString *file;
325  
326    if (tokens->getLength() < 2) {
327      goto err1;
328 @@ -788,13 +848,15 @@
329      if (tokens->getLength() != 3) {
330        goto err2;
331      }
332 -    param->t1.fileName = ((GString *)tokens->get(2))->copy();
333 +    file = (GString *)tokens->get(2);
334 +    param->t1.fileName = qualify_filename(this->path, file);
335      break;
336    case displayFontTT:
337      if (tokens->getLength() != 3) {
338        goto err2;
339      }
340 -    param->tt.fileName = ((GString *)tokens->get(2))->copy();
341 +    file = (GString *)tokens->get(2);
342 +    param->tt.fileName = qualify_filename(this->path, file);
343      break;
344    }
345  
346 Index: Lexer.cc
347 ===================================================================
348 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/Lexer.cc,v
349 retrieving revision 1.4
350 retrieving revision 1.5
351 diff -u -r1.4 -r1.5
352 --- Lexer.cc    3 Dec 2005 10:11:33 -0000       1.4
353 +++ Lexer.cc    14 Mar 2006 12:43:23 -0000      1.5
354 @@ -74,6 +74,7 @@
355      curStr.streamReset();
356    }
357  }
358 +static int illegalChars = 0;
359  
360  Lexer::~Lexer() {
361    if (!curStr.isNone()) {
362 @@ -83,6 +84,9 @@
363    if (freeArray) {
364      delete streams;
365    }
366 +  if(illegalChars)
367 +      error(0, "Illegal characters in hex string (%d)", illegalChars);
368 +  illegalChars = 0;
369  }
370  
371  int Lexer::getChar() {
372 @@ -330,7 +334,8 @@
373         } else if (c2 >= 'a' && c2 <= 'f') {
374           c += c2 - 'a' + 10;
375         } else {
376 -         error(getPos(), "Illegal digit in hex char in name");
377 +         illegalChars++;
378 +         //error(getPos(), "Illegal digit in hex char in name");
379         }
380        }
381       notEscChar:
382 @@ -384,8 +389,10 @@
383             c2 += c - 'A' + 10;
384           else if (c >= 'a' && c <= 'f')
385             c2 += c - 'a' + 10;
386 -         else
387 -           error(getPos(), "Illegal character <%02x> in hex string", c);
388 +         else {
389 +           illegalChars++;
390 +           //error(getPos(), "Illegal character <%02x> in hex string", c);
391 +         }
392           if (++m == 2) {
393             if (n == tokBufSize) {
394               if (!s)
395 @@ -421,7 +428,8 @@
396        tokBuf[2] = '\0';
397        obj->initCmd(tokBuf);
398      } else {
399 -      error(getPos(), "Illegal character '>'");
400 +      illegalChars++;
401 +      //error(getPos(), "Illegal character '>'");
402        obj->initError();
403      }
404      break;
405 @@ -430,7 +438,8 @@
406    case ')':
407    case '{':
408    case '}':
409 -    error(getPos(), "Illegal character '%c'", c);
410 +    //error(getPos(), "Illegal character '%c'", c);
411 +    illegalChars++;
412      obj->initError();
413      break;
414  
415 @@ -459,7 +468,6 @@
416      }
417      break;
418    }
419 -
420    return obj;
421  }
422  
423 Index: Link.cc
424 ===================================================================
425 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/Link.cc,v
426 retrieving revision 1.5
427 retrieving revision 1.6
428 diff -u -r1.5 -r1.6
429 --- Link.cc     3 Dec 2005 10:11:33 -0000       1.5
430 +++ Link.cc     26 Mar 2006 08:26:59 -0000      1.6
431 @@ -430,10 +430,9 @@
432        delete dest;
433        dest = NULL;
434      }
435 -
436    // error
437    } else {
438 -    error(-1, "Illegal annotation destination");
439 +    error(-1, "Illegal annotation destination %d", destObj->getType());
440    }
441  }
442  
443 @@ -468,10 +467,9 @@
444        delete dest;
445        dest = NULL;
446      }
447 -
448    // error
449    } else {
450 -    error(-1, "Illegal annotation destination");
451 +    error(-1, "Illegal annotation destination %d", destObj->getType());
452    }
453  }
454  
455 Index: OutputDev.h
456 ===================================================================
457 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/OutputDev.h,v
458 retrieving revision 1.7
459 retrieving revision 1.9
460 diff -u -r1.7 -r1.9
461 --- OutputDev.h 3 Dec 2005 10:11:33 -0000       1.7
462 +++ OutputDev.h 3 Dec 2005 10:31:47 -0000       1.9
463 @@ -74,7 +74,7 @@
464    virtual void setDefaultCTM(double *ctm);
465  
466    // Start a page.
467 -  virtual void startPage(int pageNum, GfxState *state) {}
468 +  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
469  
470    // End a page.
471    virtual void endPage() {}
472 Index: Stream.cc
473 ===================================================================
474 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/Stream.cc,v
475 retrieving revision 1.7
476 retrieving revision 1.8
477 diff -u -r1.7 -r1.8
478 --- Stream.cc   3 Dec 2005 10:11:33 -0000       1.7
479 +++ Stream.cc   3 Dec 2005 10:30:41 -0000       1.8
480 @@ -17,6 +17,8 @@
481  #include <stddef.h>
482  #ifndef WIN32
483  #include <unistd.h>
484 +#else
485 +extern "C" int unlink(char *filename);
486  #endif
487  #include <string.h>
488  #include <ctype.h>
489 Index: config.h
490 --- config.h    2007-09-09 12:11:20.000000000 +0200
491 +++ config.h    2007-09-09 12:11:40.000000000 +0200
492 @@ -53,9 +53,9 @@
493  
494  // user config file name, relative to the user's home directory
495  #if defined(VMS) || defined(WIN32)
496 -#define xpdfUserConfigFile "xpdfrc"
497 +#define xpdfUserConfigFile "pdf2swf.conf"
498  #else
499 -#define xpdfUserConfigFile ".xpdfrc"
500 +#define xpdfUserConfigFile ".pdf2swf.conf"
501  #endif
502  
503  // system config file name (set via the configure script)
504 @@ -64,7 +64,7 @@
505  #else
506  // under Windows, we get the directory with the executable and then
507  // append this file name
508 -#define xpdfSysConfigFile "xpdfrc"
509 +#define xpdfSysConfigFile "pdf2swf.conf"
510  #endif
511  
512  //------------------------------------------------------------------------
513 Index: gfile.h
514 ===================================================================
515 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/gfile.h,v
516 retrieving revision 1.9
517 retrieving revision 1.10
518 diff -u -r1.9 -r1.10
519 --- gfile.h     3 Dec 2005 10:11:33 -0000       1.9
520 +++ gfile.h     3 Dec 2005 10:30:41 -0000       1.10
521 @@ -58,6 +58,9 @@
522  // Get current directory.
523  extern GString *getCurrentDir();
524  
525 +/* create a temporary filename */
526 +char* mktmpname(char*ptr);
527 +
528  // Append a file name to a path string.  <path> may be an empty
529  // string, denoting the current directory).  Returns <path>.
530  extern GString *appendToPath(GString *path, char *fileName);
531 Index: GlobalParams.h
532 ===================================================================
533 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/GlobalParams.h,v
534 retrieving revision 1.5
535 retrieving revision 1.6
536 diff -u -r1.5 -r1.6
537 --- GlobalParams.h      2006-10-10 19:54:29.000000000 +0200
538 +++ GlobalParams.h      2006-11-12 11:19:40.000000000 +0100
539 @@ -213,8 +213,8 @@
540    FILE *getUnicodeMapFile(GString *encodingName);
541    FILE *findCMapFile(GString *collection, GString *cMapName);
542    FILE *findToUnicodeFile(GString *name);
543 -  DisplayFontParam *getDisplayFont(GString *fontName);
544 -  DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
545 +  virtual DisplayFontParam *getDisplayFont(GString *fontName);
546 +  virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
547    GString *getPSFile();
548    int getPSPaperWidth();
549    int getPSPaperHeight();
550 @@ -218,1 +218,1 @@
551 -  void parseFile(GString *fileName, FILE *f);
552 +public: void parseFile(GString *fileName, FILE *f); private:
553 @@ -246,6 +246,10 @@
554    GBool loadPlugin(char *type, char *name);
555  #endif
556  
557 +  //----- config file base path
558 +
559 +  GString*path;
560 +
561    //----- static tables
562  
563    NameToCharCode *             // mapping from char name to
564 --- SplashOutputDev.h   2006-11-12 12:07:22.000000000 +0100
565 +++ SplashOutputDev.h   2006-11-12 12:08:48.000000000 +0100
566 @@ -70,7 +70,7 @@
567    //----- initialization and control
568  
569    // Start a page.
570 -  virtual void startPage(int pageNum, GfxState *state);
571 +  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
572  
573    // End a page.
574    virtual void endPage();
575 --- SplashOutputDev.cc  2006-11-12 12:07:06.000000000 +0100
576 +++ SplashOutputDev.cc  2006-11-12 12:09:36.000000000 +0100
577 @@ -696,7 +696,7 @@
578    nT3Fonts = 0;
579  }
580  
581 -void SplashOutputDev::startPage(int pageNum, GfxState *state) {
582 +void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
583    int w, h;
584    double *ctm;
585    SplashCoord mat[6];
586 --- TextOutputDev.h     2006-11-12 12:23:01.000000000 +0100
587 +++ TextOutputDev.h     2006-11-12 12:25:31.000000000 +0100
588 @@ -578,7 +578,7 @@
589    //----- initialization and control
590  
591    // Start a page.
592 -  virtual void startPage(int pageNum, GfxState *state);
593 +  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
594  
595    // End a page.
596    virtual void endPage();
597 --- TextOutputDev.cc    2006-11-12 12:22:53.000000000 +0100
598 +++ TextOutputDev.cc    2006-11-12 12:25:03.000000000 +0100
599 @@ -3805,7 +3805,7 @@
600    }
601  }
602  
603 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
604 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
605    text->startPage(state);
606  }
607  
608 --- CoreOutputDev.cc    2006-11-12 12:21:59.000000000 +0100
609 +++ CoreOutputDev.cc    2006-11-12 12:23:29.000000000 +0100
610 @@ -57,5 +57,5 @@
611  
612  void CoreOutputDev::clear() {
613    startDoc(NULL);
614 -  startPage(0, NULL);
615 +  startPage(0, NULL, 0,0,0,0);
616  }
617 --- SplashFTFontEngine.cc       2006-11-19 22:30:44.000000000 +0100
618 +++ SplashFTFontEngine.cc       2006-11-19 22:30:56.000000000 +0100
619 @@ -13,9 +13,7 @@
620  #endif
621  
622  #include <stdio.h>
623 -#ifndef WIN32
624  #  include <unistd.h>
625 -#endif
626  #include "gmem.h"
627  #include "GString.h"
628  #include "gfile.h"
629 --- SplashOutputDev.cc  2007-09-09 12:29:45.000000000 +0200
630 +++ SplashOutputDev.cc  2007-09-09 12:30:02.000000000 +0200
631 @@ -13,6 +13,7 @@
632  #endif
633  
634  #include <string.h>
635 +#include <unistd.h>
636  #include <math.h>
637  #include "gfile.h"
638  #include "GlobalParams.h"
639 --- SplashFontFile.cc   2007-09-09 12:33:00.000000000 +0200
640 +++ SplashFontFile.cc   2007-09-09 12:33:07.000000000 +0200
641 @@ -11,9 +11,7 @@
642  #endif
643  
644  #include <stdio.h>
645 -#ifndef WIN32
646 -#  include <unistd.h>
647 -#endif
648 +#include <unistd.h>
649  #include "GString.h"
650  #include "SplashFontFile.h"
651  #include "SplashFontFileID.h"
652 --- xpdf/SplashFont.h.orig      2008-09-09 21:31:01.000000000 +0200
653 +++ xpdf/SplashFont.h   2008-10-05 17:36:44.000000000 +0200
654 @@ -73,6 +73,9 @@
655    virtual GBool makeGlyph(int c, int xFrac, int yFrac,
656                           SplashGlyphBitmap *bitmap) = 0;
657  
658 +  // return the number of characters in this font
659 +  virtual int getNumChars() = 0;
660 +
661    // Return the path for a glyph.
662    virtual SplashPath *getGlyphPath(int c) = 0;
663  
664 @@ -83,6 +86,9 @@
665    void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
666      { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
667  
668 +  double ascender;
669 +  double descender;
670 +  double last_advance; //set after getGlyphPath()
671  protected:
672  
673    SplashFontFile *fontFile;
674 --- orig/GfxFont.h      2007-07-28 00:11:06.000000000 +0200
675 +++ GfxFont.h   2007-09-09 18:31:31.000000000 +0200
676 @@ -164,6 +164,7 @@
677    virtual int getNextChar(char *s, int len, CharCode *code,
678                           Unicode *u, int uSize, int *uLen,
679                           double *dx, double *dy, double *ox, double *oy) = 0;
680 +  virtual CharCodeToUnicode* getCTU() = 0;
681  
682  protected:
683  
684 @@ -204,6 +205,7 @@
685    virtual int getNextChar(char *s, int len, CharCode *code,
686                           Unicode *u, int uSize, int *uLen,
687                           double *dx, double *dy, double *ox, double *oy);
688 +  virtual CharCodeToUnicode* getCTU();
689  
690    // Return the encoding.
691    char **getEncoding() { return enc; }
692 @@ -266,6 +268,7 @@
693    virtual int getNextChar(char *s, int len, CharCode *code,
694                           Unicode *u, int uSize, int *uLen,
695                           double *dx, double *dy, double *ox, double *oy);
696 +  virtual CharCodeToUnicode* getCTU();
697  
698    // Return the writing mode (0=horizontal, 1=vertical).
699    virtual int getWMode();
700 --- orig/GfxFont.cc     2007-07-28 00:11:06.000000000 +0200
701 +++ GfxFont.cc  2007-09-09 18:33:37.000000000 +0200
702 @@ -925,6 +925,10 @@
703    return 1;
704  }
705  
706 +CharCodeToUnicode* Gfx8BitFont::getCTU() {
707 +    return ctu;
708 +}
709 +
710  CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
711    ctu->incRefCnt();
712    return ctu;
713 @@ -1417,6 +1421,10 @@
714    }
715  }
716  
717 +CharCodeToUnicode* GfxCIDFont::getCTU() {
718 +    return ctu;
719 +}
720 +
721  int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
722                             Unicode *u, int uSize, int *uLen,
723                             double *dx, double *dy, double *ox, double *oy) {
724 --- OutputDev.h Sat Jul 28 00:11:08 2007
725 +++ OutputDev.h Sun Sep  9 13:50:40 2007
726 @@ -17,6 +17,7 @@
727  
728  #include "gtypes.h"
729  #include "CharTypes.h"
730 +#include "Object.h"
731  
732  class GString;
733  class Gfx;
734 --- SplashOutputDev.h   2007-10-20 13:17:02.000000000 +0200
735 +++ SplashOutputDev.h   2007-10-20 13:17:23.000000000 +0200
736 @@ -206,6 +206,7 @@
737    virtual void setVectorAntialias(GBool vaa);
738  #endif
739  
740 +  void doUpdateFont(GfxState *state);
741  private:
742  
743    void setupScreenParams(double hDPI, double vDPI);
744 @@ -215,7 +216,6 @@
745    SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
746  #endif
747    SplashPath *convertPath(GfxState *state, GfxPath *path);
748 -  void doUpdateFont(GfxState *state);
749    void drawType3Glyph(T3FontCache *t3Font,
750                       T3FontCacheTag *tag, Guchar *data);
751    static GBool imageMaskSrc(void *data, SplashColorPtr line);
752 --- xpdf/GlobalParams.h 2007-10-20 13:18:03.000000000 +0200
753 +++ xpdf/GlobalParams.h 2007-10-20 13:25:52.000000000 +0200
754 @@ -196,7 +196,7 @@
755    // file.
756    GlobalParams(char *cfgFileName);
757  
758 -  ~GlobalParams();
759 +  virtual ~GlobalParams();
760  
761    void setBaseDir(char *dir);
762    void setupBaseFonts(char *dir);
763 --- xpdf/SplashOutputDev.h.orig 2007-10-21 17:43:29.000000000 +0200
764 +++ xpdf/SplashOutputDev.h      2007-11-19 10:07:27.000000000 +0100
765 @@ -197,6 +197,8 @@
766  #endif
767  
768    void doUpdateFont(GfxState *state);
769 +  
770 +  SplashPath *convertPath(GfxState *state, GfxPath *path);
771  private:
772  
773    void setupScreenParams(double hDPI, double vDPI);
774 @@ -205,7 +207,6 @@
775  #else
776    SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
777  #endif
778 -  SplashPath *convertPath(GfxState *state, GfxPath *path);
779    void drawType3Glyph(T3FontCache *t3Font,
780                       T3FontCacheTag *tag, Guchar *data);
781    static GBool imageMaskSrc(void *data, SplashColorPtr line);
782 --- xpdf/SplashFont.cc.orig     2008-09-09 21:31:01.000000000 +0200
783 +++ xpdf/SplashFont.cc  2008-10-05 17:37:08.000000000 +0200
784 @@ -48,6 +48,10 @@
785    cacheTags = NULL;
786  
787    xMin = yMin = xMax = yMax = 0;
788 +
789 +  last_advance = -1;
790 +  ascender = -1;
791 +  descender = -1;
792  }
793  
794  void SplashFont::initCache() {
795 --- xpdf/SplashFTFont.cc.orig   2008-09-09 21:31:01.000000000 +0200
796 +++ xpdf/SplashFTFont.cc        2008-10-05 17:37:32.000000000 +0200
797 @@ -46,6 +46,7 @@
798    int x, y;
799  
800    face = fontFileA->face;
801 +  
802    if (FT_New_Size(face, &sizeObj)) {
803      return;
804    }
805 @@ -54,6 +55,10 @@
806    if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
807      return;
808    }
809
810 +  this->ascender = face->ascender;
811 +  this->descender = face->descender;
812 +
813    // if the textMat values are too small, FreeType's fixed point
814    // arithmetic doesn't work so well
815    textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
816 @@ -228,6 +233,12 @@
817    GBool needClose;
818  };
819  
820 +int SplashFTFont::getNumChars()
821 +{
822 +  SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
823 +  return ff->face->num_glyphs;
824 +}
825 +
826  SplashPath *SplashFTFont::getGlyphPath(int c) {
827    static FT_Outline_Funcs outlineFuncs = {
828  #if FREETYPE_MINOR <= 1
829 @@ -249,6 +260,8 @@
830    FT_UInt gid;
831    FT_Glyph glyph;
832  
833 +  this->last_advance = -1;
834 +
835    ff = (SplashFTFontFile *)fontFile;
836    ff->face->size = sizeObj;
837    FT_Set_Transform(ff->face, &textMatrix, NULL);
838 @@ -268,6 +281,8 @@
839    if (FT_Get_Glyph(slot, &glyph)) {
840      return NULL;
841    }
842 +  this->last_advance = glyph->advance.x/65536.0;
843 +
844    path.path = new SplashPath();
845    path.textScale = textScale;
846    path.needClose = gFalse;
847 --- xpdf/SplashFTFont.h.orig    2008-09-09 21:31:01.000000000 +0200
848 +++ xpdf/SplashFTFont.h 2008-10-04 17:39:57.000000000 +0200
849 @@ -42,6 +42,9 @@
850    virtual GBool makeGlyph(int c, int xFrac, int yFrac,
851                           SplashGlyphBitmap *bitmap);
852  
853 +  // return the number of characters in this font
854 +  virtual int getNumChars();
855 +
856    // Return the path for a glyph.
857    virtual SplashPath *getGlyphPath(int c);
858  
859 --- xpdf/SplashScreen.cc.orig   2008-10-06 17:59:44.000000000 +0200
860 +++ xpdf/SplashScreen.cc        2008-10-06 18:20:09.000000000 +0200
861 @@ -363,6 +363,8 @@
862  int SplashScreen::test(int x, int y, Guchar value) {
863    int xx, yy;
864  
865 +  return 1;
866 +
867    if (value < minVal) {
868      return 0;
869    }
870 --- xpdf/gfile.cc.orig  2007-02-27 23:05:51.000000000 +0100
871 +++ xpdf/gfile.cc       2008-10-12 15:15:22.000000000 +0200
872 @@ -439,6 +439,52 @@
873  #endif
874  }
875  
876 +static char* getTempDir()
877 +{
878 +#ifdef WIN32
879 +    char*dir = getenv("TMP");
880 +    if(!dir) dir = getenv("TEMP");
881 +    if(!dir) dir = getenv("tmp");
882 +    if(!dir) dir = getenv("temp");
883 +    if(!dir) dir = "C:\\";
884 +#else
885 +    char* dir = "/tmp/";
886 +#endif
887 +    return dir;
888 +}
889 +
890 +char* mktmpname(char*ptr) {
891 +    static char tmpbuf[128];
892 +    char*dir = getTempDir();
893 +    int l = strlen(dir);
894 +    char*sep = "";
895 +    if(!ptr)
896 +       ptr = tmpbuf;
897 +    if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
898 +#ifdef WIN32
899 +       sep = "\\";
900 +#else
901 +       sep = "/";
902 +#endif
903 +    }
904 +
905 + //   used to be mktemp. This does remove the warnings, but
906 + //   It's not exactly an improvement.
907 +#ifdef HAVE_LRAND48
908 +    sprintf(ptr, "%s%s%08x%08x",dir,sep,lrand48(),lrand48());
909 +#else
910 +#   ifdef HAVE_RAND
911 +       sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
912 +#   else
913 +       static int count = 1;
914 +       sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
915 +       count ++;
916 +#   endif
917 +#endif
918 +     return ptr;
919 +}
920 +
921 +
922  GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
923  #if defined(WIN32)
924    //---------- Win32 ----------
925 @@ -460,7 +506,7 @@
926    s->append("x");
927    t = (int)time(NULL);
928    for (i = 0; i < 1000; ++i) {
929 -    sprintf(buf, "%d", t + i);
930 +    sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
931      s2 = s->copy()->append(buf);
932      if (ext) {
933        s2->append(ext);
934 @@ -468,8 +514,7 @@
935      if (!(f2 = fopen(s2->getCString(), "r"))) {
936        if (!(f2 = fopen(s2->getCString(), mode))) {
937         delete s2;
938 -       delete s;
939 -       return gFalse;
940 +        continue;
941        }
942        *name = s2;
943        *f = f2;
944 @@ -479,6 +524,7 @@
945      fclose(f2);
946      delete s2;
947    }
948 +  fprintf(stderr, "Couldn't create temporary file\n");
949    delete s;
950    return gFalse;
951  #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
952 @@ -489,7 +535,7 @@
953    // with this file name after the tmpnam call and before the fopen
954    // call.  I will happily accept fixes to this function for non-Unix
955    // OSs.
956 -  if (!(s = tmpnam(NULL))) {
957 +  if (!(s = mktmpname(NULL))) {
958      return gFalse;
959    }
960    *name = new GString(s);
961 @@ -516,7 +562,7 @@
962      (*name)->append("/XXXXXX")->append(ext);
963      fd = mkstemps((*name)->getCString(), strlen(ext));
964  #else
965 -    if (!(s = tmpnam(NULL))) {
966 +    if (!(s = mktmpname(NULL))) {
967        return gFalse;
968      }
969      *name = new GString(s);
970 @@ -533,7 +579,7 @@
971      (*name)->append("/XXXXXX");
972      fd = mkstemp((*name)->getCString());
973  #else // HAVE_MKSTEMP
974 -    if (!(s = tmpnam(NULL))) {
975 +    if (!(s = mktmpname(NULL))) {
976        return gFalse;
977      }
978      *name = new GString(s);