qt4/src/poppler-page-private.h | 7 +++ qt4/src/poppler-page.cc | 72 ++++++++++++++++++++++++++++++----------- qt4/src/poppler-qt4.h | 14 +++++++ 3 files changed, 73 insertions(+), 20 deletions(-)
New commits: commit 262203bd86403e43034fbfbbeef5a5894a62ecb2 Author: Albert Astals Cid <[email protected]> Date: Sat Jun 30 14:36:28 2012 +0200 [qt4] Refactor part of ::search() functions diff --git a/qt4/src/poppler-page-private.h b/qt4/src/poppler-page-private.h index ecdca17..91955e0 100644 --- a/qt4/src/poppler-page-private.h +++ b/qt4/src/poppler-page-private.h @@ -1,6 +1,6 @@ /* poppler-page.cc: qt interface to poppler * Copyright (C) 2005, Net Integration Technologies, Inc. - * Copyright (C) 2007, Albert Astals Cid <[email protected]> + * Copyright (C) 2007, 2012, Albert Astals Cid <[email protected]> * Copyright (C) 2008, Pino Toscano <[email protected]> * * This program is free software; you can redistribute it and/or modify @@ -21,10 +21,13 @@ #ifndef _POPPLER_PAGE_PRIVATE_H_ #define _POPPLER_PAGE_PRIVATE_H_ +#include "CharTypes.h" + class QRectF; class LinkAction; class Page; +class TextPage; namespace Poppler { @@ -42,6 +45,8 @@ public: PageTransition *transition; static Link* convertLinkActionToLink(::LinkAction * a, DocumentData *parentDoc, const QRectF &linkArea); + + TextPage *prepareTextSearch(const QString &text, Page::SearchMode caseSensitive, Page::Rotation rotate, GBool *sCase, QVector<Unicode> *u); }; } diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index ca6744e..349a1bb 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -1,7 +1,7 @@ /* poppler-page.cc: qt interface to poppler * Copyright (C) 2005, Net Integration Technologies, Inc. * Copyright (C) 2005, Brad Hards <[email protected]> - * Copyright (C) 2005-2011, Albert Astals Cid <[email protected]> + * Copyright (C) 2005-2012, Albert Astals Cid <[email protected]> * Copyright (C) 2005, Stefan Kebekus <[email protected]> * Copyright (C) 2006-2011, Pino Toscano <[email protected]> * Copyright (C) 2008 Carlos Garcia Campos <[email protected]> @@ -208,6 +208,25 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo return popplerLink; } +TextPage *PageData::prepareTextSearch(const QString &text, Page::SearchMode caseSensitive, Page::Rotation rotate, GBool *sCase, QVector<Unicode> *u) +{ + const QChar * str = text.unicode(); + const int len = text.length(); + u->resize(len); + for (int i = 0; i < len; ++i) (*u)[i] = str[i].unicode(); + + if (caseSensitive == Page::CaseSensitive) *sCase = gTrue; + else *sCase = gFalse; + + const int rotation = (int)rotate * 90; + + // fetch ourselves a textpage + TextOutputDev td(NULL, gTrue, 0, gFalse, gFalse); + parentDoc->doc->displayPage( &td, index + 1, 72, 72, rotation, false, true, false ); + TextPage *textPage=td.takeText(); + + return textPage; +} Page::Page(DocumentData *doc, int index) { m_page = new PageData(); @@ -377,32 +396,19 @@ QString Page::text(const QRectF &r) const bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, 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; + QVector<Unicode> u; + TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u); bool found = false; - - int rotation = (int)rotate * 90; - - // fetch ourselves a textpage - 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(); - if (direction == FromTop) - found = textPage->findText( u.data(), len, + found = textPage->findText( u.data(), u.size(), gTrue, gTrue, gFalse, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom ); else if ( direction == NextResult ) - found = textPage->findText( u.data(), len, + found = textPage->findText( u.data(), u.size(), gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom ); else if ( direction == PreviousResult ) - found = textPage->findText( u.data(), len, + found = textPage->findText( u.data(), u.size(), gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse, &sLeft, &sTop, &sRight, &sBottom ); textPage->decRefCnt(); @@ -430,25 +436,14 @@ bool Page::search(const QString &text, QRectF &rect, SearchDirection direction, 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; + QVector<Unicode> u; + TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u); - 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, + while(textPage->findText( u.data(), u.size(), gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom )) { QRectF result; commit bd71f80c409dbb47231088c3c6661946ccde6e67 Author: Adam Reichold <[email protected]> Date: Thu Jun 28 17:42:17 2012 +0200 [qt4] add whole-page search method to Poppler::Page diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index 6a16d03..ca6744e 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -12,6 +12,7 @@ * Copyright (C) 2010 Hib Eris <[email protected]> * Copyright (C) 2012 Tobias Koenig <[email protected]> * Copyright (C) 2012 Fabio D'Urso <[email protected]> + * Copyright (C) 2012 Adam Reichold <[email protected]> * * 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 827ea53..425b1e0 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -12,6 +12,7 @@ * Copyright (C) 2012, Guillermo A. Amaral B. <[email protected]> * Copyright (C) 2012, Fabio D'Urso <[email protected]> * Copyright (C) 2012, Tobias Koenig <[email protected]> + * Copyright (C) 2012 Adam Reichold <[email protected]> * * 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 _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
