diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2017-06-11 00:24:36 +0200 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2017-06-12 11:58:58 +0200 |
commit | 3b05c3b4b4b6c3891b4b7e88d91889cf327a34a8 (patch) | |
tree | 2ddd80983fe3affc1d2bd15b82b237b3865d4730 /vcl | |
parent | 23cf6dbe4d35d0d9beeaa2193247c6f67a869c66 (diff) |
Refactor create layout cache in status bar
Create SalLayout in StatusBar instead of getting cache through output
parameter.
Pass cache as a constant to the output device afterwards.
Results in a more readable code, with more evident memory management.
Change-Id: I4f949ea8f390b31379f661d611a183ceb3d91c25
Reviewed-on: https://gerrit.libreoffice.org/38651
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/outdev/text.cxx | 60 | ||||
-rw-r--r-- | vcl/source/window/status.cxx | 32 |
2 files changed, 39 insertions, 53 deletions
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index 3937af3eb543..150fd828887d 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -803,7 +803,7 @@ void OutputDevice::SetTextAlign( TextAlign eAlign ) void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen, MetricVector* pVector, OUString* pDisplayText, - SalLayout** pLayoutCache + SalLayout* pLayoutCache ) { assert(!is_double_buffered_window()); @@ -875,10 +875,10 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, if ( !IsDeviceOutputNecessary() || pVector ) return; - if(mpFontInstance && pLayoutCache) + if(mpFontInstance) // do not use cache with modified string - if( mpFontInstance->mpConversion ) - *pLayoutCache = nullptr; + if(mpFontInstance->mpConversion) + pLayoutCache = nullptr; // without cache if(!pLayoutCache) @@ -893,29 +893,23 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, } else { - // with cache, but there is no cache yet - if(!*pLayoutCache) - *pLayoutCache = ImplLayout(rStr, nIndex, nLen, rStartPt); + // initialize font if needed + if( mbNewFont ) + if( !ImplNewFont() ) + return; + if( mbInitFont ) + InitFont(); - if( *pLayoutCache ) - { - // initialize font if needed - if( mbNewFont ) - if( !ImplNewFont() ) - return; - if( mbInitFont ) - InitFont(); - - OUString aStrModifiable = rStr; - ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStrModifiable, nIndex, nLen, - 0, nullptr); - - // position, justify, etc. the layout - (*pLayoutCache)->AdjustLayout( aLayoutArgs ); - (*pLayoutCache)->DrawBase() = ImplLogicToDevicePixel( rStartPt ); - - ImplDrawText( **pLayoutCache ); - } + + OUString aStrModifiable = rStr; + ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStrModifiable, nIndex, nLen, + 0, nullptr); + + // position, justify, etc. the layout + pLayoutCache->AdjustLayout( aLayoutArgs ); + pLayoutCache->DrawBase() = ImplLogicToDevicePixel( rStartPt ); + + ImplDrawText( *pLayoutCache ); } if( mpAlphaVDev ) @@ -924,7 +918,7 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, long OutputDevice::GetTextWidth( const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen, vcl::TextLayoutCache const*const pLayoutCache, - SalLayout** pSalLayoutCache) const + SalLayout const*const pSalLayoutCache) const { long nWidth = GetTextArray( rStr, nullptr, nIndex, @@ -992,7 +986,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr, long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, sal_Int32 nIndex, sal_Int32 nLen, vcl::TextLayoutCache const*const pLayoutCache, - SalLayout** pSalLayoutCache) const + SalLayout const*const pSalLayoutCache) const { if( nIndex >= rStr.getLength() ) return 0; // TODO: this looks like a buggy caller? @@ -1002,9 +996,9 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, nLen = rStr.getLength() - nIndex; } - SalLayout* pSalLayout = pSalLayoutCache ? *pSalLayoutCache : nullptr; + const SalLayout* pSalLayout = pSalLayoutCache; - if(!pSalLayout) + if(!pSalLayoutCache) { // do layout pSalLayout = ImplLayout(rStr, nIndex, nLen, @@ -1023,12 +1017,6 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, } return 0; } - - // update cache if used - if(pSalLayoutCache) - { - *pSalLayoutCache = pSalLayout; - } } #if VCL_FLOAT_DEVICE_PIXEL diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx index c4f44d8e1a4b..099ac900d886 100644 --- a/vcl/source/window/status.cxx +++ b/vcl/source/window/status.cxx @@ -373,11 +373,17 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen } SalLayout* pLayoutCache = pItem->mxLayoutCache.get(); - Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,&pLayoutCache), rRenderContext.GetTextHeight()); - // update cache if necessary - if(pLayoutCache != pItem->mxLayoutCache.get() ) - pItem->mxLayoutCache.reset(pLayoutCache); + if(!pLayoutCache) + { + pLayoutCache = rRenderContext.ImplLayout(pItem->maText, 0, -1); + + // update cache + if(pLayoutCache) + pItem->mxLayoutCache.reset(pLayoutCache); + } + + Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,pLayoutCache), rRenderContext.GetTextHeight()); Point aTextPos = ImplGetItemTextPos(aTextRectSize, aTextSize, pItem->mnBits); @@ -387,7 +393,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen aTextPos, pItem->maText, 0, -1, nullptr, nullptr, - &pLayoutCache ); + pLayoutCache ); } else { @@ -397,13 +403,9 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen aTextPos, pItem->maText, 0, -1, nullptr, nullptr, - &pLayoutCache ); + pLayoutCache ); } - // update cache if necessary - if(pLayoutCache != pItem->mxLayoutCache.get() ) - pItem->mxLayoutCache.reset(pLayoutCache); - // call DrawItem if necessary if (pItem->mnBits & StatusBarItemBits::UserDraw) { @@ -1163,20 +1165,16 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText ) if ( pItem->maText != rText ) { - // invalidate cache - pItem->mxLayoutCache.reset(); - pItem->maText = rText; // adjust item width - see also DataChanged() long nFudge = GetTextHeight()/4; - SalLayout* pLayoutCache = nullptr; - - long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,&pLayoutCache ) + nFudge; + SalLayout* pSalLayout = ImplLayout(pItem->maText,0,-1); + long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pSalLayout ) + nFudge; // update cache - pItem->mxLayoutCache.reset(pLayoutCache); + pItem->mxLayoutCache.reset(pSalLayout); if( (nWidth > pItem->mnWidth + STATUSBAR_OFFSET) || ((nWidth < pItem->mnWidth) && (mnDX - STATUSBAR_OFFSET) < mnItemsWidth )) |