From 6bf8080516ffe50afba89f1f07f486000423bcd8 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Mon, 23 Aug 1999 13:13:52 +0000 Subject: [PATCH] New version using Derek's merged Stream stuff, disabled helper utils build until I sync with Derek. --- pdf/xpdf/Gfx.cc | 2 +- pdf/xpdf/Makefile.am | 4 +- pdf/xpdf/Object.h | 4 - pdf/xpdf/PDFDoc.cc | 130 ++++++++++++++---- pdf/xpdf/PDFDoc.h | 9 +- pdf/xpdf/Parser.cc | 2 +- pdf/xpdf/Stream.cc | 212 +++++++++++++---------------- pdf/xpdf/Stream.h | 241 +++++++++++++-------------------- pdf/xpdf/XRef.cc | 28 ++-- pdf/xpdf/XRef.h | 13 +- pdf/xpdf/bonobo-image-x-pdf.cc | 7 +- 11 files changed, 324 insertions(+), 328 deletions(-) diff --git a/pdf/xpdf/Gfx.cc b/pdf/xpdf/Gfx.cc index bbf5bdf2..7666ad03 100644 --- a/pdf/xpdf/Gfx.cc +++ b/pdf/xpdf/Gfx.cc @@ -1523,7 +1523,7 @@ Stream *Gfx::buildImageStream() { obj.free(); // make stream - str = new SubStream(parser->getStream(), &dict); + str = new EmbedStream(parser->getStream(), &dict); str = str->addFilters(&dict); return str; diff --git a/pdf/xpdf/Makefile.am b/pdf/xpdf/Makefile.am index b72a32ab..9e7873d5 100644 --- a/pdf/xpdf/Makefile.am +++ b/pdf/xpdf/Makefile.am @@ -11,7 +11,9 @@ else gui = xpdf endif -bin_PROGRAMS = pdftops pdftotext pdfinfo pdftopbm pdfimages $(gui) bonobo-image-x-pdf +#bin_PROGRAMS = pdftops pdftotext pdfinfo pdftopbm pdfimages $(gui) bonobo-image-x-pdf +# Wait for Derek to send updated pdfto* +bin_PROGRAMS = $(gui) bonobo-image-x-pdf common_sources = \ Array.cc \ diff --git a/pdf/xpdf/Object.h b/pdf/xpdf/Object.h index cb7a4180..789cd5fa 100644 --- a/pdf/xpdf/Object.h +++ b/pdf/xpdf/Object.h @@ -177,7 +177,6 @@ public: char *streamGetLine(char *buf, int size); int streamGetPos(); void streamSetPos(int pos); -/* BaseFile streamGetFile();*/ Dict *streamGetDict(); // Output. @@ -290,9 +289,6 @@ inline int Object::streamGetPos() inline void Object::streamSetPos(int pos) { stream->setPos(pos); } -/*inline BaseFile Object::streamGetFile() - { return stream->getFile(); }*/ - inline Dict *Object::streamGetDict() { return stream->getDict(); } diff --git a/pdf/xpdf/PDFDoc.cc b/pdf/xpdf/PDFDoc.cc index 111c1897..06b1cd79 100644 --- a/pdf/xpdf/PDFDoc.cc +++ b/pdf/xpdf/PDFDoc.cc @@ -18,6 +18,7 @@ #include "config.h" #include "Page.h" #include "Catalog.h" +#include "Stream.h" #include "XRef.h" #include "Link.h" #include "OutputDev.h" @@ -25,37 +26,78 @@ #include "Error.h" #include "PDFDoc.h" +//------------------------------------------------------------------------ + +#define headerSearchSize 1024 // read this many bytes at beginning of + // file to look for '%PDF' + //------------------------------------------------------------------------ // PDFDoc //------------------------------------------------------------------------ -PDFDoc::PDFDoc(Stream *str1, GString *fileName1) { - Object catObj; +PDFDoc::PDFDoc(GString *fileName1) { + Object obj; + GString *fileName2; - // setup ok = gFalse; - catalog = NULL; - xref = NULL; - links = NULL; - str = str1; + file = NULL; + str = NULL; + + // try to open file fileName = fileName1; - if (!(str && str->isOk())) + fileName2 = NULL; +#ifdef VMS + if (!(file = fopen(fileName->getCString(), "rb", "ctx=stm"))) { + error(-1, "Couldn't open file '%s'", fileName->getCString()); return; + } +#else + if (!(file = fopen(fileName->getCString(), "rb"))) { + fileName2 = fileName->copy(); + fileName2->lowerCase(); + if (!(file = fopen(fileName2->getCString(), "rb"))) { + fileName2->upperCase(); + if (!(file = fopen(fileName2->getCString(), "rb"))) { + error(-1, "Couldn't open file '%s'", fileName->getCString()); + delete fileName2; + return; + } + } + delete fileName2; + } +#endif // create stream -/* obj.initNull(); */ -/* str = new FileStream(file, 0, -1, &obj); */ + obj.initNull(); + str = new FileStream(file, 0, -1, &obj); + + ok = setup(); +} + +PDFDoc::PDFDoc(BaseStream *str) { + ok = gFalse; + fileName = NULL; + file = NULL; + this->str = str; + ok = setup(); +} + +GBool PDFDoc::setup() { + Object catObj; + + xref = NULL; + catalog = NULL; + links = NULL; // check header -/* str->checkHeader(); FIXME */ + checkHeader(); // read xref table xref = new XRef(str); -/* delete str; */ if (!xref->isOk()) { error(-1, "Couldn't read xref table"); - return; + return gFalse; } // read catalog @@ -63,27 +105,63 @@ PDFDoc::PDFDoc(Stream *str1, GString *fileName1) { catObj.free(); if (!catalog->isOk()) { error(-1, "Couldn't read page catalog"); - return; + return gFalse; } // done - ok = gTrue; - return; + return gTrue; } PDFDoc::~PDFDoc() { - if (catalog) + if (catalog) { delete catalog; - if (xref) + } + if (xref) { delete xref; + } if (str) { - delete (str); - str = NULL; + delete str; + } + if (file) { + fclose(file); } - if (fileName) + if (fileName) { delete fileName; - if (links) + } + if (links) { delete links; + } +} + +// Check for a PDF header on this stream. Skip past some garbage +// if necessary. +void PDFDoc::checkHeader() { + char hdrBuf[headerSearchSize+1]; + char *p; + double version; + int i; + + for (i = 0; i < headerSearchSize; ++i) { + hdrBuf[i] = str->getChar(); + } + hdrBuf[headerSearchSize] = '\0'; + for (i = 0; i < headerSearchSize - 5; ++i) { + if (!strncmp(&hdrBuf[i], "%PDF-", 5)) { + break; + } + } + if (i >= headerSearchSize - 5) { + error(-1, "May not be a PDF file (continuing anyway)"); + return; + } + str->moveStart(i); + p = strtok(&hdrBuf[i+5], " \t\n\r"); + version = atof(p); + if (!(hdrBuf[i+5] >= '0' && hdrBuf[i+5] <= '9') || + version > pdfVersionNum + 0.0001) { + error(-1, "PDF version %s -- xpdf supports version %s" + " (continuing anyway)", p, pdfVersion); + } } void PDFDoc::displayPage(OutputDev *out, int page, int zoom, int rotate, @@ -125,16 +203,16 @@ void PDFDoc::displayPages(OutputDev *out, int firstPage, int lastPage, GBool PDFDoc::saveAs(GString *name) { FILE *f; - char buf[4096]; - int n; + int c; if (!(f = fopen(name->getCString(), "wb"))) { error(-1, "Couldn't open file '%s'", name->getCString()); return gFalse; } str->reset(); - while (str->getLine (buf, 4096)) - fputs (buf, f); + while ((c = str->getChar()) != EOF) { + fputc(c, f); + } fclose(f); return gTrue; } diff --git a/pdf/xpdf/PDFDoc.h b/pdf/xpdf/PDFDoc.h index f76cfaf8..b978bc7d 100644 --- a/pdf/xpdf/PDFDoc.h +++ b/pdf/xpdf/PDFDoc.h @@ -17,6 +17,7 @@ #include "Link.h" class GString; +class BaseStream; class XRef; class Catalog; class OutputDev; @@ -31,7 +32,8 @@ class LinkDest; class PDFDoc { public: - PDFDoc(Stream *str1, GString *fileName1); + PDFDoc(GString *fileName1); + PDFDoc(BaseStream *str); ~PDFDoc(); // Was PDF document successfully opened? @@ -93,10 +95,13 @@ public: private: + GBool setup(); + void checkHeader(); void getLinks(int page); GString *fileName; - Stream *str; + FILE *file; + BaseStream *str; XRef *xref; Catalog *catalog; Links *links; diff --git a/pdf/xpdf/Parser.cc b/pdf/xpdf/Parser.cc index 0b61002c..55685807 100644 --- a/pdf/xpdf/Parser.cc +++ b/pdf/xpdf/Parser.cc @@ -126,7 +126,7 @@ Stream *Parser::makeStream(Object *dict) { } // make base stream - str = lexer->getStream()->subStream (pos, length, dict); + str = lexer->getStream()->getBaseStream()->makeSubStream(pos, length, dict); // get filters str = str->addFilters(dict); diff --git a/pdf/xpdf/Stream.cc b/pdf/xpdf/Stream.cc index 08b806a7..adcf788b 100644 --- a/pdf/xpdf/Stream.cc +++ b/pdf/xpdf/Stream.cc @@ -45,11 +45,6 @@ extern "C" int unlink(char *filename); #endif #endif -//------------------------------------------------------------------------ - -#define headerSearchSize 1024 // read this many bytes at beginning of - // file to look for '%PDF' - //------------------------------------------------------------------------ // Stream (base class) //------------------------------------------------------------------------ @@ -87,10 +82,6 @@ char *Stream::getLine(char *buf, int size) { return buf; } -void Stream::setPos(int pos) { - error(-1, "Internal: called setPos() on non-FileStream"); -} - GString *Stream::getPSFilter(char *indent) { return new GString(); } @@ -264,6 +255,33 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params) { return str; } +//------------------------------------------------------------------------ +// BaseStream +//------------------------------------------------------------------------ + +BaseStream::BaseStream(Object *dict) { + this->dict = *dict; +} + +BaseStream::~BaseStream() { + dict.free(); +} + +//------------------------------------------------------------------------ +// FilterStream +//------------------------------------------------------------------------ + +FilterStream::FilterStream(Stream *str) { + this->str = str; +} + +FilterStream::~FilterStream() { +} + +void FilterStream::setPos(int pos) { + error(-1, "Internal: called setPos() on FilterStream"); +} + //------------------------------------------------------------------------ // ImageStream //------------------------------------------------------------------------ @@ -511,95 +529,24 @@ GBool StreamPredictor::getNextLine() { // FileStream //------------------------------------------------------------------------ -GBool FileStream::checkHeader() { - char hdrBuf[headerSearchSize+1]; - char *p; - double version; - int i; - - for (i = 0; i < headerSearchSize; ++i) - hdrBuf[i] = getChar(); - hdrBuf[headerSearchSize] = '\0'; - for (i = 0; i < headerSearchSize - 5; ++i) { - if (!strncmp(&hdrBuf[i], "%PDF-", 5)) - break; - } - if (i >= headerSearchSize - 5) { - error(-1, "May not be a PDF file (continuing anyway)"); - return gFalse; - } - start += i; - p = strtok(&hdrBuf[i+5], " \t\n\r"); - version = atof(p); - if (!(hdrBuf[i+5] >= '0' && hdrBuf[i+5] <= '9') || - version > pdfVersionNum + 0.0001) { - error(getPos(), "PDF version %s -- xpdf supports version %s" - " (continuing anyway)", p, pdfVersion); - return gFalse; - } - return gTrue; -} - -FILE *fileOpen (GString *fileName1) { - GString *fileName2; - // try to open file - fileName2 = NULL; - FILE *file = NULL; - -#ifdef VMS - if (!(file = fopen(fileName->getCString(), "rb", "ctx=stm"))) { - error(-1, "Couldn't open file '%s'", fileName->getCString()); - return NULL; - } -#else - if (!(file = fopen(fileName1->getCString(), "rb"))) { - fileName2 = fileName1->copy(); - fileName2->lowerCase(); - if (!(file = fopen(fileName2->getCString(), "rb"))) { - fileName2->upperCase(); - if (!(file = fopen(fileName2->getCString(), "rb"))) { - error(-1, "Couldn't open file '%s'", fileName1->getCString()); - delete fileName2; - return NULL; - } - } - delete fileName2; - } -#endif - return file; -} - -FileStream::FileStream() { -} - -FileStream::FileStream(FILE *f1) { - f = f1; - start = 0; - length = -1; +FileStream::FileStream(FILE *f, int start, int length, Object *dict): + BaseStream(dict) { + this->f = f; + this->start = start; + this->length = length; bufPtr = bufEnd = buf; bufPos = start; savePos = -1; - dict.initNull(); - if (f) - checkHeader(); -} - -Stream *FileStream::subStream (int start1, int length1, Object *dict1) { - FileStream *scp = new FileStream (); - scp->f = f; - scp->start = start1; - scp->length = length1; - scp->bufPtr = bufEnd = buf; - scp->bufPos = start; - scp->savePos = -1; - scp->dict = *dict1; - return scp; } FileStream::~FileStream() { - if (savePos >= 0) + if (savePos >= 0) { fseek(f, savePos, SEEK_SET); - dict.free(); + } +} + +Stream *FileStream::makeSubStream(int start, int length, Object *dict) { + return new FileStream(f, start, length, dict); } void FileStream::reset() { @@ -644,25 +591,48 @@ void FileStream::setPos(int pos1) { bufPtr = bufEnd = buf; } +void FileStream::moveStart(int delta) { + this->start += delta; + bufPtr = bufEnd = buf; + bufPos = start; +} + //------------------------------------------------------------------------ -// SubStream +// EmbedStream //------------------------------------------------------------------------ -SubStream::SubStream(Stream *str1, Object *dict1) { - str = str1; - dict = *dict1; +EmbedStream::EmbedStream(Stream *str, Object *dict): + BaseStream(dict) { + this->str = str; } -SubStream::~SubStream() { - dict.free(); +EmbedStream::~EmbedStream() { +} + +Stream *EmbedStream::makeSubStream(int start, int length, Object *dict) { + error(-1, "Internal: called makeSubStream() on EmbedStream"); + return NULL; +} + +void EmbedStream::setPos(int pos) { + error(-1, "Internal: called setPos() on EmbedStream"); +} + +int EmbedStream::getStart() { + error(-1, "Internal: called getStart() on EmbedStream"); + return 0; +} + +void EmbedStream::moveStart(int start) { + error(-1, "Internal: called moveStart() on EmbedStream"); } //------------------------------------------------------------------------ // ASCIIHexStream //------------------------------------------------------------------------ -ASCIIHexStream::ASCIIHexStream(Stream *str1) { - str = str1; +ASCIIHexStream::ASCIIHexStream(Stream *str): + FilterStream(str) { buf = EOF; eof = gFalse; } @@ -746,8 +716,8 @@ GBool ASCIIHexStream::isBinary(GBool last) { // ASCII85Stream //------------------------------------------------------------------------ -ASCII85Stream::ASCII85Stream(Stream *str1) { - str = str1; +ASCII85Stream::ASCII85Stream(Stream *str): + FilterStream(str) { index = n = 0; eof = gFalse; } @@ -822,9 +792,9 @@ GBool ASCII85Stream::isBinary(GBool last) { // LZWStream //------------------------------------------------------------------------ -LZWStream::LZWStream(Stream *str1, int predictor1, int columns1, int colors1, - int bits1, int early1) { - str = str1; +LZWStream::LZWStream(Stream *str, int predictor1, int columns1, int colors1, + int bits1, int early1): + FilterStream(str) { if (predictor1 != 1) { pred = new StreamPredictor(this, predictor1, columns1, colors1, bits1); } else { @@ -1102,8 +1072,8 @@ GBool LZWStream::isBinary(GBool last) { // RunLengthStream //------------------------------------------------------------------------ -RunLengthStream::RunLengthStream(Stream *str1) { - str = str1; +RunLengthStream::RunLengthStream(Stream *str): + FilterStream(str) { bufPtr = bufEnd = buf; eof = gFalse; } @@ -1162,8 +1132,8 @@ GBool RunLengthStream::fillBuf() { CCITTFaxStream::CCITTFaxStream(Stream *str, int encoding, GBool endOfLine, GBool byteAlign, int columns, int rows, - GBool endOfBlock, GBool black) { - this->str = str; + GBool endOfBlock, GBool black): + FilterStream(str) { this->encoding = encoding; this->endOfLine = endOfLine; this->byteAlign = byteAlign; @@ -1751,10 +1721,10 @@ static int dctZigZag[64] = { 63 }; -DCTStream::DCTStream(Stream *str1) { +DCTStream::DCTStream(Stream *str): + FilterStream(str) { int i, j; - str = str1; width = height = 0; mcuWidth = mcuHeight = 0; numComps = 0; @@ -2733,9 +2703,9 @@ FlateDecode FlateStream::distDecode[flateMaxDistCodes] = { {13, 24577} }; -FlateStream::FlateStream(Stream *str1, int predictor1, int columns1, - int colors1, int bits1) { - str = str1; +FlateStream::FlateStream(Stream *str, int predictor1, int columns1, + int colors1, int bits1): + FilterStream(str) { if (predictor1 != 1) { pred = new StreamPredictor(this, predictor1, columns1, colors1, bits1); } else { @@ -3163,8 +3133,8 @@ int FlateStream::getCodeWord(int bits) { // EOFStream //------------------------------------------------------------------------ -EOFStream::EOFStream(Stream *str1) { - str = str1; +EOFStream::EOFStream(Stream *str): + FilterStream(str) { } EOFStream::~EOFStream() { @@ -3175,8 +3145,8 @@ EOFStream::~EOFStream() { // FixedLengthEncoder //------------------------------------------------------------------------ -FixedLengthEncoder::FixedLengthEncoder(Stream *str1, int length1) { - str = str1; +FixedLengthEncoder::FixedLengthEncoder(Stream *str, int length1): + FilterStream(str) { length = length1; count = 0; } @@ -3208,8 +3178,8 @@ int FixedLengthEncoder::lookChar() { // ASCII85Encoder //------------------------------------------------------------------------ -ASCII85Encoder::ASCII85Encoder(Stream *str1) { - str = str1; +ASCII85Encoder::ASCII85Encoder(Stream *str): + FilterStream(str) { bufPtr = bufEnd = buf; lineLen = 0; eof = gFalse; @@ -3277,8 +3247,8 @@ GBool ASCII85Encoder::fillBuf() { // RunLengthEncoder //------------------------------------------------------------------------ -RunLengthEncoder::RunLengthEncoder(Stream *str1) { - str = str1; +RunLengthEncoder::RunLengthEncoder(Stream *str): + FilterStream(str) { bufPtr = bufEnd = nextEnd = buf; eof = gFalse; } diff --git a/pdf/xpdf/Stream.h b/pdf/xpdf/Stream.h index 33d73178..e4c70c9d 100644 --- a/pdf/xpdf/Stream.h +++ b/pdf/xpdf/Stream.h @@ -17,6 +17,8 @@ #include "gtypes.h" #include "Object.h" +class BaseStream; + //------------------------------------------------------------------------ enum StreamKind { @@ -71,7 +73,7 @@ public: virtual int getPos() = 0; // Go to a position in the stream. - virtual void setPos(int pos1); + virtual void setPos(int pos1) = 0; // Get PostScript command for the filter(s). virtual GString *getPSFilter(char *indent); @@ -79,17 +81,8 @@ public: // Does this stream type potentially contain non-printable chars? virtual GBool isBinary(GBool last = gTrue) = 0; - // Get the base FileStream or SubStream of this stream. - virtual Stream *getBaseStream() = 0; - - // Get a substream of this stream. - virtual Stream *subStream(int start1, int length1, Object *dict1) = 0; - - // Get start offset of a stream's data. - virtual int getStart() = 0; - - // Whether we failed to load ? - virtual GBool isOk() = 0; + // Get the BaseStream or EmbedStream of this stream. + virtual BaseStream *getBaseStream() = 0; // Get the dictionary associated with this stream. virtual Dict *getDict() = 0; @@ -108,6 +101,52 @@ private: int ref; // reference count }; +//------------------------------------------------------------------------ +// BaseStream +// +// This is the base class for all streams that read directly from a file. +//------------------------------------------------------------------------ + +class BaseStream: public Stream { +public: + + BaseStream(Object *dict); + virtual ~BaseStream(); + virtual Stream *makeSubStream(int start, int length, Object *dict) = 0; + virtual void setPos(int pos1) = 0; + virtual BaseStream *getBaseStream() { return this; } + virtual Dict *getDict() { return dict.getDict(); } + + // Get/set position of first byte of stream within the file. + virtual int getStart() = 0; + virtual void moveStart(int delta) = 0; + +private: + + Object dict; +}; + +//------------------------------------------------------------------------ +// FilterStream +// +// This is the base class for all streams that filter another stream. +//------------------------------------------------------------------------ + +class FilterStream: public Stream { +public: + + FilterStream(Stream *str); + virtual ~FilterStream(); + virtual int getPos() { return str->getPos(); } + virtual void setPos(int pos); + virtual BaseStream *getBaseStream() { return str->getBaseStream(); } + virtual Dict *getDict() { return str->getDict(); } + +protected: + + Stream *str; +}; + //------------------------------------------------------------------------ // ImageStream //------------------------------------------------------------------------ @@ -180,15 +219,12 @@ private: // FileStream //------------------------------------------------------------------------ -// Portable pdf open helper function. -extern FILE *fileOpen (GString *fileName1); +class FileStream: public BaseStream { +public: -class FileStream: public Stream { - private: - FileStream(); - public: - FileStream(FILE *f1); + FileStream(FILE *f, int start, int length, Object *dict); virtual ~FileStream(); + virtual Stream *makeSubStream(int start, int length, Object *dict); virtual StreamKind getKind() { return strFile; } virtual void reset(); virtual int getChar() @@ -198,16 +234,12 @@ class FileStream: public Stream { virtual int getPos() { return bufPos + (bufPtr - buf); } virtual void setPos(int pos1); virtual GBool isBinary(GBool last = gTrue) { return last; } - virtual Stream *getBaseStream() { return this; } - virtual Stream *subStream (int start1, int length1, Object *dict1); virtual int getStart() { return start; } - virtual GBool isOk() { return f != NULL; } - virtual Dict *getDict() { return dict.getDict(); } + virtual void moveStart(int delta); - private: +private: GBool fillBuf(); - GBool checkHeader(); FILE *f; int start; @@ -217,64 +249,58 @@ class FileStream: public Stream { char *bufEnd; int bufPos; int savePos; - Object dict; }; //------------------------------------------------------------------------ -// SubStream +// EmbedStream +// +// This is a special stream type used for embedded streams (inline +// images). It reads directly from the base stream -- after the +// EmbedStream is deleted, reads from the base stream will proceed where +// the BaseStream left off. Note that this is very different behavior +// that creating a new FileStream (using makeSubStream). //------------------------------------------------------------------------ -class SubStream: public Stream { +class EmbedStream: public BaseStream { public: - SubStream(Stream *str1, Object *dict1); - virtual ~SubStream(); + EmbedStream(Stream *str, Object *dict); + virtual ~EmbedStream(); + virtual Stream *makeSubStream(int start, int length, Object *dict); virtual StreamKind getKind() { return str->getKind(); } virtual void reset() {} virtual int getChar() { return str->getChar(); } virtual int lookChar() { return str->lookChar(); } virtual int getPos() { return str->getPos(); } + virtual void setPos(int pos); virtual GBool isBinary(GBool last = gTrue) { return last; } - virtual Stream *getBaseStream() { return this; } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return dict.getDict(); } + virtual int getStart(); + virtual void moveStart(int delta); private: Stream *str; - Object dict; }; //------------------------------------------------------------------------ // ASCIIHexStream //------------------------------------------------------------------------ -class ASCIIHexStream: public Stream { +class ASCIIHexStream: public FilterStream { public: - ASCIIHexStream(Stream *str1); + ASCIIHexStream(Stream *str); virtual ~ASCIIHexStream(); virtual StreamKind getKind() { return strASCIIHex; } virtual void reset(); virtual int getChar() { int c = lookChar(); buf = EOF; return c; } virtual int lookChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } private: - Stream *str; int buf; GBool eof; }; @@ -283,29 +309,21 @@ private: // ASCII85Stream //------------------------------------------------------------------------ -class ASCII85Stream: public Stream { +class ASCII85Stream: public FilterStream { public: - ASCII85Stream(Stream *str1); + ASCII85Stream(Stream *str); virtual ~ASCII85Stream(); virtual StreamKind getKind() { return strASCII85; } virtual void reset(); virtual int getChar() { int ch = lookChar(); ++index; return ch; } virtual int lookChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } private: - Stream *str; int c[5]; int b[4]; int index, n; @@ -316,10 +334,10 @@ private: // LZWStream //------------------------------------------------------------------------ -class LZWStream: public Stream { +class LZWStream: public FilterStream { public: - LZWStream(Stream *str1, int predictor1, int columns1, int colors1, + LZWStream(Stream *str, int predictor1, int columns1, int colors1, int bits1, int early1); virtual ~LZWStream(); virtual StreamKind getKind() { return strLZW; } @@ -327,19 +345,11 @@ public: virtual int getChar(); virtual int lookChar(); virtual int getRawChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } private: - Stream *str; // stream StreamPredictor *pred; // predictor int early; // early parameter char zCmd[256]; // uncompress command @@ -361,10 +371,10 @@ private: // RunLengthStream //------------------------------------------------------------------------ -class RunLengthStream: public Stream { +class RunLengthStream: public FilterStream { public: - RunLengthStream(Stream *str1); + RunLengthStream(Stream *str); virtual ~RunLengthStream(); virtual StreamKind getKind() { return strRunLength; } virtual void reset(); @@ -372,19 +382,11 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } private: - Stream *str; char buf[128]; // buffer char *bufPtr; // next char to read char *bufEnd; // end of buffer @@ -399,7 +401,7 @@ private: struct CCITTCodeTable; -class CCITTFaxStream: public Stream { +class CCITTFaxStream: public FilterStream { public: CCITTFaxStream(Stream *str, int encoding, GBool endOfLine, @@ -411,19 +413,11 @@ public: virtual int getChar() { int c = lookChar(); buf = EOF; return c; } virtual int lookChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } private: - Stream *str; // stream int encoding; // 'K' parameter GBool endOfLine; // 'EndOfLine' parameter GBool byteAlign; // 'EncodedByteAlign' parameter @@ -472,29 +466,21 @@ struct DCTHuffTable { Guchar sym[256]; // symbols }; -class DCTStream: public Stream { +class DCTStream: public FilterStream { public: - DCTStream(Stream *str1); + DCTStream(Stream *str); virtual ~DCTStream(); virtual StreamKind getKind() { return strDCT; } virtual void reset(); virtual int getChar(); virtual int lookChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } Stream *getRawStream() { return str; } private: - Stream *str; // stream int width, height; // image size int mcuWidth, mcuHeight; // size of min coding unit, in data units DCTCompInfo compInfo[4]; // info for each component @@ -564,10 +550,10 @@ struct FlateDecode { int first; // first length/distance }; -class FlateStream: public Stream { +class FlateStream: public FilterStream { public: - FlateStream(Stream *str1, int predictor1, int columns1, + FlateStream(Stream *str, int predictor1, int columns1, int colors1, int bits1); virtual ~FlateStream(); virtual StreamKind getKind() { return strFlate; } @@ -575,19 +561,11 @@ public: virtual int getChar(); virtual int lookChar(); virtual int getRawChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent); virtual GBool isBinary(GBool last = gTrue); - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } private: - Stream *str; // stream StreamPredictor *pred; // predictor Guchar buf[flateWindow]; // output data buffer int index; // current index into output buffer @@ -623,57 +601,38 @@ private: // EOFStream //------------------------------------------------------------------------ -class EOFStream: public Stream { +class EOFStream: public FilterStream { public: - EOFStream(Stream *str1); + EOFStream(Stream *str); virtual ~EOFStream(); virtual StreamKind getKind() { return strWeird; } virtual void reset() {} virtual int getChar() { return EOF; } virtual int lookChar() { return EOF; } - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } - -private: - - Stream *str; }; //------------------------------------------------------------------------ // FixedLengthEncoder //------------------------------------------------------------------------ -class FixedLengthEncoder: public Stream { +class FixedLengthEncoder: public FilterStream { public: - FixedLengthEncoder(Stream *str1, int length1); + FixedLengthEncoder(Stream *str, int length1); ~FixedLengthEncoder(); virtual StreamKind getKind() { return strWeird; } virtual void reset(); virtual int getChar(); virtual int lookChar(); - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } virtual GBool isEncoder() { return gTrue; } private: - Stream *str; int length; int count; }; @@ -682,10 +641,10 @@ private: // ASCII85Encoder //------------------------------------------------------------------------ -class ASCII85Encoder: public Stream { +class ASCII85Encoder: public FilterStream { public: - ASCII85Encoder(Stream *str1); + ASCII85Encoder(Stream *str); virtual ~ASCII85Encoder(); virtual StreamKind getKind() { return strWeird; } virtual void reset(); @@ -693,20 +652,12 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } virtual GBool isEncoder() { return gTrue; } private: - Stream *str; char buf[8]; char *bufPtr; char *bufEnd; @@ -720,10 +671,10 @@ private: // RunLengthEncoder //------------------------------------------------------------------------ -class RunLengthEncoder: public Stream { +class RunLengthEncoder: public FilterStream { public: - RunLengthEncoder(Stream *str1); + RunLengthEncoder(Stream *str); virtual ~RunLengthEncoder(); virtual StreamKind getKind() { return strWeird; } virtual void reset(); @@ -731,20 +682,12 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual int getPos() { return str->getPos(); } virtual GString *getPSFilter(char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } - virtual Stream *getBaseStream() { return str->getBaseStream(); } - virtual Stream *subStream (int start1, int length1, Object *dict1) - { return str->subStream (start1, length1, dict1); } - virtual int getStart() { return str->getStart(); } - virtual GBool isOk() { return str->isOk(); } - virtual Dict *getDict() { return str->getDict(); } virtual GBool isEncoder() { return gTrue; } private: - Stream *str; char buf[131]; char *bufPtr; char *bufEnd; diff --git a/pdf/xpdf/XRef.cc b/pdf/xpdf/XRef.cc index c725a4a3..f3672de6 100644 --- a/pdf/xpdf/XRef.cc +++ b/pdf/xpdf/XRef.cc @@ -38,7 +38,7 @@ XRef *xref = NULL; // XRef //------------------------------------------------------------------------ -XRef::XRef(Stream *str1) { +XRef::XRef(BaseStream *str) { XRef *oldXref; int pos; int i; @@ -53,14 +53,14 @@ XRef::XRef(Stream *str1) { xref = NULL; // read the trailer - str = str1; + this->str = str; start = str->getStart(); - pos = readTrailer(str); + pos = readTrailer(); // if there was a problem with the trailer, // try to reconstruct the xref table if (pos == 0) { - if (!(ok = constructXRef(str))) { + if (!(ok = constructXRef())) { xref = oldXref; return; } @@ -72,7 +72,7 @@ XRef::XRef(Stream *str1) { entries[i].offset = -1; entries[i].used = gFalse; } - while (readXRef(str, &pos)) ; + while (readXRef(&pos)) ; // if there was a problem with the xref table, // try to reconstruct it @@ -80,7 +80,7 @@ XRef::XRef(Stream *str1) { gfree(entries); size = 0; entries = NULL; - if (!(ok = constructXRef(str))) { + if (!(ok = constructXRef())) { xref = oldXref; return; } @@ -105,7 +105,7 @@ XRef::~XRef() { // Read startxref position, xref table size, and root. Returns // first xref position. -int XRef::readTrailer(Stream *str) { +int XRef::readTrailer() { Parser *parser; Object obj; char buf[xrefSearchSize+1]; @@ -166,7 +166,7 @@ int XRef::readTrailer(Stream *str) { // read trailer dict obj.initNull(); - parser = new Parser(new Lexer(str->subStream (start + pos1, -1, &obj))); + parser = new Parser(new Lexer(str->makeSubStream(start + pos1, -1, &obj))); parser->getObj(&trailerDict); if (trailerDict.isDict()) { trailerDict.dictLookupNF("Size", &obj); @@ -193,7 +193,7 @@ int XRef::readTrailer(Stream *str) { } // Read an xref table and the prev pointer from the trailer. -GBool XRef::readXRef(Stream *str, int *pos) { +GBool XRef::readXRef(int *pos) { Parser *parser; Object obj, obj2; char s[20]; @@ -258,7 +258,7 @@ GBool XRef::readXRef(Stream *str, int *pos) { // read prev pointer from trailer dictionary obj.initNull(); - parser = new Parser(new Lexer(str->subStream (str->getPos(), -1, &obj))); + parser = new Parser(new Lexer(str->makeSubStream(str->getPos(), -1, &obj))); parser->getObj(&obj); if (!obj.isCmd("trailer")) goto err1; @@ -287,7 +287,7 @@ GBool XRef::readXRef(Stream *str, int *pos) { } // Attempt to construct an xref table for a damaged file. -GBool XRef::constructXRef(Stream *str) { +GBool XRef::constructXRef() { Parser *parser; Object obj; char buf[256]; @@ -311,7 +311,8 @@ GBool XRef::constructXRef(Stream *str) { // got trailer dictionary if (!strncmp(p, "trailer", 7)) { obj.initNull(); - parser = new Parser(new Lexer(str->subStream(start + pos + 8, -1, &obj))); + parser = new Parser(new Lexer( + str->makeSubStream(start + pos + 8, -1, &obj))); if (!trailerDict.isNone()) trailerDict.free(); parser->getObj(&trailerDict); @@ -414,7 +415,8 @@ Object *XRef::fetch(int num, int gen, Object *obj) { e = &entries[num]; if (e->gen == gen && e->offset >= 0) { obj1.initNull(); - parser = new Parser(new Lexer(str->subStream(start + e->offset, -1, &obj1))); + parser = new Parser(new Lexer( + str->makeSubStream(start + e->offset, -1, &obj1))); parser->getObj(&obj1); parser->getObj(&obj2); parser->getObj(&obj3); diff --git a/pdf/xpdf/XRef.h b/pdf/xpdf/XRef.h index 7ef411dd..8e947e42 100644 --- a/pdf/xpdf/XRef.h +++ b/pdf/xpdf/XRef.h @@ -13,12 +13,11 @@ #pragma interface #endif -#include #include "gtypes.h" #include "Object.h" class Dict; -class FileStream; +class Stream; //------------------------------------------------------------------------ // XRef @@ -34,7 +33,7 @@ class XRef { public: // Constructor. Read xref table from stream. - XRef(Stream *str); + XRef(BaseStream *str); // Destructor. ~XRef(); @@ -60,7 +59,7 @@ public: private: - Stream *str; // input file + BaseStream *str; // input stream int start; // offset in file (to allow for garbage // at beginning of file) XRefEntry *entries; // xref entries @@ -69,9 +68,9 @@ private: GBool ok; // true if xref table is valid Object trailerDict; // trailer dictionary - int readTrailer(Stream *str); - GBool readXRef(Stream *str, int *pos); - GBool constructXRef(Stream *str); + int readTrailer(); + GBool readXRef(int *pos); + GBool constructXRef(); GBool checkEncrypted(); }; diff --git a/pdf/xpdf/bonobo-image-x-pdf.cc b/pdf/xpdf/bonobo-image-x-pdf.cc index 04c90521..3a36ecf8 100644 --- a/pdf/xpdf/bonobo-image-x-pdf.cc +++ b/pdf/xpdf/bonobo-image-x-pdf.cc @@ -229,6 +229,7 @@ load_image_from_stream (GnomePersistStream *ps, GNOME_Stream stream, void *data) #define CHUNK 512 FILE *hack; char *name; + Object obj; if (bed->pdf || bed->stream) { @@ -244,9 +245,9 @@ load_image_from_stream (GnomePersistStream *ps, GNOME_Stream stream, void *data) printf ("Loading PDF from persiststream\n"); #endif bed->stream = stream; - BonoboStream *bs = new BonoboStream (stream); - GString *st = new GString ("Bonobo.pdf"); - bed->pdf = new PDFDoc (bs, st); + obj.initNull(); + BonoboStream *bs = new BonoboStream (stream, 0, -1, &obj); + bed->pdf = new PDFDoc (bs); #if PDF_DEBUG > 0 printf ("Done load\n"); -- 2.43.5