--- poppler-git-02feb11-level1bug-binary/poppler/GlobalParams.cc- 2011-02-02 06:40:53.000000000 +0100 +++ poppler-git-02feb11-level1bug-binary/poppler/GlobalParams.cc 2011-02-04 18:30:48.506240416 +0100 @@ -665,6 +665,7 @@ psPreload = gFalse; psOPI = gFalse; psASCIIHex = gFalse; + psBinary = gFalse; textEncoding = new GooString("UTF-8"); #if defined(_WIN32) textEOL = eolDOS; @@ -1380,6 +1381,15 @@ return ah; } +GBool GlobalParams::getPSBinary() { + GBool binary; + + lockGlobalParams; + binary = psBinary; + unlockGlobalParams; + return binary; +} + GooString *GlobalParams::getTextEncodingName() { GooString *s; @@ -1737,6 +1747,12 @@ unlockGlobalParams; } +void GlobalParams::setPSBinary(GBool binary) { + lockGlobalParams; + psBinary = binary; + unlockGlobalParams; +} + void GlobalParams::setTextEncoding(char *encodingName) { lockGlobalParams; delete textEncoding; --- poppler-git-02feb11-level1bug-binary/poppler/GlobalParams.h- 2011-02-02 06:40:53.000000000 +0100 +++ poppler-git-02feb11-level1bug-binary/poppler/GlobalParams.h 2011-02-04 17:12:33.866633738 +0100 @@ -199,6 +199,7 @@ GBool getPSPreload(); GBool getPSOPI(); GBool getPSASCIIHex(); + GBool getPSBinary(); GooString *getTextEncodingName(); EndOfLineKind getTextEOL(); GBool getTextPageBreaks(); @@ -244,6 +245,7 @@ void setPSPreload(GBool preload); void setPSOPI(GBool opi); void setPSASCIIHex(GBool hex); + void setPSBinary(GBool binary); void setTextEncoding(char *encodingName); GBool setTextEOL(char *s); void setTextPageBreaks(GBool pageBreaks); @@ -325,6 +327,7 @@ // memory GBool psOPI; // generate PostScript OPI comments? GBool psASCIIHex; // use ASCIIHex instead of ASCII85? + GBool psBinary; // use binary instead of hex GooString *textEncoding; // encoding (unicodeMap) to use for text // output EndOfLineKind textEOL; // type of EOL marker to use for text --- poppler-git-02feb11-level1bug-binary/poppler/PSOutputDev.cc- 2011-02-04 17:11:11.605585960 +0100 +++ poppler-git-02feb11-level1bug-binary/poppler/PSOutputDev.cc 2011-02-06 20:02:37.833231675 +0100 @@ -511,6 +511,10 @@ " /pdfImBuf1 4 index string def", " { currentfile pdfImBuf1 readhexstring pop } image", "} def", + "/pdfIm1Bin {", + " /pdfImBuf1 4 index string def", + " { currentfile pdfImBuf1 readstring pop } image", + "} def", "~1s", "/pdfIm1Sep {", " /pdfImBuf1 4 index string def", @@ -523,11 +527,26 @@ " { currentfile pdfImBuf4 readhexstring pop }", " true 4 colorimage", "} def", + "/pdfIm1SepBin {", + " /pdfImBuf1 4 index string def", + " /pdfImBuf2 4 index string def", + " /pdfImBuf3 4 index string def", + " /pdfImBuf4 4 index string def", + " { currentfile pdfImBuf1 readstring pop }", + " { currentfile pdfImBuf2 readstring pop }", + " { currentfile pdfImBuf3 readstring pop }", + " { currentfile pdfImBuf4 readstring pop }", + " true 4 colorimage", + "} def", "~1ns", "/pdfImM1 {", " fCol /pdfImBuf1 4 index 7 add 8 idiv string def", " { currentfile pdfImBuf1 readhexstring pop } imagemask", "} def", + "/pdfImM1Bin {", + " fCol /pdfImBuf1 4 index 7 add 8 idiv string def", + " { currentfile pdfImBuf1 readstring pop } imagemask", + "} def", "/pdfImM1a {", " { 2 copy get exch 1 add exch } imagemask", " pop pop", @@ -1315,6 +1334,9 @@ writePS("%%DocumentCustomColors: (atend)\n"); } writePS("%%DocumentSuppliedResources: (atend)\n"); + if ((level == psLevel1 || level == psLevel1Sep) && globalParams->getPSBinary()) { + writePS("%%DocumentData: Binary\n"); + } switch (mode) { case psModePSOrigPageSizes: @@ -2971,6 +2993,7 @@ int c, w, h, x, y, comp, i; char hexBuf[32*2 + 2]; // 32 values X 2 chars/value + line ending + null Guchar digit; + GBool useBinary; if (!forceRasterize) { scan = new PreScanOutputDev(); @@ -3071,47 +3094,76 @@ m0, m1, m2, m3, m4, m5); switch (level) { case psLevel1: - writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1\n", - w, h, w, -h, h); + useBinary = globalParams->getPSBinary(); + writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1{5:s}\n", + w, h, w, -h, h, + useBinary ? "Bin" : ""); p = bitmap->getDataPtr(); i = 0; - for (y = 0; y < h; ++y) { - for (x = 0; x < w; ++x) { - digit = *p / 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - digit = *p++ % 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - if (i >= 64) { - hexBuf[i++] = '\n'; - writePSBuf(hexBuf, i); - i = 0; + if (useBinary) { + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + hexBuf[i++] = *p++; + if (i >= 64) { + writePSBuf(hexBuf, i); + i = 0; + } + } + } + } else { + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + digit = *p / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + digit = *p++ % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); + i = 0; + } } } } if (i != 0) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); } break; case psLevel1Sep: - writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1Sep\n", - w, h, w, -h, h); + useBinary = globalParams->getPSBinary(); + writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1Sep{5:s}\n", + w, h, w, -h, h, + useBinary ? "Bin" : ""); p = bitmap->getDataPtr(); i = 0; col[0] = col[1] = col[2] = col[3] = 0; if (((psProcessCyan | psProcessMagenta | psProcessYellow | psProcessBlack) & ~processColors) != 0) { for (y = 0; y < h; ++y) { for (comp = 0; comp < 4; ++comp) { - for (x = 0; x < w; ++x) { - col[comp] |= p[4*x + comp]; - digit = p[4*x + comp] / 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - digit = p[4*x + comp] % 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - if (i >= 64) { - hexBuf[i++] = '\n'; - writePSBuf(hexBuf, i); - i = 0; + if (useBinary) { + for (x = 0; x < w; ++x) { + col[comp] |= p[4*x + comp]; + hexBuf[i++] = p[4*x + comp]; + if (i >= 64) { + writePSBuf(hexBuf, i); + i = 0; + } + } + } else { + for (x = 0; x < w; ++x) { + col[comp] |= p[4*x + comp]; + digit = p[4*x + comp] / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + digit = p[4*x + comp] % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); + i = 0; + } } } } @@ -3120,15 +3172,25 @@ } else { for (y = 0; y < h; ++y) { for (comp = 0; comp < 4; ++comp) { - for (x = 0; x < w; ++x) { - digit = p[4*x + comp] / 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - digit = p[4*x + comp] % 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - if (i >= 64) { - hexBuf[i++] = '\n'; - writePSBuf(hexBuf, i); - i = 0; + if (useBinary) { + for (x = 0; x < w; ++x) { + hexBuf[i++] = p[4*x + comp]; + if (i >= 64) { + writePSBuf(hexBuf, i); + i = 0; + } + } + } else { + for (x = 0; x < w; ++x) { + digit = p[4*x + comp] / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + digit = p[4*x + comp] % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); + i = 0; + } } } } @@ -3136,7 +3198,9 @@ } } if (i != 0) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); } if (col[0]) { @@ -4543,6 +4607,9 @@ int col, x, y, c, i; char hexBuf[32*2 + 2]; // 32 values X 2 chars/value + line ending + null Guchar digit, grayValue; + GBool useBinary; + + useBinary = globalParams->getPSBinary(); // explicit masking if (maskStr && !(maskColors && colorMap)) { @@ -4593,13 +4660,15 @@ width, height, invert ? "true" : "false", width, -height, height); } else if (colorMap) { - writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1\n", + writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1{5:s}\n", width, height, - width, -height, height); + width, -height, height, + useBinary ? "Bin" : ""); } else { - writePSFmt("{0:d} {1:d} {2:s} [{3:d} 0 0 {4:d} 0 {5:d}] pdfImM1\n", + writePSFmt("{0:d} {1:d} {2:s} [{3:d} 0 0 {4:d} 0 {5:d}] pdfImM1{6:s}\n", width, height, invert ? "true" : "false", - width, -height, height); + width, -height, height, + useBinary ? "Bin" : ""); } // image data @@ -4621,19 +4690,27 @@ imgStr->getPixel(pixBuf); colorMap->getGray(pixBuf, &gray); grayValue = colToByte(gray); - digit = grayValue / 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - digit = grayValue % 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + if (useBinary) { + hexBuf[i++] = grayValue; + } else { + digit = grayValue / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + digit = grayValue % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + } if (i >= 64) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); i = 0; } } } if (i != 0) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); } str->close(); @@ -4646,19 +4723,27 @@ for (y = 0; y < height; ++y) { for (x = 0; x < width; x += 8) { grayValue = str->getChar(); - digit = grayValue / 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); - digit = grayValue % 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + if (useBinary) { + hexBuf[i++] = grayValue; + } else { + digit = grayValue / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + digit = grayValue % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a' - 10: '0'); + } if (i >= 64) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); i = 0; } } } if (i != 0) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); } str->close(); @@ -4683,6 +4768,9 @@ GBool checkProcessColor; char hexBuf[32*2 + 2]; // 32 values X 2 chars/value + line ending + null Guchar digit; + GBool useBinary; + + useBinary = globalParams->getPSBinary(); // explicit masking if (maskStr && !(maskColors && colorMap)) { @@ -4690,9 +4778,10 @@ } // width, height, matrix, bits per component - writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1Sep\n", + writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1Sep{5:s}\n", width, height, - width, -height, height); + width, -height, height, + useBinary ? "Bin" : ""); // allocate a line buffer lineBuf = (Guchar *)gmallocn(width, 4); @@ -4734,23 +4823,37 @@ } // write one line of each color component - for (comp = 0; comp < 4; ++comp) { - for (x = 0; x < width; ++x) { - digit = lineBuf[4*x + comp] / 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); - digit = lineBuf[4*x + comp] % 16; - hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); - if (i >= 64) { - hexBuf[i++] = '\n'; - writePSBuf(hexBuf, i); - i = 0; + if (useBinary) { + for (comp = 0; comp < 4; ++comp) { + for (x = 0; x < width; ++x) { + hexBuf[i++] = lineBuf[4*x + comp]; + if (i >= 64) { + writePSBuf(hexBuf, i); + i = 0; + } + } + } + } else { + for (comp = 0; comp < 4; ++comp) { + for (x = 0; x < width; ++x) { + digit = lineBuf[4*x + comp] / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + digit = lineBuf[4*x + comp] % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); + i = 0; + } } } } } if (i != 0) { - hexBuf[i++] = '\n'; + if (!useBinary) { + hexBuf[i++] = '\n'; + } writePSBuf(hexBuf, i); } --- poppler-git-02feb11-level1bug-binary/utils/pdftops.1- 2011-02-02 06:40:53.000000000 +0100 +++ poppler-git-02feb11-level1bug-binary/utils/pdftops.1 2011-02-06 19:58:24.260091523 +0100 @@ -95,6 +95,13 @@ information. (This option is only available if pdftops was compiled with OPI support.) .TP +.B \-binary +Write binary data in Level 1 PostScript. By default, pdftops writes +hex-encoded data in Level 1 PostScript. Binary data is non-standard +in Level 1 PostScript but reduces the file size and can be useful +when Level 1 PostScript is required only for its restricted use +of PostScript operators. +.TP .B \-noembt1 By default, any Type 1 fonts which are embedded in the PDF file are copied into the PostScript file. This option causes pdftops to --- poppler-git-02feb11-level1bug-binary/utils/pdftops.cc- 2011-02-02 06:40:53.000000000 +0100 +++ poppler-git-02feb11-level1bug-binary/utils/pdftops.cc 2011-02-04 18:30:25.577223097 +0100 @@ -85,6 +85,7 @@ #if OPI_SUPPORT static GBool doOPI = gFalse; #endif +static GBool psBinary = gFalse; static GBool noEmbedT1Fonts = gFalse; static GBool noEmbedTTFonts = gFalse; static GBool noEmbedCIDPSFonts = gFalse; @@ -132,6 +133,8 @@ {"-opi", argFlag, &doOPI, 0, "generate OPI comments"}, #endif + {"-binary", argFlag, &psBinary, 0, + "write binary data in Level 1 PostScript"}, {"-noembt1", argFlag, &noEmbedT1Fonts, 0, "don't embed Type 1 fonts"}, {"-noembtt", argFlag, &noEmbedTTFonts, 0, @@ -289,6 +292,9 @@ globalParams->setPSOPI(doOPI); } #endif + if (psBinary) { + globalParams->setPSBinary(psBinary); + } if (quiet) { globalParams->setErrQuiet(quiet); }