use unique_ptr in sw

Change-Id: I471875142391e537a4301dfe42beb8f8803ff46b
Reviewed-on: https://gerrit.libreoffice.org/66036
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2019-01-09 15:38:12 +02:00
parent 3d14462e23
commit 152e2e6943
9 changed files with 36 additions and 44 deletions

View File

@@ -1346,7 +1346,7 @@ void InsertCnt_( SwLayoutFrame *pLay, SwDoc *pDoc,
const SwFrameFormats *pTable = pDoc->GetSpzFrameFormats(); const SwFrameFormats *pTable = pDoc->GetSpzFrameFormats();
SwFrame *pFrame = nullptr; SwFrame *pFrame = nullptr;
std::unique_ptr<SwActualSection> pActualSection; std::unique_ptr<SwActualSection> pActualSection;
SwLayHelper *pPageMaker; std::unique_ptr<SwLayHelper> pPageMaker;
//If the layout will be created (bPages == true) we do head on the progress //If the layout will be created (bPages == true) we do head on the progress
//Flys and DrawObjects are not connected immediately, this //Flys and DrawObjects are not connected immediately, this
@@ -1355,8 +1355,8 @@ void InsertCnt_( SwLayoutFrame *pLay, SwDoc *pDoc,
{ {
// Attention: the SwLayHelper class uses references to the content-, // Attention: the SwLayHelper class uses references to the content-,
// page-, layout-frame etc. and may change them! // page-, layout-frame etc. and may change them!
pPageMaker = new SwLayHelper( pDoc, pFrame, pPrv, pPage, pLay, pPageMaker.reset(new SwLayHelper( pDoc, pFrame, pPrv, pPage, pLay,
pActualSection, nIndex, 0 == nEndIndex ); pActualSection, nIndex, 0 == nEndIndex ));
if( bStartPercent ) if( bStartPercent )
{ {
const sal_uLong nPageCount = pPageMaker->CalcPageCount(); const sal_uLong nPageCount = pPageMaker->CalcPageCount();
@@ -1747,7 +1747,7 @@ void InsertCnt_( SwLayoutFrame *pLay, SwDoc *pDoc,
if( pPageMaker ) if( pPageMaker )
{ {
pPageMaker->CheckFlyCache( pPage ); pPageMaker->CheckFlyCache( pPage );
delete pPageMaker; pPageMaker.reset();
if( pDoc->GetLayoutCache() ) if( pDoc->GetLayoutCache() )
{ {
#ifdef DBG_UTIL #ifdef DBG_UTIL

View File

@@ -6214,12 +6214,12 @@ void SwFrame::PaintSwFrameBackground( const SwRect &rRect, const SwPageFrame *pP
if ( aRect.HasArea() ) if ( aRect.HasArea() )
{ {
SvxBrushItem* pNewItem = nullptr; std::unique_ptr<SvxBrushItem> pNewItem;
if( pCol ) if( pCol )
{ {
pNewItem = new SvxBrushItem( *pCol, RES_BACKGROUND ); pNewItem.reset(new SvxBrushItem( *pCol, RES_BACKGROUND ));
pItem = pNewItem; pItem = pNewItem.get();
aFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(*pCol)); aFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(*pCol));
} }
@@ -6287,8 +6287,6 @@ void SwFrame::PaintSwFrameBackground( const SwRect &rRect, const SwPageFrame *pP
bConsiderBackgroundTransparency ); bConsiderBackgroundTransparency );
} }
} }
if( pCol )
delete pNewItem;
} }
} }
else else

View File

@@ -1307,7 +1307,7 @@ void SwTextFrame::Format_( SwTextFormatter &rLine, SwTextFormatInfo &rInf,
SwCharRange &rReformat = pPara->GetReformat(); SwCharRange &rReformat = pPara->GetReformat();
SwRepaint &rRepaint = pPara->GetRepaint(); SwRepaint &rRepaint = pPara->GetRepaint();
SwRepaint *pFreeze = nullptr; std::unique_ptr<SwRepaint> pFreeze;
// Due to performance reasons we set rReformat to COMPLETE_STRING in Init() // Due to performance reasons we set rReformat to COMPLETE_STRING in Init()
// In this case we adjust rReformat // In this case we adjust rReformat
@@ -1566,7 +1566,7 @@ void SwTextFrame::Format_( SwTextFormatter &rLine, SwTextFormatInfo &rInf,
{ {
while( rLine.Next() ) while( rLine.Next() )
; //Nothing ; //Nothing
pFreeze = new SwRepaint( rRepaint ); // to minimize painting pFreeze.reset(new SwRepaint( rRepaint )); // to minimize painting
} }
else else
break; break;
@@ -1578,7 +1578,7 @@ void SwTextFrame::Format_( SwTextFormatter &rLine, SwTextFormatInfo &rInf,
if( pFreeze ) if( pFreeze )
{ {
rRepaint = *pFreeze; rRepaint = *pFreeze;
delete pFreeze; pFreeze.reset();
} }
if( !rLine.IsStop() ) if( !rLine.IsStop() )

View File

@@ -464,17 +464,17 @@ bool SwTextFrame::PaintEmpty( const SwRect &rRect, bool bCheck ) const
return false; return false;
else if( pSh->GetWin() ) else if( pSh->GetWin() )
{ {
SwFont *pFnt; std::unique_ptr<SwFont> pFnt;
const SwTextNode& rTextNode = *GetTextNodeForParaProps(); const SwTextNode& rTextNode = *GetTextNodeForParaProps();
if ( rTextNode.HasSwAttrSet() ) if ( rTextNode.HasSwAttrSet() )
{ {
const SwAttrSet *pAttrSet = &( rTextNode.GetSwAttrSet() ); const SwAttrSet *pAttrSet = &( rTextNode.GetSwAttrSet() );
pFnt = new SwFont( pAttrSet, rTextNode.getIDocumentSettingAccess() ); pFnt.reset(new SwFont( pAttrSet, rTextNode.getIDocumentSettingAccess() ));
} }
else else
{ {
SwFontAccess aFontAccess( &rTextNode.GetAnyFormatColl(), pSh ); SwFontAccess aFontAccess( &rTextNode.GetAnyFormatColl(), pSh );
pFnt = new SwFont( aFontAccess.Get()->GetFont() ); pFnt.reset(new SwFont( aFontAccess.Get()->GetFont() ));
} }
const IDocumentRedlineAccess& rIDRA = rTextNode.getIDocumentRedlineAccess(); const IDocumentRedlineAccess& rIDRA = rTextNode.getIDocumentRedlineAccess();
@@ -516,14 +516,12 @@ bool SwTextFrame::PaintEmpty( const SwRect &rRect, bool bCheck ) const
if ( rSpace.GetTextFirstLineOfst() > 0 ) if ( rSpace.GetTextFirstLineOfst() > 0 )
aPos.AdjustX(rSpace.GetTextFirstLineOfst() ); aPos.AdjustX(rSpace.GetTextFirstLineOfst() );
SwSaveClip *pClip; std::unique_ptr<SwSaveClip> pClip;
if( IsUndersized() ) if( IsUndersized() )
{ {
pClip = new SwSaveClip( pSh->GetOut() ); pClip.reset(new SwSaveClip( pSh->GetOut() ));
pClip->ChgClip( rRect ); pClip->ChgClip( rRect );
} }
else
pClip = nullptr;
aPos.AdjustY(pFnt->GetAscent( pSh, *pSh->GetOut() ) ); aPos.AdjustY(pFnt->GetAscent( pSh, *pSh->GetOut() ) );
@@ -554,15 +552,13 @@ bool SwTextFrame::PaintEmpty( const SwRect &rRect, bool bCheck ) const
aDrawInf.SetGrammarCheck( nullptr ); aDrawInf.SetGrammarCheck( nullptr );
aDrawInf.SetSmartTags( nullptr ); aDrawInf.SetSmartTags( nullptr );
aDrawInf.SetFrame( this ); aDrawInf.SetFrame( this );
aDrawInf.SetFont( pFnt ); aDrawInf.SetFont( pFnt.get() );
aDrawInf.SetSnapToGrid( false ); aDrawInf.SetSnapToGrid( false );
pFnt->SetColor(NON_PRINTING_CHARACTER_COLOR); pFnt->SetColor(NON_PRINTING_CHARACTER_COLOR);
pFnt->DrawText_( aDrawInf ); pFnt->DrawText_( aDrawInf );
} }
delete pClip;
} }
delete pFnt;
return true; return true;
} }
} }

