Commit 6ee907f2 authored by Albert Astals Cid's avatar Albert Astals Cid

[xpdf303] More merges from Thomas, basically PSOutputDev and some other small stuff

parent 4fcd42cf
......@@ -729,7 +729,7 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, GBool ps) {
if (!isCIDFont()) {
//----- 8-bit PS resident font
if (ps) {
if (name && ps) {
if ((path = globalParams->getPSResidentFont(name))) {
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocResident;
......@@ -756,7 +756,7 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, GBool ps) {
substName = new GooString(base14SubstFonts[substIdx]);
if (ps) {
error(errSyntaxWarning, -1, "Substituting font '{0:s}' for '{1:t}'",
base14SubstFonts[substIdx], name);
base14SubstFonts[substIdx], name ? name : new GooString("null"));
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocResident;
fontLoc->fontType = fontType1;
......
......@@ -582,6 +582,10 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
psOPI = gFalse;
psASCIIHex = gFalse;
psBinary = gFalse;
psUncompressPreloadedImages = gFalse;
psRasterResolution = 300;
psRasterMono = gFalse;
psAlwaysRasterize = gFalse;
textEncoding = new GooString("UTF-8");
#if defined(_WIN32)
textEOL = eolDOS;
......@@ -596,6 +600,7 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
disableFreeTypeHinting = gFalse;
antialias = gTrue;
vectorAntialias = gTrue;
antialiasPrinting = gFalse;
strokeAdjust = gTrue;
screenType = screenUnset;
screenSize = -1;
......@@ -610,7 +615,6 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
printCommands = gFalse;
profileCommands = gFalse;
errQuiet = gFalse;
splashResolution = 0.0;
cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
unicodeToUnicodeCache =
......@@ -1559,6 +1563,42 @@ GBool GlobalParams::getPSBinary() {
return binary;
}
GBool GlobalParams::getPSUncompressPreloadedImages() {
GBool ah;
lockGlobalParams;
ah = psUncompressPreloadedImages;
unlockGlobalParams;
return ah;
}
double GlobalParams::getPSRasterResolution() {
double res;
lockGlobalParams;
res = psRasterResolution;
unlockGlobalParams;
return res;
}
GBool GlobalParams::getPSRasterMono() {
GBool mono;
lockGlobalParams;
mono = psRasterMono;
unlockGlobalParams;
return mono;
}
GBool GlobalParams::getPSAlwaysRasterize() {
GBool rast;
lockGlobalParams;
rast = psAlwaysRasterize;
unlockGlobalParams;
return rast;
}
GooString *GlobalParams::getTextEncodingName() {
GooString *s;
......@@ -1631,6 +1671,15 @@ GBool GlobalParams::getVectorAntialias() {
return f;
}
GBool GlobalParams::getAntialiasPrinting() {
GBool f;
lockGlobalParams;
f = antialiasPrinting;
unlockGlobalParams;
return f;
}
GBool GlobalParams::getStrokeAdjust() {
GBool f;
......@@ -1745,14 +1794,6 @@ GBool GlobalParams::getErrQuiet() {
return errQuiet;
}
double GlobalParams::getSplashResolution() {
double r;
lockGlobalParams;
r = splashResolution;
unlockGlobalParams;
return r;
}
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GooString *collection) {
GooString *fileName;
CharCodeToUnicode *ctu;
......@@ -1944,6 +1985,30 @@ void GlobalParams::setPSBinary(GBool binary) {
unlockGlobalParams;
}
void GlobalParams::setPSUncompressPreloadedImages(GBool uncomp) {
lockGlobalParams;
psUncompressPreloadedImages = uncomp;
unlockGlobalParams;
}
void GlobalParams::setPSRasterResolution(double res) {
lockGlobalParams;
psRasterResolution = res;
unlockGlobalParams;
}
void GlobalParams::setPSRasterMono(GBool mono) {
lockGlobalParams;
psRasterMono = mono;
unlockGlobalParams;
}
void GlobalParams::setPSAlwaysRasterize(GBool always) {
lockGlobalParams;
psAlwaysRasterize = always;
unlockGlobalParams;
}
void GlobalParams::setTextEncoding(char *encodingName) {
lockGlobalParams;
delete textEncoding;
......@@ -2015,6 +2080,12 @@ GBool GlobalParams::setVectorAntialias(char *s) {
return ok;
}
void GlobalParams::setAntialiasPrinting(GBool anti) {
lockGlobalParams;
antialiasPrinting = anti;
unlockGlobalParams;
}
void GlobalParams::setStrokeAdjust(GBool adjust)
{
lockGlobalParams;
......@@ -2107,12 +2178,6 @@ void GlobalParams::setErrQuiet(GBool errQuietA) {
unlockGlobalParams;
}
void GlobalParams::setSplashResolution(double SplashResolutionA) {
lockGlobalParams;
splashResolution = SplashResolutionA;
unlockGlobalParams;
}
void GlobalParams::addSecurityHandler(XpdfSecurityHandler *handler) {
#ifdef ENABLE_PLUGINS
lockGlobalParams;
......
......@@ -165,6 +165,10 @@ public:
GBool getPSOPI();
GBool getPSASCIIHex();
GBool getPSBinary();
GBool getPSUncompressPreloadedImages();
double getPSRasterResolution();
GBool getPSRasterMono();
GBool getPSAlwaysRasterize();
GooString *getTextEncodingName();
EndOfLineKind getTextEOL();
GBool getTextPageBreaks();
......@@ -173,6 +177,7 @@ public:
GBool getDisableFreeTypeHinting();
GBool getAntialias();
GBool getVectorAntialias();
GBool getAntialiasPrinting();
GBool getStrokeAdjust();
ScreenType getScreenType();
int getScreenSize();
......@@ -217,6 +222,10 @@ public:
void setPSOPI(GBool opi);
void setPSASCIIHex(GBool hex);
void setPSBinary(GBool binary);
void setPSUncompressPreloadedImages(GBool uncomp);
void setPSRasterResolution(double res);
void setPSRasterMono(GBool mono);
void setPSAlwaysRasterize(GBool always);
void setTextEncoding(char *encodingName);
GBool setTextEOL(char *s);
void setTextPageBreaks(GBool pageBreaks);
......@@ -225,6 +234,7 @@ public:
GBool setDisableFreeTypeHinting(char *s);
GBool setAntialias(char *s);
GBool setVectorAntialias(char *s);
void setAntialiasPrinting(GBool print);
void setStrokeAdjust(GBool strokeAdjust);
void setScreenType(ScreenType st);
void setScreenSize(int size);
......@@ -239,7 +249,6 @@ public:
void setPrintCommands(GBool printCommandsA);
void setProfileCommands(GBool profileCommandsA);
void setErrQuiet(GBool errQuietA);
void setSplashResolution(double splashResolutionA);
//----- security handlers
......@@ -313,6 +322,12 @@ private:
GBool psOPI; // generate PostScript OPI comments?
GBool psASCIIHex; // use ASCIIHex instead of ASCII85?
GBool psBinary; // use binary instead of hex
GBool psUncompressPreloadedImages; // uncompress all preloaded images
double psRasterResolution; // PostScript rasterization resolution (dpi)
GBool psRasterMono; // true to do PostScript rasterization
// in monochrome (gray); false to do it
// in color (RGB/CMYK)
GBool psAlwaysRasterize; // force PostScript rasterization
GooString *textEncoding; // encoding (unicodeMap) to use for text
// output
EndOfLineKind textEOL; // type of EOL marker to use for text
......@@ -323,6 +338,7 @@ private:
GBool disableFreeTypeHinting; // FreeType disable hinting flag
GBool antialias; // anti-aliasing enable flag
GBool vectorAntialias; // vector anti-aliasing enable flag
GBool antialiasPrinting; // allow anti-aliasing when printing
GBool strokeAdjust; // stroke adjustment enable flag
ScreenType screenType; // halftone screen type
int screenSize; // screen matrix size
......
......@@ -60,9 +60,9 @@ description for all fonts available in Windows. That's how MuPDF works.
#define DEFAULT_SUBSTITUTE_FONT "Helvetica"
static struct {
char *name;
char *t1FileName;
char *ttFileName;
const char *name;
const char *t1FileName;
const char *ttFileName;
} displayFontTab[] = {
{"Courier", "n022003l.pfb", "cour.ttf"},
{"Courier-Bold", "n022004l.pfb", "courbd.ttf"},
......@@ -253,7 +253,8 @@ void SysFontList::scanWindowsFonts(GooString *winFontDir) {
data[dataLen] = '\0';
n = strlen(data);
if (!strcasecmp(data + n - 4, ".ttf") ||
!strcasecmp(data + n - 4, ".ttc")) {
!strcasecmp(data + n - 4, ".ttc") ||
!strcasecmp(data + n - 4, ".otf")) {
fontPath = new GooString(data);
if (!(dataLen >= 3 && data[1] == ':' && data[2] == '\\')) {
fontPath->insert(0, '\\');
......@@ -301,6 +302,11 @@ SysFontInfo *SysFontList::makeWindowsFont(char *name, int fontNum,
n -= 11;
}
// remove trailing ' (OpenType)'
if (n > 11 && !strncmp(name + n - 11, " (OpenType)", 11)) {
n -= 11;
}
// remove trailing ' Italic'
if (n > 7 && !strncmp(name + n - 7, " Italic", 7)) {
n -= 7;
......@@ -401,7 +407,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
*fontNum = fi->fontNum;
} else {
GooString *substFontName = new GooString(findSubstituteName(fontName->getCString()));
error(errSyntaxError, -1, "Couldn't find a font for '{0:t}', subst is '{0:s}'", fontName, substFontName);
error(errSyntaxError, -1, "Couldn't find a font for '{0:t}', subst is '{1:t}'", fontName, substFontName);
if ((fi = sysFonts->find(substFontName, gFalse))) {
path = fi->path->copy();
*type = fi->type;
......
......@@ -134,7 +134,7 @@ void Hints::readTables(BaseStream *str, Linearization *linearization, XRef *xref
if (parser->getObj(&obj)->isInt() &&
(num = obj.getInt(), obj.free(), parser->getObj(&obj)->isInt()) &&
(gen = obj.getInt(), obj.free(), parser->getObj(&obj)->isCmd("obj")) &&
(obj.free(), parser->getObj(&obj,
(obj.free(), parser->getObj(&obj, gFalse,
secHdlr ? secHdlr->getFileKey() : (Guchar *)NULL,
secHdlr ? secHdlr->getEncAlgorithm() : cryptRC4,
secHdlr ? secHdlr->getFileKeyLength() : 0,
......
......@@ -86,8 +86,8 @@
//------------------------------------------------------------------------
// Resolution at which pages with transparency will be rasterized.
#define defaultSplashDPI 300
// Max size of a slice when rasterizing pages, in pixels.
#define rasterizationSliceSize 20000000
//------------------------------------------------------------------------
// PostScript prolog and setup
......@@ -113,16 +113,24 @@ static const char *prolog[] = {
" } for",
"~123sn",
"/pdfSetup {",
" 3 1 roll 2 array astore",
" /setpagedevice where {",
" pop 3 dict begin",
" pop 2 dict begin",
" /Policies 1 dict dup begin /PageSize 6 def end def",
" { /Duplex true def } if",
" currentdict end setpagedevice",
" } {",
" pop",
" } ifelse",
"} def",
"/pdfSetupPaper {",
" 2 array astore",
" /setpagedevice where {",
" pop 2 dict begin",
" /PageSize exch def",
" /ImagingBBox null def",
" /Policies 1 dict dup begin /PageSize 3 def end def",
" { /Duplex true def } if",
" currentdict end setpagedevice",
" } {",
" pop pop",
" pop",
" } ifelse",
"} def",
"~1sn",
......@@ -410,82 +418,82 @@ static const char *prolog[] = {
"/Td { pdfTextMat transform moveto } def",
"/Tm { /pdfTextMat exch def } def",
"% text string operators",
"/xyshow where {",
" pop",
" /xyshow2 {",
" dup length array",
" 0 2 2 index length 1 sub {",
" 2 index 1 index 2 copy get 3 1 roll 1 add get",
" pdfTextMat dtransform",
" 4 2 roll 2 copy 6 5 roll put 1 add 3 1 roll dup 4 2 roll put",
" } for",
" exch pop",
" xyshow",
" } def",
"}{",
" /xyshow2 {",
" currentfont /FontType get 0 eq {",
" 0 2 3 index length 1 sub {",
" currentpoint 4 index 3 index 2 getinterval show moveto",
" 2 copy get 2 index 3 2 roll 1 add get",
" pdfTextMat dtransform rmoveto",
" } for",
" } {",
" 0 1 3 index length 1 sub {",
" currentpoint 4 index 3 index 1 getinterval show moveto",
" 2 copy 2 mul get 2 index 3 2 roll 2 mul 1 add get",
" pdfTextMat dtransform rmoveto",
" } for",
" } ifelse",
" pop pop",
" } def",
"} ifelse",
"/cshow where {",
" pop",
" /cshow2 {",
" dup {",
" pop pop",
" 1 string dup 0 3 index put 3 index exec",
" /xycp {", // xycharpath
" 0 3 2 roll",
" {",
" pop pop currentpoint 3 2 roll",
" 1 string dup 0 4 3 roll put false charpath moveto",
" 2 copy get 2 index 2 index 1 add get",
" pdfTextMat dtransform rmoveto",
" 2 add",
" } exch cshow",
" pop pop",
" } def",
"}{",
" /cshow2 {",
" /xycp {", // xycharpath
" currentfont /FontType get 0 eq {",
" 0 2 2 index length 1 sub {",
" 2 copy get exch 1 add 2 index exch get",
" 2 copy exch 256 mul add",
" 2 string dup 0 6 5 roll put dup 1 5 4 roll put",
" 3 index exec",
" 0 2 3 index length 1 sub {",
" currentpoint 4 index 3 index 2 getinterval false charpath moveto",
" 2 copy get 2 index 3 2 roll 1 add get",
" pdfTextMat dtransform rmoveto",
" } for",
" } {",
" dup {",
" 1 string dup 0 3 index put 3 index exec",
" } forall",
" 0 1 3 index length 1 sub {",
" currentpoint 4 index 3 index 1 getinterval false charpath moveto",
" 2 copy 2 mul get 2 index 3 2 roll 2 mul 1 add get",
" pdfTextMat dtransform rmoveto",
" } for",
" } ifelse",
" pop pop",
" } def",
"} ifelse",
"/awcp {", // awidthcharpath
" exch {",
" false charpath",
" 5 index 5 index rmoveto",
" 6 index eq { 7 index 7 index rmoveto } if",
" } exch cshow2",
" 6 {pop} repeat",
"} def",
"/Tj {",
" fCol", // because stringwidth has to draw Type 3 chars
" 1 index stringwidth pdfTextMat idtransform pop",
" sub 1 index length dup 0 ne { div } { pop pop 0 } ifelse",
" pdfWordSpacing pdfHorizScaling mul 0 pdfTextMat dtransform 32",
" 4 3 roll pdfCharSpacing pdfHorizScaling mul add 0",
" pdfTextMat dtransform",
" 6 5 roll Tj1",
"} def",
"/Tj16 {",
" fCol", // because stringwidth has to draw Type 3 chars
" 2 index stringwidth pdfTextMat idtransform pop",
" sub exch div",
" pdfWordSpacing pdfHorizScaling mul 0 pdfTextMat dtransform 32",
" 4 3 roll pdfCharSpacing pdfHorizScaling mul add 0",
" pdfTextMat dtransform",
" 6 5 roll Tj1",
"} def",
"/Tj16V {",
" fCol", // because stringwidth has to draw Type 3 chars
" 2 index stringwidth pdfTextMat idtransform exch pop",
" sub exch div",
" 0 pdfWordSpacing pdfTextMat dtransform 32",
" 4 3 roll pdfCharSpacing add 0 exch",
" pdfTextMat dtransform",
" 6 5 roll Tj1",
"} def",
"/Tj1 {",
" 0 pdfTextRise pdfTextMat dtransform rmoveto",
" currentpoint 8 2 roll",
" pdfTextRender 1 and 0 eq pdfPatternCS not and {",
" 6 copy awidthshow",
" currentpoint 4 2 roll",
" pdfTextRender 1 and 0 eq {",
" 2 copy xyshow2",
" } if",
" pdfTextRender 3 and dup 1 eq exch 2 eq or {",
" 7 index 7 index moveto",
" 6 copy",
" 3 index 3 index moveto",
" 2 copy",
" currentfont /FontType get 3 eq { fCol } { sCol } ifelse",
" false awcp currentpoint stroke moveto",
" xycp currentpoint stroke moveto",
" } if",
" pdfTextRender 4 and 0 ne pdfPatternCS or {",
" 8 6 roll moveto",
" false awcp",
" pdfTextRender 4 and 0 ne {",
" 4 2 roll moveto xycp",
" /pdfTextClipPath [ pdfTextClipPath aload pop",
" {/moveto cvx}",
" {/lineto cvx}",
......@@ -494,13 +502,13 @@ static const char *prolog[] = {
" pathforall ] def",
" currentpoint newpath moveto",
" } {",
" 8 {pop} repeat",
" pop pop pop pop",
" } ifelse",
" 0 pdfTextRise neg pdfTextMat dtransform rmoveto",
"} def",
"/TJm { pdfFontSize 0.001 mul mul neg 0",
"/TJm { 0.001 mul pdfFontSize mul pdfHorizScaling mul neg 0",
" pdfTextMat dtransform rmoveto } def",
"/TJmV { pdfFontSize 0.001 mul mul neg 0 exch",
"/TJmV { 0.001 mul pdfFontSize mul neg 0 exch",
" pdfTextMat dtransform rmoveto } def",
"/Tclip { pdfTextClipPath cvx exec clip newpath",
" /pdfTextClipPath [] def } def",
......@@ -548,19 +556,52 @@ static const char *prolog[] = {
" fCol /pdfImBuf1 4 index 7 add 8 idiv string def",
" { currentfile pdfImBuf1 readstring pop } imagemask",
"} def",
"/pdfImStr {",
" 2 copy exch length lt {",
" 2 copy get exch 1 add exch",
" } {",
" ()",
" } ifelse",
"} def",
"/pdfImM1a {",
" { 2 copy get exch 1 add exch } imagemask",
" { pdfImStr } imagemask",
" pop pop",
"} def",
"~23sn",
"% Level 2 image operators",
"% Level 2/3 image operators",
"/pdfImBuf 100 string def",
"/pdfIm {",
" image",
"/pdfImStr {",
" 2 copy exch length lt {",
" 2 copy get exch 1 add exch",
" } {",
" ()",
" } ifelse",
"} def",
"/skipEOD {",
" { currentfile pdfImBuf readline",
" not { pop exit } if",
" (%-EOD-) eq { exit } if } loop",
"} def",
"/pdfIm { image skipEOD } def",
"~3sn",
"/pdfMask {",
" /ReusableStreamDecode filter",
" skipEOD",
" /maskStream exch def",
"} def",
"/pdfMaskEnd { maskStream closefile } def",
"/pdfMaskInit {",
" /maskArray exch def",
" /maskIdx 0 def",
"} def",
"/pdfMaskSrc {",
" maskIdx maskArray length lt {",
" maskArray maskIdx get",
" /maskIdx maskIdx 1 add def",
" } {",
" ()",
" } ifelse",
"} def",
"~23s",
"/pdfImSep {",
" findcmykcustomcolor exch",
......@@ -576,17 +617,10 @@ static const char *prolog[] = {
" 255 exch sub put",
" } for }",
" 6 5 roll customcolorimage",
" { currentfile pdfImBuf readline",
" not { pop exit } if",
" (%-EOD-) eq { exit } if } loop",
" skipEOD",
"} def",
"~23sn",
"/pdfImM {",
" fCol imagemask",
" { currentfile pdfImBuf readline",
" not { pop exit } if",
" (%-EOD-) eq { exit } if } loop",
"} def",
"/pdfImM { fCol imagemask skipEOD } def",
"~123sn",
"/pr { 2 index 2 index 3 2 roll putinterval 4 add } def",
"/pdfImClip {",
......@@ -891,6 +925,13 @@ struct PSOutImgClipRect {
int x0, x1, y0, y1;
};
//------------------------------------------------------------------------
struct PSOutPaperSize {
PSOutPaperSize(int wA, int hA) { w = wA; h = hA; }
int w, h;
};
//------------------------------------------------------------------------
// DeviceNRecoder
//------------------------------------------------------------------------
......@@ -944,6 +985,9 @@ DeviceNRecoder::~DeviceNRecoder() {
if (imgStr) {
delete imgStr;
}
if (str->isEncoder()) {
delete str;
}
}
void DeviceNRecoder::reset() {
......@@ -994,8 +1038,9 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc,
int firstPage, int lastPage, PSOutMode modeA,
int paperWidthA, int paperHeightA, GBool duplexA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
GBool forceRasterizeA,
GBool manualCtrlA) {
GBool manualCtrlA,
PSOutCustomCodeCbk customCodeCbkA,
void *customCodeCbkDataA) {
FILE *f;
PSFileType fileTypeA;
......@@ -1003,23 +1048,23 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc,
underlayCbkData = NULL;
overlayCbk = NULL;
overlayCbkData = NULL;
customCodeCbk = customCodeCbkA;
customCodeCbkData = customCodeCbkDataA;
fontIDs = NULL;
fontNames = new GooHash(gTrue);
fontFileIDs = NULL;
fontFileNames = NULL;
t1FontNames = NULL;
font8Info = NULL;
font16Enc = NULL;
imgIDs = NULL;
formIDs = NULL;
xobjStack = NULL;
paperSizes = NULL;
embFontList = NULL;
customColors = NULL;
haveTextClip = gFalse;
t3String = NULL;
forceRasterize = forceRasterizeA;
// open file or pipe
if (!strcmp(fileName, "-")) {
fileTypeA = psStdout;
......@@ -1061,29 +1106,30 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
int firstPage, int lastPage, PSOutMode modeA,
int paperWidthA, int paperHeightA, GBool duplexA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
GBool forceRasterizeA,
GBool manualCtrlA) {
GBool manualCtrlA,
PSOutCustomCodeCbk customCodeCbkA,
void *customCodeCbkDataA) {
underlayCbk = NULL;
underlayCbkData = NULL;
overlayCbk = NULL;
overlayCbkData = NULL;
customCodeCbk = customCodeCbkA;
customCodeCbkData = customCodeCbkDataA;
fontIDs = NULL;
fontNames = new GooHash(gTrue);
fontFileIDs = NULL;
fontFileNames = NULL;
t1FontNames = NULL;
font8Info = NULL;
font16Enc = NULL;
imgIDs = NULL;
formIDs = NULL;
xobjStack = NULL;
paperSizes = NULL;
embFontList = NULL;
customColors = NULL;
haveTextClip = gFalse;
t3String = NULL;
forceRasterize = forceRasterizeA;
init(outputFuncA, outputStreamA, psGeneric, psTitle,
doc, firstPage, lastPage, modeA,
imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA,
......@@ -1098,6 +1144,9 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
GBool duplexA) {
Catalog *catalog;
PDFRectangle *box;
PSOutPaperSize *size;
GooList *names;
int pg, w, h, i;
// initialize
displayText = gTrue;
......@@ -1118,14 +1167,38 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
imgURY = imgURYA;
if (paperWidth < 0 || paperHeight < 0) {
Page *page;
if ((page = doc->getPage(firstPage))) {
paperWidth = (int)ceil(page->getMediaWidth());
paperHeight = (int)ceil(page->getMediaHeight());
} else {
error(errSyntaxError, -1, "Invalid page {0:d}", firstPage);
paperWidth = 1;
paperHeight = 1;
paperMatch = gTrue;
paperSizes = new GooList();
paperWidth = paperHeight = 1; // in case the document has zero pages
for (pg = (firstPage >= 1) ? firstPage : 1;
pg <= lastPage && pg <= catalog->getNumPages();
++pg) {
page = catalog->getPage(pg);
if (page == NULL) {
paperMatch = gFalse;
break;
}
w = (int)ceil(page->getMediaWidth());
h = (int)ceil(page->getMediaHeight());
for (i = 0; i < paperSizes->getLength(); ++i) {
size = (PSOutPaperSize *)paperSizes->get(i);
if (size->w == w && size->h == h) {
break;
}
}
if (i == paperSizes->getLength()) {
paperSizes->append(new PSOutPaperSize(w, h));
}
if (w > paperWidth) {
paperWidth = w;
}
if (h > paperHeight) {
paperHeight = h;
}
}
// NB: img{LLX,LLY,URX,URY} will be set by startPage()
} else {
paperMatch = gFalse;
}
preload = globalParams->getPSPreload();
if (imgLLX == 0 && imgURX == 0 && imgLLY == 0 && imgURY == 0) {
......@@ -1161,14 +1234,18 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
fontIDSize = 64;
fontIDLen = 0;
fontIDs = (Ref *)gmallocn(fontIDSize, sizeof(Ref));
fontFileIDSize = 64;
fontFileIDLen = 0;
fontFileIDs = (Ref *)gmallocn(fontFileIDSize, sizeof(Ref));
fontFileNameSize = 64;
fontFileNameLen = 0;
fontFileNames = (GooString **)gmallocn(fontFileNameSize, sizeof(GooString *));
psFileNames = (GooString **)gmallocn(fontFileNameSize, sizeof(GooString *));
nextTrueTypeNum = 0;
fontIDs = (Ref *)gmallocn(fontIDSize, sizeof(Ref));
for (i = 0; i < 14; ++i) {
fontNames->add(new GooString(psBase14SubstFonts[i].psName), 1);
}
names = globalParams->getPSResidentFonts();
for (i = 0; i < names->getLength(); ++i) {
fontNames->add((GooString *)names->get(i), 1);
}
delete names;
t1FontNameSize = 64;
t1FontNameLen = 0;
t1FontNames = (PST1FontName *)gmallocn(t1FontNameSize, sizeof(PST1FontName));
font8InfoLen = 0;
font8InfoSize = 0;
font16EncLen = 0;
......@@ -1246,6 +1323,9 @@ PSOutputDev::~PSOutputDev() {
}
#endif
}
if (paperSizes) {
deleteGooList(paperSizes, PS