-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hello,

Am 10.01.2015 um 23:45 schrieb Albert Astals Cid:
> Maybe you can add some tests to check_search.cpp?

Attached patch with a test case for the four flag combinations added
to the Qt4 and Qt5 versions of "check_search.cpp".

Of course, this very much highlights the ugliness of shoe horning the
flags into the existing enumeration. But I don't think that making
"Poppler::Page::search" take an "int" instead of "SearchMode" would be
ABI compatible strictly speaking, since now the compiler is free to
choose the underlying type for the enumeration.

Best regards, Adam.

> Cheers, Albert
> 
> El Dissabte, 10 de gener de 2015, a les 23:26:01, Adam Reichold va
> escriure:
>> Hello again,
>> 
>> Am 10.01.2015 um 22:25 schrieb Albert Astals Cid:
>>> El Dissabte, 10 de gener de 2015, a les 17:51:48, Adam Reichold
>>> va
>>> 
>>> escriure:
>>>> 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.
>>> 
>>> Looks good to me. The qt5/ side would need the documentation
>>> update too, no?
>> 
>> patch with fixed Qt5 documentation and "\since" commands
>> attached.
>> 
>> Best regards, Adam.
>> 
>>> Cheers, Albert
>>> 
>>>> Best regards, Adam.
>>> 
>>> _______________________________________________ poppler
>>> mailing list [email protected] 
>>> http://lists.freedesktop.org/mailman/listinfo/poppler
> 
> 
> _______________________________________________ poppler mailing
> list [email protected] 
> http://lists.freedesktop.org/mailman/listinfo/poppler
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJUsbe8AAoJEPSSjE3STU34+qYIAMeoWptZ/vpQ+/q0bm7wmyvz
eOAULufrXlaH5OkNRsTRF/q6273um9zqPELtX9BFP5HnxXuufQnaYsUlwwhlUqms
LGEJ+g363hxFOj9xq0IhfFfoFZkeoc233tX1aFtU6bWlTQ8llgZi+fT7dOhZFZRN
vjjhZs4kTAR1p9vvXYvy08uyU1tsVLzBPl9m+eZ3G2555CRUtzBtn7zwaiI88yA0
4pWjqE7Mn5LqU30hMPQiuda605CPd8hqZrQeKBCZpBUp2gzUtUj4vgSUGWHo32bV
nO9DFOuduhwO7Je4XLLKI7rFnpj61M4oipzu/OV57U3JbwoMNmCL9KkXJ7I97MI=
=a0vd
-----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/4] 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 028c1c896f9090ad29ebd2b4226b515ed30bf2d2 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sat, 10 Jan 2015 17:43:27 +0100
Subject: [PATCH 2/4] 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          | 13 +++++++------
 3 files changed, 24 insertions(+), 20 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..8271653 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
 	};
 	
 	/**
@@ -588,24 +589,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 250037466a724e9e68c8a2bfd8c165fb40d6c750 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sat, 10 Jan 2015 23:14:49 +0100
Subject: [PATCH 3/4] Document when the 'WholeWordsOnly' flag became available
 in the Qt frontends

---
 qt4/src/poppler-qt4.h | 2 +-
 qt5/src/poppler-qt5.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 2bfaee5..fc3b0ea 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -578,7 +578,7 @@ delete it;
 	*/
 	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
+			  WholeWordsOnly = 1<<1,    ///< Only whole words are matched \since 0.31
 	};
 	
 	/**
diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h
index 8271653..9847474 100644
--- a/qt5/src/poppler-qt5.h
+++ b/qt5/src/poppler-qt5.h
@@ -579,7 +579,7 @@ delete it;
 	*/
 	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
+			  WholeWordsOnly = 1<<1,    ///< Only whole words are matched \since 0.31
 	};
 	
 	/**
-- 
2.2.1


>From b42ebd2c94a59f5384e4f6f1691c11924f4eb49f Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 11 Jan 2015 00:30:11 +0100
Subject: [PATCH 4/4] Add whole-words-only Qt frontend test cases

---
 qt4/tests/check_search.cpp | 31 +++++++++++++++++++++++++++++++
 qt5/tests/check_search.cpp | 31 +++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/qt4/tests/check_search.cpp b/qt4/tests/check_search.cpp
index cabf82d..b500dad 100644
--- a/qt4/tests/check_search.cpp
+++ b/qt4/tests/check_search.cpp
@@ -8,6 +8,7 @@ class TestSearch: public QObject
 private slots:
     void bug7063();
     void testNextAndPrevious();
+    void testWholeWordsOnly();
 };
 
 void TestSearch::bug7063()
@@ -86,6 +87,36 @@ void TestSearch::testNextAndPrevious()
     delete doc;
 }
 
+void TestSearch::testWholeWordsOnly()
+{
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
+
+    const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
+
+    const Poppler::Page::SearchMode mode0 = Poppler::Page::CaseSensitive;
+    const Poppler::Page::SearchMode mode1 = Poppler::Page::WholeWordsOnly;
+    const Poppler::Page::SearchMode mode2 = Poppler::Page::CaseInsensitive;
+    const Poppler::Page::SearchMode mode3 = static_cast< Poppler::Page::SearchMode >(Poppler::Page::CaseInsensitive | Poppler::Page::WholeWordsOnly);
+
+    double left, top, right, bottom;
+
+    QCOMPARE( page->search(QLatin1String("brown"), left, top, right, bottom, direction, mode0), true );
+    QCOMPARE( page->search(QLatin1String("brOwn"), left, top, right, bottom, direction, mode0), false );
+
+    QCOMPARE( page->search(QLatin1String("brown"), left, top, right, bottom, direction, mode1), true );
+    QCOMPARE( page->search(QLatin1String("own"), left, top, right, bottom, direction, mode1), false );
+
+    QCOMPARE( page->search(QLatin1String("brOwn"), left, top, right, bottom, direction, mode2), true );
+    QCOMPARE( page->search(QLatin1String("brawn"), left, top, right, bottom, direction, mode2), false );
+
+    QCOMPARE( page->search(QLatin1String("brOwn"), left, top, right, bottom, direction, mode3), true );
+    QCOMPARE( page->search(QLatin1String("Own"), left, top, right, bottom, direction, mode3), false );
+}
+
 QTEST_MAIN(TestSearch)
 #include "check_search.moc"
 
diff --git a/qt5/tests/check_search.cpp b/qt5/tests/check_search.cpp
index efb5556..7c043f3 100644
--- a/qt5/tests/check_search.cpp
+++ b/qt5/tests/check_search.cpp
@@ -8,6 +8,7 @@ class TestSearch: public QObject
 private slots:
     void bug7063();
     void testNextAndPrevious();
+    void testWholeWords();
 };
 
 void TestSearch::bug7063()
@@ -93,6 +94,36 @@ void TestSearch::testNextAndPrevious()
     delete doc;
 }
 
+void TestSearch::testWholeWordsOnly()
+{
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
+
+    const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
+
+    const Poppler::Page::SearchMode mode0 = Poppler::Page::CaseSensitive;
+    const Poppler::Page::SearchMode mode1 = Poppler::Page::WholeWordsOnly;
+    const Poppler::Page::SearchMode mode2 = Poppler::Page::CaseInsensitive;
+    const Poppler::Page::SearchMode mode3 = static_cast< Poppler::Page::SearchMode >(Poppler::Page::CaseInsensitive | Poppler::Page::WholeWordsOnly);
+
+    double left, top, right, bottom;
+
+    QCOMPARE( page->search(QLatin1String("brown"), left, top, right, bottom, direction, mode0), true );
+    QCOMPARE( page->search(QLatin1String("brOwn"), left, top, right, bottom, direction, mode0), false );
+
+    QCOMPARE( page->search(QLatin1String("brown"), left, top, right, bottom, direction, mode1), true );
+    QCOMPARE( page->search(QLatin1String("own"), left, top, right, bottom, direction, mode1), false );
+
+    QCOMPARE( page->search(QLatin1String("brOwn"), left, top, right, bottom, direction, mode2), true );
+    QCOMPARE( page->search(QLatin1String("brawn"), left, top, right, bottom, direction, mode2), false );
+
+    QCOMPARE( page->search(QLatin1String("brOwn"), left, top, right, bottom, direction, mode3), true );
+    QCOMPARE( page->search(QLatin1String("Own"), left, top, right, bottom, direction, mode3), false );
+}
+
 QTEST_MAIN(TestSearch)
 #include "check_search.moc"
 
-- 
2.2.1

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to