From b5422296c55b3fe7b1f96920263feb9c2f97f51d Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 24 Feb 2021 20:40:57 +0100 Subject: pdfium: turn the PDFium class into an interface This will allow a dummy implementation that only provides PDFiumLibrary::get() and nothing else. Change-Id: Ia63b3f0b7751e5c05716825f0854282e4007207e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111502 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- include/vcl/filter/PDFiumLibrary.hxx | 19 ++++++----------- vcl/source/graphic/VectorGraphicSearch.cxx | 2 +- vcl/source/pdf/PDFiumLibrary.cxx | 34 ++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 5bd7e57eec5f..9d2be861b520 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -49,23 +49,16 @@ class PDFiumBitmap; class PDFiumDocument; class PDFiumPageObject; -class VCL_DLLPUBLIC PDFium final +class VCL_DLLPUBLIC PDFium { -private: - PDFium(const PDFium&) = delete; - PDFium& operator=(const PDFium&) = delete; - - OUString maLastError; - public: - PDFium(); - ~PDFium(); + virtual ~PDFium() = default; - const OUString& getLastError() const { return maLastError; } + virtual const OUString& getLastError() const = 0; - std::unique_ptr openDocument(const void* pData, int nSize); - static PDFErrorType getLastErrorCode(); - std::unique_ptr createBitmap(int nWidth, int nHeight, int nAlpha); + virtual std::unique_ptr openDocument(const void* pData, int nSize) = 0; + virtual PDFErrorType getLastErrorCode() = 0; + virtual std::unique_ptr createBitmap(int nWidth, int nHeight, int nAlpha) = 0; }; class PDFiumPage; diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx index a32d7d93e5ed..14e67e0b7138 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -233,7 +233,7 @@ bool VectorGraphicSearch::searchPDF(std::shared_ptr const& rD if (!mpImplementation->mpPdfDocument) { //TODO: Handle failure to load. - switch (vcl::pdf::PDFium::getLastErrorCode()) + switch (mpImplementation->mpPDFium->getLastErrorCode()) { case vcl::pdf::PDFErrorType::Success: break; diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 617ea16cb6eb..cb91edf99ebc 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -394,6 +394,25 @@ public: std::unique_ptr getSignature(int nIndex) override; std::vector getTrailerEnds() override; }; + +class PDFiumImpl : public PDFium +{ +private: + PDFiumImpl(const PDFiumImpl&) = delete; + PDFiumImpl& operator=(const PDFiumImpl&) = delete; + + OUString maLastError; + +public: + PDFiumImpl(); + ~PDFiumImpl() override; + + const OUString& getLastError() const override { return maLastError; } + + std::unique_ptr openDocument(const void* pData, int nSize) override; + PDFErrorType getLastErrorCode() override; + std::unique_ptr createBitmap(int nWidth, int nHeight, int nAlpha) override; +}; } OUString convertPdfDateToISO8601(OUString const& rInput) @@ -453,7 +472,7 @@ OUString convertPdfDateToISO8601(OUString const& rInput) + sTimeZoneString; } -PDFium::PDFium() +PDFiumImpl::PDFiumImpl() { FPDF_LIBRARY_CONFIG aConfig; aConfig.version = 2; @@ -463,9 +482,9 @@ PDFium::PDFium() FPDF_InitLibraryWithConfig(&aConfig); } -PDFium::~PDFium() { FPDF_DestroyLibrary(); } +PDFiumImpl::~PDFiumImpl() { FPDF_DestroyLibrary(); } -std::unique_ptr PDFium::openDocument(const void* pData, int nSize) +std::unique_ptr PDFiumImpl::openDocument(const void* pData, int nSize) { maLastError = OUString(); std::unique_ptr pPDFiumDocument; @@ -509,9 +528,12 @@ std::unique_ptr PDFium::openDocument(const void* pData, int nSiz return pPDFiumDocument; } -PDFErrorType PDFium::getLastErrorCode() { return static_cast(FPDF_GetLastError()); } +PDFErrorType PDFiumImpl::getLastErrorCode() +{ + return static_cast(FPDF_GetLastError()); +} -std::unique_ptr PDFium::createBitmap(int nWidth, int nHeight, int nAlpha) +std::unique_ptr PDFiumImpl::createBitmap(int nWidth, int nHeight, int nAlpha) { std::unique_ptr pPDFiumBitmap; FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nWidth, nHeight, nAlpha); @@ -1309,7 +1331,7 @@ int PDFiumSearchHandleImpl::getSearchCount() { return FPDFText_GetSchCount(mpSea std::shared_ptr& PDFiumLibrary::get() { - static auto pInstance = std::make_shared(); + static std::shared_ptr pInstance = std::make_shared(); return pInstance; } -- cgit