Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv29307/qt4/src

Modified Files:
        poppler-document.cc poppler-private.h poppler-qt4.h 
Log Message:
        * 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


Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-document.cc,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- poppler-document.cc 30 Dec 2006 14:50:25 -0000      1.27
+++ poppler-document.cc 13 Jan 2007 17:56:07 -0000      1.28
@@ -49,6 +49,28 @@
        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);

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-private.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- poppler-private.h   4 Jan 2007 19:10:16 -0000       1.16
+++ poppler-private.h   13 Jan 2007 17:56:07 -0000      1.17
@@ -66,9 +66,22 @@
     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;

Index: poppler-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- poppler-qt4.h       30 Dec 2006 14:50:25 -0000      1.42
+++ poppler-qt4.h       13 Jan 2007 17:56:07 -0000      1.43
@@ -441,6 +441,20 @@
        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 @@
   
     private:
        DocumentData *m_doc;
+       
        Document(DocumentData *dataA);
+       static Document *checkDocument(DocumentData *doc);
     };
 
     /**

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to