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 haveCompMap = gFalse;
661 haveChannelDefn = gFalse;
673 GBool haveBPC, haveCSMode;
675 csPrec = 0; // make gcc happy
676 + Guint num_components = 0;
677 haveBPC = haveCSMode = gFalse;
679 if (str->lookChar() == 0xff) {
682 if (readULong(&dummy) &&
684 - readUWord(&dummy) &&
685 + readUWord(&num_components) &&
693 + if(*csMode == streamCSDeviceRGB && num_components == 4) {
694 + *csMode = streamCSDeviceRGBX;
699 --- xpdf/Lexer.cc.orig 2010-05-18 11:22:18.000000000 -0700
700 +++ xpdf/Lexer.cc 2010-05-18 11:22:18.000000000 -0700
702 curStr.streamReset();
705 +static int illegalChars = 0;
708 if (!curStr.isNone()) {
714 + error(0, "Illegal characters in hex string (%d)", illegalChars);
718 int Lexer::getChar() {
720 } else if (c2 >= 'a' && c2 <= 'f') {
723 - error(getPos(), "Illegal digit in hex char in name");
725 + //error(getPos(), "Illegal digit in hex char in name");
731 else if (c >= 'a' && c <= 'f')
734 - error(getPos(), "Illegal character <%02x> in hex string", c);
737 + //error(getPos(), "Illegal character <%02x> in hex string", c);
740 if (n == tokBufSize) {
744 obj->initCmd(tokBuf);
746 - error(getPos(), "Illegal character '>'");
748 + //error(getPos(), "Illegal character '>'");
756 - error(getPos(), "Illegal character '%c'", c);
757 + //error(getPos(), "Illegal character '%c'", c);
770 --- xpdf/Link.cc.orig 2010-05-18 11:22:18.000000000 -0700
771 +++ xpdf/Link.cc 2010-05-18 11:22:18.000000000 -0700
779 - error(-1, "Illegal annotation destination");
780 + error(-1, "Illegal annotation destination %d", destObj->getType());
791 - error(-1, "Illegal annotation destination");
792 + error(-1, "Illegal annotation destination %d", destObj->getType());
796 --- xpdf/OutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
797 +++ xpdf/OutputDev.h 2010-05-18 11:22:18.000000000 -0700
801 #include "CharTypes.h"
810 - virtual void startPage(int pageNum, GfxState *state) {}
811 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
814 virtual void endPage() {}
815 --- xpdf/SplashFTFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
816 +++ xpdf/SplashFTFont.cc 2010-05-18 11:22:18.000000000 -0700
820 face = fontFileA->face;
822 if (FT_New_Size(face, &sizeObj)) {
826 if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
830 + this->ascender = face->ascender;
831 + this->descender = face->descender;
833 // if the textMat values are too small, FreeType's fixed point
834 // arithmetic doesn't work so well
835 textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
840 +int SplashFTFont::getNumChars()
842 + SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
843 + return ff->face->num_glyphs;
846 SplashPath *SplashFTFont::getGlyphPath(int c) {
847 static FT_Outline_Funcs outlineFuncs = {
848 #if FREETYPE_MINOR <= 1
853 + this->last_advance = -1;
855 ff = (SplashFTFontFile *)fontFile;
856 ff->face->size = sizeObj;
857 FT_Set_Transform(ff->face, &textMatrix, NULL);
858 @@ -262,17 +275,24 @@
859 // skip the TrueType notdef glyph
862 - if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
864 + if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
865 + fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
868 if (FT_Get_Glyph(slot, &glyph)) {
871 + this->last_advance = glyph->advance.x/65536.0;
873 path.path = new SplashPath();
874 path.textScale = textScale;
875 path.needClose = gFalse;
876 - FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
877 + error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
878 &outlineFuncs, &path);
880 + fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
882 if (path.needClose) {
885 --- xpdf/SplashFTFont.h.orig 2010-05-18 11:22:18.000000000 -0700
886 +++ xpdf/SplashFTFont.h 2010-05-18 11:22:18.000000000 -0700
888 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
889 SplashGlyphBitmap *bitmap);
891 + // return the number of characters in this font
892 + virtual int getNumChars();
894 // Return the path for a glyph.
895 virtual SplashPath *getGlyphPath(int c);
897 --- xpdf/SplashFTFontEngine.cc.orig 2010-05-18 11:22:18.000000000 -0700
898 +++ xpdf/SplashFTFontEngine.cc 2010-05-18 11:22:18.000000000 -0700
909 --- xpdf/SplashFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
910 +++ xpdf/SplashFont.cc 2010-05-18 11:22:18.000000000 -0700
914 xMin = yMin = xMax = yMax = 0;
921 void SplashFont::initCache() {
922 --- xpdf/SplashFont.h.orig 2010-05-18 11:22:18.000000000 -0700
923 +++ xpdf/SplashFont.h 2010-05-18 11:22:18.000000000 -0700
925 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
926 SplashGlyphBitmap *bitmap) = 0;
928 + // return the number of characters in this font
929 + virtual int getNumChars() = 0;
931 // Return the path for a glyph.
932 virtual SplashPath *getGlyphPath(int c) = 0;
935 void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
936 { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
940 + double last_advance; //set after getGlyphPath()
943 SplashFontFile *fontFile;
944 --- xpdf/SplashFontFile.cc.orig 2010-05-18 11:22:18.000000000 -0700
945 +++ xpdf/SplashFontFile.cc 2010-05-18 11:22:18.000000000 -0700
951 -# include <unistd.h>
955 #include "SplashFontFile.h"
956 #include "SplashFontFileID.h"
957 --- xpdf/SplashOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
958 +++ xpdf/SplashOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
966 #include "GlobalParams.h"
971 -void SplashOutputDev::startPage(int pageNum, GfxState *state) {
972 +void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
976 @@ -2646,9 +2647,9 @@
978 softMask = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(),
979 1, splashModeMono8, gFalse);
980 - memset(softMask->getDataPtr(), 0,
981 - softMask->getRowSize() * softMask->getHeight());
982 + memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
983 p = softMask->getDataPtr() + ty * softMask->getRowSize() + tx;
984 + if (tx<softMask->getWidth() && ty<softMask->getHeight())
985 for (y = 0; y < tBitmap->getHeight(); ++y) {
986 for (x = 0; x < tBitmap->getWidth(); ++x) {
987 tBitmap->getPixel(x, y, color);
988 --- xpdf/SplashOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
989 +++ xpdf/SplashOutputDev.h 2010-05-18 11:22:18.000000000 -0700
991 //----- initialization and control
994 - virtual void startPage(int pageNum, GfxState *state);
995 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
998 virtual void endPage();
1000 virtual void setVectorAntialias(GBool vaa);
1003 + void doUpdateFont(GfxState *state);
1005 + SplashPath *convertPath(GfxState *state, GfxPath *path);
1008 void setupScreenParams(double hDPI, double vDPI);
1011 SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
1013 - SplashPath *convertPath(GfxState *state, GfxPath *path);
1014 - void doUpdateFont(GfxState *state);
1015 void drawType3Glyph(T3FontCache *t3Font,
1016 T3FontCacheTag *tag, Guchar *data);
1017 static GBool imageMaskSrc(void *data, SplashColorPtr line);
1018 --- xpdf/SplashScreen.cc.orig 2010-05-18 11:22:18.000000000 -0700
1019 +++ xpdf/SplashScreen.cc 2010-05-18 11:22:18.000000000 -0700
1021 int SplashScreen::test(int x, int y, Guchar value) {
1026 if (value < minVal) {
1029 --- xpdf/SplashXPathScanner.cc.orig 2010-05-18 11:22:18.000000000 -0700
1030 +++ xpdf/SplashXPathScanner.cc 2010-05-18 11:22:18.000000000 -0700
1031 @@ -394,10 +394,10 @@
1035 - for (; xx + 7 <= xx0; xx += 8) {
1036 + for (; xx + 7 < xx0; xx += 8) {
1041 *p &= 0xff >> (xx0 & 7);
1044 @@ -417,10 +417,10 @@
1048 - for (; xx + 7 <= xx0; xx += 8) {
1049 + for (; xx + 7 < xx0; xx += 8) {
1054 *p &= 0xff >> (xx0 & 7);
1057 --- xpdf/Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
1058 +++ xpdf/Stream.cc 2010-05-18 11:22:18.000000000 -0700
1064 +extern "C" int unlink(char *filename);
1068 @@ -2456,6 +2460,9 @@
1069 // check for an EOB run
1071 while (i <= scanInfo.lastCoeff) {
1077 if ((bit = readBit()) == EOF) {
1078 @@ -2480,6 +2487,9 @@
1088 @@ -2505,6 +2515,9 @@
1091 while (i <= scanInfo.lastCoeff) {
1097 if ((bit = readBit()) == EOF) {
1098 @@ -2527,6 +2540,9 @@
1106 while (data[j] != 0) {
1107 if ((bit = readBit()) == EOF) {
1108 @@ -2535,6 +2551,9 @@
1110 data[j] += 1 << scanInfo.al;
1118 --- xpdf/Stream.h.orig 2010-05-18 11:22:18.000000000 -0700
1119 +++ xpdf/Stream.h 2010-05-18 11:22:18.000000000 -0700
1124 - streamCSDeviceCMYK
1125 + streamCSDeviceCMYK,
1126 + streamCSDeviceRGBX
1129 //------------------------------------------------------------------------
1130 --- xpdf/TextOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
1131 +++ xpdf/TextOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
1132 @@ -3877,7 +3877,7 @@
1136 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
1137 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
1138 text->startPage(state);
1141 --- xpdf/TextOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
1142 +++ xpdf/TextOutputDev.h 2010-05-18 11:22:18.000000000 -0700
1144 friend class TextFlow;
1145 friend class TextWordList;
1146 friend class TextPage;
1147 + friend class XMLOutputDev;
1150 //------------------------------------------------------------------------
1152 //----- initialization and control
1155 - virtual void startPage(int pageNum, GfxState *state);
1156 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
1159 virtual void endPage();
1160 --- xpdf/gfile.cc.orig 2010-05-18 11:22:18.000000000 -0700
1161 +++ xpdf/gfile.cc 2010-05-18 11:22:18.000000000 -0700
1162 @@ -439,6 +439,52 @@
1166 +static char* getTempDir()
1169 + char*dir = getenv("TMP");
1170 + if(!dir) dir = getenv("TEMP");
1171 + if(!dir) dir = getenv("tmp");
1172 + if(!dir) dir = getenv("temp");
1173 + if(!dir) dir = "C:\\";
1175 + char* dir = "/tmp/";
1180 +char* mktmpname(char*ptr) {
1181 + static char tmpbuf[128];
1182 + char*dir = getTempDir();
1183 + int l = strlen(dir);
1187 + if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
1195 + // used to be mktemp. This does remove the warnings, but
1196 + // It's not exactly an improvement.
1197 +#ifdef HAVE_LRAND48
1198 + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
1201 + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
1203 + static int count = 1;
1204 + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
1212 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
1214 //---------- Win32 ----------
1217 t = (int)time(NULL);
1218 for (i = 0; i < 1000; ++i) {
1219 - sprintf(buf, "%d", t + i);
1220 + sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
1221 s2 = s->copy()->append(buf);
1225 if (!(f2 = fopen(s2->getCString(), "r"))) {
1226 if (!(f2 = fopen(s2->getCString(), mode))) {
1238 + fprintf(stderr, "Couldn't create temporary file\n");
1241 #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
1243 // with this file name after the tmpnam call and before the fopen
1244 // call. I will happily accept fixes to this function for non-Unix
1246 - if (!(s = tmpnam(NULL))) {
1247 + if (!(s = mktmpname(NULL))) {
1250 *name = new GString(s);
1252 (*name)->append("/XXXXXX")->append(ext);
1253 fd = mkstemps((*name)->getCString(), strlen(ext));
1255 - if (!(s = tmpnam(NULL))) {
1256 + if (!(s = mktmpname(NULL))) {
1259 *name = new GString(s);
1261 (*name)->append("/XXXXXX");
1262 fd = mkstemp((*name)->getCString());
1263 #else // HAVE_MKSTEMP
1264 - if (!(s = tmpnam(NULL))) {
1265 + if (!(s = mktmpname(NULL))) {
1268 *name = new GString(s);
1269 --- xpdf/gfile.h.orig 2010-05-18 11:22:18.000000000 -0700
1270 +++ xpdf/gfile.h 2010-05-18 11:22:18.000000000 -0700
1272 // Get current directory.
1273 extern GString *getCurrentDir();
1275 +/* create a temporary filename */
1276 +char* mktmpname(char*ptr);
1278 // Append a file name to a path string. <path> may be an empty
1279 // string, denoting the current directory). Returns <path>.
1280 extern GString *appendToPath(GString *path, char *fileName);
1281 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:33:21.000000000 -0700
1282 +++ xpdf/JBIG2Stream.cc 2010-06-03 16:55:03.000000000 -0700
1285 //========================================================================
1288 +//========================================================================
1290 +// Modified under the Poppler project - http://poppler.freedesktop.org
1292 +// All changes made under the Poppler project to this file are licensed
1293 +// under GPL version 2 or later
1295 +// Copyright (C) 2006 Raj Kumar <rkumar@archive.org>
1296 +// Copyright (C) 2006 Paul Walmsley <paul@booyaka.com>
1297 +// Copyright (C) 2006-2009 Albert Astals Cid <aacid@kde.org>
1298 +// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
1300 +// To see a description of the changes please see the Changelog file that
1301 +// came with your tarball or type make ChangeLog if you are building from git
1303 +//========================================================================
1305 +#include <config.h>
1307 #ifdef USE_GCC_PRAGMAS
1308 #pragma implementation
1311 //------------------------------------------------------------------------
1313 -static int contextSize[4] = { 16, 13, 10, 10 };
1314 -static int refContextSize[2] = { 13, 10 };
1315 +static const int contextSize[4] = { 16, 13, 10, 10 };
1316 +static const int refContextSize[2] = { 13, 10 };
1318 //------------------------------------------------------------------------
1319 // JBIG2HuffmanTable
1324 -JBIG2HuffmanTable huffTableA[] = {
1325 +static JBIG2HuffmanTable huffTableA[] = {
1327 { 16, 2, 8, 0x002 },
1328 { 272, 3, 16, 0x006 },
1330 { 0, 0, jbig2HuffmanEOT, 0 }
1333 -JBIG2HuffmanTable huffTableB[] = {
1334 +static JBIG2HuffmanTable huffTableB[] = {
1339 { 0, 0, jbig2HuffmanEOT, 0 }
1342 -JBIG2HuffmanTable huffTableC[] = {
1343 +static JBIG2HuffmanTable huffTableC[] = {
1348 { 0, 0, jbig2HuffmanEOT, 0 }
1351 -JBIG2HuffmanTable huffTableD[] = {
1352 +static JBIG2HuffmanTable huffTableD[] = {
1357 { 0, 0, jbig2HuffmanEOT, 0 }
1360 -JBIG2HuffmanTable huffTableE[] = {
1361 +static JBIG2HuffmanTable huffTableE[] = {
1366 { 0, 0, jbig2HuffmanEOT, 0 }
1369 -JBIG2HuffmanTable huffTableF[] = {
1370 +static JBIG2HuffmanTable huffTableF[] = {
1372 { 128, 3, 7, 0x002 },
1373 { 256, 3, 8, 0x003 },
1375 { 0, 0, jbig2HuffmanEOT, 0 }
1378 -JBIG2HuffmanTable huffTableG[] = {
1379 +static JBIG2HuffmanTable huffTableG[] = {
1380 { -512, 3, 8, 0x000 },
1381 { 256, 3, 8, 0x001 },
1382 { 512, 3, 9, 0x002 },
1384 { 0, 0, jbig2HuffmanEOT, 0 }
1387 -JBIG2HuffmanTable huffTableH[] = {
1388 +static JBIG2HuffmanTable huffTableH[] = {
1390 { 0, 2, jbig2HuffmanOOB, 0x001 },
1393 { 0, 0, jbig2HuffmanEOT, 0 }
1396 -JBIG2HuffmanTable huffTableI[] = {
1397 +static JBIG2HuffmanTable huffTableI[] = {
1398 { 0, 2, jbig2HuffmanOOB, 0x000 },
1399 { -1, 3, 1, 0x002 },
1402 { 0, 0, jbig2HuffmanEOT, 0 }
1405 -JBIG2HuffmanTable huffTableJ[] = {
1406 +static JBIG2HuffmanTable huffTableJ[] = {
1407 { -2, 2, 2, 0x000 },
1409 { 0, 2, jbig2HuffmanOOB, 0x002 },
1411 { 0, 0, jbig2HuffmanEOT, 0 }
1414 -JBIG2HuffmanTable huffTableK[] = {
1415 +static JBIG2HuffmanTable huffTableK[] = {
1420 { 0, 0, jbig2HuffmanEOT, 0 }
1423 -JBIG2HuffmanTable huffTableL[] = {
1424 +static JBIG2HuffmanTable huffTableL[] = {
1429 { 0, 0, jbig2HuffmanEOT, 0 }
1432 -JBIG2HuffmanTable huffTableM[] = {
1433 +static JBIG2HuffmanTable huffTableM[] = {
1438 { 0, 0, jbig2HuffmanEOT, 0 }
1441 -JBIG2HuffmanTable huffTableN[] = {
1442 +static JBIG2HuffmanTable huffTableN[] = {
1444 { -2, 3, 0, 0x004 },
1445 { -1, 3, 0, 0x005 },
1447 { 0, 0, jbig2HuffmanEOT, 0 }
1450 -JBIG2HuffmanTable huffTableO[] = {
1451 +static JBIG2HuffmanTable huffTableO[] = {
1453 { -1, 3, 0, 0x004 },
1458 int JBIG2MMRDecoder::get2DCode() {
1460 + const CCITTCode *p;
1463 buf = str->getChar() & 0xff;
1467 int JBIG2MMRDecoder::getWhiteCode() {
1469 + const CCITTCode *p;
1476 int JBIG2MMRDecoder::getBlackCode() {
1478 + const CCITTCode *p;
1483 void combine(JBIG2Bitmap *bitmap, int x, int y, Guint combOp);
1484 Guchar *getDataPtr() { return data; }
1485 int getDataSize() { return h * line; }
1486 + GBool isOk() { return data != NULL; }
1490 @@ -685,10 +703,11 @@
1493 line = (wA + 7) >> 3;
1495 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1496 - // force a call to gmalloc(-1), which will throw an exception
1499 + error(-1, "invalid width/height");
1503 // need to allocate one extra guard byte for use in combine()
1504 data = (Guchar *)gmalloc(h * line + 1);
1505 @@ -701,10 +720,11 @@
1508 line = bitmap->line;
1510 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1511 - // force a call to gmalloc(-1), which will throw an exception
1514 + error(-1, "invalid width/height");
1518 // need to allocate one extra guard byte for use in combine()
1519 data = (Guchar *)gmalloc(h * line + 1);
1522 void JBIG2Bitmap::expand(int newH, Guint pixel) {
1523 if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
1524 + error(-1, "invalid width/height");
1529 // need to allocate one extra guard byte for use in combine()
1530 @@ -1002,6 +1025,7 @@
1531 Guint getSize() { return size; }
1532 void setBitmap(Guint idx, JBIG2Bitmap *bitmap) { bitmaps[idx] = bitmap; }
1533 JBIG2Bitmap *getBitmap(Guint idx) { return bitmaps[idx]; }
1534 + GBool isOk() { return bitmaps != NULL; }
1535 void setGenericRegionStats(JArithmeticDecoderStats *stats)
1536 { genericRegionStats = stats; }
1537 void setRefinementRegionStats(JArithmeticDecoderStats *stats)
1538 @@ -1022,13 +1046,9 @@
1539 JBIG2SymbolDict::JBIG2SymbolDict(Guint segNumA, Guint sizeA):
1540 JBIG2Segment(segNumA)
1545 bitmaps = (JBIG2Bitmap **)gmallocn(size, sizeof(JBIG2Bitmap *));
1546 - for (i = 0; i < size; ++i) {
1547 - bitmaps[i] = NULL;
1549 + if (!bitmaps) size = 0;
1550 genericRegionStats = NULL;
1551 refinementRegionStats = NULL;
1553 @@ -1037,9 +1057,7 @@
1556 for (i = 0; i < size; ++i) {
1558 - delete bitmaps[i];
1560 + delete bitmaps[i];
1563 if (genericRegionStats) {
1564 @@ -1247,6 +1265,7 @@
1565 Guint segNum, segFlags, segType, page, segLength;
1566 Guint refFlags, nRefSegs;
1572 @@ -1314,6 +1333,9 @@
1576 + // keep track of the start of the segment data
1577 + segDataPos = getPos();
1579 // check for missing page information segment
1580 if (!pageBitmap && ((segType >= 4 && segType <= 7) ||
1581 (segType >= 20 && segType <= 43))) {
1582 @@ -1398,6 +1420,45 @@
1586 + // Make sure the segment handler read all of the bytes in the
1587 + // segment data, unless this segment is marked as having an
1588 + // unknown length (section 7.2.7 of the JBIG2 Final Committee Draft)
1590 + if (segLength != 0xffffffff) {
1592 + int segExtraBytes = segDataPos + segLength - getPos();
1593 + if (segExtraBytes > 0) {
1595 + // If we didn't read all of the bytes in the segment data,
1596 + // indicate an error, and throw away the rest of the data.
1598 + // v.3.1.01.13 of the LuraTech PDF Compressor Server will
1599 + // sometimes generate an extraneous NULL byte at the end of
1600 + // arithmetic-coded symbol dictionary segments when numNewSyms
1601 + // == 0. Segments like this often occur for blank pages.
1603 + error(getPos(), "%d extraneous byte%s after segment",
1604 + segExtraBytes, (segExtraBytes > 1) ? "s" : "");
1606 + // Burn through the remaining bytes -- inefficient, but
1607 + // hopefully we're not doing this much
1610 + for (int i = segExtraBytes; i > 0; i--) {
1614 + } else if (segExtraBytes < 0) {
1616 + // If we read more bytes than we should have, according to the
1617 + // segment length field, note an error.
1619 + error(getPos(), "Previous segment handler read too many bytes");
1628 @@ -1493,6 +1554,9 @@
1629 codeTables = new GList();
1631 for (i = 0; i < nRefSegs; ++i) {
1632 + // This is need by bug 12014, returning gFalse makes it not crash
1633 + // but we end up with a empty page while acroread is able to render
1635 if ((seg = findSegment(refSegs[i]))) {
1636 if (seg->getType() == jbig2SegSymbolDict) {
1637 j = ((JBIG2SymbolDict *)seg)->getSize();
1638 @@ -1503,8 +1567,11 @@
1641 } else if (seg->getType() == jbig2SegCodeTable) {
1642 - codeTables->append(seg);
1643 + codeTables->append(seg);
1646 + delete codeTables;
1650 if (numInputSyms > UINT_MAX - numNewSyms) {
1651 @@ -1530,12 +1600,11 @@
1653 inputSymbolDict = NULL;
1654 for (i = 0; i < nRefSegs; ++i) {
1655 - if ((seg = findSegment(refSegs[i]))) {
1656 - if (seg->getType() == jbig2SegSymbolDict) {
1657 - inputSymbolDict = (JBIG2SymbolDict *)seg;
1658 - for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1659 - bitmaps[k++] = inputSymbolDict->getBitmap(j);
1661 + seg = findSegment(refSegs[i]);
1662 + if (seg != NULL && seg->getType() == jbig2SegSymbolDict) {
1663 + inputSymbolDict = (JBIG2SymbolDict *)seg;
1664 + for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1665 + bitmaps[k++] = inputSymbolDict->getBitmap(j);
1669 @@ -1753,6 +1822,10 @@
1671 // create the symbol dict object
1672 symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
1673 + if (!symbolDict->isOk()) {
1674 + delete symbolDict;
1678 // exported symbol list
1680 @@ -1766,6 +1839,7 @@
1681 if (i + run > numInputSyms + numNewSyms ||
1682 (ex && j + run > numExSyms)) {
1683 error(getPos(), "Too many exported symbols in JBIG2 symbol dictionary");
1684 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1688 @@ -1780,6 +1854,7 @@
1690 if (j != numExSyms) {
1691 error(getPos(), "Too few symbols in JBIG2 symbol dictionary");
1692 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1696 @@ -2095,18 +2170,20 @@
1700 - // combine the region bitmap into the page bitmap
1702 - if (pageH == 0xffffffff && y + h > curPageH) {
1703 - pageBitmap->expand(y + h, pageDefPixel);
1705 - pageBitmap->combine(bitmap, x, y, extCombOp);
1708 + // combine the region bitmap into the page bitmap
1710 + if (pageH == 0xffffffff && y + h > curPageH) {
1711 + pageBitmap->expand(y + h, pageDefPixel);
1713 + pageBitmap->combine(bitmap, x, y, extCombOp);
1716 - // store the region bitmap
1718 - bitmap->setSegNum(segNum);
1719 - segments->append(bitmap);
1720 + // store the region bitmap
1722 + bitmap->setSegNum(segNum);
1723 + segments->append(bitmap);
1727 // clean up the Huffman decoder
1728 @@ -2159,6 +2236,10 @@
1730 // allocate the bitmap
1731 bitmap = new JBIG2Bitmap(0, w, h);
1732 + if (!bitmap->isOk()) {
1737 bitmap->clearToOne();
1739 @@ -2235,73 +2316,84 @@
1743 + GBool decodeSuccess;
1745 - huffDecoder->decodeInt(&rdw, huffRDWTable);
1746 - huffDecoder->decodeInt(&rdh, huffRDHTable);
1747 - huffDecoder->decodeInt(&rdx, huffRDXTable);
1748 - huffDecoder->decodeInt(&rdy, huffRDYTable);
1749 - huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1750 + decodeSuccess = huffDecoder->decodeInt(&rdw, huffRDWTable);
1751 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdh, huffRDHTable);
1752 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdx, huffRDXTable);
1753 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdy, huffRDYTable);
1754 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1755 huffDecoder->reset();
1756 arithDecoder->start();
1758 - arithDecoder->decodeInt(&rdw, iardwStats);
1759 - arithDecoder->decodeInt(&rdh, iardhStats);
1760 - arithDecoder->decodeInt(&rdx, iardxStats);
1761 - arithDecoder->decodeInt(&rdy, iardyStats);
1762 + decodeSuccess = arithDecoder->decodeInt(&rdw, iardwStats);
1763 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdh, iardhStats);
1764 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdx, iardxStats);
1765 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdy, iardyStats);
1768 + if (decodeSuccess && syms[symID])
1770 + refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1771 + refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1774 + readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1775 + rdh + syms[symID]->getHeight(),
1776 + templ, gFalse, syms[symID],
1777 + refDX, refDY, atx, aty);
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);
1787 //~ do we need to use the bmSize value here (in Huffman mode)?
1789 symbolBitmap = syms[symID];
1792 - // combine the symbol bitmap into the region bitmap
1793 - //~ something is wrong here - refCorner shouldn't degenerate into
1795 - bw = symbolBitmap->getWidth() - 1;
1796 - bh = symbolBitmap->getHeight() - 1;
1798 - switch (refCorner) {
1799 - case 0: // bottom left
1800 - bitmap->combine(symbolBitmap, tt, s, combOp);
1802 - case 1: // top left
1803 - bitmap->combine(symbolBitmap, tt, s, combOp);
1805 - case 2: // bottom right
1806 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1808 - case 3: // top right
1809 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1811 + if (symbolBitmap) {
1812 + // combine the symbol bitmap into the region bitmap
1813 + //~ something is wrong here - refCorner shouldn't degenerate into
1815 + bw = symbolBitmap->getWidth() - 1;
1816 + bh = symbolBitmap->getHeight() - 1;
1818 + switch (refCorner) {
1819 + case 0: // bottom left
1820 + bitmap->combine(symbolBitmap, tt, s, combOp);
1822 + case 1: // top left
1823 + bitmap->combine(symbolBitmap, tt, s, combOp);
1825 + case 2: // bottom right
1826 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1828 + case 3: // top right
1829 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1834 + switch (refCorner) {
1835 + case 0: // bottom left
1836 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1838 + case 1: // top left
1839 + bitmap->combine(symbolBitmap, s, tt, combOp);
1841 + case 2: // bottom right
1842 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1844 + case 3: // top right
1845 + bitmap->combine(symbolBitmap, s, tt, combOp);
1852 - switch (refCorner) {
1853 - case 0: // bottom left
1854 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1856 - case 1: // top left
1857 - bitmap->combine(symbolBitmap, s, tt, combOp);
1859 - case 2: // bottom right
1860 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1862 - case 3: // top right
1863 - bitmap->combine(symbolBitmap, s, tt, combOp);
1866 + delete symbolBitmap;
1871 - delete symbolBitmap;
1873 + // NULL symbolBitmap only happens on error
1879 @@ -2431,11 +2523,12 @@
1880 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1883 - if (!(seg = findSegment(refSegs[0])) ||
1884 - seg->getType() != jbig2SegPatternDict) {
1885 + seg = findSegment(refSegs[0]);
1886 + if (seg == NULL || seg->getType() != jbig2SegPatternDict) {
1887 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1891 patternDict = (JBIG2PatternDict *)seg;
1894 @@ -2591,6 +2684,8 @@
1896 bitmap = readGenericBitmap(mmr, w, h, templ, tpgdOn, gFalse,
1897 NULL, atx, aty, mmr ? length - 18 : 0);
1901 // combine the region bitmap into the page bitmap
1903 @@ -2616,7 +2711,7 @@
1904 int *codingLine, int *a0i, int w) {
1905 if (a1 > codingLine[*a0i]) {
1907 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1908 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1911 if ((*a0i & 1) ^ blackPixels) {
1912 @@ -2630,7 +2725,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 @@ -2657,13 +2752,17 @@
1922 JBIG2Bitmap *bitmap;
1924 Guint ltpCX, cx, cx0, cx1, cx2;
1925 - JBIG2BitmapPtr cxPtr0, cxPtr1;
1926 - JBIG2BitmapPtr atPtr0, atPtr1, atPtr2, atPtr3;
1927 + JBIG2BitmapPtr cxPtr0 = {0}, cxPtr1 = {0};
1928 + JBIG2BitmapPtr atPtr0 = {0}, atPtr1 = {0}, atPtr2 = {0}, atPtr3 = {0};
1929 int *refLine, *codingLine;
1930 int code1, code2, code3;
1931 int x, y, a0i, b1i, blackPixels, pix, i;
1933 bitmap = new JBIG2Bitmap(0, w, h);
1934 + if (!bitmap->isOk()) {
1938 bitmap->clearToZero();
1941 @@ -2682,7 +2781,7 @@
1942 // ---> max refLine size = w + 2
1943 codingLine = (int *)gmallocn(w + 1, sizeof(int));
1944 refLine = (int *)gmallocn(w + 2, sizeof(int));
1945 - codingLine[0] = w;
1946 + for (i = 0; i < w + 1; ++i) codingLine[i] = w;
1948 for (y = 0; y < h; ++y) {
1950 @@ -3093,8 +3192,8 @@
1953 if (nRefSegs == 1) {
1954 - if (!(seg = findSegment(refSegs[0])) ||
1955 - seg->getType() != jbig2SegBitmap) {
1956 + seg = findSegment(refSegs[0]);
1957 + if (seg == NULL || seg->getType() != jbig2SegBitmap) {
1958 error(getPos(), "Bad bitmap reference in JBIG2 generic refinement segment");
1961 @@ -3143,11 +3242,24 @@
1962 JBIG2Bitmap *bitmap;
1964 Guint ltpCX, cx, cx0, cx2, cx3, cx4, tpgrCX0, tpgrCX1, tpgrCX2;
1965 - JBIG2BitmapPtr cxPtr0, cxPtr1, cxPtr2, cxPtr3, cxPtr4, cxPtr5, cxPtr6;
1966 - JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
1967 + JBIG2BitmapPtr cxPtr0 = {0};
1968 + JBIG2BitmapPtr cxPtr1 = {0};
1969 + JBIG2BitmapPtr cxPtr2 = {0};
1970 + JBIG2BitmapPtr cxPtr3 = {0};
1971 + JBIG2BitmapPtr cxPtr4 = {0};
1972 + JBIG2BitmapPtr cxPtr5 = {0};
1973 + JBIG2BitmapPtr cxPtr6 = {0};
1974 + JBIG2BitmapPtr tpgrCXPtr0 = {0};
1975 + JBIG2BitmapPtr tpgrCXPtr1 = {0};
1976 + JBIG2BitmapPtr tpgrCXPtr2 = {0};
1979 bitmap = new JBIG2Bitmap(0, w, h);
1980 + if (!bitmap->isOk())
1985 bitmap->clearToZero();
1987 // set up the typical row context
1988 @@ -3332,6 +3444,12 @@
1990 pageBitmap = new JBIG2Bitmap(0, pageW, curPageH);
1992 + if (!pageBitmap->isOk()) {
1993 + delete pageBitmap;
1994 + pageBitmap = NULL;
1998 // default pixel value
2000 pageBitmap->clearToOne();