include/vcl/BinaryDataContainer.hxx | 36 +++------ include/vcl/vectorgraphicdata.hxx | 7 - offapi/UnoApi_offapi.mk | 2 offapi/com/sun/star/util/BinaryDataContainer.idl | 30 +++++++ offapi/com/sun/star/util/XBinaryDataContainer.idl | 29 +++++++ sfx2/source/appl/appmisc.cxx | 37 +++++++++ vcl/Library_vcl.mk | 2 vcl/qa/cppunit/GraphicTest.cxx | 8 +- vcl/source/filter/graphicfilter.cxx | 5 - vcl/source/filter/ipdf/pdfread.cxx | 6 - vcl/source/filter/wmf/wmf.cxx | 3 vcl/source/gdi/TypeSerializer.cxx | 7 - vcl/source/gdi/impgraph.cxx | 9 -- vcl/source/gdi/vectorgraphicdata.cxx | 35 --------- vcl/source/graphic/BinaryDataContainer.cxx | 36 +++++++++ vcl/source/graphic/UnoBinaryDataContainer.cxx | 84 ++++++++++++++++++++++ vcl/vcl.common.component | 4 + 17 files changed, 256 insertions(+), 84 deletions(-)
New commits: commit 35066cbbebfb897691e9a52480300a356a201c8c 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 14:55:36 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..54c99b4f197e 100644 --- a/sfx2/source/appl/appmisc.cxx +++ b/sfx2/source/appl/appmisc.cxx @@ -172,7 +172,7 @@ bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWid 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(), commit 02e54ce96184a90e8f53746befd9566ab864b82d Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Dec 26 08:50:01 2020 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Dec 26 08:50:01 2020 +0900 vcl: remove VectorGraphicData const. which loads data from file It is not VectorGraphicData responsibility to load data from a file, so remove the constructor which attemts to do it and move it to the only user of this constructor. Change-Id: Ie03defb0cb4f17f4039aee44bb3e41bffc17488d diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx index 1787d060e11b..cb3963947d2d 100644 --- a/include/vcl/vectorgraphicdata.hxx +++ b/include/vcl/vectorgraphicdata.hxx @@ -93,7 +93,6 @@ public: const OUString& rPath, VectorGraphicDataType eVectorDataType, sal_Int32 nPageIndex = -1); - VectorGraphicData(const OUString& rPath, VectorGraphicDataType eVectorDataType); ~VectorGraphicData(); /// compare op diff --git a/sfx2/source/appl/appmisc.cxx b/sfx2/source/appl/appmisc.cxx index f7ddfb297d6a..37011ff1cc2f 100644 --- a/sfx2/source/appl/appmisc.cxx +++ b/sfx2/source/appl/appmisc.cxx @@ -31,6 +31,7 @@ #include <rtl/bootstrap.hxx> #include <svl/stritem.hxx> #include <tools/urlobj.hxx> +#include <tools/stream.hxx> #include <sfx2/app.hxx> #include <appdata.hxx> @@ -124,6 +125,32 @@ static bool FileExists( const INetURLObject& rURL ) return bRet; } +namespace +{ + +bool loadDataFromFile(OUString const & rPath, std::vector<sal_uInt8> & rBinaryData) +{ + SvFileStream rStream(rPath, StreamMode::STD_READ); + if (rStream.GetError()) + return false; + + const sal_uInt32 nStreamLength(rStream.remainingSize()); + + if (nStreamLength) + { + rBinaryData.clear(); + rBinaryData.resize(nStreamLength); + rStream.ReadBytes(rBinaryData.data(), nStreamLength); + + if (!rStream.GetError()) + { + return true; + } + } + return false; +} +} // end anonymous namespace + bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth) { // Load from disk @@ -137,7 +164,15 @@ bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWid if ( !FileExists(aObj) ) return false; - VectorGraphicData aVectorGraphicData(aObj.PathToFileName(), VectorGraphicDataType::Svg); + std::vector<sal_uInt8> aBinaryData; + OUString aPath = aObj.PathToFileName(); + if (!loadDataFromFile(aObj.PathToFileName(), aBinaryData)) + return false; + + VectorGraphicDataArray aVectorGraphicDataArray; + std::copy(aBinaryData.cbegin(), aBinaryData.cend(), aVectorGraphicDataArray.begin()); + + VectorGraphicData aVectorGraphicData(aVectorGraphicDataArray, aPath, VectorGraphicDataType::Svg); // transform into [0,0,width,width*aspect] std dimensions diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx index a8134a60c852..b36b232061b2 100644 --- a/vcl/source/gdi/vectorgraphicdata.cxx +++ b/vcl/source/gdi/vectorgraphicdata.cxx @@ -307,35 +307,6 @@ VectorGraphicData::VectorGraphicData( { } -VectorGraphicData::VectorGraphicData( - const OUString& rPath, - VectorGraphicDataType eVectorDataType) -: maVectorGraphicDataArray(), - maPath(rPath), - mbSequenceCreated(false), - maRange(), - maSequence(), - maReplacement(), - mNestedBitmapSize(0), - meVectorGraphicDataType(eVectorDataType), - mnPageIndex(-1) -{ - SvFileStream rIStm(rPath, StreamMode::STD_READ); - if(rIStm.GetError()) - return; - const sal_uInt32 nStmLen(rIStm.remainingSize()); - if (nStmLen) - { - maVectorGraphicDataArray.realloc(nStmLen); - rIStm.ReadBytes(maVectorGraphicDataArray.begin(), nStmLen); - - if (rIStm.GetError()) - { - maVectorGraphicDataArray = VectorGraphicDataArray(); - } - } -} - VectorGraphicData::~VectorGraphicData() { } commit fdaf912672195e94f756ffd64acfdab77c86f783 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Dec 26 08:48:03 2020 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Dec 26 08:48:03 2020 +0900 vcl: remove unneeded check Change-Id: I3da0449afe3d21581934278f9a6fe03c4e652214 diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 6e444e3712ef..02709008d31f 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -786,8 +786,7 @@ Size ImpGraphic::ImplGetPrefSize() const case GraphicType::GdiMetafile: { - if (ImplIsSupportedGraphic()) - aSize = maMetaFile.GetPrefSize(); + aSize = maMetaFile.GetPrefSize(); } break; commit d99f906eac415029f3a74b53083b4a8407a8765e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Dec 25 20:10:44 2020 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Fri Dec 25 20:10:44 2020 +0900 vcl: add an UNO interface and impl. for BinaryDataContainer Change-Id: Icbc384892bee8c31eb7f3a39ff9a64f1199b23b1 diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index eabb1272588a..5e7fa60ebc34 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -446,6 +446,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/ui/test,\ UITest \ )) $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/util,\ + BinaryDataContainer \ JobManager \ NumberFormatter \ NumberFormatsSupplier \ @@ -4143,6 +4144,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\ VetoException \ XAccounting \ XAtomServer \ + XBinaryDataContainer \ XBroadcaster \ XCancellable \ XChainable \ diff --git a/offapi/com/sun/star/util/BinaryDataContainer.idl b/offapi/com/sun/star/util/BinaryDataContainer.idl new file mode 100644 index 000000000000..be4102a20b1c --- /dev/null +++ b/offapi/com/sun/star/util/BinaryDataContainer.idl @@ -0,0 +1,30 @@ +/* -*- 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/. + */ + +#ifndef com_sun_star_util_BinaryDataContainer_idl +#define com_sun_star_util_BinaryDataContainer_idl + + +module com { module sun { module star { module util +{ + +/** Implementation of a container for binary data. + + @since LibreOffice 7.2 + */ + +service BinaryDataContainer : XBinaryDataContainer +{ +}; + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/com/sun/star/util/XBinaryDataContainer.idl b/offapi/com/sun/star/util/XBinaryDataContainer.idl new file mode 100644 index 000000000000..563ac4db7e00 --- /dev/null +++ b/offapi/com/sun/star/util/XBinaryDataContainer.idl @@ -0,0 +1,29 @@ +/* -*- 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/. + */ + +#ifndef com_sun_star_util_XBinaryDataContainer_idl +#define com_sun_star_util_XBinaryDataContainer_idl + +module com { module sun { module star { module util +{ + +/** Container for binary data, typically an in-memory content of files. + + @since LibreOffice 7.2 + */ +interface XBinaryDataContainer +{ + sequence<byte> getCopyAsByteSequence(); +}; + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index b326147ca5a1..a1ea249cb964 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -337,6 +337,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/graphic/GraphicObject2 \ vcl/source/graphic/GraphicReader \ vcl/source/graphic/Manager \ + vcl/source/graphic/UnoBinaryDataContainer \ vcl/source/graphic/UnoGraphic \ vcl/source/graphic/UnoGraphicMapper \ vcl/source/graphic/UnoGraphicDescriptor \ diff --git a/vcl/source/graphic/UnoBinaryDataContainer.cxx b/vcl/source/graphic/UnoBinaryDataContainer.cxx new file mode 100644 index 000000000000..cd6ce99d4a39 --- /dev/null +++ b/vcl/source/graphic/UnoBinaryDataContainer.cxx @@ -0,0 +1,84 @@ +/* -*- 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 <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.hxx> + +#include <com/sun/star/util/XBinaryDataContainer.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <vcl/BinaryDataContainer.hxx> + +using namespace css; + +namespace +{ +typedef ::cppu::WeakImplHelper<util::XBinaryDataContainer, css::lang::XServiceInfo> + BinaryDataContainer_BASE; + +class UnoBinaryDataContainer : public BinaryDataContainer_BASE +{ +private: + BinaryDataContainer maBinaryDataContainer; + +public: + explicit UnoBinaryDataContainer() {} + + BinaryDataContainer const& getBinaryDataContainer() { return maBinaryDataContainer; } + + void setBinaryDataContainer(BinaryDataContainer const& rBinaryDataContainer) + { + maBinaryDataContainer = rBinaryDataContainer; + } + + // XBinaryDataContainer + css::uno::Sequence<sal_Int8> SAL_CALL getCopyAsByteSequence() override + { + if (maBinaryDataContainer.isEmpty()) + return css::uno::Sequence<sal_Int8>(); + + size_t nSize = maBinaryDataContainer.getSize(); + + css::uno::Sequence<sal_Int8> aData(nSize); + + std::copy(maBinaryDataContainer.cbegin(), maBinaryDataContainer.cend(), aData.getArray()); + + return aData; + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override + { + return "com.sun.star.util.BinaryDataContainer"; + } + + virtual sal_Bool SAL_CALL supportsService(OUString const& rServiceName) override + { + return cppu::supportsService(this, rServiceName); + } + + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override + { + return uno::Sequence<OUString>{ "com.sun.star.util.BinaryDataContainer" }; + } +}; + +} // end anonymous namespace + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_util_BinaryDataContainer_get_implementation( + SAL_UNUSED_PARAMETER uno::XComponentContext*, + SAL_UNUSED_PARAMETER uno::Sequence<uno::Any> const&) +{ + return cppu::acquire(new UnoBinaryDataContainer()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/vcl.common.component b/vcl/vcl.common.component index 2665a136afcc..abf5da9c10dd 100644 --- a/vcl/vcl.common.component +++ b/vcl/vcl.common.component @@ -35,4 +35,8 @@ constructor="dtrans_CMimeContentTypeFactory_get_implementation"> <service name="com.sun.star.datatransfer.MimeContentTypeFactory"/> </implementation> + <implementation name="com.sun.star.util.BinaryDataContainer" + constructor="com_sun_star_comp_util_BinaryDataContainer_get_implementation"> + <service name="com.sun.star.util.BinaryDataContainer"/> + </implementation> </component> commit 6a7a13a3220043e6e39e15341c6095b3d9f86433 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Dec 25 20:08:41 2020 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Fri Dec 25 20:08:41 2020 +0900 vcl: add cxx for BinaryDataContainer as some impl. is not trivial Change-Id: I00a0ae052f7863408864059e8b445d98d600eabc diff --git a/include/vcl/BinaryDataContainer.hxx b/include/vcl/BinaryDataContainer.hxx index 7ec9926b245c..844d6c5bb81f 100644 --- a/include/vcl/BinaryDataContainer.hxx +++ b/include/vcl/BinaryDataContainer.hxx @@ -13,8 +13,12 @@ #include <vcl/dllapi.h> #include <vector> #include <memory> -#include <boost/functional/hash.hpp> +/** Container for the binary data, which responsiility is to manage the + * make it as simple as possible to manage the binary data. The binary + * data can be anything, but typically it is a in-memory data from + * files (i.e. files of graphic formats). + */ class VCL_DLLPUBLIC BinaryDataContainer final { private: @@ -22,18 +26,9 @@ private: std::shared_ptr<std::vector<sal_uInt8>> mpData; public: - explicit BinaryDataContainer() {} - - explicit BinaryDataContainer(size_t nSize) - : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize)) - { - } - - explicit BinaryDataContainer(const sal_uInt8* pData, size_t nSize) - : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize)) - { - std::copy(pData, pData + nSize, mpData->data()); - } + 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; @@ -41,19 +36,14 @@ public: BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) = default; size_t getSize() const { return mpData ? mpData->size() : 0; } - bool isEmpty() const { return mpData ? mpData->empty() : true; } - const sal_uInt8* getData() const { return mpData ? mpData->data() : nullptr; } - size_t calculateHash() const - { - size_t nSeed = 0; - boost::hash_combine(nSeed, getSize()); - for (sal_uInt8 const& rByte : *mpData) - boost::hash_combine(nSeed, rByte); - return nSeed; - } + size_t calculateHash() const; + + auto cbegin() { return mpData->cbegin(); } + + auto cend() { return mpData->cend(); } }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 5798ce031c90..b326147ca5a1 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -330,6 +330,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/pdf/XmpMetadata \ vcl/source/pdf/PDFiumLibrary \ vcl/source/pdf/ExternalPDFStreams \ + vcl/source/graphic/BinaryDataContainer \ vcl/source/graphic/GraphicID \ vcl/source/graphic/GraphicLoader \ vcl/source/graphic/GraphicObject \ diff --git a/vcl/source/graphic/BinaryDataContainer.cxx b/vcl/source/graphic/BinaryDataContainer.cxx new file mode 100644 index 000000000000..4c556195fe6a --- /dev/null +++ b/vcl/source/graphic/BinaryDataContainer.cxx @@ -0,0 +1,36 @@ +/* -*- 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 <vcl/BinaryDataContainer.hxx> +#include <boost/functional/hash.hpp> + +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)) +{ + std::copy(pData, pData + nSize, mpData->data()); +} + +size_t BinaryDataContainer::calculateHash() const +{ + size_t nSeed = 0; + boost::hash_combine(nSeed, getSize()); + for (sal_uInt8 const& rByte : *mpData) + boost::hash_combine(nSeed, rByte); + return nSeed; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits