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 /vcl | |
parent | 99bbed5cd87af8ff1b7e3d197d937fb17af021e6 (diff) |
pdf: share pdf data in Graphic
Change-Id: I8146aa4e206788afff71142e1877fd7a885f4652
Diffstat (limited to 'vcl')
-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 |
4 files changed, 48 insertions, 32 deletions
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(); |