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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Fri May 15 10:24:15 UTC 2020


 include/vcl/VectorGraphicSearch.hxx        |    6 ++---
 vcl/source/graphic/VectorGraphicSearch.cxx |   33 +++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 11 deletions(-)

New commits:
commit 78a8e2c75b8c370b5c1b9f41de5df02174a47e23
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: Fri May 15 12:20:42 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

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..34ac0abd6654 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())
@@ -146,7 +162,8 @@ bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rD
 
     sal_Int32 nPageIndex = std::max(rData->getPageIndex(), 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