[poppler] 6 commits - cpp/poppler-document.cpp cpp/poppler-document.h cpp/poppler-embedded-file.cpp cpp/poppler-embedded-file.h cpp/poppler-font.cpp cpp/poppler-global.cpp cpp/poppler-global.h cpp/poppler-page.cpp cpp/poppler-private.cpp cpp/poppler-private.h poppler/XRef.cc

Pino Toscano pino at kemper.freedesktop.org
Fri May 28 09:13:55 PDT 2010


 cpp/poppler-document.cpp      |   10 ++---
 cpp/poppler-document.h        |    2 -
 cpp/poppler-embedded-file.cpp |    8 ++--
 cpp/poppler-embedded-file.h   |    4 +-
 cpp/poppler-font.cpp          |   79 ++++++++++++++++++++++++++++++++++++++++--
 cpp/poppler-global.cpp        |   25 +------------
 cpp/poppler-global.h          |    4 +-
 cpp/poppler-page.cpp          |   68 ++++++++++++++++++++++++++++++++++++
 cpp/poppler-private.cpp       |   25 +++++++++++++
 cpp/poppler-private.h         |    2 +
 poppler/XRef.cc               |    2 -
 11 files changed, 191 insertions(+), 38 deletions(-)

New commits:
commit a72c68117ba05f3934e2df227cdcaf53a375f0ce
Author: Pino Toscano <pino at kde.org>
Date:   Fri May 28 18:11:02 2010 +0200

    [cpp apidox] add a start of API documentation for the 'page' class

diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp
index e61415c..1bfb8d4 100644
--- a/cpp/poppler-page.cpp
+++ b/cpp/poppler-page.cpp
@@ -42,17 +42,41 @@ page_private::~page_private()
     delete transition;
 }
 
+/**
+ \class poppler::page poppler-page.h "poppler/cpp/poppler-page.h"
+
+ A page in a PDF %document.
+ */
+
+/**
+ \enum poppler::page::orientation_enum
+
+ The possible orientation of a page.
+*/
+
+/**
+ \enum poppler::page::search_direction_enum
+
+ The direction/action to follow when performing a text search.
+*/
+
 
 page::page(document_private *doc, int index)
     : d(new page_private(doc, index))
 {
 }
 
+/**
+ Destructor.
+ */
 page::~page()
 {
     delete d;
 }
 
+/**
+ \returns the orientation of the page
+ */
 page::orientation_enum page::orientation() const
 {
     const int rotation = d->page->getRotate();
@@ -71,11 +95,26 @@ page::orientation_enum page::orientation() const
     }
 }
 
+/**
+ The eventual duration the page can be hinted to be shown in a presentation.
+
+ If this value is positive (usually different than -1) then a PDF viewer, when
+ showing the page in a presentation, should show the page for at most for this
+ number of seconds, and then switch to the next page (if any). Note this is
+ purely a presentation attribute, it has no influence on the behaviour.
+
+ \returns the duration time (in seconds) of the page
+ */
 double page::duration() const
 {
     return d->page->getDuration();
 }
 
+/**
+ Returns the size of one rect of the page.
+
+ \returns the size of the specified page rect
+ */
 rectf page::page_rect(page_box_enum box) const
 {
     PDFRectangle *r = 0;
@@ -102,6 +141,9 @@ rectf page::page_rect(page_box_enum box) const
     return rectf();
 }
 
+/**
+ \returns the label of the page, if any
+ */
 ustring page::label() const
 {
     GooString goo;
@@ -112,6 +154,14 @@ ustring page::label() const
     return detail::unicode_GooString_to_ustring(&goo);
 }
 
+/**
+ The transition from this page to the next one.
+
+ If it is set, then a PDF viewer in a presentation should perform the
+ specified transition effect when switching from this page to the next one.
+
+ \returns the transition effect for the switch to the next page, if any
+ */
 page_transition* page::transition() const
 {
     if (!d->transition) {
@@ -124,6 +174,16 @@ page_transition* page::transition() const
     return d->transition;
 }
 
+/**
+ Search the page for some text.
+
+ \param text the text to search
+ \param[in,out] r the area where to start search, which will be set to the area
+                  of the match (if any)
+ \param direction in which direction search for text
+ \param case_sensitivity whether search in a case sensitive way
+ \param rotation the rotation assumed for the page
+ */
 bool page::search(const ustring &text, rectf &r, search_direction_enum direction,
                   case_sensitivity_enum case_sensitivity, rotation_enum rotation) const
 {
@@ -173,6 +233,14 @@ bool page::search(const ustring &text, rectf &r, search_direction_enum direction
     return found;
 }
 
+/**
+ Returns the text in the page.
+
+ \param r if not empty, it will be extracted the text in it; otherwise, the
+          text of the whole page
+
+ \returns the text of the page in the specified rect or in the whole page
+ */
 ustring page::text(const rectf &r) const
 {
     std::auto_ptr<GooString> s;
commit acf7729e8e270e1b4b2a552272dc280ae6d7b352
Author: Pino Toscano <pino at kde.org>
Date:   Fri May 28 17:38:35 2010 +0200

    [cpp] fix the font_iterator current page status

diff --git a/cpp/poppler-font.cpp b/cpp/poppler-font.cpp
index 27a0107..ab3b409 100644
--- a/cpp/poppler-font.cpp
+++ b/cpp/poppler-font.cpp
@@ -62,7 +62,7 @@ public:
     font_iterator_private(int start_page, document_private *dd)
         : font_info_scanner(dd->doc, start_page)
         , total_pages(dd->doc->getNumPages())
-        , current_page((std::max)(start_page, 0) - 1)
+        , current_page((std::max)(start_page, 0))
     {
     }
     ~font_iterator_private()
@@ -206,6 +206,10 @@ font_iterator::~font_iterator()
  */
 std::vector<font_info> font_iterator::next()
 {
+    if (!has_next()) {
+        return std::vector<font_info>();
+    }
+
     ++d->current_page;
 
     GooList *items = d->font_info_scanner.scan(1);
@@ -225,7 +229,7 @@ std::vector<font_info> font_iterator::next()
 */
 bool font_iterator::has_next() const
 {
-    return (d->current_page + 1) < d->total_pages;
+    return d->current_page < d->total_pages;
 }
 
 /**
commit 4e017ff24a01cbbf1b39eedc3d7697f8b180fdd9
Author: Pino Toscano <pino at kde.org>
Date:   Fri May 28 17:15:28 2010 +0200

    [cpp apidox] add API documentation for the 'font_info' and 'font_iterator' classes

diff --git a/cpp/poppler-font.cpp b/cpp/poppler-font.cpp
index 5c3221b..27a0107 100644
--- a/cpp/poppler-font.cpp
+++ b/cpp/poppler-font.cpp
@@ -74,7 +74,22 @@ public:
     int current_page;
 };
 
+/**
+ \class poppler::font_info poppler-font.h "poppler/cpp/poppler-font.h"
 
+ The information about a font used in a PDF %document.
+ */
+
+/**
+ \enum poppler::font_info::type_enum
+
+ The various types of fonts available in a PDF %document.
+*/
+
+
+/**
+ Constructs an invalid font information.
+ */
 font_info::font_info()
     : d(new font_info_private())
 {
@@ -85,41 +100,65 @@ font_info::font_info(font_info_private &dd)
 {
 }
 
+/**
+ Copy constructor.
+ */
 font_info::font_info(const font_info &fi)
     : d(new font_info_private(*fi.d))
 {
 }
 
+/**
+ Destructor.
+ */
 font_info::~font_info()
 {
     delete d;
 }
 
+/**
+ \returns the name of the font
+ */
 std::string font_info::name() const
 {
     return d->font_name;
 }
 
+/**
+ \returns the file name of the font, in case the font is not embedded nor subset
+ */
 std::string font_info::file() const
 {
     return d->font_file;
 }
 
+/**
+ \returns whether the font is totally embedded in the %document
+ */
 bool font_info::is_embedded() const
 {
     return d->is_embedded;
 }
 
+/**
+ \returns whether there is a subset of the font embedded in the %document
+ */
 bool font_info::is_subset() const
 {
     return d->is_subset;
 }
 
+/**
+ \returns the type of the font
+ */
 font_info::type_enum font_info::type() const
 {
     return d->type;
 }
 
+/**
+ Assignment operator.
+ */
 font_info& font_info::operator=(const font_info &fi)
 {
     if (this != &fi) {
@@ -128,17 +167,43 @@ font_info& font_info::operator=(const font_info &fi)
     return *this;
 }
 
+/**
+ \class poppler::font_iterator poppler-font.h "poppler/cpp/poppler-font.h"
+
+ Reads the fonts in the PDF %document page by page.
+
+ font_iterator is the way to collect the list of the fonts used in a PDF
+ %document, reading them incrementally page by page.
+
+ A typical usage of this might look like:
+ \code
+poppler::font_iterator *it = doc->create_font_iterator();
+while (it->has_next()) {
+    std::vector<poppler::font_info> fonts = it->next();
+    // do domething with the fonts
+}
+// after we are done with the iterator, it must be deleted
+delete it;
+\endcode
+ */
+
 
 font_iterator::font_iterator(int start_page, document_private *dd)
     : d(new font_iterator_private(start_page, dd))
 {
 }
 
+/**
+ Destructor.
+ */
 font_iterator::~font_iterator()
 {
     delete d;
 }
 
+/**
+ Returns the fonts of the current page and advances to the next one.
+ */
 std::vector<font_info> font_iterator::next()
 {
     ++d->current_page;
@@ -155,11 +220,17 @@ std::vector<font_info> font_iterator::next()
     return fonts;
 }
 
+/**
+ \returns whether the iterator has more pages to advance to
+*/
 bool font_iterator::has_next() const
 {
     return (d->current_page + 1) < d->total_pages;
 }
 
+/**
+ \returns the current page
+*/
 int font_iterator::current_page() const
 {
     return d->current_page;
commit 2ff840b62e41e2fc98e9fcff7330f40216de58a5
Author: Pino Toscano <pino at kde.org>
Date:   Fri May 28 14:34:37 2010 +0200

    [cpp] move the actual convert_date(const char*) implementation in the detail
    
    this way it is possible to call it from inside poppler-cpp without an implicit conversion to std::string

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 4a4077d..50d21a4 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -350,7 +350,7 @@ time_type document::info_date(const std::string &key) const
     Object obj;
     time_type result = time_type(-1);
     if (info_dict->lookup(PSTR(key.c_str()), &obj)->isString()) {
-        result = convert_date(obj.getString()->getCString());
+        result = detail::convert_date(obj.getString()->getCString());
     }
     obj.free();
     info.free();
diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index 1b05a4c..7fe6204 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -103,7 +103,7 @@ int embedded_file::size() const
  */
 time_type embedded_file::modification_date() const
 {
-    return convert_date(d->emb_file->modDate()->getCString());
+    return detail::convert_date(d->emb_file->modDate()->getCString());
 }
 
 /**
@@ -112,7 +112,7 @@ time_type embedded_file::modification_date() const
  */
 time_type embedded_file::creation_date() const
 {
-    return convert_date(d->emb_file->createDate()->getCString());
+    return detail::convert_date(d->emb_file->createDate()->getCString());
 }
 
 /**
diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index 509dfdb..fbdf5a9 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -19,10 +19,9 @@
 
 #include "poppler-global.h"
 
-#include "DateInfo.h"
+#include "poppler-private.h"
 
 #include <cerrno>
-#include <ctime>
 #include <cstring>
 #include <iostream>
 
@@ -190,25 +189,7 @@ ustring ustring::from_latin1(const std::string &str)
  */
 time_type poppler::convert_date(const std::string &date)
 {
-    int year, mon, day, hour, min, sec, tzHours, tzMins;
-    char tz;
-
-    if (!parseDateString(date.c_str(), &year, &mon, &day, &hour, &min, &sec,
-                                       &tz, &tzHours, &tzMins)) {
-        return time_type(-1);
-    }
-
-    struct tm time;
-    time.tm_sec = sec;
-    time.tm_min = min;
-    time.tm_hour = hour;
-    time.tm_mday = day;
-    time.tm_mon = mon - 1;
-    time.tm_year = year - 1900;
-    time.tm_wday = -1;
-    time.tm_yday = -1;
-    time.tm_isdst = -1;
-    return mktime(&time);
+    return detail::convert_date(date.c_str());
 }
 
 std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array)
diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp
index 51d557c..5b63786 100644
--- a/cpp/poppler-private.cpp
+++ b/cpp/poppler-private.cpp
@@ -18,9 +18,11 @@
 
 #include "poppler-private.h"
 
+#include "DateInfo.h"
 #include "GooString.h"
 #include "Page.h"
 
+#include <ctime>
 #include <iostream>
 #include <sstream>
 
@@ -105,3 +107,26 @@ GooString* detail::ustring_to_unicode_GooString(const ustring &str)
     GooString *goo = new GooString(&ba[0]);
     return goo;
 }
+
+time_type detail::convert_date(const char *date)
+{
+    int year, mon, day, hour, min, sec, tzHours, tzMins;
+    char tz;
+
+    if (!parseDateString(date, &year, &mon, &day, &hour, &min, &sec,
+                               &tz, &tzHours, &tzMins)) {
+        return time_type(-1);
+    }
+
+    struct tm time;
+    time.tm_sec = sec;
+    time.tm_min = min;
+    time.tm_hour = hour;
+    time.tm_mday = day;
+    time.tm_mon = mon - 1;
+    time.tm_year = year - 1900;
+    time.tm_wday = -1;
+    time.tm_yday = -1;
+    time.tm_isdst = -1;
+    return mktime(&time);
+}
diff --git a/cpp/poppler-private.h b/cpp/poppler-private.h
index fb3bc6c..9f7952b 100644
--- a/cpp/poppler-private.h
+++ b/cpp/poppler-private.h
@@ -45,6 +45,8 @@ ustring unicode_GooString_to_ustring(GooString *str);
 ustring unicode_to_ustring(const Unicode *u, int length);
 GooString* ustring_to_unicode_GooString(const ustring &str);
 
+time_type convert_date(const char *date);
+
 }
 
 template <typename ConstIterator>
commit 8112e9111313eaded4cd2e89d0e67efb0f3e29db
Author: Pino Toscano <pino at kde.org>
Date:   Fri May 28 13:13:50 2010 +0200

    [cpp] add a time_type typedef
    
    ... defined as unsigned int, and use it all around
    (it changes nothing for client code)

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index ff1beaa..4a4077d 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -334,21 +334,21 @@ ustring document::info_key(const std::string &key) const
  \returns the time_t value for the \p key
  \see info_keys, info_date
  */
-unsigned int document::info_date(const std::string &key) const
+time_type document::info_date(const std::string &key) const
 {
     if (d->is_locked) {
-        return (unsigned int)(-1);
+        return time_type(-1);
     }
 
     Object info;
     if (!d->doc->getDocInfo(&info)->isDict()) {
         info.free();
-        return (unsigned int)(-1);
+        return time_type(-1);
     }
 
     Dict *info_dict = info.getDict();
     Object obj;
-    unsigned int result = (unsigned int)(-1);
+    time_type result = time_type(-1);
     if (info_dict->lookup(PSTR(key.c_str()), &obj)->isString()) {
         result = convert_date(obj.getString()->getCString());
     }
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 5d394bb..665b9e7 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -62,7 +62,7 @@ public:
     void get_pdf_version(int *major, int *minor) const;
     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;
+    time_type info_date(const std::string &key) const;
     bool is_encrypted() const;
     bool is_linearized() const;
     bool has_permission(permission_enum which) const;
diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index bd53a13..1b05a4c 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -101,7 +101,7 @@ int embedded_file::size() const
  \returns the time_t representing the modification date of the embedded file,
           if available
  */
-unsigned int embedded_file::modification_date() const
+time_type embedded_file::modification_date() const
 {
     return convert_date(d->emb_file->modDate()->getCString());
 }
@@ -110,7 +110,7 @@ unsigned int embedded_file::modification_date() const
  \returns the time_t representing the creation date of the embedded file,
           if available
  */
-unsigned int embedded_file::creation_date() const
+time_type embedded_file::creation_date() const
 {
     return convert_date(d->emb_file->createDate()->getCString());
 }
diff --git a/cpp/poppler-embedded-file.h b/cpp/poppler-embedded-file.h
index e4f5c91..307fdd6 100644
--- a/cpp/poppler-embedded-file.h
+++ b/cpp/poppler-embedded-file.h
@@ -37,8 +37,8 @@ public:
     std::string name() const;
     ustring description() const;
     int size() const;
-    unsigned int /*time_t*/ modification_date() const;
-    unsigned int /*time_t*/ creation_date() const;
+    time_type modification_date() const;
+    time_type creation_date() const;
     byte_array checksum() const;
     std::string mime_type() const;
     byte_array data() const;
diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index 96cb321..509dfdb 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -188,14 +188,14 @@ ustring ustring::from_latin1(const std::string &str)
 /**
  Converts a string representing a PDF date to a value compatible with time_t.
  */
-unsigned int poppler::convert_date(const std::string &date)
+time_type poppler::convert_date(const std::string &date)
 {
     int year, mon, day, hour, min, sec, tzHours, tzMins;
     char tz;
 
     if (!parseDateString(date.c_str(), &year, &mon, &day, &hour, &min, &sec,
                                        &tz, &tzHours, &tzMins)) {
-        return (unsigned int)(-1);
+        return time_type(-1);
     }
 
     struct tm time;
diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h
index 9010af1..5650182 100644
--- a/cpp/poppler-global.h
+++ b/cpp/poppler-global.h
@@ -72,6 +72,8 @@ enum case_sensitivity_enum { case_sensitive, case_insensitive };
 
 typedef std::vector<char> byte_array;
 
+typedef unsigned int /* time_t */ time_type;
+
 // to disable warning only for this occurrence
 #ifdef _MSC_VER
 #pragma warning(push)
@@ -100,7 +102,7 @@ private:
 #pragma warning(pop)
 #endif
 
-POPPLER_CPP_EXPORT unsigned int /*time_t*/ convert_date(const std::string &date);
+POPPLER_CPP_EXPORT time_type convert_date(const std::string &date);
 
 POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const byte_array &array);
 
commit bc5bdb43b12437e00aaddc27a74b9ac4b6498446
Author: Pino Toscano <pino at kde.org>
Date:   Fri May 28 13:01:53 2010 +0200

    use the proper type for iterating on a GooVector

diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index a4e3941..8ce370c 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -510,7 +510,7 @@ GBool XRef::readXRefTable(Parser *parser, Guint *pos, GooVector<Guint> *followed
   // check for an 'XRefStm' key
   if (obj.getDict()->lookup("XRefStm", &obj2)->isInt()) {
     pos2 = (Guint)obj2.getInt();
-    for (uint i = 0; ok == gTrue && i < followedXRefStm->size(); ++i) {
+    for (size_t i = 0; ok == gTrue && i < followedXRefStm->size(); ++i) {
       if (followedXRefStm->at(i) == pos2) {
         ok = gFalse;
       }


More information about the poppler mailing list