diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-17 13:40:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-11-14 10:19:32 +0100 |
commit | 8f54136caa786523fd224f6c98fc8e7c45cd805d (patch) | |
tree | e77e4cba4e281a32e2bee5fd6a10d43ae6c7a360 /vcl/source/outdev | |
parent | b5344daa0cfc31cf187832261651e5490b19d922 (diff) |
use std::unique_ptr for SalLayout
to make the ownership passing around more obvious
Change-Id: I147ec6d9cfe7566cf3600685e0730ed741c2d90d
Reviewed-on: https://gerrit.libreoffice.org/43454
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/outdev')
-rw-r--r-- | vcl/source/outdev/font.cxx | 20 | ||||
-rw-r--r-- | vcl/source/outdev/text.cxx | 61 | ||||
-rw-r--r-- | vcl/source/outdev/textline.cxx | 4 |
3 files changed, 30 insertions, 55 deletions
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx index c018113a9ff5..2a5d88852fb2 100644 --- a/vcl/source/outdev/font.cxx +++ b/vcl/source/outdev/font.cxx @@ -1295,7 +1295,7 @@ void OutputDevice::ImplDrawEmphasisMarks( SalLayout& rSalLayout ) mpMetaFile = pOldMetaFile; } -SalLayout* OutputDevice::getFallbackFont( +std::unique_ptr<SalLayout> OutputDevice::getFallbackFont( FontSelectPattern &rFontSelData, int nFallbackLevel, ImplLayoutArgs& rLayoutArgs) const { @@ -1307,7 +1307,7 @@ SalLayout* OutputDevice::getFallbackFont( mpGraphics->SetFont( &rFontSelData, nFallbackLevel ); rLayoutArgs.ResetPos(); - SalLayout* pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel ); + std::unique_ptr<SalLayout> pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel ); if (!pFallback) return nullptr; @@ -1315,7 +1315,6 @@ SalLayout* OutputDevice::getFallbackFont( if (!pFallback->LayoutText(rLayoutArgs)) { // there is no need for a font that couldn't resolve anything - delete pFallback; return nullptr; } @@ -1324,7 +1323,7 @@ SalLayout* OutputDevice::getFallbackFont( return pFallback; } -SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLayoutArgs& rLayoutArgs ) const +std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_ptr<SalLayout> pSalLayout, ImplLayoutArgs& rLayoutArgs ) const { // This function relies on a valid mpFontInstance, if it doesn't exist bail out // - we'd have crashed later on anyway. At least here we can catch the error in debug @@ -1337,7 +1336,7 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay } // prepare multi level glyph fallback - MultiSalLayout* pMultiSalLayout = nullptr; + std::unique_ptr<MultiSalLayout> pMultiSalLayout; ImplLayoutRuns aLayoutRuns = rLayoutArgs.maRuns; rLayoutArgs.PrepareFallback(); rLayoutArgs.mnFlags |= SalLayoutFlags::ForFallback; @@ -1382,13 +1381,13 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay } // create and add glyph fallback layout to multilayout - SalLayout* pFallback = getFallbackFont(aFontSelData, + std::unique_ptr<SalLayout> pFallback = getFallbackFont(aFontSelData, nFallbackLevel, rLayoutArgs); if (pFallback) { if( !pMultiSalLayout ) - pMultiSalLayout = new MultiSalLayout( *pSalLayout ); - pMultiSalLayout->AddFallback( *pFallback, + pMultiSalLayout.reset( new MultiSalLayout( std::move(pSalLayout) ) ); + pMultiSalLayout->AddFallback( std::move(pFallback), rLayoutArgs.maRuns, aFontSelData.mpFontData ); if (nFallbackLevel == MAX_FALLBACK-1) pMultiSalLayout->SetIncomplete(true); @@ -1402,7 +1401,7 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay } if( pMultiSalLayout && pMultiSalLayout->LayoutText( rLayoutArgs ) ) - pSalLayout = pMultiSalLayout; + pSalLayout = std::move(pMultiSalLayout); // restore orig font settings pSalLayout->InitFont(); @@ -1426,7 +1425,7 @@ sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt, sal_Int32* pKashidaPosDropped ) const { // do layout - SalLayout* pSalLayout = ImplLayout( rTxt, nIdx, nLen ); + std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rTxt, nIdx, nLen ); if( !pSalLayout ) return 0; sal_Int32 nDropped = 0; @@ -1438,7 +1437,6 @@ sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt, ++nDropped; } } - delete pSalLayout; return nDropped; } diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index 7b1a8f957d38..1d93f7730aae 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -864,13 +864,11 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, // without cache if(!pLayoutCache) { - SalLayout* pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt); + std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt); if(pSalLayout) { ImplDrawText( *pSalLayout ); - delete pSalLayout; } - } else { @@ -953,11 +951,10 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr, if( mbOutputClipped ) return; - SalLayout* pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags); + std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags); if( pSalLayout ) { ImplDrawText( *pSalLayout ); - delete pSalLayout; } if( mpAlphaVDev ) @@ -977,13 +974,15 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, nLen = rStr.getLength() - nIndex; } + std::unique_ptr<SalLayout> xSalLayout; const SalLayout* pSalLayout = pSalLayoutCache; if(!pSalLayoutCache) { // do layout - pSalLayout = ImplLayout(rStr, nIndex, nLen, + xSalLayout = ImplLayout(rStr, nIndex, nLen, Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache); + pSalLayout = xSalLayout.get(); if( !pSalLayout ) { // The caller expects this to init the elements of pDXAry. @@ -1009,9 +1008,6 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray.get() ); int nWidthFactor = pSalLayout->GetUnitsPerPixel(); - if(!pSalLayoutCache) - delete pSalLayout; - // convert virtual char widths to virtual absolute positions if( pDXPixelArray ) { @@ -1056,9 +1052,6 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, long nWidth = pSalLayout->FillDXArray( pDXAry ); int nWidthFactor = pSalLayout->GetUnitsPerPixel(); - if(!pSalLayoutCache) - delete pSalLayout; - // convert virtual char widths to virtual absolute positions if( pDXAry ) for( int i = 1; i < nLen; ++i ) @@ -1094,14 +1087,13 @@ bool OutputDevice::GetCaretPositions( const OUString& rStr, long* pCaretXArray, nLen = rStr.getLength() - nIndex; // layout complex text - SalLayout* pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0) ); + std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0) ); if( !pSalLayout ) return false; int nWidthFactor = pSalLayout->GetUnitsPerPixel(); pSalLayout->GetCaretPositions( 2*nLen, pCaretXArray ); long nWidth = pSalLayout->GetTextWidth(); - delete pSalLayout; // fixup unknown caret positions int i; @@ -1157,11 +1149,10 @@ void OutputDevice::DrawStretchText( const Point& rStartPt, sal_uLong nWidth, if ( !IsDeviceOutputNecessary() ) return; - SalLayout* pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, nWidth); + std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, nWidth); if( pSalLayout ) { ImplDrawText( *pSalLayout ); - delete pSalLayout; } if( mpAlphaVDev ) @@ -1258,7 +1249,7 @@ ImplLayoutArgs OutputDevice::ImplPrepareLayoutArgs( OUString& rStr, return aLayoutArgs; } -SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, +std::unique_ptr<SalLayout> OutputDevice::ImplLayout(const OUString& rOrigStr, sal_Int32 nMinIndex, sal_Int32 nLen, const Point& rLogicalPos, long nLogicalWidth, const long* pDXArray, SalLayoutFlags flags, @@ -1334,13 +1325,12 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, nPixelWidth, pDXPixelArray, flags, pLayoutCache); // get matching layout object for base font - SalLayout* pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 ); + std::unique_ptr<SalLayout> pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 ); // layout text if( pSalLayout && !pSalLayout->LayoutText( aLayoutArgs ) ) { - delete pSalLayout; - pSalLayout = nullptr; + pSalLayout.reset(); } if( !pSalLayout ) @@ -1349,7 +1339,7 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, // do glyph fallback if needed // #105768# avoid fallback for very small font sizes if (aLayoutArgs.NeedFallback() && mpFontInstance->maFontSelData.mnHeight >= 3) - pSalLayout = ImplGlyphFallbackLayout(pSalLayout, aLayoutArgs); + pSalLayout = ImplGlyphFallbackLayout(std::move(pSalLayout), aLayoutArgs); // position, justify, etc. the layout pSalLayout->AdjustLayout( aLayoutArgs ); @@ -1379,12 +1369,11 @@ std::shared_ptr<vcl::TextLayoutCache> OutputDevice::CreateTextLayoutCache( ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs(copyBecausePrepareModifiesIt, 0, rString.getLength(), 0, nullptr); - SalLayout *const pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 ); + std::unique_ptr<SalLayout> pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 ); if (!pSalLayout) return nullptr; std::shared_ptr<vcl::TextLayoutCache> const ret( pSalLayout->CreateTextLayoutCache(copyBecausePrepareModifiesIt)); - delete pSalLayout; return ret; } @@ -1404,7 +1393,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth, long nCharExtra, vcl::TextLayoutCache const*const pLayoutCache) const { - SalLayout *const pSalLayout = ImplLayout( rStr, nIndex, nLen, + std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache); sal_Int32 nRetVal = -1; if( pSalLayout ) @@ -1424,8 +1413,6 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth, nExtraPixelWidth = LogicWidthToDeviceCoordinate( nCharExtra ); } nRetVal = pSalLayout->GetTextBreak( nTextPixelWidth, nExtraPixelWidth, nSubPixelFactor ); - - delete pSalLayout; } return nRetVal; @@ -1439,7 +1426,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth, { rHyphenPos = -1; - SalLayout *const pSalLayout = ImplLayout( rStr, nIndex, nLen, + std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache); sal_Int32 nRetVal = -1; if( pSalLayout ) @@ -1465,12 +1452,11 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth, // calculate hyphenated break position OUString aHyphenStr(nHyphenChar); - SalLayout* pHyphenLayout = ImplLayout( aHyphenStr, 0, 1 ); + std::unique_ptr<SalLayout> pHyphenLayout = ImplLayout( aHyphenStr, 0, 1 ); if( pHyphenLayout ) { // calculate subpixel width of hyphenation character long nHyphenPixelWidth = pHyphenLayout->GetTextWidth() * nSubPixelFactor; - delete pHyphenLayout; // calculate hyphenated break position nTextPixelWidth -= nHyphenPixelWidth; @@ -1482,8 +1468,6 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth, if( rHyphenPos > nRetVal ) rHyphenPos = nRetVal; } - - delete pSalLayout; } return nRetVal; @@ -2328,7 +2312,7 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c if ( !IsDeviceOutputNecessary() ) return aSysLayoutData; - SalLayout* pLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry); + std::unique_ptr<SalLayout> pLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry); if ( !pLayout ) return aSysLayoutData; @@ -2350,8 +2334,6 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c // Get font data aSysLayoutData.orientation = pLayout->GetOrientation(); - delete pLayout; - return aSysLayoutData; } @@ -2363,7 +2345,7 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect, bool bRet = false; rRect.SetEmpty(); - SalLayout* pSalLayout = nullptr; + std::unique_ptr<SalLayout> pSalLayout; const Point aPoint; // calculate offset when nBase!=nIndex long nXOffset = 0; @@ -2376,7 +2358,6 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect, { nXOffset = pSalLayout->GetTextWidth(); nXOffset /= pSalLayout->GetUnitsPerPixel(); - delete pSalLayout; // TODO: fix offset calculation for Bidi case if( nBase < nIndex) nXOffset = -nXOffset; @@ -2413,8 +2394,6 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect, if( mbMap ) rRect += Point( maMapRes.mnMapOfsX, maMapRes.mnMapOfsY ); } - - delete pSalLayout; } return bRet; @@ -2450,7 +2429,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector, const_cast<OutputDevice&>(*this).mbNewFont = true; } - SalLayout* pSalLayout = nullptr; + std::unique_ptr<SalLayout> pSalLayout; // calculate offset when nBase!=nIndex long nXOffset = 0; @@ -2462,7 +2441,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector, if( pSalLayout ) { nXOffset = pSalLayout->GetTextWidth(); - delete pSalLayout; + pSalLayout.reset(); // TODO: fix offset calculation for Bidi case if( nBase > nIndex) nXOffset = -nXOffset; @@ -2500,7 +2479,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector, } } - delete pSalLayout; + pSalLayout.reset(); } if( bOldMap ) diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx index 513e22f09aa6..7d1d44075823 100644 --- a/vcl/source/outdev/textline.cxx +++ b/vcl/source/outdev/textline.cxx @@ -600,11 +600,10 @@ void OutputDevice::ImplDrawStrikeoutChar( long nBaseX, long nBaseY, // calculate approximation of strikeout atom size long nStrikeoutWidth = 0; - SalLayout* pLayout = ImplLayout( aStrikeoutTest, 0, nTestStrLen ); + std::unique_ptr<SalLayout> pLayout = ImplLayout( aStrikeoutTest, 0, nTestStrLen ); if( pLayout ) { nStrikeoutWidth = pLayout->GetTextWidth() / (nTestStrLen * pLayout->GetUnitsPerPixel()); - delete pLayout; } if( nStrikeoutWidth <= 0 ) // sanity check return; @@ -664,7 +663,6 @@ void OutputDevice::ImplDrawStrikeoutChar( long nBaseX, long nBaseY, pLayout->DrawText( *mpGraphics ); - delete pLayout; Pop(); SetTextColor( aOldColor ); |