View File

@@ -400,20 +400,19 @@ void SwDropPortion::Paint( const SwTextPaintInfo &rInf ) const
rInf.DrawBackground( *this ); rInf.DrawBackground( *this );
// make sure that font is not rotated // make sure that font is not rotated
SwFont* pTmpFont = nullptr; std::unique_ptr<SwFont> pTmpFont;
if ( rInf.GetFont()->GetOrientation( rInf.GetTextFrame()->IsVertical() ) ) if ( rInf.GetFont()->GetOrientation( rInf.GetTextFrame()->IsVertical() ) )
{ {
pTmpFont = new SwFont( *rInf.GetFont() ); pTmpFont.reset(new SwFont( *rInf.GetFont() ));
pTmpFont->SetVertical( 0, rInf.GetTextFrame()->IsVertical() ); pTmpFont->SetVertical( 0, rInf.GetTextFrame()->IsVertical() );
} }
SwFontSave aFontSave( rInf, pTmpFont ); SwFontSave aFontSave( rInf, pTmpFont.get() );
// for text inside drop portions we let vcl handle the text directions // for text inside drop portions we let vcl handle the text directions
SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() ); SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
aLayoutModeModifier.SetAuto(); aLayoutModeModifier.SetAuto();
SwTextPortion::Paint( rInf ); SwTextPortion::Paint( rInf );
delete pTmpFont;
} }
} }

