diff options
-rw-r--r-- | vcl/source/filter/wmf/emfwr.cxx | 15 | ||||
-rw-r--r-- | vcl/source/filter/wmf/emfwr.hxx | 3 | ||||
-rw-r--r-- | vcl/source/filter/wmf/enhwmf.cxx | 33 | ||||
-rw-r--r-- | vcl/source/filter/wmf/winmtf.cxx | 132 | ||||
-rw-r--r-- | vcl/source/filter/wmf/winmtf.hxx | 102 | ||||
-rw-r--r-- | vcl/source/filter/wmf/winwmf.cxx | 46 |
6 files changed, 120 insertions, 211 deletions
diff --git a/vcl/source/filter/wmf/emfwr.cxx b/vcl/source/filter/wmf/emfwr.cxx index 921d5fd003f0..083bd779278a 100644 --- a/vcl/source/filter/wmf/emfwr.cxx +++ b/vcl/source/filter/wmf/emfwr.cxx @@ -293,8 +293,7 @@ bool EMFWriter::WriteEMF(const GDIMetaFile& rMtf) maVDev->SetMapMode( rMtf.GetPrefMapMode() ); // don't work with pixel as destination map mode -> higher resolution preferable maDestMapMode.SetMapUnit( MAP_100TH_MM ); - mpHandlesUsed = new bool[ MAXHANDLES ]; - memset( mpHandlesUsed, 0, MAXHANDLES * sizeof( bool ) ); + mHandlesUsed = std::vector<bool>(MAXHANDLES, false); mnHandleCount = mnRecordCount = mnRecordPos = mnRecordPlusPos = 0; mbRecordOpen = mbRecordPlusOpen = false; mbLineChanged = mbFillChanged = mbTextChanged = false; @@ -365,7 +364,7 @@ bool EMFWriter::WriteEMF(const GDIMetaFile& rMtf) .WriteInt32( aMtfSizeLog.Width() * 10 ).WriteInt32( aMtfSizeLog.Height() * 10 ); //use [MS-EMF 2.2.11] HeaderExtension2 Object m_rStm.Seek( nEndPos ); - delete[] mpHandlesUsed; + mHandlesUsed.clear(); return( m_rStm.GetError() == ERRCODE_NONE ); } @@ -374,11 +373,11 @@ sal_uLong EMFWriter::ImplAcquireHandle() { sal_uLong nHandle = HANDLE_INVALID; - for( sal_uLong i = 0; i < MAXHANDLES && ( HANDLE_INVALID == nHandle ); i++ ) + for( sal_uLong i = 0; i < mHandlesUsed.size() && ( HANDLE_INVALID == nHandle ); i++ ) { - if( !mpHandlesUsed[ i ] ) + if( !mHandlesUsed[ i ] ) { - mpHandlesUsed[ i ] = true; + mHandlesUsed[ i ] = true; if( ( nHandle = i ) == mnHandleCount ) mnHandleCount++; @@ -391,8 +390,8 @@ sal_uLong EMFWriter::ImplAcquireHandle() void EMFWriter::ImplReleaseHandle( sal_uLong nHandle ) { - DBG_ASSERT( nHandle && ( nHandle < MAXHANDLES ), "Handle out of range" ); - mpHandlesUsed[ nHandle - 1 ] = false; + DBG_ASSERT( nHandle && ( nHandle < mHandlesUsed.size() ), "Handle out of range" ); + mHandlesUsed[ nHandle - 1 ] = false; } void EMFWriter::ImplBeginRecord( sal_uInt32 nType ) diff --git a/vcl/source/filter/wmf/emfwr.hxx b/vcl/source/filter/wmf/emfwr.hxx index 79491fc7c0d9..41d268440ade 100644 --- a/vcl/source/filter/wmf/emfwr.hxx +++ b/vcl/source/filter/wmf/emfwr.hxx @@ -36,7 +36,7 @@ private: ScopedVclPtr<VirtualDevice> maVDev; MapMode maDestMapMode; SvStream& m_rStm; - bool* mpHandlesUsed; + std::vector<bool> mHandlesUsed; sal_uLong mnHandleCount; sal_uLong mnRecordCount; sal_uLong mnRecordPos; @@ -92,7 +92,6 @@ public: explicit EMFWriter(SvStream &rStream) : maVDev( VclPtr<VirtualDevice>::Create() ) , m_rStm(rStream) - , mpHandlesUsed(nullptr) , mnHandleCount(0) , mnRecordCount(0) , mnRecordPos(0) diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx index 1a0e7def2de7..ed02537cf635 100644 --- a/vcl/source/filter/wmf/enhwmf.cxx +++ b/vcl/source/filter/wmf/enhwmf.cxx @@ -20,6 +20,7 @@ #include <osl/endian.h> #include <basegfx/matrix/b2dhommatrix.hxx> #include <vcl/dibtools.hxx> +#include <o3tl/make_unique.hxx> #include "winmtf.hxx" @@ -401,7 +402,7 @@ bool ImplReadRegion( tools::PolyPolygon& rPolyPoly, SvStream& rStream, sal_uInt3 } // anonymous namespace EnhWMFReader::EnhWMFReader(SvStream& rStream,GDIMetaFile& rGDIMetaFile,FilterConfigItem* pConfigItem) - : WinMtf(new WinMtfOutput(rGDIMetaFile), rStream , pConfigItem) + : WinMtf(rGDIMetaFile, rStream , pConfigItem) , bRecordPath(false) , nRecordCount(0) , bEMFPlus(false) @@ -702,26 +703,26 @@ bool EnhWMFReader::ReadEnhWMF() switch( nRecType ) { case EMR_POLYBEZIERTO : - ReadAndDrawPolygon<sal_Int32>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int32>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyBezier( rPolygon, aTo, aRecordPath ); }, true ); break; case EMR_POLYBEZIER : - ReadAndDrawPolygon<sal_Int32>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int32>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyBezier( rPolygon, aTo, aRecordPath ); }, false ); break; case EMR_POLYGON : - ReadAndDrawPolygon<sal_Int32>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int32>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolygon( rPolygon, aTo, aRecordPath ); }, false ); break; case EMR_POLYLINETO : - ReadAndDrawPolygon<sal_Int32>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int32>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyLine( rPolygon, aTo, aRecordPath ); }, true ); break; case EMR_POLYLINE : - ReadAndDrawPolygon<sal_Int32>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int32>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyLine( rPolygon, aTo, aRecordPath ); }, false ); break; @@ -977,7 +978,7 @@ bool EnhWMFReader::ReadEnhWMF() default : aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::NONE ); } - pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) ); + pOut->CreateObjectIndexed(nIndex, o3tl::make_unique<WinMtfLineStyle>( ReadColor(), aLineInfo, bTransparent )); } } break; @@ -1065,7 +1066,7 @@ bool EnhWMFReader::ReadEnhWMF() default : aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::NONE ); } - pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( aColorRef, aLineInfo, bTransparent ) ); + pOut->CreateObjectIndexed(nIndex, o3tl::make_unique<WinMtfLineStyle>( aColorRef, aLineInfo, bTransparent )); } } break; @@ -1077,7 +1078,7 @@ bool EnhWMFReader::ReadEnhWMF() if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) { pWMF->ReadUInt32( nStyle ); - pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ) ); + pOut->CreateObjectIndexed(nIndex, o3tl::make_unique<WinMtfFillStyle>( ReadColor(), ( nStyle == BS_HOLLOW ) )); } } break; @@ -1519,7 +1520,7 @@ bool EnhWMFReader::ReadEnhWMF() // aLogFont.lfWidth = aTransVec.getX(); // aLogFont.lfHeight = aTransVec.getY(); - pOut->CreateObject( nIndex, GDI_FONT, new WinMtfFontStyle( aLogFont ) ); + pOut->CreateObjectIndexed(nIndex, o3tl::make_unique<WinMtfFontStyle>( aLogFont )); } } break; @@ -1617,27 +1618,27 @@ bool EnhWMFReader::ReadEnhWMF() break; case EMR_POLYBEZIERTO16 : - ReadAndDrawPolygon<sal_Int16>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int16>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyBezier( rPolygon, aTo, aRecordPath ); }, true ); break; case EMR_POLYBEZIER16 : - ReadAndDrawPolygon<sal_Int16>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int16>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyBezier( rPolygon, aTo, aRecordPath ); }, false ); break; case EMR_POLYGON16 : - ReadAndDrawPolygon<sal_Int16>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int16>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolygon( rPolygon, aTo, aRecordPath ); }, false ); break; case EMR_POLYLINETO16 : - ReadAndDrawPolygon<sal_Int16>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int16>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyLine( rPolygon, aTo, aRecordPath ); }, true ); break; case EMR_POLYLINE16 : - ReadAndDrawPolygon<sal_Int16>( [] ( WinMtfOutput* pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) + ReadAndDrawPolygon<sal_Int16>( [] ( std::unique_ptr<WinMtfOutput> &pWinMtfOutput, tools::Polygon& rPolygon, bool aTo, bool aRecordPath ) { pWinMtfOutput->DrawPolyLine( rPolygon, aTo, aRecordPath ); }, false ); break; @@ -1710,7 +1711,7 @@ bool EnhWMFReader::ReadEnhWMF() } } - pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( aBitmap ) ); + pOut->CreateObjectIndexed(nIndex, o3tl::make_unique<WinMtfFillStyle>( aBitmap )); } break; diff --git a/vcl/source/filter/wmf/winmtf.cxx b/vcl/source/filter/wmf/winmtf.cxx index ca8141faa713..e6f610a5ee2d 100644 --- a/vcl/source/filter/wmf/winmtf.cxx +++ b/vcl/source/filter/wmf/winmtf.cxx @@ -256,8 +256,8 @@ WinMtfFontStyle::WinMtfFontStyle( LOGFONTW& rFont ) aFont.SetFontSize(aFontSize); }; -WinMtf::WinMtf( WinMtfOutput* pWinMtfOutput, SvStream& rStreamWMF, FilterConfigItem* pConfigItem ) - : pOut( pWinMtfOutput ) +WinMtf::WinMtf( GDIMetaFile& rGDIMetaFile, SvStream& rStreamWMF, FilterConfigItem* pConfigItem ) + : pOut( o3tl::make_unique<WinMtfOutput>(rGDIMetaFile) ) , pWMF( &rStreamWMF ) , nEndPos( 0 ) , pFilterConfigItem( pConfigItem ) @@ -282,8 +282,6 @@ WinMtf::WinMtf( WinMtfOutput* pWinMtfOutput, SvStream& rStreamWMF, FilterConfigI WinMtf::~WinMtf() { - delete pOut; - if ( xStatusIndicator.is() ) xStatusIndicator->end(); } @@ -532,98 +530,90 @@ tools::PolyPolygon& WinMtfOutput::ImplMap( tools::PolyPolygon& rPolyPolygon ) void WinMtfOutput::SelectObject( sal_Int32 nIndex ) { - std::unique_ptr<GDIObj> stock_object; - GDIObj *pGDIObj = nullptr; - if ( nIndex & ENHMETA_STOCK_OBJECT ) { - stock_object = o3tl::make_unique<GDIObj>(); - pGDIObj = stock_object.get(); - } - else - { - nIndex &= 0xffff; // safety check: don't allow index to be > 65535 - - if ( (sal_uInt32)nIndex < vGDIObj.size() ) - pGDIObj = vGDIObj[ nIndex ].get(); - } - - if( !pGDIObj ) - return; - - if ( nIndex & ENHMETA_STOCK_OBJECT ) - { - sal_uInt16 nStockId = (sal_uInt8)nIndex; + sal_uInt16 nStockId = (sal_uInt8)nIndex; switch( nStockId ) { case WHITE_BRUSH : { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ) ) ); + maFillStyle = WinMtfFillStyle( Color( COL_WHITE ) ); + mbFillStyleSelected = true; } break; case LTGRAY_BRUSH : { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_LIGHTGRAY ) ) ); + maFillStyle = WinMtfFillStyle( Color( COL_LIGHTGRAY ) ); + mbFillStyleSelected = true; } break; case GRAY_BRUSH : case DKGRAY_BRUSH : { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_GRAY ) ) ); + maFillStyle = WinMtfFillStyle( Color( COL_GRAY ) ); + mbFillStyleSelected = true; } break; case BLACK_BRUSH : { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_BLACK ) ) ); + maFillStyle = WinMtfFillStyle( Color( COL_BLACK ) ); + mbFillStyleSelected = true; } break; case NULL_BRUSH : { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_TRANSPARENT ), true ) ); + maFillStyle = WinMtfFillStyle( Color( COL_TRANSPARENT ), true ); + mbFillStyleSelected = true; } break; case WHITE_PEN : { - pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_WHITE ) ) ); + maLineStyle = WinMtfLineStyle( Color( COL_WHITE ) ); } break; case BLACK_PEN : { - pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_BLACK ) ) ); + maLineStyle = WinMtfLineStyle( Color( COL_BLACK ) ); } break; case NULL_PEN : { - pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_TRANSPARENT ), true ) ); + maLineStyle = WinMtfLineStyle( Color( COL_TRANSPARENT ), true ); } break; default: break; } } - if ( pGDIObj->pStyle ) + else { - switch( pGDIObj->eType ) + nIndex &= 0xffff; // safety check: don't allow index to be > 65535 + + GDIObj *pGDIObj = nullptr; + + if ( (sal_uInt32)nIndex < vGDIObj.size() ) + pGDIObj = vGDIObj[ nIndex ].get(); + + if ( pGDIObj ) { - case GDI_PEN : - maLineStyle = static_cast<WinMtfLineStyle*>(pGDIObj->pStyle); - break; - case GDI_BRUSH : + const auto pen = dynamic_cast<WinMtfLineStyle*>(pGDIObj); + if (pen) + maLineStyle = *pen; + + const auto brush = dynamic_cast<WinMtfFillStyle*>(pGDIObj); + if (brush) { - maFillStyle = static_cast<WinMtfFillStyle*>(pGDIObj->pStyle); + maFillStyle = *brush; mbFillStyleSelected = true; } - break; - case GDI_FONT : - maFont = static_cast<WinMtfFontStyle*>(pGDIObj->pStyle)->aFont; - break; - default: - break; // -Wall many options not handled. + + const auto font = dynamic_cast<WinMtfFontStyle*>(pGDIObj); + if (font) + maFont = font->aFont; } } } - void WinMtfOutput::SetTextLayoutMode( ComplexTextLayoutMode nTextLayoutMode ) { mnTextLayoutMode = nTextLayoutMode; @@ -683,20 +673,21 @@ void WinMtfOutput::ImplDrawClippedPolyPolygon( const tools::PolyPolygon& rPolyPo } } -void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle ) +void WinMtfOutput::CreateObject( std::unique_ptr<GDIObj> pObject ) { - if ( pStyle ) + if ( pObject ) { - if ( eType == GDI_FONT ) + const auto pLineStyle = dynamic_cast<WinMtfLineStyle*>(pObject.get()); + const auto pFontStyle = dynamic_cast<WinMtfFontStyle*>(pObject.get()); + + if ( pFontStyle ) { - WinMtfFontStyle* pFontStyle = static_cast<WinMtfFontStyle*>(pStyle); if (pFontStyle->aFont.GetFontHeight() == 0) pFontStyle->aFont.SetFontHeight(423); ImplMap(pFontStyle->aFont); // defaulting to 12pt } - else if ( eType == GDI_PEN ) + else if ( pLineStyle ) { - WinMtfLineStyle* pLineStyle = static_cast<WinMtfLineStyle*>(pStyle); Size aSize(pLineStyle->aLineInfo.GetWidth(), 0); aSize = ImplMap(aSize); pLineStyle->aLineInfo.SetWidth(aSize.Width()); @@ -711,26 +702,26 @@ void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle ) if ( nIndex == vGDIObj.size() ) ImplResizeObjectArry( vGDIObj.size() + 16 ); - vGDIObj[ nIndex ] = o3tl::make_unique<GDIObj>( eType, pStyle ); + vGDIObj[ nIndex ] = std::move(pObject); } -void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pStyle ) +void WinMtfOutput::CreateObjectIndexed( sal_Int32 nIndex, std::unique_ptr<GDIObj> pObject ) { if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) { nIndex &= 0xffff; // safety check: do not allow index to be > 65535 - if ( pStyle ) + if ( pObject ) { - if ( eType == GDI_FONT ) + const auto pLineStyle = dynamic_cast<WinMtfLineStyle*>(pObject.get()); + const auto pFontStyle = dynamic_cast<WinMtfFontStyle*>(pObject.get()); + if ( pFontStyle ) { - WinMtfFontStyle* pFontStyle = static_cast<WinMtfFontStyle*>(pStyle); if (pFontStyle->aFont.GetFontHeight() == 0) pFontStyle->aFont.SetFontHeight(423); ImplMap(pFontStyle->aFont); } - else if ( eType == GDI_PEN ) + else if ( pLineStyle ) { - WinMtfLineStyle* pLineStyle = static_cast<WinMtfLineStyle*>(pStyle); Size aSize(pLineStyle->aLineInfo.GetWidth(), 0); pLineStyle->aLineInfo.SetWidth( ImplMap(aSize).Width() ); @@ -747,27 +738,12 @@ void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pS if ( (sal_uInt32)nIndex >= vGDIObj.size() ) ImplResizeObjectArry( nIndex + 16 ); - vGDIObj[ nIndex ] = o3tl::make_unique<GDIObj>( eType, pStyle ); + vGDIObj[ nIndex ] = std::move(pObject); } - else - { - switch ( eType ) - { - case GDI_PEN : - delete static_cast<WinMtfLineStyle*>(pStyle); - break; - case GDI_BRUSH : - delete static_cast<WinMtfFillStyle*>(pStyle); - break; - case GDI_FONT : - delete static_cast<WinMtfFontStyle*>(pStyle); - break; +} - default: - OSL_FAIL( "unsupported style not deleted" ); - break; - } - } +GDIObj::~GDIObj() +{ } void WinMtfOutput::DeleteObject( sal_Int32 nIndex ) diff --git a/vcl/source/filter/wmf/winmtf.hxx b/vcl/source/filter/wmf/winmtf.hxx index db4aa0155953..3f4182ee44bf 100644 --- a/vcl/source/filter/wmf/winmtf.hxx +++ b/vcl/source/filter/wmf/winmtf.hxx @@ -28,6 +28,7 @@ #include <vcl/bitmapaccess.hxx> #include <vcl/lineinfo.hxx> #include <vcl/fltcall.hxx> +#include <o3tl/make_unique.hxx> #define ERROR 0 #define NULLREGION 1 @@ -285,7 +286,12 @@ public: void AddPolyPolygon( const tools::PolyPolygon& rPolyPolygon ); }; -struct WinMtfFontStyle +struct GDIObj +{ + virtual ~GDIObj(); // Polymorphic base class +}; + +struct WinMtfFontStyle : GDIObj { vcl::Font aFont; @@ -299,7 +305,7 @@ typedef enum FillStylePattern } WinMtfFillStyleType; -struct WinMtfFillStyle +struct WinMtfFillStyle : GDIObj { Color aFillColor; bool bTransparent; @@ -340,17 +346,9 @@ struct WinMtfFillStyle return *this; } - WinMtfFillStyle& operator=(WinMtfFillStyle* pStyle) - { - aFillColor = pStyle->aFillColor; - bTransparent = pStyle->bTransparent; - aBmp = pStyle->aBmp; - aType = pStyle->aType; - return *this; - } }; -struct WinMtfLineStyle +struct WinMtfLineStyle : GDIObj { Color aLineColor; LineInfo aLineInfo; @@ -463,68 +461,6 @@ struct BSaveStruct typedef std::vector<std::unique_ptr<BSaveStruct>> BSaveStructList_impl; -enum GDIObjectType -{ - GDI_DUMMY = 0, - GDI_PEN = 1, - GDI_BRUSH = 2, - GDI_FONT = 3, - GDI_PALETTE = 4, - GDI_BITMAP = 5, - GDI_REGION = 6 -}; - -struct GDIObj -{ - void* pStyle; - GDIObjectType eType; - - GDIObj() - : pStyle (nullptr) - , eType (GDI_DUMMY) - {} - - GDIObj(GDIObjectType eT, void* pS) - : pStyle(pS) - , eType(eT) - {} - - void Set(GDIObjectType eT, void* pS) - { - pStyle = pS; - eType = eT; - } - - void Delete() - { - if (pStyle == nullptr) - return; - - switch (eType) - { - case GDI_PEN : - delete static_cast<WinMtfLineStyle*>(pStyle); - break; - case GDI_BRUSH : - delete static_cast<WinMtfFillStyle*>(pStyle); - break; - case GDI_FONT : - delete static_cast<WinMtfFontStyle*>(pStyle); - break; - - default: - OSL_FAIL( "unsupported style deleted" ); - break; - } - pStyle = nullptr; - } - - ~GDIObj() - { - Delete(); - } -}; - class WinMtfOutput { WinMtfPathObj aPathObj; @@ -632,8 +568,15 @@ public: void SetBkColor( const Color& rColor ); void SetTextColor( const Color& rColor ); void SetTextAlign( sal_uInt32 nAlign ); - void CreateObject( GDIObjectType, void* pStyle = nullptr ); - void CreateObject( sal_Int32 nIndex, GDIObjectType, void* pStyle = nullptr ); + + void CreateObject( std::unique_ptr<GDIObj> pObject); + void CreateObjectIndexed( sal_Int32 nIndex, std::unique_ptr<GDIObj> pObject ); + + void CreateObject() + { + CreateObject(o3tl::make_unique<GDIObj>()); + } + void DeleteObject( sal_Int32 nIndex ); void SelectObject( sal_Int32 nIndex ); rtl_TextEncoding GetCharSet(){ return maFont.GetCharSet(); }; @@ -712,7 +655,7 @@ class WinMtf { protected: - WinMtfOutput* pOut; + std::unique_ptr<WinMtfOutput> pOut; SvStream* pWMF; // the WMF/EMF file to be read sal_uInt32 nStartPos, nEndPos; @@ -728,7 +671,7 @@ protected: void Callback( sal_uInt16 nPercent ); WinMtf( - WinMtfOutput* pOut, + GDIMetaFile& rGDIMetaFile, SvStream& rStreamWMF, FilterConfigItem* pConfigItem = nullptr ); @@ -750,7 +693,6 @@ public: ~EnhWMFReader(); bool ReadEnhWMF(); - void ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC); private: template <class T> void ReadAndDrawPolyPolygon(); template <class T> void ReadAndDrawPolyLine(); @@ -758,6 +700,7 @@ private: template <class T, class Drawer> void ReadAndDrawPolygon(Drawer drawer, const bool skipFirst); Rectangle ReadRectangle(); + void ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC); }; class WMFReader : public WinMtf @@ -768,7 +711,7 @@ private: sal_uInt32 nRecSize; // embedded EMF data - SvMemoryStream* pEMFStream; + std::unique_ptr<SvMemoryStream> pEMFStream; // total number of comment records containing EMF data sal_uInt32 nEMFRecCount; @@ -802,7 +745,6 @@ public: WMFReader(SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = nullptr, WMF_EXTERNALHEADER* pExtHeader = nullptr); - ~WMFReader(); // read WMF file from stream and fill the GDIMetaFile void ReadWMF(); diff --git a/vcl/source/filter/wmf/winwmf.cxx b/vcl/source/filter/wmf/winwmf.cxx index 245455d8e4a9..ae5cc87509ef 100644 --- a/vcl/source/filter/wmf/winwmf.cxx +++ b/vcl/source/filter/wmf/winwmf.cxx @@ -29,6 +29,7 @@ #include <vcl/svapp.hxx> #include <vcl/dibtools.hxx> #include <tools/fract.hxx> +#include <o3tl/make_unique.hxx> // MS Windows defines @@ -766,7 +767,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) Bitmap::ReleaseAccess( pBmp ); } Color aColor( (sal_uInt8)( nRed / nCount ), (sal_uInt8)( nGreen / nCount ), (sal_uInt8)( nBlue / nCount ) ); - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( aColor, false ) ); + pOut->CreateObject(o3tl::make_unique<WinMtfFillStyle>( aColor, false )); } break; @@ -780,19 +781,19 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) case W_META_CREATEPALETTE: { - pOut->CreateObject( GDI_DUMMY ); + pOut->CreateObject(); } break; case W_META_CREATEBRUSH: { - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ), false ) ); + pOut->CreateObject(o3tl::make_unique<WinMtfFillStyle>( Color( COL_WHITE ), false )); } break; case W_META_CREATEPATTERNBRUSH: { - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ), false ) ); + pOut->CreateObject(o3tl::make_unique<WinMtfFillStyle>( Color( COL_WHITE ), false )); } break; @@ -869,7 +870,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) default : aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::NONE ); } - pOut->CreateObject( GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) ); + pOut->CreateObject(o3tl::make_unique<WinMtfLineStyle>( ReadColor(), aLineInfo, bTransparent )); } break; @@ -877,7 +878,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) { sal_uInt16 nStyle = 0; pWMF->ReadUInt16( nStyle ); - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ) ); + pOut->CreateObject(o3tl::make_unique<WinMtfFillStyle>( ReadColor(), ( nStyle == BS_HOLLOW ) )); } break; @@ -920,25 +921,25 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) eCharSet = RTL_TEXTENCODING_MS_1252; aLogFont.alfFaceName = OUString( lfFaceName, strlen(lfFaceName), eCharSet ); - pOut->CreateObject( GDI_FONT, new WinMtfFontStyle( aLogFont ) ); + pOut->CreateObject(o3tl::make_unique<WinMtfFontStyle>( aLogFont )); } break; case W_META_CREATEBITMAPINDIRECT: { - pOut->CreateObject( GDI_DUMMY ); + pOut->CreateObject(); } break; case W_META_CREATEBITMAP: { - pOut->CreateObject( GDI_DUMMY ); + pOut->CreateObject(); } break; case W_META_CREATEREGION: { - pOut->CreateObject( GDI_DUMMY ); + pOut->CreateObject(); } break; @@ -1091,22 +1092,20 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) { // first EMF comment nEMFRecCount = nComRecCount; nEMFSize = nEMFTotalSize; - pEMFStream = new SvMemoryStream( nEMFSize ); + pEMFStream = o3tl::make_unique<SvMemoryStream>( nEMFSize ); } else if( ( nEMFRecCount != nComRecCount ) || ( nEMFSize != nEMFTotalSize ) ) // add additional checks here { // total records should be the same as in previous comments nEMFRecCount = 0xFFFFFFFF; - delete pEMFStream; - pEMFStream = nullptr; + pEMFStream.reset(); } nEMFRec++; if( pEMFStream && nCurRecSize + 34 > nLen ) { nEMFRecCount = 0xFFFFFFFF; - delete pEMFStream; - pEMFStream = nullptr; + pEMFStream.reset(); } if( pEMFStream ) @@ -1298,7 +1297,7 @@ void WMFReader::ReadWMF() nCurrentAction = 0; nUnicodeEscapeAction = 0; - pEMFStream = nullptr; + pEMFStream.reset(); nEMFRecCount = 0; nEMFRec = 0; nEMFSize = 0; @@ -1364,9 +1363,9 @@ void WMFReader::ReadWMF() { GDIMetaFile aMeta; pEMFStream->Seek( 0 ); - EnhWMFReader* pEMFReader = new EnhWMFReader ( *pEMFStream, aMeta ); + std::unique_ptr<EnhWMFReader> pEMFReader(o3tl::make_unique<EnhWMFReader>( *pEMFStream, aMeta )); bEMFAvailable = pEMFReader->ReadEnhWMF(); - delete pEMFReader; // destroy first!!! + pEMFReader.reset(); // destroy first!!! if( bEMFAvailable ) { @@ -1383,8 +1382,7 @@ void WMFReader::ReadWMF() { // something went wrong // continue with WMF, don't try this again - delete pEMFStream; - pEMFStream = nullptr; + pEMFStream.reset(); } } } @@ -1789,10 +1787,9 @@ void WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) WMFReader::WMFReader(SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem, WMF_EXTERNALHEADER* pExtHeader) - : WinMtf(new WinMtfOutput(rGDIMetaFile) , rStreamWMF, pConfigItem) + : WinMtf(rGDIMetaFile, rStreamWMF, pConfigItem) , nUnitsPerInch(96) , nRecSize(0) - , pEMFStream(nullptr) , nEMFRecCount(0) , nEMFRec(0) , nEMFSize(0) @@ -1802,9 +1799,4 @@ WMFReader::WMFReader(SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, , pExternalHeader(pExtHeader) {} -WMFReader::~WMFReader() -{ - delete pEMFStream; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |