diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-06-28 09:11:09 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-29 14:35:20 +0200 |
commit | 34745b022d0c58e262c7ad3bfd103e769b2cdd18 (patch) | |
tree | 88e0793a5e8eb5189763f29c051030782b89fdfc /svx | |
parent | a73a3fcee62a10dd7063e6e98627c37dd0570fb7 (diff) |
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@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/inc/svdpdf.hxx | 2 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 55 |
2 files changed, 18 insertions, 39 deletions
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); } } |