[poppler] 4 commits - cpp/poppler-document.cpp cpp/poppler-document-private.h cpp/poppler-embedded-file.cpp cpp/poppler-embedded-file.h cpp/poppler-toc.cpp cpp/tests

Pino Toscano pino at kemper.freedesktop.org
Tue Feb 23 08:07:52 PST 2010


 cpp/poppler-document-private.h |    2 -
 cpp/poppler-document.cpp       |   10 +++++--
 cpp/poppler-embedded-file.cpp  |   53 ++++++++++++++++++++++++++++++++++++--
 cpp/poppler-embedded-file.h    |    2 -
 cpp/poppler-toc.cpp            |   57 +++++++++++++++++++++++++++++++++++++++++
 cpp/tests/poppler-dump.cpp     |    4 +-
 6 files changed, 119 insertions(+), 9 deletions(-)

New commits:
commit fcbc571a98775b1daa8f562fc8674fb2d15b6626
Author: Pino Toscano <pino at kde.org>
Date:   Tue Feb 23 17:02:47 2010 +0100

    [cpp] make checksum() return an array of data, instead of a string
    
    a checksum is a sequence of values after all, so just return it as such instead of pretending it is a string
    accordingly adapt the mini dump application

diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index 18c9921..bbf097f 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -118,9 +118,15 @@ unsigned int embedded_file::creation_date() const
 /**
  \returns the checksum of the embedded file
  */
-std::string embedded_file::checksum() const
+byte_array embedded_file::checksum() const
 {
-    return std::string(d->emb_file->checksum()->getCString());
+    GooString *cs = d->emb_file->checksum();
+    const char *ccs = cs->getCString();
+    byte_array data(cs->getLength());
+    for (int i = 0; i < cs->getLength(); ++i) {
+        data[i] = ccs[i];
+    }
+    return data;
 }
 
 /**
diff --git a/cpp/poppler-embedded-file.h b/cpp/poppler-embedded-file.h
index 04ad7be..e493c9e 100644
--- a/cpp/poppler-embedded-file.h
+++ b/cpp/poppler-embedded-file.h
@@ -39,7 +39,7 @@ public:
     int size() const;
     unsigned int /*time_t*/ modification_date() const;
     unsigned int /*time_t*/ creation_date() const;
-    std::string checksum() const;
+    byte_array checksum() const;
     std::string mime_type() const;
     byte_array data() const;
 
diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index 745d038..693d107 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -106,10 +106,10 @@ static char charToHex(int x)
     return x < 10 ? x + '0' : x - 10 + 'a';
 }
 
