summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-10-28 09:27:29 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-10-29 12:38:51 +0200
commit894b4911ffb96ff667fdeb3aec7922316ab7230a (patch)
tree3942ed8088c058b70bb79984b186c5156284abf4 /emfio
parent5b0ae3b59cd2cccfb72d991657366eb2a69bff49 (diff)
pass DX array around using o3tl::span instead of pointer
so we get bounds checking in debug mode Note that I cannot just pass around the std::vectors involved because there is a place in editeng which calls with a subset of a vector. Change-Id: I5088a139593c27bf9cbe5d843ab4b0048ac6d508 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124330 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'emfio')
-rw-r--r--emfio/inc/mtftools.hxx2
-rw-r--r--emfio/source/reader/emfreader.cxx13
-rw-r--r--emfio/source/reader/mtftools.cxx23
-rw-r--r--emfio/source/reader/wmfreader.cxx19
4 files changed, 30 insertions, 27 deletions
diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 527eae4a5a57..a9de54706f6d 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -675,7 +675,7 @@ namespace emfio
);
void DrawText(Point& rPosition,
OUString const & rString,
- tools::Long* pDXArry = nullptr,
+ std::vector<tools::Long>* pDXArry = nullptr,
tools::Long* pDYArry = nullptr,
bool bRecordPath = false,
sal_Int32 nGraphicsMode = GM_COMPATIBLE);
diff --git a/emfio/source/reader/emfreader.cxx b/emfio/source/reader/emfreader.cxx
index f3b114a57c01..ff258182595f 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -1939,14 +1939,15 @@ namespace emfio
SAL_INFO("emfio", "\t\tText: " << aText);
SAL_INFO("emfio", "\t\tDxBuffer:");
- std::unique_ptr<tools::Long[]> pDXAry, pDYAry;
+ std::vector<tools::Long> aDXAry;
+ std::unique_ptr<tools::Long[]> pDYAry;
sal_Int32 nDxSize;
bool bOverflow = o3tl::checked_multiply<sal_Int32>(nLen, (nOptions & ETO_PDY) ? 8 : 4, nDxSize);
if (!bOverflow && offDx && ((nCurPos + offDx + nDxSize) <= nNextPos ) && nNextPos <= mnEndPos)
{
mpInputStream->Seek( nCurPos + offDx );
- pDXAry.reset( new tools::Long[aText.getLength()] );
+ aDXAry.resize(aText.getLength());
if (nOptions & ETO_PDY)
{
pDYAry.reset( new tools::Long[aText.getLength()] );
@@ -1965,7 +1966,7 @@ namespace emfio
}
}
- pDXAry[i] = 0;
+ aDXAry[i] = 0;
if (nOptions & ETO_PDY)
{
pDYAry[i] = 0;
@@ -1975,7 +1976,7 @@ namespace emfio
{
sal_Int32 nDxTmp = 0;
mpInputStream->ReadInt32(nDxTmp);
- pDXAry[i] += nDxTmp;
+ aDXAry[i] += nDxTmp;
if (nOptions & ETO_PDY)
{
sal_Int32 nDyTmp = 0;
@@ -1984,7 +1985,7 @@ namespace emfio
}
}
- SAL_INFO("emfio", "\t\t\tSpacing " << i << ": " << pDXAry[i]);
+ SAL_INFO("emfio", "\t\t\tSpacing " << i << ": " << aDXAry[i]);
}
}
if ( nOptions & ETO_CLIPPED )
@@ -1992,7 +1993,7 @@ namespace emfio
Push(); // Save the current clip. It will be restored after text drawing
IntersectClipRect( aRect );
}
- DrawText(aPos, aText, pDXAry.get(), pDYAry.get(), mbRecordPath, nGfxMode);
+ DrawText(aPos, aText, aDXAry.empty() ? nullptr : &aDXAry, pDYAry.get(), mbRecordPath, nGfxMode);
if ( nOptions & ETO_CLIPPED )
Pop();
}
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index f78fee7bd5d9..d43a62e665e1 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -1677,7 +1677,7 @@ namespace emfio
}
}
- void MtfTools::DrawText( Point& rPosition, OUString const & rText, tools::Long* pDXArry, tools::Long* pDYArry, bool bRecordPath, sal_Int32 nGfxMode )
+ void MtfTools::DrawText( Point& rPosition, OUString const & rText, std::vector<tools::Long>* pDXArry, tools::Long* pDYArry, bool bRecordPath, sal_Int32 nGfxMode )
{
UpdateClipRegion();
rPosition = ImplMap( rPosition );
@@ -1689,13 +1689,13 @@ namespace emfio
sal_Int32 nSumX = 0, nSumY = 0;
for (sal_Int32 i = 0; i < rText.getLength(); i++ )
{
- nSumX += pDXArry[i];
+ nSumX += (*pDXArry)[i];
// #i121382# Map DXArray using WorldTransform
const Size aSizeX(ImplMap(Size(nSumX, 0)));
const basegfx::B2DVector aVectorX(aSizeX.Width(), aSizeX.Height());
- pDXArry[i] = basegfx::fround(aVectorX.getLength());
- pDXArry[i] *= (nSumX >= 0 ? 1 : -1);
+ (*pDXArry)[i] = basegfx::fround(aVectorX.getLength());
+ (*pDXArry)[i] *= (nSumX >= 0 ? 1 : -1);
if (pDYArry)
{
@@ -1796,9 +1796,9 @@ namespace emfio
{
nTextWidth = pVDev->GetTextWidth( OUString(rText[ nLen - 1 ]) );
if( nLen > 1 )
- nTextWidth += pDXArry[ nLen - 2 ];
+ nTextWidth += (*pDXArry)[ nLen - 2 ];
// tdf#39894: We should consider the distance to next character cell origin
- aActPosDelta.setX( pDXArry[ nLen - 1 ] );
+ aActPosDelta.setX( (*pDXArry)[ nLen - 1 ] );
if ( pDYArry )
{
aActPosDelta.setY( pDYArry[ nLen - 1 ] );
@@ -1859,25 +1859,26 @@ namespace emfio
{
for (sal_Int32 i = 0; i < rText.getLength(); ++i)
{
- Point aCharDisplacement( i ? pDXArry[i-1] : 0, i ? pDYArry[i-1] : 0 );
+ Point aCharDisplacement( i ? (*pDXArry)[i-1] : 0, i ? pDYArry[i-1] : 0 );
Point().RotateAround(aCharDisplacement, maFont.GetOrientation());
- mpGDIMetaFile->AddAction( new MetaTextArrayAction( rPosition + aCharDisplacement, OUString( rText[i] ), nullptr, 0, 1 ) );
+ mpGDIMetaFile->AddAction( new MetaTextArrayAction( rPosition + aCharDisplacement, OUString( rText[i] ), o3tl::span<const tools::Long>{}, 0, 1 ) );
}
}
else
{
/* because text without dx array is badly scaled, we
will create such an array if necessary */
- tools::Long* pDX = pDXArry;
+ o3tl::span<const tools::Long> pDX;
std::vector<tools::Long> aMyDXArray;
if (pDXArry)
{
+ pDX = { pDXArry->data(), pDXArry->size() };
// only useful when we have an imported DXArray
if(!rText.isEmpty())
{
maScaledFontHelper.evaluateAlternativeFontScale(
rText,
- pDXArry[rText.getLength() - 1] // extract imported TextLength
+ (*pDXArry)[rText.getLength() - 1] // extract imported TextLength
);
}
}
@@ -1889,7 +1890,7 @@ namespace emfio
pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
pVDev->SetFont( maLatestFont );
pVDev->GetTextArray( rText, &aMyDXArray, 0, rText.getLength());
- pDX = aMyDXArray.data();
+ pDX = { aMyDXArray.data(), aMyDXArray.size() };
}
mpGDIMetaFile->AddAction( new MetaTextArrayAction( rPosition, rText, pDX, 0, rText.getLength() ) );
}
diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx
index 62c5168a6bf0..9a04cdeb9823 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -721,7 +721,8 @@ namespace emfio
IntersectClipRect( aRect );
}
SAL_INFO( "emfio", "\t\t\t Text : " << aText );
- std::unique_ptr<tools::Long[]> pDXAry, pDYAry;
+ std::vector<tools::Long> aDXAry;
+ std::unique_ptr<tools::Long[]> pDYAry;
auto nDxArySize = nMaxStreamPos - mpInputStream->Tell();
auto nDxAryEntries = nDxArySize >> 1;
bool bUseDXAry = false;
@@ -729,7 +730,7 @@ namespace emfio
if ( ( ( nDxAryEntries % nOriginalTextLen ) == 0 ) && ( nNewTextLen <= nOriginalTextLen ) )
{
sal_Int32 i; // needed just outside the for
- pDXAry.reset(new tools::Long[ nNewTextLen ]);
+ aDXAry.resize( nNewTextLen );
if ( nOptions & ETO_PDY )
{
pDYAry.reset(new tools::Long[ nNewTextLen ]);
@@ -767,7 +768,7 @@ namespace emfio
}
}
- pDXAry[ i ] = nDx;
+ aDXAry[ i ] = nDx;
if ( nOptions & ETO_PDY )
{
pDYAry[i] = nDy;
@@ -776,8 +777,8 @@ namespace emfio
if ( i == nNewTextLen )
bUseDXAry = true;
}
- if ( pDXAry && bUseDXAry )
- DrawText( aPosition, aText, pDXAry.get(), pDYAry.get() );
+ if ( bUseDXAry )
+ DrawText( aPosition, aText, &aDXAry, pDYAry.get() );
else
DrawText( aPosition, aText );
if ( nOptions & ETO_CLIPPED )
@@ -1256,7 +1257,7 @@ namespace emfio
{
Point aPt;
sal_uInt32 nStringLen, nDXCount;
- std::unique_ptr<tools::Long[]> pDXAry;
+ std::vector<tools::Long> aDXAry;
SvMemoryStream aMemoryStream( nEscLen );
aMemoryStream.WriteBytes(pData.get(), nEscLen);
aMemoryStream.Seek( STREAM_SEEK_TO_BEGIN );
@@ -1274,15 +1275,15 @@ namespace emfio
if ( ( static_cast< sal_uInt64 >( nDXCount ) * sizeof( sal_Int32 ) ) >= ( nEscLen - aMemoryStream.Tell() ) )
nDXCount = 0;
if ( nDXCount )
- pDXAry.reset(new tools::Long[ nDXCount ]);
+ aDXAry.resize(nDXCount);
for (sal_uInt32 i = 0; i < nDXCount; i++ )
{
sal_Int32 val;
aMemoryStream.ReadInt32( val);
- pDXAry[ i ] = val;
+ aDXAry[ i ] = val;
}
aMemoryStream.ReadUInt32(mnSkipActions);
- DrawText( aPt, aString, pDXAry.get() );
+ DrawText( aPt, aString, aDXAry.empty() ? nullptr : &aDXAry );
}
}
}