include/vcl/VectorGraphicSearch.hxx        |    3 +
 vcl/qa/cppunit/VectorGraphicSearchTest.cxx |   23 +++++++++++++
 vcl/source/graphic/VectorGraphicSearch.cxx |   49 ++++++++++++++++++++++++++++-
 3 files changed, 74 insertions(+), 1 deletion(-)

New commits:
commit 423cf93f347528e11a538b927e7587ab06e30e5b
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat May 16 19:45:41 2020 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Sat May 16 19:45:41 2020 +0200

    vcl: VectorGraphicSearch - add search result selection rectangles
    
    Change-Id: Ia0c5610f600719bcfb5de503f3876fc896cb630a

diff --git a/include/vcl/VectorGraphicSearch.hxx 
b/include/vcl/VectorGraphicSearch.hxx
index 6c2589db1d01..41c7745d0cf5 100644
--- a/include/vcl/VectorGraphicSearch.hxx
+++ b/include/vcl/VectorGraphicSearch.hxx
@@ -14,6 +14,8 @@
 #include <vcl/vectorgraphicdata.hxx>
 #include <vcl/dllapi.h>
 
+#include <basegfx/range/b2drectangle.hxx>
+
 #include <memory>
 
 class SearchContext;
@@ -34,6 +36,7 @@ public:
     bool search(OUString const& rSearchString);
     bool next();
     int index();
+    std::vector<basegfx::B2DRectangle> getTextRectangles();
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx 
b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
index 0ed21ccf9e26..112748d23bbe 100644
--- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
+++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
@@ -9,6 +9,7 @@
 
 #include <cppunit/TestAssert.h>
 #include <cppunit/extensions/HelperMacros.h>
+
 #include <unotest/bootstrapfixturebase.hxx>
 #include <unotest/directories.hxx>
 
@@ -43,6 +44,28 @@ void VectorGraphicSearchTest::test()
     CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy"));
     CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
     CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+    auto aRectangles = aSearch.getTextRectangles();
+    CPPUNIT_ASSERT_EQUAL(size_t(4), aRectangles.size());
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(229.00, aRectangles[0].getMinX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(231.85, aRectangles[0].getMaxX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(724.10, aRectangles[0].getMinY(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(732.42, aRectangles[0].getMaxY(), 1E-2);
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(232.47, aRectangles[1].getMinX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(237.22, aRectangles[1].getMaxX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(723.99, aRectangles[1].getMinY(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(729.72, aRectangles[1].getMaxY(), 1E-2);
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(237.68, aRectangles[2].getMinX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(242.35, aRectangles[2].getMaxX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(724.09, aRectangles[2].getMinY(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(729.60, aRectangles[2].getMaxY(), 1E-2);
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(242.81, aRectangles[3].getMinX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(248.61, aRectangles[3].getMaxX(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(721.51, aRectangles[3].getMinY(), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(729.60, aRectangles[3].getMaxY(), 1E-2);
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(VectorGraphicSearchTest);
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx 
b/vcl/source/graphic/VectorGraphicSearch.cxx
index 34ac0abd6654..8e90145cbecb 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -8,9 +8,10 @@
  *
  */
 
-#include <sal/config.h>
 #include <vcl/VectorGraphicSearch.hxx>
 
+#include <sal/config.h>
+
 #include <fpdf_doc.h>
 #include <fpdf_text.h>
 
@@ -93,6 +94,44 @@ public:
             return FPDFText_GetSchResultIndex(mpSearchHandle);
         return -1;
     }
+
+    int size()
+    {
+        if (mpSearchHandle)
+            return FPDFText_GetSchCount(mpSearchHandle);
+        return -1;
+    }
+
+    std::vector<basegfx::B2DRectangle> getTextRectangles()
+    {
+        std::vector<basegfx::B2DRectangle> aRectangles;
+
+        if (!mpTextPage || !mpSearchHandle)
+            return aRectangles;
+
+        int nIndex = index();
+        if (nIndex < 0)
+            return aRectangles;
+
+        int nSize = size();
+        if (nSize <= 0)
+            return aRectangles;
+
+        for (int nCount = 0; nCount < nSize; nCount++)
+        {
+            double left = 0.0;
+            double right = 0.0;
+            double bottom = 0.0;
+            double top = 0.0;
+
+            if (FPDFText_GetCharBox(mpTextPage, nIndex + nCount, &left, 
&right, &bottom, &top))
+            {
+                aRectangles.emplace_back(left, bottom, right, top);
+            }
+        }
+
+        return aRectangles;
+    }
 };
 
 VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic)
@@ -182,4 +221,12 @@ int VectorGraphicSearch::index()
     return -1;
 }
 
+std::vector<basegfx::B2DRectangle> VectorGraphicSearch::getTextRectangles()
+{
+    if (mpSearchContext)
+        return mpSearchContext->getTextRectangles();
+
+    return std::vector<basegfx::B2DRectangle>();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to