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) &&
74 --- xpdf/CoreOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
75 +++ xpdf/CoreOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
78 void CoreOutputDev::clear() {
81 + startPage(0, NULL, 0,0,0,0);
83 --- xpdf/Decrypt.cc.orig 2010-05-18 11:22:18.000000000 -0700
84 +++ xpdf/Decrypt.cc 2010-05-18 11:22:18.000000000 -0700
89 + if(!n || n>16) n=16;
90 for (i = 15; i >= n; --i) {
91 s->buf[i] = s->buf[i-n];
93 --- xpdf/Gfx.cc.orig 2010-05-18 11:22:18.000000000 -0700
94 +++ xpdf/Gfx.cc 2010-05-18 11:22:18.000000000 -0700
99 - out->startPage(pageNum, state);
101 + out->startPage(pageNum, state, cropBox->x1,cropBox->y1,cropBox->x2,cropBox->y2);
103 + out->startPage(pageNum, state, 0,0,0,0);
105 out->setDefaultCTM(state->getCTM());
106 out->updateAll(state);
107 for (i = 0; i < 6; ++i) {
109 abortCheckCbkData = abortCheckCbkDataA;
114 state->moveTo(cropBox->x1, cropBox->y1);
115 state->lineTo(cropBox->x2, cropBox->y1);
123 Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
124 @@ -3182,8 +3188,11 @@
125 u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
126 &dx, &dy, &originX, &originY);
127 dx = dx * state->getFontSize() + state->getCharSpace();
128 - if (n == 1 && *p == ' ') {
129 - dx += state->getWordSpace();
130 + if (n == 1 && (*p == ' ' || *p == 0)) {
131 + double w=state->getWordSpace();
133 + w=state->getFontSize()/3; // workaround for zero word space
136 dx *= state->getHorizScaling();
137 dy *= state->getFontSize();
138 @@ -3476,11 +3485,13 @@
141 if (!obj1.isNull()) {
142 - colorSpace = GfxColorSpace::parse(&obj1);
143 + colorSpace = GfxColorSpace::parse(&obj1, csMode);
144 } else if (csMode == streamCSDeviceGray) {
145 colorSpace = new GfxDeviceGrayColorSpace();
146 } else if (csMode == streamCSDeviceRGB) {
147 colorSpace = new GfxDeviceRGBColorSpace();
148 + } else if (csMode == streamCSDeviceRGBX) {
149 + colorSpace = new GfxDeviceRGBXColorSpace();
150 } else if (csMode == streamCSDeviceCMYK) {
151 colorSpace = new GfxDeviceCMYKColorSpace();
153 @@ -3824,6 +3835,7 @@
154 out->beginTransparencyGroup(state, bbox, blendingColorSpace,
155 isolated, knockout, softMask);
157 + GfxState*old_state = state;
159 // set new base matrix
160 for (i = 0; i < 6; ++i) {
161 @@ -3835,6 +3847,9 @@
162 display(str, gFalse);
164 if (softMask || transpGroup) {
165 + // restore graphics state
166 + while(state != old_state)
168 out->endTransparencyGroup(state);
171 --- xpdf/GfxFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
172 +++ xpdf/GfxFont.cc 2010-05-18 11:22:18.000000000 -0700
177 +CharCodeToUnicode* Gfx8BitFont::getCTU() {
181 CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
184 @@ -1411,6 +1415,10 @@
188 +CharCodeToUnicode* GfxCIDFont::getCTU() {
192 int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
193 Unicode *u, int uSize, int *uLen,
194 double *dx, double *dy, double *ox, double *oy) {
195 --- xpdf/GfxFont.h.orig 2010-05-18 11:22:18.000000000 -0700
196 +++ xpdf/GfxFont.h 2010-05-18 11:22:18.000000000 -0700
198 virtual int getNextChar(char *s, int len, CharCode *code,
199 Unicode *u, int uSize, int *uLen,
200 double *dx, double *dy, double *ox, double *oy) = 0;
201 + virtual CharCodeToUnicode* getCTU() = 0;
206 virtual int getNextChar(char *s, int len, CharCode *code,
207 Unicode *u, int uSize, int *uLen,
208 double *dx, double *dy, double *ox, double *oy);
209 + virtual CharCodeToUnicode* getCTU();
211 // Return the encoding.
212 char **getEncoding() { return enc; }
214 CharCodeToUnicode *getToUnicode();
216 // Return the character name associated with <code>.
217 - char *getCharName(int code) { return enc[code]; }
218 + char *getCharName(int code) { return code>=256?0:enc[code]; }
220 // Returns true if the PDF font specified an encoding.
221 GBool getHasEncoding() { return hasEncoding; }
223 virtual int getNextChar(char *s, int len, CharCode *code,
224 Unicode *u, int uSize, int *uLen,
225 double *dx, double *dy, double *ox, double *oy);
226 + virtual CharCodeToUnicode* getCTU();
228 // Return the writing mode (0=horizontal, 1=vertical).
229 virtual int getWMode();
230 --- xpdf/GfxState.cc.orig 2010-05-18 11:22:18.000000000 -0700
231 +++ xpdf/GfxState.cc 2010-05-18 11:22:18.000000000 -0700
235 #include "GfxState.h"
238 //------------------------------------------------------------------------
241 GfxColorSpace::~GfxColorSpace() {
244 -GfxColorSpace *GfxColorSpace::parse(Object *csObj) {
245 +GfxColorSpace *GfxColorSpace::parse(Object *csObj, StreamColorSpaceMode csMode) {
250 if (csObj->isName("DeviceGray") || csObj->isName("G")) {
251 cs = new GfxDeviceGrayColorSpace();
252 } else if (csObj->isName("DeviceRGB") || csObj->isName("RGB")) {
253 - cs = new GfxDeviceRGBColorSpace();
254 + if(csMode == streamCSDeviceRGBX)
255 + cs = new GfxDeviceRGBXColorSpace();
257 + cs = new GfxDeviceRGBColorSpace();
258 } else if (csObj->isName("DeviceCMYK") || csObj->isName("CMYK")) {
259 cs = new GfxDeviceCMYKColorSpace();
260 } else if (csObj->isName("Pattern")) {
262 if (obj1.isName("DeviceGray") || obj1.isName("G")) {
263 cs = new GfxDeviceGrayColorSpace();
264 } else if (obj1.isName("DeviceRGB") || obj1.isName("RGB")) {
265 - cs = new GfxDeviceRGBColorSpace();
266 + if(csMode == streamCSDeviceRGBX)
267 + cs = new GfxDeviceRGBColorSpace();
269 + cs = new GfxDeviceRGBColorSpace();
270 } else if (obj1.isName("DeviceCMYK") || obj1.isName("CMYK")) {
271 cs = new GfxDeviceCMYKColorSpace();
272 } else if (obj1.isName("CalGray")) {
276 //------------------------------------------------------------------------
277 +// GfxDeviceRGBXColorSpace
278 +//------------------------------------------------------------------------
280 +GfxDeviceRGBXColorSpace::GfxDeviceRGBXColorSpace() {
283 +GfxColorSpace *GfxDeviceRGBXColorSpace::copy() {
284 + return new GfxDeviceRGBXColorSpace();
287 +//------------------------------------------------------------------------
288 // GfxCalRGBColorSpace
289 //------------------------------------------------------------------------
292 - 0.11 * color->c[2] + 0.5));
295 +/*void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
296 + unsigned char r,g,b;
297 + float c = color->c[0];
298 + float m = color->c[1];
299 + float y = color->c[2];
300 + float k = color->c[3];
301 + convert_cmyk2rgb(c,m,y,k, &r,&g,&b);
307 void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
308 double c, m, y, k, c1, m1, y1, k1, r, g, b, x;
310 @@ -3187,6 +3217,7 @@
311 GfxIndexedColorSpace *indexedCS;
312 GfxSeparationColorSpace *sepCS;
313 int maxPixel, indexHigh;
314 + int maxPixelForAlloc;
318 @@ -3199,6 +3230,7 @@
319 // bits per component and color space
321 maxPixel = (1 << bits) - 1;
322 + maxPixelForAlloc = (1 << (bits>8?bits:8));
323 colorSpace = colorSpaceA;
326 @@ -3253,7 +3285,7 @@
327 lookup2 = indexedCS->getLookup();
328 colorSpace2->getDefaultRanges(x, y, indexHigh);
329 for (k = 0; k < nComps2; ++k) {
330 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
331 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
332 sizeof(GfxColorComp));
333 for (i = 0; i <= maxPixel; ++i) {
334 j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
335 @@ -3272,7 +3304,7 @@
336 nComps2 = colorSpace2->getNComps();
337 sepFunc = sepCS->getFunc();
338 for (k = 0; k < nComps2; ++k) {
339 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
340 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
341 sizeof(GfxColorComp));
342 for (i = 0; i <= maxPixel; ++i) {
343 x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
344 @@ -3282,7 +3314,7 @@
347 for (k = 0; k < nComps; ++k) {
348 - lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
349 + lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
350 sizeof(GfxColorComp));
351 for (i = 0; i <= maxPixel; ++i) {
352 lookup[k][i] = dblToCol(decodeLow[k] +
353 @@ -3754,7 +3786,10 @@
356 void GfxState::setPath(GfxPath *pathA) {
364 --- xpdf/GfxState.h.orig 2010-05-18 11:22:18.000000000 -0700
365 +++ xpdf/GfxState.h 2010-05-18 11:22:18.000000000 -0700
367 virtual GfxColorSpaceMode getMode() = 0;
369 // Construct a color space. Returns NULL if unsuccessful.
370 - static GfxColorSpace *parse(Object *csObj);
371 + static GfxColorSpace *parse(Object *csObj, StreamColorSpaceMode csMode = streamCSNone);
373 // Convert to gray, RGB, or CMYK.
374 virtual void getGray(GfxColor *color, GfxGray *gray) = 0;
378 //------------------------------------------------------------------------
379 +// GfxDeviceRGBXColorSpace
380 +//------------------------------------------------------------------------
382 +class GfxDeviceRGBXColorSpace: public GfxDeviceRGBColorSpace {
385 + GfxDeviceRGBXColorSpace();
386 + virtual GfxColorSpace *copy();
387 + virtual int getNComps() { return 4; }
391 +//------------------------------------------------------------------------
392 // GfxCalRGBColorSpace
393 //------------------------------------------------------------------------
395 --- xpdf/GlobalParams.cc.orig 2010-05-18 11:22:18.000000000 -0700
396 +++ xpdf/GlobalParams.cc 2010-05-18 11:22:18.000000000 -0700
403 + char* cfgFileName = fileName->getCString();
404 + char* pos1 = strrchr(cfgFileName, '/');
405 + char* pos2 = strrchr(cfgFileName, '\\');
406 + char* p = pos1>pos2?pos1:pos2;
407 + int pos = p ? p-cfgFileName : -1;
408 + GString*path = new GString(new GString(cfgFileName), 0, (pos < 0 ? strlen(cfgFileName): pos));
412 + path->append('\\');
415 + path->append('\\');
421 + this->path = new GString();
425 while (getLine(buf, sizeof(buf) - 1, f)) {
426 parseLine(buf, fileName, line);
427 @@ -1114,6 +1137,42 @@
428 deleteGList(tokens, GString);
431 +static char is_absolute(char*filename)
433 + int l = strlen(filename);
434 + if(filename[0] == '/' || filename[0] == '\\')
436 + if(l>2 && filename[1]==':' && (filename[2]=='\\' || filename[2]=='/'))
441 +static GString* qualify_filename(GString*path, GString*filename)
443 + GString*fullpath = 0;
444 + char*prefix = "/usr/local/share/xpdf/";
446 + if (!is_absolute(filename->getCString())) {
447 + /* relative path */
448 + fullpath = path->copy();
449 + fullpath->append(filename);
450 + } else if (!strncmp(filename->getCString(), prefix, strlen(prefix))) {
451 + /* xpdf default path */
452 + char*s = strchr(filename->getCString()+strlen(prefix), '/');
454 + fullpath = path->copy();
455 + fullpath->append(s+1);
457 + fullpath = filename->copy();
460 + /* absolute path */
461 + fullpath = filename->copy();
463 + //printf("%s -%s-> %s\n", filename->getCString(), path->getCString(), fullpath->getCString());
467 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
470 @@ -1128,10 +1187,10 @@
471 fileName->getCString(), line);
474 - name = (GString *)tokens->get(1);
475 + name = qualify_filename(this->path, (GString *)tokens->get(1));
476 if (!(f = fopen(name->getCString(), "r"))) {
477 - error(-1, "Couldn't open 'nameToUnicode' file '%s'",
478 - name->getCString());
479 + error(-1, "Couldn't open 'nameToUnicode' file '%s' using path '%s'",
480 + name->getCString(), path->getCString());
484 @@ -1160,10 +1219,12 @@
486 collection = (GString *)tokens->get(1);
487 name = (GString *)tokens->get(2);
489 if ((old = (GString *)cidToUnicodes->remove(collection))) {
492 - cidToUnicodes->add(collection->copy(), name->copy());
494 + cidToUnicodes->add(collection->copy(), qualify_filename(this->path, name));
497 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
498 @@ -1180,7 +1241,8 @@
499 if ((old = (GString *)unicodeToUnicodes->remove(font))) {
502 - unicodeToUnicodes->add(font->copy(), file->copy());
504 + unicodeToUnicodes->add(font->copy(), qualify_filename(this->path, file));
507 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
508 @@ -1197,7 +1259,8 @@
509 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
512 - unicodeMaps->add(encodingName->copy(), name->copy());
514 + unicodeMaps->add(encodingName->copy(), qualify_filename(this->path, name));
517 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
518 @@ -1215,23 +1278,30 @@
520 cMapDirs->add(collection->copy(), list);
522 - list->append(dir->copy());
524 + list->append(qualify_filename(this->path, dir));
527 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
531 if (tokens->getLength() != 2) {
532 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
533 fileName->getCString(), line);
536 - toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
538 + dir = (GString *)tokens->get(1);
540 + toUnicodeDirs->append(qualify_filename(this->path, dir));
543 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
544 DisplayFontParamKind kind,
545 GString *fileName, int line) {
546 DisplayFontParam *param, *old;
549 if (tokens->getLength() < 2) {
551 @@ -1243,13 +1313,15 @@
552 if (tokens->getLength() != 3) {
555 - param->t1.fileName = ((GString *)tokens->get(2))->copy();
556 + file = (GString *)tokens->get(2);
557 + param->t1.fileName = qualify_filename(this->path, file);
560 if (tokens->getLength() != 3) {
563 - param->tt.fileName = ((GString *)tokens->get(2))->copy();
564 + file = (GString *)tokens->get(2);
565 + param->tt.fileName = qualify_filename(this->path, file);
569 --- xpdf/GlobalParams.h.orig 2010-05-18 11:22:18.000000000 -0700
570 +++ xpdf/GlobalParams.h 2010-05-18 11:22:18.000000000 -0700
573 GlobalParams(char *cfgFileName);
576 + virtual ~GlobalParams();
578 void setBaseDir(char *dir);
579 void setupBaseFonts(char *dir);
581 FILE *getUnicodeMapFile(GString *encodingName);
582 FILE *findCMapFile(GString *collection, GString *cMapName);
583 FILE *findToUnicodeFile(GString *name);
584 - DisplayFontParam *getDisplayFont(GString *fontName);
585 - DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
586 + virtual DisplayFontParam *getDisplayFont(GString *fontName);
587 + virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
588 GString *getPSFile();
589 int getPSPaperWidth();
590 int getPSPaperHeight();
594 void createDefaultKeyBindings();
595 - void parseFile(GString *fileName, FILE *f);
596 +public: void parseFile(GString *fileName, FILE *f); private:
597 void parseNameToUnicode(GList *tokens, GString *fileName, int line);
598 void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
599 void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line);
601 GBool loadPlugin(char *type, char *name);
604 + //----- config file base path
608 //----- static tables
610 NameToCharCode * // mapping from char name to
611 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
612 +++ xpdf/JBIG2Stream.cc 2010-05-18 11:22:18.000000000 -0700
613 @@ -1514,11 +1514,14 @@
616 // compute symbol code length
618 - i = (numInputSyms + numNewSyms) >> 1;
624 + while (i < numInputSyms + numNewSyms) {
628 + if (huff && symCodeLen == 0) {
632 // get the input symbol bitmaps
633 @@ -1921,6 +1924,9 @@
637 + if (huff && symCodeLen == 0) {
641 // get the symbol bitmaps
642 syms = (JBIG2Bitmap **)gmallocn(numSyms, sizeof(JBIG2Bitmap *));
643 --- xpdf/JPXStream.cc.orig 2010-05-18 11:22:18.000000000 -0700
644 +++ xpdf/JPXStream.cc 2010-05-18 11:22:18.000000000 -0700
646 GBool haveBPC, haveCSMode;
648 csPrec = 0; // make gcc happy
649 + Guint num_components = 0;
650 haveBPC = haveCSMode = gFalse;
652 if (str->lookChar() == 0xff) {
655 if (readULong(&dummy) &&
657 - readUWord(&dummy) &&
658 + readUWord(&num_components) &&
666 + if(*csMode == streamCSDeviceRGB && num_components == 4) {
667 + *csMode = streamCSDeviceRGBX;
672 --- xpdf/Lexer.cc.orig 2010-05-18 11:22:18.000000000 -0700
673 +++ xpdf/Lexer.cc 2010-05-18 11:22:18.000000000 -0700
675 curStr.streamReset();
678 +static int illegalChars = 0;
681 if (!curStr.isNone()) {
687 + error(0, "Illegal characters in hex string (%d)", illegalChars);
691 int Lexer::getChar() {
693 } else if (c2 >= 'a' && c2 <= 'f') {
696 - error(getPos(), "Illegal digit in hex char in name");
698 + //error(getPos(), "Illegal digit in hex char in name");
704 else if (c >= 'a' && c <= 'f')
707 - error(getPos(), "Illegal character <%02x> in hex string", c);
710 + //error(getPos(), "Illegal character <%02x> in hex string", c);
713 if (n == tokBufSize) {
717 obj->initCmd(tokBuf);
719 - error(getPos(), "Illegal character '>'");
721 + //error(getPos(), "Illegal character '>'");
729 - error(getPos(), "Illegal character '%c'", c);
730 + //error(getPos(), "Illegal character '%c'", c);
743 --- xpdf/Link.cc.orig 2010-05-18 11:22:18.000000000 -0700
744 +++ xpdf/Link.cc 2010-05-18 11:22:18.000000000 -0700
752 - error(-1, "Illegal annotation destination");
753 + error(-1, "Illegal annotation destination %d", destObj->getType());
764 - error(-1, "Illegal annotation destination");
765 + error(-1, "Illegal annotation destination %d", destObj->getType());
769 --- xpdf/OutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
770 +++ xpdf/OutputDev.h 2010-05-18 11:22:18.000000000 -0700
774 #include "CharTypes.h"
783 - virtual void startPage(int pageNum, GfxState *state) {}
784 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
787 virtual void endPage() {}
788 --- xpdf/SplashFTFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
789 +++ xpdf/SplashFTFont.cc 2010-05-18 11:22:18.000000000 -0700
793 face = fontFileA->face;
795 if (FT_New_Size(face, &sizeObj)) {
799 if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
803 + this->ascender = face->ascender;
804 + this->descender = face->descender;
806 // if the textMat values are too small, FreeType's fixed point
807 // arithmetic doesn't work so well
808 textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
813 +int SplashFTFont::getNumChars()
815 + SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
816 + return ff->face->num_glyphs;
819 SplashPath *SplashFTFont::getGlyphPath(int c) {
820 static FT_Outline_Funcs outlineFuncs = {
821 #if FREETYPE_MINOR <= 1
826 + this->last_advance = -1;
828 ff = (SplashFTFontFile *)fontFile;
829 ff->face->size = sizeObj;
830 FT_Set_Transform(ff->face, &textMatrix, NULL);
831 @@ -262,17 +275,24 @@
832 // skip the TrueType notdef glyph
835 - if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
837 + if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
838 + fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
841 if (FT_Get_Glyph(slot, &glyph)) {
844 + this->last_advance = glyph->advance.x/65536.0;
846 path.path = new SplashPath();
847 path.textScale = textScale;
848 path.needClose = gFalse;
849 - FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
850 + error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
851 &outlineFuncs, &path);
853 + fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
855 if (path.needClose) {
858 --- xpdf/SplashFTFont.h.orig 2010-05-18 11:22:18.000000000 -0700
859 +++ xpdf/SplashFTFont.h 2010-05-18 11:22:18.000000000 -0700
861 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
862 SplashGlyphBitmap *bitmap);
864 + // return the number of characters in this font
865 + virtual int getNumChars();
867 // Return the path for a glyph.
868 virtual SplashPath *getGlyphPath(int c);
870 --- xpdf/SplashFTFontEngine.cc.orig 2010-05-18 11:22:18.000000000 -0700
871 +++ xpdf/SplashFTFontEngine.cc 2010-05-18 11:22:18.000000000 -0700
882 --- xpdf/SplashFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
883 +++ xpdf/SplashFont.cc 2010-05-18 11:22:18.000000000 -0700
887 xMin = yMin = xMax = yMax = 0;
894 void SplashFont::initCache() {
895 --- xpdf/SplashFont.h.orig 2010-05-18 11:22:18.000000000 -0700
896 +++ xpdf/SplashFont.h 2010-05-18 11:22:18.000000000 -0700
898 virtual GBool makeGlyph(int c, int xFrac, int yFrac,
899 SplashGlyphBitmap *bitmap) = 0;
901 + // return the number of characters in this font
902 + virtual int getNumChars() = 0;
904 // Return the path for a glyph.
905 virtual SplashPath *getGlyphPath(int c) = 0;
908 void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
909 { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
913 + double last_advance; //set after getGlyphPath()
916 SplashFontFile *fontFile;
917 --- xpdf/SplashFontFile.cc.orig 2010-05-18 11:22:18.000000000 -0700
918 +++ xpdf/SplashFontFile.cc 2010-05-18 11:22:18.000000000 -0700
924 -# include <unistd.h>
928 #include "SplashFontFile.h"
929 #include "SplashFontFileID.h"
930 --- xpdf/SplashOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
931 +++ xpdf/SplashOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
939 #include "GlobalParams.h"
944 -void SplashOutputDev::startPage(int pageNum, GfxState *state) {
945 +void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
949 @@ -2646,9 +2647,9 @@
951 softMask = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(),
952 1, splashModeMono8, gFalse);
953 - memset(softMask->getDataPtr(), 0,
954 - softMask->getRowSize() * softMask->getHeight());
955 + memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
956 p = softMask->getDataPtr() + ty * softMask->getRowSize() + tx;
957 + if (tx<softMask->getWidth() && ty<softMask->getHeight())
958 for (y = 0; y < tBitmap->getHeight(); ++y) {
959 for (x = 0; x < tBitmap->getWidth(); ++x) {
960 tBitmap->getPixel(x, y, color);
961 --- xpdf/SplashOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
962 +++ xpdf/SplashOutputDev.h 2010-05-18 11:22:18.000000000 -0700
964 //----- initialization and control
967 - virtual void startPage(int pageNum, GfxState *state);
968 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
971 virtual void endPage();
973 virtual void setVectorAntialias(GBool vaa);
976 + void doUpdateFont(GfxState *state);
978 + SplashPath *convertPath(GfxState *state, GfxPath *path);
981 void setupScreenParams(double hDPI, double vDPI);
984 SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
986 - SplashPath *convertPath(GfxState *state, GfxPath *path);
987 - void doUpdateFont(GfxState *state);
988 void drawType3Glyph(T3FontCache *t3Font,
989 T3FontCacheTag *tag, Guchar *data);
990 static GBool imageMaskSrc(void *data, SplashColorPtr line);
991 --- xpdf/SplashScreen.cc.orig 2010-05-18 11:22:18.000000000 -0700
992 +++ xpdf/SplashScreen.cc 2010-05-18 11:22:18.000000000 -0700
994 int SplashScreen::test(int x, int y, Guchar value) {
999 if (value < minVal) {
1002 --- xpdf/SplashXPathScanner.cc.orig 2010-05-18 11:22:18.000000000 -0700
1003 +++ xpdf/SplashXPathScanner.cc 2010-05-18 11:22:18.000000000 -0700
1004 @@ -394,10 +394,10 @@
1008 - for (; xx + 7 <= xx0; xx += 8) {
1009 + for (; xx + 7 < xx0; xx += 8) {
1014 *p &= 0xff >> (xx0 & 7);
1017 @@ -417,10 +417,10 @@
1021 - for (; xx + 7 <= xx0; xx += 8) {
1022 + for (; xx + 7 < xx0; xx += 8) {
1027 *p &= 0xff >> (xx0 & 7);
1030 --- xpdf/Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
1031 +++ xpdf/Stream.cc 2010-05-18 11:22:18.000000000 -0700
1037 +extern "C" int unlink(char *filename);
1041 --- xpdf/Stream.h.orig 2010-05-18 11:22:18.000000000 -0700
1042 +++ xpdf/Stream.h 2010-05-18 11:22:18.000000000 -0700
1047 - streamCSDeviceCMYK
1048 + streamCSDeviceCMYK,
1049 + streamCSDeviceRGBX
1052 //------------------------------------------------------------------------
1053 --- xpdf/TextOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
1054 +++ xpdf/TextOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
1055 @@ -3877,7 +3877,7 @@
1059 -void TextOutputDev::startPage(int pageNum, GfxState *state) {
1060 +void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
1061 text->startPage(state);
1064 --- xpdf/TextOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
1065 +++ xpdf/TextOutputDev.h 2010-05-18 11:22:18.000000000 -0700
1067 friend class TextFlow;
1068 friend class TextWordList;
1069 friend class TextPage;
1070 + friend class XMLOutputDev;
1073 //------------------------------------------------------------------------
1075 //----- initialization and control
1078 - virtual void startPage(int pageNum, GfxState *state);
1079 + virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
1082 virtual void endPage();
1083 --- xpdf/gfile.cc.orig 2010-05-18 11:22:18.000000000 -0700
1084 +++ xpdf/gfile.cc 2010-05-18 11:22:18.000000000 -0700
1085 @@ -439,6 +439,52 @@
1089 +static char* getTempDir()
1092 + char*dir = getenv("TMP");
1093 + if(!dir) dir = getenv("TEMP");
1094 + if(!dir) dir = getenv("tmp");
1095 + if(!dir) dir = getenv("temp");
1096 + if(!dir) dir = "C:\\";
1098 + char* dir = "/tmp/";
1103 +char* mktmpname(char*ptr) {
1104 + static char tmpbuf[128];
1105 + char*dir = getTempDir();
1106 + int l = strlen(dir);
1110 + if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
1118 + // used to be mktemp. This does remove the warnings, but
1119 + // It's not exactly an improvement.
1120 +#ifdef HAVE_LRAND48
1121 + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
1124 + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
1126 + static int count = 1;
1127 + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
1135 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
1137 //---------- Win32 ----------
1140 t = (int)time(NULL);
1141 for (i = 0; i < 1000; ++i) {
1142 - sprintf(buf, "%d", t + i);
1143 + sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
1144 s2 = s->copy()->append(buf);
1148 if (!(f2 = fopen(s2->getCString(), "r"))) {
1149 if (!(f2 = fopen(s2->getCString(), mode))) {
1161 + fprintf(stderr, "Couldn't create temporary file\n");
1164 #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
1166 // with this file name after the tmpnam call and before the fopen
1167 // call. I will happily accept fixes to this function for non-Unix
1169 - if (!(s = tmpnam(NULL))) {
1170 + if (!(s = mktmpname(NULL))) {
1173 *name = new GString(s);
1175 (*name)->append("/XXXXXX")->append(ext);
1176 fd = mkstemps((*name)->getCString(), strlen(ext));
1178 - if (!(s = tmpnam(NULL))) {
1179 + if (!(s = mktmpname(NULL))) {
1182 *name = new GString(s);
1184 (*name)->append("/XXXXXX");
1185 fd = mkstemp((*name)->getCString());
1186 #else // HAVE_MKSTEMP
1187 - if (!(s = tmpnam(NULL))) {
1188 + if (!(s = mktmpname(NULL))) {
1191 *name = new GString(s);
1192 --- xpdf/gfile.h.orig 2010-05-18 11:22:18.000000000 -0700
1193 +++ xpdf/gfile.h 2010-05-18 11:22:18.000000000 -0700
1195 // Get current directory.
1196 extern GString *getCurrentDir();
1198 +/* create a temporary filename */
1199 +char* mktmpname(char*ptr);
1201 // Append a file name to a path string. <path> may be an empty
1202 // string, denoting the current directory). Returns <path>.
1203 extern GString *appendToPath(GString *path, char *fileName);
1204 --- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:33:21.000000000 -0700
1205 +++ xpdf/JBIG2Stream.cc 2010-06-03 16:55:03.000000000 -0700
1208 //========================================================================
1211 +//========================================================================
1213 +// Modified under the Poppler project - http://poppler.freedesktop.org
1215 +// All changes made under the Poppler project to this file are licensed
1216 +// under GPL version 2 or later
1218 +// Copyright (C) 2006 Raj Kumar <rkumar@archive.org>
1219 +// Copyright (C) 2006 Paul Walmsley <paul@booyaka.com>
1220 +// Copyright (C) 2006-2009 Albert Astals Cid <aacid@kde.org>
1221 +// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
1223 +// To see a description of the changes please see the Changelog file that
1224 +// came with your tarball or type make ChangeLog if you are building from git
1226 +//========================================================================
1228 +#include <config.h>
1230 #ifdef USE_GCC_PRAGMAS
1231 #pragma implementation
1234 //------------------------------------------------------------------------
1236 -static int contextSize[4] = { 16, 13, 10, 10 };
1237 -static int refContextSize[2] = { 13, 10 };
1238 +static const int contextSize[4] = { 16, 13, 10, 10 };
1239 +static const int refContextSize[2] = { 13, 10 };
1241 //------------------------------------------------------------------------
1242 // JBIG2HuffmanTable
1247 -JBIG2HuffmanTable huffTableA[] = {
1248 +static JBIG2HuffmanTable huffTableA[] = {
1250 { 16, 2, 8, 0x002 },
1251 { 272, 3, 16, 0x006 },
1253 { 0, 0, jbig2HuffmanEOT, 0 }
1256 -JBIG2HuffmanTable huffTableB[] = {
1257 +static JBIG2HuffmanTable huffTableB[] = {
1262 { 0, 0, jbig2HuffmanEOT, 0 }
1265 -JBIG2HuffmanTable huffTableC[] = {
1266 +static JBIG2HuffmanTable huffTableC[] = {
1271 { 0, 0, jbig2HuffmanEOT, 0 }
1274 -JBIG2HuffmanTable huffTableD[] = {
1275 +static JBIG2HuffmanTable huffTableD[] = {
1280 { 0, 0, jbig2HuffmanEOT, 0 }
1283 -JBIG2HuffmanTable huffTableE[] = {
1284 +static JBIG2HuffmanTable huffTableE[] = {
1289 { 0, 0, jbig2HuffmanEOT, 0 }
1292 -JBIG2HuffmanTable huffTableF[] = {
1293 +static JBIG2HuffmanTable huffTableF[] = {
1295 { 128, 3, 7, 0x002 },
1296 { 256, 3, 8, 0x003 },
1298 { 0, 0, jbig2HuffmanEOT, 0 }
1301 -JBIG2HuffmanTable huffTableG[] = {
1302 +static JBIG2HuffmanTable huffTableG[] = {
1303 { -512, 3, 8, 0x000 },
1304 { 256, 3, 8, 0x001 },
1305 { 512, 3, 9, 0x002 },
1307 { 0, 0, jbig2HuffmanEOT, 0 }
1310 -JBIG2HuffmanTable huffTableH[] = {
1311 +static JBIG2HuffmanTable huffTableH[] = {
1313 { 0, 2, jbig2HuffmanOOB, 0x001 },
1316 { 0, 0, jbig2HuffmanEOT, 0 }
1319 -JBIG2HuffmanTable huffTableI[] = {
1320 +static JBIG2HuffmanTable huffTableI[] = {
1321 { 0, 2, jbig2HuffmanOOB, 0x000 },
1322 { -1, 3, 1, 0x002 },
1325 { 0, 0, jbig2HuffmanEOT, 0 }
1328 -JBIG2HuffmanTable huffTableJ[] = {
1329 +static JBIG2HuffmanTable huffTableJ[] = {
1330 { -2, 2, 2, 0x000 },
1332 { 0, 2, jbig2HuffmanOOB, 0x002 },
1334 { 0, 0, jbig2HuffmanEOT, 0 }
1337 -JBIG2HuffmanTable huffTableK[] = {
1338 +static JBIG2HuffmanTable huffTableK[] = {
1343 { 0, 0, jbig2HuffmanEOT, 0 }
1346 -JBIG2HuffmanTable huffTableL[] = {
1347 +static JBIG2HuffmanTable huffTableL[] = {
1352 { 0, 0, jbig2HuffmanEOT, 0 }
1355 -JBIG2HuffmanTable huffTableM[] = {
1356 +static JBIG2HuffmanTable huffTableM[] = {
1361 { 0, 0, jbig2HuffmanEOT, 0 }
1364 -JBIG2HuffmanTable huffTableN[] = {
1365 +static JBIG2HuffmanTable huffTableN[] = {
1367 { -2, 3, 0, 0x004 },
1368 { -1, 3, 0, 0x005 },
1370 { 0, 0, jbig2HuffmanEOT, 0 }
1373 -JBIG2HuffmanTable huffTableO[] = {
1374 +static JBIG2HuffmanTable huffTableO[] = {
1376 { -1, 3, 0, 0x004 },
1381 int JBIG2MMRDecoder::get2DCode() {
1383 + const CCITTCode *p;
1386 buf = str->getChar() & 0xff;
1390 int JBIG2MMRDecoder::getWhiteCode() {
1392 + const CCITTCode *p;
1399 int JBIG2MMRDecoder::getBlackCode() {
1401 + const CCITTCode *p;
1406 void combine(JBIG2Bitmap *bitmap, int x, int y, Guint combOp);
1407 Guchar *getDataPtr() { return data; }
1408 int getDataSize() { return h * line; }
1409 + GBool isOk() { return data != NULL; }
1413 @@ -685,10 +703,11 @@
1416 line = (wA + 7) >> 3;
1418 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1419 - // force a call to gmalloc(-1), which will throw an exception
1422 + error(-1, "invalid width/height");
1426 // need to allocate one extra guard byte for use in combine()
1427 data = (Guchar *)gmalloc(h * line + 1);
1428 @@ -701,10 +720,11 @@
1431 line = bitmap->line;
1433 if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
1434 - // force a call to gmalloc(-1), which will throw an exception
1437 + error(-1, "invalid width/height");
1441 // need to allocate one extra guard byte for use in combine()
1442 data = (Guchar *)gmalloc(h * line + 1);
1445 void JBIG2Bitmap::expand(int newH, Guint pixel) {
1446 if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
1447 + error(-1, "invalid width/height");
1452 // need to allocate one extra guard byte for use in combine()
1453 @@ -1002,6 +1025,7 @@
1454 Guint getSize() { return size; }
1455 void setBitmap(Guint idx, JBIG2Bitmap *bitmap) { bitmaps[idx] = bitmap; }
1456 JBIG2Bitmap *getBitmap(Guint idx) { return bitmaps[idx]; }
1457 + GBool isOk() { return bitmaps != NULL; }
1458 void setGenericRegionStats(JArithmeticDecoderStats *stats)
1459 { genericRegionStats = stats; }
1460 void setRefinementRegionStats(JArithmeticDecoderStats *stats)
1461 @@ -1022,13 +1046,9 @@
1462 JBIG2SymbolDict::JBIG2SymbolDict(Guint segNumA, Guint sizeA):
1463 JBIG2Segment(segNumA)
1468 bitmaps = (JBIG2Bitmap **)gmallocn(size, sizeof(JBIG2Bitmap *));
1469 - for (i = 0; i < size; ++i) {
1470 - bitmaps[i] = NULL;
1472 + if (!bitmaps) size = 0;
1473 genericRegionStats = NULL;
1474 refinementRegionStats = NULL;
1476 @@ -1037,9 +1057,7 @@
1479 for (i = 0; i < size; ++i) {
1481 - delete bitmaps[i];
1483 + delete bitmaps[i];
1486 if (genericRegionStats) {
1487 @@ -1247,6 +1265,7 @@
1488 Guint segNum, segFlags, segType, page, segLength;
1489 Guint refFlags, nRefSegs;
1495 @@ -1314,6 +1333,9 @@
1499 + // keep track of the start of the segment data
1500 + segDataPos = getPos();
1502 // check for missing page information segment
1503 if (!pageBitmap && ((segType >= 4 && segType <= 7) ||
1504 (segType >= 20 && segType <= 43))) {
1505 @@ -1398,6 +1420,45 @@
1509 + // Make sure the segment handler read all of the bytes in the
1510 + // segment data, unless this segment is marked as having an
1511 + // unknown length (section 7.2.7 of the JBIG2 Final Committee Draft)
1513 + if (segLength != 0xffffffff) {
1515 + int segExtraBytes = segDataPos + segLength - getPos();
1516 + if (segExtraBytes > 0) {
1518 + // If we didn't read all of the bytes in the segment data,
1519 + // indicate an error, and throw away the rest of the data.
1521 + // v.3.1.01.13 of the LuraTech PDF Compressor Server will
1522 + // sometimes generate an extraneous NULL byte at the end of
1523 + // arithmetic-coded symbol dictionary segments when numNewSyms
1524 + // == 0. Segments like this often occur for blank pages.
1526 + error(getPos(), "%d extraneous byte%s after segment",
1527 + segExtraBytes, (segExtraBytes > 1) ? "s" : "");
1529 + // Burn through the remaining bytes -- inefficient, but
1530 + // hopefully we're not doing this much
1533 + for (int i = segExtraBytes; i > 0; i--) {
1537 + } else if (segExtraBytes < 0) {
1539 + // If we read more bytes than we should have, according to the
1540 + // segment length field, note an error.
1542 + error(getPos(), "Previous segment handler read too many bytes");
1551 @@ -1493,6 +1554,9 @@
1552 codeTables = new GList();
1554 for (i = 0; i < nRefSegs; ++i) {
1555 + // This is need by bug 12014, returning gFalse makes it not crash
1556 + // but we end up with a empty page while acroread is able to render
1558 if ((seg = findSegment(refSegs[i]))) {
1559 if (seg->getType() == jbig2SegSymbolDict) {
1560 j = ((JBIG2SymbolDict *)seg)->getSize();
1561 @@ -1503,8 +1567,11 @@
1564 } else if (seg->getType() == jbig2SegCodeTable) {
1565 - codeTables->append(seg);
1566 + codeTables->append(seg);
1569 + delete codeTables;
1573 if (numInputSyms > UINT_MAX - numNewSyms) {
1574 @@ -1530,12 +1600,11 @@
1576 inputSymbolDict = NULL;
1577 for (i = 0; i < nRefSegs; ++i) {
1578 - if ((seg = findSegment(refSegs[i]))) {
1579 - if (seg->getType() == jbig2SegSymbolDict) {
1580 - inputSymbolDict = (JBIG2SymbolDict *)seg;
1581 - for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1582 - bitmaps[k++] = inputSymbolDict->getBitmap(j);
1584 + seg = findSegment(refSegs[i]);
1585 + if (seg != NULL && seg->getType() == jbig2SegSymbolDict) {
1586 + inputSymbolDict = (JBIG2SymbolDict *)seg;
1587 + for (j = 0; j < inputSymbolDict->getSize(); ++j) {
1588 + bitmaps[k++] = inputSymbolDict->getBitmap(j);
1592 @@ -1753,6 +1822,10 @@
1594 // create the symbol dict object
1595 symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
1596 + if (!symbolDict->isOk()) {
1597 + delete symbolDict;
1601 // exported symbol list
1603 @@ -1766,6 +1839,7 @@
1604 if (i + run > numInputSyms + numNewSyms ||
1605 (ex && j + run > numExSyms)) {
1606 error(getPos(), "Too many exported symbols in JBIG2 symbol dictionary");
1607 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1611 @@ -1780,6 +1854,7 @@
1613 if (j != numExSyms) {
1614 error(getPos(), "Too few symbols in JBIG2 symbol dictionary");
1615 + for ( ; j < numExSyms; ++j) symbolDict->setBitmap(j, NULL);
1619 @@ -2095,18 +2170,20 @@
1623 - // combine the region bitmap into the page bitmap
1625 - if (pageH == 0xffffffff && y + h > curPageH) {
1626 - pageBitmap->expand(y + h, pageDefPixel);
1628 - pageBitmap->combine(bitmap, x, y, extCombOp);
1631 + // combine the region bitmap into the page bitmap
1633 + if (pageH == 0xffffffff && y + h > curPageH) {
1634 + pageBitmap->expand(y + h, pageDefPixel);
1636 + pageBitmap->combine(bitmap, x, y, extCombOp);
1639 - // store the region bitmap
1641 - bitmap->setSegNum(segNum);
1642 - segments->append(bitmap);
1643 + // store the region bitmap
1645 + bitmap->setSegNum(segNum);
1646 + segments->append(bitmap);
1650 // clean up the Huffman decoder
1651 @@ -2159,6 +2236,10 @@
1653 // allocate the bitmap
1654 bitmap = new JBIG2Bitmap(0, w, h);
1655 + if (!bitmap->isOk()) {
1660 bitmap->clearToOne();
1662 @@ -2235,73 +2316,84 @@
1666 + GBool decodeSuccess;
1668 - huffDecoder->decodeInt(&rdw, huffRDWTable);
1669 - huffDecoder->decodeInt(&rdh, huffRDHTable);
1670 - huffDecoder->decodeInt(&rdx, huffRDXTable);
1671 - huffDecoder->decodeInt(&rdy, huffRDYTable);
1672 - huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1673 + decodeSuccess = huffDecoder->decodeInt(&rdw, huffRDWTable);
1674 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdh, huffRDHTable);
1675 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdx, huffRDXTable);
1676 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&rdy, huffRDYTable);
1677 + decodeSuccess = decodeSuccess && huffDecoder->decodeInt(&bmSize, huffRSizeTable);
1678 huffDecoder->reset();
1679 arithDecoder->start();
1681 - arithDecoder->decodeInt(&rdw, iardwStats);
1682 - arithDecoder->decodeInt(&rdh, iardhStats);
1683 - arithDecoder->decodeInt(&rdx, iardxStats);
1684 - arithDecoder->decodeInt(&rdy, iardyStats);
1685 + decodeSuccess = arithDecoder->decodeInt(&rdw, iardwStats);
1686 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdh, iardhStats);
1687 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdx, iardxStats);
1688 + decodeSuccess = decodeSuccess && arithDecoder->decodeInt(&rdy, iardyStats);
1691 + if (decodeSuccess && syms[symID])
1693 + refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1694 + refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1697 + readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1698 + rdh + syms[symID]->getHeight(),
1699 + templ, gFalse, syms[symID],
1700 + refDX, refDY, atx, aty);
1702 - refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
1703 - refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
1706 - readGenericRefinementRegion(rdw + syms[symID]->getWidth(),
1707 - rdh + syms[symID]->getHeight(),
1708 - templ, gFalse, syms[symID],
1709 - refDX, refDY, atx, aty);
1710 //~ do we need to use the bmSize value here (in Huffman mode)?
1712 symbolBitmap = syms[symID];
1715 - // combine the symbol bitmap into the region bitmap
1716 - //~ something is wrong here - refCorner shouldn't degenerate into
1718 - bw = symbolBitmap->getWidth() - 1;
1719 - bh = symbolBitmap->getHeight() - 1;
1721 - switch (refCorner) {
1722 - case 0: // bottom left
1723 - bitmap->combine(symbolBitmap, tt, s, combOp);
1725 - case 1: // top left
1726 - bitmap->combine(symbolBitmap, tt, s, combOp);
1728 - case 2: // bottom right
1729 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1731 - case 3: // top right
1732 - bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1734 + if (symbolBitmap) {
1735 + // combine the symbol bitmap into the region bitmap
1736 + //~ something is wrong here - refCorner shouldn't degenerate into
1738 + bw = symbolBitmap->getWidth() - 1;
1739 + bh = symbolBitmap->getHeight() - 1;
1741 + switch (refCorner) {
1742 + case 0: // bottom left
1743 + bitmap->combine(symbolBitmap, tt, s, combOp);
1745 + case 1: // top left
1746 + bitmap->combine(symbolBitmap, tt, s, combOp);
1748 + case 2: // bottom right
1749 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1751 + case 3: // top right
1752 + bitmap->combine(symbolBitmap, tt - bw, s, combOp);
1757 + switch (refCorner) {
1758 + case 0: // bottom left
1759 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1761 + case 1: // top left
1762 + bitmap->combine(symbolBitmap, s, tt, combOp);
1764 + case 2: // bottom right
1765 + bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1767 + case 3: // top right
1768 + bitmap->combine(symbolBitmap, s, tt, combOp);
1775 - switch (refCorner) {
1776 - case 0: // bottom left
1777 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1779 - case 1: // top left
1780 - bitmap->combine(symbolBitmap, s, tt, combOp);
1782 - case 2: // bottom right
1783 - bitmap->combine(symbolBitmap, s, tt - bh, combOp);
1785 - case 3: // top right
1786 - bitmap->combine(symbolBitmap, s, tt, combOp);
1789 + delete symbolBitmap;
1794 - delete symbolBitmap;
1796 + // NULL symbolBitmap only happens on error
1802 @@ -2431,11 +2523,12 @@
1803 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1806 - if (!(seg = findSegment(refSegs[0])) ||
1807 - seg->getType() != jbig2SegPatternDict) {
1808 + seg = findSegment(refSegs[0]);
1809 + if (seg == NULL || seg->getType() != jbig2SegPatternDict) {
1810 error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
1814 patternDict = (JBIG2PatternDict *)seg;
1817 @@ -2591,6 +2684,8 @@
1819 bitmap = readGenericBitmap(mmr, w, h, templ, tpgdOn, gFalse,
1820 NULL, atx, aty, mmr ? length - 18 : 0);
1824 // combine the region bitmap into the page bitmap
1826 @@ -2616,7 +2711,7 @@
1827 int *codingLine, int *a0i, int w) {
1828 if (a1 > codingLine[*a0i]) {
1830 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1831 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1834 if ((*a0i & 1) ^ blackPixels) {
1835 @@ -2630,7 +2725,7 @@
1836 int *codingLine, int *a0i, int w) {
1837 if (a1 > codingLine[*a0i]) {
1839 - error(getPos(), "JBIG2 MMR row is wrong length ({0:d})", a1);
1840 + error(getPos(), "JBIG2 MMR row is wrong length (%d)", a1);
1843 if ((*a0i & 1) ^ blackPixels) {
1844 @@ -2657,13 +2752,17 @@
1845 JBIG2Bitmap *bitmap;
1847 Guint ltpCX, cx, cx0, cx1, cx2;
1848 - JBIG2BitmapPtr cxPtr0, cxPtr1;
1849 - JBIG2BitmapPtr atPtr0, atPtr1, atPtr2, atPtr3;
1850 + JBIG2BitmapPtr cxPtr0 = {0}, cxPtr1 = {0};
1851 + JBIG2BitmapPtr atPtr0 = {0}, atPtr1 = {0}, atPtr2 = {0}, atPtr3 = {0};
1852 int *refLine, *codingLine;
1853 int code1, code2, code3;
1854 int x, y, a0i, b1i, blackPixels, pix, i;
1856 bitmap = new JBIG2Bitmap(0, w, h);
1857 + if (!bitmap->isOk()) {
1861 bitmap->clearToZero();
1864 @@ -2682,7 +2781,7 @@
1865 // ---> max refLine size = w + 2
1866 codingLine = (int *)gmallocn(w + 1, sizeof(int));
1867 refLine = (int *)gmallocn(w + 2, sizeof(int));
1868 - codingLine[0] = w;
1869 + for (i = 0; i < w + 1; ++i) codingLine[i] = w;
1871 for (y = 0; y < h; ++y) {
1873 @@ -3093,8 +3192,8 @@
1876 if (nRefSegs == 1) {
1877 - if (!(seg = findSegment(refSegs[0])) ||
1878 - seg->getType() != jbig2SegBitmap) {
1879 + seg = findSegment(refSegs[0]);
1880 + if (seg == NULL || seg->getType() != jbig2SegBitmap) {
1881 error(getPos(), "Bad bitmap reference in JBIG2 generic refinement segment");
1884 @@ -3143,11 +3242,24 @@
1885 JBIG2Bitmap *bitmap;
1887 Guint ltpCX, cx, cx0, cx2, cx3, cx4, tpgrCX0, tpgrCX1, tpgrCX2;
1888 - JBIG2BitmapPtr cxPtr0, cxPtr1, cxPtr2, cxPtr3, cxPtr4, cxPtr5, cxPtr6;
1889 - JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
1890 + JBIG2BitmapPtr cxPtr0 = {0};
1891 + JBIG2BitmapPtr cxPtr1 = {0};
1892 + JBIG2BitmapPtr cxPtr2 = {0};
1893 + JBIG2BitmapPtr cxPtr3 = {0};
1894 + JBIG2BitmapPtr cxPtr4 = {0};
1895 + JBIG2BitmapPtr cxPtr5 = {0};
1896 + JBIG2BitmapPtr cxPtr6 = {0};
1897 + JBIG2BitmapPtr tpgrCXPtr0 = {0};
1898 + JBIG2BitmapPtr tpgrCXPtr1 = {0};
1899 + JBIG2BitmapPtr tpgrCXPtr2 = {0};
1902 bitmap = new JBIG2Bitmap(0, w, h);
1903 + if (!bitmap->isOk())
1908 bitmap->clearToZero();
1910 // set up the typical row context
1911 @@ -3332,6 +3444,12 @@
1913 pageBitmap = new JBIG2Bitmap(0, pageW, curPageH);
1915 + if (!pageBitmap->isOk()) {
1916 + delete pageBitmap;
1917 + pageBitmap = NULL;
1921 // default pixel value
1923 pageBitmap->clearToOne();