summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-16 19:45:41 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-01 12:21:20 +0200
commit4062b3f87689e48fd250d9cf0297a24b5427bf59 (patch)
treeacf2965ce607284032fc2d587ccf1109ca4000b8
parent115655a09868d5977f740995d88e36d958f30bb5 (diff)
vcl: VectorGraphicSearch - add search result selection rectangles
Change-Id: Ia0c5610f600719bcfb5de503f3876fc896cb630a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95256 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--include/vcl/VectorGraphicSearch.hxx3
-rw-r--r--vcl/qa/cppunit/VectorGraphicSearchTest.cxx23
-rw-r--r--vcl/source/graphic/VectorGraphicSearch.cxx49
3 files changed, 74 insertions, 1 deletions
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 53127b85d9c1..a00df2555fb5 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: */