diff options
author | Adam Reichold <adamreichold@myopera.com> | 2012-06-28 17:42:17 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2012-06-30 14:44:40 +0200 |
commit | bd71f80c409dbb47231088c3c6661946ccde6e67 (patch) | |
tree | 7d7acb2387a3d4b59647bbe4ed2c12ec7276e1c8 /qt4/src | |
parent | 46ebe7dc84b14ce8dda7b3b1da516b9d99ac3344 (diff) |
[qt4] add whole-page search method to Poppler::Page
Diffstat (limited to 'qt4/src')
-rw-r--r-- | qt4/src/poppler-page.cc | 39 | ||||
-rw-r--r-- | qt4/src/poppler-qt4.h | 14 |
2 files changed, 53 insertions, 0 deletions
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index 6a16d032..ca6744e9 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -12,6 +12,7 @@ * Copyright (C) 2010 Hib Eris <hib@hiberis.nl> * Copyright (C) 2012 Tobias Koenig <tokoe@kdab.com> * Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it> + * Copyright (C) 2012 Adam Reichold <adamreichold@myopera.com> * * 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 @@ -427,6 +428,44 @@ bool Page::search(const QString &text, QRectF &rect, SearchDirection direction, return found; } +QList<QRectF> Page::search(const QString &text, SearchMode caseSensitive, Rotation rotate) const +{ + const QChar * str = text.unicode(); + int len = text.length(); + QVector<Unicode> u(len); + for (int i = 0; i < len; ++i) u[i] = str[i].unicode(); + + GBool sCase; + if (caseSensitive == CaseSensitive) sCase = gTrue; + else sCase = gFalse; + + int rotation = (int)rotate * 90; + + QList<QRectF> results; + double sLeft = 0.0, sTop = 0.0, sRight = 0.0, sBottom = 0.0; + + TextOutputDev td(NULL, gTrue, 0, gFalse, gFalse); + m_page->parentDoc->doc->displayPage( &td, m_page->index + 1, 72, 72, rotation, false, true, false ); + TextPage *textPage=td.takeText(); + + while(textPage->findText( u.data(), len, + gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom )) + { + QRectF result; + + result.setLeft(sLeft); + result.setTop(sTop); + result.setRight(sRight); + result.setBottom(sBottom); + + results.append(result); + } + + textPage->decRefCnt(); + + return results; +} + QList<TextBox*> Page::textList(Rotation rotate) const { TextOutputDev *output_dev; diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index 827ea533..425b1e03 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -12,6 +12,7 @@ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral@kde.org> * Copyright (C) 2012, Fabio D'Urso <fabiodurso@hotmail.it> * Copyright (C) 2012, Tobias Koenig <tobias.koenig@kdab.com> + * Copyright (C) 2012 Adam Reichold <adamreichold@myopera.com> * * 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 @@ -602,6 +603,19 @@ delete it; \since 0.14 **/ bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + + /** + Returns a list of all occurrences of the specified text on the page. + + \param text the text to search + \param caseSensitive whether to be case sensitive + \param rotate the rotation to apply for the search order + + \warning Do not use the returned QRectF as arguments of another search call because of truncation issues if qreal is defined as float. + + \since 0.22 + **/ + QList<QRectF> search(const QString &text, SearchMode caseSensitive, Rotation rotate = Rotate0) const; /** Returns a list of text of the page |