-static std::string out_hex_string(const std::string &str)
+static std::string out_hex_string(const poppler::byte_array &str)
 {
     std::string ret(str.size() * 2, '\0');
-    const char *str_p = str.data();
+    const char *str_p = &str[0];
     for (unsigned int i = 0; i < str.size(); ++i, ++str_p) {
         ret[i * 2] = charToHex((*str_p & 0xf0) >> 4);
         ret[i * 2 + 1] = charToHex(*str_p & 0xf);
commit fbefb9bef9f7a099d51919255a98f412d1e1d696
Author: Pino Toscano <pino at kde.org>
Date:   Tue Feb 23 16:56:47 2010 +0100

    [cpp apidox] add API documentation for the 'embedded_file' class

diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index 6dfe321..18c9921 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -42,57 +42,100 @@ embedded_file* embedded_file_private::create(EmbFile *ef)
     return new embedded_file(*new embedded_file_private(ef));
 }
 
+/**
+ \class poppler::embedded_file poppler-embedded-file.h "poppler/cpp/poppler-embedded-file.h"
+
+ Represents a file embedded in a PDF %document.
+ */
+
 
 embedded_file::embedded_file(embedded_file_private &dd)
     : d(&dd)
 {
 }
 
+/**
+ Destroys the embedded file.
+ */
 embedded_file::~embedded_file()
 {
     delete d;
 }
 
+/**
+ \returns whether the embedded file is valid
+ */
 bool embedded_file::is_valid() const
 {
     return d->emb_file->isOk();
 }
 
+/**
+ \returns the name of the embedded file
+ */
 std::string embedded_file::name() const
 {
     return std::string(d->emb_file->name()->getCString());
 }
 
+/**
+ \returns the description of the embedded file
+ */
 ustring embedded_file::description() const
 {
     return detail::unicode_GooString_to_ustring(d->emb_file->description());
 }
 
+/**
+ \note this is not always available in the PDF %document, in that case this
+       will return \p -1.
+
+ \returns the size of the embedded file, if known
+ */
 int embedded_file::size() const
 {
     return d->emb_file->size();
 }
 
+/**
+ \returns the time_t representing the modification date of the embedded file,
+          if available
+ */
 unsigned int embedded_file::modification_date() const
 {
     return convert_date(d->emb_file->modDate()->getCString());
 }
 
+/**
+ \returns the time_t representing the creation date of the embedded file,
+          if available
+ */
 unsigned int embedded_file::creation_date() const
 {
     return convert_date(d->emb_file->createDate()->getCString());
 }
 
+/**
+ \returns the checksum of the embedded file
+ */
 std::string embedded_file::checksum() const
 {
     return std::string(d->emb_file->checksum()->getCString());
 }
 
+/**
+ \returns the MIME type of the embedded file, if available
+ */
 std::string embedded_file::mime_type() const
 {
     return std::string(d->emb_file->mimeType()->getCString());
 }
 
+/**
+ Reads all the data of the embedded file.
+
+ \returns the data of the embedded file
+ */
 byte_array embedded_file::data() const
 {
     if (!is_valid()) {
commit 6d39cca0a035fc656d3b86ba66dedaccee532fcb
Author: Pino Toscano <pino at kde.org>
Date:   Tue Feb 23 16:41:56 2010 +0100

    [cpp apidox] add API documentation for the 'toc' and 'toc_item' classes

diff --git a/cpp/poppler-toc.cpp b/cpp/poppler-toc.cpp
index 1fc0f4d..9789221 100644
--- a/cpp/poppler-toc.cpp
+++ b/cpp/poppler-toc.cpp
@@ -89,53 +89,110 @@ void toc_item_private::load_children(GooList *items)
     }
 }
 
+/**
+ \class poppler::toc poppler-toc.h "poppler/cpp/poppler-toc.h"
+
+ Represents the TOC (Table of Contents) of a PDF %document.
+
+ The TOC of a PDF %document is represented as a tree of items.
+ */
+
 
 toc::toc()
     : d(new toc_private())
 {
 }
 
+/**
+ Destroys the TOC.
+ */
 toc::~toc()
 {
     delete d;
 }
 
+/**
+ Returns the "invisible item" representing the root of the TOC.
+
+ This item is special, it has no title nor actions, it is open and its children
+ are the effective root items of the TOC. This is provided as a convenience
+ when iterating throught the TOC.
+
+ \returns the root "item"
+ */
 toc_item* toc::root() const
 {
     return &d->root;
 }
 
+/**
+ \class poppler::toc_item poppler-toc.h "poppler/cpp/poppler-toc.h"
+
+ Represents an item of the TOC (Table of Contents) of a PDF %document.
+ */
+
+/**
+ \typedef std::vector<toc_item *>::const_iterator poppler::toc_item::iterator
+
+ An iterator for the children of a TOC item.
+ */
+
 
 toc_item::toc_item()
     : d(new toc_item_private())
 {
 }
 
+/**
+ Destroys the TOC item.
+ */
 toc_item::~toc_item()
 {
     delete d;
 }
 
+/**
+ \returns the title of the TOC item
+ */
 ustring toc_item::title() const
 {
     return d->title;
 }
 
+/**
+ Returns whether the TOC item should be represented as open when showing the
+ TOC.
+
+ This is not a functional behaviour, but a visualisation hint of the item.
+ Regardless of this state, the item can be expanded and collapsed freely when
+ represented in a TOC view of a PDF viewer.
+
+ \returns whether the TOC item should be open
+ */
 bool toc_item::is_open() const
 {
     return d->is_open;
 }
 
+/**
+ \returns the children of the TOC item
+ */
 std::vector<toc_item *> toc_item::children() const
 {
     return d->children;
 }
 
+/**
+ \returns an iterator to the being of the list of children of the TOC item
+ */
 toc_item::iterator toc_item::children_begin() const
 {
     return d->children.begin();
 }
 
+/**
+ \returns an iterator to the end of the list of children of the TOC item
+ */
 toc_item::iterator toc_item::children_end() const
 {
     return d->children.end();
commit 857e4ceb26d959c48c7af6bff53ca1bfe5307236
Author: Pino Toscano <pino at kde.org>
Date:   Tue Feb 23 15:39:58 2010 +0100

    [cpp] when the loading of the document fails, put back the data where it was before

diff --git a/cpp/poppler-document-private.h b/cpp/poppler-document-private.h
index 9820603..9568166 100644
--- a/cpp/poppler-document-private.h
+++ b/cpp/poppler-document-private.h
@@ -42,7 +42,7 @@ public:
                      const std::string &user_password);
     ~document_private();
 
-    static document* check_document(document_private *doc);
+    static document* check_document(document_private *doc, byte_array *file_data);
 
     PDFDoc *doc;
     byte_array doc_data;
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index b96bea3..50d451f 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -89,7 +89,7 @@ void document_private::init()
     count++;
 }
 
-document* document_private::check_document(document_private *doc)
+document* document_private::check_document(document_private *doc, byte_array *file_data)
 {
     if (doc->doc->isOk() || doc->doc->getErrorCode() == errEncrypted) {
         if (doc->doc->getErrorCode() == errEncrypted) {
@@ -97,6 +97,10 @@ document* document_private::check_document(document_private *doc)
         }
         return new document(*doc);
     } else {
+        // put back the document data where it was before
+        if (file_data) {
+            file_data->swap(doc->doc_data);
+        }
         delete doc;
     }
     return 0;
@@ -546,7 +550,7 @@ document* document::load_from_file(const std::string &file_name,
     document_private *doc = new document_private(
                                 new GooString(file_name.c_str()),
                                 owner_password, user_password);
-    return document_private::check_document(doc);
+    return document_private::check_document(doc, 0);
 }
 
 /**
@@ -569,5 +573,5 @@ document* document::load_from_data(byte_array *file_data,
 
     document_private *doc = new document_private(
                                 file_data, owner_password, user_password);
-    return document_private::check_document(doc);
+    return document_private::check_document(doc, file_data);
 }


More information about the poppler mailing list