[poppler] 5 commits - cpp/.gitignore cpp/poppler-global.h cpp/poppler-page.cpp cpp/poppler-page.h cpp/poppler-rectangle.h

Pino Toscano pino at kemper.freedesktop.org
Mon Feb 22 15:05:29 PST 2010


 cpp/.gitignore          |    1 
 cpp/poppler-global.h    |    2 +
 cpp/poppler-page.cpp    |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 cpp/poppler-page.h      |    9 ++++++
 cpp/poppler-rectangle.h |   18 ++++++++++++
 5 files changed, 97 insertions(+)

New commits:
commit 7838b182143086192ac8dcf571da0ce1743619e2
Author: Pino Toscano <pino at kde.org>
Date:   Tue Feb 23 00:04:09 2010 +0100

    [cpp] add the directory of the generated html apidox to the ignore list

diff --git a/cpp/.gitignore b/cpp/.gitignore
index 0556b92..5f43221 100644
--- a/cpp/.gitignore
+++ b/cpp/.gitignore
@@ -5,3 +5,4 @@
 Makefile
 Makefile.in
 poppler-version.h
+APIDOCS-html
commit 71a38a23a9db5cac872c666283b7abcb1462210c
Author: Pino Toscano <pino at kde.org>
Date:   Mon Feb 22 23:43:34 2010 +0100

    [cpp] add page::text() to get the text inside a page region

diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp
index c6a596d..5a0c29c 100644
--- a/cpp/poppler-page.cpp
+++ b/cpp/poppler-page.cpp
@@ -25,6 +25,8 @@
 
 #include "TextOutputDev.h"
 
+#include <memory>
+
 using namespace poppler;
 
 page_private::page_private(document_private *_doc, int _index)
@@ -170,3 +172,17 @@ bool page::search(const ustring &text, rectf &r, search_direction_enum direction
 
     return found;
 }
+
+ustring page::text(const rectf &r) const
+{
+    std::auto_ptr<GooString> s;
+    TextOutputDev td(0, gFalse, gFalse, gFalse);
+    d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false);
+    if (r.is_empty()) {
+        const PDFRectangle *rect = d->page->getCropBox();
+        s.reset(td.getText(rect->x1, rect->y1, rect->x2, rect->y2));
+    } else {
+        s.reset(td.getText(r.left(), r.top(), r.right(), r.bottom()));
+    }
+    return ustring::from_utf_8(s->getCString());
+}
diff --git a/cpp/poppler-page.h b/cpp/poppler-page.h
index 256f96e..308afd3 100644
--- a/cpp/poppler-page.h
+++ b/cpp/poppler-page.h
@@ -56,6 +56,7 @@ public:
 
     bool search(const ustring &text, rectf &r, search_direction_enum direction,
                 case_sensitivity_enum case_sensitivity, rotation_enum rotation = rotate_0) const;
+    ustring text(const rectf &rect = rectf()) const;
 
 private:
     page(document_private *doc, int index);
commit 4c75360233bc67f097551980a46ecce976927220
Author: Pino Toscano <pino at kde.org>
Date:   Mon Feb 22 23:05:53 2010 +0100

    [cpp] add page::search()

diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp
index c8ce706..c6a596d 100644
--- a/cpp/poppler-page.cpp
+++ b/cpp/poppler-page.cpp
@@ -23,6 +23,8 @@
 #include "poppler-page-private.h"
 #include "poppler-private.h"
 
+#include "TextOutputDev.h"
+
 using namespace poppler;
 
 page_private::page_private(document_private *_doc, int _index)
@@ -119,3 +121,52 @@ page_transition* page::transition() const
     }
     return d->transition;
 }
