diff options
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 12 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 26 | ||||
-rw-r--r-- | vcl/source/graphic/VectorGraphicSearch.cxx | 13 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 36 |
5 files changed, 51 insertions, 37 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index d65aad0a5e6d..9d478d0dd368 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -305,6 +305,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/gdi/wall \ vcl/source/gdi/scrptrun \ vcl/source/gdi/CommonSalLayout \ + vcl/source/pdf/PDFiumLibrary \ vcl/source/graphic/GraphicLoader \ vcl/source/graphic/GraphicObject \ vcl/source/graphic/GraphicObject2 \ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 9b2268f3bf8e..edde9018c539 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -33,6 +33,8 @@ #include <fpdf_text.h> #include <fpdfview.h> +#include <vcl/filter/PDFiumLibrary.hxx> + using namespace ::com::sun::star; static std::ostream& operator<<(std::ostream& rStrm, const Color& rColor) @@ -78,6 +80,7 @@ class PdfExportTest : public test::BootstrapFixture, public unotest::MacrosTest SvMemoryStream maMemory; // Export the document as PDF, then parse it with PDFium. DocumentHolder exportAndParse(const OUString& rURL, const utl::MediaDescriptor& rDescriptor); + std::shared_ptr<vcl::pdf::PDFium> mpPDFium; public: PdfExportTest(); @@ -207,18 +210,11 @@ void PdfExportTest::setUp() mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); mxDesktop.set(frame::Desktop::create(mxComponentContext)); - FPDF_LIBRARY_CONFIG config; - config.version = 2; - config.m_pUserFontPaths = nullptr; - config.m_pIsolate = nullptr; - config.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&config); + mpPDFium = vcl::pdf::PDFiumLibrary::get(); } void PdfExportTest::tearDown() { - FPDF_DestroyLibrary(); - if (mxComponent.is()) mxComponent->dispose(); diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index f9104152fbe8..2502b98e1b35 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -23,6 +23,8 @@ #include <bitmapwriteaccess.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> + using namespace com::sun::star; namespace @@ -83,12 +85,7 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n else { // Downconvert to PDF-1.6. - FPDF_LIBRARY_CONFIG aConfig; - aConfig.version = 2; - aConfig.m_pUserFontPaths = nullptr; - aConfig.m_pIsolate = nullptr; - aConfig.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&aConfig); + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); // Read input into a buffer. SvMemoryStream aInBuffer; @@ -109,7 +106,6 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n return false; FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); aWriter.m_aStream.Seek(STREAM_SEEK_TO_BEGIN); rOutStream.WriteStream(aWriter.m_aStream); @@ -154,12 +150,7 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi const size_t nFirstPage, int nPages, const double fResolutionDPI) { #if HAVE_FEATURE_PDFIUM - FPDF_LIBRARY_CONFIG aConfig; - aConfig.version = 2; - aConfig.m_pUserFontPaths = nullptr; - aConfig.m_pIsolate = nullptr; - aConfig.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&aConfig); + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); // Load the buffer using pdfium. FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(pBuffer, nSize, /*password=*/nullptr); @@ -209,7 +200,6 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi } FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); return rBitmaps.size(); #else @@ -256,12 +246,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si auto pGfxLink = std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf); - FPDF_LIBRARY_CONFIG aConfig; - aConfig.version = 2; - aConfig.m_pUserFontPaths = nullptr; - aConfig.m_pIsolate = nullptr; - aConfig.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&aConfig); + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); // Load the buffer using pdfium. FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument( @@ -301,7 +286,6 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si } FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); return rGraphics.size(); #else diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx index 94d954516f13..5c4022685f71 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -10,6 +10,8 @@ #include <vcl/VectorGraphicSearch.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> + #include <sal/config.h> #include <fpdf_doc.h> @@ -18,10 +20,12 @@ class VectorGraphicSearch::Implementation { public: + std::shared_ptr<vcl::pdf::PDFium> mpPDFium; FPDF_DOCUMENT mpPdfDocument; Implementation() - : mpPdfDocument(nullptr) + : mpPDFium(vcl::pdf::PDFiumLibrary::get()) + , mpPdfDocument(nullptr) { } @@ -181,19 +185,12 @@ VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic) : mpImplementation(std::make_unique<VectorGraphicSearch::Implementation>()) , maGraphic(rGraphic) { - FPDF_LIBRARY_CONFIG aConfig; - aConfig.version = 2; - aConfig.m_pUserFontPaths = nullptr; - aConfig.m_pIsolate = nullptr; - aConfig.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&aConfig); } VectorGraphicSearch::~VectorGraphicSearch() { mpSearchContext.reset(); mpImplementation.reset(); - FPDF_DestroyLibrary(); } bool VectorGraphicSearch::search(OUString const& rSearchString, SearchStartPosition eStartPosition) diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx new file mode 100644 index 000000000000..604807524bf9 --- /dev/null +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <config_features.h> + +#if HAVE_FEATURE_PDFIUM + +#include <vcl/filter/PDFiumLibrary.hxx> +#include <fpdf_doc.h> + +namespace vcl::pdf +{ +PDFium::PDFium() +{ + FPDF_LIBRARY_CONFIG aConfig; + aConfig.version = 2; + aConfig.m_pUserFontPaths = nullptr; + aConfig.m_pIsolate = nullptr; + aConfig.m_v8EmbedderSlot = 0; + FPDF_InitLibraryWithConfig(&aConfig); +} + +PDFium::~PDFium() { FPDF_DestroyLibrary(); } + +} // end vcl::pdf + +#endif // HAVE_FEATURE_PDFIUM + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |