[Libreoffice-commits] core.git: include/vcl svx/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 29 12:36:00 UTC 2020


 include/vcl/filter/PDFiumLibrary.hxx |    2 +
 svx/source/inc/svdpdf.hxx            |    2 -
 svx/source/svdraw/svdpdf.cxx         |   55 ++++++++++-------------------------
 3 files changed, 20 insertions(+), 39 deletions(-)

New commits:
commit 34745b022d0c58e262c7ad3bfd103e769b2cdd18
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Jun 28 09:11:09 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Jun 29 14:35:20 2020 +0200

    use PDFium wrapper in ImpSdrPdfImport (partially)
    
    Change-Id: If13bcaa6a256354aceb2e1998521644041c03b7b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97363
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 2a70c3f89bce..35826097e45e 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -90,6 +90,8 @@ public:
             FPDF_ClosePage(mpPage);
     }
 
+    FPDF_PAGE getPointer() { return mpPage; }
+
     int getAnnotationCount();
     int getAnnotationIndex(std::unique_ptr<PDFiumAnnotation> const& rAnnotation);
 
diff --git a/svx/source/inc/svdpdf.hxx b/svx/source/inc/svdpdf.hxx
index 9403e90e5dda..71e66ff3deac 100644
--- a/svx/source/inc/svdpdf.hxx
+++ b/svx/source/inc/svdpdf.hxx
@@ -88,7 +88,7 @@ class SVXCORE_DLLPUBLIC ImpSdrPdfImport final
     // clipregion
     basegfx::B2DPolyPolygon maClip;
 
-    FPDF_DOCUMENT mpPdfDocument;
+    std::unique_ptr<vcl::pdf::PDFiumDocument> mpPdfDocument;
     int mnPageCount;
     double mdPageHeightPts;
     /// The current transformation matrix, typically used with Form objects.
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index c6430017bf19..4b21cb2d08fe 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -112,7 +112,6 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools:
     , mbNoLine(false)
     , mbNoFill(false)
     , maClip()
-    , mpPdfDocument(nullptr)
     , mnPageCount(0)
     , mdPageHeightPts(0)
     , mpPDFium(vcl::pdf::PDFiumLibrary::get())
@@ -131,65 +130,46 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools:
 
     // Load the buffer using pdfium.
     auto const& rVectorGraphicData = rGraphic.getVectorGraphicData();
-    mpPdfDocument = FPDF_LoadMemDocument(
-        rVectorGraphicData->getVectorGraphicDataArray().getConstArray(),
-        rVectorGraphicData->getVectorGraphicDataArrayLength(), /*password=*/nullptr);
+    auto* pData = rVectorGraphicData->getVectorGraphicDataArray().getConstArray();
+    sal_Int32 nSize = rVectorGraphicData->getVectorGraphicDataArrayLength();
+    mpPdfDocument = mpPDFium->openDocument(pData, nSize);
     if (!mpPdfDocument)
-    {
-        //TODO: Handle failure to load.
-        switch (FPDF_GetLastError())
-        {
-            case FPDF_ERR_SUCCESS:
-                break;
-            case FPDF_ERR_UNKNOWN:
-                break;
-            case FPDF_ERR_FILE:
-                break;
-            case FPDF_ERR_FORMAT:
-                break;
-            case FPDF_ERR_PASSWORD:
-                break;
-            case FPDF_ERR_SECURITY:
-                break;
-            case FPDF_ERR_PAGE:
-                break;
-            default:
-                break;
-        }
-
         return;
-    }
 
-    mnPageCount = FPDF_GetPageCount(mpPdfDocument);
+    mnPageCount = mpPdfDocument->getPageCount();
 }
 
-ImpSdrPdfImport::~ImpSdrPdfImport() { FPDF_CloseDocument(mpPdfDocument); }
+ImpSdrPdfImport::~ImpSdrPdfImport() = default;
 
 void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport,
                                 int nPageIndex)
 {
-    const int nPageCount = FPDF_GetPageCount(mpPdfDocument);
+    const int nPageCount = mpPdfDocument->getPageCount();
     if (nPageCount > 0 && nPageIndex >= 0 && nPageIndex < nPageCount)
     {
         // Render next page.
-        FPDF_PAGE pPdfPage = FPDF_LoadPage(mpPdfDocument, nPageIndex);
-        if (pPdfPage == nullptr)
+        auto pPdfPage = mpPdfDocument->openPage(nPageIndex);
+        if (!pPdfPage)
             return;
 
-        const double dPageWidth = FPDF_GetPageWidth(pPdfPage);
-        const double dPageHeight = FPDF_GetPageHeight(pPdfPage);
+        basegfx::B2DSize dPageSize = mpPdfDocument->getPageSize(nPageIndex);
+
+        const double dPageWidth = dPageSize.getX();
+        const double dPageHeight = dPageSize.getY();
+
         SetupPageScale(dPageWidth, dPageHeight);
 
         // Load the page text to extract it when we get text elements.
-        FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage);
+        FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage->getPointer());
 
-        const int nPageObjectCount = FPDFPage_CountObjects(pPdfPage);
+        const int nPageObjectCount = FPDFPage_CountObjects(pPdfPage->getPointer());
         if (pProgrInfo)
             pProgrInfo->SetActionCount(nPageObjectCount);
 
         for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; ++nPageObjectIndex)
         {
-            FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage, nPageObjectIndex);
+            FPDF_PAGEOBJECT pPageObject
+                = FPDFPage_GetObject(pPdfPage->getPointer(), nPageObjectIndex);
             ImportPdfObject(pPageObject, pTextPage, nPageObjectIndex);
             if (pProgrInfo && pActionsToReport)
             {
@@ -206,7 +186,6 @@ void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pAction
         }
 
         FPDFText_ClosePage(pTextPage);
-        FPDF_ClosePage(pPdfPage);
     }
 }
 


More information about the Libreoffice-commits mailing list