View File

@@ -221,7 +221,7 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat,
mvItems.pop_back(); mvItems.pop_back();
} }
::basegfx::B2DPolyPolygon aPolyPolygon; ::basegfx::B2DPolyPolygon aPolyPolygon;
::basegfx::B2DPolyPolygon* pPolyPolygon = nullptr; std::unique_ptr<::basegfx::B2DPolyPolygon> pPolyPolygon;
if ( auto pVirtFlyDrawObj = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) ) if ( auto pVirtFlyDrawObj = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) )
{ {
@@ -242,13 +242,13 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat,
} }
::basegfx::B2DPolyPolygon aContourPoly(pObj->TakeContour()); ::basegfx::B2DPolyPolygon aContourPoly(pObj->TakeContour());
pPolyPolygon = new ::basegfx::B2DPolyPolygon(aContourPoly); pPolyPolygon.reset(new ::basegfx::B2DPolyPolygon(aContourPoly));
} }
const SvxLRSpaceItem &rLRSpace = pFormat->GetLRSpace(); const SvxLRSpaceItem &rLRSpace = pFormat->GetLRSpace();
const SvxULSpaceItem &rULSpace = pFormat->GetULSpace(); const SvxULSpaceItem &rULSpace = pFormat->GetULSpace();
CacheItem item { CacheItem item {
pObj, // due to #37347 the Object must be entered only after GetContour() pObj, // due to #37347 the Object must be entered only after GetContour()
o3tl::make_unique<TextRanger>( aPolyPolygon, pPolyPolygon, 20, o3tl::make_unique<TextRanger>( aPolyPolygon, pPolyPolygon.get(), 20,
static_cast<sal_uInt16>(rLRSpace.GetLeft()), static_cast<sal_uInt16>(rLRSpace.GetRight()), static_cast<sal_uInt16>(rLRSpace.GetLeft()), static_cast<sal_uInt16>(rLRSpace.GetRight()),
pFormat->GetSurround().IsOutside(), false, pFrame->IsVertical() ) pFormat->GetSurround().IsOutside(), false, pFrame->IsVertical() )
}; };
@@ -256,7 +256,7 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat,
mvItems[0].mxTextRanger->SetUpper( rULSpace.GetUpper() ); mvItems[0].mxTextRanger->SetUpper( rULSpace.GetUpper() );
mvItems[0].mxTextRanger->SetLower( rULSpace.GetLower() ); mvItems[0].mxTextRanger->SetLower( rULSpace.GetLower() );
delete pPolyPolygon; pPolyPolygon.reset();
nPntCnt += mvItems[0].mxTextRanger->GetPointCount(); nPntCnt += mvItems[0].mxTextRanger->GetPointCount();
while( nPntCnt > POLY_MAX && mvItems.size() > POLY_MIN ) while( nPntCnt > POLY_MAX && mvItems.size() > POLY_MIN )

View File

@@ -737,9 +737,8 @@ void SwTextFrame::ConnectFootnote( SwTextFootnote *pFootnote, const SwTwips nDea
if( bBrutal ) if( bBrutal )
{ {
pBoss->RemoveFootnote( pSrcFrame, pFootnote, false ); pBoss->RemoveFootnote( pSrcFrame, pFootnote, false );
SwSaveFootnoteHeight *pHeight = bEnd ? nullptr : new SwSaveFootnoteHeight( pBoss, nDeadLine ); std::unique_ptr<SwSaveFootnoteHeight> pHeight(bEnd ? nullptr : new SwSaveFootnoteHeight( pBoss, nDeadLine ));
pBoss->AppendFootnote( this, pFootnote ); pBoss->AppendFootnote( this, pFootnote );
delete pHeight;
} }
} }

View File

