From 95b04f52b567526a72922af67b926096d10424c1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 23 Aug 2017 14:36:48 +0200 Subject: loplugin:useuniqueptr in cppcanvas Change-Id: I8e995128a7a1c5911efc82a762dbe7be015b2050 Reviewed-on: https://gerrit.libreoffice.org/41493 Tested-by: Jenkins Reviewed-by: Noel Grandin --- cppcanvas/source/inc/implrenderer.hxx | 5 ++- cppcanvas/source/mtfrenderer/emfplus.cxx | 54 +++++++++++++-------------- cppcanvas/source/mtfrenderer/implrenderer.cxx | 3 -- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/cppcanvas/source/inc/implrenderer.hxx b/cppcanvas/source/inc/implrenderer.hxx index de215e0132ca..df26d09a4654 100644 --- a/cppcanvas/source/inc/implrenderer.hxx +++ b/cppcanvas/source/inc/implrenderer.hxx @@ -33,8 +33,9 @@ #include -#include #include +#include +#include class GDIMetaFile; class VirtualDevice; @@ -294,7 +295,7 @@ static float GetSwapFloat( SvStream& rSt ) /* EMF+ */ XForm aBaseTransform; XForm aWorldTransform; - EMFPObject* aObjects [256]; + std::unique_ptr aObjects [256]; float fPageScale; sal_Int32 nOriginX; sal_Int32 nOriginY; diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index 171e313271b3..7a9c2b96c3b4 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -321,7 +321,7 @@ namespace cppcanvas } else { rState.isFillColorSet = true; // extract UseBrush - EMFPBrush* brush = static_cast( aObjects [brushIndexOrColor & 0xff] ); + EMFPBrush* brush = static_cast( aObjects [brushIndexOrColor & 0xff].get() ); SAL_INFO("cppcanvas.emf", "EMF+\tbrush fill slot: " << brushIndexOrColor << " (type: " << (brush ? brush->GetType() : -1) << ")"); // give up in case something wrong happened @@ -612,7 +612,7 @@ namespace cppcanvas void ImplRenderer::EMFPPlusDrawPolygon (const ::basegfx::B2DPolyPolygon& polygon, const ActionFactoryParameters& rParms, OutDevState& rState, const CanvasSharedPtr& rCanvas, sal_uInt32 penIndex) { - EMFPPen* pen = static_cast( aObjects [penIndex & 0xff] ); + EMFPPen* pen = static_cast( aObjects [penIndex & 0xff].get() ); SAL_WARN_IF( !pen, "cppcanvas.emf", "emf+ missing pen" ); @@ -702,28 +702,27 @@ namespace cppcanvas index = flags & 0xff; if (aObjects [index] != nullptr) { - delete aObjects [index]; - aObjects [index] = nullptr; + aObjects [index].reset(); } switch (flags & 0x7f00) { case EmfPlusObjectTypeBrush: { - EMFPBrush *brush; - aObjects [index] = brush = new EMFPBrush (); + std::unique_ptr brush(new EMFPBrush()); brush->Read (rObjectStream, *this); + aObjects [index] = std::move(brush); break; } case EmfPlusObjectTypePen: { - EMFPPen *pen; - aObjects [index] = pen = new EMFPPen (); + std::unique_ptr pen(new EMFPPen ()); pen->Read (rObjectStream, *this); + aObjects [index] = std::move(pen); break; } - case EmfPlusObjectTypePath: + case EmfPlusObjectTypePath: { sal_uInt32 header, pathFlags; sal_Int32 points; @@ -732,48 +731,47 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+\tpath"); SAL_INFO("cppcanvas.emf", "EMF+\theader: 0x" << std::hex << header << " points: " << std::dec << points << " additional flags: 0x" << std::hex << pathFlags << std::dec); - EMFPPath *path; - aObjects [index] = path = new EMFPPath (points); + std::unique_ptr path(new EMFPPath (points)); path->Read (rObjectStream, pathFlags, *this); + aObjects [index] = std::move(path); break; + } case EmfPlusObjectTypeRegion: { - EMFPRegion *region; - - aObjects [index] = region = new EMFPRegion (); + std::unique_ptr region(new EMFPRegion ()); region->Read (rObjectStream); - + aObjects [index] = std::move(region); break; } case EmfPlusObjectTypeImage: { - EMFPImage *image; - aObjects [index] = image = new EMFPImage; + std::unique_ptr image(new EMFPImage); image->type = 0; image->width = 0; image->height = 0; image->stride = 0; image->pixelFormat = 0; image->Read (rObjectStream, dataSize, bUseWholeStream); + aObjects [index] = std::move(image); break; } case EmfPlusObjectTypeFont: { - EMFPFont *font; - aObjects [index] = font = new EMFPFont; + std::unique_ptr font(new EMFPFont); font->emSize = 0; font->sizeUnit = 0; font->fontFlags = 0; font->Read (rObjectStream); + aObjects [index] = std::move(font); break; } case EmfPlusObjectTypeStringFormat: { - EMFPStringFormat *stringFormat; - aObjects [index] = stringFormat = new EMFPStringFormat(); + std::unique_ptr stringFormat(new EMFPStringFormat()); stringFormat->Read (rObjectStream); + aObjects [index] = std::move(stringFormat); break; } case EmfPlusObjectTypeImageAttributes: @@ -794,7 +792,7 @@ namespace cppcanvas double ImplRenderer::setFont (css::rendering::FontRequest& aFontRequest, sal_uInt8 fontObjectId, const ActionFactoryParameters& rParms, OutDevState& rState) { - EMFPFont *font = static_cast< EMFPFont* >( aObjects[ fontObjectId ] ); + EMFPFont *font = static_cast< EMFPFont* >( aObjects[ fontObjectId ].get() ); aFontRequest.FontDescription.FamilyName = font->family; double cellSize = font->emSize; @@ -996,7 +994,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+ FillPath slot: " << index); - EMFPPlusFillPolygon( static_cast( aObjects [index])->GetPolygon (*this), rFactoryParms, rState, rCanvas, flags & 0x8000, brushIndexOrColor); + EMFPPlusFillPolygon( static_cast( aObjects [index].get())->GetPolygon (*this), rFactoryParms, rState, rCanvas, flags & 0x8000, brushIndexOrColor); } break; case EmfPlusRecordTypeDrawEllipse: @@ -1120,7 +1118,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+ DrawPath"); SAL_INFO("cppcanvas.emf", "EMF+\tpen: " << penIndex); - EMFPPath* path = static_cast( aObjects [flags & 0xff] ); + EMFPPath* path = static_cast( aObjects [flags & 0xff].get() ); SAL_WARN_IF( !path, "cppcanvas.emf", "EmfPlusRecordTypeDrawPath missing path" ); EMFPPlusDrawPolygon (path->GetPolygon (*this), rFactoryParms, rState, rCanvas, penIndex); @@ -1185,7 +1183,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+\tTODO: use image attributes"); if (sourceUnit == 2 && aObjects [flags & 0xff]) { // we handle only GraphicsUnit.Pixel now - EMFPImage& image = *static_cast( aObjects [flags & 0xff]); + EMFPImage& image = *static_cast( aObjects [flags & 0xff].get()); float sx, sy, sw, sh; sal_Int32 aCount; @@ -1281,7 +1279,7 @@ namespace cppcanvas OUString text = read_uInt16s_ToOUString(rMF, stringLength); - EMFPStringFormat *stringFormat = static_cast< EMFPStringFormat* >( aObjects[ formatId & 0xff ] ); + EMFPStringFormat *stringFormat = static_cast< EMFPStringFormat* >( aObjects[ formatId & 0xff ].get() ); css::rendering::FontRequest aFontRequest; if (stringFormat) { @@ -1538,7 +1536,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+ SetClipPath combine mode: " << combineMode); SAL_INFO("cppcanvas.emf", "EMF+\tpath in slot: " << (flags & 0xff)); - EMFPPath& path = *static_cast( aObjects [flags & 0xff] ); + EMFPPath& path = *static_cast( aObjects [flags & 0xff].get() ); ::basegfx::B2DPolyPolygon& clipPoly (path.GetPolygon (*this)); clipPoly.transform (rState.mapModeTransform); @@ -1563,7 +1561,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+ SetClipRegion"); SAL_INFO("cppcanvas.emf", "EMF+\tregion in slot: " << (flags & 0xff) << " combine mode: " << combineMode); - EMFPRegion *region = static_cast(aObjects [flags & 0xff]); + EMFPRegion *region = static_cast(aObjects [flags & 0xff].get()); // reset clip if (region && region->parts == 0 && region->initialState == EmfPlusRegionInitialStateInfinite) { diff --git a/cppcanvas/source/mtfrenderer/implrenderer.cxx b/cppcanvas/source/mtfrenderer/implrenderer.cxx index 19e97640264c..0df7f6a9032e 100644 --- a/cppcanvas/source/mtfrenderer/implrenderer.cxx +++ b/cppcanvas/source/mtfrenderer/implrenderer.cxx @@ -2985,9 +2985,6 @@ namespace cppcanvas ImplRenderer::~ImplRenderer() { - // don't leak EMFPObjects - for(EMFPObject* aObject : aObjects) - delete aObject; } bool ImplRenderer::drawSubset( sal_Int32 nStartIndex, -- cgit