Now we can compile but not run auxiliary utils.
+1999-08-19 Michael Meeks <michael@imaginator.com>
+
+ * PDFDoc.cc: Altered to read / write lines.
+
+ * PDFDoc.cc: Move FileStream::checkHeader so its called
+ in FileStream constructor.
+
1999-08-18 Michael Meeks <michael@imaginator.com>
* gpdf.cc: cloned from test-container.
gui = xpdf
endif
-#bin_PROGRAMS = pdftops pdftotext pdfinfo pdftopbm pdfimages $(gui) bonobo-image-x-pdf
-bin_PROGRAMS = bonobo-image-x-pdf gpdf
+bin_PROGRAMS = pdftops pdftotext pdfinfo pdftopbm pdfimages $(gui) bonobo-image-x-pdf
common_sources = \
Array.cc \
bonobo_image_x_pdf_SOURCES = \
$(common_sources) \
- BonoboFile.h \
- BonoboFile.cc \
+ BonoboStream.h \
+ BonoboStream.cc \
GOutputDev.cc \
bonobo-image-x-pdf.cc
#include "gtypes.h"
#include "gmem.h"
#include "GString.h"
-#include "BaseFile.h"
class Array;
class Dict;
char *streamGetLine(char *buf, int size);
int streamGetPos();
void streamSetPos(int pos);
- BaseFile streamGetFile();
+/* BaseFile streamGetFile();*/
Dict *streamGetDict();
// Output.
inline void Object::streamSetPos(int pos)
{ stream->setPos(pos); }
-inline BaseFile Object::streamGetFile()
- { return stream->getFile(); }
+/*inline BaseFile Object::streamGetFile()
+ { return stream->getFile(); }*/
inline Dict *Object::streamGetDict()
{ return stream->getDict(); }
// PDFDoc
//------------------------------------------------------------------------
-PDFDoc::PDFDoc(BaseFile file1, GString *fileName1) {
- FileStream *str;
+PDFDoc::PDFDoc(Stream *str1, GString *fileName1) {
Object catObj;
- Object obj;
// setup
ok = gFalse;
catalog = NULL;
xref = NULL;
- file = NULL;
links = NULL;
fileName = fileName1;
- file = file1;
- if (!file)
+ if (!str1)
return;
// create stream
- obj.initNull();
- str = new FileStream(file, 0, -1, &obj);
+/* obj.initNull(); */
+/* str = new FileStream(file, 0, -1, &obj); */
+ str = str1;
// check header
- str->checkHeader();
+/* str->checkHeader(); FIXME */
// read xref table
xref = new XRef(str);
- delete str;
+/* delete str; */
if (!xref->isOk()) {
error(-1, "Couldn't read xref table");
return;
delete catalog;
if (xref)
delete xref;
- if (file)
- bfclose(file);
+ if (str) {
+ delete (str);
+ str = NULL;
+ }
if (fileName)
delete fileName;
if (links)
error(-1, "Couldn't open file '%s'", name->getCString());
return gFalse;
}
- brewind(file);
- while ((n = bfread(buf, 1, sizeof(buf), file)) > 0)
- fwrite(buf, 1, n, f);
+ str->reset();
+ while (str->getLine (buf, 4096))
+ fputs (buf, f);
fclose(f);
return gTrue;
}
#include <stdio.h>
#include "Link.h"
-#include "BaseFile.h"
class GString;
class XRef;
class PDFDoc {
public:
- PDFDoc(BaseFile file, GString *fileName1);
+ PDFDoc(Stream *str1, GString *fileName1);
~PDFDoc();
// Was PDF document successfully opened?
void getLinks(int page);
GString *fileName;
- BaseFile file;
+ Stream *str;
XRef *xref;
Catalog *catalog;
Links *links;
}
// make base stream
- str = new FileStream(lexer->getStream()->getFile(), pos, length, dict);
+ str = lexer->getStream()->subStream (pos, length, dict);
// get filters
str = str->addFilters(dict);
// FileStream
//------------------------------------------------------------------------
-FileStream::FileStream(BaseFile f1, int start1, int length1, Object *dict1) {
+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;
+
+#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(FILE *f1) {
f = f1;
+ start = 0;
+ length = -1;
+ bufPtr = bufEnd = buf;
+ bufPos = start;
+ savePos = -1;
+ dict.initNull();
+ checkHeader();
+}
+
+Stream *FileStream::subStream (int start1, int length1, Object *dict1) {
start = start1;
length = length1;
bufPtr = bufEnd = buf;
FileStream::~FileStream() {
if (savePos >= 0)
- bfseek(f, savePos, SEEK_SET);
+ fseek(f, savePos, SEEK_SET);
dict.free();
}
void FileStream::reset() {
- savePos = (int)bftell(f);
- bfseek(f, start, SEEK_SET);
+ savePos = (int)ftell(f);
+ fseek(f, start, SEEK_SET);
bufPtr = bufEnd = buf;
bufPos = start;
}
n = start + length - bufPos;
else
n = 256;
- n = bfread(buf, 1, n, f);
+ n = fread(buf, 1, n, f);
bufEnd = buf + n;
if (bufPtr >= bufEnd)
return gFalse;
long size;
if (pos1 >= 0) {
- bfseek(f, pos1, SEEK_SET);
+ fseek(f, pos1, SEEK_SET);
bufPos = pos1;
} else {
- bfseek(f, 0, SEEK_END);
- size = bftell(f);
+ fseek(f, 0, SEEK_END);
+ size = ftell(f);
if (pos1 < -size)
pos1 = (int)(-size);
- bfseek(f, pos1, SEEK_END);
- bufPos = (int)bftell(f);
+ fseek(f, pos1, SEEK_END);
+ bufPos = (int)ftell(f);
}
bufPtr = bufEnd = buf;
}
-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;
-}
-
//------------------------------------------------------------------------
// SubStream
//------------------------------------------------------------------------
#include <stdio.h>
#include "gtypes.h"
#include "Object.h"
-#include "BaseFile.h"
//------------------------------------------------------------------------
// Get the base FileStream or SubStream of this stream.
virtual Stream *getBaseStream() = 0;
- // Get the base file of this stream.
- virtual BaseFile getFile() = 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;
// Get the dictionary associated with this stream.
virtual Dict *getDict() = 0;
// FileStream
//------------------------------------------------------------------------
+// Portable pdf open helper function.
+extern FILE *fileOpen (GString *fileName1);
+
class FileStream: public Stream {
public:
-
- FileStream(BaseFile f1, int start1, int length1, Object *dict1);
+ FileStream(FILE *f1);
virtual ~FileStream();
virtual StreamKind getKind() { return strFile; }
virtual void reset();
virtual void setPos(int pos1);
virtual GBool isBinary(GBool last = gTrue) { return last; }
virtual Stream *getBaseStream() { return this; }
- virtual BaseFile getFile() { return f; }
+ virtual Stream *subStream (int start1, int length1, Object *dict1);
+ virtual int getStart () { return start; }
virtual Dict *getDict() { return dict.getDict(); }
- // Check for a PDF header on this stream. Skip past some garbage
- // if necessary.
- GBool checkHeader();
-
- // Get position of first byte of stream within the file.
- int getStart() { return start; }
-
private:
GBool fillBuf();
+ GBool checkHeader();
- BaseFile f;
+ FILE *f;
int start;
int length;
char buf[256];
virtual int getPos() { return str->getPos(); }
virtual GBool isBinary(GBool last = gTrue) { return last; }
virtual Stream *getBaseStream() { return this; }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return dict.getDict(); }
private:
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
Stream *getRawStream() { return str; }
virtual GString *getPSFilter(char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent) { return NULL; }
virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
private:
virtual GString *getPSFilter(char *indent) { return NULL; }
virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
virtual GBool isEncoder() { return gTrue; }
virtual GString *getPSFilter(char *indent) { return NULL; }
virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
virtual GBool isEncoder() { return gTrue; }
virtual GString *getPSFilter(char *indent) { return NULL; }
virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
virtual Stream *getBaseStream() { return str->getBaseStream(); }
- virtual BaseFile getFile() { return str->getFile(); }
+ virtual Stream *subStream (int start1, int length1, Object *dict1)
+ { return str->subStream (start1, length1, dict1); }
+ virtual int getStart () { return str->getStart (); }
virtual Dict *getDict() { return str->getDict(); }
virtual GBool isEncoder() { return gTrue; }
// XRef
//------------------------------------------------------------------------
-XRef::XRef(FileStream *str) {
+XRef::XRef(Stream *str1) {
XRef *oldXref;
int pos;
int i;
xref = NULL;
// read the trailer
- file = str->getFile();
+ str = str1;
start = str->getStart();
pos = readTrailer(str);
// Read startxref position, xref table size, and root. Returns
// first xref position.
-int XRef::readTrailer(FileStream *str) {
+int XRef::readTrailer(Stream *str) {
Parser *parser;
Object obj;
char buf[xrefSearchSize+1];
// read trailer dict
obj.initNull();
- parser = new Parser(new Lexer(new FileStream(file, start + pos1, -1, &obj)));
+ parser = new Parser(new Lexer(str->subStream (start + pos1, -1, &obj)));
parser->getObj(&trailerDict);
if (trailerDict.isDict()) {
trailerDict.dictLookupNF("Size", &obj);
}
// Read an xref table and the prev pointer from the trailer.
-GBool XRef::readXRef(FileStream *str, int *pos) {
+GBool XRef::readXRef(Stream *str, int *pos) {
Parser *parser;
Object obj, obj2;
char s[20];
// read prev pointer from trailer dictionary
obj.initNull();
- parser = new Parser(new Lexer(
- new FileStream(file, str->getPos(), -1, &obj)));
+ parser = new Parser(new Lexer(str->subStream (str->getPos(), -1, &obj)));
parser->getObj(&obj);
if (!obj.isCmd("trailer"))
goto err1;
}
// Attempt to construct an xref table for a damaged file.
-GBool XRef::constructXRef(FileStream *str) {
+GBool XRef::constructXRef(Stream *str) {
Parser *parser;
Object obj;
char buf[256];
// got trailer dictionary
if (!strncmp(p, "trailer", 7)) {
obj.initNull();
- parser = new Parser(new Lexer(
- new FileStream(file, start + pos + 8, -1, &obj)));
+ parser = new Parser(new Lexer(str->subStream(start + pos + 8, -1, &obj)));
if (!trailerDict.isNone())
trailerDict.free();
parser->getObj(&trailerDict);
e = &entries[num];
if (e->gen == gen && e->offset >= 0) {
obj1.initNull();
- parser = new Parser(new Lexer(
- new FileStream(file, start + e->offset, -1, &obj1)));
+ parser = new Parser(new Lexer(str->subStream(start + e->offset, -1, &obj1)));
parser->getObj(&obj1);
parser->getObj(&obj2);
parser->getObj(&obj3);
#include <stdio.h>
#include "gtypes.h"
#include "Object.h"
-#include "BaseFile.h"
class Dict;
class FileStream;
public:
// Constructor. Read xref table from stream.
- XRef(FileStream *str);
+ XRef(Stream *str);
// Destructor.
~XRef();
private:
- BaseFile file; // input file
+ Stream *str; // input file
int start; // offset in file (to allow for garbage
// at beginning of file)
XRefEntry *entries; // xref entries
GBool ok; // true if xref table is valid
Object trailerDict; // trailer dictionary
- int readTrailer(FileStream *str);
- GBool readXRef(FileStream *str, int *pos);
- GBool constructXRef(FileStream *str);
+ int readTrailer(Stream *str);
+ GBool readXRef(Stream *str, int *pos);
+ GBool constructXRef(Stream *str);
GBool checkEncrypted();
};
#include "Params.h"
#include "Error.h"
#include "config.h"
+#include "BonoboStream.h"
GBool printCommands = gFalse;
printf ("Loading PDF from persiststream\n");
bonobo_object_data->stream = stream;
- bonobo_object_data->pdf = new PDFDoc (stream, new GString ("Bonobo.pdf"));
+ bonobo_object_data->pdf = new PDFDoc (new BonoboStream (stream),
+ new GString ("Bonobo.pdf"));
printf ("Done load\n");
if (!(bonobo_object_data->pdf->isOk())) {
g_warning ("Duff pdf data\n");
// open PDF fihe
xref = NULL;
- doc = new PDFDoc(bxpdfopen(fileName), fileName);
+ doc = new PDFDoc(new FileStream(fileOpen(fileName)), fileName);
if (!doc->isOk()) {
goto err1;
}
// open PDF file
xref = NULL;
- doc = new PDFDoc(bxpdfopen(fileName), fileName);
+ doc = new PDFDoc(new FileStream(fileOpen(fileName)), fileName);
if (!doc->isOk())
exit(1);
// open PDF file
xref = NULL;
- doc = new PDFDoc(bxpdfopen(fileName), fileName);
+ doc = new PDFDoc(new FileStream (fileOpen (fileName)), fileName);
if (!doc->isOk())
exit(1);
PDFDoc *doc;
GString *fileName;
GString *psFileName;
+ FILE *file;
PSOutputDev *psOut;
GBool ok;
char *p;
// open PDF file
xref = NULL;
- doc = new PDFDoc(bxpdfopen(fileName), fileName);
+ doc = new PDFDoc(new FileStream (fileOpen (fileName)), fileName);
if (!doc->isOk()) {
goto err1;
}
// open PDF file
xref = NULL;
- doc = new PDFDoc(bxpdfopen(fileName), fileName);
+ doc = new PDFDoc(new FileStream (fileOpen(fileName)), fileName);
if (!doc->isOk()) {
goto err1;
}