summaryrefslogtreecommitdiff
path: root/vcl/source/filter/ipdf/pdfread.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-31 11:50:20 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-09-12 11:23:56 +0200
commit12025e528ef50af9e3176a19465f860723e30871 (patch)
treebbba4c2b68914026c137e30a4a80659cde649024 /vcl/source/filter/ipdf/pdfread.cxx
parent3854dceda7fbda3c579322030b7802a180e959e0 (diff)
pdfium: only init pdfium library once 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. [ Leaving out the vector graphic search bits, the motivation is to just have this in libreoffice-7-0, so that recent pdf sig verify improvements can be backported. ] (cherry picked from commit 067a8a954c8e1d8d6465a4ab5fb61e93f16c26c2) Conflicts: vcl/source/graphic/VectorGraphicSearch.cxx Change-Id: I5c7e5de7f8b97d10efb394c67c7a61b976c8d57c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102317 Tested-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit b7de766b4dc5b4810277069bcf53a9f3737e87da) Conflicts: svx/source/svdraw/svdpdf.cxx svx/source/svdraw/svdpdf.hxx vcl/Library_vcl.mk vcl/qa/cppunit/pdfexport/pdfexport.cxx vcl/source/filter/ipdf/pdfread.cxx
Diffstat (limited to 'vcl/source/filter/ipdf/pdfread.cxx')
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx18
1 files changed, 4 insertions, 14 deletions
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index e3fe26332e2f..ec4d068ac007 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -20,6 +20,8 @@
#include <vcl/graph.hxx>
#include <bitmapwriteaccess.hxx>
+#include <vcl/filter/PDFiumLibrary.hxx>
+
using namespace com::sun::star;
namespace
@@ -58,12 +60,7 @@ double pointToPixel(double fPoint) { return fPoint / 72 * 96; }
size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, sal_uInt64 nPos,
sal_uInt64 nSize, const size_t nFirstPage, int nPages)
{
- 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;
@@ -119,7 +116,6 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, sal_uIn
}
FPDF_CloseDocument(pPdfDocument);
- FPDF_DestroyLibrary();
return rBitmaps.size();
}
@@ -159,12 +155,7 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n
else
{
// Downconvert to PDF-1.5.
- 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;
@@ -182,7 +173,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);