[Libreoffice-commits] core.git: filter/source include/filter oox/source sd/source sw/source
Armin Le Grand
Armin.Le.Grand at cib.de
Tue Jul 10 14:29:52 UTC 2018
filter/source/msfilter/escherex.cxx | 448 +++++++++++++++++++---------------
filter/source/msfilter/eschesdo.cxx | 5
include/filter/msfilter/escherex.hxx | 38 +-
oox/source/export/vmlexport.cxx | 45 ++-
sd/source/filter/eppt/epptso.cxx | 17 -
sw/source/filter/ww8/rtfsdrexport.cxx | 12
sw/source/filter/ww8/wrtw8esh.cxx | 21 -
7 files changed, 316 insertions(+), 270 deletions(-)
New commits:
commit b9bc45705bc3204c968fd6c902a1d5003c008023
Author: Armin Le Grand <Armin.Le.Grand at cib.de>
Date: Fri Jul 6 15:16:06 2018 +0200
Make EscherPropertyContainer::CreatePolygonProperties safer
Additionally adapted EscherPropertyContainer's AddOpt
methods to be more safe and flexible. Added support for
SvMemoryStream. Changed Data handling in EscherPropSortStruct
to use std::vector<sal_uInt8>, adapted all usages and
converions throgh all modules. This makes memorty handling
for these parts much safer (no more local new-ops, no
longer delete[] there).
Currently there are quite some usages of nProp.size() and
&nProp[0] to access the data. but the base for further
changes to work more on std::vector is done.
Change-Id: I982225c5bfc06fdd9e195d18cd3c550d15f1d48d
Reviewed-on: https://gerrit.libreoffice.org/57061
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand at cib.de>
diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx
index af43ad6b1903..775ebda731c9 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -169,39 +169,71 @@ EscherPropertyContainer::EscherPropertyContainer(
EscherPropertyContainer::~EscherPropertyContainer()
{
- if ( bHasComplexData )
+};
+
+void EscherPropertyContainer::AddOpt(
+ sal_uInt16 nPropID,
+ bool bBlib,
+ sal_uInt32 nSizeReduction,
+ SvMemoryStream& rStream)
+{
+ sal_uInt8 const* pBuf(static_cast<sal_uInt8 const *>(rStream.GetData()));
+ const sal_uInt64 nSize(rStream.GetSize());
+ std::vector<sal_uInt8> aBuf;
+ aBuf.reserve(nSize);
+
+ for(sal_uInt64 a(0); a < nSize; a++)
{
- size_t nSortCount = pSortStruct.size();
- while ( nSortCount-- )
- delete[] pSortStruct[ nSortCount ].pBuf;
+ aBuf.push_back(*pBuf++);
}
-};
-void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, sal_uInt32 nPropValue, bool bBlib )
+ sal_uInt32 nPropValue(static_cast<sal_uInt32>(nSize));
+
+ if(0 != nSizeReduction && nPropValue > nSizeReduction)
+ {
+ nPropValue -= nSizeReduction;
+ }
+
+ AddOpt(nPropID, bBlib, nPropValue, aBuf);
+}
+
+void EscherPropertyContainer::AddOpt(
+ sal_uInt16 nPropID,
+ sal_uInt32 nPropValue,
+ bool bBlib)
{
- AddOpt( nPropID, bBlib, nPropValue, nullptr, 0 );
+ AddOpt(nPropID, bBlib, nPropValue, std::vector<sal_uInt8>());
}
-void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, const OUString& rString )
+void EscherPropertyContainer::AddOpt(
+ sal_uInt16 nPropID,
+ const OUString& rString)
{
- sal_Int32 j, i, nLen = rString.getLength() * 2 + 2;
- sal_uInt8* pBuf = new sal_uInt8[ nLen ];
- for ( j = i = 0; i < rString.getLength(); i++ )
+ std::vector<sal_uInt8> aBuf;
+ aBuf.reserve(rString.getLength() * 2 + 2);
+
+ for(sal_Int32 i(0); i < rString.getLength(); i++)
{
- sal_uInt16 nChar = static_cast<sal_uInt16>(rString[ i ]);
- pBuf[ j++ ] = static_cast<sal_uInt8>(nChar);
- pBuf[ j++ ] = static_cast<sal_uInt8>( nChar >> 8 );
+ const sal_Unicode nUnicode(rString[i]);
+ aBuf.push_back(static_cast<sal_uInt8>(nUnicode));
+ aBuf.push_back(static_cast<sal_uInt8>(nUnicode >> 8));
}
- pBuf[ j++ ] = 0;
- pBuf[ j++ ] = 0;
- AddOpt( nPropID, true, nLen, pBuf, nLen );
+
+ aBuf.push_back(0);
+ aBuf.push_back(0);
+
+ AddOpt(nPropID, true, aBuf.size(), aBuf);
}
-void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, bool bBlib, sal_uInt32 nPropValue, sal_uInt8* pProp, sal_uInt32 nPropSize )
+void EscherPropertyContainer::AddOpt(
+ sal_uInt16 nPropID,
+ bool bBlib,
+ sal_uInt32 nPropValue,
+ const std::vector<sal_uInt8>& rProp)
{
if ( bBlib ) // bBlib is only valid when fComplex = 0
nPropID |= 0x4000;
- if ( pProp )
+ if ( !rProp.empty() )
nPropID |= 0x8000; // fComplex = sal_True;
for( size_t i = 0; i < pSortStruct.size(); i++ )
@@ -209,16 +241,14 @@ void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, bool bBlib, sal_uInt32
if ( ( pSortStruct[ i ].nPropId &~0xc000 ) == ( nPropID &~0xc000 ) ) // check, whether the Property only gets replaced
{
pSortStruct[ i ].nPropId = nPropID;
- if ( pSortStruct[ i ].pBuf )
+ if ( !pSortStruct[ i ].nProp.empty() )
{
- nCountSize -= pSortStruct[ i ].nPropSize;
- delete[] pSortStruct[ i ].pBuf;
+ nCountSize -= pSortStruct[ i ].nProp.size();
}
- pSortStruct[ i ].pBuf = pProp;
- pSortStruct[ i ].nPropSize = nPropSize;
+ pSortStruct[ i ].nProp = rProp;
pSortStruct[ i ].nPropValue = nPropValue;
- if ( pProp )
- nCountSize += nPropSize;
+ if ( !rProp.empty() )
+ nCountSize += rProp.size();
return;
}
}
@@ -226,13 +256,12 @@ void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, bool bBlib, sal_uInt32
nCountSize += 6;
pSortStruct.emplace_back();
pSortStruct.back().nPropId = nPropID; // insert property
- pSortStruct.back().pBuf = pProp;
- pSortStruct.back().nPropSize = nPropSize;
+ pSortStruct.back().nProp = rProp;
pSortStruct.back().nPropValue = nPropValue;
- if ( pProp )
+ if ( !rProp.empty() )
{
- nCountSize += nPropSize;
+ nCountSize += rProp.size();
bHasComplexData = true;
}
}
@@ -304,8 +333,10 @@ void EscherPropertyContainer::Commit( SvStream& rSt, sal_uInt16 nVersion, sal_uI
{
for ( size_t i = 0; i < pSortStruct.size(); i++ )
{
- if ( pSortStruct[ i ].pBuf )
- rSt.WriteBytes(pSortStruct[i].pBuf, pSortStruct[i].nPropSize);
+ if ( !pSortStruct[ i ].nProp.empty() )
+ rSt.WriteBytes(
+ &pSortStruct[i].nProp[0],
+ pSortStruct[i].nProp.size());
}
}
}
@@ -1316,12 +1347,7 @@ bool EscherPropertyContainer::ImplCreateEmbeddedBmp(GraphicObject const & rGraph
if (aProvider.GetBlibID( aMemStrm, rGraphicObject))
{
- // grab BLIP from stream and insert directly as complex property
- // ownership of stream memory goes to complex property
- aMemStrm.ObjectOwnsMemory( false );
- sal_uInt8 const * pBuf = static_cast<sal_uInt8 const *>(aMemStrm.GetData());
- sal_uInt32 nSize = aMemStrm.Seek( STREAM_SEEK_TO_END );
- AddOpt( ESCHER_Prop_fillBlip, true, nSize, const_cast<sal_uInt8 *>(pBuf), nSize );
+ AddOpt(ESCHER_Prop_fillBlip, true, 0, aMemStrm);
return true;
}
}
@@ -1698,12 +1724,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(const uno::Reference<beans
if (aProvider.GetBlibID(aMemStrm, aGraphicObject, nullptr, pGraphicAttr.get(), bOOxmlExport))
{
- // grab BLIP from stream and insert directly as complex property
- // ownership of stream memory goes to complex property
- aMemStrm.ObjectOwnsMemory( false );
- sal_uInt8 const * pBuf = static_cast<sal_uInt8 const *>(aMemStrm.GetData());
- sal_uInt32 nSize = aMemStrm.Seek( STREAM_SEEK_TO_END );
- AddOpt(ESCHER_Prop_fillBlip, true, nSize, const_cast<sal_uInt8 *>(pBuf), nSize );
+ AddOpt(ESCHER_Prop_fillBlip, true, 0, aMemStrm);
bRetValue = true;
}
}
@@ -1776,143 +1797,188 @@ bool EscherPropertyContainer::CreatePolygonProperties(
awt::Rectangle& rGeoRect,
tools::Polygon const * pPolygon )
{
- bool bRetValue = true;
- bool bLine = ( nFlags & ESCHER_CREATEPOLYGON_LINE ) != 0;
-
tools::PolyPolygon aPolyPolygon;
- if ( pPolygon )
- aPolyPolygon.Insert( *pPolygon );
+ if(nullptr != pPolygon)
+ {
+ aPolyPolygon.Insert(*pPolygon);
+ }
else
{
uno::Any aAny;
- bRetValue = EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet,
- bBezier ? OUString("PolyPolygonBezier") : OUString("PolyPolygon"), true );
- if ( bRetValue )
+
+ if(EscherPropertyValueHelper::GetPropertyValue(
+ aAny,
+ rXPropSet,
+ bBezier ? OUString("PolyPolygonBezier") : OUString("PolyPolygon"),
+ true))
{
- aPolyPolygon = GetPolyPolygon( aAny );
- bRetValue = aPolyPolygon.Count() != 0;
+ aPolyPolygon = GetPolyPolygon(aAny);
+ }
+ else
+ {
+ return false;
}
}
- if ( bRetValue )
+
+ if(0 == aPolyPolygon.Count())
+ {
+ return false;
+ }
+
+ if(0 != (nFlags & ESCHER_CREATEPOLYGON_LINE))
{
- if ( bLine )
+ if((1 == aPolyPolygon.Count()) && (2 == aPolyPolygon[0].GetSize()))
{
- if ( ( aPolyPolygon.Count() == 1 ) && ( aPolyPolygon[ 0 ].GetSize() == 2 ) )
- {
- const tools::Polygon& rPoly = aPolyPolygon[ 0 ];
- rGeoRect = awt::Rectangle(
- rPoly[0].X(), rPoly[0].Y(),
- rPoly[1].X() - rPoly[0].X(),
- rPoly[1].Y() - rPoly[0].Y());
- }
- else
- bRetValue = false;
+ const tools::Polygon& rPoly(aPolyPolygon[0]);
+
+ rGeoRect = awt::Rectangle(
+ rPoly[0].X(),
+ rPoly[0].Y(),
+ rPoly[1].X() - rPoly[0].X(),
+ rPoly[1].Y() - rPoly[0].Y());
+
+ return true;
}
- else
+
+ return false;
+ }
+
+ const tools::Rectangle aRect(aPolyPolygon.GetBoundRect());
+
+ rGeoRect = awt::Rectangle(
+ aRect.Left(),
+ aRect.Top(),
+ aRect.GetWidth(),
+ aRect.GetHeight());
+
+ const sal_uInt16 nPolyCount(aPolyPolygon.Count());
+ sal_uInt32 nTotalPoints(0);
+ std::vector< sal_uInt8 > aVertices(4, 0);
+ std::vector< sal_uInt8 > aSegments(4, 0);
+
+ aVertices.push_back(static_cast<sal_uInt8>(0xf0));
+ aVertices.push_back(static_cast<sal_uInt8>(0xff));
+
+ aSegments.push_back(static_cast<sal_uInt8>(2));
+ aSegments.push_back(static_cast<sal_uInt8>(0));
+
+ for(sal_uInt16 j(0); j < nPolyCount; ++j)
+ {
+ const tools::Polygon aPolygon(aPolyPolygon[j]);
+ const sal_uInt16 nPoints(aPolygon.GetSize());
+
+ if(0 == nPoints)
{
- tools::Polygon aPolygon;
+ continue;
+ }
- sal_uInt16 nPolyCount = aPolyPolygon.Count();
- sal_uInt32 nTotalPoints(0), nTotalBezPoints(0);
- tools::Rectangle aRect( aPolyPolygon.GetBoundRect() );
- rGeoRect = awt::Rectangle( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight() );
+ // Polygon start
+ aSegments.push_back(static_cast<sal_uInt8>(0x0));
+ aSegments.push_back(static_cast<sal_uInt8>(0x40));
- for (sal_uInt16 i = 0; i < nPolyCount; ++i)
- {
- sal_uInt16 k = aPolyPolygon[ i ].GetSize();
- nTotalPoints += k;
- for (sal_uInt16 j = 0; j < k; ++j)
- {
- if ( aPolyPolygon[ i ].GetFlags( j ) != PolyFlags::Control )
- nTotalBezPoints++;
- }
- }
- sal_uInt32 nVerticesBufSize = ( nTotalPoints << 2 ) + 6;
- sal_uInt8* pVerticesBuf = new sal_uInt8[ nVerticesBufSize ];
+ sal_uInt16 nSegmentIgnoreCounter(0);
+
+ // write points from polygon to buffer
+ for(sal_uInt16 i(0); i < nPoints; ++i)
+ {
+ Point aPoint(aPolygon[i]);
+ aPoint.AdjustX(-(rGeoRect.X));
+ aPoint.AdjustY(-(rGeoRect.Y));
- sal_uInt32 nSegmentBufSize = ( ( nTotalBezPoints << 2 ) + 8 );
- if ( nPolyCount > 1 )
- nSegmentBufSize += ( nPolyCount << 1 );
- sal_uInt8* pSegmentBuf = new sal_uInt8[ nSegmentBufSize ];
+ aVertices.push_back(static_cast<sal_uInt8>(aPoint.X()));
+ aVertices.push_back(static_cast<sal_uInt8>(aPoint.X() >> 8));
+ aVertices.push_back(static_cast<sal_uInt8>(aPoint.Y()));
+ aVertices.push_back(static_cast<sal_uInt8>(aPoint.Y() >> 8));
- sal_uInt8* pPtr = pVerticesBuf;
- *pPtr++ = static_cast<sal_uInt8>(nTotalPoints); // Little endian
- *pPtr++ = static_cast<sal_uInt8>( nTotalPoints >> 8 );
- *pPtr++ = static_cast<sal_uInt8>(nTotalPoints);
- *pPtr++ = static_cast<sal_uInt8>( nTotalPoints >> 8 );
- *pPtr++ = sal_uInt8(0xf0);
- *pPtr++ = sal_uInt8(0xff);
+ nTotalPoints++;
- for (sal_uInt16 j = 0; j < nPolyCount; ++j)
+ if(0 != nSegmentIgnoreCounter)
{
- aPolygon = aPolyPolygon[ j ];
- sal_uInt16 nPoints = aPolygon.GetSize();
- for (sal_uInt16 i = 0; i < nPoints; ++i) // write points from polygon to buffer
- {
- Point aPoint = aPolygon[ i ];
- aPoint.AdjustX( -(rGeoRect.X) );
- aPoint.AdjustY( -(rGeoRect.Y) );
-
- *pPtr++ = static_cast<sal_uInt8>( aPoint.X() );
- *pPtr++ = static_cast<sal_uInt8>( aPoint.X() >> 8 );
- *pPtr++ = static_cast<sal_uInt8>( aPoint.Y() );
- *pPtr++ = static_cast<sal_uInt8>( aPoint.Y() >> 8 );
- }
+ nSegmentIgnoreCounter--;
}
+ else
+ {
+ aSegments.push_back(static_cast<sal_uInt8>(0));
- pPtr = pSegmentBuf;
- *pPtr++ = static_cast<sal_uInt8>( ( nSegmentBufSize - 6 ) >> 1 );
- *pPtr++ = static_cast<sal_uInt8>( ( nSegmentBufSize - 6 ) >> 9 );
- *pPtr++ = static_cast<sal_uInt8>( ( nSegmentBufSize - 6 ) >> 1 );
- *pPtr++ = static_cast<sal_uInt8>( ( nSegmentBufSize - 6 ) >> 9 );
- *pPtr++ = sal_uInt8(2);
- *pPtr++ = sal_uInt8(0);
+ if(bBezier)
+ {
+ aSegments.push_back(static_cast<sal_uInt8>(0xb3));
+ }
+ else
+ {
+ aSegments.push_back(static_cast<sal_uInt8>(0xac));
+ }
- for (sal_uInt16 j = 0; j < nPolyCount; ++j)
- {
- *pPtr++ = 0x0; // Polygon start
- *pPtr++ = 0x40;
- aPolygon = aPolyPolygon[ j ];
- sal_uInt16 nPoints = aPolygon.GetSize();
- for (sal_uInt16 i = 0; i < nPoints; ++i) // write Polyflags to Buffer
+ if(i + 1 == nPoints)
{
- *pPtr++ = 0;
- if ( bBezier )
- *pPtr++ = 0xb3;
- else
- *pPtr++ = 0xac;
- if ( ( i + 1 ) != nPoints )
+ if(nPolyCount > 1)
{
- *pPtr++ = 1;
- if ( aPolygon.GetFlags( i + 1 ) == PolyFlags::Control )
- {
- *pPtr++ = 0x20;
- i += 2;
- }
- else
- *pPtr++ = 0;
+ // end of polygon
+ aSegments.push_back(static_cast<sal_uInt8>(1));
+ aSegments.push_back(static_cast<sal_uInt8>(0x60));
}
}
- if ( nPolyCount > 1 )
+ else
{
- *pPtr++ = 1; // end of polygon
- *pPtr++ = 0x60;
+ aSegments.push_back(static_cast<sal_uInt8>(1));
+
+ if(PolyFlags::Control == aPolygon.GetFlags(i + 1))
+ {
+ aSegments.push_back(static_cast<sal_uInt8>(0x20));
+ nSegmentIgnoreCounter = 2;
+ }
+ else
+ {
+ aSegments.push_back(static_cast<sal_uInt8>(0));
+ }
}
}
- *pPtr++ = 0;
- *pPtr++ = 0x80;
+ }
+ }
- AddOpt( ESCHER_Prop_geoRight, rGeoRect.Width );
- AddOpt( ESCHER_Prop_geoBottom, rGeoRect.Height );
+ if(0 != nTotalPoints && aSegments.size() >= 6 && aVertices.size() >= 6)
+ {
+ // Little endian
+ aVertices[0] = static_cast<sal_uInt8>(nTotalPoints);
+ aVertices[1] = static_cast<sal_uInt8>(nTotalPoints >> 8);
+ aVertices[2] = static_cast<sal_uInt8>(nTotalPoints);
+ aVertices[3] = static_cast<sal_uInt8>(nTotalPoints >> 8);
+
+ aSegments.push_back(static_cast<sal_uInt8>(0));
+ aSegments.push_back(static_cast<sal_uInt8>(0x80));
+
+ const sal_uInt32 nSegmentBufSize(aSegments.size() - 6);
+ aSegments[0] = static_cast<sal_uInt8>(nSegmentBufSize >> 1);
+ aSegments[1] = static_cast<sal_uInt8>(nSegmentBufSize >> 9);
+ aSegments[2] = static_cast<sal_uInt8>(nSegmentBufSize >> 1);
+ aSegments[3] = static_cast<sal_uInt8>(nSegmentBufSize >> 9);
+
+ AddOpt(
+ ESCHER_Prop_geoRight,
+ rGeoRect.Width);
+ AddOpt(
+ ESCHER_Prop_geoBottom,
+ rGeoRect.Height);
+ AddOpt(
+ ESCHER_Prop_shapePath,
+ ESCHER_ShapeComplex);
+ AddOpt(
+ ESCHER_Prop_pVertices,
+ true,
+ aVertices.size() - 6,
+ aVertices);
+ AddOpt(
+ ESCHER_Prop_pSegmentInfo,
+ true,
+ aSegments.size(),
+ aSegments);
- AddOpt( ESCHER_Prop_shapePath, ESCHER_ShapeComplex );
- AddOpt( ESCHER_Prop_pVertices, true, nVerticesBufSize - 6, pVerticesBuf, nVerticesBufSize );
- AddOpt( ESCHER_Prop_pSegmentInfo, true, nSegmentBufSize, pSegmentBuf, nSegmentBufSize );
- }
+ return true;
}
- return bRetValue;
+
+ return false;
}
@@ -2858,26 +2924,24 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
{
sal_uInt16 nElementSize = 8;
sal_uInt32 nStreamSize = nElementSize * nElements + 6;
- SvMemoryStream aOut( nStreamSize );
- aOut.WriteUInt16( nElements )
+ SvMemoryStream aMemStrm( nStreamSize );
+ aMemStrm.WriteUInt16( nElements )
.WriteUInt16( nElements )
.WriteUInt16( nElementSize );
for (auto const& equation : aEquations)
{
- aOut.WriteUInt16( equation.nOperation )
+ aMemStrm.WriteUInt16( equation.nOperation )
.WriteInt16( equation.nPara[ 0 ] )
.WriteInt16( equation.nPara[ 1 ] )
.WriteInt16( equation.nPara[ 2 ] );
}
- sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
- memcpy( pBuf, aOut.GetData(), nStreamSize );
- AddOpt( DFF_Prop_pFormulas, true, nStreamSize - 6, pBuf, nStreamSize );
+
+ AddOpt(DFF_Prop_pFormulas, true, 6, aMemStrm);
}
else
{
- sal_uInt8* pBuf = new sal_uInt8[ 1 ];
- AddOpt( DFF_Prop_pFormulas, true, 0, pBuf, 0 );
+ AddOpt(DFF_Prop_pFormulas, 0, true);
}
}
}
@@ -2963,25 +3027,23 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
{
sal_uInt16 j, nElementSize = 8;
sal_uInt32 nStreamSize = nElementSize * nElements + 6;
- SvMemoryStream aOut( nStreamSize );
- aOut.WriteUInt16( nElements )
+ SvMemoryStream aMemStrm( nStreamSize );
+ aMemStrm.WriteUInt16( nElements )
.WriteUInt16( nElements )
.WriteUInt16( nElementSize );
for( j = 0; j < nElements; j++ )
{
sal_Int32 X = GetValueForEnhancedCustomShapeParameter( aGluePoints[ j ].First, aEquationOrder );
sal_Int32 Y = GetValueForEnhancedCustomShapeParameter( aGluePoints[ j ].Second, aEquationOrder );
- aOut.WriteInt32( X )
+ aMemStrm.WriteInt32( X )
.WriteInt32( Y );
}
- sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
- memcpy( pBuf, aOut.GetData(), nStreamSize );
- AddOpt( DFF_Prop_connectorPoints, true, nStreamSize - 6, pBuf, nStreamSize ); // -6
+
+ AddOpt(DFF_Prop_connectorPoints, true, 6, aMemStrm); // -6
}
else
{
- sal_uInt8* pBuf = new sal_uInt8[ 1 ];
- AddOpt( DFF_Prop_connectorPoints, true, 0, pBuf, 0 );
+ AddOpt(DFF_Prop_connectorPoints, 0, true);
}
}
}
@@ -3005,8 +3067,8 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
sal_uInt16 j, nElements = static_cast<sal_uInt16>(aSegments.getLength());
sal_uInt16 nElementSize = 2;
sal_uInt32 nStreamSize = nElementSize * nElements + 6;
- SvMemoryStream aOut( nStreamSize );
- aOut.WriteUInt16( nElements )
+ SvMemoryStream aMemStrm( nStreamSize );
+ aMemStrm.WriteUInt16( nElements )
.WriteUInt16( nElements )
.WriteUInt16( nElementSize );
for ( j = 0; j < nElements; j++ )
@@ -3100,16 +3162,14 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
}
break;
}
- aOut.WriteUInt16( nVal );
+ aMemStrm.WriteUInt16( nVal );
}
- sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
- memcpy( pBuf, aOut.GetData(), nStreamSize );
- AddOpt( DFF_Prop_pSegmentInfo, false, nStreamSize - 6, pBuf, nStreamSize );
+
+ AddOpt(DFF_Prop_pSegmentInfo, false, 6, aMemStrm);
}
else
{
- sal_uInt8* pBuf = new sal_uInt8[ 1 ];
- AddOpt( DFF_Prop_pSegmentInfo, true, 0, pBuf, 0 );
+ AddOpt(DFF_Prop_pSegmentInfo, 0, true);
}
}
}
@@ -3144,8 +3204,8 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
sal_uInt16 j, nElements = static_cast<sal_uInt16>(aPathTextFrames.getLength());
sal_uInt16 nElementSize = 16;
sal_uInt32 nStreamSize = nElementSize * nElements + 6;
- SvMemoryStream aOut( nStreamSize );
- aOut.WriteUInt16( nElements )
+ SvMemoryStream aMemStrm( nStreamSize );
+ aMemStrm.WriteUInt16( nElements )
.WriteUInt16( nElements )
.WriteUInt16( nElementSize );
for ( j = 0; j < nElements; j++ )
@@ -3155,19 +3215,17 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
sal_Int32 nRight = GetValueForEnhancedCustomShapeParameter( aPathTextFrames[ j ].BottomRight.First, aEquationOrder );
sal_Int32 nBottom = GetValueForEnhancedCustomShapeParameter( aPathTextFrames[ j ].BottomRight.Second, aEquationOrder );
- aOut.WriteInt32( nLeft )
+ aMemStrm.WriteInt32( nLeft )
.WriteInt32( nTop )
.WriteInt32( nRight )
.WriteInt32( nBottom );
}
- sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
- memcpy( pBuf, aOut.GetData(), nStreamSize );
- AddOpt( DFF_Prop_textRectangles, true, nStreamSize - 6, pBuf, nStreamSize );
+
+ AddOpt(DFF_Prop_textRectangles, true, 6, aMemStrm);
}
else
{
- sal_uInt8* pBuf = new sal_uInt8[ 1 ];
- AddOpt( DFF_Prop_textRectangles, true, 0, pBuf, 0 );
+ AddOpt(DFF_Prop_textRectangles, 0, true);
}
}
}
@@ -3395,8 +3453,8 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
{
sal_uInt16 k, nElementSize = 36;
sal_uInt32 nStreamSize = nElementSize * nElements + 6;
- SvMemoryStream aOut( nStreamSize );
- aOut.WriteUInt16( nElements )
+ SvMemoryStream aMemStrm( nStreamSize );
+ aMemStrm.WriteUInt16( nElements )
.WriteUInt16( nElements )
.WriteUInt16( nElementSize );
@@ -3542,7 +3600,7 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
}
}
}
- aOut.WriteUInt32( nFlags )
+ aMemStrm.WriteUInt32( nFlags )
.WriteInt32( nXPosition )
.WriteInt32( nYPosition )
.WriteInt32( nXMap )
@@ -3555,14 +3613,12 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
if ( nFlags & 8 )
nAdjustmentsWhichNeedsToBeConverted |= ( 1 << ( nYPosition - 0x100 ) );
}
- sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
- memcpy( pBuf, aOut.GetData(), nStreamSize );
- AddOpt( DFF_Prop_Handles, true, nStreamSize - 6, pBuf, nStreamSize );
+
+ AddOpt(DFF_Prop_Handles, true, 6, aMemStrm);
}
else
{
- sal_uInt8* pBuf = new sal_uInt8[ 1 ];
- AddOpt( DFF_Prop_Handles, true, 0, pBuf, 0 );
+ AddOpt(DFF_Prop_Handles, 0, true);
}
}
}
@@ -3600,25 +3656,23 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
sal_uInt16 j, nElements = static_cast<sal_uInt16>(aCoordinates.getLength());
sal_uInt16 nElementSize = 8;
sal_uInt32 nStreamSize = nElementSize * nElements + 6;
- SvMemoryStream aOut( nStreamSize );
- aOut.WriteUInt16( nElements )
+ SvMemoryStream aMemStrm( nStreamSize );
+ aMemStrm.WriteUInt16( nElements )
.WriteUInt16( nElements )
.WriteUInt16( nElementSize );
for( j = 0; j < nElements; j++ )
{
sal_Int32 X = GetValueForEnhancedCustomShapeParameter( aCoordinates[ j ].First, aEquationOrder, true );
sal_Int32 Y = GetValueForEnhancedCustomShapeParameter( aCoordinates[ j ].Second, aEquationOrder, true );
- aOut.WriteInt32( X )
+ aMemStrm.WriteInt32( X )
.WriteInt32( Y );
}
- sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
- memcpy( pBuf, aOut.GetData(), nStreamSize );
- AddOpt( DFF_Prop_pVertices, true, nStreamSize - 6, pBuf, nStreamSize ); // -6
+
+ AddOpt(DFF_Prop_pVertices, true, 6, aMemStrm); // -6
}
else
{
- sal_uInt8* pBuf = new sal_uInt8[ 1 ];
- AddOpt( DFF_Prop_pVertices, true, 0, pBuf, 0 );
+ AddOpt(DFF_Prop_pVertices, 0, true);
}
}
}
diff --git a/filter/source/msfilter/eschesdo.cxx b/filter/source/msfilter/eschesdo.cxx
index 2e390b724d4e..6ca01c04252b 100644
--- a/filter/source/msfilter/eschesdo.cxx
+++ b/filter/source/msfilter/eschesdo.cxx
@@ -243,10 +243,7 @@ sal_uInt32 ImplEESdrWriter::ImplWriteShape( ImplEESdrObject& rObj,
const std::unique_ptr< SvMemoryStream >& pMemStrm = pInteraction->getHyperlinkRecord();
if ( pMemStrm.get() )
{
- pMemStrm->ObjectOwnsMemory( false );
- sal_uInt8 const * pBuf = static_cast<sal_uInt8 const *>(pMemStrm->GetData());
- sal_uInt32 nSize = pMemStrm->Seek( STREAM_SEEK_TO_END );
- aPropOpt.AddOpt( ESCHER_Prop_pihlShape, false, nSize, const_cast<sal_uInt8 *>(pBuf), nSize );
+ aPropOpt.AddOpt(ESCHER_Prop_pihlShape, false, 0, *pMemStrm.get());
}
aPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x00080008 );
}
diff --git a/include/filter/msfilter/escherex.hxx b/include/filter/msfilter/escherex.hxx
index 58d492402ac2..e31116562d75 100644
--- a/include/filter/msfilter/escherex.hxx
+++ b/include/filter/msfilter/escherex.hxx
@@ -656,8 +656,7 @@ class SdrObjCustomShape;
struct EscherPropSortStruct
{
- sal_uInt8* pBuf;
- sal_uInt32 nPropSize;
+ std::vector<sal_uInt8> nProp;
sal_uInt32 nPropValue;
sal_uInt16 nPropId;
};
@@ -703,21 +702,26 @@ public:
// GraphicObjects are saved to PowerPoint
~EscherPropertyContainer();
- void AddOpt( sal_uInt16 nPropertyID, const OUString& rString );
-
- void AddOpt(
- sal_uInt16 nPropertyID,
- sal_uInt32 nPropValue,
- bool bBlib = false
- );
-
- void AddOpt(
- sal_uInt16 nPropertyID,
- bool bBlib,
- sal_uInt32 nPropValue,
- sal_uInt8* pProp,
- sal_uInt32 nPropSize
- );
+ void AddOpt(
+ sal_uInt16 nPropID,
+ bool bBlib,
+ sal_uInt32 nSizeReduction,
+ SvMemoryStream& rStream);
+
+ void AddOpt(
+ sal_uInt16 nPropertyID,
+ const OUString& rString);
+
+ void AddOpt(
+ sal_uInt16 nPropertyID,
+ sal_uInt32 nPropValue,
+ bool bBlib = false);
+
+ void AddOpt(
+ sal_uInt16 nPropertyID,
+ bool bBlib,
+ sal_uInt32 nPropValue,
+ const std::vector<sal_uInt8>& rProp);
bool GetOpt( sal_uInt16 nPropertyID, sal_uInt32& rPropValue ) const;
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx
index a655c77f9318..5594f3e416b8 100644
--- a/oox/source/export/vmlexport.cxx
+++ b/oox/source/export/vmlexport.cxx
@@ -494,11 +494,11 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
if ( rProps.GetOpt( ESCHER_Prop_pVertices, aVertices ) &&
rProps.GetOpt( ESCHER_Prop_pSegmentInfo, aSegments ) )
{
- const sal_uInt8 *pVerticesIt = aVertices.pBuf + 6;
- const sal_uInt8 *pSegmentIt = aSegments.pBuf;
+ const sal_uInt8 *pVerticesIt = &aVertices.nProp[0] + 6;
+ const sal_uInt8 *pSegmentIt = &aSegments.nProp[0];
OStringBuffer aPath( 512 );
- sal_uInt16 nPointSize = aVertices.pBuf[4] + ( aVertices.pBuf[5] << 8 );
+ sal_uInt16 nPointSize = aVertices.nProp[4] + ( aVertices.nProp[5] << 8 );
// number of segments
sal_uInt16 nSegments = impl_GetUInt16( pSegmentIt );
@@ -685,8 +685,8 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
SvMemoryStream aStream;
// The first bytes are WW8-specific, we're only interested in the PNG
int nHeaderSize = 25;
- aStream.WriteBytes(aStruct.pBuf + nHeaderSize,
- aStruct.nPropSize - nHeaderSize);
+ aStream.WriteBytes(&aStruct.nProp[0] + nHeaderSize,
+ aStruct.nProp.size() - nHeaderSize);
aStream.Seek(0);
Graphic aGraphic;
GraphicConverter::Import(aStream, aGraphic);
@@ -895,9 +895,14 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
if (rProps.GetOpt(ESCHER_Prop_gtextUNICODE, aUnicode))
{
SvMemoryStream aStream;
- aStream.WriteBytes(opt.pBuf, opt.nPropSize);
+
+ if(!opt.nProp.empty())
+ {
+ aStream.WriteBytes(&opt.nProp[0], opt.nProp.size());
+ }
+
aStream.Seek(0);
- OUString aTextPathString = SvxMSDffManager::MSDFFReadZString(aStream, opt.nPropSize, true);
+ OUString aTextPathString = SvxMSDffManager::MSDFFReadZString(aStream, opt.nProp.size(), true);
aStream.Seek(0);
m_pSerializer->singleElementNS( XML_v, XML_path,
@@ -912,9 +917,9 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
OUString aStyle;
if (rProps.GetOpt(ESCHER_Prop_gtextFont, aFont))
{
- aStream.WriteBytes(aFont.pBuf, aFont.nPropSize);
+ aStream.WriteBytes(&aFont.nProp[0], aFont.nProp.size());
aStream.Seek(0);
- OUString aTextPathFont = SvxMSDffManager::MSDFFReadZString(aStream, aFont.nPropSize, true);
+ OUString aTextPathFont = SvxMSDffManager::MSDFFReadZString(aStream, aFont.nProp.size(), true);
aStyle += "font-family:\"" + aTextPathFont + "\"";
}
sal_uInt32 nSize;
@@ -953,9 +958,14 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
case ESCHER_Prop_wzName:
{
SvMemoryStream aStream;
- aStream.WriteBytes(opt.pBuf, opt.nPropSize);
+
+ if(!opt.nProp.empty())
+ {
+ aStream.WriteBytes(&opt.nProp[0], opt.nProp.size());
+ }
+
aStream.Seek(0);
- OUString idStr = SvxMSDffManager::MSDFFReadZString(aStream, opt.nPropSize, true);
+ OUString idStr = SvxMSDffManager::MSDFFReadZString(aStream, opt.nProp.size(), true);
aStream.Seek(0);
if (!IsWaterMarkShape(m_pSdrObject->GetName()) && !m_bSkipwzName)
m_pShapeAttrList->add(XML_ID, OUStringToOString(idStr, RTL_TEXTENCODING_UTF8).getStr());
@@ -965,13 +975,18 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
break;
default:
#if OSL_DEBUG_LEVEL > 0
+ const size_t opt_nProp_size(opt.nProp.size());
+ const sal_uInt8 opt_nProp_empty(0);
fprintf( stderr, "TODO VMLExport::Commit(), unimplemented id: %d, value: %" SAL_PRIuUINT32 ", data: [%" SAL_PRIuUINT32 ", %p]\n",
- nId, opt.nPropValue, opt.nPropSize, opt.pBuf );
- if ( opt.nPropSize )
+ nId,
+ opt.nPropValue,
+ static_cast<unsigned int>(opt_nProp_size),
+ 0 == opt_nProp_size ? &opt_nProp_empty : &opt.nProp[0]);
+ if ( opt.nProp.size() )
{
- const sal_uInt8 *pIt = opt.pBuf;
+ const sal_uInt8 *pIt = &opt.nProp[0];
fprintf( stderr, " ( " );
- for ( int nCount = opt.nPropSize; nCount; --nCount )
+ for ( int nCount = opt.nProp.size(); nCount; --nCount )
{
fprintf( stderr, "%02x ", *pIt );
++pIt;
diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx
index 957977041c36..7d5040e8664d 100644
--- a/sd/source/filter/eppt/epptso.cxx
+++ b/sd/source/filter/eppt/epptso.cxx
@@ -2054,19 +2054,7 @@ void PPTWriter::ImplWritePage( const PHLayout& rLayout, EscherSolverContainer& a
if ( !aControlName.isEmpty() )
{
- sal_uInt16 nBufSize;
- nBufSize = ( aControlName.getLength() + 1 ) << 1;
- sal_uInt8* pBuf = new sal_uInt8[ nBufSize ];
- sal_uInt8* pTmp = pBuf;
- for ( sal_Int32 i = 0; i < aControlName.getLength(); i++ )
- {
- sal_Unicode nUnicode = aControlName[i];
- *pTmp++ = static_cast<sal_uInt8>(nUnicode);
- *pTmp++ = static_cast<sal_uInt8>( nUnicode >> 8 );
- }
- *pTmp++ = 0;
- *pTmp = 0;
- aPropOpt.AddOpt( ESCHER_Prop_wzName, true, nBufSize, pBuf, nBufSize );
+ aPropOpt.AddOpt(ESCHER_Prop_wzName, aControlName);
}
}
else if ( mType == "drawing.Connector" )
@@ -3140,7 +3128,6 @@ void PPTWriter::ImplCreateTable( uno::Reference< drawing::XShape > const & rXSha
EscherPropertyContainer aPropOpt2;
SvMemoryStream aMemStrm;
- aMemStrm.ObjectOwnsMemory( false );
aMemStrm.WriteUInt16( nRowCount )
.WriteUInt16( nRowCount )
.WriteUInt16( 4 );
@@ -3151,7 +3138,7 @@ void PPTWriter::ImplCreateTable( uno::Reference< drawing::XShape > const & rXSha
aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x1000100 );
aPropOpt2.AddOpt( ESCHER_Prop_tableProperties, 1 );
- aPropOpt2.AddOpt( ESCHER_Prop_tableRowProperties, true, aMemStrm.Tell(), static_cast< sal_uInt8* >( const_cast< void* >( aMemStrm.GetData() ) ), aMemStrm.Tell() );
+ aPropOpt2.AddOpt(ESCHER_Prop_tableRowProperties, true, 0, aMemStrm);
aPropOpt.CreateShapeProperties( rXShape );
aPropOpt.Commit( *mpStrm );
aPropOpt2.Commit( *mpStrm, 3, ESCHER_UDefProp );
diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx
index b0e96e21b5e3..d06b9705933f 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -270,16 +270,16 @@ void RtfSdrExport::Commit(EscherPropertyContainer& rProps, const tools::Rectangl
if (rProps.GetOpt(ESCHER_Prop_pVertices, aVertices)
&& rProps.GetOpt(ESCHER_Prop_pSegmentInfo, aSegments)
- && aVertices.nPropSize >= 6 && aSegments.nPropSize >= 6)
+ && aVertices.nProp.size() >= 6 && aSegments.nProp.size() >= 6)
{
- const sal_uInt8* pVerticesIt = aVertices.pBuf + 6;
+ const sal_uInt8* pVerticesIt = &aVertices.nProp[0] + 6;
std::size_t nVerticesPos = 6;
- const sal_uInt8* pSegmentIt = aSegments.pBuf;
+ const sal_uInt8* pSegmentIt = &aSegments.nProp[0];
OStringBuffer aSegmentInfo(512);
OStringBuffer aVerticies(512);
- sal_uInt16 nPointSize = aVertices.pBuf[4] + (aVertices.pBuf[5] << 8);
+ sal_uInt16 nPointSize = aVertices.nProp[4] + (aVertices.nProp[5] << 8);
// number of segments
sal_uInt16 nSegments = impl_GetUInt16(pSegmentIt);
@@ -432,8 +432,8 @@ void RtfSdrExport::Commit(EscherPropertyContainer& rProps, const tools::Rectangl
.append(SAL_NEWLINE_STRING);
int nHeaderSize
= 25; // The first bytes are WW8-specific, we're only interested in the PNG
- aBuf.append(msfilter::rtfutil::WriteHex(rOpt.pBuf + nHeaderSize,
- rOpt.nPropSize - nHeaderSize));
+ aBuf.append(msfilter::rtfutil::WriteHex(&rOpt.nProp[0] + nHeaderSize,
+ rOpt.nProp.size() - nHeaderSize));
aBuf.append('}');
m_aShapeProps.insert(
std::pair<OString, OString>("fillBlip", aBuf.makeStringAndClear()));
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index f36c89117179..9b1040de6d6f 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -291,11 +291,9 @@ void SwBasicEscherEx::PreWriteHyperlinkWithinFly(const SwFrameFormat& rFormat,Es
const SwFormatURL *pINetFormat = dynamic_cast<const SwFormatURL*>(pItem);
if (pINetFormat && !pINetFormat->GetURL().isEmpty())
{
- SvMemoryStream *rStrm = new SvMemoryStream ;
- WriteHyperlinkWithinFly( *rStrm, pINetFormat );
- sal_uInt8 const * pBuf = static_cast<sal_uInt8 const *>(rStrm->GetData());
- sal_uInt32 nSize = rStrm->Seek( STREAM_SEEK_TO_END );
- rPropOpt.AddOpt( ESCHER_Prop_pihlShape, true, nSize, const_cast<sal_uInt8 *>(pBuf), nSize );
+ SvMemoryStream aStrm;
+ WriteHyperlinkWithinFly( aStrm, pINetFormat );
+ rPropOpt.AddOpt(ESCHER_Prop_pihlShape, true, 0, aStrm);
sal_uInt32 nValue;
OUString aNamestr = pINetFormat->GetName();
if (!aNamestr.isEmpty())
@@ -1634,11 +1632,7 @@ sal_Int32 SwBasicEscherEx::WriteGrfFlyFrame(const SwFrameFormat& rFormat, sal_uI
SwWW8Writer::InsAsString16( aBuf, sURL );
SwWW8Writer::InsUInt16( aBuf, 0 );
- sal_uInt16 nArrLen = aBuf.size();
- sal_uInt8* pArr = new sal_uInt8[ nArrLen ];
- std::copy( aBuf.begin(), aBuf.end(), pArr);
-
- aPropOpt.AddOpt(ESCHER_Prop_pibName, true, nArrLen, pArr, nArrLen);
+ aPropOpt.AddOpt(ESCHER_Prop_pibName, true, aBuf.size(), aBuf);
nFlags = ESCHER_BlipFlagLinkToFile | ESCHER_BlipFlagURL |
ESCHER_BlipFlagDoNotSave;
}
@@ -2145,12 +2139,7 @@ sal_Int32 SwEscherEx::WriteFlyFrameAttr(const SwFrameFormat& rFormat, MSO_SPT eS
aPolyDump.WriteUInt32( aPoly[nI].Y() );
}
- sal_uInt16 nArrLen = msword_cast<sal_uInt16>(aPolyDump.Tell());
- void *pArr = const_cast<void *>(aPolyDump.GetData());
- //PropOpt wants to own the buffer
- aPolyDump.ObjectOwnsMemory(false);
- rPropOpt.AddOpt(DFF_Prop_pWrapPolygonVertices, false,
- nArrLen, static_cast<sal_uInt8 *>(pArr), nArrLen);
+ rPropOpt.AddOpt(DFF_Prop_pWrapPolygonVertices, false, 0, aPolyDump);
}
}
}
More information about the Libreoffice-commits
mailing list