[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - include/vcl sd/qa svx/source vcl/inc vcl/qa vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Mon Dec 28 01:06:31 UTC 2020
include/vcl/vectorgraphicdata.hxx | 19 ++++++-
sd/qa/unit/SdrPdfImportTest.cxx | 11 ++--
sd/qa/unit/import-tests.cxx | 4 -
svx/source/svdraw/svdpdf.cxx | 4 -
svx/source/xoutdev/_xoutbmp.cxx | 3 -
vcl/inc/pdf/ExternalPDFStreams.hxx | 7 +-
vcl/qa/cppunit/PDFiumLibraryTest.cxx | 30 ++++--------
vcl/source/filter/graphicfilter.cxx | 9 ++-
vcl/source/filter/ipdf/pdfread.cxx | 21 ++++----
vcl/source/gdi/TypeSerializer.cxx | 6 +-
vcl/source/gdi/impgraph.cxx | 4 -
vcl/source/gdi/pdfwriter_impl.cxx | 13 ++---
vcl/source/gdi/pdfwriter_impl.hxx | 3 -
vcl/source/gdi/vectorgraphicdata.cxx | 72 +++++++++++++++++++----------
vcl/source/graphic/GraphicID.cxx | 5 --
vcl/source/graphic/VectorGraphicSearch.cxx | 4 -
vcl/source/pdf/ExternalPDFStreams.cxx | 9 +--
17 files changed, 129 insertions(+), 95 deletions(-)
New commits:
commit 29d11ca997552df56917a5e310e5b68e0c3d187b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Dec 28 10:03:18 2020 +0900
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:05:02 2020 +0900
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
diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx
index e231435312e8..8d55a9487d26 100644
--- a/include/vcl/vectorgraphicdata.hxx
+++ b/include/vcl/vectorgraphicdata.hxx
@@ -23,6 +23,7 @@
#include <basegfx/range/b2drange.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <vcl/bitmapex.hxx>
+#include <vcl/BinaryDataContainer.hxx>
#include <rtl/ustring.hxx>
#include <deque>
#include <memory>
@@ -55,7 +56,7 @@ class VCL_DLLPUBLIC VectorGraphicData
{
private:
// the file and length
- VectorGraphicDataArray maVectorGraphicDataArray;
+ BinaryDataContainer maDataContainer;
// on demand created content
bool mbSequenceCreated;
@@ -89,6 +90,10 @@ public:
const VectorGraphicDataArray& rVectorGraphicDataArray,
VectorGraphicDataType eVectorDataType,
sal_Int32 nPageIndex = -1);
+ VectorGraphicData(
+ const BinaryDataContainer& rDataContainer,
+ VectorGraphicDataType eVectorDataType,
+ sal_Int32 nPageIndex = -1);
~VectorGraphicData();
/// compare op
@@ -98,8 +103,16 @@ public:
void setWmfExternalHeader(const WmfExternal& aExtHeader);
/// data read
- const VectorGraphicDataArray& getVectorGraphicDataArray() const { return maVectorGraphicDataArray; }
- sal_uInt32 getVectorGraphicDataArrayLength() const { return maVectorGraphicDataArray.getLength(); }
+ const BinaryDataContainer& getBinaryDataContainer() const
+ {
+ return maDataContainer;
+ }
+
+ sal_uInt32 getVectorGraphicDataArrayLength() const
+ {
+ return maDataContainer.getSize();
+ }
+
enum class State { UNPARSED, PARSED };
std::pair<State, size_t> getSizeBytes() const;
diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx
index f5e24fd19ede..85fb33d8243c 100644
--- a/sd/qa/unit/SdrPdfImportTest.cxx
+++ b/sd/qa/unit/SdrPdfImportTest.cxx
@@ -175,8 +175,7 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
CPPUNIT_ASSERT(pViewShell);
- const void* pData = nullptr;
- int nLength = 0;
+ BinaryDataContainer aContainer;
{
// Get the first page - there should be only one.
@@ -202,13 +201,15 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
pVectorGraphicData->getVectorGraphicDataType());
// Write the PDF
- pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
- nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+ aContainer = pVectorGraphicData->getBinaryDataContainer();
}
{ // check graphic PDF has annotations
- auto pPDFDocument = pPdfiumLibrary->openDocument(pData, nLength);
+ CPPUNIT_ASSERT_EQUAL(false, aContainer.isEmpty());
+
+ auto pPDFDocument
+ = pPdfiumLibrary->openDocument(aContainer.getData(), aContainer.getSize());
auto pPDFPage = pPDFDocument->openPage(0);
CPPUNIT_ASSERT_EQUAL(2, pPDFPage->getAnnotationCount());
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 12b340ccf3fa..3de5d48b1f75 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -1380,8 +1380,8 @@ void SdImportTest::testPDFImportShared()
{
Graphic const & rGraphic = aGraphics[i];
CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected all PDF streams to be identical.",
- rFirstGraphic.getVectorGraphicData()->getVectorGraphicDataArray().getConstArray(),
- rGraphic.getVectorGraphicData()->getVectorGraphicDataArray().getConstArray());
+ rFirstGraphic.getVectorGraphicData()->getBinaryDataContainer().getData(),
+ rGraphic.getVectorGraphicData()->getBinaryDataContainer().getData());
CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected all GfxLinks to be identical.",
rFirstGraphic.GetSharedGfxLink().get(),
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index e1ae905cef33..4cd84120fafe 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -125,8 +125,8 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools:
// Load the buffer using pdfium.
auto const& rVectorGraphicData = rGraphic.getVectorGraphicData();
- auto* pData = rVectorGraphicData->getVectorGraphicDataArray().getConstArray();
- sal_Int32 nSize = rVectorGraphicData->getVectorGraphicDataArrayLength();
+ auto* pData = rVectorGraphicData->getBinaryDataContainer().getData();
+ sal_Int32 nSize = rVectorGraphicData->getBinaryDataContainer().getSize();
mpPdfDocument = mpPDFium->openDocument(pData, nSize);
if (!mpPdfDocument)
return;
diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx
index 1d0c23e92780..6dba9e722a7d 100644
--- a/svx/source/xoutdev/_xoutbmp.cxx
+++ b/svx/source/xoutdev/_xoutbmp.cxx
@@ -149,7 +149,8 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName,
if (pOStm)
{
- pOStm->WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
+ auto & rDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
+ pOStm->WriteBytes(rDataContainer.getData(), rDataContainer.getSize());
aMedium.Commit();
if (!aMedium.GetError())
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 577f73ed1130..597737864a87 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -65,12 +65,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());
@@ -93,11 +92,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());
@@ -119,11 +117,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());
@@ -169,11 +166,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());
@@ -226,11 +222,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());
@@ -304,11 +299,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 02747b4e869b..65f3b8bb450f 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1986,7 +1986,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())
{
@@ -2019,7 +2020,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())
{
@@ -2113,7 +2115,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 c70363cef0f8..2c2c8526e779 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 8dc81eb4987f..aeb471852ec8 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1200,8 +1200,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 ea8273592989..36b7460a69cf 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -4485,12 +4485,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()));
@@ -9004,22 +9004,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 00d016ace285..992ba59d1dd2 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 <outdata.hxx>
#include <vcl/filter/pdfobjectcontainer.hxx>
@@ -403,7 +404,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 61618b7adfe8..609040f44129 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,9 @@ void VectorGraphicData::ensureReplacement()
void VectorGraphicData::ensureSequenceAndRange()
{
- if (mbSequenceCreated || !maVectorGraphicDataArray.hasElements())
+ printf ("VectorGraphicData::ensureSequenceAndRange\n");
+
+ if (mbSequenceCreated || maDataContainer.isEmpty())
return;
// import SVG to maSequence, also set maRange
@@ -194,11 +197,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 +213,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 +225,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 +235,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 +251,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 +291,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 +305,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(),
@@ -332,7 +358,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);
}
More information about the Libreoffice-commits
mailing list