+
+bool page::search(const ustring &text, rectf &r, search_direction_enum direction,
+                  case_sensitivity_enum case_sensitivity, rotation_enum rotation) const
+{
+    const size_t len = text.length();
+    std::vector<Unicode> u(len);
+    for (size_t i = 0; i < len; ++i) {
+        u[i] = text[i];
+    }
+
+    const GBool sCase = case_sensitivity == case_sensitive ? gTrue : gFalse;
+    const int rotation_value = (int)rotation * 90;
+
+    bool found = false;
+    double rect_left = r.left();
+    double rect_top = r.top();
+    double rect_right = r.right();
+    double rect_bottom = r.bottom();
+
+    TextOutputDev td(NULL, gTrue, gFalse, gFalse);
+    d->doc->doc->displayPage(&td, d->index + 1, 72, 72, rotation_value, false, true, false);
+    TextPage *text_page = td.takeText();
+
+    switch (direction) {
+    case search_from_top:
+        found = text_page->findText(&u[0], len,
+                    gTrue, gTrue, gFalse, gFalse, sCase, gFalse,
+                    &rect_left, &rect_top, &rect_right, &rect_bottom);
+        break;
+    case search_next_result:
+        found = text_page->findText(&u[0], len,
+                    gFalse, gTrue, gTrue, gFalse, sCase, gFalse,
+                    &rect_left, &rect_top, &rect_right, &rect_bottom);
+        break;
+    case search_previous_result:
+        found = text_page->findText(&u[0], len,
+                    gFalse, gTrue, gTrue, gFalse, sCase, gTrue,
+                    &rect_left, &rect_top, &rect_right, &rect_bottom);
+        break;
+    }
+
+    text_page->decRefCnt();
+    r.set_left(rect_left);
+    r.set_top(rect_top);
+    r.set_right(rect_right);
+    r.set_bottom(rect_bottom);
+
+    return found;
+}
diff --git a/cpp/poppler-page.h b/cpp/poppler-page.h
index 65cea52..256f96e 100644
--- a/cpp/poppler-page.h
+++ b/cpp/poppler-page.h
@@ -39,6 +39,11 @@ public:
         seascape,
         upside_down
     };
+    enum search_direction_enum {
+        search_from_top,
+        search_next_result,
+        search_previous_result
+    };
 
     ~page();
 
@@ -49,6 +54,9 @@ public:
 
     page_transition* transition() const;
 
+    bool search(const ustring &text, rectf &r, search_direction_enum direction,
+                case_sensitivity_enum case_sensitivity, rotation_enum rotation = rotate_0) const;
+
 private:
     page(document_private *doc, int index);
 
commit 8932c53a084083eb42d109dd17bac3ad41ce65b5
Author: Pino Toscano <pino at kde.org>
Date:   Mon Feb 22 22:39:36 2010 +0100

    [cpp] add getters and setters for left/top/right/bottom

diff --git a/cpp/poppler-rectangle.h b/cpp/poppler-rectangle.h
index 18674b2..dabacc9 100644
--- a/cpp/poppler-rectangle.h
+++ b/cpp/poppler-rectangle.h
@@ -51,6 +51,24 @@ public:
     T height() const
     { return y2 - y1; }
 
+    T left() const
+    { return x1; }
+    T top() const
+    { return y1; }
+    T right() const
+    { return x2; }
+    T bottom() const
+    { return y2; }
+
+    void set_left(T value)
+    { x1 = value; }
+    void set_top(T value)
+    { y1 = value; }
+    void set_right(T value)
+    { x2 = value; }
+    void set_bottom(T value)
+    { y2 = value; }
+
 private:
     T x1, y1, x2, y2;
 };
commit 8e1ea57f558fa3a1702a17d79b5aaffc486c6a56
Author: Pino Toscano <pino at kde.org>
Date:   Mon Feb 22 22:19:51 2010 +0100

    [cpp] add a global enum for case sensitivity

diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h
index 1eb1fa3..b19378c 100644
--- a/cpp/poppler-global.h
+++ b/cpp/poppler-global.h
@@ -67,6 +67,8 @@ enum permission_enum { perm_print, perm_change, perm_copy, perm_add_notes,
                        perm_fill_forms, perm_accessibility, perm_assemble,
                        perm_print_high_resolution };
 
+enum case_sensitivity_enum { case_sensitive, case_insensitive };
+
 typedef std::vector<char> byte_array;
 
 class POPPLER_CPP_EXPORT ustring : public std::basic_string<unsigned short>


More information about the poppler mailing list