disabled all dithering
[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.cc
514 ===================================================================
515 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/gfile.cc,v
516 retrieving revision 1.12
517 retrieving revision 1.13
518 diff -u -r1.12 -r1.13
519 --- gfile.cc    3 Dec 2005 10:11:33 -0000       1.12
520 +++ gfile.cc    3 Dec 2005 10:30:41 -0000       1.13
521 @@ -437,6 +437,52 @@
522  #endif
523  }
524  
525 +static char* getTempDir()
526 +{
527 +#ifdef WIN32
528 +    char*dir = getenv("TMP");
529 +    if(!dir) dir = getenv("TEMP");
530 +    if(!dir) dir = getenv("tmp");
531 +    if(!dir) dir = getenv("temp");
532 +    if(!dir) dir = "C:\\";
533 +#else
534 +    char* dir = "/tmp/";
535 +#endif
536 +    return dir;
537 +}
538 +
539 +char* mktmpname(char*ptr) {
540 +    static char tmpbuf[128];
541 +    char*dir = getTempDir();
542 +    int l = strlen(dir);
543 +    char*sep = "";
544 +    if(!ptr)
545 +       ptr = tmpbuf;
546 +    if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
547 +#ifdef WIN32
548 +       sep = "\\";
549 +#else
550 +       sep = "/";
551 +#endif
552 +    }
553 +
554 + //   used to be mktemp. This does remove the warnings, but
555 + //   It's not exactly an improvement.
556 +#ifdef HAVE_LRAND48
557 +    sprintf(ptr, "%s%s%08x%08x",dir,sep,lrand48(),lrand48());
558 +#else
559 +#   ifdef HAVE_RAND
560 +       sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
561 +#   else
562 +       static int count = 1;
563 +       sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
564 +       count ++;
565 +#   endif
566 +#endif
567 +     return ptr;
568 +}
569 +
570 +
571  GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
572  #if defined(WIN32)
573    //---------- Win32 ----------
574 @@ -463,7 +509,7 @@
575    // with this file name after the tmpnam call and before the fopen
576    // call.  I will happily accept fixes to this function for non-Unix
577    // OSs.
578 -  if (!(s = tmpnam(NULL))) {
579 +  if (!(s = mktmpname(NULL))) {
580      return gFalse;
581    }
582    *name = new GString(s);
583 @@ -490,7 +536,7 @@
584      (*name)->append("/XXXXXX")->append(ext);
585      fd = mkstemps((*name)->getCString(), strlen(ext));
586  #else
587 -    if (!(s = tmpnam(NULL))) {
588 +    if (!(s = mktmpname(NULL))) {
589        return gFalse;
590      }
591      *name = new GString(s);
592 @@ -507,7 +553,7 @@
593      (*name)->append("/XXXXXX");
594      fd = mkstemp((*name)->getCString());
595  #else // HAVE_MKSTEMP
596 -    if (!(s = tmpnam(NULL))) {
597 +    if (!(s = mktmpname(NULL))) {
598        return gFalse;
599      }
600      *name = new GString(s);
601 Index: gfile.h
602 ===================================================================
603 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/gfile.h,v
604 retrieving revision 1.9
605 retrieving revision 1.10
606 diff -u -r1.9 -r1.10
607 --- gfile.h     3 Dec 2005 10:11:33 -0000       1.9
608 +++ gfile.h     3 Dec 2005 10:30:41 -0000       1.10
609 @@ -58,6 +58,9 @@
610  // Get current directory.
611  extern GString *getCurrentDir();
612  
613 +/* create a temporary filename */
614 +char* mktmpname(char*ptr);
615 +
616  // Append a file name to a path string.  <path> may be an empty
617  // string, denoting the current directory).  Returns <path>.
618  extern GString *appendToPath(GString *path, char *fileName);
619 Index: GlobalParams.h
620 ===================================================================
621 RCS file: /home/kramm/cvs/swftools.cache.cvsroot/swftools.cache/pdf2swf/xpdf/GlobalParams.h,v
622 retrieving revision 1.5
623 retrieving revision 1.6
624 diff -u -r1.5 -r1.6
625 --- GlobalParams.h      2006-10-10 19:54:29.000000000 +0200
626 +++ GlobalParams.h      2006-11-12 11:19:40.000000000 +0100
627 @@ -213,8 +213,8 @@
628    FILE *getUnicodeMapFile(GString *encodingName);
629    FILE *findCMapFile(GString *collection, GString *cMapName);
630    FILE *findToUnicodeFile(GString *name);
631 -  DisplayFontParam *getDisplayFont(GString *fontName);
632 -  DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
633 +  virtual DisplayFontParam *getDisplayFont(GString *fontName);
634 +  virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
635    GString *getPSFile();
636    int getPSPaperWidth();
637    int getPSPaperHeight();
638 @@ -218,1 +218,1 @@
639 -  void parseFile(GString *fileName, FILE *f);
640 +public: void parseFile(GString *fileName, FILE *f); private:
641 @@ -246,6 +246,10 @@
642    GBool loadPlugin(char *type, char *name);
643  #endif
644  
645 +  //----- config file base path
646 +
647 +  GString*path;
648 +
649    //----- static tables
650  
651    NameToCharCode *             // mapping from char name to
652 --- SplashOutputDev.h   2006-11-12 12:07:22.000000000 +0100
653 +++ SplashOutputDev.h   2006-11-12 12:08:48.000000000 +0100
654 @@ -70,7 +70,7 @@
655    //----- initialization and control
656  
657    // Start a page.
658 -  virtual void startPage(int pageNum, GfxState *state);
659 +  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
660  
661    // End a page.
662    virtual void endPage();
663 --- SplashOutputDev.cc  2006-11-12 12:07:06.000000000 +0100
664 +++ SplashOutputDev.cc  2006-11-12 12:09:36.000000000 +0100
665 @@ -696,7 +696,7 @@
666    nT3Fonts = 0;
667  }
668  
669 -void SplashOutputDev::startPage(int pageNum, GfxState *state) {
670 +void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
671    int w, h;
672    double *ctm;
673    SplashCoord mat[6];
674 --- TextOutputDev.h     2006-11-12 12:23:01.000000000 +0100
675 +++ TextOutputDev.h     2006-11-12 12:25:31.000000000 +0100
676 @@ -578,7 +578,7 @@
677    //----- initialization and control
678  
679    // Start a page.
680 -  virtual void startPage(int pageNum, GfxState *state);
681 +  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
682  
683    // End a page.
684    virtual void endPage();
685 --- TextOutputDev.cc    2006-11-12 12:22:53.000000000 +0100
686 +++ TextOutputDev.cc    2006-11-12 12:25:03.000000000 +0100
687 @@ -3805,7 +3805,7 @@
688    }
689  }
690  
691 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
692 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
693    text->startPage(state);
694  }
695  
696 --- CoreOutputDev.cc    2006-11-12 12:21:59.000000000 +0100
697 +++ CoreOutputDev.cc    2006-11-12 12:23:29.000000000 +0100
698 @@ -57,5 +57,5 @@
699  
700  void CoreOutputDev::clear() {
701    startDoc(NULL);
702 -  startPage(0, NULL);
703 +  startPage(0, NULL, 0,0,0,0);
704  }
705 --- SplashFTFontEngine.cc       2006-11-19 22:30:44.000000000 +0100
706 +++ SplashFTFontEngine.cc       2006-11-19 22:30:56.000000000 +0100
707 @@ -13,9 +13,7 @@
708  #endif
709  
710  #include <stdio.h>
711 -#ifndef WIN32
712  #  include <unistd.h>
713 -#endif
714  #include "gmem.h"
715  #include "GString.h"
716  #include "gfile.h"
717 --- SplashOutputDev.cc  2007-09-09 12:29:45.000000000 +0200
718 +++ SplashOutputDev.cc  2007-09-09 12:30:02.000000000 +0200
719 @@ -13,6 +13,7 @@
720  #endif
721  
722  #include <string.h>
723 +#include <unistd.h>
724  #include <math.h>
725  #include "gfile.h"
726  #include "GlobalParams.h"
727 --- SplashFontFile.cc   2007-09-09 12:33:00.000000000 +0200
728 +++ SplashFontFile.cc   2007-09-09 12:33:07.000000000 +0200
729 @@ -11,9 +11,7 @@
730  #endif
731  
732  #include <stdio.h>
733 -#ifndef WIN32
734 -#  include <unistd.h>
735 -#endif
736 +#include <unistd.h>
737  #include "GString.h"
738  #include "SplashFontFile.h"
739  #include "SplashFontFileID.h"
740 --- xpdf/SplashFont.h.orig      2008-09-09 21:31:01.000000000 +0200
741 +++ xpdf/SplashFont.h   2008-10-05 17:36:44.000000000 +0200
742 @@ -73,6 +73,9 @@
743    virtual GBool makeGlyph(int c, int xFrac, int yFrac,
744                           SplashGlyphBitmap *bitmap) = 0;
745  
746 +  // return the number of characters in this font
747 +  virtual int getNumChars() = 0;
748 +
749    // Return the path for a glyph.
750    virtual SplashPath *getGlyphPath(int c) = 0;
751  
752 @@ -83,6 +86,9 @@
753    void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
754      { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
755  
756 +  double ascender;
757 +  double descender;
758 +  double last_advance; //set after getGlyphPath()
759  protected:
760  
761    SplashFontFile *fontFile;
762 --- orig/GfxFont.h      2007-07-28 00:11:06.000000000 +0200
763 +++ GfxFont.h   2007-09-09 18:31:31.000000000 +0200
764 @@ -164,6 +164,7 @@
765    virtual int getNextChar(char *s, int len, CharCode *code,
766                           Unicode *u, int uSize, int *uLen,
767                           double *dx, double *dy, double *ox, double *oy) = 0;
768 +  virtual CharCodeToUnicode* getCTU() = 0;
769  
770  protected:
771  
772 @@ -204,6 +205,7 @@
773    virtual int getNextChar(char *s, int len, CharCode *code,
774                           Unicode *u, int uSize, int *uLen,
775                           double *dx, double *dy, double *ox, double *oy);
776 +  virtual CharCodeToUnicode* getCTU();
777  
778    // Return the encoding.
779    char **getEncoding() { return enc; }
780 @@ -266,6 +268,7 @@
781    virtual int getNextChar(char *s, int len, CharCode *code,
782                           Unicode *u, int uSize, int *uLen,
783                           double *dx, double *dy, double *ox, double *oy);
784 +  virtual CharCodeToUnicode* getCTU();
785  
786    // Return the writing mode (0=horizontal, 1=vertical).
787    virtual int getWMode();
788 --- orig/GfxFont.cc     2007-07-28 00:11:06.000000000 +0200
789 +++ GfxFont.cc  2007-09-09 18:33:37.000000000 +0200
790 @@ -925,6 +925,10 @@
791    return 1;
792  }
793  
794 +CharCodeToUnicode* Gfx8BitFont::getCTU() {
795 +    return ctu;
796 +}
797 +
798  CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
799    ctu->incRefCnt();
800    return ctu;
801 @@ -1417,6 +1421,10 @@
802    }
803  }
804  
805 +CharCodeToUnicode* GfxCIDFont::getCTU() {
806 +    return ctu;
807 +}
808 +
809  int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
810                             Unicode *u, int uSize, int *uLen,
811                             double *dx, double *dy, double *ox, double *oy) {
812 --- OutputDev.h Sat Jul 28 00:11:08 2007
813 +++ OutputDev.h Sun Sep  9 13:50:40 2007
814 @@ -17,6 +17,7 @@
815  
816  #include "gtypes.h"
817  #include "CharTypes.h"
818 +#include "Object.h"
819  
820  class GString;
821  class Gfx;
822 --- SplashOutputDev.h   2007-10-20 13:17:02.000000000 +0200
823 +++ SplashOutputDev.h   2007-10-20 13:17:23.000000000 +0200
824 @@ -206,6 +206,7 @@
825    virtual void setVectorAntialias(GBool vaa);
826  #endif
827  
828 +  void doUpdateFont(GfxState *state);
829  private:
830  
831    void setupScreenParams(double hDPI, double vDPI);
832 @@ -215,7 +216,6 @@
833    SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
834  #endif
835    SplashPath *convertPath(GfxState *state, GfxPath *path);
836 -  void doUpdateFont(GfxState *state);
837    void drawType3Glyph(T3FontCache *t3Font,
838                       T3FontCacheTag *tag, Guchar *data);
839    static GBool imageMaskSrc(void *data, SplashColorPtr line);
840 --- xpdf/GlobalParams.h 2007-10-20 13:18:03.000000000 +0200
841 +++ xpdf/GlobalParams.h 2007-10-20 13:25:52.000000000 +0200
842 @@ -196,7 +196,7 @@
843    // file.
844    GlobalParams(char *cfgFileName);
845  
846 -  ~GlobalParams();
847 +  virtual ~GlobalParams();
848  
849    void setBaseDir(char *dir);
850    void setupBaseFonts(char *dir);
851 --- xpdf/SplashOutputDev.h.orig 2007-10-21 17:43:29.000000000 +0200
852 +++ xpdf/SplashOutputDev.h      2007-11-19 10:07:27.000000000 +0100
853 @@ -197,6 +197,8 @@
854  #endif
855  
856    void doUpdateFont(GfxState *state);
857 +  
858 +  SplashPath *convertPath(GfxState *state, GfxPath *path);
859  private:
860  
861    void setupScreenParams(double hDPI, double vDPI);
862 @@ -205,7 +207,6 @@
863  #else
864    SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
865  #endif
866 -  SplashPath *convertPath(GfxState *state, GfxPath *path);
867    void drawType3Glyph(T3FontCache *t3Font,
868                       T3FontCacheTag *tag, Guchar *data);
869    static GBool imageMaskSrc(void *data, SplashColorPtr line);
870 --- xpdf/SplashFont.cc.orig     2008-09-09 21:31:01.000000000 +0200
871 +++ xpdf/SplashFont.cc  2008-10-05 17:37:08.000000000 +0200
872 @@ -48,6 +48,10 @@
873    cacheTags = NULL;
874  
875    xMin = yMin = xMax = yMax = 0;
876 +
877 +  last_advance = -1;
878 +  ascender = -1;
879 +  descender = -1;
880  }
881  
882  void SplashFont::initCache() {
883 --- xpdf/SplashFTFont.cc.orig   2008-09-09 21:31:01.000000000 +0200
884 +++ xpdf/SplashFTFont.cc        2008-10-05 17:37:32.000000000 +0200
885 @@ -46,6 +46,7 @@
886    int x, y;
887  
888    face = fontFileA->face;
889 +  
890    if (FT_New_Size(face, &sizeObj)) {
891      return;
892    }
893 @@ -54,6 +55,10 @@
894    if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
895      return;
896    }
897
898 +  this->ascender = face->ascender;
899 +  this->descender = face->descender;
900 +
901    // if the textMat values are too small, FreeType's fixed point
902    // arithmetic doesn't work so well
903    textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
904 @@ -228,6 +233,12 @@
905    GBool needClose;
906  };
907  
908 +int SplashFTFont::getNumChars()
909 +{
910 +  SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
911 +  return ff->face->num_glyphs;
912 +}
913 +
914  SplashPath *SplashFTFont::getGlyphPath(int c) {
915    static FT_Outline_Funcs outlineFuncs = {
916  #if FREETYPE_MINOR <= 1
917 @@ -249,6 +260,8 @@
918    FT_UInt gid;
919    FT_Glyph glyph;
920  
921 +  this->last_advance = -1;
922 +
923    ff = (SplashFTFontFile *)fontFile;
924    ff->face->size = sizeObj;
925    FT_Set_Transform(ff->face, &textMatrix, NULL);
926 @@ -268,6 +281,8 @@
927    if (FT_Get_Glyph(slot, &glyph)) {
928      return NULL;
929    }
930 +  this->last_advance = glyph->advance.x/65536.0;
931 +
932    path.path = new SplashPath();
933    path.textScale = textScale;
934    path.needClose = gFalse;
935 --- xpdf/SplashFTFont.h.orig    2008-09-09 21:31:01.000000000 +0200
936 +++ xpdf/SplashFTFont.h 2008-10-04 17:39:57.000000000 +0200
937 @@ -42,6 +42,9 @@
938    virtual GBool makeGlyph(int c, int xFrac, int yFrac,
939                           SplashGlyphBitmap *bitmap);
940  
941 +  // return the number of characters in this font
942 +  virtual int getNumChars();
943 +
944    // Return the path for a glyph.
945    virtual SplashPath *getGlyphPath(int c);
946  
947 --- xpdf/SplashScreen.cc.orig   2008-10-06 17:59:44.000000000 +0200
948 +++ xpdf/SplashScreen.cc        2008-10-06 18:20:09.000000000 +0200
949 @@ -363,6 +363,8 @@
950  int SplashScreen::test(int x, int y, Guchar value) {
951    int xx, yy;
952  
953 +  return 0;
954 +
955    if (value < minVal) {
956      return 0;
957    }