[poppler] Branch 'cpp-frontend' - 11 commits - cpp/CMakeLists.txt cpp/Makefile.am cpp/poppler-document.cpp cpp/poppler-document.h cpp/poppler-document-private.h cpp/poppler-embedded-file.cpp cpp/poppler-embedded-file.h cpp/poppler-global.cpp cpp/poppler-global.h cpp/poppler-private.cpp cpp/poppler-rectangle.cpp cpp/poppler-rectangle.h cpp/poppler-version.cpp

Pino Toscano pino at kemper.freedesktop.org
Mon Dec 14 14:57:43 PST 2009


 cpp/CMakeLists.txt             |    1 
 cpp/Makefile.am                |    1 
 cpp/poppler-document-private.h |    5 ++
 cpp/poppler-document.cpp       |   77 ++++++++++++++++++++++++++++++++++++++++-
 cpp/poppler-document.h         |   11 ++++-
 cpp/poppler-embedded-file.cpp  |    6 +--
 cpp/poppler-embedded-file.h    |    2 -
 cpp/poppler-global.cpp         |   37 ++++++++++++++-----
 cpp/poppler-global.h           |   12 +++++-
 cpp/poppler-private.cpp        |    5 +-
 cpp/poppler-rectangle.cpp      |   35 ++++++++++++++++++
 cpp/poppler-rectangle.h        |    8 +++-
 cpp/poppler-version.cpp        |    8 ++--
 13 files changed, 182 insertions(+), 26 deletions(-)

New commits:
commit 9bb90c99b65e0e9d9b65c7dbeb5b4d66377ceb21
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 23:43:12 2009 +0100

    [cpp] add destructor for 'rectangle'

diff --git a/cpp/poppler-rectangle.h b/cpp/poppler-rectangle.h
index a2b7c10..18674b2 100644
--- a/cpp/poppler-rectangle.h
+++ b/cpp/poppler-rectangle.h
@@ -33,7 +33,8 @@ public:
     rectangle(T _x, T _y, T w, T h)
         : x1(_x), y1(_y), x2(x1 + w), y2(y1 + h)
     {}
-    ~rectangle();
+    ~rectangle()
+    {}
 
     bool is_empty() const
     { return (x1 == x2) && (y1 == y2); }
commit 61ccdc9ab3b816174896fcae0899ff34f11eee80
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 23:40:51 2009 +0100

    [cpp] add out stream operators for rect and rectf

diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 3f8e9d9..0a0c6f0 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -13,6 +13,7 @@ set(poppler_cpp_SRCS
   poppler-page.cpp
   poppler-page-transition.cpp
   poppler-private.cpp
+  poppler-rectangle.cpp
   poppler-toc.cpp
   poppler-version.cpp
 )
diff --git a/cpp/Makefile.am b/cpp/Makefile.am
index b6c2d8e..6259770 100644
--- a/cpp/Makefile.am
+++ b/cpp/Makefile.am
@@ -25,6 +25,7 @@ libpoppler_cpp_la_SOURCES =			\
 	poppler-page.cpp			\
 	poppler-page-transition.cpp		\
 	poppler-private.cpp			\
+	poppler-rectangle.cpp			\
 	poppler-toc.cpp				\
 	poppler-version.cpp
 
diff --git a/cpp/poppler-rectangle.cpp b/cpp/poppler-rectangle.cpp
new file mode 100644
index 0000000..57fd859
--- /dev/null
+++ b/cpp/poppler-rectangle.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009, Pino Toscano <pino at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "poppler-rectangle.h"
+
+#include <iostream>
+
+using namespace poppler;
+
+std::ostream& poppler::operator<<(std::ostream& stream, const rect &r)
+{
+    stream << "[" << r.x() << "," << r.y() << " " << r.width() << "+" << r.height() << "]";
+    return stream;
+}
+
+std::ostream& poppler::operator<<(std::ostream& stream, const rectf &r)
+{
+    stream << "[" << r.x() << "," << r.y() << " " << r.width() << "+" << r.height() << "]";
+    return stream;
+}
diff --git a/cpp/poppler-rectangle.h b/cpp/poppler-rectangle.h
index 7465edc..a2b7c10 100644
--- a/cpp/poppler-rectangle.h
+++ b/cpp/poppler-rectangle.h
@@ -19,6 +19,8 @@
 #ifndef POPPLER_RECTANGLE_H
 #define POPPLER_RECTANGLE_H
 
