diff options
author | Albert Astals Cid <aacid@kde.org> | 2005-11-21 22:12:15 +0000 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2005-11-21 22:12:15 +0000 |
commit | e64f63416dbce497cb2167272b95491664f213e8 (patch) | |
tree | 87e3669a198131d00b868dac970052ed5d9f7879 /qt | |
parent | 8bd8cb4160b73da69d058783750352fbface66dc (diff) |
PAtch to add some more functions to the qt binding by Stefan Kebekus
Diffstat (limited to 'qt')
-rw-r--r-- | qt/poppler-page.cc | 69 | ||||
-rw-r--r-- | qt/poppler-qt.h | 41 |
2 files changed, 109 insertions, 1 deletions
diff --git a/qt/poppler-page.cc b/qt/poppler-page.cc index 5c2be542..6e292a3f 100644 --- a/qt/poppler-page.cc +++ b/qt/poppler-page.cc @@ -157,6 +157,11 @@ Page::~Page() void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h) const { + renderToPixmap(q, x, y, w, h, 72.0, 72.0); +} + +void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const +{ SplashOutputDev *output_dev; SplashBitmap *bitmap; SplashColor white; @@ -167,7 +172,7 @@ void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h) const output_dev = new SplashOutputDev(splashModeRGB8, 4, gFalse, white); output_dev->startDoc(data->doc->data->doc.getXRef ()); - data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, 72, 72, + data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, xres, yres, 0, false, false, false, -1, -1, -1, -1); bitmap = output_dev->getBitmap (); color_ptr = bitmap->getDataPtr (); @@ -223,6 +228,41 @@ QString Page::getText(const Rectangle &r) const return result; } +QValueList<TextBox*> Page::textList() const +{ + TextOutputDev *output_dev; + + QValueList<TextBox*> output_list; + + output_dev = new TextOutputDev(0, gFalse, gFalse, gFalse); + + data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, 72, 72, + 0, false, false, false, -1, -1, -1, -1); + + TextWordList *word_list = output_dev->makeWordList(); + + if (!word_list) { + delete output_dev; + return output_list; + } + + for (int i = 0; i < word_list->getLength(); i++) { + TextWord *word = word_list->get(i); + QString string = QString::fromUtf8(word->getText()->getCString()); + double xMin, yMin, xMax, yMax; + word->getBBox(&xMin, &yMin, &xMax, &yMax); + + TextBox* text_box = new TextBox(string, Rectangle(xMin, yMin, xMax, yMax)); + + output_list.append(text_box); + } + + delete word_list; + delete output_dev; + + return output_list; +} + PageTransition *Page::getTransition() const { if (!data->transition) @@ -236,4 +276,31 @@ PageTransition *Page::getTransition() const return data->transition; } +QSize Page::pageSize() const +{ + ::Page *p = data->doc->data->doc.getCatalog()->getPage(data->index + 1); + return QSize( (int)p->getMediaWidth(), (int)p->getMediaHeight() ); +} + +Page::Orientation Page::orientation() const +{ + ::Page *p = data->doc->data->doc.getCatalog()->getPage(data->index + 1); + + int rotation = p->getRotate(); + switch (rotation) { + case 90: + return Page::Landscape; + break; + case 180: + return Page::UpsideDown; + break; + case 270: + return Page::Seascape; + break; + default: + return Page::Portrait; + } +} + + } diff --git a/qt/poppler-qt.h b/qt/poppler-qt.h index ecc46ad3..c934e51a 100644 --- a/qt/poppler-qt.h +++ b/qt/poppler-qt.h @@ -43,6 +43,21 @@ class Rectangle double m_y2; }; +class TextBox +{ + public: + TextBox(const QString& text, const Rectangle &bBox) : + m_text(text), m_bBox(bBox) {}; + + QString getText() const { return m_text; }; + Rectangle getBoundingBox() const { return m_bBox; }; + + private: + QString m_text; + Rectangle m_bBox; +}; + + class PageTransitionData; class PageTransition { @@ -118,18 +133,44 @@ class Page { friend class Document; public: ~Page(); + void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const; + + /** + * This is a convenience function that is equivalent to + * renderToPixmap() with xres and yres set to 72.0. We keep it + * only for binary compatibility + **/ void renderToPixmap(QPixmap **q, int x, int y, int w, int h) const; /** + * Returns the size of the page in points + **/ + QSize pageSize() const; + + /** * Returns the text that is inside the Rectangle r * If r is a null Rectangle all text of the page is given **/ QString getText(const Rectangle &r) const; + QValueList<TextBox*> textList() const; + /** * Returns the transition of this page **/ PageTransition *getTransition() const; + + enum Orientation { + Landscape, + Portrait, + Seascape, + UpsideDown + }; + + /** + * The orientation of the page + **/ + Orientation orientation() const; private: Page(const Document *doc, int index); |