diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-05-31 11:50:20 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-03 13:32:01 +0200 |
commit | 067a8a954c8e1d8d6465a4ab5fb61e93f16c26c2 (patch) | |
tree | 26b9c6a16472a47b0aad4d156baaa73d9fe72ea5 /vcl/source/filter | |
parent | 40d682542f02d78b5ed6bd4fc0ba461a1a7fb5f1 (diff) |
pdfium: only init pdfium library one and destroy on LO exit
With more and more usage of PDFium, it is hard to keep track of
the life-time of the PDFium library, so it can happen that a
FPDF_DestroyLibrary happens when we still have another instance
where PDFium is still use. The result of this is a crash. To
prevent this, just initialize the library once and delete, when
on LO exit.
This can be improved in the future to only keep the library
active when in actual use.
Change-Id: I5c7e5de7f8b97d10efb394c67c7a61b976c8d57c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95391
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/filter')
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 1df96ad46e72..2a7e7ce04198 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -21,6 +21,8 @@ #include <bitmapwriteaccess.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> + using namespace com::sun::star; namespace @@ -82,12 +84,7 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream) 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; @@ -108,7 +105,6 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream) return false; FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); aWriter.m_aStream.Seek(STREAM_SEEK_TO_BEGIN); rOutStream.WriteStream(aWriter.m_aStream); @@ -152,12 +148,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); @@ -207,7 +198,6 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi } FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); return rBitmaps.size(); #else @@ -254,12 +244,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 @@ -298,7 +283,6 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si } FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); return rGraphics.size(); #else |