1 --- xpdf/Catalog.cc.orig 2010-05-18 11:22:18.000000000 -0700
2 +++ xpdf/Catalog.cc 2010-05-18 11:22:18.000000000 -0700
5 error(-1, "Kids object (page %d) is wrong type (%s)",
6 start+1, kids.getTypeName());
10 for (i = 0; i < kids.arrayGetLength(); ++i) {
11 kids.arrayGetNF(i, &kidRef);
12 --- xpdf/CharCodeToUnicode.cc.orig 2010-05-18 11:22:18.000000000 -0700
13 +++ xpdf/CharCodeToUnicode.cc 2010-05-18 11:22:18.000000000 -0700
17 char tok1[256], tok2[256], tok3[256];
18 - int nDigits, n1, n2, n3;
19 + int maxCode, n1, n2, n3;
21 CharCode code1, code2;
25 - nDigits = nBits / 4;
26 + maxCode = (nBits == 8) ? 0xff : (nBits == 16) ? 0xffff : 0xffffffff;
27 pst = new PSTokenizer(getCharFunc, data);
28 pst->getToken(tok1, sizeof(tok1), &n1);
29 while (pst->getToken(tok2, sizeof(tok2), &n2)) {
31 error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
34 - if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
35 + if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' &&
36 tok2[0] == '<' && tok2[n2 - 1] == '>')) {
37 - error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
38 + error(-1, "Illegal entry in bfchar block in ToUnicode CMap.");
41 tok1[n1 - 1] = tok2[n2 - 1] = '\0';
43 error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
46 + if (code1 > maxCode) {
47 + error(-1, "Invalid entry in bfchar block in ToUnicode CMap");
49 addMapping(code1, tok2 + 1, n2 - 2, 0);
51 pst->getToken(tok1, sizeof(tok1), &n1);
53 error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
56 - if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
57 - n2 == 2 + nDigits && tok2[0] == '<' && tok2[n2 - 1] == '>')) {
58 + if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' &&
59 + tok2[0] == '<' && tok2[n2 - 1] == '>')) {
60 error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
64 error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
67 + if (code1 > maxCode || code2 > maxCode) {
68 + error(-1, "Invalid entry in bfrange block in ToUnicode CMap");
71 if (!strcmp(tok3, "[")) {
73 while (pst->getToken(tok1, sizeof(tok1), &n1) &&
77 mapLen = (code + 256) & ~255;
79 map = (Unicode *)greallocn(map, mapLen, sizeof(Unicode));
81 + /* we sometimes get overflows for files trying to use 0xffffffff as charcode */
85 for (i = oldLen; i < mapLen; ++i) {
88 --- xpdf/CoreOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
89 +++ xpdf/CoreOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
92 void CoreOutputDev::clear() {
95 + startPage(0, NULL, 0,0,0,0);
97 --- xpdf/Decrypt.cc.orig 2010-05-18 11:22:18.000000000 -0700
98 +++ xpdf/Decrypt.cc 2010-05-18 11:22:18.000000000 -0700
103 + if(!n || n>16) n=16;
104 for (i = 15; i >= n; --i) {
105 s->buf[i] = s->buf[i-n];
107 --- xpdf/Gfx.cc.orig 2010-05-18 11:22:18.000000000 -0700
108 +++ xpdf/Gfx.cc 2010-05-18 11:22:18.000000000 -0700
110 fontChanged = gFalse;
113 - out->startPage(pageNum, state);
115 + out->startPage(pageNum, state, cropBox->x1,cropBox->y1,cropBox->x2,cropBox->y2);
117 + out->startPage(pageNum, state, 0,0,0,0);
119 out->setDefaultCTM(state->getCTM());
120 out->updateAll(state);
121 for (i = 0; i < 6; ++i) {
123 abortCheckCbkData = abortCheckCbkDataA;
128 state->moveTo(cropBox->x1, cropBox->y1);
129 state->lineTo(cropBox->x2, cropBox->y1);
137 Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
138 @@ -3182,8 +3188,11 @@
139 u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
140 &dx, &dy, &originX, &originY);
141 dx = dx * state->getFontSize() + state->getCharSpace();
142 - if (n == 1 && *p == ' ') {
143 - dx += state->getWordSpace();
144 + if (n == 1 && (*p == ' ' || *p == 0)) {
145 + double w=state->getWordSpace();
147 + w=state->getFontSize()/3; // workaround for zero word space
150 dx *= state->getHorizScaling();
151 dy *= state->getFontSize();
152 @@ -3476,11 +3485,13 @@
155 if (!obj1.isNull()) {
156 - colorSpace = GfxColorSpace::parse(&obj1);
157 + colorSpace = GfxColorSpace::parse(&obj1, csMode);
158 } else if (csMode == streamCSDeviceGray) {
159 colorSpace = new GfxDeviceGrayColorSpace();
160 } else if (csMode == streamCSDeviceRGB) {
161 colorSpace = new GfxDeviceRGBColorSpace();
162 + } else if (csMode == streamCSDeviceRGBX) {
163 + colorSpace = new GfxDeviceRGBXColorSpace();
164 } else if (csMode == streamCSDeviceCMYK) {
165 colorSpace = new GfxDeviceCMYKColorSpace();
167 @@ -3824,6 +3835,7 @@
168 out->beginTransparencyGroup(state, bbox, blendingColorSpace,
169 isolated, knockout, softMask);
171 + GfxState*old_state = state;
173 // set new base matrix
174 for (i = 0; i < 6; ++i) {
175 @@ -3835,6 +3847,9 @@
176 display(str, gFalse);
178 if (softMask || transpGroup) {
179 + // restore graphics state
180 + while(state != old_state)
182 out->endTransparencyGroup(state);
185 --- xpdf/GfxFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
186 +++ xpdf/GfxFont.cc 2010-05-18 11:22:18.000000000 -0700
188 embFontID = obj2.getRef();
189 if (type != fontType1) {
190 error(-1, "Mismatch between font type and embedded font file");
192 + type = isCIDFont() ? fontCIDType0 : fontType1;
200 +CharCodeToUnicode* Gfx8BitFont::getCTU() {
204 CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
207 @@ -1411,6 +1415,10 @@
211 +CharCodeToUnicode* GfxCIDFont::getCTU() {
215 int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
216 Unicode *u, int uSize, int *uLen,
217 double *dx, double *dy, double *ox, double *oy) {
218 --- xpdf/GfxFont.h.orig 2010-05-18 11:22:18.000000000 -0700
219 +++ xpdf/GfxFont.h 2010-05-18 11:22:18.000000000 -0700
221 virtual int getNextChar(char *s, int len, CharCode *code,
222 Unicode *u, int uSize, int *uLen,
223 double *dx, double *dy, double *ox, double *oy) = 0;
224 + virtual CharCodeToUnicode* getCTU() = 0;
229 virtual int getNextChar(char *s, int len, CharCode *code,
230 Unicode *u, int uSize, int *uLen,
231 double *dx, double *dy, double *ox, double *oy);
232 + virtual CharCodeToUnicode* getCTU();
234 // Return the encoding.
235 char **getEncoding() { return enc; }
237 CharCodeToUnicode *getToUnicode();
239 // Return the character name associated with <code>.
240 - char *getCharName(int code) { return enc[code]; }
241 + char *getCharName(int code) { return code>=256?0:enc[code]; }
243 // Returns true if the PDF font specified an encoding.
244 GBool getHasEncoding() { return hasEncoding; }
246 virtual int getNextChar(char *s, int len, CharCode *code,
247 Unicode *u, int uSize, int *uLen,
248 double *dx, double *dy, double *ox, double *oy);
249 + virtual CharCodeToUnicode* getCTU();
251 // Return the writing mode (0=horizontal, 1=vertical).
252 virtual int getWMode();
253 --- xpdf/GfxState.cc.orig 2010-05-18 11:22:18.000000000 -0700
254 +++ xpdf/GfxState.cc 2010-05-18 11:22:18.000000000 -0700
258 #include "GfxState.h"
261 //------------------------------------------------------------------------
264 GfxColorSpace::~GfxColorSpace() {
267 -GfxColorSpace *GfxColorSpace::parse(Object *csObj) {
268 +GfxColorSpace *GfxColorSpace::parse(Object *csObj, StreamColorSpaceMode csMode) {
273 if (csObj->isName("DeviceGray") || csObj->isName("G")) {
274 cs = new GfxDeviceGrayColorSpace();
275 } else if (csObj->isName("DeviceRGB") || csObj->isName("RGB")) {
276 - cs = new GfxDeviceRGBColorSpace();
277 + if(csMode == streamCSDeviceRGBX)
278 + cs = new GfxDeviceRGBXColorSpace();
280 + cs = new GfxDeviceRGBColorSpace();
281 } else if (csObj->isName("DeviceCMYK") || csObj->isName("CMYK")) {
282 cs = new GfxDeviceCMYKColorSpace();
283 } else if (csObj->isName("Pattern")) {
285 if (obj1.isName("DeviceGray") || obj1.isName("G")) {
286 cs = new GfxDeviceGrayColorSpace();
287 } else if (obj1.isName("DeviceRGB") || obj1.isName("RGB")) {
288 - cs = new GfxDeviceRGBColorSpace();
289 + if(csMode == streamCSDeviceRGBX)
290 + cs = new GfxDeviceRGBColorSpace();
292 + cs = new GfxDeviceRGBColorSpace();
293 } else if (obj1.isName("DeviceCMYK") || obj1.isName("CMYK")) {
294 cs = new GfxDeviceCMYKColorSpace();
295 } else if (obj1.isName("CalGray")) {
299 //------------------------------------------------------------------------
300 +// GfxDeviceRGBXColorSpace
301 +//------------------------------------------------------------------------
303 +GfxDeviceRGBXColorSpace::GfxDeviceRGBXColorSpace() {
306 +GfxColorSpace *GfxDeviceRGBXColorSpace::copy() {
307 + return new GfxDeviceRGBXColorSpace();
310 +//------------------------------------------------------------------------
311 // GfxCalRGBColorSpace
312 //------------------------------------------------------------------------
315 - 0.11 * color->c[2] + 0.5));
318 +/*void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
319 + unsigned char r,g,b;
320 + float c = color->c[0];
321 + float m = color->c[1];
322 + float y = color->c[2];
323 + float k = color->c[3];
324 + convert_cmyk2rgb(c,m,y,k, &r,&g,&b);
330 void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
331 double c, m, y, k, c1, m1, y1, k1, r, g, b, x;
333 @@ -3187,6 +3217,7 @@
334 GfxIndexedColorSpace *indexedCS;
335 GfxSeparationColorSpace *sepCS;
336 int maxPixel, indexHigh;
337 + int maxPixelForAlloc;
341 @@ -3199,6 +3230,7 @@
342 // bits per component and color space
344 maxPixel = (1 << bits) - 1;
345 + maxPixelForAlloc = (1 << (bits>8?bits:8));
346 colorSpace = colorSpaceA;
349 @@ -3253,7 +3285,7 @@
350 lookup2 = indexedCS->getLookup();
351 colorSpace2->getDefaultRanges(x, y, indexHigh);
352 for (k = 0; k < nComps2; ++k) {
353 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
354 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
355 sizeof(GfxColorComp));
356 for (i = 0; i <= maxPixel; ++i) {
357 j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
358 @@ -3272,7 +3304,7 @@
359 nComps2 = colorSpace2->getNComps();
360 sepFunc = sepCS->getFunc();
361 for (k = 0; k < nComps2; ++k) {
362 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
363 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
364 sizeof(GfxColorComp));
365 for (i = 0; i <= maxPixel; ++i) {
366 x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
367 @@ -3282,7 +3314,7 @@
370 for (k = 0; k < nComps; ++k) {
371 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
372 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
373 sizeof(GfxColorComp));
374 for (i = 0; i <= maxPixel; ++i) {
375 lookup[k][i] = dblToCol(decodeLow[k] +
376 @@ -3754,7 +3786,10 @@
379 void GfxState::setPath(GfxPath *pathA) {
387 --- xpdf/GfxState.h.orig 2010-05-18 11:22:18.000000000 -0700
388 +++ xpdf/GfxState.h 2010-05-18 11:22:18.000000000 -0700
390 virtual GfxColorSpaceMode getMode() = 0;
392 // Construct a color space. Returns NULL if unsuccessful.
393 - static GfxColorSpace *parse(Object *csObj);
394 + static GfxColorSpace *parse(Object *csObj, StreamColorSpaceMode csMode = streamCSNone);
396 // Convert to gray, RGB, or CMYK.
397 virtual void getGray(GfxColor *color, GfxGray *gray) = 0;
401 //------------------------------------------------------------------------
402 +// GfxDeviceRGBXColorSpace
403 +//------------------------------------------------------------------------
405 +class GfxDeviceRGBXColorSpace: public GfxDeviceRGBColorSpace {
408 + GfxDeviceRGBXColorSpace();
409 + virtual GfxColorSpace *copy();
410 + virtual int getNComps() { return 4; }
414 +//------------------------------------------------------------------------
415 // GfxCalRGBColorSpace
416 //------------------------------------------------------------------------
418 --- xpdf/GlobalParams.cc.orig 2010-05-18 11:22:18.000000000 -0700
419 +++ xpdf/GlobalParams.cc 2010-05-18 11:22:18.000000000 -0700
426 + char* cfgFileName = fileName->getCString();
427 + char* pos1 = strrchr(cfgFileName, '/');
428 + char* pos2 = strrchr(cfgFileName, '\\');
429 + char* p = pos1>pos2?pos1:pos2;
430 + int pos = p ? p-cfgFileName : -1;
431 + GString*path = new GString(new GString(cfgFileName), 0, (pos < 0 ? strlen(cfgFileName): pos));
435 + path->append('\\');
438 + path->append('\\');
444 + this->path = new GString();
448 while (getLine(buf, sizeof(buf) - 1, f)) {
449 parseLine(buf, fileName, line);
450 @@ -1114,6 +1137,42 @@
451 deleteGList(tokens, GString);
454 +static char is_absolute(char*filename)
456 + int l = strlen(filename);
457 + if(filename[0] == '/' || filename[0] == '\\')
459 + if(l>2 && filename[1]==':' && (filename[2]=='\\' || filename[2]=='/'))
464 +static GString* qualify_filename(GString*path, GString*filename)
466 + GString*fullpath = 0;
467 + char*prefix = "/usr/local/share/xpdf/";
469 + if (!is_absolute(filename->getCString())) {
470 + /* relative path */
471 + fullpath = path->copy();
472 + fullpath->append(filename);
473 + } else if (!strncmp(filename->getCString(), prefix, strlen(prefix))) {
474 + /* xpdf default path */
475 + char*s = strchr(filename->getCString()+strlen(prefix), '/');
477 + fullpath = path->copy();
478 + fullpath->append(s+1);
480 + fullpath = filename->copy();
483 + /* absolute path */
484 + fullpath = filename->copy();
486 + //printf("%s -%s-> %s\n", filename->getCString(), path->getCString(), fullpath->getCString());
490 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
493 @@ -1128,10 +1187,10 @@
494 fileName->getCString(), line);
497 - name = (GString *)tokens->get(1);
498 + name = qualify_filename(this->path, (GString *)tokens->get(1));
499 if (!(f = fopen(name->getCString(), "r"))) {
500 - error(-1, "Couldn't open 'nameToUnicode' file '%s'",
501 - name->getCString());
502 + error(-1, "Couldn't open 'nameToUnicode' file '%s' using path '%s'",
503 + name->getCString(), path->getCString());
507 @@ -1160,10 +1219,12 @@
509 collection = (GString *)tokens->get(1);
510 name = (GString *)tokens->get(2);
512 if ((old = (GString *)cidToUnicodes->remove(collection))) {
515 - cidToUnicodes->add(collection->copy(), name->copy());
517 + cidToUnicodes->add(collection->copy(), qualify_filename(this->path, name));
520 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
521 @@ -1180,7 +1241,8 @@
522 if ((old = (GString *)unicodeToUnicodes->remove(font))) {
525 - unicodeToUnicodes->add(font->copy(), file->copy());
527 + unicodeToUnicodes->add(font->copy(), qualify_filename(this->path, file));
530 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
531 @@ -1197,7 +1259,8 @@
532 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
535 - unicodeMaps->add(encodingName->copy(), name->copy());
537 + unicodeMaps->add(encodingName->copy(), qualify_filename(this->path, name));
540 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
541 @@ -1215,23 +1278,30 @@
543 cMapDirs->add(collection->copy(), list);
545 - list->append(dir->copy());
547 + list->append(qualify_filename(this->path, dir));
550 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
554 if (tokens->getLength() != 2) {
555 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
556 fileName->getCString(), line);
559 - toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
561 + dir = (GString *)tokens->get(1);
563 + toUnicodeDirs->append(qualify_filename(this->path, dir));
566 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
567 DisplayFontParamKind kind,
568 GString *fileName, int line) {
569 DisplayFontParam *param, *old;
572 if (tokens->getLength() < 2) {
574 @@ -1243,13 +1313,15 @@
575 if (tokens->getLength() != 3) {
578 - param->t1.fileName = ((GString *)tokens->get(2))->copy();
579 + file = (GString *)tokens->get(2);
580 + param->t1.fileName = qualify_filename(this->path, file);
583 if (tokens->getLength() != 3) {
586 - param->tt.fileName = ((GString *)tokens->get(2))->copy();
587 + file = (GString *)tokens->get(2);
588 + param->tt.fileName = qualify_filename(this->path, file);
592 --- xpdf/GlobalParams.h.orig 2010-05-18 11:22:18.000000000 -0700
593 +++ xpdf/GlobalParams.h 2010-05-18 11:22:18.000000000 -0700
596 GlobalParams(char *cfgFileName);
599 + virtual ~GlobalParams();
601 void setBaseDir(char *dir);
602 void setupBaseFonts(char *dir);
604 FILE *getUnicodeMapFile(GString *encodingName);
605 FILE *findCMapFile(GString *collection, GString *cMapName);
606 FILE *findToUnicodeFile(GString *name);
607 - DisplayFontParam *getDisplayFont(GString *fontName);
608 - DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
609 + virtual DisplayFontParam *getDisplayFont(GString *fontName);
610 + virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
611 GString *getPSFile();
612 int getPSPaperWidth();
613 int getPSPaperHeight();
617 void createDefaultKeyBindings();
618 - void parseFile(GString *fileName, FILE *f);
619 +public: void parseFile(GString *fileName, FILE *f); private:
620 void parseNameToUnicode(GList *tokens, GString *fileName, int line);
621 void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
622 void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line);
624 GBool loadPlugin(char *type, char *name);
627 + //----- config file base path
631 //----- static tables
633 NameToCharCode * // mapping from char name to
634 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
635 +++ xpdf/JBIG2Stream.cc 2010-05-18 11:22:18.000000000 -0700
636 @@ -1514,11 +1514,14 @@
639 // compute symbol code length
641 - i = (numInputSyms + numNewSyms) >> 1;
647 + while (i < numInputSyms + numNewSyms) {
651 + if (huff && symCodeLen == 0) {
655 // get the input symbol bitmaps
656 @@ -1921,6 +1924,9 @@
660 + if (huff && symCodeLen == 0) {
664 // get the symbol bitmaps
665 syms = (JBIG2Bitmap **)gmallocn(numSyms, sizeof(JBIG2Bitmap *));
666 --- xpdf/JPXStream.cc.orig 2010-05-18 11:22:18.000000000 -0700
667 +++ xpdf/JPXStream.cc 2010-05-18 11:22:18.000000000 -0700
669 haveCompMap = gFalse;
670 haveChannelDefn = gFalse;
682 GBool haveBPC, haveCSMode;
684 csPrec = 0; // make gcc happy
685 + Guint num_components = 0;
686 haveBPC = haveCSMode = gFalse;
688 if (str->lookChar() == 0xff) {
691 if (readULong(&dummy) &&
693 - readUWord(&dummy) &&
694 + readUWord(&num_components) &&
702 + if(*csMode == streamCSDeviceRGB && num_components == 4) {
703 + *csMode = streamCSDeviceRGBX;
708 --- xpdf/Lexer.cc.orig 2010-05-18 11:22:18.000000000 -0700
709 +++ xpdf/Lexer.cc 2010-05-18 11:22:18.000000000 -0700
711 curStr.streamReset();
714 +static int illegalChars = 0;
717 if (!curStr.isNone()) {
723 + error(0, "Illegal characters in hex string (%d)", illegalChars);
727 int Lexer::getChar() {
729 } else if (c2 >= 'a' && c2 <= 'f') {
732 - error(getPos(), "Illegal digit in hex char in name");
734 + //error(getPos(), "Illegal digit in hex char in name");
740 else if (c >= 'a' && c <= 'f')
743 - error(getPos(), "Illegal character <%02x> in hex string", c);
746 + //error(getPos(), "Illegal character <%02x> in hex string", c);
749 if (n == tokBufSize) {
753 obj->initCmd(tokBuf);
755 - error(getPos(), "Illegal character '>'");
757 + //error(getPos(), "Illegal character '>'");
765 - error(getPos(), "Illegal character '%c'", c);
766 + //error(getPos(), "Illegal character '%c'", c);
779 --- xpdf/Link.cc.orig 2010-05-18 11:22:18.000000000 -0700
780 +++ xpdf/Link.cc 2010-05-18 11:22:18.000000000 -0700
788 - error(-1, "Illegal annotation destination");
789 + error(-1, "Illegal annotation destination %d", destObj->getType());
800 - error(-1, "Illegal annotation destination");
801 + error(-1, "Illegal annotation destination %d", destObj->getType());
805 --- xpdf/OutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
806 +++ xpdf/OutputDev.h 2010-05-18 11:22:18.000000000 -0700
810 #include "CharTypes.h"
819 - virtual void startPage(int pageNum, GfxState *state) {}
820 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
823 virtual void endPage() {}
824 --- xpdf/SplashFTFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
825 +++ xpdf/SplashFTFont.cc 2010-05-18 11:22:18.000000000 -0700
829 face = fontFileA->face;
831 if (FT_New_Size(face, &sizeObj)) {
835 if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
839 + this->ascender = face->ascender;
840 + this->descender = face->descender;
842 // if the textMat values are too small, FreeType's fixed point
843 // arithmetic doesn't work so well
844 textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
849 +int SplashFTFont::getNumChars()
851 + SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
852 + return ff->face->num_glyphs;
855 SplashPath *SplashFTFont::getGlyphPath(int c) {
856 static FT_Outline_Funcs outlineFuncs = {
857 #if FREETYPE_MINOR <= 1
862 + this->last_advance = -1;
864 ff = (SplashFTFontFile *)fontFile;
865 ff->face->size = sizeObj;
866 FT_Set_Transform(ff->face, &textMatrix, NULL);
867 @@ -262,17 +275,24 @@
868 // skip the TrueType notdef glyph
871 - if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
873 + if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
874 + fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
877 if (FT_Get_Glyph(slot, &glyph)) {
880 + this->last_advance = glyph->advance.x/65536.0;
882 path.path = new SplashPath();
883 path.textScale = textScale;
884 path.needClose = gFalse;
885 - FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
886 + error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
887 &outlineFuncs, &path);
889 + fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
891 if (path.needClose) {
894 --- xpdf/SplashFTFont.h.orig 2010-05-18 11:22:18.000000000 -0700
895 +++ xpdf/SplashFTFont.h 2010-05-18 11:22:18.000000000 -0700
897 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
898 SplashGlyphBitmap *bitmap);
900 + // return the number of characters in this font
901 + virtual int getNumChars();
903 // Return the path for a glyph.
904 virtual SplashPath *getGlyphPath(int c);
906 --- xpdf/SplashFTFontEngine.cc.orig 2010-05-18 11:22:18.000000000 -0700
907 +++ xpdf/SplashFTFontEngine.cc 2010-05-18 11:22:18.000000000 -0700
918 --- xpdf/SplashFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
919 +++ xpdf/SplashFont.cc 2010-05-18 11:22:18.000000000 -0700
923 xMin = yMin = xMax = yMax = 0;
930 void SplashFont::initCache() {
931 --- xpdf/SplashFont.h.orig 2010-05-18 11:22:18.000000000 -0700
932 +++ xpdf/SplashFont.h 2010-05-18 11:22:18.000000000 -0700
934 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
935 SplashGlyphBitmap *bitmap) = 0;
937 + // return the number of characters in this font
938 + virtual int getNumChars() = 0;
940 // Return the path for a glyph.
941 virtual SplashPath *getGlyphPath(int c) = 0;
944 void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
945 { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
949 + double last_advance; //set after getGlyphPath()
952 SplashFontFile *fontFile;
953 --- xpdf/SplashFontFile.cc.orig 2010-05-18 11:22:18.000000000 -0700
954 +++ xpdf/SplashFontFile.cc 2010-05-18 11:22:18.000000000 -0700
960 -# include <unistd.h>
964 #include "SplashFontFile.h"
965 #include "SplashFontFileID.h"
966 --- xpdf/SplashOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
967 +++ xpdf/SplashOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
975 #include "GlobalParams.h"
980 -void SplashOutputDev::startPage(int pageNum, GfxState *state) {
981 +void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
985 @@ -2646,9 +2647,9 @@
987 softMask = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(),
988 1, splashModeMono8, gFalse);
989 - memset(softMask->getDataPtr(), 0,
990 - softMask->getRowSize() * softMask->getHeight());
991 + memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
992 p = softMask->getDataPtr() + ty * softMask->getRowSize() + tx;
993 + if (tx<softMask->getWidth() && ty<softMask->getHeight())
994 for (y = 0; y < tBitmap->getHeight(); ++y) {
995 for (x = 0; x < tBitmap->getWidth(); ++x) {
996 tBitmap->getPixel(x, y, color);
997 --- xpdf/SplashOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
998 +++ xpdf/SplashOutputDev.h 2010-05-18 11:22:18.000000000 -0700
1000 //----- initialization and control
1003 - virtual void startPage(int pageNum, GfxState *state);
1004 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
1007 virtual void endPage();
1009 virtual void setVectorAntialias(GBool vaa);
1012 + void doUpdateFont(GfxState *state);
1014 + SplashPath *convertPath(GfxState *state, GfxPath *path);
1017 void setupScreenParams(double hDPI, double vDPI);
1020 SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
1022 - SplashPath *convertPath(GfxState *state, GfxPath *path);
1023 - void doUpdateFont(GfxState *state);
1024 void drawType3Glyph(T3FontCache *t3Font,
1025 T3FontCacheTag *tag, Guchar *data);
1026 static GBool imageMaskSrc(void *data, SplashColorPtr line);
1027 --- xpdf/SplashScreen.cc.orig 2010-05-18 11:22:18.000000000 -0700
1028 +++ xpdf/SplashScreen.cc 2010-05-18 11:22:18.000000000 -0700
1030 int SplashScreen::test(int x, int y, Guchar value) {
1035 if (value < minVal) {
1038 --- xpdf/SplashXPathScanner.cc.orig 2010-05-18 11:22:18.000000000 -0700
1039 +++ xpdf/SplashXPathScanner.cc 2010-05-18 11:22:18.000000000 -0700
1040 @@ -394,10 +394,10 @@
1044 - for (; xx + 7 <= xx0; xx += 8) {
1045 + for (; xx + 7 < xx0; xx += 8) {
1050 *p &= 0xff >> (xx0 & 7);
1053 @@ -417,10 +417,10 @@
1057 - for (; xx + 7 <= xx0; xx += 8) {
1058 + for (; xx + 7 < xx0; xx += 8) {
1063 *p &= 0xff >> (xx0 & 7);
1066 --- xpdf/Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
1067 +++ xpdf/Stream.cc 2010-05-18 11:22:18.000000000 -0700
1073 +extern "C" int unlink(char *filename);
1077 @@ -2456,6 +2460,9 @@
1078 // check for an EOB run
1080 while (i <= scanInfo.lastCoeff) {
1086 if ((bit = readBit()) == EOF) {
1087 @@ -2480,6 +2487,9 @@
1097 @@ -2505,6 +2515,9 @@
1100 while (i <= scanInfo.lastCoeff) {
1106 if ((bit = readBit()) == EOF) {
1107 @@ -2527,6 +2540,9 @@
1115 while (data[j] != 0) {
1116 if ((bit = readBit()) == EOF) {
1117 @@ -2535,6 +2551,9 @@
1119 data[j] += 1 << scanInfo.al;
1127 --- xpdf/Stream.h.orig 2010-05-18 11:22:18.000000000 -0700
1128 +++ xpdf/Stream.h 2010-05-18 11:22:18.000000000 -0700
1133 - streamCSDeviceCMYK
1134 + streamCSDeviceCMYK,
1135 + streamCSDeviceRGBX
1138 //------------------------------------------------------------------------
1139 --- xpdf/TextOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
1140 +++ xpdf/TextOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
1141 @@ -3877,7 +3877,7 @@
1145 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
1146 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
1147 text->startPage(state);
1150 --- xpdf/TextOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
1151 +++ xpdf/TextOutputDev.h 2010-05-18 11:22:18.000000000 -0700
1153 friend class TextFlow;
1154 friend class TextWordList;
1155 friend class TextPage;
1156 + friend class XMLOutputDev;
1159 //------------------------------------------------------------------------
1161 //----- initialization and control
1164 - virtual void startPage(int pageNum, GfxState *state);
1165 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
1168 virtual void endPage();
1169 --- xpdf/gfile.cc.orig 2010-05-18 11:22:18.000000000 -0700
1170 +++ xpdf/gfile.cc 2010-05-18 11:22:18.000000000 -0700
1171 @@ -439,6 +439,52 @@
1175 +static char* getTempDir()
1178 + char*dir = getenv("TMP");
1179 + if(!dir) dir = getenv("TEMP");
1180 + if(!dir) dir = getenv("tmp");
1181 + if(!dir) dir = getenv("temp");
1182 + if(!dir) dir = "C:\\";
1184 + char* dir = "/tmp/";
1189 +char* mktmpname(char*ptr) {
1190 + static char tmpbuf[128];
1191 + char*dir = getTempDir();
1192 + int l = strlen(dir);
1196 + if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
1204 + // used to be mktemp. This does remove the warnings, but
1205 + // It's not exactly an improvement.
1206 +#ifdef HAVE_LRAND48
1207 + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
1210 + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
1212 + static int count = 1;
1213 + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
1221 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
1223 //---------- Win32 ----------
1226 t = (int)time(NULL);
1227 for (i = 0; i < 1000; ++i) {
1228 - sprintf(buf, "%d", t + i);
1229 + sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
1230 s2 = s->copy()->append(buf);
1234 if (!(f2 = fopen(s2->getCString(), "r"))) {
1235 if (!(f2 = fopen(s2->getCString(), mode))) {
1247 + fprintf(stderr, "Couldn't create temporary file\n");
1250 #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
1252 // with this file name after the tmpnam call and before the fopen
1253 // call. I will happily accept fixes to this function for non-Unix
1255 - if (!(s = tmpnam(NULL))) {
1256 + if (!(s = mktmpname(NULL))) {
1259 *name = new GString(s);
1261 (*name)->append("/XXXXXX")->append(ext);
1262 fd = mkstemps((*name)->getCString(), strlen(ext));
1264 - if (!(s = tmpnam(NULL))) {
1265 + if (!(s = mktmpname(NULL))) {
1268 *name = new GString(s);
1270 (*name)->append("/XXXXXX");
1271 fd = mkstemp((*name)->getCString());
1272 #else // HAVE_MKSTEMP
1273 - if (!(s = tmpnam(NULL))) {
1274 + if (!(s = mktmpname(NULL))) {
1277 *name = new GString(s);
1278 --- xpdf/gfile.h.orig 2010-05-18 11:22:18.000000000 -0700
1279 +++ xpdf/gfile.h 2010-05-18 11:22:18.000000000 -0700
1281 // Get current directory.
1282 extern GString *getCurrentDir();
1284 +/* create a temporary filename */
1285 +char* mktmpname(char*ptr);
1287 // Append a file name to a path string. <path> may be an empty
1288 // string, denoting the current directory). Returns <path>.
1289 extern GString *appendToPath(GString *path, char *fileName);
1290 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:33:21.000000000 -0700
1291 +++ xpdf/JBIG2Stream.cc 2010-06-03 16:55:03.000000000 -0700
1294 //========================================================================
1297 +//========================================================================
1299 +// Modified under the Poppler project - http://poppler.freedesktop.org
1301 +// All changes made under the Poppler project to this file are licensed
1302 +// under GPL version 2 or later
1304 +// Copyright (C) 2006 Raj Kumar <rkumar@archive.org>
1305 +// Copyright (C) 2006 Paul Walmsley <paul@booyaka.com>
1306 +// Copyright (C) 2006-2009 Albert Astals Cid <aacid@kde.org>
1307 +// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
1309 +// To see a description of the changes please see the Changelog file that
1310 +// came with your tarball or type make ChangeLog if you are building from git
1312 +//========================================================================
1314 +#include <config.h>
1316 #ifdef USE_GCC_PRAGMAS
1317 #pragma implementation
1320 //------------------------------------------------------------------------
1322 -static int contextSize[4] = { 16, 13, 10, 10 };
1323 -static int refContextSize[2] = { 13, 10 };
1324 +static const int contextSize[4] = { 16, 13, 10, 10 };
1325 +static const int refContextSize[2] = { 13, 10 };
1327 //------------------------------------------------------------------------
1328 // JBIG2HuffmanTable
1333 -JBIG2HuffmanTable huffTableA[] = {
1334 +static JBIG2HuffmanTable huffTableA[] = {
1336 { 16, 2, 8, 0x002 },
1337 { 272, 3, 16, 0x006 },
1339 { 0, 0, jbig2HuffmanEOT, 0 }
1342 -JBIG2HuffmanTable huffTableB[] = {
1343 +static JBIG2HuffmanTable huffTableB[] = {
1348 { 0, 0, jbig2HuffmanEOT, 0 }
1351 -JBIG2HuffmanTable huffTableC[] = {
1352 +static JBIG2HuffmanTable huffTableC[] = {
1357 { 0, 0, jbig2HuffmanEOT, 0 }
1360 -JBIG2HuffmanTable huffTableD[] = {
1361 +static JBIG2HuffmanTable huffTableD[] = {
1366 { 0, 0, jbig2HuffmanEOT, 0 }
1369 -JBIG2HuffmanTable huffTableE[] = {
1370 +static JBIG2HuffmanTable huffTableE[] = {
1375 { 0, 0, jbig2HuffmanEOT, 0 }
1378 -JBIG2HuffmanTable huffTableF[] = {
1379 +static JBIG2HuffmanTable huffTableF[] = {
1381 { 128, 3, 7, 0x002 },
1382 { 256, 3, 8, 0x003 },
1384 { 0, 0, jbig2HuffmanEOT, 0 }
1387 -JBIG2HuffmanTable huffTableG[] = {
1388 +static JBIG2HuffmanTable huffTableG[] = {
1389 { -512, 3, 8, 0x000 },
1390 { 256, 3, 8, 0x001 },
1391 { 512, 3, 9, 0x002 },
1393 { 0, 0, jbig2HuffmanEOT, 0 }
1396 -JBIG2HuffmanTable huffTableH[] = {
1397 +static JBIG2HuffmanTable huffTableH[] = {
1399 { 0, 2, jbig2HuffmanOOB, 0x001 },
1402 { 0, 0, jbig2HuffmanEOT, 0 }
1405 -JBIG2HuffmanTable huffTableI[] = {
1406 +static JBIG2HuffmanTable huffTableI[] = {
1407 { 0, 2, jbig2HuffmanOOB, 0x000 },
1408 { -1, 3, 1, 0x002 },
1411 { 0, 0, jbig2HuffmanEOT, 0 }
1414 -JBIG2HuffmanTable huffTableJ[] = {
1415 +static JBIG2HuffmanTable huffTableJ[] = {
1416 { -2, 2, 2, 0x000 },
1418 { 0, 2, jbig2HuffmanOOB, 0x002 },
1420 { 0, 0, jbig2HuffmanEOT, 0 }
1423 -JBIG2HuffmanTable huffTableK[] = {
1424 +static JBIG2HuffmanTable huffTableK[] = {
1429 { 0, 0, jbig2HuffmanEOT, 0 }
1432 -JBIG2HuffmanTable huffTableL[] = {
1433 +static JBIG2HuffmanTable huffTableL[] = {
1438 { 0, 0, jbig2HuffmanEOT, 0 }
1441 -JBIG2HuffmanTable huffTableM[] = {
1442 +static JBIG2HuffmanTable huffTableM[] = {
1447 { 0, 0, jbig2HuffmanEOT, 0 }
1450 -JBIG2HuffmanTable huffTableN[] = {
1451 +static JBIG2HuffmanTable huffTableN[] = {
1453 { -2, 3, 0, 0x004 },
1454 { -1, 3, 0, 0x005 },
1456 { 0, 0, jbig2HuffmanEOT, 0 }
1459 -JBIG2HuffmanTable huffTableO[] = {
1460 +static JBIG2HuffmanTable huffTableO[] = {
1462 { -1, 3, 0, 0x004 },
1467 int JBIG2MMRDecoder::get2DCode() {
1469 + const CCITTCode *p;
1472 buf = str->getChar() & 0xff;
1476 int JBIG2MMRDecoder::getWhiteCode() {
1478 + const CCITTCode *p;
1485 int JBIG2MMRDecoder::getBlackCode() {
1487 + const CCITTCode *p;
1492 void combine(JBIG2Bitmap *bitmap, int x, int y, Guint combOp);
1493 Guchar *getDataPtr() { return data; }
1494 int getDataSize() { return h * line; }
1495 + GBool isOk() { return data != NULL; }
1499 @@ -685,10 +703,11 @@
1502 line = (wA + 7) >> 3;
1504 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1505 - // force a call to gmalloc(-1), which will throw an exception
1508 + error(-1, "invalid width/height");
1512 // need to allocate one extra guard byte for use in combine()
1513 data = (Guchar *)gmalloc(h * line + 1);
1514 @@ -701,10 +720,11 @@
1517 line = bitmap->line;
1519 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1520 - // force a call to gmalloc(-1), which will throw an exception
1523 + error(-1, "invalid width/height");
1527 // need to allocate one extra guard byte for use in combine()
1528 data = (Guchar *)gmalloc(h * line + 1);
1531 void JBIG2Bitmap::expand(int newH, Guint pixel) {
1532 if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
1533 + error(-1, "invalid width/height");
1538 // need to allocate one extra guard byte for use in combine()
1539 @@ -1002,6 +1025,7 @@
1540 Guint getSize() { return size; }
1541 void setBitmap(Guint idx, JBIG2Bitmap *bitmap) { bitmaps[idx] = bitmap; }
1542 JBIG2Bitmap *getBitmap(Guint idx) { return bitmaps[idx]; }
1543 + GBool isOk() { return bitmaps != NULL; }
1544 void setGenericRegionStats(JArithmeticDecoderStats *stats)
1545 { genericRegionStats = stats; }
1546 void setRefinementRegionStats(JArithmeticDecoderStats *stats)
1547 @@ -1022,13 +1046,9 @@
1548 JBIG2SymbolDict::JBIG2SymbolDict(Guint segNumA, Guint sizeA):
1549 JBIG2Segment(segNumA)
1554 bitmaps = (JBIG2Bitmap **)gmallocn(size, sizeof(JBIG2Bitmap *));
1555 - for (i = 0; i < size; ++i) {
1556 - bitmaps[i] = NULL;
1558 + if (!bitmaps) size = 0;
1559 genericRegionStats = NULL;
1560 refinementRegionStats = NULL;
1562 @@ -1037,9 +1057,7 @@
1565 for (i = 0; i < size; ++i) {
1567 - delete bitmaps[i];
1569 + delete bitmaps[i];
1572 if (genericRegionStats) {
1573 @@ -1247,6 +1265,7 @@
1574 Guint segNum, segFlags, segType, page, segLength;
1575 Guint refFlags, nRefSegs;
1581 @@ -1314,6 +1333,9 @@
1585 + // keep track of the start of the segment data
1586 + segDataPos = getPos();
1588 // check for missing page information segment
1589 if (!pageBitmap && ((segType >= 4 && segType <= 7) ||
1590 (segType >= 20 && segType <= 43))) {
1591 @@ -1398,6 +1420,45 @@
1595 + // Make sure the segment handler read all of the bytes in the
1596 + // segment data, unless this segment is marked as having an
1597 + // unknown length (section 7.2.7 of the JBIG2 Final Committee Draft)
1599 + if (segLength != 0xffffffff) {
1601 + int segExtraBytes = segDataPos + segLength - getPos();
1602 + if (segExtraBytes > 0) {
1604 + // If we didn't read all of the bytes in the segment data,
1605 + // indicate an error, and throw away the rest of the data.
1607 + // v.3.1.01.13 of the LuraTech PDF Compressor Server will
1608 + // sometimes generate an extraneous NULL byte at the end of
1609 + // arithmetic-coded symbol dictionary segments when numNewSyms
1610 + // == 0. Segments like this often occur for blank pages.
1612 + error(getPos(), "%d extraneous byte%s after segment",
1613 + segExtraBytes, (segExtraBytes > 1) ? "s" : "");
1615 + // Burn through the remaining bytes -- inefficient, but
1616 + // hopefully we're not doing this much
1619 + for (int i = segExtraBytes; i > 0; i--) {
1623 + } else if (segExtraBytes < 0) {
1625 + // If we read more bytes than we should have, according to the
1626 + // segment length field, note an error.
1628 + error(getPos(), "Previous segment handler read too many bytes");
1637 @@ -1493,6 +1554,9 @@
1638 codeTables = new GList();
1640 for (i = 0; i < nRefSegs; ++i) {
1641 + // This is need by bug 12014, returning gFalse makes it not crash
1642 + // but we end up with a empty page while acroread is able to render
1644 if ((seg = findSegment(refSegs[i]))) {
1645 if (seg->getType() == jbig2SegSymbolDict) {
1646 j = ((JBIG2SymbolDict *)seg)->getSize();
1647 @@ -1503,8 +1567,11 @@
1650 } else if (seg->getType() == jbig2SegCodeTable) {
1651 - codeTables->append(seg);
1652 + codeTables->append(seg);
1655 + delete codeTables;
1659 if (numInputSyms > UINT_MAX - numNewSyms) {
1660 @@ -1530,12 +1600,11 @@
1662 inputSymbolDict = NULL;
1663 for (i = 0; i < nRefSegs; ++i) {
1664 - if ((seg = findSegment(refSegs[i]))) {
1665 - if (seg->getType() == jbig2SegSymbolDict) {
1666 - inputSymbolDict = (JBIG2SymbolDict *)seg;
1667 - for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1668 - bitmaps[k++] = inputSymbolDict->getBitmap(j);
1670 + seg = findSegment(refSegs[i]);
1671 + if (seg != NULL && seg->getType() == jbig2SegSymbolDict) {
1672 + inputSymbolDict = (JBIG2SymbolDict *)seg;
1673 + for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1674 + bitmaps[k++] = inputSymbolDict->getBitmap(j);
1678 @@ -1753,6 +1822,10 @@
1680 // create the symbol dict object
1681 symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
1682 + if (!symbolDict->isOk()) {
1683 + delete symbolDict;
1687 // exported symbol list
1689 @@ -1766,6 +1839,7 @@
1690 if (i + run > numInputSyms + numNewSyms ||
1691 (ex && j + run > numExSyms)) {
1692 error(getPos(), "Too many exported symbols in JBIG2 symbol dictionary");
1693 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1697 @@ -1780,6 +1854,7 @@
1699 if (j != numExSyms) {
1700 error(getPos(), "Too few symbols in JBIG2 symbol dictionary");
1701 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1705 @@ -2095,18 +2170,20 @@
1709 - // combine the region bitmap into the page bitmap
1711 - if (pageH == 0xffffffff && y + h > curPageH) {
1712 - pageBitmap->expand(y + h, pageDefPixel);
1714 - pageBitmap->combine(bitmap, x, y, extCombOp);
1717 + // combine the region bitmap into the page bitmap
1719 + if (pageH == 0xffffffff && y + h > curPageH) {
1720 + pageBitmap->expand(y + h, pageDefPixel);
1722 + pageBitmap->combine(bitmap, x, y, extCombOp);
1725 - // store the region bitmap
1727 - bitmap->setSegNum(segNum);
1728 - segments->append(bitmap);
1729 + // store the region bitmap
1731 + bitmap->setSegNum(segNum);
1732 + segments->append(bitmap);
1736 // clean up the Huffman decoder
1737 @@ -2159,6 +2236,10 @@
1739 // allocate the bitmap
1740 bitmap = new JBIG2Bitmap(0, w, h);
1741 + if (!bitmap->isOk()) {
1746 bitmap->clearToOne();
1748 @@ -2235,73 +2316,84 @@
1752 + GBool decodeSuccess;
1754 - huffDecoder->decodeInt(&rdw, huffRDWTable);
1755 - huffDecoder->decodeInt(&rdh, huffRDHTable);
1756 - huffDecoder->decodeInt(&rdx, huffRDXTable);
1757 - huffDecoder->decodeInt(&rdy, huffRDYTable);
1758 - huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1759 + decodeSuccess = huffDecoder->decodeInt(&rdw, huffRDWTable);
1760 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdh, huffRDHTable);
1761 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdx, huffRDXTable);
1762 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdy, huffRDYTable);
1763 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1764 huffDecoder->reset();
1765 arithDecoder->start();
1767 - arithDecoder->decodeInt(&rdw, iardwStats);
1768 - arithDecoder->decodeInt(&rdh, iardhStats);
1769 - arithDecoder->decodeInt(&rdx, iardxStats);
1770 - arithDecoder->decodeInt(&rdy, iardyStats);
1771 + decodeSuccess = arithDecoder->decodeInt(&rdw, iardwStats);
1772 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdh, iardhStats);
1773 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdx, iardxStats);
1774 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdy, iardyStats);
1777 + if (decodeSuccess && syms[symID])
1779 + refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1780 + refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1783 + readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1784 + rdh + syms[symID]->getHeight(),
1785 + templ, gFalse, syms[symID],
1786 + refDX, refDY, atx, aty);
1788 - refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1789 - refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1792 - readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1793 - rdh + syms[symID]->getHeight(),
1794 - templ, gFalse, syms[symID],
1795 - refDX, refDY, atx, aty);
1796 //~ do we need to use the bmSize value here (in Huffman mode)?
1798 symbolBitmap = syms[symID];
1801 - // combine the symbol bitmap into the region bitmap
1802 - //~ something is wrong here - refCorner shouldn't degenerate into
1804 - bw = symbolBitmap->getWidth() - 1;
1805 - bh = symbolBitmap->getHeight() - 1;
1807 - switch (refCorner) {
1808 - case 0: // bottom left
1809 - bitmap->combine(symbolBitmap, tt, s, combOp);
1811 - case 1: // top left
1812 - bitmap->combine(symbolBitmap, tt, s, combOp);
1814 - case 2: // bottom right
1815 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1817 - case 3: // top right
1818 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1820 + if (symbolBitmap) {
1821 + // combine the symbol bitmap into the region bitmap
1822 + //~ something is wrong here - refCorner shouldn't degenerate into
1824 + bw = symbolBitmap->getWidth() - 1;
1825 + bh = symbolBitmap->getHeight() - 1;
1827 + switch (refCorner) {
1828 + case 0: // bottom left
1829 + bitmap->combine(symbolBitmap, tt, s, combOp);
1831 + case 1: // top left
1832 + bitmap->combine(symbolBitmap, tt, s, combOp);
1834 + case 2: // bottom right
1835 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1837 + case 3: // top right
1838 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1843 + switch (refCorner) {
1844 + case 0: // bottom left
1845 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1847 + case 1: // top left
1848 + bitmap->combine(symbolBitmap, s, tt, combOp);
1850 + case 2: // bottom right
1851 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1853 + case 3: // top right
1854 + bitmap->combine(symbolBitmap, s, tt, combOp);
1861 - switch (refCorner) {
1862 - case 0: // bottom left
1863 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1865 - case 1: // top left
1866 - bitmap->combine(symbolBitmap, s, tt, combOp);
1868 - case 2: // bottom right
1869 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1871 - case 3: // top right
1872 - bitmap->combine(symbolBitmap, s, tt, combOp);
1875 + delete symbolBitmap;
1880 - delete symbolBitmap;
1882 + // NULL symbolBitmap only happens on error
1888 @@ -2431,11 +2523,12 @@
1889 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1892 - if (!(seg = findSegment(refSegs[0])) ||
1893 - seg->getType() != jbig2SegPatternDict) {
1894 + seg = findSegment(refSegs[0]);
1895 + if (seg == NULL || seg->getType() != jbig2SegPatternDict) {
1896 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1900 patternDict = (JBIG2PatternDict *)seg;
1903 @@ -2591,6 +2684,8 @@
1905 bitmap = readGenericBitmap(mmr, w, h, templ, tpgdOn, gFalse,
1906 NULL, atx, aty, mmr ? length - 18 : 0);
1910 // combine the region bitmap into the page bitmap
1912 @@ -2616,7 +2711,7 @@
1913 int *codingLine, int *a0i, int w) {
1914 if (a1 > codingLine[*a0i]) {
1916 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1917 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1920 if ((*a0i & 1) ^ blackPixels) {
1921 @@ -2630,7 +2725,7 @@
1922 int *codingLine, int *a0i, int w) {
1923 if (a1 > codingLine[*a0i]) {
1925 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1926 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1929 if ((*a0i & 1) ^ blackPixels) {
1930 @@ -2657,13 +2752,17 @@
1931 JBIG2Bitmap *bitmap;
1933 Guint ltpCX, cx, cx0, cx1, cx2;
1934 - JBIG2BitmapPtr cxPtr0, cxPtr1;
1935 - JBIG2BitmapPtr atPtr0, atPtr1, atPtr2, atPtr3;
1936 + JBIG2BitmapPtr cxPtr0 = {0}, cxPtr1 = {0};
1937 + JBIG2BitmapPtr atPtr0 = {0}, atPtr1 = {0}, atPtr2 = {0}, atPtr3 = {0};
1938 int *refLine, *codingLine;
1939 int code1, code2, code3;
1940 int x, y, a0i, b1i, blackPixels, pix, i;
1942 bitmap = new JBIG2Bitmap(0, w, h);
1943 + if (!bitmap->isOk()) {
1947 bitmap->clearToZero();
1950 @@ -2682,7 +2781,7 @@
1951 // ---> max refLine size = w + 2
1952 codingLine = (int *)gmallocn(w + 1, sizeof(int));
1953 refLine = (int *)gmallocn(w + 2, sizeof(int));
1954 - codingLine[0] = w;
1955 + for (i = 0; i < w + 1; ++i) codingLine[i] = w;
1957 for (y = 0; y < h; ++y) {
1959 @@ -3093,8 +3192,8 @@
1962 if (nRefSegs == 1) {
1963 - if (!(seg = findSegment(refSegs[0])) ||
1964 - seg->getType() != jbig2SegBitmap) {
1965 + seg = findSegment(refSegs[0]);
1966 + if (seg == NULL || seg->getType() != jbig2SegBitmap) {
1967 error(getPos(), "Bad bitmap reference in JBIG2 generic refinement segment");
1970 @@ -3143,11 +3242,24 @@
1971 JBIG2Bitmap *bitmap;
1973 Guint ltpCX, cx, cx0, cx2, cx3, cx4, tpgrCX0, tpgrCX1, tpgrCX2;
1974 - JBIG2BitmapPtr cxPtr0, cxPtr1, cxPtr2, cxPtr3, cxPtr4, cxPtr5, cxPtr6;
1975 - JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
1976 + JBIG2BitmapPtr cxPtr0 = {0};
1977 + JBIG2BitmapPtr cxPtr1 = {0};
1978 + JBIG2BitmapPtr cxPtr2 = {0};
1979 + JBIG2BitmapPtr cxPtr3 = {0};
1980 + JBIG2BitmapPtr cxPtr4 = {0};
1981 + JBIG2BitmapPtr cxPtr5 = {0};
1982 + JBIG2BitmapPtr cxPtr6 = {0};
1983 + JBIG2BitmapPtr tpgrCXPtr0 = {0};
1984 + JBIG2BitmapPtr tpgrCXPtr1 = {0};
1985 + JBIG2BitmapPtr tpgrCXPtr2 = {0};
1988 bitmap = new JBIG2Bitmap(0, w, h);
1989 + if (!bitmap->isOk())
1994 bitmap->clearToZero();
1996 // set up the typical row context
1997 @@ -3332,6 +3444,12 @@
1999 pageBitmap = new JBIG2Bitmap(0, pageW, curPageH);
2001 + if (!pageBitmap->isOk()) {
2002 + delete pageBitmap;
2003 + pageBitmap = NULL;
2007 // default pixel value
2009 pageBitmap->clearToOne();