+#include "poppler-global.h"
+
 namespace poppler
 {
 
@@ -55,6 +57,9 @@ private:
 typedef rectangle<int> rect;
 typedef rectangle<double> rectf;
 
+POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const rect &r);
+POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const rectf &r);
+
 }
 
 #endif
commit 69dd51fed3de41f8b799b811ae5ee59c0d5f59c2
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 22:24:07 2009 +0100

    [cpp] add namespace to namespace functiond to link properly

diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index 9ce7641..cc52b55 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -133,7 +133,7 @@ ustring ustring::from_latin1(const std::string &str)
 }
 
 
-unsigned int convert_date(const std::string &date)
+unsigned int poppler::convert_date(const std::string &date)
 {
     int year, mon, day, hour, min, sec, tzHours, tzMins;
     char tz;
@@ -156,7 +156,7 @@ unsigned int convert_date(const std::string &date)
     return mktime(&time);
 }
 
-std::ostream& operator<<(std::ostream& stream, const byte_array &array)
+std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array)
 {
     stream << "[";
     const std::ios_base::fmtflags f = stream.flags();
diff --git a/cpp/poppler-version.cpp b/cpp/poppler-version.cpp
index 89f95a3..b39af53 100644
--- a/cpp/poppler-version.cpp
+++ b/cpp/poppler-version.cpp
@@ -20,22 +20,22 @@
 
 using namespace poppler;
 
-std::string version_string()
+std::string poppler::version_string()
 {
     return std::string(POPPLER_VERSION);
 }
 
-unsigned int version_major()
+unsigned int poppler::version_major()
 {
     return POPPLER_VERSION_MAJOR;
 }
 
-unsigned int version_minor()
+unsigned int poppler::version_minor()
 {
     return POPPLER_VERSION_MINOR;
 }
 
-unsigned int version_micro()
+unsigned int poppler::version_micro()
 {
     return POPPLER_VERSION_MICRO;
 }
commit 3923fa4890984d8616d86016f4f4a94e8ef3e992
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 22:23:15 2009 +0100

    [cpp] add default empty parameters for the passwords of the document loading functions

diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index ab6eb27..5d394bb 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -81,11 +81,11 @@ public:
     std::vector<embedded_file *> embedded_files() const;
 
     static document* load_from_file(const std::string &file_name,
-                                    const std::string &owner_password,
-                                    const std::string &user_password);
+                                    const std::string &owner_password = std::string(),
+                                    const std::string &user_password = std::string());
     static document* load_from_data(byte_array *file_data,
-                                    const std::string &owner_password,
-                                    const std::string &user_password);
+                                    const std::string &owner_password = std::string(),
+                                    const std::string &user_password = std::string());
 
 private:
     document(document_private &dd);
commit 1d23cc677e9b0a9f61c53e0ea365537f33abe5bf
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 21:44:56 2009 +0100

    [cpp] add "human friendly" output representation for byte_array

diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index cc15bce..9ce7641 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -22,6 +22,7 @@
 
 #include <ctime>
 #include <cstring>
+#include <iostream>
 
 using namespace poppler;
 
@@ -154,3 +155,25 @@ unsigned int convert_date(const std::string &date)
     time.tm_isdst = -1;
     return mktime(&time);
 }
+
+std::ostream& operator<<(std::ostream& stream, const byte_array &array)
+{
+    stream << "[";
+    const std::ios_base::fmtflags f = stream.flags();
+    std::hex(stream);
+    const char *data = array.data();
+    const byte_array::size_type out_len = std::min<byte_array::size_type>(array.size(), 50);
+    for (byte_array::size_type i = 0; i < out_len; ++i)
+    {
+        if (i != 0) {
+            stream << " ";
+        }
+        stream << ((data[i] & 0xf0) >> 4) << (data[i] & 0xf);
+    }
+    stream.flags(f);
+    if (out_len < array.size()) {
+        stream << " ...";
+    }
+    stream << "]";
+    return stream;
+}
diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h
index da7c295..4b08e8d 100644
--- a/cpp/poppler-global.h
+++ b/cpp/poppler-global.h
@@ -33,6 +33,7 @@
 #  define POPPLER_CPP_EXPORT LIB_IMPORT
 #endif
 
+#include <iosfwd>
 #include <string>
 #include <vector>
 
@@ -88,6 +89,8 @@ private:
 
 POPPLER_CPP_EXPORT unsigned int /*time_t*/ convert_date(const std::string &date);
 
+POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const byte_array &array);
+
 }
 
 #endif
commit a337c1d757d52c1c238229d2f0cd3a41694b0e08
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 16:18:22 2009 +0100

    [cpp] add document metadata reading

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index ab14bf9..0ff526f 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -294,6 +294,15 @@ bool document::has_permission(permission_enum which) const
     return true;
 }
 
+ustring document::metadata() const
+{
+    std::auto_ptr<GooString> md(d->doc->getCatalog()->readMetadata());
+    if (md.get()) {
+        return detail::unicode_GooString_to_ustring(md.get());
+    }
+    return ustring();
+}
+
 int document::pages() const
 {
     return d->doc->getNumPages();
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 66abe87..ab6eb27 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -66,6 +66,7 @@ public:
     bool is_encrypted() const;
     bool is_linearized() const;
     bool has_permission(permission_enum which) const;
+    ustring metadata() const;
 
     int pages() const;
     page* create_page(const ustring &label) const;
commit c9cb6353ad5279d09615eb2c944b2b053cdf5ccc
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 15:52:25 2009 +0100

    [cpp] add function to query for document "permissions"

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 908d4d2..ab14bf9 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -271,6 +271,29 @@ bool document::is_linearized() const
     return d->doc->isLinearized();
 }
 
+bool document::has_permission(permission_enum which) const
+{
+    switch (which) {
+    case perm_print:
+        return d->doc->okToPrint();
+    case perm_change:
+        return d->doc->okToChange();
+    case perm_copy:
+        return d->doc->okToCopy();
+    case perm_add_notes:
+        return d->doc->okToAddNotes();
+    case perm_fill_forms:
+        return d->doc->okToFillForm();
+    case perm_accessibility:
+        return d->doc->okToAccessibility();
+    case perm_assemble:
+        return d->doc->okToAssemble();
+    case perm_print_high_resolution:
+        return d->doc->okToPrintHighRes();
+    }
+    return true;
+}
+
 int document::pages() const
 {
     return d->doc->getNumPages();
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index cc3c10d..66abe87 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -65,6 +65,7 @@ public:
     unsigned int /*time_t*/ info_date(const std::string &key) const;
     bool is_encrypted() const;
     bool is_linearized() const;
+    bool has_permission(permission_enum which) const;
 
     int pages() const;
     page* create_page(const ustring &label) const;
diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h
index a6a9146..da7c295 100644
--- a/cpp/poppler-global.h
+++ b/cpp/poppler-global.h
@@ -60,6 +60,10 @@ enum rotation_enum { rotate_0, rotate_90, rotate_180, rotate_270 };
 
 enum page_box_enum { media_box, crop_box, bleed_box, trim_box, art_box };
 
+enum permission_enum { perm_print, perm_change, perm_copy, perm_add_notes,
+                       perm_fill_forms, perm_accessibility, perm_assemble,
+                       perm_print_high_resolution };
+
 typedef std::vector<char> byte_array;
 
 class POPPLER_CPP_EXPORT ustring : public std::basic_string<unsigned short>
commit 30e90c7c1b41c62ddc21905e7ccdea4c95547e80
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 15:33:36 2009 +0100

    [cpp] add is_encrypted and is_linearized for document

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index d1bc026..908d4d2 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -261,6 +261,16 @@ unsigned int document::info_date(const std::string &key) const
     return result;
 }
 
+bool document::is_encrypted() const
+{
+    return d->doc->isEncrypted();
+}
+
+bool document::is_linearized() const
+{
+    return d->doc->isLinearized();
+}
+
 int document::pages() const
 {
     return d->doc->getNumPages();
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 213a81a..cc3c10d 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -63,6 +63,8 @@ public:
     std::vector<std::string> info_keys() const;
     ustring info_key(const std::string &key) const;
     unsigned int /*time_t*/ info_date(const std::string &key) const;
+    bool is_encrypted() const;
+    bool is_linearized() const;
 
     int pages() const;
     page* create_page(const ustring &label) const;
commit 93fd588c519958a1f66231c111ea8a6b0a759be1
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 13:19:24 2009 +0100

    [cpp] add the possibility to load a document from raw data

diff --git a/cpp/poppler-document-private.h b/cpp/poppler-document-private.h
index 52ed935..9820603 100644
--- a/cpp/poppler-document-private.h
+++ b/cpp/poppler-document-private.h
@@ -19,6 +19,8 @@
 #ifndef POPPLER_DOCUMENT_PRIVATE_H
 #define POPPLER_DOCUMENT_PRIVATE_H
 
+#include "poppler-global.h"
+
 #include "poppler-config.h"
 #include "GooString.h"
 #include "PDFDoc.h"
@@ -36,11 +38,14 @@ class document_private
 public:
     document_private(GooString *file_path, const std::string &owner_password,
                      const std::string &user_password);
+    document_private(byte_array *file_data, const std::string &owner_password,
+                     const std::string &user_password);
     ~document_private();
 
     static document* check_document(document_private *doc);
 
     PDFDoc *doc;
+    byte_array doc_data;
     bool is_locked;
     std::vector<embedded_file *> embedded_files;
 
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 46f52b9..d1bc026 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -49,6 +49,22 @@ document_private::document_private(GooString *file_path, const std::string &owne
     init();
 }
 
+document_private::document_private(byte_array *file_data,
+                                   const std::string &owner_password,
+                                   const std::string &user_password)
+    : doc(0)
+    , is_locked(false)
+{
+    Object obj;
+    obj.initNull();
+    file_data->swap(doc_data);
+    MemStream *memstr = new MemStream(doc_data.data(), 0, doc_data.size(), &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);
@@ -106,11 +122,15 @@ bool document::unlock(const std::string &owner_password, const std::string &user
 {
     if (d->is_locked) {
         document_private *newdoc = 0;
-        {
+        if (d->doc_data.size() > 0) {
+            newdoc = new document_private(&d->doc_data,
+                                          owner_password, user_password);
+        } else {
             newdoc = new document_private(new GooString(d->doc->getFileName()),
                                           owner_password, user_password);
         }
         if (!newdoc->doc->isOk()) {
+            d->doc_data.swap(newdoc->doc_data);
             delete newdoc;
         } else {
             delete d;
@@ -314,3 +334,16 @@ document* document::load_from_file(const std::string &file_name,
                                 owner_password, user_password);
     return document_private::check_document(doc);
 }
+
+document* document::load_from_data(byte_array *file_data,
+                                   const std::string &owner_password,
+                                   const std::string &user_password)
+{
+    if (!file_data || file_data->size() < 10) {
+        return 0;
+    }
+
+    document_private *doc = new document_private(
+                                file_data, owner_password, user_password);
+    return document_private::check_document(doc);
+}
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 7ff4337..213a81a 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -79,6 +79,9 @@ public:
     static document* load_from_file(const std::string &file_name,
                                     const std::string &owner_password,
                                     const std::string &user_password);
+    static document* load_from_data(byte_array *file_data,
+                                    const std::string &owner_password,
+                                    const std::string &user_password);
 
 private:
     document(document_private &dd);
commit 53996365b159cf84adf2cac56c76b8bda8dfb12e
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 12:57:41 2009 +0100

    [cpp] use the byte_array typedef

diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index 487b32d..6dfe321 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -93,15 +93,15 @@ std::string embedded_file::mime_type() const
     return std::string(d->emb_file->mimeType()->getCString());
 }
 
-std::vector<char> embedded_file::data() const
+byte_array embedded_file::data() const
 {
     if (!is_valid()) {
-        return std::vector<char>();
+        return byte_array();
     }
 
     Stream *stream = d->emb_file->streamObject().getStream();
     stream->reset();
-    std::vector<char> ret(1024);
+    byte_array ret(1024);
     size_t data_len = 0;
     int i;
     while ((i = stream->getChar()) != EOF) {
diff --git a/cpp/poppler-embedded-file.h b/cpp/poppler-embedded-file.h
index 250b84a..04ad7be 100644
--- a/cpp/poppler-embedded-file.h
+++ b/cpp/poppler-embedded-file.h
@@ -41,7 +41,7 @@ public:
     unsigned int /*time_t*/ creation_date() const;
     std::string checksum() const;
     std::string mime_type() const;
-    std::vector<char> data() const;
+    byte_array data() const;
 
 private:
     embedded_file(embedded_file_private &dd);
commit cfb4f5dfabf31de22d68aa0d5796cb7a33d8b462
Author: Pino Toscano <pino at kde.org>
Date:   Mon Dec 14 11:06:36 2009 +0100

    [cpp] add a byte_array typedef, and use it for utf8 string data

diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index ce27061..cc15bce 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -47,27 +47,21 @@ ustring::~ustring()
 {
 }
 
-char* ustring::to_utf_8(int *length) const
+byte_array ustring::to_utf_8() const
 {
     if (!size()) {
-        if (length) {
-            *length = 0;
-        }
-        return 0;
+        return byte_array();
     }
 
     const value_type *me = data();
     const size_t len = size() * 2 + 2;
-    char *str = new char[len];
+    byte_array str(len);
     str[0] = 0xfe;
     str[1] = 0xff;
     for (size_t i = 0; i < size(); ++i, ++me) {
         str[i * 2 + 2] = (*me & 0xff);
         str[i * 2 + 3] = ((*me >> 8) & 0xff);
     }
-    if (length) {
-        *length = len;
-    }
     return str;
 }
 
diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h
index e51878c..a6a9146 100644
--- a/cpp/poppler-global.h
+++ b/cpp/poppler-global.h
@@ -34,6 +34,7 @@
 #endif
 
 #include <string>
+#include <vector>
 
 namespace poppler
 {
@@ -59,6 +60,8 @@ enum rotation_enum { rotate_0, rotate_90, rotate_180, rotate_270 };
 
 enum page_box_enum { media_box, crop_box, bleed_box, trim_box, art_box };
 
+typedef std::vector<char> byte_array;
+
 class POPPLER_CPP_EXPORT ustring : public std::basic_string<unsigned short>
 {
 public:
@@ -66,7 +69,7 @@ public:
     ustring(size_type len, value_type ch);
     ~ustring();
 
-    char* to_utf_8(int *length = 0) const;
+    byte_array to_utf_8() const;
     std::string to_latin1() const;
 
     static ustring from_utf_8(const char *str, int len = -1);
diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp
index 16ba370..6ab3b6c 100644
--- a/cpp/poppler-private.cpp
+++ b/cpp/poppler-private.cpp
@@ -63,8 +63,7 @@ ustring detail::unicode_to_ustring(const Unicode *u, int length)
 
 GooString* detail::ustring_to_unicode_GooString(const ustring &str)
 {
-    char *u = str.to_utf_8();
-    GooString *goo = new GooString(u);
-    delete [] u;
+    const byte_array utf8_data = str.to_utf_8();
+    GooString *goo = new GooString(utf8_data.data());
     return goo;
 }


More information about the poppler mailing list