aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-02-24 20:40:57 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-02-25 08:24:22 +0100
commitb5422296c55b3fe7b1f96920263feb9c2f97f51d (patch)
treeebab2def5269a44085f1091108427c36e874edf4
parenta9a350c13d8fb454c3f1db7ca6a7f10c1e7a19bb (diff)
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 <vmiklos@collabora.com>
-rw-r--r--include/vcl/filter/PDFiumLibrary.hxx19
-rw-r--r--vcl/source/graphic/VectorGraphicSearch.cxx2
-rw-r--r--vcl/source/pdf/PDFiumLibrary.cxx34
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<PDFiumDocument> openDocument(const void* pData, int nSize);
- static PDFErrorType getLastErrorCode();
- std::unique_ptr<PDFiumBitmap> createBitmap(int nWidth, int nHeight, int nAlpha);
+ virtual std::unique_ptr<PDFiumDocument> openDocument(const void* pData, int nSize) = 0;
+ virtual PDFErrorType getLastErrorCode() = 0;
+ virtual std::unique_ptr<PDFiumBitmap> 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<VectorGraphicData> 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<PDFiumSignature> getSignature(int nIndex) override;
std::vector<unsigned int> 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<PDFiumDocument> openDocument(const void* pData, int nSize) override;
+ PDFErrorType getLastErrorCode() override;
+ std::unique_ptr<PDFiumBitmap> 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<PDFiumDocument> PDFium::openDocument(const void* pData, int nSize)
+std::unique_ptr<PDFiumDocument> PDFiumImpl::openDocument(const void* pData, int nSize)
{
maLastError = OUString();
std::unique_ptr<PDFiumDocument> pPDFiumDocument;
@@ -509,9 +528,12 @@ std::unique_ptr<PDFiumDocument> PDFium::openDocument(const void* pData, int nSiz
return pPDFiumDocument;
}
-PDFErrorType PDFium::getLastErrorCode() { return static_cast<PDFErrorType>(FPDF_GetLastError()); }
+PDFErrorType PDFiumImpl::getLastErrorCode()
+{
+ return static_cast<PDFErrorType>(FPDF_GetLastError());
+}
-std::unique_ptr<PDFiumBitmap> PDFium::createBitmap(int nWidth, int nHeight, int nAlpha)
+std::unique_ptr<PDFiumBitmap> PDFiumImpl::createBitmap(int nWidth, int nHeight, int nAlpha)
{
std::unique_ptr<PDFiumBitmap> pPDFiumBitmap;
FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nWidth, nHeight, nAlpha);
@@ -1309,7 +1331,7 @@ int PDFiumSearchHandleImpl::getSearchCount() { return FPDFText_GetSchCount(mpSea
std::shared_ptr<PDFium>& PDFiumLibrary::get()
{
- static auto pInstance = std::make_shared<PDFium>();
+ static std::shared_ptr<PDFium> pInstance = std::make_shared<PDFiumImpl>();
return pInstance;
}