@@ -1968,16 +1968,16 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
aTextSize.setWidth( m_pPrinter->GetTextWidth( rInf.GetText(), aTextSize.setWidth( m_pPrinter->GetTextWidth( rInf.GetText(),
sal_Int32(rInf.GetIdx()), sal_Int32(nLn))); sal_Int32(rInf.GetIdx()), sal_Int32(nLn)));
aTextSize.setHeight( m_pPrinter->GetTextHeight() ); aTextSize.setHeight( m_pPrinter->GetTextHeight() );
long* pKernArray = new long[sal_Int32(nLn)]; std::unique_ptr<long[]> pKernArray(new long[sal_Int32(nLn)]);
CreateScrFont( *rInf.GetShell(), rInf.GetOut() ); CreateScrFont( *rInf.GetShell(), rInf.GetOut() );
if( !GetScrFont()->IsSameInstance( rInf.GetOut().GetFont() ) ) if( !GetScrFont()->IsSameInstance( rInf.GetOut().GetFont() ) )
rInf.GetOut().SetFont( *m_pScrFont ); rInf.GetOut().SetFont( *m_pScrFont );
long nScrPos; long nScrPos;
m_pPrinter->GetTextArray(rInf.GetText(), pKernArray, m_pPrinter->GetTextArray(rInf.GetText(), pKernArray.get(),
sal_Int32(rInf.GetIdx()), sal_Int32(nLn)); sal_Int32(rInf.GetIdx()), sal_Int32(nLn));
if( bCompress ) if( bCompress )
rInf.SetKanaDiff( rInf.GetScriptInfo()->Compress( pKernArray, rInf.SetKanaDiff( rInf.GetScriptInfo()->Compress( pKernArray.get(),
rInf.GetIdx(), nLn, rInf.GetKanaComp(), rInf.GetIdx(), nLn, rInf.GetKanaComp(),
static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()) ,lcl_IsFullstopCentered( rInf.GetOut() ) ) ); static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()) ,lcl_IsFullstopCentered( rInf.GetOut() ) ) );
else else
@@ -2027,7 +2027,7 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
} }
} }
delete[] pKernArray; pKernArray.reset();
aTextSize.setWidth( nScrPos ); aTextSize.setWidth( nScrPos );
} }
else else

View File

@@ -486,9 +486,9 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
rDo.SetCapInf( aCapInf ); rDo.SetCapInf( aCapInf );
SwFntObj *pOldLast = pLastFont; SwFntObj *pOldLast = pLastFont;
SwFntAccess *pBigFontAccess = nullptr; std::unique_ptr<SwFntAccess> pBigFontAccess;
SwFntObj *pBigFont; SwFntObj *pBigFont;
SwFntAccess *pSpaceFontAccess = nullptr; std::unique_ptr<SwFntAccess> pSpaceFontAccess;
SwFntObj *pSpaceFont = nullptr; SwFntObj *pSpaceFont = nullptr;
const void* nFontCacheId2 = nullptr; const void* nFontCacheId2 = nullptr;
@@ -508,8 +508,8 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
if ( bWordWise ) if ( bWordWise )
{ {
aFont.SetWordLineMode( false ); aFont.SetWordLineMode( false );
pSpaceFontAccess = new SwFntAccess( nFontCacheId2, nIndex2, &aFont, pSpaceFontAccess.reset(new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
rDo.GetInf().GetShell() ); rDo.GetInf().GetShell() ));
pSpaceFont = pSpaceFontAccess->Get(); pSpaceFont = pSpaceFontAccess->Get();
} }
else else
@@ -521,8 +521,8 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
aFont.SetStrikeout( STRIKEOUT_NONE ); aFont.SetStrikeout( STRIKEOUT_NONE );
nFontCacheId2 = nullptr; nFontCacheId2 = nullptr;
nIndex2 = 0; nIndex2 = 0;
pBigFontAccess = new SwFntAccess( nFontCacheId2, nIndex2, &aFont, pBigFontAccess.reset(new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
rDo.GetInf().GetShell() ); rDo.GetInf().GetShell() ));
pBigFont = pBigFontAccess->Get(); pBigFont = pBigFontAccess->Get();
} }
else else
@@ -733,7 +733,7 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
// clean up: // clean up:
if( pBigFont != pOldLast ) if( pBigFont != pOldLast )
delete pBigFontAccess; pBigFontAccess.reset();
if( bTextLines ) if( bTextLines )
{ {
@@ -744,7 +744,7 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
static_cast<SwDoDrawCapital&>( rDo ).DrawSpace( aStartPos ); static_cast<SwDoDrawCapital&>( rDo ).DrawSpace( aStartPos );
} }
if ( bWordWise ) if ( bWordWise )
delete pSpaceFontAccess; pSpaceFontAccess.reset();
} }
pLastFont = pOldLast; pLastFont = pOldLast;
pLastFont->SetDevFont( rDo.GetInf().GetShell(), rDo.GetOut() ); pLastFont->SetDevFont( rDo.GetInf().GetShell(), rDo.GetOut() );