Commit db62e07f authored by Marco Pesenti Gritti's avatar Marco Pesenti Gritti

2005-09-16 Marco Pesenti Gritti <mpg@redhat.com>

        * poppler/PDFDoc.cc:
        * poppler/PDFDoc.h:
        * poppler/XRef.cc:
        * poppler/XRef.h:

        Merge more from 3.01
parent 3acc7be5
......@@ -46,13 +46,15 @@
//------------------------------------------------------------------------
PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
GooString *userPassword) {
GooString *userPassword, void *guiDataA) {
Object obj;
GooString *fileName1, *fileName2;
ok = gFalse;
errCode = errNone;
guiData = guiDataA;
file = NULL;
str = NULL;
xref = NULL;
......@@ -99,9 +101,10 @@ PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
}
PDFDoc::PDFDoc(BaseStream *strA, GooString *ownerPassword,
GooString *userPassword) {
GooString *userPassword, void *guiDataA) {
ok = gFalse;
errCode = errNone;
guiData = guiDataA;
fileName = NULL;
file = NULL;
str = strA;
......@@ -124,13 +127,19 @@ GBool PDFDoc::setup(GooString *ownerPassword, GooString *userPassword) {
checkHeader();
// read xref table
xref = new XRef(str, ownerPassword, userPassword);
xref = new XRef(str);
if (!xref->isOk()) {
error(-1, "Couldn't read xref table");
errCode = xref->getErrorCode();
return gFalse;
}
// check for encryption
if (!checkEncryption(ownerPassword, userPassword)) {
errCode = errEncrypted;
return gFalse;
}
// read catalog
catalog = new Catalog(xref);
if (!catalog->isOk()) {
......@@ -232,7 +241,10 @@ void PDFDoc::checkHeader() {
return;
}
str->moveStart(i);
p = strtok(&hdrBuf[i+5], " \t\n\r");
if (!(p = strtok(&hdrBuf[i+5], " \t\n\r"))) {
error(-1, "May not be a PDF file (continuing anyway)");
return;
}
{
char *theLocale = setlocale(LC_NUMERIC, "C");
pdfVersion = atof(p);
......
......@@ -15,7 +15,6 @@
#include <stdio.h>
#include "XRef.h"
#include "Link.h"
#include "Catalog.h"
#include "Page.h"
#include "Annot.h"
......@@ -36,9 +35,9 @@ class PDFDoc {
public:
PDFDoc(GooString *fileNameA, GooString *ownerPassword = NULL,
GooString *userPassword = NULL);
GooString *userPassword = NULL, void *guiDataA = NULL);
PDFDoc(BaseStream *strA, GooString *ownerPassword = NULL,
GooString *userPassword = NULL);
GooString *userPassword = NULL, void *guiDataA = NULL);
~PDFDoc();
// Was PDF document successfully opened?
......@@ -108,13 +107,9 @@ public:
// not found.
int findPage(int num, int gen) { return catalog->findPage(num, gen); }
// If point <x>,<y> is in a link, return the associated action;
// else return NULL.
LinkAction *findLink(double x, double y)
{ return links ? links->find(x, y) : (LinkAction *)NULL; }
// Return true if <x>,<y> is in a link.
GBool onLink(double x, double y) { return links->onLink(x, y); }
// Returns the links for the current page, transferring ownership to
// the caller.
Links *takeLinks();
// Find a named destination. Returns the link destination, or
// NULL if <name> is not a destination.
......@@ -161,6 +156,9 @@ public:
// Save this file with another name.
GBool saveAs(GooString *name);
// Return a pointer to the GUI (XPDFCore or WinPDFCore object).
void *getGUIData() { return guiData; }
private:
GBool setup(GooString *ownerPassword, GooString *userPassword);
......@@ -172,6 +170,7 @@ private:
GooString *fileName;
FILE *file;
BaseStream *str;
void *guiData;
double pdfVersion;
XRef *xref;
Catalog *catalog;
......
......@@ -201,7 +201,7 @@ Object *ObjectStream::getObject(int objIdx, int objNum, Object *obj) {
// XRef
//------------------------------------------------------------------------
XRef::XRef(BaseStream *strA, GooString *ownerPassword, GooString *userPassword) {
XRef::XRef(BaseStream *strA) {
Guint pos;
Object obj;
......@@ -217,6 +217,10 @@ XRef::XRef(BaseStream *strA, GooString *ownerPassword, GooString *userPassword)
permFlags = defPermFlags;
ownerPasswordOk = gFalse;
encrypted = gFalse;
permFlags = defPermFlags;
ownerPasswordOk = gFalse;
// read the trailer
str = strA;
start = str->getStart();
......@@ -466,6 +470,7 @@ GBool XRef::readXRefTable(Parser *parser, Guint *pos) {
pos2 = (Guint)obj2.getInt();
readXRef(&pos2);
if (!ok) {
obj2.free();
goto err1;
}
}
......@@ -686,7 +691,7 @@ GBool XRef::constructXRef() {
obj.initNull();
parser = new Parser(NULL,
new Lexer(NULL,
str->makeSubStream(start + pos + 7, gFalse, 0, &obj)));
str->makeSubStream(pos + 7, gFalse, 0, &obj)));
parser->getObj(&newTrailerDict);
if (newTrailerDict.isDict()) {
newTrailerDict.dictLookupNF("Root", &obj);
......@@ -865,6 +870,10 @@ Object *XRef::fetch(int num, int gen, Object *obj) {
if (!obj1.isInt() || obj1.getInt() != num ||
!obj2.isInt() || obj2.getInt() != gen ||
!obj3.isCmd("obj")) {
obj1.free();
obj2.free();
obj3.free();
delete parser;
goto err;
}
parser->getObj(obj, encrypted ? fileKey : (Guchar *)NULL, keyLength,
......
......@@ -41,7 +41,7 @@ class XRef {
public:
// Constructor. Read xref table from stream.
XRef(BaseStream *strA, GooString *ownerPassword, GooString *userPassword);
XRef(BaseStream *strA);
// Destructor.
~XRef();
......@@ -57,6 +57,10 @@ public:
Guchar *fileKeyA, int keyLengthA,
int encVersionA, int encRevisionA);
// Set the encryption parameters.
void setEncryption(int permFlagsA, GBool ownerPasswordOkA,
Guchar *fileKeyA, int keyLengthA, int encVersionA);
// Is the file encrypted?
GBool isEncrypted() { return encrypted; }
......@@ -129,7 +133,6 @@ private:
GBool readXRefStreamSection(Stream *xrefStr, int *w, int first, int n);
GBool readXRefStream(Stream *xrefStr, Guint *pos);
GBool constructXRef();
GBool checkEncrypted(GooString *ownerPassword, GooString *userPassword);
Guint strToUnsigned(char *s);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment