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

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
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJUsab1AAoJEPSSjE3STU34+LgH/jA0PKoylbSdEELNtqa1Nzv4
FD2HOs9uJnQmthwp/jODVw67OE22+ejyCiCjng6p/nKqv2Z33dEP/c+WzQzAYX8h
uXnZWtLLBi1lm9V2ZuJf8L/27UnYcCVzCBqSCdUaHPjxM//7HrSkG/f9DMBhQdpi
/m4aUAxT3eT5+zRhmKp9Ta15nnyaMych80LveU+Gff3/Iowt5QBtGDsfRnI6+/wX
LclmwTX4Zj5Bapqdq5Xtxgv8MySbP498EqEag+SjdlsTpD8tdOyLjDCz9iFlLWR5
v326fOwuXozMnbfCh6ECpkuMQoOePZNfspKka+t8rHYMjeOWjMc5/9yXscZ2zW4=
=XHoI
-----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/3] 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/3] 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/3] 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

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

Reply via email to