Rebased ref, commits from common ancestor: commit 9b6ecd3e99015d436224decc2c3d611ac194f9a6 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Dec 27 19:07:57 2020 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sun Dec 27 19:07:57 2020 +0900
vcl: implement BinaryDataContainer copy, move + test Also remove constructor that takes size only - BinaryDataContainer should always be constructed with data, that is copied into the container and should be immutable. Change-Id: Ic61b393b7729b948843bd20e6676c9290c68936f diff --git a/include/vcl/BinaryDataContainer.hxx b/include/vcl/BinaryDataContainer.hxx index 844d6c5bb81f..da0607cdfc97 100644 --- a/include/vcl/BinaryDataContainer.hxx +++ b/include/vcl/BinaryDataContainer.hxx @@ -27,13 +27,29 @@ private: public: explicit BinaryDataContainer(); - explicit BinaryDataContainer(size_t nSize); explicit BinaryDataContainer(const sal_uInt8* pData, size_t nSize); - explicit BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer) = default; - explicit BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer) = default; - BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer) = default; - BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) = default; + BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer) + : mpData(rBinaryDataContainer.mpData) + { + } + + BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer) + : mpData(std::move(rBinaryDataContainer.mpData)) + { + } + + BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer) + { + mpData = rBinaryDataContainer.mpData; + return *this; + } + + BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) + { + mpData = std::move(rBinaryDataContainer.mpData); + return *this; + } size_t getSize() const { return mpData ? mpData->size() : 0; } bool isEmpty() const { return mpData ? mpData->empty() : true; } diff --git a/vcl/CppunitTest_vcl_graphic_test.mk b/vcl/CppunitTest_vcl_graphic_test.mk index 2f2c61735ef8..9221fd474fdd 100644 --- a/vcl/CppunitTest_vcl_graphic_test.mk +++ b/vcl/CppunitTest_vcl_graphic_test.mk @@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_graphic_test, \ vcl/qa/cppunit/GraphicFormatDetectorTest \ vcl/qa/cppunit/GraphicNativeMetadataTest \ vcl/qa/cppunit/VectorGraphicSearchTest \ + vcl/qa/cppunit/BinaryDataContainerTest \ )) $(eval $(call gb_CppunitTest_use_externals,vcl_graphic_test, \ diff --git a/vcl/qa/cppunit/BinaryDataContainerTest.cxx b/vcl/qa/cppunit/BinaryDataContainerTest.cxx new file mode 100644 index 000000000000..597e7d4bc3aa --- /dev/null +++ b/vcl/qa/cppunit/BinaryDataContainerTest.cxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <vcl/BinaryDataContainer.hxx> + +using namespace css; + +namespace +{ +class BinaryDataContainerTest : public CppUnit::TestFixture +{ + void test(); + + CPPUNIT_TEST_SUITE(BinaryDataContainerTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void BinaryDataContainerTest::test() +{ + { + BinaryDataContainer aContainer; + CPPUNIT_ASSERT_EQUAL(true, bool(aContainer.isEmpty())); + CPPUNIT_ASSERT_EQUAL(size_t(0), aContainer.getSize()); + } + { + std::vector<sal_uInt8> aTestByteArray = { 1, 2, 3, 4 }; + BinaryDataContainer aContainer(aTestByteArray.data(), aTestByteArray.size()); + CPPUNIT_ASSERT_EQUAL(false, bool(aContainer.isEmpty())); + CPPUNIT_ASSERT_EQUAL(size_t(4), aContainer.getSize()); + + // Test Copy + BinaryDataContainer aCopyOfContainer = aContainer; + CPPUNIT_ASSERT_EQUAL(false, bool(aCopyOfContainer.isEmpty())); + CPPUNIT_ASSERT_EQUAL(size_t(4), aCopyOfContainer.getSize()); + CPPUNIT_ASSERT_EQUAL(aCopyOfContainer.getData(), aContainer.getData()); + + // Test Move + BinaryDataContainer aMovedInContainer = std::move(aCopyOfContainer); + CPPUNIT_ASSERT_EQUAL(false, bool(aMovedInContainer.isEmpty())); + CPPUNIT_ASSERT_EQUAL(size_t(4), aMovedInContainer.getSize()); + CPPUNIT_ASSERT_EQUAL(aMovedInContainer.getData(), aContainer.getData()); + + CPPUNIT_ASSERT_EQUAL(true, bool(aCopyOfContainer.isEmpty())); + CPPUNIT_ASSERT_EQUAL(size_t(0), aCopyOfContainer.getSize()); + } +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(BinaryDataContainerTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/graphic/BinaryDataContainer.cxx b/vcl/source/graphic/BinaryDataContainer.cxx index 4c556195fe6a..7576852215b1 100644 --- a/vcl/source/graphic/BinaryDataContainer.cxx +++ b/vcl/source/graphic/BinaryDataContainer.cxx @@ -13,11 +13,6 @@ BinaryDataContainer::BinaryDataContainer() = default; -BinaryDataContainer::BinaryDataContainer(size_t nSize) - : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize)) -{ -} - BinaryDataContainer::BinaryDataContainer(const sal_uInt8* pData, size_t nSize) : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize)) { commit 089cd9184635d69733c05dff1b1907659db97e34 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Dec 26 12:41:08 2020 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Dec 26 21:05:39 2020 +0900 vcl: remove "path" attribute from VectorGraphicData This isn't used for anything important for the vector graphic and is mostly empty string anyways. Change-Id: I1c5b52b5b407bd320cb5053141f1699971607399 diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx index cb3963947d2d..e231435312e8 100644 --- a/include/vcl/vectorgraphicdata.hxx +++ b/include/vcl/vectorgraphicdata.hxx @@ -57,9 +57,6 @@ private: // the file and length VectorGraphicDataArray maVectorGraphicDataArray; - // The absolute Path if available - OUString maPath; - // on demand created content bool mbSequenceCreated; basegfx::B2DRange maRange; @@ -90,7 +87,6 @@ private: public: VectorGraphicData( const VectorGraphicDataArray& rVectorGraphicDataArray, - const OUString& rPath, VectorGraphicDataType eVectorDataType, sal_Int32 nPageIndex = -1); ~VectorGraphicData(); @@ -106,7 +102,7 @@ public: sal_uInt32 getVectorGraphicDataArrayLength() const { return maVectorGraphicDataArray.getLength(); } enum class State { UNPARSED, PARSED }; std::pair<State, size_t> getSizeBytes() const; - const OUString& getPath() const { return maPath; } + const VectorGraphicDataType& getVectorGraphicDataType() const { return meVectorGraphicDataType; } /// data read and evtl. on demand creation diff --git a/sfx2/source/appl/appmisc.cxx b/sfx2/source/appl/appmisc.cxx index 37011ff1cc2f..c62fcd47a1e5 100644 --- a/sfx2/source/appl/appmisc.cxx +++ b/sfx2/source/appl/appmisc.cxx @@ -166,13 +166,13 @@ bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWid std::vector<sal_uInt8> aBinaryData; OUString aPath = aObj.PathToFileName(); - if (!loadDataFromFile(aObj.PathToFileName(), aBinaryData)) + if (!loadDataFromFile(aPath, aBinaryData)) return false; VectorGraphicDataArray aVectorGraphicDataArray; std::copy(aBinaryData.cbegin(), aBinaryData.cend(), aVectorGraphicDataArray.begin()); - VectorGraphicData aVectorGraphicData(aVectorGraphicDataArray, aPath, VectorGraphicDataType::Svg); + VectorGraphicData aVectorGraphicData(aVectorGraphicDataArray, VectorGraphicDataType::Svg); // transform into [0,0,width,width*aspect] std dimensions diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx index 4c6a1a6972dc..e68d5cdc6c0e 100644 --- a/vcl/qa/cppunit/GraphicTest.cxx +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -325,6 +325,10 @@ void GraphicTest::testUnloadedGraphicSizeUnit() Size aMtfSize100(42, 42); SvFileStream aStream(aURL, StreamMode::READ); Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100); + + CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize()); + + // Force it to swap in aGraphic.makeAvailable(); // Without the accompanying fix in place, this test would have failed with: @@ -753,10 +757,10 @@ void GraphicTest::testSwappingVectorGraphic_SVG_WithoutGfxLink() CPPUNIT_ASSERT_EQUAL(true, bool(xStream)); // Check size of the stream - CPPUNIT_ASSERT_EQUAL(sal_uInt64(249), xStream->remainingSize()); + CPPUNIT_ASSERT_EQUAL(sal_uInt64(247), xStream->remainingSize()); std::vector<unsigned char> aHash = calculateHash(xStream); - CPPUNIT_ASSERT_EQUAL(std::string("322da9ea0683f03ce35cf8a71e59b686b9be28e8"), + CPPUNIT_ASSERT_EQUAL(std::string("666820973fd95e6cd9e7bc5f1c53732acbc99326"), toHexString(aHash)); } diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 2a708336d233..02747b4e869b 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -1620,7 +1620,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, if(!aMemStream.GetError() ) { - auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, rPath, VectorGraphicDataType::Svg); + auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, VectorGraphicDataType::Svg); rGraphic = Graphic(aVectorGraphicDataPtr); bOkay = true; } @@ -1633,7 +1633,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, if(!rIStream.GetError()) { - auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, rPath, VectorGraphicDataType::Svg); + auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, VectorGraphicDataType::Svg); rGraphic = Graphic(aVectorGraphicDataPtr); bOkay = true; } @@ -1710,7 +1710,6 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>( aNewData, - rPath, aDataType); if (pExtHeader) diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index dbfa5ceeaf68..c70363cef0f8 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -240,8 +240,8 @@ bool importPdfVectorGraphicData(SvStream& rStream, return false; } - rVectorGraphicData = std::make_shared<VectorGraphicData>(aPdfDataArray, OUString(), - VectorGraphicDataType::Pdf); + rVectorGraphicData + = std::make_shared<VectorGraphicData>(aPdfDataArray, VectorGraphicDataType::Pdf); return true; } @@ -481,7 +481,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, OUString(), VectorGraphicDataType::Pdf, nPageIndex); + aPdfDataArray, 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/filter/wmf/wmf.cxx b/vcl/source/filter/wmf/wmf.cxx index 8a04bc1d3025..70ff37f7473f 100644 --- a/vcl/source/filter/wmf/wmf.cxx +++ b/vcl/source/filter/wmf/wmf.cxx @@ -54,7 +54,6 @@ bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF ) auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>( aNewData, - OUString(), VectorGraphicDataType::Emf); // create a Graphic and grep Metafile from it @@ -97,7 +96,7 @@ bool ConvertGraphicToWMF(const Graphic& rGraphic, SvStream& rTargetStream, uno::Sequence<sal_Int8> aData(reinterpret_cast<const sal_Int8*>(aLink.GetData()), aLink.GetDataSize()); auto aVectorGraphicData - = std::make_shared<VectorGraphicData>(aData, OUString(), VectorGraphicDataType::Emf); + = std::make_shared<VectorGraphicData>(aData, VectorGraphicDataType::Emf); aVectorGraphicData->setEnableEMFPlus(false); Graphic aGraphic(aVectorGraphicData); bool bRet = ConvertGDIMetaFileToWMF(aGraphic.GetGDIMetaFile(), rTargetStream, pConfigItem, diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx index e501c58c6be7..114a8de73719 100644 --- a/vcl/source/gdi/TypeSerializer.cxx +++ b/vcl/source/gdi/TypeSerializer.cxx @@ -281,7 +281,6 @@ void TypeSerializer::readGraphic(Graphic& rGraphic) VectorGraphicDataArray aData(nLength); mrStream.ReadBytes(aData.getArray(), nLength); - OUString aPath = mrStream.ReadUniOrByteString(mrStream.GetStreamCharSet()); if (!mrStream.GetError()) { @@ -301,7 +300,7 @@ void TypeSerializer::readGraphic(Graphic& rGraphic) } auto aVectorGraphicDataPtr - = std::make_shared<VectorGraphicData>(aData, aPath, aDataType); + = std::make_shared<VectorGraphicData>(aData, aDataType); rGraphic = Graphic(aVectorGraphicDataPtr); } } @@ -391,8 +390,8 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic) mrStream.WriteUInt32(nSize); mrStream.WriteBytes( pVectorGraphicData->getVectorGraphicDataArray().getConstArray(), nSize); - mrStream.WriteUniOrByteString(pVectorGraphicData->getPath(), - mrStream.GetStreamCharSet()); + // For backwards compatibility, used to serialize path + mrStream.WriteUniOrByteString(OUString(), mrStream.GetStreamCharSet()); } else if (aGraphic.IsAnimated()) { diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 02709008d31f..8dc81eb4987f 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1202,8 +1202,6 @@ bool ImpGraphic::swapOutGraphic(SvStream& rStream) rStream.WriteBytes( maVectorGraphicData->getVectorGraphicDataArray().getConstArray(), maVectorGraphicData->getVectorGraphicDataArrayLength()); - - rStream.WriteUniOrByteString(maVectorGraphicData->getPath(), rStream.GetStreamCharSet()); } else if (ImplIsAnimated()) { @@ -1557,8 +1555,6 @@ bool ImpGraphic::swapInGraphic(SvStream& rStream) rStream.ReadBytes(aNewData.getArray(), nVectorGraphicDataArrayLength); - OUString aPath = rStream.ReadUniOrByteString(rStream.GetStreamCharSet()); - if (rStream.GetError()) return false; @@ -1582,7 +1578,7 @@ bool ImpGraphic::swapInGraphic(SvStream& rStream) return false; } - auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, aPath, aDataType); + auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, aDataType); if (!rStream.GetError()) { diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx index b36b232061b2..61618b7adfe8 100644 --- a/vcl/source/gdi/vectorgraphicdata.cxx +++ b/vcl/source/gdi/vectorgraphicdata.cxx @@ -198,7 +198,7 @@ void VectorGraphicData::ensureSequenceAndRange() 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, maPath)); + maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(myInputStream, OUString())); break; } @@ -232,7 +232,7 @@ void VectorGraphicData::ensureSequenceAndRange() aSequence = comphelper::containerToSequence(aVector); } - maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, maPath, aSequence)); + maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, OUString(), aSequence)); } break; @@ -292,11 +292,9 @@ std::pair<VectorGraphicData::State, size_t> VectorGraphicData::getSizeBytes() co VectorGraphicData::VectorGraphicData( const VectorGraphicDataArray& rVectorGraphicDataArray, - const OUString& rPath, VectorGraphicDataType eVectorDataType, sal_Int32 nPageIndex) : maVectorGraphicDataArray(rVectorGraphicDataArray), - maPath(rPath), mbSequenceCreated(false), maRange(), maSequence(), _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits