Kaydet (Commit) e76d4584 authored tarafından Mark Page's avatar Mark Page Kaydeden (comit) Noel Grandin

Change vGDIObj pointer to unique_ptr to reduce WinMtfOutput complexity

Change-Id: Ia81d3b30a874c2e722f7b836db9fab0be2d6e27b
Reviewed-on: https://gerrit.libreoffice.org/24488Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst fa6efd45
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <rtl/tencinfo.h> #include <rtl/tencinfo.h>
#include <vcl/virdev.hxx> #include <vcl/virdev.hxx>
#include <o3tl/make_unique.hxx>
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
#define EMFP_DEBUG(x) x #define EMFP_DEBUG(x) x
...@@ -531,19 +532,23 @@ tools::PolyPolygon& WinMtfOutput::ImplMap( tools::PolyPolygon& rPolyPolygon ) ...@@ -531,19 +532,23 @@ tools::PolyPolygon& WinMtfOutput::ImplMap( tools::PolyPolygon& rPolyPolygon )
void WinMtfOutput::SelectObject( sal_Int32 nIndex ) void WinMtfOutput::SelectObject( sal_Int32 nIndex )
{ {
GDIObj* pGDIObj = nullptr; std::unique_ptr<GDIObj> stock_object;
GDIObj *pGDIObj = nullptr;
if ( nIndex & ENHMETA_STOCK_OBJECT ) if ( nIndex & ENHMETA_STOCK_OBJECT )
pGDIObj = new GDIObj(); {
stock_object = o3tl::make_unique<GDIObj>();
pGDIObj = stock_object.get();
}
else else
{ {
nIndex &= 0xffff; // safety check: don't allow index to be > 65535 nIndex &= 0xffff; // safety check: don't allow index to be > 65535
if ( (sal_uInt32)nIndex < vGDIObj.size() ) if ( (sal_uInt32)nIndex < vGDIObj.size() )
pGDIObj = vGDIObj[ nIndex ]; pGDIObj = vGDIObj[ nIndex ].get();
} }
if( pGDIObj == nullptr ) if( !pGDIObj )
return; return;
if ( nIndex & ENHMETA_STOCK_OBJECT ) if ( nIndex & ENHMETA_STOCK_OBJECT )
...@@ -616,8 +621,6 @@ void WinMtfOutput::SelectObject( sal_Int32 nIndex ) ...@@ -616,8 +621,6 @@ void WinMtfOutput::SelectObject( sal_Int32 nIndex )
break; // -Wall many options not handled. break; // -Wall many options not handled.
} }
} }
if ( nIndex & ENHMETA_STOCK_OBJECT )
delete pGDIObj;
} }
...@@ -648,7 +651,7 @@ void WinMtfOutput::SetTextAlign( sal_uInt32 nAlign ) ...@@ -648,7 +651,7 @@ void WinMtfOutput::SetTextAlign( sal_uInt32 nAlign )
void WinMtfOutput::ImplResizeObjectArry( sal_uInt32 nNewEntrys ) void WinMtfOutput::ImplResizeObjectArry( sal_uInt32 nNewEntrys )
{ {
vGDIObj.resize(nNewEntrys, nullptr); vGDIObj.resize(nNewEntrys);
} }
void WinMtfOutput::ImplDrawClippedPolyPolygon( const tools::PolyPolygon& rPolyPoly ) void WinMtfOutput::ImplDrawClippedPolyPolygon( const tools::PolyPolygon& rPolyPoly )
...@@ -702,13 +705,13 @@ void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle ) ...@@ -702,13 +705,13 @@ void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle )
sal_uInt32 nIndex; sal_uInt32 nIndex;
for ( nIndex = 0; nIndex < vGDIObj.size(); nIndex++ ) for ( nIndex = 0; nIndex < vGDIObj.size(); nIndex++ )
{ {
if ( vGDIObj[ nIndex ] == nullptr ) if ( !vGDIObj[ nIndex ] )
break; break;
} }
if ( nIndex == vGDIObj.size() ) if ( nIndex == vGDIObj.size() )
ImplResizeObjectArry( vGDIObj.size() + 16 ); ImplResizeObjectArry( vGDIObj.size() + 16 );
vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); vGDIObj[ nIndex ] = o3tl::make_unique<GDIObj>( eType, pStyle );
} }
void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pStyle ) void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pStyle )
...@@ -744,10 +747,7 @@ void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pS ...@@ -744,10 +747,7 @@ void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pS
if ( (sal_uInt32)nIndex >= vGDIObj.size() ) if ( (sal_uInt32)nIndex >= vGDIObj.size() )
ImplResizeObjectArry( nIndex + 16 ); ImplResizeObjectArry( nIndex + 16 );
if ( vGDIObj[ nIndex ] != nullptr ) vGDIObj[ nIndex ] = o3tl::make_unique<GDIObj>( eType, pStyle );
delete vGDIObj[ nIndex ];
vGDIObj[ nIndex ] = new GDIObj( eType, pStyle );
} }
else else
{ {
...@@ -776,8 +776,7 @@ void WinMtfOutput::DeleteObject( sal_Int32 nIndex ) ...@@ -776,8 +776,7 @@ void WinMtfOutput::DeleteObject( sal_Int32 nIndex )
{ {
if ( (sal_uInt32)nIndex < vGDIObj.size() ) if ( (sal_uInt32)nIndex < vGDIObj.size() )
{ {
delete vGDIObj[ nIndex ]; vGDIObj[ nIndex ].reset();
vGDIObj[ nIndex ] = nullptr;
} }
} }
} }
...@@ -883,9 +882,6 @@ WinMtfOutput::~WinMtfOutput() ...@@ -883,9 +882,6 @@ WinMtfOutput::~WinMtfOutput()
mpGDIMetaFile->SetPrefSize( Size( mnDevWidth, mnDevHeight ) ); mpGDIMetaFile->SetPrefSize( Size( mnDevWidth, mnDevHeight ) );
else else
mpGDIMetaFile->SetPrefSize( mrclFrame.GetSize() ); mpGDIMetaFile->SetPrefSize( mrclFrame.GetSize() );
for ( size_t i = 0; i < vGDIObj.size(); i++ )
delete vGDIObj[ i ];
} }
void WinMtfOutput::UpdateClipRegion() void WinMtfOutput::UpdateClipRegion()
......
...@@ -551,7 +551,7 @@ class WinMtfOutput ...@@ -551,7 +551,7 @@ class WinMtfOutput
RasterOp meLatestRasterOp; RasterOp meLatestRasterOp;
RasterOp meRasterOp; RasterOp meRasterOp;
std::vector< GDIObj* > vGDIObj; std::vector< std::unique_ptr<GDIObj> > vGDIObj;
Point maActPos; Point maActPos;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment