Commit 457038e9 authored by Albert Astals Cid's avatar Albert Astals Cid

* poppler/Stream.h:

        * poppler/Stream.cc: Add MemStream::setNeedFree method
        * qt4/src/poppler-document.cc:
        * qt4/src/poppler-private.h:
        * qt4/src/poppler-qt4.h: Add Document::loadFromData method
parent 4e2a9c49
2007-01-13 Albert Astals Cid <aacid@kde.org>
* poppler/Stream.h:
* poppler/Stream.cc: Add MemStream::setNeedFree method
* qt4/src/poppler-document.cc:
* qt4/src/poppler-private.h:
* qt4/src/poppler-qt4.h: Add Document::loadFromData method
2007-01-11 Albert Astals Cid <aacid@kde.org>
* goo/gmem.c: Merge change from xpdf-3.01pl2
......
......@@ -806,6 +806,11 @@ void MemStream::doDecryption(Guchar *fileKey, int keyLength,
}
}
void MemStream::setNeedFree(GBool needsFree)
{
needFree = needsFree;
}
//------------------------------------------------------------------------
// EmbedStream
//------------------------------------------------------------------------
......
......@@ -318,6 +318,7 @@ public:
virtual void moveStart(int delta);
virtual void doDecryption(Guchar *fileKey, int keyLength,
int objNum, int objGen);
void setNeedFree(GBool needsFree);
private:
......
......@@ -49,6 +49,28 @@ namespace Poppler {
DocumentData *doc = new DocumentData(new GooString(QFile::encodeName(filePath)),
new GooString(ownerPassword.data()),
new GooString(userPassword.data()));
return checkDocument(doc);
}
Document *Document::loadFromData(const QByteArray &fileContents,
const QByteArray &ownerPassword,
const QByteArray &userPassword)
{
// create stream
Object obj;
obj.initNull();
char *data = (char*)gmalloc(fileContents.length());
memcpy(data, fileContents.data(), fileContents.length() * sizeof(char));
MemStream *str = new MemStream(data, 0, fileContents.length(), &obj);
str->setNeedFree(true);
DocumentData *doc = new DocumentData(str,
new GooString(ownerPassword.data()),
new GooString(userPassword.data()));
return checkDocument(doc);
}
Document *Document::checkDocument(DocumentData *doc)
{
Document *pdoc;
if (doc->doc.isOk() || doc->doc.getErrorCode() == errEncrypted) {
pdoc = new Document(doc);
......
......@@ -66,9 +66,22 @@ namespace Poppler {
class DocumentData {
public:
DocumentData(GooString *filePath, GooString *ownerPassword, GooString *userPassword) :
doc(filePath, ownerPassword, userPassword), m_fontInfoScanner(0),
m_backend(Document::SplashBackend), m_outputDev(0)
doc(filePath, ownerPassword, userPassword)
{
init(ownerPassword, userPassword);
}
DocumentData(MemStream *str, GooString *ownerPassword, GooString *userPassword) :
doc(str, ownerPassword, userPassword)
{
init(ownerPassword, userPassword);
}
void init(GooString *ownerPassword, GooString *userPassword)
{
m_fontInfoScanner = 0;
m_backend = Document::SplashBackend;
m_outputDev = 0;
paperColor = Qt::white;
// It might be more appropriate to delete these in PDFDoc
delete ownerPassword;
......
......@@ -441,6 +441,20 @@ namespace Poppler {
static Document *load(const QString & filePath,
const QByteArray &ownerPassword=QByteArray(),
const QByteArray &userPassword=QByteArray());
/**
Load the document from memory
\param fileContents the file contents. They are copied so there is no need
to keep the byte array around for the full life time of
the document.
\warning The application owns the pointer to Document, and this should
be deleted when no longer required.
*/
static Document *loadFromData(const QByteArray &fileContents,
const QByteArray &ownerPassword=QByteArray(),
const QByteArray &userPassword=QByteArray());
/**
Get a specified Page
......@@ -721,7 +735,9 @@ height = dummy.height();
private:
DocumentData *m_doc;
Document(DocumentData *dataA);
static Document *checkDocument(DocumentData *doc);
};
/**
......
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