diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-12-28 10:03:18 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-01-13 07:22:31 +0100 |
commit | dcfac443c608aec2ce4e5fa30a3dd021b5a8bfd3 (patch) | |
tree | f1bd5d83427625eadb91d9e3685616efe43e7ada /vcl | |
parent | 68b1ae7b493eea4d77f36a0c8566ca0224f04798 (diff) |
vcl: use BinaryDataContianer in VectorGraphicData
This change is needed so we can use the same data in GfxLink and
in VectorGraphicData. Currently the data needed to be duplicated,
which is less than ideal.
Change-Id: I79419921d09681fa8f0b1ac4bf8ea84199d4aae6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108440
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/pdf/ExternalPDFStreams.hxx | 7 | ||||
-rw-r--r-- | vcl/qa/cppunit/PDFiumLibraryTest.cxx | 30 | ||||
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 9 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 21 | ||||
-rw-r--r-- | vcl/source/gdi/TypeSerializer.cxx | 6 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 4 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 13 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.hxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/vectorgraphicdata.cxx | 81 | ||||
-rw-r--r-- | vcl/source/graphic/GraphicID.cxx | 5 | ||||
-rw-r--r-- | vcl/source/graphic/VectorGraphicSearch.cxx | 4 | ||||
-rw-r--r-- | vcl/source/pdf/ExternalPDFStreams.cxx | 9 |
12 files changed, 104 insertions, 88 deletions
diff --git a/vcl/inc/pdf/ExternalPDFStreams.hxx b/vcl/inc/pdf/ExternalPDFStreams.hxx index ab3d057bd83c..f47aa56578d8 100644 --- a/vcl/inc/pdf/ExternalPDFStreams.hxx +++ b/vcl/inc/pdf/ExternalPDFStreams.hxx @@ -18,6 +18,7 @@ #include <memory> #include <vcl/filter/pdfdocument.hxx> +#include <vcl/BinaryDataContainer.hxx> namespace vcl { @@ -27,7 +28,7 @@ namespace vcl // reused to avoid unnecessary parsing. struct VCL_DLLPUBLIC ExternalPDFStream { - std::vector<sal_uInt8> maData; + BinaryDataContainer maDataContainer; std::shared_ptr<filter::PDFDocument> mpPDFDocument; std::map<sal_Int32, sal_Int32> maCopiedResources; @@ -38,7 +39,7 @@ struct VCL_DLLPUBLIC ExternalPDFStream if (!mpPDFDocument) { SvMemoryStream aPDFStream; - aPDFStream.WriteBytes(maData.data(), maData.size()); + aPDFStream.WriteBytes(maDataContainer.getData(), maDataContainer.getSize()); aPDFStream.Seek(0); mpPDFDocument = std::make_shared<filter::PDFDocument>(); if (!mpPDFDocument->Read(aPDFStream)) @@ -61,7 +62,7 @@ private: public: ExternalPDFStreams() {} - sal_Int32 store(const sal_uInt8* pData, sal_uInt32 nLength); + sal_Int32 store(BinaryDataContainer const& rDataContainer); ExternalPDFStream& get(sal_uInt32 nIndex); }; diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx index c2d55ce61b26..fce6537bcac1 100644 --- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx +++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx @@ -67,12 +67,11 @@ void PDFiumLibraryTest::testDocument() CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, pVectorGraphicData->getVectorGraphicDataType()); - const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); - int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer(); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); CPPUNIT_ASSERT(pPdfium); - auto pDocument = pPdfium->openDocument(pData, nLength); + auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize()); CPPUNIT_ASSERT(pDocument); CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); @@ -95,11 +94,10 @@ void PDFiumLibraryTest::testPages() CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, pVectorGraphicData->getVectorGraphicDataType()); - const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); - int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer(); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); - auto pDocument = pPdfium->openDocument(pData, nLength); + auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize()); CPPUNIT_ASSERT(pDocument); CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); @@ -121,11 +119,10 @@ void PDFiumLibraryTest::testPageObjects() CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, pVectorGraphicData->getVectorGraphicDataType()); - const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); - int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer(); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); - auto pDocument = pPdfium->openDocument(pData, nLength); + auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize()); CPPUNIT_ASSERT(pDocument); CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); @@ -171,11 +168,10 @@ void PDFiumLibraryTest::testAnnotationsMadeInEvince() CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, pVectorGraphicData->getVectorGraphicDataType()); - const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); - int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer(); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); - auto pDocument = pPdfium->openDocument(pData, nLength); + auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize()); CPPUNIT_ASSERT(pDocument); CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); @@ -228,11 +224,10 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat() CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, pVectorGraphicData->getVectorGraphicDataType()); - const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); - int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer(); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); - auto pDocument = pPdfium->openDocument(pData, nLength); + auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize()); CPPUNIT_ASSERT(pDocument); CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); @@ -306,11 +301,10 @@ void PDFiumLibraryTest::testAnnotationsDifferentTypes() CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, pVectorGraphicData->getVectorGraphicDataType()); - const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); - int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer(); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); - auto pDocument = pPdfium->openDocument(pData, nLength); + auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize()); CPPUNIT_ASSERT(pDocument); CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index cd5287f1fe8b..5b4ad1737165 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -2004,7 +2004,8 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r == rVectorGraphicDataPtr->getVectorGraphicDataType() && !bIsEMF) { - rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()); + auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer(); + rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize()); if (rOStm.GetError()) { @@ -2037,7 +2038,8 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength() && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getVectorGraphicDataType()) { - rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()); + auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer(); + rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize()); if (rOStm.GetError()) { @@ -2131,7 +2133,8 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength() && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getVectorGraphicDataType()) { - rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()); + auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer(); + rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize()); if( rOStm.GetError() ) { diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 9c8493fcf58c..bfa27f68358b 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -442,18 +442,17 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG ::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE)); // Save the original PDF stream for later use. - VectorGraphicDataArray aPdfDataArray = createVectorGraphicDataArray(*xStream); - if (!aPdfDataArray.hasElements()) - return 0; + BinaryDataContainer aBinaryDataContainer; + { + VectorGraphicDataArray aPdfDataArray = createVectorGraphicDataArray(*xStream); + if (!aPdfDataArray.hasElements()) + return 0; + const sal_uInt8* pData = reinterpret_cast<const sal_uInt8*>(aPdfDataArray.getConstArray()); + aBinaryDataContainer = BinaryDataContainer(pData, aPdfDataArray.getLength()); + } // Prepare the link with the PDF stream. - const size_t nGraphicContentSize = aPdfDataArray.getLength(); - std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]); - - std::copy(aPdfDataArray.begin(), aPdfDataArray.end(), pGraphicContent.get()); - - auto pGfxLink = std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, - GfxLinkType::NativePdf); + auto pGfxLink = std::make_shared<GfxLink>(aBinaryDataContainer, GfxLinkType::NativePdf); auto pPdfium = vcl::pdf::PDFiumLibrary::get(); @@ -481,7 +480,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG tools::Long nPageHeight = convertTwipToMm100(aPageSize.getY() * pointToTwipconversionRatio); auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>( - aPdfDataArray, VectorGraphicDataType::Pdf, nPageIndex); + aBinaryDataContainer, VectorGraphicDataType::Pdf, nPageIndex); // Create the Graphic with the VectorGraphicDataPtr and link the original PDF stream. // We swap out this Graphic as soon as possible, and a later swap in diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx index 114a8de73719..b1cdf4790c01 100644 --- a/vcl/source/gdi/TypeSerializer.cxx +++ b/vcl/source/gdi/TypeSerializer.cxx @@ -386,10 +386,10 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic) } } - sal_uInt32 nSize = pVectorGraphicData->getVectorGraphicDataArrayLength(); + sal_uInt32 nSize = pVectorGraphicData->getBinaryDataContainer().getSize(); mrStream.WriteUInt32(nSize); - mrStream.WriteBytes( - pVectorGraphicData->getVectorGraphicDataArray().getConstArray(), nSize); + mrStream.WriteBytes(pVectorGraphicData->getBinaryDataContainer().getData(), + nSize); // For backwards compatibility, used to serialize path mrStream.WriteUniOrByteString(OUString(), mrStream.GetStreamCharSet()); } diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 83e3a196d030..9ce49671b5ef 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1207,8 +1207,8 @@ bool ImpGraphic::swapOutGraphic(SvStream& rStream) rStream.WriteUInt32(maVectorGraphicData->getVectorGraphicDataArrayLength()); rStream.WriteBytes( - maVectorGraphicData->getVectorGraphicDataArray().getConstArray(), - maVectorGraphicData->getVectorGraphicDataArrayLength()); + maVectorGraphicData->getBinaryDataContainer().getData(), + maVectorGraphicData->getBinaryDataContainer().getSize()); } else if (ImplIsAnimated()) { diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index cb1efa987c60..aee37877c7f6 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -4484,12 +4484,12 @@ bool PDFWriterImpl::emitEmbeddedFiles() aLine.append(rEmbeddedFile.m_nObject); aLine.append(" 0 obj\n"); aLine.append("<< /Type /EmbeddedFile /Length "); - aLine.append(static_cast<sal_Int64>(rEmbeddedFile.m_pData->size())); + aLine.append(static_cast<sal_Int64>(rEmbeddedFile.m_aDataContainer.getSize())); aLine.append(" >>\nstream\n"); CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength())); aLine.setLength(0); - CHECK_RETURN(writeBuffer(rEmbeddedFile.m_pData->data(), rEmbeddedFile.m_pData->size())); + CHECK_RETURN(writeBuffer(rEmbeddedFile.m_aDataContainer.getData(), rEmbeddedFile.m_aDataContainer.getSize())); aLine.append("\nendstream\nendobj\n\n"); CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength())); @@ -9003,22 +9003,19 @@ void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObject if (!rGraphic.getVectorGraphicData() || rGraphic.getVectorGraphicData()->getVectorGraphicDataType() != VectorGraphicDataType::Pdf) return; - sal_uInt32 nLength = rGraphic.getVectorGraphicData()->getVectorGraphicDataArrayLength(); - auto const & rArray = rGraphic.getVectorGraphicData()->getVectorGraphicDataArray(); + BinaryDataContainer const & rDataContainer = rGraphic.getVectorGraphicData()->getBinaryDataContainer(); if (m_aContext.UseReferenceXObject) { - auto pPDFData = std::make_shared<std::vector<sal_Int8>>(rArray.getConstArray(), rArray.getConstArray() + nLength); - // Store the original PDF data as an embedded file. m_aEmbeddedFiles.emplace_back(); m_aEmbeddedFiles.back().m_nObject = createObject(); - m_aEmbeddedFiles.back().m_pData = pPDFData; + m_aEmbeddedFiles.back().m_aDataContainer = rDataContainer; rEmit.m_nEmbeddedObject = m_aEmbeddedFiles.back().m_nObject; } else { - sal_Int32 aIndex = m_aExternalPDFStreams.store(reinterpret_cast<const sal_uInt8*>(rArray.getConstArray()), nLength); + sal_Int32 aIndex = m_aExternalPDFStreams.store(rDataContainer); rEmit.m_nExternalPDFPageIndex = rGraphic.getVectorGraphicData()->getPageIndex(); rEmit.m_nExternalPDFDataIndex = aIndex; } diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index 25a2774f7ab7..cfbe450e859a 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -50,6 +50,7 @@ #include <o3tl/lru_map.hxx> #include <comphelper/hash.hxx> #include <tools/stream.hxx> +#include <vcl/BinaryDataContainer.hxx> #include <vcl/filter/pdfobjectcontainer.hxx> #include <pdf/ExternalPDFStreams.hxx> @@ -402,7 +403,7 @@ struct PDFEmbeddedFile /// ID of the file. sal_Int32 m_nObject; /// Contents of the file. - std::shared_ptr<std::vector<sal_Int8>> m_pData; + BinaryDataContainer m_aDataContainer; PDFEmbeddedFile() : m_nObject(0) diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx index 046cf9e503ad..4bd56a01a887 100644 --- a/vcl/source/gdi/vectorgraphicdata.cxx +++ b/vcl/source/gdi/vectorgraphicdata.cxx @@ -39,6 +39,7 @@ #include <vcl/outdev.hxx> #include <vcl/wmfexternal.hxx> #include <vcl/pdfread.hxx> +#include <unotools/streamwrap.hxx> using namespace ::com::sun::star; @@ -117,9 +118,9 @@ bool VectorGraphicData::operator==(const VectorGraphicData& rCandidate) const if (getVectorGraphicDataArrayLength() == rCandidate.getVectorGraphicDataArrayLength()) { if (0 == memcmp( - getVectorGraphicDataArray().getConstArray(), - rCandidate.getVectorGraphicDataArray().getConstArray(), - getVectorGraphicDataArrayLength())) + maDataContainer.getData(), + rCandidate.maDataContainer.getData(), + maDataContainer.getSize())) { return true; } @@ -151,8 +152,8 @@ void VectorGraphicData::ensurePdfReplacement() sal_Int32 nUsePageIndex = 0; if (mnPageIndex >= 0) nUsePageIndex = mnPageIndex; - vcl::RenderPDFBitmaps(maVectorGraphicDataArray.getConstArray(), - maVectorGraphicDataArray.getLength(), aBitmaps, nUsePageIndex, 1, + vcl::RenderPDFBitmaps(maDataContainer.getData(), + maDataContainer.getSize(), aBitmaps, nUsePageIndex, 1, &maSizeHint); if (!aBitmaps.empty()) maReplacement = aBitmaps[0]; @@ -181,7 +182,7 @@ void VectorGraphicData::ensureReplacement() void VectorGraphicData::ensureSequenceAndRange() { - if (mbSequenceCreated || !maVectorGraphicDataArray.hasElements()) + if (mbSequenceCreated || maDataContainer.isEmpty()) return; // import SVG to maSequence, also set maRange @@ -194,11 +195,15 @@ void VectorGraphicData::ensureSequenceAndRange() { case VectorGraphicDataType::Svg: { + css::uno::Sequence<sal_Int8> aDataSequence(maDataContainer.getSize()); + std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aDataSequence.begin()); + const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence)); + + const uno::Reference< graphic::XSvgParser > xSvgParser = graphic::SvgTools::create(xContext); - const uno::Reference< io::XInputStream > myInputStream(new comphelper::SequenceInputStream(maVectorGraphicDataArray)); - if (myInputStream.is()) - maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(myInputStream, OUString())); + if (xInputStream.is()) + maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(xInputStream, OUString())); break; } @@ -206,7 +211,11 @@ void VectorGraphicData::ensureSequenceAndRange() case VectorGraphicDataType::Wmf: { const uno::Reference< graphic::XEmfParser > xEmfParser = graphic::EmfTools::create(xContext); - const uno::Reference< io::XInputStream > myInputStream(new comphelper::SequenceInputStream(maVectorGraphicDataArray)); + + css::uno::Sequence<sal_Int8> aDataSequence(maDataContainer.getSize()); + std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aDataSequence.begin()); + const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence)); + uno::Sequence< ::beans::PropertyValue > aSequence; if (mpExternalHeader) @@ -214,7 +223,7 @@ void VectorGraphicData::ensureSequenceAndRange() aSequence = mpExternalHeader->getSequence(); } - if (myInputStream.is()) + if (xInputStream.is()) { // Pass the size hint of the graphic to the EMF parser. geometry::RealPoint2D aSizeHint; @@ -224,15 +233,12 @@ void VectorGraphicData::ensureSequenceAndRange() if (!mbEnableEMFPlus) { - auto aVector - = comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>( - aSequence); - aVector.push_back( - comphelper::makePropertyValue("EMFPlusEnable", uno::makeAny(false))); + auto aVector = comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(aSequence); + aVector.push_back(comphelper::makePropertyValue("EMFPlusEnable", uno::makeAny(false))); aSequence = comphelper::containerToSequence(aVector); } - maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, OUString(), aSequence)); + maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(xInputStream, OUString(), aSequence)); } break; @@ -243,7 +249,10 @@ void VectorGraphicData::ensureSequenceAndRange() uno::Sequence<beans::PropertyValue> aDecompositionParameters = comphelper::InitPropertySequence({ {"PageIndex", uno::makeAny<sal_Int32>(mnPageIndex)}, }); - auto xPrimitive2D = xPdfDecomposer->getDecomposition(maVectorGraphicDataArray, aDecompositionParameters); + // TODO: change xPdfDecomposer to use BinaryDataContainer directly + VectorGraphicDataArray aVectorGraphicDataArray(maDataContainer.getSize()); + std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aVectorGraphicDataArray.begin()); + auto xPrimitive2D = xPdfDecomposer->getDecomposition(aVectorGraphicDataArray, aDecompositionParameters); maSequence = comphelper::sequenceToContainer<std::deque<uno::Reference<graphic::XPrimitive2D>>>(xPrimitive2D); break; @@ -280,13 +289,13 @@ void VectorGraphicData::ensureSequenceAndRange() std::pair<VectorGraphicData::State, size_t> VectorGraphicData::getSizeBytes() const { - if (!maSequence.empty() && maVectorGraphicDataArray.hasElements()) + if (!maSequence.empty() && !maDataContainer.isEmpty()) { - return std::make_pair(State::PARSED, maVectorGraphicDataArray.getLength() + mNestedBitmapSize); + return std::make_pair(State::PARSED, maDataContainer.getSize() + mNestedBitmapSize); } else { - return std::make_pair(State::UNPARSED, maVectorGraphicDataArray.getLength()); + return std::make_pair(State::UNPARSED, maDataContainer.getSize()); } } @@ -294,7 +303,22 @@ VectorGraphicData::VectorGraphicData( const VectorGraphicDataArray& rVectorGraphicDataArray, VectorGraphicDataType eVectorDataType, sal_Int32 nPageIndex) -: maVectorGraphicDataArray(rVectorGraphicDataArray), +: maDataContainer(reinterpret_cast<const sal_uInt8*>(rVectorGraphicDataArray.begin()), rVectorGraphicDataArray.getLength()), + mbSequenceCreated(false), + maRange(), + maSequence(), + maReplacement(), + mNestedBitmapSize(0), + meVectorGraphicDataType(eVectorDataType), + mnPageIndex(nPageIndex) +{ +} + +VectorGraphicData::VectorGraphicData( + const BinaryDataContainer& rDataContainer, + VectorGraphicDataType eVectorDataType, + sal_Int32 nPageIndex) +: maDataContainer(rDataContainer), mbSequenceCreated(false), maRange(), maSequence(), @@ -308,8 +332,7 @@ VectorGraphicData::VectorGraphicData( VectorGraphicData::VectorGraphicData( const OUString& rPath, VectorGraphicDataType eVectorDataType) -: maVectorGraphicDataArray(), - mbSequenceCreated(false), +: mbSequenceCreated(false), maRange(), maSequence(), maReplacement(), @@ -323,12 +346,12 @@ VectorGraphicData::VectorGraphicData( const sal_uInt32 nStmLen(rIStm.remainingSize()); if (nStmLen) { - maVectorGraphicDataArray.realloc(nStmLen); - rIStm.ReadBytes(maVectorGraphicDataArray.begin(), nStmLen); + VectorGraphicDataArray aVectorGraphicDataArray(nStmLen); + rIStm.ReadBytes(aVectorGraphicDataArray.begin(), nStmLen); - if (rIStm.GetError()) + if (!rIStm.GetError()) { - maVectorGraphicDataArray = VectorGraphicDataArray(); + maDataContainer = BinaryDataContainer(reinterpret_cast<const sal_uInt8*>(aVectorGraphicDataArray.begin()), aVectorGraphicDataArray.getLength()); } } } @@ -360,7 +383,7 @@ const BitmapEx& VectorGraphicData::getReplacement() const BitmapChecksum VectorGraphicData::GetChecksum() const { - return vcl_get_checksum(0, maVectorGraphicDataArray.getConstArray(), maVectorGraphicDataArray.getLength()); + return vcl_get_checksum(0, maDataContainer.getData(), maDataContainer.getSize()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/graphic/GraphicID.cxx b/vcl/source/graphic/GraphicID.cxx index 1cad217241fa..cfd2d751d246 100644 --- a/vcl/source/graphic/GraphicID.cxx +++ b/vcl/source/graphic/GraphicID.cxx @@ -39,9 +39,8 @@ GraphicID::GraphicID(ImpGraphic const& rGraphic) mnID1 |= rVectorGraphicDataPtr->getVectorGraphicDataArrayLength(); mnID2 = basegfx::fround(rRange.getWidth()); mnID3 = basegfx::fround(rRange.getHeight()); - mnID4 = vcl_get_checksum( - 0, rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), - rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()); + mnID4 = vcl_get_checksum(0, rVectorGraphicDataPtr->getBinaryDataContainer().getData(), + rVectorGraphicDataPtr->getBinaryDataContainer().getSize()); } else if (rGraphic.ImplIsAnimated()) { diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx index dfa747bc1a6a..3c1003d29654 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -252,8 +252,8 @@ bool VectorGraphicSearch::search(OUString const& rSearchString, bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rData) { mpImplementation->mpPdfDocument - = FPDF_LoadMemDocument(rData->getVectorGraphicDataArray().getConstArray(), - rData->getVectorGraphicDataArrayLength(), /*password=*/nullptr); + = FPDF_LoadMemDocument(rData->getBinaryDataContainer().getData(), + rData->getBinaryDataContainer().getSize(), /*password=*/nullptr); if (!mpImplementation->mpPdfDocument) { diff --git a/vcl/source/pdf/ExternalPDFStreams.cxx b/vcl/source/pdf/ExternalPDFStreams.cxx index 08f31ed22829..e3716e1e0aed 100644 --- a/vcl/source/pdf/ExternalPDFStreams.cxx +++ b/vcl/source/pdf/ExternalPDFStreams.cxx @@ -13,19 +13,18 @@ namespace vcl { -sal_Int32 ExternalPDFStreams::store(const sal_uInt8* pData, sal_uInt32 nLength) +sal_Int32 ExternalPDFStreams::store(BinaryDataContainer const& rDataContainer) { sal_Int32 nIndex = -1; - std::vector<sal_uInt8> aHash - = comphelper::Hash::calculateHash(pData, nLength, comphelper::HashType::SHA1); + std::vector<sal_uInt8> aHash = comphelper::Hash::calculateHash( + rDataContainer.getData(), rDataContainer.getSize(), comphelper::HashType::SHA1); auto it = maStreamIndexMap.find(aHash); if (it == maStreamIndexMap.end()) { auto& rExternalStream = maStreamList.emplace_back(); - rExternalStream.maData.resize(nLength); - std::copy(pData, pData + nLength, rExternalStream.maData.begin()); + rExternalStream.maDataContainer = rDataContainer; nIndex = maStreamList.size() - 1; maStreamIndexMap.emplace(aHash, nIndex); } |