[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - include/vcl vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 9 11:41:06 UTC 2020


 include/vcl/VectorGraphicSearch.hxx        |    6 ++--
 vcl/source/graphic/VectorGraphicSearch.cxx |   35 +++++++++++++++++++++--------
 2 files changed, 29 insertions(+), 12 deletions(-)

New commits:
commit 2514c23a4bde8adf0872494c9009bae6b8dba816
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri May 15 12:20:42 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Jun 9 13:40:35 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>

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();
 }


More information about the Libreoffice-commits mailing list