summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-05-14 08:15:30 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-04 12:36:28 -0400
commit075aa655ba5d4def1cdfa3bb3fed25ce9371fbd9 (patch)
tree5b2f1046db3ece7cad218b4893ba83e7a3c109d3
parent5c0b46d3c899d85b16ab9866ae0575ddaef3a81e (diff)
svx: share PDF stream when saving imported PDF as images
(cherry picked from commit 23642eead069133d794bb1ac5cf9e7042d18d876) Change-Id: I05dd9ccb8f61c795212f8c587ee0a69c3cd75cf6
-rw-r--r--include/svx/xmlgrhlp.hxx2
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx3
-rw-r--r--svx/source/xml/xmlgrhlp.cxx9
3 files changed, 13 insertions, 1 deletions
diff --git a/include/svx/xmlgrhlp.hxx b/include/svx/xmlgrhlp.hxx
index 7cea0279bab0..4d9fa58a1b49 100644
--- a/include/svx/xmlgrhlp.hxx
+++ b/include/svx/xmlgrhlp.hxx
@@ -25,6 +25,7 @@
#include <vcl/GraphicObject.hxx>
#include <vector>
#include <set>
+#include <unordered_map>
#include <utility>
#include <com/sun/star/document/XGraphicObjectResolver.hpp>
#include <com/sun/star/document/XGraphicStorageHandler.hpp>
@@ -58,6 +59,7 @@ private:
std::unordered_map<OUString, css::uno::Reference<css::graphic::XGraphic>> maGraphicObjects;
std::unordered_map<Graphic, std::pair<OUString, OUString>> maExportGraphics;
+ std::unordered_map<void*, std::pair<OUString, OUString>> maExportPdf;
SvXMLGraphicHelperMode meCreateMode;
OUString maOutputMimeType;
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 8291ea5b05bc..7e83356daa7c 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -108,6 +108,7 @@ bool SdPdfFilter::Import()
std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
memcpy(pGraphicContent.get(), aPdfData.get(), nGraphicContentSize);
GfxLink aGfxLink(std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf);
+ auto pPdfData = std::make_shared<uno::Sequence<sal_Int8>>(aPdfData);
mrDocument.CreateFirstPages();
for (int i = 0; i < aBitmaps.size() - 1; ++i)
@@ -120,7 +121,7 @@ bool SdPdfFilter::Import()
{
// Create the Graphic and link the original PDF stream.
Graphic aGraphic(aBitmap);
- aGraphic.setPdfData(std::make_shared<uno::Sequence<sal_Int8>>(aPdfData));
+ aGraphic.setPdfData(pPdfData);
aGraphic.SetGfxLink(aGfxLink);
aGraphic.setOriginURL(aFileName);
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index 3f98e4af7ab4..e69bfcbe7e0d 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -41,6 +41,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>
@@ -767,11 +768,19 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X
const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData = aGraphic.getPdfData();
if (rPdfData->hasElements())
{
+ // See if we have this PDF already, and avoid duplicate storage.
+ auto aIt = maExportPdf.find(rPdfData.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());
+
+ // Put into cache.
+ maExportPdf[rPdfData.get()] = std::make_pair(rPictureStreamName, aMimeType);
}
else
{