fixed jpeg2000 problem
[swftools.git] / lib / pdf / xpdf-changes.patch
1 196c196
2 <     goto err1;
3 ---
4 >     return start;
5 211c211
6 <   int nDigits, n1, n2, n3;
7 ---
8 >   int maxCode, n1, n2, n3;
9 217c217
10 <   nDigits = nBits / 4;
11 ---
12 >   maxCode = (nBits == 8) ? 0xff : (nBits == 16) ? 0xffff : 0xffffffff;
13 244c244
14 <       if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
15 ---
16 >       if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' &&
17 246c246
18 <         error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
19 ---
20 >         error(-1, "Illegal entry in bfchar block in ToUnicode CMap.");
21 253a254,256
22 >         if (code1 > maxCode) {
23 >           error(-1, "Invalid entry in bfchar block in ToUnicode CMap");
24 >         }
25 269,270c272,273
26 <       if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
27 <             n2 == 2 + nDigits && tok2[0] == '<' && tok2[n2 - 1] == '>')) {
28 ---
29 >       if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' &&
30 >             tok2[0] == '<' && tok2[n2 - 1] == '>')) {
31 279a283,286
32 >         if (code1 > maxCode || code2 > maxCode) {
33 >           error(-1, "Invalid entry in bfrange block in ToUnicode CMap");
34 >       }
35
36 60c60
37 <   startPage(0, NULL);
38 ---
39 >   startPage(0, NULL, 0,0,0,0);
40 598a599
41 >     if(!n || n>16) n=16;
42 457c457,461
43 <   out->startPage(pageNum, state);
44 ---
45 >   if(cropBox) {
46 >       out->startPage(pageNum, state, cropBox->x1,cropBox->y1,cropBox->x2,cropBox->y2);
47 >   } else {
48 >       out->startPage(pageNum, state, 0,0,0,0);
49 >   }
50 467a472
51 > #ifdef XPDFEXE
52 477a483
53 > #endif
54 3185,3186c3191,3195
55 <       if (n == 1 && *p == ' ') {
56 <       dx += state->getWordSpace();
57 ---
58 >       if (n == 1 && (*p == ' ' || *p == 0)) {
59 >         double w=state->getWordSpace();
60 >         if (w==0 && dx==0)
61 >           w=state->getFontSize()/3; // workaround for zero word space
62 >         dx += w;
63 3479c3488
64 <       colorSpace = GfxColorSpace::parse(&obj1);
65 ---
66 >       colorSpace = GfxColorSpace::parse(&obj1, csMode);
67 3483a3493,3494
68 >     } else if (csMode == streamCSDeviceRGBX) {
69 >       colorSpace = new GfxDeviceRGBXColorSpace();
70 3826a3838
71 >   GfxState*old_state = state;
72 3837a3850,3852
73 >     // restore graphics state
74 >     while(state != old_state)
75 >       restoreState();
76 921a922,925
77 > CharCodeToUnicode* Gfx8BitFont::getCTU() {
78 >     return ctu;
79 > }
80
81 1413a1418,1421
82 > CharCodeToUnicode* GfxCIDFont::getCTU() {
83 >     return ctu;
84 > }
85
86 166a167
87 >   virtual CharCodeToUnicode* getCTU() = 0;
88 206a208
89 >   virtual CharCodeToUnicode* getCTU();
90 215c217
91 <   char *getCharName(int code) { return enc[code]; }
92 ---
93 >   char *getCharName(int code) { return code>=256?0:enc[code]; }
94 268a271
95 >   virtual CharCodeToUnicode* getCTU();
96 23a24
97 > #include "cmyk.h"
98 95c96
99 < GfxColorSpace *GfxColorSpace::parse(Object *csObj) {
100 ---
101 > GfxColorSpace *GfxColorSpace::parse(Object *csObj, StreamColorSpaceMode csMode) {
102 104c105,108
103 <       cs = new GfxDeviceRGBColorSpace();
104 ---
105 >       if(csMode == streamCSDeviceRGBX)
106 >       cs = new GfxDeviceRGBXColorSpace();
107 >       else
108 >       cs = new GfxDeviceRGBColorSpace();
109 117c121,124
110 <       cs = new GfxDeviceRGBColorSpace();
111 ---
112 >       if(csMode == streamCSDeviceRGBX)
113 >         cs = new GfxDeviceRGBColorSpace();
114 >       else
115 >       cs = new GfxDeviceRGBColorSpace();
116 335a343,353
117 > // GfxDeviceRGBXColorSpace
118 > //------------------------------------------------------------------------
119
120 > GfxDeviceRGBXColorSpace::GfxDeviceRGBXColorSpace() {
121 > }
122
123 > GfxColorSpace *GfxDeviceRGBXColorSpace::copy() {
124 >   return new GfxDeviceRGBXColorSpace();
125 > }
126
127 > //------------------------------------------------------------------------
128 492a511,522
129 > /*void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
130 >     unsigned char r,g,b;
131 >     float c = color->c[0];
132 >     float m = color->c[1];
133 >     float y = color->c[2];
134 >     float k = color->c[3];
135 >     convert_cmyk2rgb(c,m,y,k, &r,&g,&b);
136 >     rgb->r = r/255.0;
137 >     rgb->g = g/255.0;
138 >     rgb->b = b/255.0;
139 > }*/
140
141 3189a3220
142 >   int maxPixelForAlloc;
143 3201a3233
144 >   maxPixelForAlloc = (1 << (bits>8?bits:8));
145 3256c3288
146 <       lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
147 ---
148 >       lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
149 3275c3307
150 <       lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
151 ---
152 >       lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
153 3285c3317
154 <       lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
155 ---
156 >       lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
157 3756a3789,3790
158 >   if(pathA) {
159 >       if(path)
160 3757a3792
161 >   }
162 141c141
163 <   static GfxColorSpace *parse(Object *csObj);
164 ---
165 >   static GfxColorSpace *parse(Object *csObj, StreamColorSpaceMode csMode = streamCSNone);
166 254a255,267
167 > // GfxDeviceRGBXColorSpace
168 > //------------------------------------------------------------------------
169
170 > class GfxDeviceRGBXColorSpace: public GfxDeviceRGBColorSpace {
171 > public:
172
173 >   GfxDeviceRGBXColorSpace();
174 >   virtual GfxColorSpace *copy();
175 >   virtual int getNComps() { return 4; }
176 > private:
177 > };
178
179 > //------------------------------------------------------------------------
180 916a917,939
181 >   /* extract path */
182 >   if(fileName) {
183 >     char* cfgFileName = fileName->getCString();
184 >     char* pos1 = strrchr(cfgFileName, '/');
185 >     char* pos2 = strrchr(cfgFileName, '\\');
186 >     char* p = pos1>pos2?pos1:pos2;
187 >     int pos = p ? p-cfgFileName : -1;
188 >     GString*path = new GString(new GString(cfgFileName), 0, (pos < 0 ? strlen(cfgFileName): pos));
189 >     if(pos1>=0)
190 >       path->append('/');
191 >     else if(pos2>=0)
192 >       path->append('\\');
193 >     else
194 > #ifdef WIN32
195 >       path->append('\\');
196 > #else
197 >       path->append('/');
198 > #endif
199 >     this->path = path;
200 >   } else {
201 >     this->path = new GString();
202 >   }
203 >   
204 1116a1140,1175
205 > static char is_absolute(char*filename)
206 > {
207 >     int l = strlen(filename);
208 >     if(filename[0] == '/' || filename[0] == '\\') 
209 >       return 1;
210 >     if(l>2 && filename[1]==':' && (filename[2]=='\\' || filename[2]=='/'))
211 >       return 1;
212 >     return 0;
213 > }
214
215 > static GString* qualify_filename(GString*path, GString*filename)
216 > {
217 >   GString*fullpath = 0;
218 >   char*prefix = "/usr/local/share/xpdf/";
219
220 >   if (!is_absolute(filename->getCString())) {
221 >     /* relative path */
222 >     fullpath = path->copy();
223 >     fullpath->append(filename);
224 >   } else if (!strncmp(filename->getCString(), prefix, strlen(prefix))) {
225 >     /* xpdf default path */
226 >     char*s = strchr(filename->getCString()+strlen(prefix), '/');
227 >     if(s) {
228 >       fullpath = path->copy();
229 >       fullpath->append(s+1);
230 >     } else {
231 >       fullpath = filename->copy();
232 >     }
233 >   } else {
234 >     /* absolute path */
235 >     fullpath = filename->copy();
236 >   }
237 >   //printf("%s -%s-> %s\n", filename->getCString(), path->getCString(), fullpath->getCString());
238 >   return fullpath;
239 > }
240
241 1131c1190
242 <   name = (GString *)tokens->get(1);
243 ---
244 >   name = qualify_filename(this->path, (GString *)tokens->get(1));
245 1133,1134c1192,1193
246 <     error(-1, "Couldn't open 'nameToUnicode' file '%s'",
247 <         name->getCString());
248 ---
249 >     error(-1, "Couldn't open 'nameToUnicode' file '%s' using path '%s'",
250 >         name->getCString(), path->getCString());
251 1162a1222
252
253 1166c1226,1227
254 <   cidToUnicodes->add(collection->copy(), name->copy());
255 ---
256
257 >   cidToUnicodes->add(collection->copy(), qualify_filename(this->path, name));
258 1183c1244,1245
259 <   unicodeToUnicodes->add(font->copy(), file->copy());
260 ---
261
262 >   unicodeToUnicodes->add(font->copy(), qualify_filename(this->path, file));
263 1200c1262,1263
264 <   unicodeMaps->add(encodingName->copy(), name->copy());
265 ---
266
267 >   unicodeMaps->add(encodingName->copy(), qualify_filename(this->path, name));
268 1218c1281,1282
269 <   list->append(dir->copy());
270 ---
271
272 >   list->append(qualify_filename(this->path, dir));
273 1222a1287,1288
274 >   GString *dir;
275
276 1228c1294,1297
277 <   toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
278 ---
279
280 >   dir = (GString *)tokens->get(1);
281
282 >   toUnicodeDirs->append(qualify_filename(this->path, dir));
283 1234a1304
284 >   GString *file;
285 1246c1316,1317
286 <     param->t1.fileName = ((GString *)tokens->get(2))->copy();
287 ---
288 >     file = (GString *)tokens->get(2);
289 >     param->t1.fileName = qualify_filename(this->path, file);
290 1252c1323,1324
291 <     param->tt.fileName = ((GString *)tokens->get(2))->copy();
292 ---
293 >     file = (GString *)tokens->get(2);
294 >     param->tt.fileName = qualify_filename(this->path, file);
295 199c199
296 <   ~GlobalParams();
297 ---
298 >   virtual ~GlobalParams();
299 216,217c216,217
300 <   DisplayFontParam *getDisplayFont(GString *fontName);
301 <   DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
302 ---
303 >   virtual DisplayFontParam *getDisplayFont(GString *fontName);
304 >   virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
305 319c319
306 <   void parseFile(GString *fileName, FILE *f);
307 ---
308 > public: void parseFile(GString *fileName, FILE *f); private:
309 360a361,364
310 >   //----- config file base path
311
312 >   GString*path;
313
314 1517,1521c1517,1524
315 <   symCodeLen = 1;
316 <   i = (numInputSyms + numNewSyms) >> 1;
317 <   while (i) {
318 <     ++symCodeLen;
319 <     i >>= 1;
320 ---
321 >   symCodeLen = 0;
322 >   i = 1;
323 >   while (i < numInputSyms + numNewSyms) {
324 >    ++symCodeLen;
325 >    i <<= 1;
326 >   }
327 >   if (huff && symCodeLen == 0) {
328 >    symCodeLen = 1;
329 1923a1927,1929
330 >   if (huff && symCodeLen == 0) {
331 >     symCodeLen = 1;
332 >   }
333 452a453
334 >   Guint num_components = 0;
335 466c467
336 <           readUWord(&dummy) &&
337 ---
338 >           readUWord(&num_components) &&
339 521a523,525
340 >   if(*csMode == streamCSDeviceRGB && num_components == 4) {
341 >     *csMode = streamCSDeviceRGBX;
342 >   }
343 76a77
344 > static int illegalChars = 0;
345 85a87,89
346 >   if(illegalChars)
347 >       error(0, "Illegal characters in hex string (%d)", illegalChars);
348 >   illegalChars = 0;
349 333c337,338
350 <         error(getPos(), "Illegal digit in hex char in name");
351 ---
352 >         illegalChars++;
353 >         //error(getPos(), "Illegal digit in hex char in name");
354 387,388c392,395
355 <         else
356 <           error(getPos(), "Illegal character <%02x> in hex string", c);
357 ---
358 >         else {
359 >           illegalChars++;
360 >           //error(getPos(), "Illegal character <%02x> in hex string", c);
361 >         }
362 424c431,432
363 <       error(getPos(), "Illegal character '>'");
364 ---
365 >       illegalChars++;
366 >       //error(getPos(), "Illegal character '>'");
367 433c441,442
368 <     error(getPos(), "Illegal character '%c'", c);
369 ---
370 >     //error(getPos(), "Illegal character '%c'", c);
371 >     illegalChars++;
372 462d470
373
374 433d432
375
376 436c435
377 <     error(-1, "Illegal annotation destination");
378 ---
379 >     error(-1, "Illegal annotation destination %d", destObj->getType());
380 471d469
381
382 474c472
383 <     error(-1, "Illegal annotation destination");
384 ---
385 >     error(-1, "Illegal annotation destination %d", destObj->getType());
386 19a20
387 > #include "Object.h"
388 97c98
389 <   virtual void startPage(int pageNum, GfxState *state) {}
390 ---
391 >   virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
392 48a49
393 >   
394 56a58,61
395 >  
396 >   this->ascender = face->ascender;
397 >   this->descender = face->descender;
398
399 230a236,241
400 > int SplashFTFont::getNumChars()
401 > {
402 >   SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
403 >   return ff->face->num_glyphs;
404 > }
405
406 251a263,264
407 >   this->last_advance = -1;
408
409 265c278,280
410 <   if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
411 ---
412 >   int error = 0;
413 >   if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
414 >       fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
415 270a286,287
416 >   this->last_advance = glyph->advance.x/65536.0;
417
418 274c291
419 <   FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
420 ---
421 >   error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
422 275a293,295
423 >   if(error) {
424 >       fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
425 >   }
426 44a45,47
427 >   // return the number of characters in this font
428 >   virtual int getNumChars();
429
430 16d15
431 < #ifndef WIN32
432 18d16
433 < #endif
434 50a51,54
435
436 >   last_advance = -1;
437 >   ascender = -1;
438 >   descender = -1;
439 75a76,78
440 >   // return the number of characters in this font
441 >   virtual int getNumChars() = 0;
442
443 85a89,91
444 >   double ascender;
445 >   double descender;
446 >   double last_advance; //set after getGlyphPath()
447 14,16c14
448 < #ifndef WIN32
449 < #  include <unistd.h>
450 < #endif
451 ---
452 > #include <unistd.h>
453 15a16
454 > #include <unistd.h>
455 705c706
456 < void SplashOutputDev::startPage(int pageNum, GfxState *state) {
457 ---
458 > void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
459 2649,2650c2650
460 <   memset(softMask->getDataPtr(), 0,
461 <        softMask->getRowSize() * softMask->getHeight());
462 ---
463 >   memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
464 2651a2652
465 >   if (tx<softMask->getWidth() && ty<softMask->getHeight())
466 73c73
467 <   virtual void startPage(int pageNum, GfxState *state);
468 ---
469 >   virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
470 198a199,201
471 >   void doUpdateFont(GfxState *state);
472 >   
473 >   SplashPath *convertPath(GfxState *state, GfxPath *path);
474 207,208d209
475 <   SplashPath *convertPath(GfxState *state, GfxPath *path);
476 <   void doUpdateFont(GfxState *state);
477 365a366,367
478 >   return 1;
479
480 397c397
481 <       for (; xx + 7 <= xx0; xx += 8) {
482 ---
483 >       for (; xx + 7 < xx0; xx += 8) {
484 400c400
485 <       if (xx <= xx0) {
486 ---
487 >       if (xx < xx0) {
488 420c420
489 <       for (; xx + 7 <= xx0; xx += 8) {
490 ---
491 >       for (; xx + 7 < xx0; xx += 8) {
492 423c423
493 <       if (xx <= xx0) {
494 ---
495 >       if (xx < xx0) {
496 20a21,22
497 > #else
498 > extern "C" int unlink(char *filename);
499 44c44,45
500 <   streamCSDeviceCMYK
501 ---
502 >   streamCSDeviceCMYK,
503 >   streamCSDeviceRGBX
504 3880c3880
505 < void TextOutputDev::startPage(int pageNum, GfxState *state) {
506 ---
507 > void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
508 172a173
509 >   friend class XMLOutputDev;
510 581c582
511 <   virtual void startPage(int pageNum, GfxState *state);
512 ---
513 >   virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
514 441a442,487
515 > static char* getTempDir()
516 > {
517 > #ifdef WIN32
518 >     char*dir = getenv("TMP");
519 >     if(!dir) dir = getenv("TEMP");
520 >     if(!dir) dir = getenv("tmp");
521 >     if(!dir) dir = getenv("temp");
522 >     if(!dir) dir = "C:\\";
523 > #else
524 >     char* dir = "/tmp/";
525 > #endif
526 >     return dir;
527 > }
528
529 > char* mktmpname(char*ptr) {
530 >     static char tmpbuf[128];
531 >     char*dir = getTempDir();
532 >     int l = strlen(dir);
533 >     char*sep = "";
534 >     if(!ptr)
535 >       ptr = tmpbuf;
536 >     if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
537 > #ifdef WIN32
538 >       sep = "\\";
539 > #else
540 >       sep = "/";
541 > #endif
542 >     }
543
544 >  //   used to be mktemp. This does remove the warnings, but
545 >  //   It's not exactly an improvement.
546 > #ifdef HAVE_LRAND48
547 >     sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
548 > #else
549 > #   ifdef HAVE_RAND
550 >       sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
551 > #   else
552 >       static int count = 1;
553 >       sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
554 >       count ++;
555 > #   endif
556 > #endif
557 >      return ptr;
558 > }
559
560
561 463c509
562 <     sprintf(buf, "%d", t + i);
563 ---
564 >     sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
565 471,472c517
566 <       delete s;
567 <       return gFalse;
568 ---
569 >         continue;
570 481a527
571 >   fprintf(stderr, "Couldn't create temporary file\n");
572 492c538
573 <   if (!(s = tmpnam(NULL))) {
574 ---
575 >   if (!(s = mktmpname(NULL))) {
576 519c565
577 <     if (!(s = tmpnam(NULL))) {
578 ---
579 >     if (!(s = mktmpname(NULL))) {
580 536c582
581 <     if (!(s = tmpnam(NULL))) {
582 ---
583 >     if (!(s = mktmpname(NULL))) {
584 60a61,63
585 > /* create a temporary filename */
586 > char* mktmpname(char*ptr);
587