[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - 6 commits - include/svx include/tools include/vcl svx/source vcl/qa vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jul 30 05:06:35 UTC 2020
include/svx/svdmrkv.hxx | 6 -
include/tools/UnitConversion.hxx | 13 ++-
include/vcl/VectorGraphicSearch.hxx | 9 +-
svx/source/svdraw/svdmrkv.cxx | 24 ++----
vcl/qa/cppunit/VectorGraphicSearchTest.cxx | 36 +++++++++
vcl/source/graphic/VectorGraphicSearch.cxx | 115 ++++++++++++++++++++++++++---
6 files changed, 171 insertions(+), 32 deletions(-)
New commits:
commit b8c7fdfb00858d16db4796c23c77a33211f7244c
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed May 27 12:54:54 2020 +0200
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Jul 29 23:01:29 2020 +0200
svx: convert ImplMarkingOverlay and friends to use unique_ptr
Change-Id: I19ba9e93f2804fded237b760a28f3ce62e4b2c5f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95305
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit a6c0dc079700d662e14d422d18c6c3a9c2c3b7af)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95916
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 716fa0cc58a39a9975a6827088e9209b7b3311e6)
diff --git a/include/svx/svdmrkv.hxx b/include/svx/svdmrkv.hxx
index 94608620e6b1..c66ddf5bca8e 100644
--- a/include/svx/svdmrkv.hxx
+++ b/include/svx/svdmrkv.hxx
@@ -94,9 +94,9 @@ class SVX_DLLPUBLIC SdrMarkView : public SdrSnapView
friend class SdrPageView;
// #114409#-3 Migrate selections
- ImplMarkingOverlay* mpMarkObjOverlay;
- ImplMarkingOverlay* mpMarkPointsOverlay;
- ImplMarkingOverlay* mpMarkGluePointsOverlay;
+ std::unique_ptr<ImplMarkingOverlay> mpMarkObjOverlay;
+ std::unique_ptr<ImplMarkingOverlay> mpMarkPointsOverlay;
+ std::unique_ptr<ImplMarkingOverlay> mpMarkGluePointsOverlay;
protected:
SdrObject* mpMarkedObj; // If not just one object ( i.e. More than one object ) is marked.
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 8c23ae2b114d..4871df93b629 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -161,9 +161,6 @@ SdrMarkView::SdrMarkView(
SdrModel& rSdrModel,
OutputDevice* pOut)
: SdrSnapView(rSdrModel, pOut),
- mpMarkObjOverlay(nullptr),
- mpMarkPointsOverlay(nullptr),
- mpMarkGluePointsOverlay(nullptr),
maHdlList(this)
{
ImpClearVars();
@@ -360,10 +357,10 @@ void SdrMarkView::BegMarkObj(const Point& rPnt, bool bUnmark)
{
BrkAction();
- DBG_ASSERT(nullptr == mpMarkObjOverlay, "SdrMarkView::BegMarkObj: There exists a mpMarkObjOverlay (!)");
+ DBG_ASSERT(!mpMarkObjOverlay, "SdrMarkView::BegMarkObj: There exists a mpMarkObjOverlay (!)");
basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
- mpMarkObjOverlay = new ImplMarkingOverlay(*this, aStartPos, bUnmark);
+ mpMarkObjOverlay.reset(new ImplMarkingOverlay(*this, aStartPos, bUnmark));
maDragStat.Reset(rPnt);
maDragStat.NextPoint();
@@ -407,8 +404,7 @@ void SdrMarkView::BrkMarkObj()
if(IsMarkObj())
{
DBG_ASSERT(mpMarkObjOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
- delete mpMarkObjOverlay;
- mpMarkObjOverlay = nullptr;
+ mpMarkObjOverlay.reset();
}
}
@@ -419,9 +415,9 @@ bool SdrMarkView::BegMarkPoints(const Point& rPnt, bool bUnmark)
{
BrkAction();
- DBG_ASSERT(nullptr == mpMarkPointsOverlay, "SdrMarkView::BegMarkObj: There exists a mpMarkPointsOverlay (!)");
+ DBG_ASSERT(!mpMarkPointsOverlay, "SdrMarkView::BegMarkObj: There exists a mpMarkPointsOverlay (!)");
basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
- mpMarkPointsOverlay = new ImplMarkingOverlay(*this, aStartPos, bUnmark);
+ mpMarkPointsOverlay.reset(new ImplMarkingOverlay(*this, aStartPos, bUnmark));
maDragStat.Reset(rPnt);
maDragStat.NextPoint();
@@ -472,8 +468,7 @@ void SdrMarkView::BrkMarkPoints()
if(IsMarkPoints())
{
DBG_ASSERT(mpMarkPointsOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
- delete mpMarkPointsOverlay;
- mpMarkPointsOverlay = nullptr;
+ mpMarkPointsOverlay.reset();
}
}
@@ -484,10 +479,10 @@ bool SdrMarkView::BegMarkGluePoints(const Point& rPnt, bool bUnmark)
{
BrkAction();
- DBG_ASSERT(nullptr == mpMarkGluePointsOverlay, "SdrMarkView::BegMarkObj: There exists a mpMarkGluePointsOverlay (!)");
+ DBG_ASSERT(!mpMarkGluePointsOverlay, "SdrMarkView::BegMarkObj: There exists a mpMarkGluePointsOverlay (!)");
basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
- mpMarkGluePointsOverlay = new ImplMarkingOverlay(*this, aStartPos, bUnmark);
+ mpMarkGluePointsOverlay.reset(new ImplMarkingOverlay(*this, aStartPos, bUnmark));
maDragStat.Reset(rPnt);
maDragStat.NextPoint();
maDragStat.SetMinMove(mnMinMovLog);
@@ -531,8 +526,7 @@ void SdrMarkView::BrkMarkGluePoints()
if(IsMarkGluePoints())
{
DBG_ASSERT(mpMarkGluePointsOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
- delete mpMarkGluePointsOverlay;
- mpMarkGluePointsOverlay = nullptr;
+ mpMarkGluePointsOverlay.reset();
}
}
commit c0eab53fe745b5fbb66b950ae549e5a2466bd060
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat May 23 11:54:01 2020 +0200
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Jul 29 20:46:49 2020 +0200
vcl: add conversion point to twip int64 & double values
Change-Id: Id54d28b57c055269259317521f59d37dcdf9a456
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95274
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 5f8f8889a47a7079fc1beaa179e29cc32aa10e0e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95914
(cherry picked from commit 37543a1bad3122461fd7b2ebe61f4a60e16a4ba4)
diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx
index 2093db6181d9..2585fecbb590 100644
--- a/include/tools/UnitConversion.hxx
+++ b/include/tools/UnitConversion.hxx
@@ -20,11 +20,15 @@ constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
return (n >= 0) ? (n * 72 + 63) / 127 : (n * 72 - 63) / 127;
}
+constexpr sal_Int64 convertPointToTwip(sal_Int64 nNumber) { return nNumber * 20; }
+
constexpr sal_Int64 convertPointToMm100(sal_Int64 nNumber)
{
- return convertTwipToMm100(nNumber * 20);
+ return convertTwipToMm100(convertPointToTwip(nNumber));
}
+constexpr double convertPointToTwip(double fNumber) { return fNumber * 20.0; }
+
constexpr double convertPointToMm100(double fNumber) { return fNumber * 35.27777777778; }
// Convert PPT's "master unit" (1/576 inch) to twips
commit 0bcca08d53d6f67f5021ea888ea096ec9ac21ba8
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun May 17 20:32:49 2020 +0200
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Jul 29 20:46:07 2020 +0200
vcl: VectorGraphicSearch return text rectangles in 100th mm
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95261
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 936a670f61fed891f8aaec77b2422f366240f193)
Change-Id: I12e7ad10dc3ed68d20d94713acece1361da27e81
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95834
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit f73fef6b9b519adaadf51abb5aa1fb3dd0cda9a9)
diff --git a/include/vcl/VectorGraphicSearch.hxx b/include/vcl/VectorGraphicSearch.hxx
index 41c7745d0cf5..5420e161448b 100644
--- a/include/vcl/VectorGraphicSearch.hxx
+++ b/include/vcl/VectorGraphicSearch.hxx
@@ -15,6 +15,7 @@
#include <vcl/dllapi.h>
#include <basegfx/range/b2drectangle.hxx>
+#include <basegfx/vector/b2dsize.hxx>
#include <memory>
@@ -34,6 +35,7 @@ public:
VectorGraphicSearch(Graphic const& rGraphic);
~VectorGraphicSearch();
bool search(OUString const& rSearchString);
+ basegfx::B2DSize pageSize();
bool next();
int index();
std::vector<basegfx::B2DRectangle> getTextRectangles();
diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
index 112748d23bbe..01022a3fe225 100644
--- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
+++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
@@ -44,28 +44,41 @@ void VectorGraphicSearchTest::test()
CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy"));
CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ basegfx::B2DSize aSize = aSearch.pageSize();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(21590.00, aSize.getX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(27940.00, aSize.getY(), 1E-2);
+
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);
+ // Check first and last
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8078.61, aRectangles[0].getMinX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8179.36, aRectangles[0].getMaxX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2101.56, aRectangles[0].getMinY(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2395.36, aRectangles[0].getMaxY(), 1E-2);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8565.86, aRectangles[3].getMinX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8770.76, aRectangles[3].getMaxX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2201.05, aRectangles[3].getMinY(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2486.37, aRectangles[3].getMaxY(), 1E-2);
+
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+
+ aRectangles = aSearch.getTextRectangles();
+ CPPUNIT_ASSERT_EQUAL(size_t(4), aRectangles.size());
+
+ // Check first and last
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6562.23, aRectangles[0].getMinX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6662.98, aRectangles[0].getMaxX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(5996.23, aRectangles[0].getMinY(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6290.02, aRectangles[0].getMaxY(), 1E-2);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(7049.48, aRectangles[3].getMinX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(7254.38, aRectangles[3].getMaxX(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6095.71, aRectangles[3].getMinY(), 1E-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6381.04, 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 a00df2555fb5..d54f32930276 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -64,6 +64,22 @@ public:
FPDF_ClosePage(mpPage);
}
+ basegfx::B2DSize getPageSize()
+ {
+ basegfx::B2DSize aSize;
+ if (!mpPdfDocument)
+ return aSize;
+
+ double fPageWidth = 0;
+ double fPageHeight = 0;
+ if (FPDF_GetPageSizeByIndex(mpPdfDocument, mnPageIndex, &fPageWidth, &fPageHeight))
+ {
+ aSize = basegfx::B2DSize(convertPointToMm100(fPageWidth),
+ convertPointToMm100(fPageHeight));
+ }
+ return aSize;
+ }
+
bool initialize()
{
if (!mpPdfDocument)
@@ -117,6 +133,8 @@ public:
if (nSize <= 0)
return aRectangles;
+ double fPageHeight = getPageSize().getY();
+
for (int nCount = 0; nCount < nSize; nCount++)
{
double left = 0.0;
@@ -126,6 +144,11 @@ public:
if (FPDFText_GetCharBox(mpTextPage, nIndex + nCount, &left, &right, &bottom, &top))
{
+ left = convertPointToMm100(left);
+ right = convertPointToMm100(right);
+ top = fPageHeight - convertPointToMm100(top);
+ bottom = fPageHeight - convertPointToMm100(bottom);
+
aRectangles.emplace_back(left, bottom, right, top);
}
}
@@ -207,6 +230,14 @@ bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rD
return mpSearchContext->initialize();
}
+basegfx::B2DSize VectorGraphicSearch::pageSize()
+{
+ basegfx::B2DSize aSize;
+ if (mpSearchContext)
+ aSize = mpSearchContext->getPageSize();
+ return aSize;
+}
+
bool VectorGraphicSearch::next()
{
if (mpSearchContext)
commit 6cfffc0cfd30792e1e7d26bff3a5abf132e74761
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat May 16 19:45:41 2020 +0200
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Jul 29 20:45:52 2020 +0200
vcl: VectorGraphicSearch - add search result selection rectangles
Change-Id: Ia0c5610f600719bcfb5de503f3876fc896cb630a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95256
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 4062b3f87689e48fd250d9cf0297a24b5427bf59)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95833
(cherry picked from commit 4d823e2cfa3171a54f20c313d7670be8ed9fa604)
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: */
commit f37819fbf3a2713ef699062e5cd8c482891aa57d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri May 15 12:20:42 2020 +0200
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Jul 29 20:45:11 2020 +0200
vcl: Add internal "Implementation" class for VectorGraphicSearch
We need to hide includes (needed for members) of PDFium inside
from the outside, so not everyone using the VectorGraphicSearch
needs to depend on PDFium too.
Change-Id: I95e46c714758b130594d78a4618af7350e29a075
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95255
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 115655a09868d5977f740995d88e36d958f30bb5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95832
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 2514c23a4bde8adf0872494c9009bae6b8dba816)
diff --git a/include/vcl/VectorGraphicSearch.hxx b/include/vcl/VectorGraphicSearch.hxx
index 3411d0a931e6..6c2589db1d01 100644
--- a/include/vcl/VectorGraphicSearch.hxx
+++ b/include/vcl/VectorGraphicSearch.hxx
@@ -14,8 +14,6 @@
#include <vcl/vectorgraphicdata.hxx>
#include <vcl/dllapi.h>
-#include <fpdf_doc.h>
-
#include <memory>
class SearchContext;
@@ -23,9 +21,11 @@ class SearchContext;
class VCL_DLLPUBLIC VectorGraphicSearch final
{
private:
+ class Implementation;
+ std::unique_ptr<Implementation> mpImplementation;
Graphic maGraphic;
- FPDF_DOCUMENT mpPdfDocument;
std::unique_ptr<SearchContext> mpSearchContext;
+
bool searchPDF(std::shared_ptr<VectorGraphicData> const& rData, OUString const& rSearchString);
public:
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx
index 864c65f2dda2..53127b85d9c1 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -11,8 +11,26 @@
#include <sal/config.h>
#include <vcl/VectorGraphicSearch.hxx>
+#include <fpdf_doc.h>
#include <fpdf_text.h>
+class VectorGraphicSearch::Implementation
+{
+public:
+ FPDF_DOCUMENT mpPdfDocument;
+
+ Implementation()
+ : mpPdfDocument(nullptr)
+ {
+ }
+
+ ~Implementation()
+ {
+ if (mpPdfDocument)
+ FPDF_CloseDocument(mpPdfDocument);
+ }
+};
+
class SearchContext
{
public:
@@ -78,8 +96,8 @@ public:
};
VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic)
- : maGraphic(rGraphic)
- , mpPdfDocument(nullptr)
+ : mpImplementation(std::make_unique<VectorGraphicSearch::Implementation>())
+ , maGraphic(rGraphic)
{
FPDF_LIBRARY_CONFIG aConfig;
aConfig.version = 2;
@@ -92,9 +110,7 @@ VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic)
VectorGraphicSearch::~VectorGraphicSearch()
{
mpSearchContext.reset();
-
- if (mpPdfDocument)
- FPDF_CloseDocument(mpPdfDocument);
+ mpImplementation.reset();
FPDF_DestroyLibrary();
}
@@ -115,11 +131,11 @@ bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rD
if (rSearchString.isEmpty())
return false;
- mpPdfDocument
+ mpImplementation->mpPdfDocument
= FPDF_LoadMemDocument(rData->getVectorGraphicDataArray().getConstArray(),
rData->getVectorGraphicDataArrayLength(), /*password=*/nullptr);
- if (!mpPdfDocument)
+ if (!mpImplementation->mpPdfDocument)
{
//TODO: Handle failure to load.
switch (FPDF_GetLastError())
@@ -144,9 +160,10 @@ bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rD
return false;
}
- sal_Int32 nPageIndex = std::max(rData->getPageIndex(), 0);
+ sal_Int32 nPageIndex = std::max(rData->getPageIndex(), sal_Int32(0));
- mpSearchContext.reset(new SearchContext(mpPdfDocument, nPageIndex, rSearchString));
+ mpSearchContext.reset(
+ new SearchContext(mpImplementation->mpPdfDocument, nPageIndex, rSearchString));
return mpSearchContext->initialize();
}
commit 98e9c22ad50acea9567a02162ec067c4a8c2e9ff
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun May 17 20:12:33 2020 +0200
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Jul 29 20:44:40 2020 +0200
vcl: add conversion point to 100th mm for double values
Integer conversion throws away percision, which is problematic
when we work with floating point values.
Change-Id: Ib34e46bd59aa67e933d49bc800e96cc6426414e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95260
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 0e29e9ea7f4fe58d8dbdc7a9b9f58543a93d5bf5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95831
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 5eb4a8b5562fde916b4049580c62a3e400922446)
diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx
index e59077d8a5fa..2093db6181d9 100644
--- a/include/tools/UnitConversion.hxx
+++ b/include/tools/UnitConversion.hxx
@@ -15,13 +15,18 @@ constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
return (n >= 0) ? (n * 127 + 36) / 72 : (n * 127 - 36) / 72;
}
-constexpr sal_Int64 convertPointToMm100(sal_Int64 n) { return convertTwipToMm100(n * 20); }
-
constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
{
return (n >= 0) ? (n * 72 + 63) / 127 : (n * 72 - 63) / 127;
}
+constexpr sal_Int64 convertPointToMm100(sal_Int64 nNumber)
+{
+ return convertTwipToMm100(nNumber * 20);
+}
+
+constexpr double convertPointToMm100(double fNumber) { return fNumber * 35.27777777778; }
+
// Convert PPT's "master unit" (1/576 inch) to twips
constexpr sal_Int64 convertMasterUnitToTwip(sal_Int64 n) { return n * 2540.0 / 576.0; }
More information about the Libreoffice-commits
mailing list