[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - 2 commits - include/tools include/vcl vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed May 20 08:21:52 UTC 2020


 include/tools/UnitConversion.hxx           |    9 +++--
 include/vcl/VectorGraphicSearch.hxx        |    2 +
 vcl/qa/cppunit/VectorGraphicSearchTest.cxx |   51 ++++++++++++++++++-----------
 vcl/source/graphic/VectorGraphicSearch.cxx |   30 +++++++++++++++++
 4 files changed, 71 insertions(+), 21 deletions(-)

New commits:
commit c17dbebcf0561830cfea3cea4b9a0a7a31f5a8c3
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: Sun May 17 20:32:49 2020 +0200

    vcl: VectorGraphicSearch return text rectangles in 100th mm
    
    Change-Id: I12e7ad10dc3ed68d20d94713acece1361da27e81

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 8e90145cbecb..56c00efa172a 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -64,6 +64,21 @@ public:
             FPDF_ClosePage(mpPage);
     }
 
+    basegfx::B2DSize getPageSize()
+    {
+        basegfx::B2DSize aSize;
+        if (!mpPdfDocument)
+            return aSize;
+
+        FS_SIZEF aPDFSize;
+        if (FPDF_GetPageSizeByIndexF(mpPdfDocument, mnPageIndex, &aPDFSize))
+        {
+            aSize = basegfx::B2DSize(convertPointToMm100(aPDFSize.width),
+                                     convertPointToMm100(aPDFSize.height));
+        }
+        return aSize;
+    }
+
     bool initialize()
     {
         if (!mpPdfDocument)
@@ -117,6 +132,8 @@ public:
         if (nSize <= 0)
             return aRectangles;
 
+        double fPageHeight = getPageSize().getY();
+
         for (int nCount = 0; nCount < nSize; nCount++)
         {
             double left = 0.0;
@@ -126,6 +143,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 +229,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 d63b79c23749885fb0fb60dc62a3958fb77043d6
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: Sun May 17 20:12:33 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

diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx
index 8ad489dee590..0a4de38ad60d 100644
--- a/include/tools/UnitConversion.hxx
+++ b/include/tools/UnitConversion.hxx
@@ -15,11 +15,16 @@ 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; }
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list