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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sat Jun 20 11:11:39 UTC 2020


 vcl/source/filter/ipdf/pdfread.cxx |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

New commits:
commit 4fa45de60601d34b3a821b35b5aca72f494a7487
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Jun 15 14:01:49 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sat Jun 20 13:11:02 2020 +0200

    vcl: use pdfium c++ wraper classes in ImportPDFUnloaded
    
    Change-Id: I1d0d97f4b981fa62aa38dc5ceaf89d3976bbccbe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96754
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 2a7e7ce04198..10caf1a975f5 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -247,28 +247,27 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
 
     // Load the buffer using pdfium.
-    FPDF_DOCUMENT pPdfDocument
-        = FPDF_LoadMemDocument(pGfxLink->GetData(), pGfxLink->GetDataSize(), /*password=*/nullptr);
+    auto pPdfDocument = pPdfium->openDocument(pGfxLink->GetData(), pGfxLink->GetDataSize());
+
     if (!pPdfDocument)
         return 0;
 
-    const int nPageCount = FPDF_GetPageCount(pPdfDocument);
+    const int nPageCount = pPdfDocument->getPageCount();
     if (nPageCount <= 0)
         return 0;
 
     for (int nPageIndex = 0; nPageIndex < nPageCount; ++nPageIndex)
     {
-        double fPageWidth = 0;
-        double fPageHeight = 0;
-        if (FPDF_GetPageSizeByIndex(pPdfDocument, nPageIndex, &fPageWidth, &fPageHeight) == 0)
+        basegfx::B2DSize aPageSize = pPdfDocument->getPageSize(nPageIndex);
+        if (aPageSize.getX() <= 0.0 || aPageSize.getY() <= 0.0)
             continue;
 
         // Returned unit is points, convert that to twip
         // 1 pt = 20 twips
         constexpr double pointToTwipconversionRatio = 20;
 
-        long nPageWidth = convertTwipToMm100(fPageWidth * pointToTwipconversionRatio);
-        long nPageHeight = convertTwipToMm100(fPageHeight * pointToTwipconversionRatio);
+        long nPageWidth = convertTwipToMm100(aPageSize.getX() * pointToTwipconversionRatio);
+        long nPageHeight = convertTwipToMm100(aPageSize.getY() * pointToTwipconversionRatio);
 
         auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(
             aPdfDataArray, OUString(), VectorGraphicDataType::Pdf, nPageIndex);
@@ -282,8 +281,6 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
         rGraphics.emplace_back(std::move(aGraphic), Size(nPageWidth, nPageHeight));
     }
 
-    FPDF_CloseDocument(pPdfDocument);
-
     return rGraphics.size();
 #else
     (void)rURL;


More information about the Libreoffice-commits mailing list