diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-03-17 15:33:54 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-06-07 10:45:17 +0200 |
commit | 9b11fdd36ec80f9d1ae0a05455745361e0ce9ced (patch) | |
tree | 857ad890a0ff1c96d707cb145fafd74b79d53603 | |
parent | 99bbed5cd87af8ff1b7e3d197d937fb17af021e6 (diff) |
pdf: share pdf data in Graphic
Change-Id: I8146aa4e206788afff71142e1877fd7a885f4652
-rw-r--r-- | include/vcl/graph.hxx | 6 | ||||
-rw-r--r-- | svx/source/svdraw/svdograf.cxx | 2 | ||||
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 6 | ||||
-rw-r--r-- | svx/source/xoutdev/_xoutbmp.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/graphic/ndgrf.cxx | 4 | ||||
-rw-r--r-- | vcl/inc/impgraph.hxx | 11 | ||||
-rw-r--r-- | vcl/source/gdi/graph.cxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 49 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 10 |
9 files changed, 61 insertions, 43 deletions
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx index 3eb7c79e7c1e..847e20e202ab 100644 --- a/include/vcl/graph.hxx +++ b/include/vcl/graph.hxx @@ -230,8 +230,10 @@ public: const VectorGraphicDataPtr& getVectorGraphicData() const; - void setPdfData(const css::uno::Sequence<sal_Int8>& rPdfData); - const css::uno::Sequence<sal_Int8>& getPdfData() const; + void setPdfData(const std::shared_ptr<css::uno::Sequence<sal_Int8>>& rPdfData); + void setPdfData(const css::uno::Sequence<sal_Int8>& rPdfData) { setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(rPdfData)); } + std::shared_ptr<css::uno::Sequence<sal_Int8>> getPdfData() const; + bool hasPdfData() const; static css::uno::Sequence<sal_Int8> getUnoTunnelId(); }; diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index cd80929059b7..2f8129b03257 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -433,7 +433,7 @@ const GraphicObject* SdrGrafObj::GetReplacementGraphicObject() const { const_cast< SdrGrafObj* >(this)->mpReplacementGraphicObject.reset(new GraphicObject(rVectorGraphicDataPtr->getReplacement())); } - else if (mpGraphicObject->GetGraphic().getPdfData().hasElements() || + else if (mpGraphicObject->GetGraphic().hasPdfData() || mpGraphicObject->GetGraphic().GetType() == GraphicType::GdiMetafile) { // Replacement graphic for PDF and metafiles is just the bitmap. diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index a0f01b8671ac..c261e8450858 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -764,14 +764,14 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(aStream.xStream)); if (bUseGfxLink && aGfxLink.GetDataSize() && aGfxLink.GetData()) { - const uno::Sequence<sal_Int8>& rPdfData = aGraphic.getPdfData(); - if (rPdfData.hasElements()) + if (aGraphic.hasPdfData()) { // 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()); + std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = aGraphic.getPdfData(); + pStream->WriteBytes(pPdfData->getConstArray(), pPdfData->getLength()); } else { diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index 55128d08f7d8..a37508c2fcd1 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -173,7 +173,7 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, } // Write PDF data in original form if possible. - if (rGraphic.getPdfData().hasElements() && rFilterName.equalsIgnoreAsciiCase("pdf")) + if (rGraphic.hasPdfData() && rFilterName.equalsIgnoreAsciiCase("pdf")) { if (!(nFlags & XOutFlags::DontAddExtension)) aURL.setExtension(rFilterName); @@ -182,8 +182,8 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, SfxMedium aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE|StreamMode::SHARE_DENYNONE|StreamMode::TRUNC); if (SvStream* pOutStream = aMedium.GetOutStream()) { - uno::Sequence<sal_Int8> aPdfData = rGraphic.getPdfData(); - pOutStream->WriteBytes(aPdfData.getConstArray(), aPdfData.getLength()); + std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = rGraphic.getPdfData(); + pOutStream->WriteBytes(pPdfData->getConstArray(), pPdfData->getLength()); aMedium.Commit(); if (!aMedium.GetError()) nErr = ERRCODE_NONE; diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx index 5cfd3ce51508..cd346b957123 100644 --- a/sw/source/core/graphic/ndgrf.cxx +++ b/sw/source/core/graphic/ndgrf.cxx @@ -395,8 +395,8 @@ const GraphicObject* SwGrfNode::GetReplacementGrfObj() const { const_cast< SwGrfNode* >(this)->mpReplacementGraphic = new GraphicObject(rVectorGraphicDataPtr->getReplacement()); } - else if (GetGrfObj().GetGraphic().getPdfData().hasElements() - || GetGrfObj().GetGraphic().GetType() == GraphicType::GdiMetafile) + else if (GetGrfObj().GetGraphic().hasPdfData() || + GetGrfObj().GetGraphic().GetType() == GraphicType::GdiMetafile) { // Replacement graphic for PDF and metafiles is just the bitmap. const_cast<SwGrfNode*>(this)->mpReplacementGraphic = new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx()); diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx index 4338ed20021d..052bed0924a5 100644 --- a/vcl/inc/impgraph.hxx +++ b/vcl/inc/impgraph.hxx @@ -88,7 +88,7 @@ private: bool mbSwapOut; bool mbDummyContext; VectorGraphicDataPtr maVectorGraphicData; - css::uno::Sequence<sal_Int8> maPdfData; + std::shared_ptr<css::uno::Sequence<sal_Int8>> mpPdfData; std::unique_ptr<GraphicID> mpGraphicID; GraphicExternalLink maGraphicExternalLink; @@ -133,6 +133,11 @@ private: return mpGraphicID->getIDString(); } + bool hasPdfData() const + { + return mpPdfData && mpPdfData->hasElements(); + } + void ImplCreateSwapInfo(); void ImplClearGraphics(); void ImplClear(); @@ -214,9 +219,9 @@ private: const VectorGraphicDataPtr& getVectorGraphicData() const; - const css::uno::Sequence<sal_Int8>& getPdfData() const; + const std::shared_ptr<css::uno::Sequence<sal_Int8>>& getPdfData() const; - void setPdfData(const css::uno::Sequence<sal_Int8>& rPdfData); + void setPdfData(const std::shared_ptr<css::uno::Sequence<sal_Int8>>& rPdfData); bool ensureAvailable () const; diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index 19bb99d254e4..21b8a5713651 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -557,17 +557,23 @@ const VectorGraphicDataPtr& Graphic::getVectorGraphicData() const return mxImpGraphic->getVectorGraphicData(); } -void Graphic::setPdfData(const uno::Sequence<sal_Int8>& rPdfData) +void Graphic::setPdfData(const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData) { ImplTestRefCount(); mxImpGraphic->setPdfData(rPdfData); } -const uno::Sequence<sal_Int8>& Graphic::getPdfData() const +std::shared_ptr<uno::Sequence<sal_Int8>> Graphic::getPdfData() const { return mxImpGraphic->getPdfData(); } +bool Graphic::hasPdfData() const +{ + std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = getPdfData(); + return pPdfData && pPdfData->hasElements(); +} + OUString Graphic::getOriginURL() const { if (mxImpGraphic) diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index c718f9673610..6e1691470ae1 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -195,7 +195,7 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic) , mbSwapOut(rImpGraphic.mbSwapOut) , mbDummyContext(rImpGraphic.mbDummyContext) , maVectorGraphicData(rImpGraphic.maVectorGraphicData) - , maPdfData(rImpGraphic.maPdfData) + , mpPdfData(rImpGraphic.mpPdfData) , maGraphicExternalLink(rImpGraphic.maGraphicExternalLink) , maLastUsed (std::chrono::high_resolution_clock::now()) , mbPrepared (rImpGraphic.mbPrepared) @@ -223,7 +223,7 @@ ImpGraphic::ImpGraphic(ImpGraphic&& rImpGraphic) , mbSwapOut(rImpGraphic.mbSwapOut) , mbDummyContext(rImpGraphic.mbDummyContext) , maVectorGraphicData(std::move(rImpGraphic.maVectorGraphicData)) - , maPdfData(std::move(rImpGraphic.maPdfData)) + , mpPdfData(std::move(rImpGraphic.mpPdfData)) , maGraphicExternalLink(rImpGraphic.maGraphicExternalLink) , maLastUsed (std::chrono::high_resolution_clock::now()) , mbPrepared (rImpGraphic.mbPrepared) @@ -341,7 +341,7 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink ); maVectorGraphicData = rImpGraphic.maVectorGraphicData; - maPdfData = rImpGraphic.maPdfData; + mpPdfData = rImpGraphic.mpPdfData; maLastUsed = std::chrono::high_resolution_clock::now(); vcl::graphic::Manager::get().changeExisting(this, aOldSizeBytes); @@ -366,7 +366,7 @@ ImpGraphic& ImpGraphic::operator=(ImpGraphic&& rImpGraphic) mpSwapFile = std::move(rImpGraphic.mpSwapFile); mpGfxLink = std::move(rImpGraphic.mpGfxLink); maVectorGraphicData = std::move(rImpGraphic.maVectorGraphicData); - maPdfData = std::move(rImpGraphic.maPdfData); + mpPdfData = std::move(rImpGraphic.mpPdfData); maGraphicExternalLink = rImpGraphic.maGraphicExternalLink; mbPrepared = rImpGraphic.mbPrepared; @@ -419,9 +419,9 @@ bool ImpGraphic::operator==( const ImpGraphic& rImpGraphic ) const bRet = (*maVectorGraphicData) == (*rImpGraphic.maVectorGraphicData); } } - else if (maPdfData.hasElements()) + else if (mpPdfData && mpPdfData->hasElements()) { - bRet = maPdfData == rImpGraphic.maPdfData; + bRet = (rImpGraphic.mpPdfData && *mpPdfData == *rImpGraphic.mpPdfData); } else if( mpAnimation ) { @@ -450,18 +450,18 @@ const VectorGraphicDataPtr& ImpGraphic::getVectorGraphicData() const return maVectorGraphicData; } -void ImpGraphic::setPdfData(const uno::Sequence<sal_Int8>& rPdfData) +void ImpGraphic::setPdfData(const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData) { ensureAvailable(); - maPdfData = rPdfData; + mpPdfData = rPdfData; } -const uno::Sequence<sal_Int8>& ImpGraphic::getPdfData() const +const std::shared_ptr<uno::Sequence<sal_Int8>>& ImpGraphic::getPdfData() const { ensureAvailable(); - return maPdfData; + return mpPdfData; } void ImpGraphic::ImplCreateSwapInfo() @@ -485,7 +485,7 @@ void ImpGraphic::ImplClearGraphics() mpAnimation.reset(); mpGfxLink.reset(); maVectorGraphicData.reset(); - maPdfData = uno::Sequence<sal_Int8>(); + mpPdfData.reset(); } ImpSwapFile::~ImpSwapFile() @@ -1681,10 +1681,10 @@ BitmapChecksum ImpGraphic::ImplGetChecksum() const nRet = maEx.GetChecksum(); } - if (maPdfData.hasElements()) + if (mpPdfData && mpPdfData->hasElements()) // Include the PDF data in the checksum, so a metafile with // and without PDF data is considered to be different. - nRet = vcl_get_checksum(nRet, maPdfData.getConstArray(), maPdfData.getLength()); + nRet = vcl_get_checksum(nRet, mpPdfData->getConstArray(), mpPdfData->getLength()); } break; @@ -1874,12 +1874,17 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic ) rIStm.ReadUInt32(nPdfDataLength); Bitmap aBitmap; - if (nPdfDataLength && !rIStm.GetError() && - vcl::ImportPDF(rIStm, aBitmap, rImpGraphic.maPdfData, - rIStm.Tell(), nPdfDataLength)) + if (nPdfDataLength && !rIStm.GetError()) { - rImpGraphic.maEx = aBitmap; - rImpGraphic.meType = GraphicType::Bitmap; + if (!rImpGraphic.mpPdfData) + rImpGraphic.mpPdfData.reset(new uno::Sequence<sal_Int8>()); + + if (vcl::ImportPDF(rIStm, aBitmap, *rImpGraphic.mpPdfData, + rIStm.Tell(), nPdfDataLength)) + { + rImpGraphic.maEx = aBitmap; + rImpGraphic.meType = GraphicType::Bitmap; + } } } else @@ -1910,7 +1915,7 @@ void WriteImpGraphic(SvStream& rOStm, const ImpGraphic& rImpGraphic) if( ( rOStm.GetVersion() >= SOFFICE_FILEFORMAT_50 ) && ( rOStm.GetCompressMode() & SvStreamCompressFlags::NATIVE ) && rImpGraphic.mpGfxLink && rImpGraphic.mpGfxLink->IsNative() && - !rImpGraphic.maPdfData.hasElements()) + !rImpGraphic.hasPdfData()) { // native format rOStm.WriteUInt32( NATIVE_FORMAT_50 ); @@ -1971,12 +1976,12 @@ void WriteImpGraphic(SvStream& rOStm, const ImpGraphic& rImpGraphic) rOStm.WriteUniOrByteString(rImpGraphic.getVectorGraphicData()->getPath(), rOStm.GetStreamCharSet()); } - else if (rImpGraphic.maPdfData.hasElements()) + else if (rImpGraphic.hasPdfData()) { // Stream out PDF data. rOStm.WriteUInt32(nPdfMagic); - rOStm.WriteUInt32(rImpGraphic.maPdfData.getLength()); - rOStm.WriteBytes(rImpGraphic.maPdfData.getConstArray(), rImpGraphic.maPdfData.getLength()); + rOStm.WriteUInt32(rImpGraphic.mpPdfData->getLength()); + rOStm.WriteBytes(rImpGraphic.mpPdfData->getConstArray(), rImpGraphic.mpPdfData->getLength()); } else if( rImpGraphic.ImplIsAnimated()) { diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 4e8c19de6541..0c9442c8971e 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -9732,7 +9732,7 @@ void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObject // no pdf data. rEmit.m_nBitmapObject = nBitmapObject; - if (!rGraphic.getPdfData().hasElements()) + if (!rGraphic.hasPdfData()) return; if (m_aContext.UseReferenceXObject) @@ -9740,12 +9740,12 @@ void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObject // Store the original PDF data as an embedded file. m_aEmbeddedFiles.emplace_back(); m_aEmbeddedFiles.back().m_nObject = createObject(); - m_aEmbeddedFiles.back().m_aData = rGraphic.getPdfData(); + m_aEmbeddedFiles.back().m_aData = *rGraphic.getPdfData(); rEmit.m_nEmbeddedObject = m_aEmbeddedFiles.back().m_nObject; } else - rEmit.m_aPDFData = rGraphic.getPdfData(); + rEmit.m_aPDFData = *rGraphic.getPdfData(); rEmit.m_nFormObject = createObject(); rEmit.m_aPixelSize = rGraphic.GetPrefSize(); @@ -9800,7 +9800,7 @@ void PDFWriterImpl::drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const { m_aJPGs.emplace( m_aJPGs.begin() ); JPGEmit& rEmit = m_aJPGs.front(); - if (!rGraphic.getPdfData().hasElements() || m_aContext.UseReferenceXObject) + if (!rGraphic.hasPdfData() || m_aContext.UseReferenceXObject) rEmit.m_nObject = createObject(); rEmit.m_aID = aID; rEmit.m_pStream.reset( pStream ); @@ -9908,7 +9908,7 @@ const PDFWriterImpl::BitmapEmit& PDFWriterImpl::createBitmapEmit( const BitmapEx m_aBitmaps.push_front( BitmapEmit() ); m_aBitmaps.front().m_aID = aID; m_aBitmaps.front().m_aBitmap = aBitmap; - if (!rGraphic.getPdfData().hasElements() || m_aContext.UseReferenceXObject) + if (!rGraphic.hasPdfData() || m_aContext.UseReferenceXObject) m_aBitmaps.front().m_nObject = createObject(); createEmbeddedFile(rGraphic, m_aBitmaps.front().m_aReferenceXObject, m_aBitmaps.front().m_nObject); it = m_aBitmaps.begin(); |