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

Hello again,

Am 11.01.2015 um 22:13 schrieb Albert Astals Cid:
> El Diumenge, 11 de gener de 2015, a les 22:04:53, Adam Reichold va
> escriure:
>> Hello,
>> 
>> Am 11.01.2015 um 21:50 schrieb Albert Astals Cid:
>>> El Diumenge, 11 de gener de 2015, a les 20:36:44, Adam Reichold
>>> va
>>> 
>>> escriure:
>>>> Hello,
>>>> 
>>>> Am 11.01.2015 um 20:19 schrieb Albert Astals Cid:
>>>>> El Diumenge, 11 de gener de 2015, a les 11:14:12, Adam
>>>>> Reichold va
>>>>> 
>>>>> escriure:
>>>>>> Hello again,
>>>>>> 
>>>>>> Am 11.01.2015 um 00:57 schrieb Albert Astals Cid:
>>>>>>> El Diumenge, 11 de gener de 2015, a les 00:37:36, Adam 
>>>>>>> Reichold va
>>>>>>> 
>>>>>>> escriure:
>>>>>>>> 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.
>>>>>>> 
>>>>>>> Meh, you're right, this is not good either since
>>>>>>> you're passing in SearchMode something that is not a
>>>>>>> SearchMode (it's the sum of two).
>>>>>>> 
>>>>>>> So yeah it'd be better to go the QFlags way. Maybe you
>>>>>>> can leave the old function there, mark it as deprecated
>>>>>>> and say that it only obeys the sensitiviness part and
>>>>>>> add a new function that accepts the qflags?
>>>>>> 
>>>>>> Ok, attached is the patch which adds a new flags type 
>>>>>> SearchFlags and corresponding overloads to the Qt4
>>>>>> frontend. I try to factor out as much common code as
>>>>>> possible and add a test case as well. I'll add the Qt5
>>>>>> frontend as soon we think the approach is sound.
>>>>>> 
>>>>>> I chose to use a new enumeration SearchFlag instead of 
>>>>>> SearchMode since the symmetry of SearchMode does not
>>>>>> really make sense if there are several non-exclusive
>>>>>> flags.
>>>>> 
>>>>> Yep, now thinking out loud, would it make sense to merge 
>>>>> SearchDirection in there too? The three enums are also 
>>>>> exclusive one another.
>>>> 
>>>> I don't think this would work, since the range of 
>>>> "SearchDirection" has more than two elements and hence would
>>>> need at least two flags but then those would not be
>>>> exclusive. E.g. I'd add two flags "NextResult" and
>>>> "PreviousResult" with "FromTop" as the default, but then the
>>>> user could specify "NextResult | PreviousResult" which does
>>>> not make sense?
>>> 
>>> Ok, let's leave it as you suggested, bring back the tests
>>> (adding uses for both deprecated and non deprecated versions)
>>> and the qt5 side and it looks good to me.
>> 
>> Ok, can you be more specific about which additional test cases
>> you'd like to have? (The ones from the previous design are
>> included already.) I'll then add them during the week.
>> ("WholeWords" won't work with the deprecated methods, but I could
>> add test cases for case sensitivity alone and also the
>> list-returning variants.)
> 
> I'd like to have the old tests but using the new non deprecated
> calls (not sure if that was added in the email that crossed the
> intewebs with my other email).

Sorry, that took me a minute to get... :-) Attached is the patch with
the search tests adjusted to use non-deprecated methods.

Best regards, Adam.

> Cheers, Albert
> 
>> 
>> Best regards, Adam.
>> 
>>> Cheers, Albert
>>> 
>>>> Best regards, Adam.
>>>> 
>>>>> But on the other hand it may feel a bit shoehorned.
>>>>> 
>>>>> What do you think?
>>>>> 
>>>>> Cheer,s Albert
>>>>> 
>>>>>> Best regards, Adam.
>>>>>> 
>>>>>>> Cheers, Albert
>>>>>>> 
>>>>>>>> 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
>>>>>>>
>>>>>>>
>>>>>>>>> 
_______________________________________________ poppler
>>>>>>> mailing list [email protected] 
>>>>>>> http://lists.freedesktop.org/mailman/listinfo/poppler
>>>>> 
>>>>> _______________________________________________ poppler 
>>>>> mailing list [email protected] 
>>>>> http://lists.freedesktop.org/mailman/listinfo/poppler
>>>> 
>>>> _______________________________________________ poppler
>>>> mailing list [email protected] 
>>>> http://lists.freedesktop.org/mailman/listinfo/poppler
>>> 
>>> _______________________________________________ poppler
>>> mailing list [email protected] 
>>> http://lists.freedesktop.org/mailman/listinfo/poppler
>> 
>> _______________________________________________ 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

iQEcBAEBCAAGBQJUsut/AAoJEPSSjE3STU34E4cIALJKcQuJxK3CVsfwIMDAxniZ
dpDiSn2Fh1YG0CoBRFfrjRosmv9neUqtSOLurJM93zO463+otXSuMMyUI3QCCeZJ
JBvUG1c2ky4DujCfnQloW27EUi2UPhzM47bWd1UHQwU9QBLCPgcknsneoO/YeYX6
022o4Dq+q4gtq6S43grUJVb67OC5oI33M9TGlMrWh7eDAIrEKXN1t/+zfNaT7e8G
L211ccNHvO7/apVDXIsiCObSpdDn8u4R84f2O47PCPTCkyYXMnLd/bLl8hBt0lS4
P7nMqmyZ4y5TLgvTXwL1XhvCpISja3UixJu9r70vhRV5UB3E9nd45G63O3CkSFc=
=In65
-----END PGP SIGNATURE-----
>From f06b9a42a536b2699ddf8100b0fa4af41e91a98f Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 11 Jan 2015 11:08:37 +0100
Subject: [PATCH 1/3] Expose whole-words find option in Qt4 frontend

Adds a SearchFlags flag type and corresponding overloads to the Qt4 frontend
so that callers can indicate whole-words matching in addition to case sensitivity.
---
 qt4/src/poppler-page-private.h |   4 +-
 qt4/src/poppler-page.cc        | 112 ++++++++++++++++++++++++++++-------------
 qt4/src/poppler-qt4.h          |  42 +++++++++++++++-
 qt4/tests/check_search.cpp     |  31 ++++++++++++
 4 files changed, 151 insertions(+), 38 deletions(-)

diff --git a/qt4/src/poppler-page-private.h b/qt4/src/poppler-page-private.h
index 91955e0..ef467e5 100644
--- a/qt4/src/poppler-page-private.h
+++ b/qt4/src/poppler-page-private.h
@@ -46,7 +46,9 @@ 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::Rotation rotate, QVector<Unicode> *u);
+  GBool performSingleTextSearch(TextPage* textPage, QVector<Unicode> &u, double &sLeft, double &sTop, double &sRight, double &sBottom, Page::SearchDirection direction, GBool sCase, GBool sWords);
+  QList<QRectF> performMultipleTextSearch(TextPage* textPage, QVector<Unicode> &u, GBool sCase, GBool sWords);
 };
 
 }
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index fc928b9..4a0e689 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -215,16 +215,13 @@ 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)
+inline TextPage *PageData::prepareTextSearch(const QString &text, Page::Rotation rotate, 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
@@ -234,7 +231,43 @@ TextPage *PageData::prepareTextSearch(const QString &text, Page::SearchMode case
   TextPage *textPage=td.takeText();
   
   return textPage;
-} 
+}
+
+inline GBool PageData::performSingleTextSearch(TextPage* textPage, QVector<Unicode> &u, double &sLeft, double &sTop, double &sRight, double &sBottom, Page::SearchDirection direction, GBool sCase, GBool sWords)
+{
+  if (direction == Page::FromTop)
+    return textPage->findText( u.data(), u.size(),
+           gTrue, gTrue, gFalse, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom );
+  else if ( direction == Page::NextResult )
+    return textPage->findText( u.data(), u.size(),
+           gFalse, gTrue, gTrue, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom );
+  else if ( direction == Page::PreviousResult )
+    return textPage->findText( u.data(), u.size(),
+           gFalse, gTrue, gTrue, gFalse, sCase, gTrue, sWords, &sLeft, &sTop, &sRight, &sBottom );
+
+  return gFalse;
+}
+
+inline QList<QRectF> PageData::performMultipleTextSearch(TextPage* textPage, QVector<Unicode> &u, GBool sCase, GBool sWords)
+{
+  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, sWords, &sLeft, &sTop, &sRight, &sBottom ))
+  {
+      QRectF result;
+
+      result.setLeft(sLeft);
+      result.setTop(sTop);
+      result.setRight(sRight);
+      result.setBottom(sBottom);
+
+      results.append(result);
+  }
+
+  return results;
+}
 
 Page::Page(DocumentData *doc, int index) {
   m_page = new PageData();
@@ -459,20 +492,27 @@ 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
 {
-  GBool sCase;
+  const GBool sCase = caseSensitive == Page::CaseSensitive ? gTrue : gFalse;
+
   QVector<Unicode> u;
-  TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &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 );
-  else if ( direction == NextResult )
-    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(), u.size(), 
-            gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse, &sLeft, &sTop, &sRight, &sBottom );
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
+
+  const bool found = m_page->performSingleTextSearch(textPage, u, sLeft, sTop, sRight, sBottom, direction, sCase, gFalse);
+
+  textPage->decRefCnt();
+
+  return found;
+}
+
+bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, SearchFlags flags, Rotation rotate) const
+{
+  const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
+  const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
+
+  QVector<Unicode> u;
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
+
+  const bool found = m_page->performSingleTextSearch(textPage, u, sLeft, sTop, sRight, sBottom, direction, sCase, sWords);
 
   textPage->decRefCnt();
 
@@ -499,31 +539,33 @@ bool Page::search(const QString &text, QRectF &rect, SearchDirection direction,
 
 QList<QRectF> Page::search(const QString &text, SearchMode caseSensitive, Rotation rotate) const
 {
-  GBool sCase;
+  const GBool sCase = caseSensitive == Page::CaseSensitive ? gTrue : gFalse;
+
   QVector<Unicode> u;
-  TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u);
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &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 ))
-  {
-      QRectF result;
-      
-      result.setLeft(sLeft);
-      result.setTop(sTop);
-      result.setRight(sRight);
-      result.setBottom(sBottom);
-      
-      results.append(result);
-  }
+  const QList<QRectF> results = m_page->performMultipleTextSearch(textPage, u, sCase, gFalse);
   
   textPage->decRefCnt();
 
   return results;
 }
 
+QList<QRectF> Page::search(const QString &text, SearchFlags flags, Rotation rotate) const
+{
+  const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
+  const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
+
+  QVector<Unicode> u;
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
+
+  const QList<QRectF> results = m_page->performMultipleTextSearch(textPage, u, sCase, sWords);
+
+  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 ee7558e..193b043 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -579,6 +579,16 @@ delete it;
 	enum SearchMode { CaseSensitive,   ///< Case differences cause no match in searching
 			  CaseInsensitive  ///< Case differences are ignored in matching
 	};
+
+        /**
+           Flags to modify the search behaviour \since 0.31
+        */
+        enum SearchFlag
+        {
+            IgnoreCase = 0x00000001,    ///< Case differences are ignored
+            WholeWorlds = 0x00000002    ///< Only whole words are matched
+        };
+        Q_DECLARE_FLAGS( SearchFlags, SearchFlag )
 	
 	/**
 	   Returns true if the specified text was found.
@@ -603,7 +613,21 @@ 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;
+        Q_DECL_DEPRECATED bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const;
+
+        /**
+           Returns true if the specified text was found.
+
+           \param text the text the search
+           \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 flags the flags to consider during matching
+           \param rotate the rotation to apply for the search order
+
+           \since 0.31
+        **/
+        bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchFlags flags = 0, Rotation rotate = Rotate0) const;
 	
 	/**
 	   Returns a list of all occurrences of the specified text on the page.
@@ -616,7 +640,20 @@ delete it;
 	   
 	   \since 0.22
 	**/
