[poppler] 2 commits - cpp/poppler-document.cpp cpp/poppler-document.h cpp/poppler-document-private.h

Pino Toscano pino at kemper.freedesktop.org
Wed Sep 22 17:22:21 PDT 2010


 cpp/poppler-document-private.h |    5 +++
 cpp/poppler-document.cpp       |   57 +++++++++++++++++++++++++++++++++++++++--
 cpp/poppler-document.h         |    4 ++
 3 files changed, 64 insertions(+), 2 deletions(-)

New commits:
commit 4ffc0ed73397e4e58f04c3577b093a3fd39c22bd
Author: Pino Toscano <pino at kde.org>
Date:   Thu Sep 23 02:21:12 2010 +0200

    [cpp] small clarification in document::load_from_data() apidox

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 77b653d..19f8d1f 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -607,12 +607,12 @@ document* document::load_from_file(const std::string &file_name,
 }
 
 /**
- Tries to load a PDF %document from the specified file.
+ Tries to load a PDF %document from the specified data.
 
  \note if the loading succeeds, the document takes ownership of the
        \p file_data (swap()ing it)
 
- \param file_data the file to open
+ \param file_data the data representing a document to open
  \returns a new document if the load succeeded (even if the document is locked),
           NULL otherwise
  */
commit 9491dc4a10706109d0f2b4d15f21b9a1db51d8c9
Author: Pino Toscano <pino at kde.org>
Date:   Thu Sep 23 02:18:07 2010 +0200

    [cpp] add document::load_from_raw_data()
    
    ... to be able to load a document from an external data buffer,
    with no need to copy the data.
    
    add as well a new document_private constructor to handle the new situation,
    and make sure to properly use the raw data when unlocking the document

diff --git a/cpp/poppler-document-private.h b/cpp/poppler-document-private.h
index 54deeb9..f78e57c 100644
--- a/cpp/poppler-document-private.h
+++ b/cpp/poppler-document-private.h
@@ -40,12 +40,17 @@ public:
                      const std::string &user_password);
     document_private(byte_array *file_data, const std::string &owner_password,
                      const std::string &user_password);
+    document_private(const char *file_data, int file_data_length,
+                     const std::string &owner_password,
+                     const std::string &user_password);
     ~document_private();
 
     static document* check_document(document_private *doc, byte_array *file_data);
 
     PDFDoc *doc;
     byte_array doc_data;
+    const char *raw_doc_data;
+    int raw_doc_data_length;
     bool is_locked;
     std::vector<embedded_file *> embedded_files;
 
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index beebff5..77b653d 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -41,6 +41,8 @@ unsigned int poppler::document_private::count = 0U;
 document_private::document_private(GooString *file_path, const std::string &owner_password,
                                    const std::string &user_password)
     : doc(0)
+    , raw_doc_data(0)
+    , raw_doc_data_length(0)
     , is_locked(false)
 {
     GooString goo_owner_password(owner_password.c_str());
@@ -53,6 +55,8 @@ document_private::document_private(byte_array *file_data,
                                    const std::string &owner_password,
                                    const std::string &user_password)
     : doc(0)
+    , raw_doc_data(0)
+    , raw_doc_data_length(0)
     , is_locked(false)
 {
     Object obj;
@@ -65,6 +69,23 @@ document_private::document_private(byte_array *file_data,
     init();
 }
 
+document_private::document_private(const char *file_data, int file_data_length,
+                                   const std::string &owner_password,
+                                   const std::string &user_password)
+    : doc(0)
+    , raw_doc_data(file_data)
+    , raw_doc_data_length(file_data_length)
+    , is_locked(false)
+{
+    Object obj;
+    obj.initNull();
+    MemStream *memstr = new MemStream(const_cast<char *>(raw_doc_data), 0, raw_doc_data_length, &obj);
+    GooString goo_owner_password(owner_password.c_str());
+    GooString goo_user_password(user_password.c_str());
+    doc = new PDFDoc(memstr, &goo_owner_password, &goo_user_password);
+    init();
+}
+
 document_private::~document_private()
 {
     delete_all(embedded_files);
@@ -182,6 +203,9 @@ bool document::unlock(const std::string &owner_password, const std::string &user
         if (d->doc_data.size() > 0) {
             newdoc = new document_private(&d->doc_data,
                                           owner_password, user_password);
+        } else if (d->raw_doc_data) {
+            newdoc = new document_private(d->raw_doc_data, d->raw_doc_data_length,
+                                          owner_password, user_password);
         } else {
             newdoc = new document_private(new GooString(d->doc->getFileName()),
                                           owner_password, user_password);
@@ -604,3 +628,32 @@ document* document::load_from_data(byte_array *file_data,
                                 file_data, owner_password, user_password);
     return document_private::check_document(doc, file_data);
 }
+
+/**
+ Tries to load a PDF %document from the specified data buffer.
+
+ \note the buffer must remain valid for the whole lifetime of the returned
+       document
+
+ \param file_data the data buffer representing a document to open
+ \param file_data_length the length of the data buffer
+
+ \returns a new document if the load succeeded (even if the document is locked),
+          NULL otherwise
+
+ \since 0.16
+ */
+document* document::load_from_raw_data(const char *file_data,
+                                       int file_data_length,
+                                       const std::string &owner_password,
+                                       const std::string &user_password)
+{
+    if (!file_data || file_data_length < 10) {
+        return 0;
+    }
+
+    document_private *doc = new document_private(
+                                file_data, file_data_length,
+                                owner_password, user_password);
+    return document_private::check_document(doc, 0);
+}
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 9ae56fd..dfae398 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -87,6 +87,10 @@ public:
     static document* load_from_data(byte_array *file_data,
                                     const std::string &owner_password = std::string(),
                                     const std::string &user_password = std::string());
+    static document* load_from_raw_data(const char *file_data,
+                                        int file_data_length,
+                                        const std::string &owner_password = std::string(),
+                                        const std::string &user_password = std::string());
 
 private:
     document(document_private &dd);


More information about the poppler mailing list