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 --- xpdf/Stream.h.orig 2010-05-18 11:22:18.000000000 -0700
1056 +++ xpdf/Stream.h 2010-05-18 11:22:18.000000000 -0700
1061 - streamCSDeviceCMYK
1062 + streamCSDeviceCMYK,
1063 + streamCSDeviceRGBX
1066 //------------------------------------------------------------------------
1067 --- xpdf/TextOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
1068 +++ xpdf/TextOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
1069 @@ -3877,7 +3877,7 @@
1073 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
1074 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
1075 text->startPage(state);
1078 --- xpdf/TextOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
1079 +++ xpdf/TextOutputDev.h 2010-05-18 11:22:18.000000000 -0700
1081 friend class TextFlow;
1082 friend class TextWordList;
1083 friend class TextPage;
1084 + friend class XMLOutputDev;
1087 //------------------------------------------------------------------------
1089 //----- initialization and control
1092 - virtual void startPage(int pageNum, GfxState *state);
1093 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
1096 virtual void endPage();
1097 --- xpdf/gfile.cc.orig 2010-05-18 11:22:18.000000000 -0700
1098 +++ xpdf/gfile.cc 2010-05-18 11:22:18.000000000 -0700
1099 @@ -439,6 +439,52 @@
1103 +static char* getTempDir()
1106 + char*dir = getenv("TMP");
1107 + if(!dir) dir = getenv("TEMP");
1108 + if(!dir) dir = getenv("tmp");
1109 + if(!dir) dir = getenv("temp");
1110 + if(!dir) dir = "C:\\";
1112 + char* dir = "/tmp/";
1117 +char* mktmpname(char*ptr) {
1118 + static char tmpbuf[128];
1119 + char*dir = getTempDir();
1120 + int l = strlen(dir);
1124 + if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
1132 + // used to be mktemp. This does remove the warnings, but
1133 + // It's not exactly an improvement.
1134 +#ifdef HAVE_LRAND48
1135 + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
1138 + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
1140 + static int count = 1;
1141 + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
1149 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
1151 //---------- Win32 ----------
1154 t = (int)time(NULL);
1155 for (i = 0; i < 1000; ++i) {
1156 - sprintf(buf, "%d", t + i);
1157 + sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
1158 s2 = s->copy()->append(buf);
1162 if (!(f2 = fopen(s2->getCString(), "r"))) {
1163 if (!(f2 = fopen(s2->getCString(), mode))) {
1175 + fprintf(stderr, "Couldn't create temporary file\n");
1178 #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
1180 // with this file name after the tmpnam call and before the fopen
1181 // call. I will happily accept fixes to this function for non-Unix
1183 - if (!(s = tmpnam(NULL))) {
1184 + if (!(s = mktmpname(NULL))) {
1187 *name = new GString(s);
1189 (*name)->append("/XXXXXX")->append(ext);
1190 fd = mkstemps((*name)->getCString(), strlen(ext));
1192 - if (!(s = tmpnam(NULL))) {
1193 + if (!(s = mktmpname(NULL))) {
1196 *name = new GString(s);
1198 (*name)->append("/XXXXXX");
1199 fd = mkstemp((*name)->getCString());
1200 #else // HAVE_MKSTEMP
1201 - if (!(s = tmpnam(NULL))) {
1202 + if (!(s = mktmpname(NULL))) {
1205 *name = new GString(s);
1206 --- xpdf/gfile.h.orig 2010-05-18 11:22:18.000000000 -0700
1207 +++ xpdf/gfile.h 2010-05-18 11:22:18.000000000 -0700
1209 // Get current directory.
1210 extern GString *getCurrentDir();
1212 +/* create a temporary filename */
1213 +char* mktmpname(char*ptr);
1215 // Append a file name to a path string. <path> may be an empty
1216 // string, denoting the current directory). Returns <path>.
1217 extern GString *appendToPath(GString *path, char *fileName);
1218 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:33:21.000000000 -0700
1219 +++ xpdf/JBIG2Stream.cc 2010-06-03 16:55:03.000000000 -0700
1222 //========================================================================
1225 +//========================================================================
1227 +// Modified under the Poppler project - http://poppler.freedesktop.org
1229 +// All changes made under the Poppler project to this file are licensed
1230 +// under GPL version 2 or later
1232 +// Copyright (C) 2006 Raj Kumar <rkumar@archive.org>
1233 +// Copyright (C) 2006 Paul Walmsley <paul@booyaka.com>
1234 +// Copyright (C) 2006-2009 Albert Astals Cid <aacid@kde.org>
1235 +// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
1237 +// To see a description of the changes please see the Changelog file that
1238 +// came with your tarball or type make ChangeLog if you are building from git
1240 +//========================================================================
1242 +#include <config.h>
1244 #ifdef USE_GCC_PRAGMAS
1245 #pragma implementation
1248 //------------------------------------------------------------------------
1250 -static int contextSize[4] = { 16, 13, 10, 10 };
1251 -static int refContextSize[2] = { 13, 10 };
1252 +static const int contextSize[4] = { 16, 13, 10, 10 };
1253 +static const int refContextSize[2] = { 13, 10 };
1255 //------------------------------------------------------------------------
1256 // JBIG2HuffmanTable
1261 -JBIG2HuffmanTable huffTableA[] = {
1262 +static JBIG2HuffmanTable huffTableA[] = {
1264 { 16, 2, 8, 0x002 },
1265 { 272, 3, 16, 0x006 },
1267 { 0, 0, jbig2HuffmanEOT, 0 }
1270 -JBIG2HuffmanTable huffTableB[] = {
1271 +static JBIG2HuffmanTable huffTableB[] = {
1276 { 0, 0, jbig2HuffmanEOT, 0 }
1279 -JBIG2HuffmanTable huffTableC[] = {
1280 +static JBIG2HuffmanTable huffTableC[] = {
1285 { 0, 0, jbig2HuffmanEOT, 0 }
1288 -JBIG2HuffmanTable huffTableD[] = {
1289 +static JBIG2HuffmanTable huffTableD[] = {
1294 { 0, 0, jbig2HuffmanEOT, 0 }
1297 -JBIG2HuffmanTable huffTableE[] = {
1298 +static JBIG2HuffmanTable huffTableE[] = {
1303 { 0, 0, jbig2HuffmanEOT, 0 }
1306 -JBIG2HuffmanTable huffTableF[] = {
1307 +static JBIG2HuffmanTable huffTableF[] = {
1309 { 128, 3, 7, 0x002 },
1310 { 256, 3, 8, 0x003 },
1312 { 0, 0, jbig2HuffmanEOT, 0 }
1315 -JBIG2HuffmanTable huffTableG[] = {
1316 +static JBIG2HuffmanTable huffTableG[] = {
1317 { -512, 3, 8, 0x000 },
1318 { 256, 3, 8, 0x001 },
1319 { 512, 3, 9, 0x002 },
1321 { 0, 0, jbig2HuffmanEOT, 0 }
1324 -JBIG2HuffmanTable huffTableH[] = {
1325 +static JBIG2HuffmanTable huffTableH[] = {
1327 { 0, 2, jbig2HuffmanOOB, 0x001 },
1330 { 0, 0, jbig2HuffmanEOT, 0 }
1333 -JBIG2HuffmanTable huffTableI[] = {
1334 +static JBIG2HuffmanTable huffTableI[] = {
1335 { 0, 2, jbig2HuffmanOOB, 0x000 },
1336 { -1, 3, 1, 0x002 },
1339 { 0, 0, jbig2HuffmanEOT, 0 }
1342 -JBIG2HuffmanTable huffTableJ[] = {
1343 +static JBIG2HuffmanTable huffTableJ[] = {
1344 { -2, 2, 2, 0x000 },
1346 { 0, 2, jbig2HuffmanOOB, 0x002 },
1348 { 0, 0, jbig2HuffmanEOT, 0 }
1351 -JBIG2HuffmanTable huffTableK[] = {
1352 +static JBIG2HuffmanTable huffTableK[] = {
1357 { 0, 0, jbig2HuffmanEOT, 0 }
1360 -JBIG2HuffmanTable huffTableL[] = {
1361 +static JBIG2HuffmanTable huffTableL[] = {
1366 { 0, 0, jbig2HuffmanEOT, 0 }
1369 -JBIG2HuffmanTable huffTableM[] = {
1370 +static JBIG2HuffmanTable huffTableM[] = {
1375 { 0, 0, jbig2HuffmanEOT, 0 }
1378 -JBIG2HuffmanTable huffTableN[] = {
1379 +static JBIG2HuffmanTable huffTableN[] = {
1381 { -2, 3, 0, 0x004 },
1382 { -1, 3, 0, 0x005 },
1384 { 0, 0, jbig2HuffmanEOT, 0 }
1387 -JBIG2HuffmanTable huffTableO[] = {
1388 +static JBIG2HuffmanTable huffTableO[] = {
1390 { -1, 3, 0, 0x004 },
1395 int JBIG2MMRDecoder::get2DCode() {
1397 + const CCITTCode *p;
1400 buf = str->getChar() & 0xff;
1404 int JBIG2MMRDecoder::getWhiteCode() {
1406 + const CCITTCode *p;
1413 int JBIG2MMRDecoder::getBlackCode() {
1415 + const CCITTCode *p;
1420 void combine(JBIG2Bitmap *bitmap, int x, int y, Guint combOp);
1421 Guchar *getDataPtr() { return data; }
1422 int getDataSize() { return h * line; }
1423 + GBool isOk() { return data != NULL; }
1427 @@ -685,10 +703,11 @@
1430 line = (wA + 7) >> 3;
1432 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1433 - // force a call to gmalloc(-1), which will throw an exception
1436 + error(-1, "invalid width/height");
1440 // need to allocate one extra guard byte for use in combine()
1441 data = (Guchar *)gmalloc(h * line + 1);
1442 @@ -701,10 +720,11 @@
1445 line = bitmap->line;
1447 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1448 - // force a call to gmalloc(-1), which will throw an exception
1451 + error(-1, "invalid width/height");
1455 // need to allocate one extra guard byte for use in combine()
1456 data = (Guchar *)gmalloc(h * line + 1);
1459 void JBIG2Bitmap::expand(int newH, Guint pixel) {
1460 if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
1461 + error(-1, "invalid width/height");
1466 // need to allocate one extra guard byte for use in combine()
1467 @@ -1002,6 +1025,7 @@
1468 Guint getSize() { return size; }
1469 void setBitmap(Guint idx, JBIG2Bitmap *bitmap) { bitmaps[idx] = bitmap; }
1470 JBIG2Bitmap *getBitmap(Guint idx) { return bitmaps[idx]; }
1471 + GBool isOk() { return bitmaps != NULL; }
1472 void setGenericRegionStats(JArithmeticDecoderStats *stats)
1473 { genericRegionStats = stats; }
1474 void setRefinementRegionStats(JArithmeticDecoderStats *stats)
1475 @@ -1022,13 +1046,9 @@
1476 JBIG2SymbolDict::JBIG2SymbolDict(Guint segNumA, Guint sizeA):
1477 JBIG2Segment(segNumA)
1482 bitmaps = (JBIG2Bitmap **)gmallocn(size, sizeof(JBIG2Bitmap *));
1483 - for (i = 0; i < size; ++i) {
1484 - bitmaps[i] = NULL;
1486 + if (!bitmaps) size = 0;
1487 genericRegionStats = NULL;
1488 refinementRegionStats = NULL;
1490 @@ -1037,9 +1057,7 @@
1493 for (i = 0; i < size; ++i) {
1495 - delete bitmaps[i];
1497 + delete bitmaps[i];
1500 if (genericRegionStats) {
1501 @@ -1247,6 +1265,7 @@
1502 Guint segNum, segFlags, segType, page, segLength;
1503 Guint refFlags, nRefSegs;
1509 @@ -1314,6 +1333,9 @@
1513 + // keep track of the start of the segment data
1514 + segDataPos = getPos();
1516 // check for missing page information segment
1517 if (!pageBitmap && ((segType >= 4 && segType <= 7) ||
1518 (segType >= 20 && segType <= 43))) {
1519 @@ -1398,6 +1420,45 @@
1523 + // Make sure the segment handler read all of the bytes in the
1524 + // segment data, unless this segment is marked as having an
1525 + // unknown length (section 7.2.7 of the JBIG2 Final Committee Draft)
1527 + if (segLength != 0xffffffff) {
1529 + int segExtraBytes = segDataPos + segLength - getPos();
1530 + if (segExtraBytes > 0) {
1532 + // If we didn't read all of the bytes in the segment data,
1533 + // indicate an error, and throw away the rest of the data.
1535 + // v.3.1.01.13 of the LuraTech PDF Compressor Server will
1536 + // sometimes generate an extraneous NULL byte at the end of
1537 + // arithmetic-coded symbol dictionary segments when numNewSyms
1538 + // == 0. Segments like this often occur for blank pages.
1540 + error(getPos(), "%d extraneous byte%s after segment",
1541 + segExtraBytes, (segExtraBytes > 1) ? "s" : "");
1543 + // Burn through the remaining bytes -- inefficient, but
1544 + // hopefully we're not doing this much
1547 + for (int i = segExtraBytes; i > 0; i--) {
1551 + } else if (segExtraBytes < 0) {
1553 + // If we read more bytes than we should have, according to the
1554 + // segment length field, note an error.
1556 + error(getPos(), "Previous segment handler read too many bytes");
1565 @@ -1493,6 +1554,9 @@
1566 codeTables = new GList();
1568 for (i = 0; i < nRefSegs; ++i) {
1569 + // This is need by bug 12014, returning gFalse makes it not crash
1570 + // but we end up with a empty page while acroread is able to render
1572 if ((seg = findSegment(refSegs[i]))) {
1573 if (seg->getType() == jbig2SegSymbolDict) {
1574 j = ((JBIG2SymbolDict *)seg)->getSize();
1575 @@ -1503,8 +1567,11 @@
1578 } else if (seg->getType() == jbig2SegCodeTable) {
1579 - codeTables->append(seg);
1580 + codeTables->append(seg);
1583 + delete codeTables;
1587 if (numInputSyms > UINT_MAX - numNewSyms) {
1588 @@ -1530,12 +1600,11 @@
1590 inputSymbolDict = NULL;
1591 for (i = 0; i < nRefSegs; ++i) {
1592 - if ((seg = findSegment(refSegs[i]))) {
1593 - if (seg->getType() == jbig2SegSymbolDict) {
1594 - inputSymbolDict = (JBIG2SymbolDict *)seg;
1595 - for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1596 - bitmaps[k++] = inputSymbolDict->getBitmap(j);
1598 + seg = findSegment(refSegs[i]);
1599 + if (seg != NULL && seg->getType() == jbig2SegSymbolDict) {
1600 + inputSymbolDict = (JBIG2SymbolDict *)seg;
1601 + for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1602 + bitmaps[k++] = inputSymbolDict->getBitmap(j);
1606 @@ -1753,6 +1822,10 @@
1608 // create the symbol dict object
1609 symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
1610 + if (!symbolDict->isOk()) {
1611 + delete symbolDict;
1615 // exported symbol list
1617 @@ -1766,6 +1839,7 @@
1618 if (i + run > numInputSyms + numNewSyms ||
1619 (ex && j + run > numExSyms)) {
1620 error(getPos(), "Too many exported symbols in JBIG2 symbol dictionary");
1621 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1625 @@ -1780,6 +1854,7 @@
1627 if (j != numExSyms) {
1628 error(getPos(), "Too few symbols in JBIG2 symbol dictionary");
1629 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1633 @@ -2095,18 +2170,20 @@
1637 - // combine the region bitmap into the page bitmap
1639 - if (pageH == 0xffffffff && y + h > curPageH) {
1640 - pageBitmap->expand(y + h, pageDefPixel);
1642 - pageBitmap->combine(bitmap, x, y, extCombOp);
1645 + // combine the region bitmap into the page bitmap
1647 + if (pageH == 0xffffffff && y + h > curPageH) {
1648 + pageBitmap->expand(y + h, pageDefPixel);
1650 + pageBitmap->combine(bitmap, x, y, extCombOp);
1653 - // store the region bitmap
1655 - bitmap->setSegNum(segNum);
1656 - segments->append(bitmap);
1657 + // store the region bitmap
1659 + bitmap->setSegNum(segNum);
1660 + segments->append(bitmap);
1664 // clean up the Huffman decoder
1665 @@ -2159,6 +2236,10 @@
1667 // allocate the bitmap
1668 bitmap = new JBIG2Bitmap(0, w, h);
1669 + if (!bitmap->isOk()) {
1674 bitmap->clearToOne();
1676 @@ -2235,73 +2316,84 @@
1680 + GBool decodeSuccess;
1682 - huffDecoder->decodeInt(&rdw, huffRDWTable);
1683 - huffDecoder->decodeInt(&rdh, huffRDHTable);
1684 - huffDecoder->decodeInt(&rdx, huffRDXTable);
1685 - huffDecoder->decodeInt(&rdy, huffRDYTable);
1686 - huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1687 + decodeSuccess = huffDecoder->decodeInt(&rdw, huffRDWTable);
1688 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdh, huffRDHTable);
1689 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdx, huffRDXTable);
1690 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdy, huffRDYTable);
1691 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1692 huffDecoder->reset();
1693 arithDecoder->start();
1695 - arithDecoder->decodeInt(&rdw, iardwStats);
1696 - arithDecoder->decodeInt(&rdh, iardhStats);
1697 - arithDecoder->decodeInt(&rdx, iardxStats);
1698 - arithDecoder->decodeInt(&rdy, iardyStats);
1699 + decodeSuccess = arithDecoder->decodeInt(&rdw, iardwStats);
1700 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdh, iardhStats);
1701 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdx, iardxStats);
1702 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdy, iardyStats);
1705 + if (decodeSuccess && syms[symID])
1707 + refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1708 + refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1711 + readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1712 + rdh + syms[symID]->getHeight(),
1713 + templ, gFalse, syms[symID],
1714 + refDX, refDY, atx, aty);
1716 - refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1717 - refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1720 - readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1721 - rdh + syms[symID]->getHeight(),
1722 - templ, gFalse, syms[symID],
1723 - refDX, refDY, atx, aty);
1724 //~ do we need to use the bmSize value here (in Huffman mode)?
1726 symbolBitmap = syms[symID];
1729 - // combine the symbol bitmap into the region bitmap
1730 - //~ something is wrong here - refCorner shouldn't degenerate into
1732 - bw = symbolBitmap->getWidth() - 1;
1733 - bh = symbolBitmap->getHeight() - 1;
1735 - switch (refCorner) {
1736 - case 0: // bottom left
1737 - bitmap->combine(symbolBitmap, tt, s, combOp);
1739 - case 1: // top left
1740 - bitmap->combine(symbolBitmap, tt, s, combOp);
1742 - case 2: // bottom right
1743 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1745 - case 3: // top right
1746 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1748 + if (symbolBitmap) {
1749 + // combine the symbol bitmap into the region bitmap
1750 + //~ something is wrong here - refCorner shouldn't degenerate into
1752 + bw = symbolBitmap->getWidth() - 1;
1753 + bh = symbolBitmap->getHeight() - 1;
1755 + switch (refCorner) {
1756 + case 0: // bottom left
1757 + bitmap->combine(symbolBitmap, tt, s, combOp);
1759 + case 1: // top left
1760 + bitmap->combine(symbolBitmap, tt, s, combOp);
1762 + case 2: // bottom right
1763 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1765 + case 3: // top right
1766 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1771 + switch (refCorner) {
1772 + case 0: // bottom left
1773 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1775 + case 1: // top left
1776 + bitmap->combine(symbolBitmap, s, tt, combOp);
1778 + case 2: // bottom right
1779 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1781 + case 3: // top right
1782 + bitmap->combine(symbolBitmap, s, tt, combOp);
1789 - switch (refCorner) {
1790 - case 0: // bottom left
1791 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1793 - case 1: // top left
1794 - bitmap->combine(symbolBitmap, s, tt, combOp);
1796 - case 2: // bottom right
1797 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1799 - case 3: // top right
1800 - bitmap->combine(symbolBitmap, s, tt, combOp);
1803 + delete symbolBitmap;
1808 - delete symbolBitmap;
1810 + // NULL symbolBitmap only happens on error
1816 @@ -2431,11 +2523,12 @@
1817 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1820 - if (!(seg = findSegment(refSegs[0])) ||
1821 - seg->getType() != jbig2SegPatternDict) {
1822 + seg = findSegment(refSegs[0]);
1823 + if (seg == NULL || seg->getType() != jbig2SegPatternDict) {
1824 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1828 patternDict = (JBIG2PatternDict *)seg;
1831 @@ -2591,6 +2684,8 @@
1833 bitmap = readGenericBitmap(mmr, w, h, templ, tpgdOn, gFalse,
1834 NULL, atx, aty, mmr ? length - 18 : 0);
1838 // combine the region bitmap into the page bitmap
1840 @@ -2616,7 +2711,7 @@
1841 int *codingLine, int *a0i, int w) {
1842 if (a1 > codingLine[*a0i]) {
1844 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1845 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1848 if ((*a0i & 1) ^ blackPixels) {
1849 @@ -2630,7 +2725,7 @@
1850 int *codingLine, int *a0i, int w) {
1851 if (a1 > codingLine[*a0i]) {
1853 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1854 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1857 if ((*a0i & 1) ^ blackPixels) {
1858 @@ -2657,13 +2752,17 @@
1859 JBIG2Bitmap *bitmap;
1861 Guint ltpCX, cx, cx0, cx1, cx2;
1862 - JBIG2BitmapPtr cxPtr0, cxPtr1;
1863 - JBIG2BitmapPtr atPtr0, atPtr1, atPtr2, atPtr3;
1864 + JBIG2BitmapPtr cxPtr0 = {0}, cxPtr1 = {0};
1865 + JBIG2BitmapPtr atPtr0 = {0}, atPtr1 = {0}, atPtr2 = {0}, atPtr3 = {0};
1866 int *refLine, *codingLine;
1867 int code1, code2, code3;
1868 int x, y, a0i, b1i, blackPixels, pix, i;
1870 bitmap = new JBIG2Bitmap(0, w, h);
1871 + if (!bitmap->isOk()) {
1875 bitmap->clearToZero();
1878 @@ -2682,7 +2781,7 @@
1879 // ---> max refLine size = w + 2
1880 codingLine = (int *)gmallocn(w + 1, sizeof(int));
1881 refLine = (int *)gmallocn(w + 2, sizeof(int));
1882 - codingLine[0] = w;
1883 + for (i = 0; i < w + 1; ++i) codingLine[i] = w;
1885 for (y = 0; y < h; ++y) {
1887 @@ -3093,8 +3192,8 @@
1890 if (nRefSegs == 1) {
1891 - if (!(seg = findSegment(refSegs[0])) ||
1892 - seg->getType() != jbig2SegBitmap) {
1893 + seg = findSegment(refSegs[0]);
1894 + if (seg == NULL || seg->getType() != jbig2SegBitmap) {
1895 error(getPos(), "Bad bitmap reference in JBIG2 generic refinement segment");
1898 @@ -3143,11 +3242,24 @@
1899 JBIG2Bitmap *bitmap;
1901 Guint ltpCX, cx, cx0, cx2, cx3, cx4, tpgrCX0, tpgrCX1, tpgrCX2;
1902 - JBIG2BitmapPtr cxPtr0, cxPtr1, cxPtr2, cxPtr3, cxPtr4, cxPtr5, cxPtr6;
1903 - JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
1904 + JBIG2BitmapPtr cxPtr0 = {0};
1905 + JBIG2BitmapPtr cxPtr1 = {0};
1906 + JBIG2BitmapPtr cxPtr2 = {0};
1907 + JBIG2BitmapPtr cxPtr3 = {0};
1908 + JBIG2BitmapPtr cxPtr4 = {0};
1909 + JBIG2BitmapPtr cxPtr5 = {0};
1910 + JBIG2BitmapPtr cxPtr6 = {0};
1911 + JBIG2BitmapPtr tpgrCXPtr0 = {0};
1912 + JBIG2BitmapPtr tpgrCXPtr1 = {0};
1913 + JBIG2BitmapPtr tpgrCXPtr2 = {0};
1916 bitmap = new JBIG2Bitmap(0, w, h);
1917 + if (!bitmap->isOk())
1922 bitmap->clearToZero();
1924 // set up the typical row context
1925 @@ -3332,6 +3444,12 @@
1927 pageBitmap = new JBIG2Bitmap(0, pageW, curPageH);
1929 + if (!pageBitmap->isOk()) {
1930 + delete pageBitmap;
1931 + pageBitmap = NULL;
1935 // default pixel value
1937 pageBitmap->clearToOne();