-	QList<QRectF> search(const QString &text, SearchMode caseSensitive, Rotation rotate = Rotate0) const;
+        Q_DECL_DEPRECATED QList<QRectF> search(const QString &text, 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 flags the flags to consider during matching
+           \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.31
+        **/
+        QList<QRectF> search(const QString &text, SearchFlags flags = 0, Rotation rotate = Rotate0) const;
 
 	/**
 	   Returns a list of text of the page
@@ -1826,6 +1863,7 @@ height = dummy.height();
 }
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Page::PainterFlags)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Page::SearchFlags)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Document::RenderHints)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PDFConverter::PDFOptions)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PSConverter::PSOptions)
diff --git a/qt4/tests/check_search.cpp b/qt4/tests/check_search.cpp
index cabf82d..98a1cec 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::SearchFlags mode0 = 0;
+    const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreCase;
+    const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWorlds;
+    const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase | Poppler::Page::WholeWorlds;
+
+    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("brawn"), left, top, right, bottom, direction, mode1), false );
+
+    QCOMPARE( page->search(QLatin1String("brown"), left, top, right, bottom, direction, mode2), true );
+    QCOMPARE( page->search(QLatin1String("own"), 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


>From c0ec4eeea97e6d9b74eb6e281b3fa03cc1be6c65 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 11 Jan 2015 21:37:19 +0100
Subject: [PATCH 2/3] Expose whole-words find option in Qt5 frontend

Adds a SearchFlags flag type and corresponding overloads to the Qt5 frontend
so that callers can indicate whole-words matching in addition to case sensitivity.
---
 qt5/src/poppler-page-private.h |   4 +-
 qt5/src/poppler-page.cc        | 114 ++++++++++++++++++++++++++++-------------
 qt5/src/poppler-qt5.h          |  44 ++++++++++++++--
 qt5/tests/check_search.cpp     |  31 +++++++++++
 4 files changed, 153 insertions(+), 40 deletions(-)

diff --git a/qt5/src/poppler-page-private.h b/qt5/src/poppler-page-private.h
index 91955e0..ef467e5 100644
--- a/qt5/src/poppler-page-private.h
+++ b/qt5/src/poppler-page-private.h
@@ -46,7 +46,9 @@ 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::Rotation rotate, QVector<Unicode> *u);
+  GBool performSingleTextSearch(TextPage* textPage, QVector<Unicode> &u, double &sLeft, double &sTop, double &sRight, double &sBottom, Page::SearchDirection direction, GBool sCase, GBool sWords);
+  QList<QRectF> performMultipleTextSearch(TextPage* textPage, QVector<Unicode> &u, GBool sCase, GBool sWords);
 };
 
 }
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index 6eea0d0..b3a453c 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -215,16 +215,13 @@ 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)
+inline TextPage *PageData::prepareTextSearch(const QString &text, Page::Rotation rotate, 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
@@ -232,9 +229,45 @@ TextPage *PageData::prepareTextSearch(const QString &text, Page::SearchMode case
   parentDoc->doc->displayPage( &td, index + 1, 72, 72, rotation, false, true, false,
     NULL, NULL, NULL, NULL, gTrue);
   TextPage *textPage=td.takeText();
-  
+
   return textPage;
-} 
+}
+
+inline GBool PageData::performSingleTextSearch(TextPage* textPage, QVector<Unicode> &u, double &sLeft, double &sTop, double &sRight, double &sBottom, Page::SearchDirection direction, GBool sCase, GBool sWords)
+{
+  if (direction == Page::FromTop)
+    return textPage->findText( u.data(), u.size(),
+           gTrue, gTrue, gFalse, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom );
+  else if ( direction == Page::NextResult )
+    return textPage->findText( u.data(), u.size(),
+           gFalse, gTrue, gTrue, gFalse, sCase, gFalse, sWords, &sLeft, &sTop, &sRight, &sBottom );
+  else if ( direction == Page::PreviousResult )
+    return textPage->findText( u.data(), u.size(),
+           gFalse, gTrue, gTrue, gFalse, sCase, gTrue, sWords, &sLeft, &sTop, &sRight, &sBottom );
+
+  return gFalse;
+}
+
+inline QList<QRectF> PageData::performMultipleTextSearch(TextPage* textPage, QVector<Unicode> &u, GBool sCase, GBool sWords)
+{
+  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, sWords, &sLeft, &sTop, &sRight, &sBottom ))
+  {
+      QRectF result;
+
+      result.setLeft(sLeft);
+      result.setTop(sTop);
+      result.setRight(sRight);
+      result.setBottom(sBottom);
+
+      results.append(result);
+  }
+
+  return results;
+}
 
 Page::Page(DocumentData *doc, int index) {
   m_page = new PageData();
@@ -459,20 +492,27 @@ 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
 {
-  GBool sCase;
+  const GBool sCase = caseSensitive == Page::CaseSensitive ? gTrue : gFalse;
+
   QVector<Unicode> u;
-  TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &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 );
-  else if ( direction == NextResult )
-    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(), u.size(), 
-            gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse, &sLeft, &sTop, &sRight, &sBottom );
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
+
+  const bool found = m_page->performSingleTextSearch(textPage, u, sLeft, sTop, sRight, sBottom, direction, sCase, gFalse);
+
+  textPage->decRefCnt();
+
+  return found;
+}
+
+bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRight, double &sBottom, SearchDirection direction, SearchFlags flags, Rotation rotate) const
+{
+  const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
+  const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
+
+  QVector<Unicode> u;
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
+
+  const bool found = m_page->performSingleTextSearch(textPage, u, sLeft, sTop, sRight, sBottom, direction, sCase, sWords);
 
   textPage->decRefCnt();
 
@@ -481,31 +521,33 @@ bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRig
 
 QList<QRectF> Page::search(const QString &text, SearchMode caseSensitive, Rotation rotate) const
 {
-  GBool sCase;
+  const GBool sCase = caseSensitive == Page::CaseSensitive ? gTrue : gFalse;
+
   QVector<Unicode> u;
-  TextPage *textPage = m_page->prepareTextSearch(text, caseSensitive, rotate, &sCase, &u);
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &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 ))
-  {
-      QRectF result;
-      
-      result.setLeft(sLeft);
-      result.setTop(sTop);
-      result.setRight(sRight);
-      result.setBottom(sBottom);
-      
-      results.append(result);
-  }
+  const QList<QRectF> results = m_page->performMultipleTextSearch(textPage, u, sCase, gFalse);
   
   textPage->decRefCnt();
 
   return results;
 }
 
+QList<QRectF> Page::search(const QString &text, SearchFlags flags, Rotation rotate) const
+{
+  const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
+  const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
+
+  QVector<Unicode> u;
+  TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
+
+  const QList<QRectF> results = m_page->performMultipleTextSearch(textPage, u, sCase, sWords);
+
+  textPage->decRefCnt();
+
+  return results;
+}
+
 QList<TextBox*> Page::textList(Rotation rotate) const
 {
   TextOutputDev *output_dev;
diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h
index dee0b19..f0ba399 100644
--- a/qt5/src/poppler-qt5.h
+++ b/qt5/src/poppler-qt5.h
@@ -580,6 +580,16 @@ delete it;
 	enum SearchMode { CaseSensitive,   ///< Case differences cause no match in searching
 			  CaseInsensitive  ///< Case differences are ignored in matching
 	};
+
+        /**
+           Flags to modify the search behaviour \since 0.31
+        */
+        enum SearchFlag
+        {
+            IgnoreCase = 0x00000001,    ///< Case differences are ignored
+            WholeWorlds = 0x00000002    ///< Only whole words are matched
+        };
+        Q_DECLARE_FLAGS( SearchFlags, SearchFlag )
 	
 	/**
 	   Returns true if the specified text was found.
@@ -592,8 +602,22 @@ 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;
-	
+        Q_DECL_DEPRECATED bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const;
+
+        /**
+           Returns true if the specified text was found.
+
+           \param text the text the search
+           \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 flags the flags to consider during matching
+           \param rotate the rotation to apply for the search order
+
+           \since 0.31
+        **/
+        bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchFlags flags = 0, Rotation rotate = Rotate0) const;
+
 	/**
 	   Returns a list of all occurrences of the specified text on the page.
 	   
@@ -605,7 +629,20 @@ delete it;
 	   
 	   \since 0.22
 	**/
-	QList<QRectF> search(const QString &text, SearchMode caseSensitive, Rotation rotate = Rotate0) const;
+        Q_DECL_DEPRECATED QList<QRectF> search(const QString &text, 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 flags the flags to consider during matching
+           \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.31
+        **/
+        QList<QRectF> search(const QString &text, SearchFlags flags = 0, Rotation rotate = Rotate0) const;
 
 	/**
 	   Returns a list of text of the page
@@ -1787,6 +1824,7 @@ height = dummy.height();
 }
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Page::PainterFlags)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Page::SearchFlags)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Document::RenderHints)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PDFConverter::PDFOptions)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PSConverter::PSOptions)
diff --git a/qt5/tests/check_search.cpp b/qt5/tests/check_search.cpp
index efb5556..d23b208 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 testWholeWordsOnly();
 };
 
 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::SearchFlags mode0 = 0;
+    const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreCase;
+    const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWorlds;
+    const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase | Poppler::Page::WholeWorlds;
+
+    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("brawn"), left, top, right, bottom, direction, mode1), false );
+
+    QCOMPARE( page->search(QLatin1String("brown"), left, top, right, bottom, direction, mode2), true );
+    QCOMPARE( page->search(QLatin1String("own"), 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


>From 3fde936641a9ccbadb2accd33665cddb61464946 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 11 Jan 2015 22:28:47 +0100
Subject: [PATCH 3/3] Make Qt4/5 search tests deprecation free

---
 qt4/tests/check_search.cpp | 134 ++++++++++++++++++++++-----------------------
 qt5/tests/check_search.cpp |  83 +++++++++++++---------------
 2 files changed, 103 insertions(+), 114 deletions(-)

diff --git a/qt4/tests/check_search.cpp b/qt4/tests/check_search.cpp
index 98a1cec..c7e283c 100644
--- a/qt4/tests/check_search.cpp
+++ b/qt4/tests/check_search.cpp
@@ -13,78 +13,76 @@ private slots:
 
 void TestSearch::bug7063()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf");
-    QVERIFY( doc );
-   
-    Poppler::Page *page = doc->page(0);
-    QRectF pageRegion( QPointF(0,0), page->pageSize() );
-
-    QCOMPARE( page->search(QString("non-ascii:"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-
-    QCOMPARE( page->search(QString("Ascii"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), false );
-    QCOMPARE( page->search(QString("Ascii"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseInsensitive), true );
-
-    QCOMPARE( page->search(QString("latin1:"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), false );
-
-    QCOMPARE( page->search(QString::fromUtf8("é"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("à"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("ç"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("search \"é\", \"à\" or \"ç\""), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("¥µ©"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("¥©"), pageRegion, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), false );
-  
-    delete doc;
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
+
+    double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
+
+    QCOMPARE( page->search(QString("non-ascii:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+
+    QCOMPARE( page->search(QString("Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false );
+    QCOMPARE( page->search(QString("Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::IgnoreCase), true );
+
+    QCOMPARE( page->search(QString("latin1:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false );
+
+    QCOMPARE( page->search(QString::fromUtf8("é"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("à"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("ç"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("search \"é\", \"à\" or \"ç\""), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("¥µ©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("¥©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false );
 }
 
 void TestSearch::testNextAndPrevious()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf");
-    QVERIFY( doc );
-  
-    Poppler::Page *page = doc->page(0);
-    QRectF region( QPointF(0,0), page->pageSize() );
-    
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 161.44) < 0.01 );
-    QVERIFY( qAbs(region.y() - 127.85) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 171.46) < 0.01 );
-    QVERIFY( qAbs(region.y() - 127.85) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 161.44) < 0.01 );
-    QVERIFY( qAbs(region.y() - 139.81) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 171.46) < 0.01 );
-    QVERIFY( qAbs(region.y() - 139.81) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), false );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 161.44) < 0.01 );
-    QVERIFY( qAbs(region.y() - 139.81) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 171.46) < 0.01 );
-    QVERIFY( qAbs(region.y() - 127.85) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), true );
-    QVERIFY( qAbs(region.x() - 161.44) < 0.01 );
-    QVERIFY( qAbs(region.y() - 127.85) < 0.01 );
-    QVERIFY( qAbs(region.width() - 6.70) < 0.01 );
-    QVERIFY( qAbs(region.height() - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), region, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), false );
-    
-    delete doc;
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
+
+    double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
+
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
+    QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true );
+    QVERIFY( qAbs(rectLeft - 171.46) < 0.01 );
+    QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true );
+    QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
+    QVERIFY( qAbs(rectTop - 139.81) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true );
+    QVERIFY( qAbs(rectLeft - 171.46) < 0.01 );
+    QVERIFY( qAbs(rectTop - 139.81) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), false );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true );
+    QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
+    QVERIFY( qAbs(rectTop - 139.81) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true );
+    QVERIFY( qAbs(rectLeft - 171.46) < 0.01 );
+    QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true );
+    QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
+    QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
+    QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
+    QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), false );
 }
 
 void TestSearch::testWholeWordsOnly()
diff --git a/qt5/tests/check_search.cpp b/qt5/tests/check_search.cpp
index d23b208..ca7fce3 100644
--- a/qt5/tests/check_search.cpp
+++ b/qt5/tests/check_search.cpp
@@ -13,85 +13,76 @@ private slots:
 
 void TestSearch::bug7063()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf");
-    QVERIFY( doc );
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
    
-    Poppler::Page *page = doc->page(0);
-    double rectLeft, rectTop, rectRight, rectBottom;
-    rectLeft = 0;
-    rectTop = 0;
-    rectRight = page->pageSize().width();
-    rectBottom = page->pageSize().height();
-    QCOMPARE( page->search(QString("non-ascii:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-
-    QCOMPARE( page->search(QString("Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), false );
-    QCOMPARE( page->search(QString("Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseInsensitive), true );
-
-    QCOMPARE( page->search(QString("latin1:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), false );
-
-    QCOMPARE( page->search(QString::fromUtf8("é"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("à"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("ç"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("search \"é\", \"à\" or \"ç\""), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("¥µ©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
-    QCOMPARE( page->search(QString::fromUtf8("¥©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), false );
-  
-    delete doc;
+    double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
+
+    QCOMPARE( page->search(QString("non-ascii:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+
+    QCOMPARE( page->search(QString("Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false );
+    QCOMPARE( page->search(QString("Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::IgnoreCase), true );
+
+    QCOMPARE( page->search(QString("latin1:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false );
+
+    QCOMPARE( page->search(QString::fromUtf8("é"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("à"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("ç"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("search \"é\", \"à\" or \"ç\""), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("¥µ©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
+    QCOMPARE( page->search(QString::fromUtf8("¥©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false );
 }
 
 void TestSearch::testNextAndPrevious()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf");
-    QVERIFY( doc );
-  
-    Poppler::Page *page = doc->page(0);
-    double rectLeft, rectTop, rectRight, rectBottom;
-    rectLeft = 0;
-    rectTop = 0;
-    rectRight = page->pageSize().width();
-    rectBottom = page->pageSize().height();
-    
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::CaseSensitive), true );
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
+
+    double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
+
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true );
     QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
     QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), true );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true );
     QVERIFY( qAbs(rectLeft - 171.46) < 0.01 );
     QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), true );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true );
     QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
     QVERIFY( qAbs(rectTop - 139.81) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), true );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true );
     QVERIFY( qAbs(rectLeft - 171.46) < 0.01 );
     QVERIFY( qAbs(rectTop - 139.81) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult, Poppler::Page::CaseSensitive), false );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), true );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), false );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true );
     QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
     QVERIFY( qAbs(rectTop - 139.81) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), true );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true );
     QVERIFY( qAbs(rectLeft - 171.46) < 0.01 );
     QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), true );
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true );
     QVERIFY( qAbs(rectLeft - 161.44) < 0.01 );
     QVERIFY( qAbs(rectTop - 127.85) < 0.01 );
     QVERIFY( qAbs(rectRight - rectLeft - 6.70) < 0.01 );
     QVERIFY( qAbs(rectBottom - rectTop - 8.85) < 0.01 );
-    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult, Poppler::Page::CaseSensitive), false );
-    
-    delete doc;
+    QCOMPARE( page->search(QString("is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), false );
 }
 
 void TestSearch::testWholeWordsOnly()
-- 
2.2.1

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

Reply via email to