-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Hello,
Attach is a patch that would expose Poppler's whole-words search option within the Qt frontends. While the implementation seems straight forward so far, I would like to request comments whether extending the "SearchMode" enumeration to flag definition is considered harmless. The proper way to do it seems to be the introduction of "QFlags<SearchMode>" which would however break compatibility and hence imply the need to have an additional overloads using a separate flag (and enumeration?) definition. Best regards, Adam. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJUsVigAAoJEPSSjE3STU34ZCkIAK93eNjnCP5SH6tEohwAm0Is 5YK6DQkMg3j20b3KPwdkhEDb13gc8EBzOb2SuNsY/pz8KsHzaTso7RDZ1XCt9GUw BSaI2UyZNDfiiflzLnS8eO0/5MRtciduYq7bLpghWlT8mq3FUc2oT1kWdeivb3+3 +xfBcjei6t9p00PIAdqpVvDcMhhrUVslvuGkD4AQHFy8QXxwJCeM5aN6PPT0GaVn 1A7UaJwBZL8ovGrGMxh95CGMXpnbMWIpFyR0Ogl2wfw13fNeSUnMWgMNMI3uT5rk mkoAw7biAjNuF6u1UHvB3OfR1hOHg9dlHcQBTvKz/604tZfzH/ac1XsK74XiY8I= =vgs3 -----END PGP SIGNATURE-----
>From 55fbf43f444e953e38db5abc28cd847065a643fd Mon Sep 17 00:00:00 2001 From: Adam Reichold <[email protected]> Date: Sat, 10 Jan 2015 17:34:51 +0100 Subject: [PATCH 1/2] Expose whole-words find option in Qt4 frontend Extends the Qt4 frontend's SearchMode enumeration to a flag definition which can also indicate whole-words matching in addition to case sensitivity. --- qt4/src/poppler-page-private.h | 2 +- qt4/src/poppler-page.cc | 33 ++++++++++++++++++--------------- qt4/src/poppler-qt4.h | 17 +++++++++-------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/qt4/src/poppler-page-private.h b/qt4/src/poppler-page-private.h index 91955e0..d39b9b1 100644 --- a/qt4/src/poppler-page-private.h +++ b/qt4/src/poppler-page-private.h @@ -46,7 +46,7 @@ public: 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); + TextPage *prepareTextSearch(const QString &text, Page::SearchMode mode, Page::Rotation rotate, GBool *sCase, GBool *sWords, QVector<Unicode> *u); }; } diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index fc928b9..4df8a5a 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -215,15 +215,18 @@ 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) +TextPage *PageData::prepareTextSearch(const QString &text, Page::SearchMode mode, Page::Rotation rotate, GBool *sCase, GBool *sWords, 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; + if (mode & Page::CaseInsensitive) *sCase = gFalse; + else *sCase = gTrue; + + if (mode & Page::WholeWordsOnly) *sWords = gTrue; + else *sWords = gFalse; const int rotation = (int)rotate * 90; @@ -457,29 +460,29 @@ QString Page::text(const QRectF &r) const return text(r, PhysicalLayout); } -bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate) const +bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, SearchMode mode, Rotation rotate) const { - GBool sCase; + GBool sCase, sWords; QVector<Unicode> u; - TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u); + TextPage *textPage = m_page->prepareTextSearch(text, mode, rotate, &sCase, &sWords, &u); bool found = false; if (direction == FromTop) found = textPage->findText( u.data(), u.size(), - gTrue, gTrue, gFalse, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom ); + gTrue, gTrue, gFalse, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom ); else if ( direction == NextResult ) found = textPage->findText( u.data(), u.size(), - gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom ); + gFalse, gTrue, gTrue, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom ); else if ( direction == PreviousResult ) found = textPage->findText( u.data(), u.size(), - gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse, &sLeft, &sTop, &sRight, &sBottom ); + gFalse, gTrue, gTrue, gFalse, sCase, gTrue, sWords, &sLeft, &sTop, &sRight, &sBottom ); textPage->decRefCnt(); return found; } -bool Page::search(const QString &text, QRectF &rect, SearchDirection direction, SearchMode caseSensitive, Rotation rotate) const +bool Page::search(const QString &text, QRectF &rect, SearchDirection direction, SearchMode mode, Rotation rotate) const { double sLeft, sTop, sRight, sBottom; sLeft = rect.left(); @@ -487,7 +490,7 @@ bool Page::search(const QString &text, QRectF &rect, SearchDirection direction, sRight = rect.right(); sBottom = rect.bottom(); - bool found = search(text, sLeft, sTop, sRight, sBottom, direction, caseSensitive, rotate); + bool found = search(text, sLeft, sTop, sRight, sBottom, direction, mode, rotate); rect.setLeft( sLeft ); rect.setTop( sTop ); @@ -497,17 +500,17 @@ bool Page::search(const QString &text, QRectF &rect, SearchDirection direction, return found; } -QList<QRectF> Page::search(const QString &text, SearchMode caseSensitive, Rotation rotate) const +QList<QRectF> Page::search(const QString &text, SearchMode mode, Rotation rotate) const { - GBool sCase; + GBool sCase, sWords; QVector<Unicode> u; - TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u); + TextPage *textPage = m_page->prepareTextSearch(text, mode, rotate, &sCase, &sWords, &u); QList<QRectF> results; double sLeft = 0.0, sTop = 0.0, sRight = 0.0, sBottom = 0.0; while(textPage->findText( u.data(), u.size(), - gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom )) + gFalse, gTrue, gTrue, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom )) { QRectF result; diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index ee7558e..2bfaee5 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -576,8 +576,9 @@ delete it; /** The type of search to perform */ - enum SearchMode { CaseSensitive, ///< Case differences cause no match in searching - CaseInsensitive ///< Case differences are ignored in matching + enum SearchMode { CaseSensitive = 0, ///< Case differences cause no match in searching + CaseInsensitive = 1<<0, ///< Case differences are ignored in matching + WholeWordsOnly = 1<<1, ///< Only whole words are matched }; /** @@ -587,10 +588,10 @@ delete it; \param rect in all directions is used to return where the text was found, for NextResult and PreviousResult indicates where to continue searching for \param direction in which direction do the search - \param caseSensitive be case sensitive? + \param mode whether matching is case sensitive or limited to whole words \param rotate the rotation to apply for the search order **/ - Q_DECL_DEPRECATED bool search(const QString &text, QRectF &rect, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + Q_DECL_DEPRECATED bool search(const QString &text, QRectF &rect, SearchDirection direction, SearchMode mode, Rotation rotate = Rotate0) const; /** Returns true if the specified text was found. @@ -599,24 +600,24 @@ delete it; \param rectXXX in all directions is used to return where the text was found, for NextResult and PreviousResult indicates where to continue searching for \param direction in which direction do the search - \param caseSensitive be case sensitive? + \param mode whether matching is case sensitive or limited to whole words \param rotate the rotation to apply for the search order \since 0.14 **/ - bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode mode, 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 mode whether matching is case sensitive or limited to whole words \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; + QList<QRectF> search(const QString &text, SearchMode mode, Rotation rotate = Rotate0) const; /** Returns a list of text of the page -- 2.2.1 >From 191c41fb043d335497f64c7f5deacbedee652428 Mon Sep 17 00:00:00 2001 From: Adam Reichold <[email protected]> Date: Sat, 10 Jan 2015 17:43:27 +0100 Subject: [PATCH 2/2] Expose whole-words find option in Qt5 frontend Extends the Qt5 frontend's SearchMode enumeration to a flag definition which can also indicate whole-words matching in addition to case sensitivity. --- qt5/src/poppler-page-private.h | 2 +- qt5/src/poppler-page.cc | 29 ++++++++++++++++------------- qt5/src/poppler-qt5.h | 9 +++++---- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/qt5/src/poppler-page-private.h b/qt5/src/poppler-page-private.h index 91955e0..d39b9b1 100644 --- a/qt5/src/poppler-page-private.h +++ b/qt5/src/poppler-page-private.h @@ -46,7 +46,7 @@ public: 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); + TextPage *prepareTextSearch(const QString &text, Page::SearchMode mode, Page::Rotation rotate, GBool *sCase, GBool *sWords, QVector<Unicode> *u); }; } diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 6eea0d0..44b85e1 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -215,15 +215,18 @@ 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) +TextPage *PageData::prepareTextSearch(const QString &text, Page::SearchMode mode, Page::Rotation rotate, GBool *sCase, GBool *sWords, 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; + if (mode & Page::CaseInsensitive) *sCase = gFalse; + else *sCase = gTrue; + + if (mode & Page::WholeWordsOnly) *sWords = gTrue; + else *sWords = gFalse; const int rotation = (int)rotate * 90; @@ -457,39 +460,39 @@ QString Page::text(const QRectF &r) const return text(r, PhysicalLayout); } -bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate) const +bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, SearchMode mode, Rotation rotate) const { - GBool sCase; + GBool sCase, sWords; QVector<Unicode> u; - TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u); + TextPage *textPage = m_page->prepareTextSearch(text, mode, rotate, &sCase, &sWords, &u); bool found = false; if (direction == FromTop) found = textPage->findText( u.data(), u.size(), - gTrue, gTrue, gFalse, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom ); + gTrue, gTrue, gFalse, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom ); else if ( direction == NextResult ) found = textPage->findText( u.data(), u.size(), - gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom ); + gFalse, gTrue, gTrue, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom ); else if ( direction == PreviousResult ) found = textPage->findText( u.data(), u.size(), - gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse, &sLeft, &sTop, &sRight, &sBottom ); + gFalse, gTrue, gTrue, gFalse, sCase, gTrue, sWords, &sLeft, &sTop, &sRight, &sBottom ); textPage->decRefCnt(); return found; } -QList<QRectF> Page::search(const QString &text, SearchMode caseSensitive, Rotation rotate) const +QList<QRectF> Page::search(const QString &text, SearchMode mode, Rotation rotate) const { - GBool sCase; + GBool sCase, sWords; QVector<Unicode> u; - TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u); + TextPage *textPage = m_page->prepareTextSearch(text, mode, rotate, &sCase, &sWords, &u); QList<QRectF> results; double sLeft = 0.0, sTop = 0.0, sRight = 0.0, sBottom = 0.0; while(textPage->findText( u.data(), u.size(), - gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom )) + gFalse, gTrue, gTrue, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom )) { QRectF result; diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index dee0b19..21ed5e7 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -577,8 +577,9 @@ delete it; /** The type of search to perform */ - enum SearchMode { CaseSensitive, ///< Case differences cause no match in searching - CaseInsensitive ///< Case differences are ignored in matching + enum SearchMode { CaseSensitive = 0, ///< Case differences cause no match in searching + CaseInsensitive = 1<<0, ///< Case differences are ignored in matching + WholeWordsOnly = 1<<1, ///< Only whole words are matched }; /** @@ -592,7 +593,7 @@ delete it; \param rotate the rotation to apply for the search order \since 0.14 **/ - bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode mode, Rotation rotate = Rotate0) const; /** Returns a list of all occurrences of the specified text on the page. @@ -605,7 +606,7 @@ delete it; \since 0.22 **/ - QList<QRectF> search(const QString &text, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + QList<QRectF> search(const QString &text, SearchMode mode, Rotation rotate = Rotate0) const; /** Returns a list of text of the page -- 2.2.1
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
