diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-05-14 08:15:30 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-05-22 12:17:10 +0200 |
commit | 23642eead069133d794bb1ac5cf9e7042d18d876 (patch) | |
tree | be0598b977e2037051212627ae795ccc302728a4 /svx | |
parent | 42733c51385b6518678a8d5483c234909db2af40 (diff) |
svx: share PDF stream when saving imported PDF as images
Change-Id: I05dd9ccb8f61c795212f8c587ee0a69c3cd75cf6
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index 59d683dea1e2..f14396447995 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -38,6 +38,7 @@ #include <vcl/cvtgrf.hxx> #include <vcl/gfxlink.hxx> #include <vcl/metaact.hxx> +#include <tools/stream.hxx> #include <tools/zcodec.hxx> #include <vcl/graphicfilter.hxx> @@ -565,15 +566,22 @@ bool SvXMLGraphicHelper::ImplWriteGraphic( const OUString& rPictureStorageName, std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aStream.xStream )); if( bUseGfxLink && aGfxLink.GetDataSize() && aGfxLink.GetData() ) { - const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData = aGraphic.getPdfData(); - if (rPdfData && rPdfData->hasElements()) + if (aGraphic.hasPdfData()) { + // See if we have this PDF already, and avoid duplicate storage. + auto aIt = maExportPdf.find(aGraphic.getPdfData().get()); + if (aIt != maExportPdf.end()) + return true; + // The graphic has PDF data attached to it, use that. // vcl::ImportPDF() possibly downgraded the PDF data from a // higher PDF version, while aGfxLink still contains the // original data provided by the user. - pStream->WriteBytes(rPdfData->getConstArray(), rPdfData->getLength()); - bRet = (pStream->GetError() == 0); + std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = aGraphic.getPdfData(); + pStream->WriteBytes(pPdfData->getConstArray(), pPdfData->getLength()); + + // put into cache + maExportPdf[aGraphic.getPdfData().get()] = std::make_pair(rPictureStreamName, aMimeType); } else pStream->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); |