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
191 +CharCodeToUnicode* Gfx8BitFont::getCTU() {
195 CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
198 @@ -1411,6 +1415,10 @@
202 +CharCodeToUnicode* GfxCIDFont::getCTU() {
206 int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
207 Unicode *u, int uSize, int *uLen,
208 double *dx, double *dy, double *ox, double *oy) {
209 --- xpdf/GfxFont.h.orig 2010-05-18 11:22:18.000000000 -0700
210 +++ xpdf/GfxFont.h 2010-05-18 11:22:18.000000000 -0700
212 virtual int getNextChar(char *s, int len, CharCode *code,
213 Unicode *u, int uSize, int *uLen,
214 double *dx, double *dy, double *ox, double *oy) = 0;
215 + virtual CharCodeToUnicode* getCTU() = 0;
220 virtual int getNextChar(char *s, int len, CharCode *code,
221 Unicode *u, int uSize, int *uLen,
222 double *dx, double *dy, double *ox, double *oy);
223 + virtual CharCodeToUnicode* getCTU();
225 // Return the encoding.
226 char **getEncoding() { return enc; }
228 CharCodeToUnicode *getToUnicode();
230 // Return the character name associated with <code>.
231 - char *getCharName(int code) { return enc[code]; }
232 + char *getCharName(int code) { return code>=256?0:enc[code]; }
234 // Returns true if the PDF font specified an encoding.
235 GBool getHasEncoding() { return hasEncoding; }
237 virtual int getNextChar(char *s, int len, CharCode *code,
238 Unicode *u, int uSize, int *uLen,
239 double *dx, double *dy, double *ox, double *oy);
240 + virtual CharCodeToUnicode* getCTU();
242 // Return the writing mode (0=horizontal, 1=vertical).
243 virtual int getWMode();
244 --- xpdf/GfxState.cc.orig 2010-05-18 11:22:18.000000000 -0700
245 +++ xpdf/GfxState.cc 2010-05-18 11:22:18.000000000 -0700
249 #include "GfxState.h"
252 //------------------------------------------------------------------------
255 GfxColorSpace::~GfxColorSpace() {
258 -GfxColorSpace *GfxColorSpace::parse(Object *csObj) {
259 +GfxColorSpace *GfxColorSpace::parse(Object *csObj, StreamColorSpaceMode csMode) {
264 if (csObj->isName("DeviceGray") || csObj->isName("G")) {
265 cs = new GfxDeviceGrayColorSpace();
266 } else if (csObj->isName("DeviceRGB") || csObj->isName("RGB")) {
267 - cs = new GfxDeviceRGBColorSpace();
268 + if(csMode == streamCSDeviceRGBX)
269 + cs = new GfxDeviceRGBXColorSpace();
271 + cs = new GfxDeviceRGBColorSpace();
272 } else if (csObj->isName("DeviceCMYK") || csObj->isName("CMYK")) {
273 cs = new GfxDeviceCMYKColorSpace();
274 } else if (csObj->isName("Pattern")) {
276 if (obj1.isName("DeviceGray") || obj1.isName("G")) {
277 cs = new GfxDeviceGrayColorSpace();
278 } else if (obj1.isName("DeviceRGB") || obj1.isName("RGB")) {
279 - cs = new GfxDeviceRGBColorSpace();
280 + if(csMode == streamCSDeviceRGBX)
281 + cs = new GfxDeviceRGBColorSpace();
283 + cs = new GfxDeviceRGBColorSpace();
284 } else if (obj1.isName("DeviceCMYK") || obj1.isName("CMYK")) {
285 cs = new GfxDeviceCMYKColorSpace();
286 } else if (obj1.isName("CalGray")) {
290 //------------------------------------------------------------------------
291 +// GfxDeviceRGBXColorSpace
292 +//------------------------------------------------------------------------
294 +GfxDeviceRGBXColorSpace::GfxDeviceRGBXColorSpace() {
297 +GfxColorSpace *GfxDeviceRGBXColorSpace::copy() {
298 + return new GfxDeviceRGBXColorSpace();
301 +//------------------------------------------------------------------------
302 // GfxCalRGBColorSpace
303 //------------------------------------------------------------------------
306 - 0.11 * color->c[2] + 0.5));
309 +/*void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
310 + unsigned char r,g,b;
311 + float c = color->c[0];
312 + float m = color->c[1];
313 + float y = color->c[2];
314 + float k = color->c[3];
315 + convert_cmyk2rgb(c,m,y,k, &r,&g,&b);
321 void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
322 double c, m, y, k, c1, m1, y1, k1, r, g, b, x;
324 @@ -3187,6 +3217,7 @@
325 GfxIndexedColorSpace *indexedCS;
326 GfxSeparationColorSpace *sepCS;
327 int maxPixel, indexHigh;
328 + int maxPixelForAlloc;
332 @@ -3199,6 +3230,7 @@
333 // bits per component and color space
335 maxPixel = (1 << bits) - 1;
336 + maxPixelForAlloc = (1 << (bits>8?bits:8));
337 colorSpace = colorSpaceA;
340 @@ -3253,7 +3285,7 @@
341 lookup2 = indexedCS->getLookup();
342 colorSpace2->getDefaultRanges(x, y, indexHigh);
343 for (k = 0; k < nComps2; ++k) {
344 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
345 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
346 sizeof(GfxColorComp));
347 for (i = 0; i <= maxPixel; ++i) {
348 j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
349 @@ -3272,7 +3304,7 @@
350 nComps2 = colorSpace2->getNComps();
351 sepFunc = sepCS->getFunc();
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 x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
358 @@ -3282,7 +3314,7 @@
361 for (k = 0; k < nComps; ++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 lookup[k][i] = dblToCol(decodeLow[k] +
367 @@ -3754,7 +3786,10 @@
370 void GfxState::setPath(GfxPath *pathA) {
378 --- xpdf/GfxState.h.orig 2010-05-18 11:22:18.000000000 -0700
379 +++ xpdf/GfxState.h 2010-05-18 11:22:18.000000000 -0700
381 virtual GfxColorSpaceMode getMode() = 0;
383 // Construct a color space. Returns NULL if unsuccessful.
384 - static GfxColorSpace *parse(Object *csObj);
385 + static GfxColorSpace *parse(Object *csObj, StreamColorSpaceMode csMode = streamCSNone);
387 // Convert to gray, RGB, or CMYK.
388 virtual void getGray(GfxColor *color, GfxGray *gray) = 0;
392 //------------------------------------------------------------------------
393 +// GfxDeviceRGBXColorSpace
394 +//------------------------------------------------------------------------
396 +class GfxDeviceRGBXColorSpace: public GfxDeviceRGBColorSpace {
399 + GfxDeviceRGBXColorSpace();
400 + virtual GfxColorSpace *copy();
401 + virtual int getNComps() { return 4; }
405 +//------------------------------------------------------------------------
406 // GfxCalRGBColorSpace
407 //------------------------------------------------------------------------
409 --- xpdf/GlobalParams.cc.orig 2010-05-18 11:22:18.000000000 -0700
410 +++ xpdf/GlobalParams.cc 2010-05-18 11:22:18.000000000 -0700
417 + char* cfgFileName = fileName->getCString();
418 + char* pos1 = strrchr(cfgFileName, '/');
419 + char* pos2 = strrchr(cfgFileName, '\\');
420 + char* p = pos1>pos2?pos1:pos2;
421 + int pos = p ? p-cfgFileName : -1;
422 + GString*path = new GString(new GString(cfgFileName), 0, (pos < 0 ? strlen(cfgFileName): pos));
426 + path->append('\\');
429 + path->append('\\');
435 + this->path = new GString();
439 while (getLine(buf, sizeof(buf) - 1, f)) {
440 parseLine(buf, fileName, line);
441 @@ -1114,6 +1137,42 @@
442 deleteGList(tokens, GString);
445 +static char is_absolute(char*filename)
447 + int l = strlen(filename);
448 + if(filename[0] == '/' || filename[0] == '\\')
450 + if(l>2 && filename[1]==':' && (filename[2]=='\\' || filename[2]=='/'))
455 +static GString* qualify_filename(GString*path, GString*filename)
457 + GString*fullpath = 0;
458 + char*prefix = "/usr/local/share/xpdf/";
460 + if (!is_absolute(filename->getCString())) {
461 + /* relative path */
462 + fullpath = path->copy();
463 + fullpath->append(filename);
464 + } else if (!strncmp(filename->getCString(), prefix, strlen(prefix))) {
465 + /* xpdf default path */
466 + char*s = strchr(filename->getCString()+strlen(prefix), '/');
468 + fullpath = path->copy();
469 + fullpath->append(s+1);
471 + fullpath = filename->copy();
474 + /* absolute path */
475 + fullpath = filename->copy();
477 + //printf("%s -%s-> %s\n", filename->getCString(), path->getCString(), fullpath->getCString());
481 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
484 @@ -1128,10 +1187,10 @@
485 fileName->getCString(), line);
488 - name = (GString *)tokens->get(1);
489 + name = qualify_filename(this->path, (GString *)tokens->get(1));
490 if (!(f = fopen(name->getCString(), "r"))) {
491 - error(-1, "Couldn't open 'nameToUnicode' file '%s'",
492 - name->getCString());
493 + error(-1, "Couldn't open 'nameToUnicode' file '%s' using path '%s'",
494 + name->getCString(), path->getCString());
498 @@ -1160,10 +1219,12 @@
500 collection = (GString *)tokens->get(1);
501 name = (GString *)tokens->get(2);
503 if ((old = (GString *)cidToUnicodes->remove(collection))) {
506 - cidToUnicodes->add(collection->copy(), name->copy());
508 + cidToUnicodes->add(collection->copy(), qualify_filename(this->path, name));
511 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
512 @@ -1180,7 +1241,8 @@
513 if ((old = (GString *)unicodeToUnicodes->remove(font))) {
516 - unicodeToUnicodes->add(font->copy(), file->copy());
518 + unicodeToUnicodes->add(font->copy(), qualify_filename(this->path, file));
521 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
522 @@ -1197,7 +1259,8 @@
523 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
526 - unicodeMaps->add(encodingName->copy(), name->copy());
528 + unicodeMaps->add(encodingName->copy(), qualify_filename(this->path, name));
531 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
532 @@ -1215,23 +1278,30 @@
534 cMapDirs->add(collection->copy(), list);
536 - list->append(dir->copy());
538 + list->append(qualify_filename(this->path, dir));
541 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
545 if (tokens->getLength() != 2) {
546 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
547 fileName->getCString(), line);
550 - toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
552 + dir = (GString *)tokens->get(1);
554 + toUnicodeDirs->append(qualify_filename(this->path, dir));
557 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
558 DisplayFontParamKind kind,
559 GString *fileName, int line) {
560 DisplayFontParam *param, *old;
563 if (tokens->getLength() < 2) {
565 @@ -1243,13 +1313,15 @@
566 if (tokens->getLength() != 3) {
569 - param->t1.fileName = ((GString *)tokens->get(2))->copy();
570 + file = (GString *)tokens->get(2);
571 + param->t1.fileName = qualify_filename(this->path, file);
574 if (tokens->getLength() != 3) {
577 - param->tt.fileName = ((GString *)tokens->get(2))->copy();
578 + file = (GString *)tokens->get(2);
579 + param->tt.fileName = qualify_filename(this->path, file);
583 --- xpdf/GlobalParams.h.orig 2010-05-18 11:22:18.000000000 -0700
584 +++ xpdf/GlobalParams.h 2010-05-18 11:22:18.000000000 -0700
587 GlobalParams(char *cfgFileName);
590 + virtual ~GlobalParams();
592 void setBaseDir(char *dir);
593 void setupBaseFonts(char *dir);
595 FILE *getUnicodeMapFile(GString *encodingName);
596 FILE *findCMapFile(GString *collection, GString *cMapName);
597 FILE *findToUnicodeFile(GString *name);
598 - DisplayFontParam *getDisplayFont(GString *fontName);
599 - DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
600 + virtual DisplayFontParam *getDisplayFont(GString *fontName);
601 + virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
602 GString *getPSFile();
603 int getPSPaperWidth();
604 int getPSPaperHeight();
608 void createDefaultKeyBindings();
609 - void parseFile(GString *fileName, FILE *f);
610 +public: void parseFile(GString *fileName, FILE *f); private:
611 void parseNameToUnicode(GList *tokens, GString *fileName, int line);
612 void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
613 void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line);
615 GBool loadPlugin(char *type, char *name);
618 + //----- config file base path
622 //----- static tables
624 NameToCharCode * // mapping from char name to
625 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
626 +++ xpdf/JBIG2Stream.cc 2010-05-18 11:22:18.000000000 -0700
627 @@ -1514,11 +1514,14 @@
630 // compute symbol code length
632 - i = (numInputSyms + numNewSyms) >> 1;
638 + while (i < numInputSyms + numNewSyms) {
642 + if (huff && symCodeLen == 0) {
646 // get the input symbol bitmaps
647 @@ -1921,6 +1924,9 @@
651 + if (huff && symCodeLen == 0) {
655 // get the symbol bitmaps
656 syms = (JBIG2Bitmap **)gmallocn(numSyms, sizeof(JBIG2Bitmap *));
657 --- xpdf/JPXStream.cc.orig 2010-05-18 11:22:18.000000000 -0700
658 +++ xpdf/JPXStream.cc 2010-05-18 11:22:18.000000000 -0700
660 GBool haveBPC, haveCSMode;
662 csPrec = 0; // make gcc happy
663 + Guint num_components = 0;
664 haveBPC = haveCSMode = gFalse;
666 if (str->lookChar() == 0xff) {
669 if (readULong(&dummy) &&
671 - readUWord(&dummy) &&
672 + readUWord(&num_components) &&
680 + if(*csMode == streamCSDeviceRGB && num_components == 4) {
681 + *csMode = streamCSDeviceRGBX;
686 --- xpdf/Lexer.cc.orig 2010-05-18 11:22:18.000000000 -0700
687 +++ xpdf/Lexer.cc 2010-05-18 11:22:18.000000000 -0700
689 curStr.streamReset();
692 +static int illegalChars = 0;
695 if (!curStr.isNone()) {
701 + error(0, "Illegal characters in hex string (%d)", illegalChars);
705 int Lexer::getChar() {
707 } else if (c2 >= 'a' && c2 <= 'f') {
710 - error(getPos(), "Illegal digit in hex char in name");
712 + //error(getPos(), "Illegal digit in hex char in name");
718 else if (c >= 'a' && c <= 'f')
721 - error(getPos(), "Illegal character <%02x> in hex string", c);
724 + //error(getPos(), "Illegal character <%02x> in hex string", c);
727 if (n == tokBufSize) {
731 obj->initCmd(tokBuf);
733 - error(getPos(), "Illegal character '>'");
735 + //error(getPos(), "Illegal character '>'");
743 - error(getPos(), "Illegal character '%c'", c);
744 + //error(getPos(), "Illegal character '%c'", c);
757 --- xpdf/Link.cc.orig 2010-05-18 11:22:18.000000000 -0700
758 +++ xpdf/Link.cc 2010-05-18 11:22:18.000000000 -0700
766 - error(-1, "Illegal annotation destination");
767 + error(-1, "Illegal annotation destination %d", destObj->getType());
778 - error(-1, "Illegal annotation destination");
779 + error(-1, "Illegal annotation destination %d", destObj->getType());
783 --- xpdf/OutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
784 +++ xpdf/OutputDev.h 2010-05-18 11:22:18.000000000 -0700
788 #include "CharTypes.h"
797 - virtual void startPage(int pageNum, GfxState *state) {}
798 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
801 virtual void endPage() {}
802 --- xpdf/SplashFTFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
803 +++ xpdf/SplashFTFont.cc 2010-05-18 11:22:18.000000000 -0700
807 face = fontFileA->face;
809 if (FT_New_Size(face, &sizeObj)) {
813 if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
817 + this->ascender = face->ascender;
818 + this->descender = face->descender;
820 // if the textMat values are too small, FreeType's fixed point
821 // arithmetic doesn't work so well
822 textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
827 +int SplashFTFont::getNumChars()
829 + SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
830 + return ff->face->num_glyphs;
833 SplashPath *SplashFTFont::getGlyphPath(int c) {
834 static FT_Outline_Funcs outlineFuncs = {
835 #if FREETYPE_MINOR <= 1
840 + this->last_advance = -1;
842 ff = (SplashFTFontFile *)fontFile;
843 ff->face->size = sizeObj;
844 FT_Set_Transform(ff->face, &textMatrix, NULL);
845 @@ -262,17 +275,24 @@
846 // skip the TrueType notdef glyph
849 - if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
851 + if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
852 + fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
855 if (FT_Get_Glyph(slot, &glyph)) {
858 + this->last_advance = glyph->advance.x/65536.0;
860 path.path = new SplashPath();
861 path.textScale = textScale;
862 path.needClose = gFalse;
863 - FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
864 + error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
865 &outlineFuncs, &path);
867 + fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
869 if (path.needClose) {
872 --- xpdf/SplashFTFont.h.orig 2010-05-18 11:22:18.000000000 -0700
873 +++ xpdf/SplashFTFont.h 2010-05-18 11:22:18.000000000 -0700
875 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
876 SplashGlyphBitmap *bitmap);
878 + // return the number of characters in this font
879 + virtual int getNumChars();
881 // Return the path for a glyph.
882 virtual SplashPath *getGlyphPath(int c);
884 --- xpdf/SplashFTFontEngine.cc.orig 2010-05-18 11:22:18.000000000 -0700
885 +++ xpdf/SplashFTFontEngine.cc 2010-05-18 11:22:18.000000000 -0700
896 --- xpdf/SplashFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
897 +++ xpdf/SplashFont.cc 2010-05-18 11:22:18.000000000 -0700
901 xMin = yMin = xMax = yMax = 0;
908 void SplashFont::initCache() {
909 --- xpdf/SplashFont.h.orig 2010-05-18 11:22:18.000000000 -0700
910 +++ xpdf/SplashFont.h 2010-05-18 11:22:18.000000000 -0700
912 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
913 SplashGlyphBitmap *bitmap) = 0;
915 + // return the number of characters in this font
916 + virtual int getNumChars() = 0;
918 // Return the path for a glyph.
919 virtual SplashPath *getGlyphPath(int c) = 0;
922 void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
923 { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
927 + double last_advance; //set after getGlyphPath()
930 SplashFontFile *fontFile;
931 --- xpdf/SplashFontFile.cc.orig 2010-05-18 11:22:18.000000000 -0700
932 +++ xpdf/SplashFontFile.cc 2010-05-18 11:22:18.000000000 -0700
938 -# include <unistd.h>
942 #include "SplashFontFile.h"
943 #include "SplashFontFileID.h"
944 --- xpdf/SplashOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
945 +++ xpdf/SplashOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
953 #include "GlobalParams.h"
958 -void SplashOutputDev::startPage(int pageNum, GfxState *state) {
959 +void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
963 @@ -2646,9 +2647,9 @@
965 softMask = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(),
966 1, splashModeMono8, gFalse);
967 - memset(softMask->getDataPtr(), 0,
968 - softMask->getRowSize() * softMask->getHeight());
969 + memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
970 p = softMask->getDataPtr() + ty * softMask->getRowSize() + tx;
971 + if (tx<softMask->getWidth() && ty<softMask->getHeight())
972 for (y = 0; y < tBitmap->getHeight(); ++y) {
973 for (x = 0; x < tBitmap->getWidth(); ++x) {
974 tBitmap->getPixel(x, y, color);
975 --- xpdf/SplashOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
976 +++ xpdf/SplashOutputDev.h 2010-05-18 11:22:18.000000000 -0700
978 //----- initialization and control
981 - virtual void startPage(int pageNum, GfxState *state);
982 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
985 virtual void endPage();
987 virtual void setVectorAntialias(GBool vaa);
990 + void doUpdateFont(GfxState *state);
992 + SplashPath *convertPath(GfxState *state, GfxPath *path);
995 void setupScreenParams(double hDPI, double vDPI);
998 SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
1000 - SplashPath *convertPath(GfxState *state, GfxPath *path);
1001 - void doUpdateFont(GfxState *state);
1002 void drawType3Glyph(T3FontCache *t3Font,
1003 T3FontCacheTag *tag, Guchar *data);
1004 static GBool imageMaskSrc(void *data, SplashColorPtr line);
1005 --- xpdf/SplashScreen.cc.orig 2010-05-18 11:22:18.000000000 -0700
1006 +++ xpdf/SplashScreen.cc 2010-05-18 11:22:18.000000000 -0700
1008 int SplashScreen::test(int x, int y, Guchar value) {
1013 if (value < minVal) {
1016 --- xpdf/SplashXPathScanner.cc.orig 2010-05-18 11:22:18.000000000 -0700
1017 +++ xpdf/SplashXPathScanner.cc 2010-05-18 11:22:18.000000000 -0700
1018 @@ -394,10 +394,10 @@
1022 - for (; xx + 7 <= xx0; xx += 8) {
1023 + for (; xx + 7 < xx0; xx += 8) {
1028 *p &= 0xff >> (xx0 & 7);
1031 @@ -417,10 +417,10 @@
1035 - for (; xx + 7 <= xx0; xx += 8) {
1036 + for (; xx + 7 < xx0; xx += 8) {
1041 *p &= 0xff >> (xx0 & 7);
1044 --- xpdf/Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
1045 +++ xpdf/Stream.cc 2010-05-18 11:22:18.000000000 -0700
1051 +extern "C" int unlink(char *filename);
1055 @@ -2456,6 +2460,9 @@
1056 // check for an EOB run
1058 while (i <= scanInfo.lastCoeff) {
1064 if ((bit = readBit()) == EOF) {
1065 @@ -2480,6 +2487,9 @@
1075 @@ -2505,6 +2515,9 @@
1078 while (i <= scanInfo.lastCoeff) {
1084 if ((bit = readBit()) == EOF) {
1085 @@ -2527,6 +2540,9 @@
1093 while (data[j] != 0) {
1094 if ((bit = readBit()) == EOF) {
1095 @@ -2535,6 +2551,9 @@
1097 data[j] += 1 << scanInfo.al;
1105 --- xpdf/Stream.h.orig 2010-05-18 11:22:18.000000000 -0700
1106 +++ xpdf/Stream.h 2010-05-18 11:22:18.000000000 -0700
1111 - streamCSDeviceCMYK
1112 + streamCSDeviceCMYK,
1113 + streamCSDeviceRGBX
1116 //------------------------------------------------------------------------
1117 --- xpdf/TextOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
1118 +++ xpdf/TextOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
1119 @@ -3877,7 +3877,7 @@
1123 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
1124 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
1125 text->startPage(state);
1128 --- xpdf/TextOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
1129 +++ xpdf/TextOutputDev.h 2010-05-18 11:22:18.000000000 -0700
1131 friend class TextFlow;
1132 friend class TextWordList;
1133 friend class TextPage;
1134 + friend class XMLOutputDev;
1137 //------------------------------------------------------------------------
1139 //----- initialization and control
1142 - virtual void startPage(int pageNum, GfxState *state);
1143 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
1146 virtual void endPage();
1147 --- xpdf/gfile.cc.orig 2010-05-18 11:22:18.000000000 -0700
1148 +++ xpdf/gfile.cc 2010-05-18 11:22:18.000000000 -0700
1149 @@ -439,6 +439,52 @@
1153 +static char* getTempDir()
1156 + char*dir = getenv("TMP");
1157 + if(!dir) dir = getenv("TEMP");
1158 + if(!dir) dir = getenv("tmp");
1159 + if(!dir) dir = getenv("temp");
1160 + if(!dir) dir = "C:\\";
1162 + char* dir = "/tmp/";
1167 +char* mktmpname(char*ptr) {
1168 + static char tmpbuf[128];
1169 + char*dir = getTempDir();
1170 + int l = strlen(dir);
1174 + if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
1182 + // used to be mktemp. This does remove the warnings, but
1183 + // It's not exactly an improvement.
1184 +#ifdef HAVE_LRAND48
1185 + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
1188 + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
1190 + static int count = 1;
1191 + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
1199 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
1201 //---------- Win32 ----------
1204 t = (int)time(NULL);
1205 for (i = 0; i < 1000; ++i) {
1206 - sprintf(buf, "%d", t + i);
1207 + sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
1208 s2 = s->copy()->append(buf);
1212 if (!(f2 = fopen(s2->getCString(), "r"))) {
1213 if (!(f2 = fopen(s2->getCString(), mode))) {
1225 + fprintf(stderr, "Couldn't create temporary file\n");
1228 #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
1230 // with this file name after the tmpnam call and before the fopen
1231 // call. I will happily accept fixes to this function for non-Unix
1233 - if (!(s = tmpnam(NULL))) {
1234 + if (!(s = mktmpname(NULL))) {
1237 *name = new GString(s);
1239 (*name)->append("/XXXXXX")->append(ext);
1240 fd = mkstemps((*name)->getCString(), strlen(ext));
1242 - if (!(s = tmpnam(NULL))) {
1243 + if (!(s = mktmpname(NULL))) {
1246 *name = new GString(s);
1248 (*name)->append("/XXXXXX");
1249 fd = mkstemp((*name)->getCString());
1250 #else // HAVE_MKSTEMP
1251 - if (!(s = tmpnam(NULL))) {
1252 + if (!(s = mktmpname(NULL))) {
1255 *name = new GString(s);
1256 --- xpdf/gfile.h.orig 2010-05-18 11:22:18.000000000 -0700
1257 +++ xpdf/gfile.h 2010-05-18 11:22:18.000000000 -0700
1259 // Get current directory.
1260 extern GString *getCurrentDir();
1262 +/* create a temporary filename */
1263 +char* mktmpname(char*ptr);
1265 // Append a file name to a path string. <path> may be an empty
1266 // string, denoting the current directory). Returns <path>.
1267 extern GString *appendToPath(GString *path, char *fileName);
1268 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:33:21.000000000 -0700
1269 +++ xpdf/JBIG2Stream.cc 2010-06-03 16:55:03.000000000 -0700
1272 //========================================================================
1275 +//========================================================================
1277 +// Modified under the Poppler project - http://poppler.freedesktop.org
1279 +// All changes made under the Poppler project to this file are licensed
1280 +// under GPL version 2 or later
1282 +// Copyright (C) 2006 Raj Kumar <rkumar@archive.org>
1283 +// Copyright (C) 2006 Paul Walmsley <paul@booyaka.com>
1284 +// Copyright (C) 2006-2009 Albert Astals Cid <aacid@kde.org>
1285 +// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
1287 +// To see a description of the changes please see the Changelog file that
1288 +// came with your tarball or type make ChangeLog if you are building from git
1290 +//========================================================================
1292 +#include <config.h>
1294 #ifdef USE_GCC_PRAGMAS
1295 #pragma implementation
1298 //------------------------------------------------------------------------
1300 -static int contextSize[4] = { 16, 13, 10, 10 };
1301 -static int refContextSize[2] = { 13, 10 };
1302 +static const int contextSize[4] = { 16, 13, 10, 10 };
1303 +static const int refContextSize[2] = { 13, 10 };
1305 //------------------------------------------------------------------------
1306 // JBIG2HuffmanTable
1311 -JBIG2HuffmanTable huffTableA[] = {
1312 +static JBIG2HuffmanTable huffTableA[] = {
1314 { 16, 2, 8, 0x002 },
1315 { 272, 3, 16, 0x006 },
1317 { 0, 0, jbig2HuffmanEOT, 0 }
1320 -JBIG2HuffmanTable huffTableB[] = {
1321 +static JBIG2HuffmanTable huffTableB[] = {
1326 { 0, 0, jbig2HuffmanEOT, 0 }
1329 -JBIG2HuffmanTable huffTableC[] = {
1330 +static JBIG2HuffmanTable huffTableC[] = {
1335 { 0, 0, jbig2HuffmanEOT, 0 }
1338 -JBIG2HuffmanTable huffTableD[] = {
1339 +static JBIG2HuffmanTable huffTableD[] = {
1344 { 0, 0, jbig2HuffmanEOT, 0 }
1347 -JBIG2HuffmanTable huffTableE[] = {
1348 +static JBIG2HuffmanTable huffTableE[] = {
1353 { 0, 0, jbig2HuffmanEOT, 0 }
1356 -JBIG2HuffmanTable huffTableF[] = {
1357 +static JBIG2HuffmanTable huffTableF[] = {
1359 { 128, 3, 7, 0x002 },
1360 { 256, 3, 8, 0x003 },
1362 { 0, 0, jbig2HuffmanEOT, 0 }
1365 -JBIG2HuffmanTable huffTableG[] = {
1366 +static JBIG2HuffmanTable huffTableG[] = {
1367 { -512, 3, 8, 0x000 },
1368 { 256, 3, 8, 0x001 },
1369 { 512, 3, 9, 0x002 },
1371 { 0, 0, jbig2HuffmanEOT, 0 }
1374 -JBIG2HuffmanTable huffTableH[] = {
1375 +static JBIG2HuffmanTable huffTableH[] = {
1377 { 0, 2, jbig2HuffmanOOB, 0x001 },
1380 { 0, 0, jbig2HuffmanEOT, 0 }
1383 -JBIG2HuffmanTable huffTableI[] = {
1384 +static JBIG2HuffmanTable huffTableI[] = {
1385 { 0, 2, jbig2HuffmanOOB, 0x000 },
1386 { -1, 3, 1, 0x002 },
1389 { 0, 0, jbig2HuffmanEOT, 0 }
1392 -JBIG2HuffmanTable huffTableJ[] = {
1393 +static JBIG2HuffmanTable huffTableJ[] = {
1394 { -2, 2, 2, 0x000 },
1396 { 0, 2, jbig2HuffmanOOB, 0x002 },
1398 { 0, 0, jbig2HuffmanEOT, 0 }
1401 -JBIG2HuffmanTable huffTableK[] = {
1402 +static JBIG2HuffmanTable huffTableK[] = {
1407 { 0, 0, jbig2HuffmanEOT, 0 }
1410 -JBIG2HuffmanTable huffTableL[] = {
1411 +static JBIG2HuffmanTable huffTableL[] = {
1416 { 0, 0, jbig2HuffmanEOT, 0 }
1419 -JBIG2HuffmanTable huffTableM[] = {
1420 +static JBIG2HuffmanTable huffTableM[] = {
1425 { 0, 0, jbig2HuffmanEOT, 0 }
1428 -JBIG2HuffmanTable huffTableN[] = {
1429 +static JBIG2HuffmanTable huffTableN[] = {
1431 { -2, 3, 0, 0x004 },
1432 { -1, 3, 0, 0x005 },
1434 { 0, 0, jbig2HuffmanEOT, 0 }
1437 -JBIG2HuffmanTable huffTableO[] = {
1438 +static JBIG2HuffmanTable huffTableO[] = {
1440 { -1, 3, 0, 0x004 },
1445 int JBIG2MMRDecoder::get2DCode() {
1447 + const CCITTCode *p;
1450 buf = str->getChar() & 0xff;
1454 int JBIG2MMRDecoder::getWhiteCode() {
1456 + const CCITTCode *p;
1463 int JBIG2MMRDecoder::getBlackCode() {
1465 + const CCITTCode *p;
1470 void combine(JBIG2Bitmap *bitmap, int x, int y, Guint combOp);
1471 Guchar *getDataPtr() { return data; }
1472 int getDataSize() { return h * line; }
1473 + GBool isOk() { return data != NULL; }
1477 @@ -685,10 +703,11 @@
1480 line = (wA + 7) >> 3;
1482 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1483 - // force a call to gmalloc(-1), which will throw an exception
1486 + error(-1, "invalid width/height");
1490 // need to allocate one extra guard byte for use in combine()
1491 data = (Guchar *)gmalloc(h * line + 1);
1492 @@ -701,10 +720,11 @@
1495 line = bitmap->line;
1497 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1498 - // force a call to gmalloc(-1), which will throw an exception
1501 + error(-1, "invalid width/height");
1505 // need to allocate one extra guard byte for use in combine()
1506 data = (Guchar *)gmalloc(h * line + 1);
1509 void JBIG2Bitmap::expand(int newH, Guint pixel) {
1510 if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
1511 + error(-1, "invalid width/height");
1516 // need to allocate one extra guard byte for use in combine()
1517 @@ -1002,6 +1025,7 @@
1518 Guint getSize() { return size; }
1519 void setBitmap(Guint idx, JBIG2Bitmap *bitmap) { bitmaps[idx] = bitmap; }
1520 JBIG2Bitmap *getBitmap(Guint idx) { return bitmaps[idx]; }
1521 + GBool isOk() { return bitmaps != NULL; }
1522 void setGenericRegionStats(JArithmeticDecoderStats *stats)
1523 { genericRegionStats = stats; }
1524 void setRefinementRegionStats(JArithmeticDecoderStats *stats)
1525 @@ -1022,13 +1046,9 @@
1526 JBIG2SymbolDict::JBIG2SymbolDict(Guint segNumA, Guint sizeA):
1527 JBIG2Segment(segNumA)
1532 bitmaps = (JBIG2Bitmap **)gmallocn(size, sizeof(JBIG2Bitmap *));
1533 - for (i = 0; i < size; ++i) {
1534 - bitmaps[i] = NULL;
1536 + if (!bitmaps) size = 0;
1537 genericRegionStats = NULL;
1538 refinementRegionStats = NULL;
1540 @@ -1037,9 +1057,7 @@
1543 for (i = 0; i < size; ++i) {
1545 - delete bitmaps[i];
1547 + delete bitmaps[i];
1550 if (genericRegionStats) {
1551 @@ -1247,6 +1265,7 @@
1552 Guint segNum, segFlags, segType, page, segLength;
1553 Guint refFlags, nRefSegs;
1559 @@ -1314,6 +1333,9 @@
1563 + // keep track of the start of the segment data
1564 + segDataPos = getPos();
1566 // check for missing page information segment
1567 if (!pageBitmap && ((segType >= 4 && segType <= 7) ||
1568 (segType >= 20 && segType <= 43))) {
1569 @@ -1398,6 +1420,45 @@
1573 + // Make sure the segment handler read all of the bytes in the
1574 + // segment data, unless this segment is marked as having an
1575 + // unknown length (section 7.2.7 of the JBIG2 Final Committee Draft)
1577 + if (segLength != 0xffffffff) {
1579 + int segExtraBytes = segDataPos + segLength - getPos();
1580 + if (segExtraBytes > 0) {
1582 + // If we didn't read all of the bytes in the segment data,
1583 + // indicate an error, and throw away the rest of the data.
1585 + // v.3.1.01.13 of the LuraTech PDF Compressor Server will
1586 + // sometimes generate an extraneous NULL byte at the end of
1587 + // arithmetic-coded symbol dictionary segments when numNewSyms
1588 + // == 0. Segments like this often occur for blank pages.
1590 + error(getPos(), "%d extraneous byte%s after segment",
1591 + segExtraBytes, (segExtraBytes > 1) ? "s" : "");
1593 + // Burn through the remaining bytes -- inefficient, but
1594 + // hopefully we're not doing this much
1597 + for (int i = segExtraBytes; i > 0; i--) {
1601 + } else if (segExtraBytes < 0) {
1603 + // If we read more bytes than we should have, according to the
1604 + // segment length field, note an error.
1606 + error(getPos(), "Previous segment handler read too many bytes");
1615 @@ -1493,6 +1554,9 @@
1616 codeTables = new GList();
1618 for (i = 0; i < nRefSegs; ++i) {
1619 + // This is need by bug 12014, returning gFalse makes it not crash
1620 + // but we end up with a empty page while acroread is able to render
1622 if ((seg = findSegment(refSegs[i]))) {
1623 if (seg->getType() == jbig2SegSymbolDict) {
1624 j = ((JBIG2SymbolDict *)seg)->getSize();
1625 @@ -1503,8 +1567,11 @@
1628 } else if (seg->getType() == jbig2SegCodeTable) {
1629 - codeTables->append(seg);
1630 + codeTables->append(seg);
1633 + delete codeTables;
1637 if (numInputSyms > UINT_MAX - numNewSyms) {
1638 @@ -1530,12 +1600,11 @@
1640 inputSymbolDict = NULL;
1641 for (i = 0; i < nRefSegs; ++i) {
1642 - if ((seg = findSegment(refSegs[i]))) {
1643 - if (seg->getType() == jbig2SegSymbolDict) {
1644 - inputSymbolDict = (JBIG2SymbolDict *)seg;
1645 - for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1646 - bitmaps[k++] = inputSymbolDict->getBitmap(j);
1648 + seg = findSegment(refSegs[i]);
1649 + if (seg != NULL && seg->getType() == jbig2SegSymbolDict) {
1650 + inputSymbolDict = (JBIG2SymbolDict *)seg;
1651 + for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1652 + bitmaps[k++] = inputSymbolDict->getBitmap(j);
1656 @@ -1753,6 +1822,10 @@
1658 // create the symbol dict object
1659 symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
1660 + if (!symbolDict->isOk()) {
1661 + delete symbolDict;
1665 // exported symbol list
1667 @@ -1766,6 +1839,7 @@
1668 if (i + run > numInputSyms + numNewSyms ||
1669 (ex && j + run > numExSyms)) {
1670 error(getPos(), "Too many exported symbols in JBIG2 symbol dictionary");
1671 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1675 @@ -1780,6 +1854,7 @@
1677 if (j != numExSyms) {
1678 error(getPos(), "Too few symbols in JBIG2 symbol dictionary");
1679 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1683 @@ -2095,18 +2170,20 @@
1687 - // combine the region bitmap into the page bitmap
1689 - if (pageH == 0xffffffff && y + h > curPageH) {
1690 - pageBitmap->expand(y + h, pageDefPixel);
1692 - pageBitmap->combine(bitmap, x, y, extCombOp);
1695 + // combine the region bitmap into the page bitmap
1697 + if (pageH == 0xffffffff && y + h > curPageH) {
1698 + pageBitmap->expand(y + h, pageDefPixel);
1700 + pageBitmap->combine(bitmap, x, y, extCombOp);
1703 - // store the region bitmap
1705 - bitmap->setSegNum(segNum);
1706 - segments->append(bitmap);
1707 + // store the region bitmap
1709 + bitmap->setSegNum(segNum);
1710 + segments->append(bitmap);
1714 // clean up the Huffman decoder
1715 @@ -2159,6 +2236,10 @@
1717 // allocate the bitmap
1718 bitmap = new JBIG2Bitmap(0, w, h);
1719 + if (!bitmap->isOk()) {
1724 bitmap->clearToOne();
1726 @@ -2235,73 +2316,84 @@
1730 + GBool decodeSuccess;
1732 - huffDecoder->decodeInt(&rdw, huffRDWTable);
1733 - huffDecoder->decodeInt(&rdh, huffRDHTable);
1734 - huffDecoder->decodeInt(&rdx, huffRDXTable);
1735 - huffDecoder->decodeInt(&rdy, huffRDYTable);
1736 - huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1737 + decodeSuccess = huffDecoder->decodeInt(&rdw, huffRDWTable);
1738 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdh, huffRDHTable);
1739 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdx, huffRDXTable);
1740 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdy, huffRDYTable);
1741 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1742 huffDecoder->reset();
1743 arithDecoder->start();
1745 - arithDecoder->decodeInt(&rdw, iardwStats);
1746 - arithDecoder->decodeInt(&rdh, iardhStats);
1747 - arithDecoder->decodeInt(&rdx, iardxStats);
1748 - arithDecoder->decodeInt(&rdy, iardyStats);
1749 + decodeSuccess = arithDecoder->decodeInt(&rdw, iardwStats);
1750 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdh, iardhStats);
1751 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdx, iardxStats);
1752 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdy, iardyStats);
1755 + if (decodeSuccess && syms[symID])
1757 + refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1758 + refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1761 + readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1762 + rdh + syms[symID]->getHeight(),
1763 + templ, gFalse, syms[symID],
1764 + refDX, refDY, atx, aty);
1766 - refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1767 - refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1770 - readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1771 - rdh + syms[symID]->getHeight(),
1772 - templ, gFalse, syms[symID],
1773 - refDX, refDY, atx, aty);
1774 //~ do we need to use the bmSize value here (in Huffman mode)?
1776 symbolBitmap = syms[symID];
1779 - // combine the symbol bitmap into the region bitmap
1780 - //~ something is wrong here - refCorner shouldn't degenerate into
1782 - bw = symbolBitmap->getWidth() - 1;
1783 - bh = symbolBitmap->getHeight() - 1;
1785 - switch (refCorner) {
1786 - case 0: // bottom left
1787 - bitmap->combine(symbolBitmap, tt, s, combOp);
1789 - case 1: // top left
1790 - bitmap->combine(symbolBitmap, tt, s, combOp);
1792 - case 2: // bottom right
1793 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1795 - case 3: // top right
1796 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1798 + if (symbolBitmap) {
1799 + // combine the symbol bitmap into the region bitmap
1800 + //~ something is wrong here - refCorner shouldn't degenerate into
1802 + bw = symbolBitmap->getWidth() - 1;
1803 + bh = symbolBitmap->getHeight() - 1;
1805 + switch (refCorner) {
1806 + case 0: // bottom left
1807 + bitmap->combine(symbolBitmap, tt, s, combOp);
1809 + case 1: // top left
1810 + bitmap->combine(symbolBitmap, tt, s, combOp);
1812 + case 2: // bottom right
1813 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1815 + case 3: // top right
1816 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1821 + switch (refCorner) {
1822 + case 0: // bottom left
1823 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1825 + case 1: // top left
1826 + bitmap->combine(symbolBitmap, s, tt, combOp);
1828 + case 2: // bottom right
1829 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1831 + case 3: // top right
1832 + bitmap->combine(symbolBitmap, s, tt, combOp);
1839 - switch (refCorner) {
1840 - case 0: // bottom left
1841 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1843 - case 1: // top left
1844 - bitmap->combine(symbolBitmap, s, tt, combOp);
1846 - case 2: // bottom right
1847 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1849 - case 3: // top right
1850 - bitmap->combine(symbolBitmap, s, tt, combOp);
1853 + delete symbolBitmap;
1858 - delete symbolBitmap;
1860 + // NULL symbolBitmap only happens on error
1866 @@ -2431,11 +2523,12 @@
1867 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1870 - if (!(seg = findSegment(refSegs[0])) ||
1871 - seg->getType() != jbig2SegPatternDict) {
1872 + seg = findSegment(refSegs[0]);
1873 + if (seg == NULL || seg->getType() != jbig2SegPatternDict) {
1874 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1878 patternDict = (JBIG2PatternDict *)seg;
1881 @@ -2591,6 +2684,8 @@
1883 bitmap = readGenericBitmap(mmr, w, h, templ, tpgdOn, gFalse,
1884 NULL, atx, aty, mmr ? length - 18 : 0);
1888 // combine the region bitmap into the page bitmap
1890 @@ -2616,7 +2711,7 @@
1891 int *codingLine, int *a0i, int w) {
1892 if (a1 > codingLine[*a0i]) {
1894 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1895 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1898 if ((*a0i & 1) ^ blackPixels) {
1899 @@ -2630,7 +2725,7 @@
1900 int *codingLine, int *a0i, int w) {
1901 if (a1 > codingLine[*a0i]) {
1903 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1904 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1907 if ((*a0i & 1) ^ blackPixels) {
1908 @@ -2657,13 +2752,17 @@
1909 JBIG2Bitmap *bitmap;
1911 Guint ltpCX, cx, cx0, cx1, cx2;
1912 - JBIG2BitmapPtr cxPtr0, cxPtr1;
1913 - JBIG2BitmapPtr atPtr0, atPtr1, atPtr2, atPtr3;
1914 + JBIG2BitmapPtr cxPtr0 = {0}, cxPtr1 = {0};
1915 + JBIG2BitmapPtr atPtr0 = {0}, atPtr1 = {0}, atPtr2 = {0}, atPtr3 = {0};
1916 int *refLine, *codingLine;
1917 int code1, code2, code3;
1918 int x, y, a0i, b1i, blackPixels, pix, i;
1920 bitmap = new JBIG2Bitmap(0, w, h);
1921 + if (!bitmap->isOk()) {
1925 bitmap->clearToZero();
1928 @@ -2682,7 +2781,7 @@
1929 // ---> max refLine size = w + 2
1930 codingLine = (int *)gmallocn(w + 1, sizeof(int));
1931 refLine = (int *)gmallocn(w + 2, sizeof(int));
1932 - codingLine[0] = w;
1933 + for (i = 0; i < w + 1; ++i) codingLine[i] = w;
1935 for (y = 0; y < h; ++y) {
1937 @@ -3093,8 +3192,8 @@
1940 if (nRefSegs == 1) {
1941 - if (!(seg = findSegment(refSegs[0])) ||
1942 - seg->getType() != jbig2SegBitmap) {
1943 + seg = findSegment(refSegs[0]);
1944 + if (seg == NULL || seg->getType() != jbig2SegBitmap) {
1945 error(getPos(), "Bad bitmap reference in JBIG2 generic refinement segment");
1948 @@ -3143,11 +3242,24 @@
1949 JBIG2Bitmap *bitmap;
1951 Guint ltpCX, cx, cx0, cx2, cx3, cx4, tpgrCX0, tpgrCX1, tpgrCX2;
1952 - JBIG2BitmapPtr cxPtr0, cxPtr1, cxPtr2, cxPtr3, cxPtr4, cxPtr5, cxPtr6;
1953 - JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
1954 + JBIG2BitmapPtr cxPtr0 = {0};
1955 + JBIG2BitmapPtr cxPtr1 = {0};
1956 + JBIG2BitmapPtr cxPtr2 = {0};
1957 + JBIG2BitmapPtr cxPtr3 = {0};
1958 + JBIG2BitmapPtr cxPtr4 = {0};
1959 + JBIG2BitmapPtr cxPtr5 = {0};
1960 + JBIG2BitmapPtr cxPtr6 = {0};
1961 + JBIG2BitmapPtr tpgrCXPtr0 = {0};
1962 + JBIG2BitmapPtr tpgrCXPtr1 = {0};
1963 + JBIG2BitmapPtr tpgrCXPtr2 = {0};
1966 bitmap = new JBIG2Bitmap(0, w, h);
1967 + if (!bitmap->isOk())
1972 bitmap->clearToZero();
1974 // set up the typical row context
1975 @@ -3332,6 +3444,12 @@
1977 pageBitmap = new JBIG2Bitmap(0, pageW, curPageH);
1979 + if (!pageBitmap->isOk()) {
1980 + delete pageBitmap;
1981 + pageBitmap = NULL;
1985 // default pixel value
1987 pageBitmap->clearToOne();