diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-01-18 15:35:47 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-01-19 15:20:41 +0000 |
commit | b05f85a3fd247baea4f2dd975f2178e04ea5dd6a (patch) | |
tree | 025f35dd38753c5e14112231657956339829004d /vcl/source/control | |
parent | baf09e572b377f569b00e61c10710787b1c151ba (diff) |
Resolves: tdf#98593 buttons in writer show different text at different zooms
The DrawControlText always renders with a reference device positions but
we pass in a rectangle which is derived a different way.
So, add a GetControlTextRect which operates on the same reference
device as DrawControlText so the rectangles match
The rectangle is mapped from pixels to logic and back from logic
to pixel, so add an argument to store the logic size from
GetControlTextRect and re-use it without conversion on the cases
where we pass back the original rectangle
zooming in/out on the button in writer is now stable wrt text shown at all zoom
levels
Change-Id: Ic581eca67d0ff265e2753ab8b6c40e8fca7e6ae4
Reviewed-on: https://gerrit.libreoffice.org/33277
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit db9ef688edd86b31606e0dd6df6a77732faca49b)
change DrawControlText to return new rect rather than change old one
Change-Id: Id5c80ff263e429d4239a844db216e87a656edb2e
(cherry picked from commit bc6479e92b56df742dd7339d337ffc78d2f9e4a1)
Ref...DeviceTextLayout::GetTextArray is only called by Ref...DeviceTextLayout
so set it as private to de-confuse this a little
Change-Id: Idde7f78a767227cc2d52e417b6c39d12e1339745
(cherry picked from commit 3d002fdb8738d9bbc9b04c0270510e349bd58149)
Reviewed-on: https://gerrit.libreoffice.org/33281
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'vcl/source/control')
-rw-r--r-- | vcl/source/control/button.cxx | 11 | ||||
-rw-r--r-- | vcl/source/control/ctrl.cxx | 42 | ||||
-rw-r--r-- | vcl/source/control/fixed.cxx | 4 | ||||
-rw-r--r-- | vcl/source/control/tabctrl.cxx | 4 |
4 files changed, 45 insertions, 16 deletions
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index cb0cb8b3d68e..47dc44a22564 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -286,7 +286,7 @@ void Button::ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, } else if (bDrawText && !bDrawImage && !bHasSymbol) { - DrawControlText(*pDev, aOutRect, aText, nTextStyle, nullptr, nullptr); + aOutRect = DrawControlText(*pDev, aOutRect, aText, nTextStyle, nullptr, nullptr); ImplSetFocusRect(aOutRect); rSize = aOutRect.GetSize(); @@ -300,6 +300,7 @@ void Button::ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, Size aTextSize; Size aSymbolSize; + Size aDeviceTextSize; Size aMax; Point aImagePos = rPos; Point aTextPos = rPos; @@ -359,7 +360,7 @@ void Button::ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, aRect.Bottom() -= (aImageSize.Height() + nImageSep); } - aRect = pDev->GetTextRect(aRect, aText, nTextStyle); + aRect = GetControlTextRect(*pDev, aRect, aText, nTextStyle, &aDeviceTextSize); aTextSize = aRect.GetSize(); aTSSize.Width() += aTextSize.Width(); @@ -511,9 +512,9 @@ void Button::ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, if (bDrawText) { - Rectangle aTOutRect( aTextPos, aTextSize ); - ImplSetFocusRect( aTOutRect ); - DrawControlText( *pDev, aTOutRect, aText, nTextStyle, nullptr, nullptr ); + const Rectangle aTOutRect(aTextPos, aTextSize); + ImplSetFocusRect(aTOutRect); + DrawControlText(*pDev, aTOutRect, aText, nTextStyle, nullptr, nullptr, &aDeviceTextSize); } else { diff --git a/vcl/source/control/ctrl.cxx b/vcl/source/control/ctrl.cxx index a137b432867e..bab54bbf8711 100644 --- a/vcl/source/control/ctrl.cxx +++ b/vcl/source/control/ctrl.cxx @@ -416,8 +416,8 @@ void Control::ImplInitSettings(const bool, const bool) ApplySettings(*this); } -void Control::DrawControlText( OutputDevice& _rTargetDevice, Rectangle& _io_rRect, const OUString& _rStr, - DrawTextFlags _nStyle, MetricVector* _pVector, OUString* _pDisplayText ) const +Rectangle Control::DrawControlText( OutputDevice& _rTargetDevice, const Rectangle& rRect, const OUString& _rStr, + DrawTextFlags _nStyle, MetricVector* _pVector, OUString* _pDisplayText, const Size* i_pDeviceSize ) const { OUString rPStr = _rStr; DrawTextFlags nPStyle = _nStyle; @@ -433,14 +433,42 @@ void Control::DrawControlText( OutputDevice& _rTargetDevice, Rectangle& _io_rRec if ( !mpControlData->mpReferenceDevice || ( mpControlData->mpReferenceDevice == &_rTargetDevice ) ) { - _io_rRect = _rTargetDevice.GetTextRect( _io_rRect, rPStr, nPStyle ); - _rTargetDevice.DrawText( _io_rRect, rPStr, nPStyle, _pVector, _pDisplayText ); + const Rectangle aRet = _rTargetDevice.GetTextRect(rRect, rPStr, nPStyle); + _rTargetDevice.DrawText(aRet, rPStr, nPStyle, _pVector, _pDisplayText); + return aRet; } - else + + ControlTextRenderer aRenderer( *this, _rTargetDevice, *mpControlData->mpReferenceDevice ); + return aRenderer.DrawText(rRect, rPStr, nPStyle, _pVector, _pDisplayText, i_pDeviceSize); +} + +Rectangle Control::GetControlTextRect( OutputDevice& _rTargetDevice, const Rectangle & rRect, + const OUString& _rStr, DrawTextFlags _nStyle, Size* o_pDeviceSize ) const +{ + OUString rPStr = _rStr; + DrawTextFlags nPStyle = _nStyle; + + bool accel = ImplGetSVData()->maNWFData.mbEnableAccel; + bool autoacc = ImplGetSVData()->maNWFData.mbAutoAccel; + + if (!accel || (autoacc && !mbShowAccelerator)) + { + rPStr = GetNonMnemonicString( _rStr ); + nPStyle &= ~DrawTextFlags::HideMnemonic; + } + + if ( !mpControlData->mpReferenceDevice || ( mpControlData->mpReferenceDevice == &_rTargetDevice ) ) { - ControlTextRenderer aRenderer( *this, _rTargetDevice, *mpControlData->mpReferenceDevice ); - _io_rRect = aRenderer.DrawText( _io_rRect, rPStr, nPStyle, _pVector, _pDisplayText ); + Rectangle aRet = _rTargetDevice.GetTextRect( rRect, rPStr, nPStyle ); + if (o_pDeviceSize) + { + *o_pDeviceSize = aRet.GetSize(); + } + return aRet; } + + ControlTextRenderer aRenderer( *this, _rTargetDevice, *mpControlData->mpReferenceDevice ); + return aRenderer.GetTextRect(rRect, rPStr, nPStyle, o_pDeviceSize); } Font diff --git a/vcl/source/control/fixed.cxx b/vcl/source/control/fixed.cxx index 688c7785ecb3..24c935b844c2 100644 --- a/vcl/source/control/fixed.cxx +++ b/vcl/source/control/fixed.cxx @@ -182,7 +182,7 @@ void FixedText::ImplDraw(OutputDevice* pDev, DrawFlags nDrawFlags, if( bFillLayout ) (mpControlData->mpLayoutData->m_aDisplayText).clear(); - Rectangle aRect( Rectangle( aPos, rSize ) ); + const Rectangle aRect(aPos, rSize); DrawControlText(*pDev, aRect, aText, nTextStyle, bFillLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : nullptr, bFillLayout ? &mpControlData->mpLayoutData->m_aDisplayText : nullptr); @@ -557,7 +557,7 @@ void FixedLine::ImplDraw(vcl::RenderContext& rRenderContext) if (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) nStyle |= DrawTextFlags::Mono; - DrawControlText(*this, aRect, aText, nStyle, nullptr, nullptr); + aRect = DrawControlText(*this, aRect, aText, nStyle, nullptr, nullptr); long nTop = aRect.Top() + ((aRect.GetHeight() - 1) / 2); aDecoView.DrawSeparator(Point(aRect.Right() + FIXEDLINE_TEXT_BORDER, nTop), Point(aOutSize.Width() - 1, nTop), false); diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx index 2e1635f30afc..8fee0c1a3590 100644 --- a/vcl/source/control/tabctrl.cxx +++ b/vcl/source/control/tabctrl.cxx @@ -939,8 +939,8 @@ void TabControl::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplTabItem* p Color aOldColor(rRenderContext.GetTextColor()); rRenderContext.SetTextColor(aColor); - Rectangle aOutRect(nXPos + aImageSize.Width(), nYPos, - nXPos + aImageSize.Width() + nTextWidth, nYPos + nTextHeight); + const Rectangle aOutRect(nXPos + aImageSize.Width(), nYPos, + nXPos + aImageSize.Width() + nTextWidth, nYPos + nTextHeight); DrawControlText(rRenderContext, aOutRect, pItem->maFormatText, nStyle, nullptr, nullptr); |