include/sfx2/charwin.hxx        |    1 -
 sfx2/source/control/charwin.cxx |   15 +++++++--------
 2 files changed, 7 insertions(+), 9 deletions(-)

New commits:
commit 92b0f88a1f6eca12f4b5df280ba60e6153bf6520
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon Dec 15 12:53:48 2025 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Dec 16 09:21:07 2025 +0100

    tdf#168594 sfx2: Move y pos calculation to SvxCharView::Paint
    
    Move the logic to calculate the y position from
    SvxCharView::UpdateFont to SvxCharView::Paint
    where this is used when drawing the text.
    
    This also means its sufficient to have a local
    variable, so use such a one and drop SvxCharView::mnY.
    
    Change-Id: Ic8ab0cc773e59e9f2b016924a0cf63a871ed9706
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195685
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx
index a449042edff4..dc16b672d774 100644
--- a/include/sfx2/charwin.hxx
+++ b/include/sfx2/charwin.hxx
@@ -28,7 +28,6 @@ class SAL_DLLPUBLIC_RTTI SvxCharView final : public 
weld::CustomWidgetController
 {
 private:
     VclPtr<VirtualDevice> mxVirDev;
-    tools::Long            mnY;
     vcl::Font       maFont;
     bool            maHasInsert;
     OUString        m_sText;
diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx
index b0673f49ff6b..10f5d08dcace 100644
--- a/sfx2/source/control/charwin.cxx
+++ b/sfx2/source/control/charwin.cxx
@@ -37,7 +37,6 @@ using namespace com::sun::star;
 
 SvxCharView::SvxCharView(const VclPtr<VirtualDevice>& rVirDev)
     : mxVirDev(rVirDev)
-    , mnY(0)
     , maHasInsert(true)
 {
 }
@@ -189,6 +188,11 @@ void SvxCharView::Paint(vcl::RenderContext& 
rRenderContext, const tools::Rectang
     Size aFontSize(aOrigFont.GetFontSize());
     ::tools::Rectangle aBoundRect;
 
+    mxVirDev->Push(PUSH_ALLFONT);
+    mxVirDev->SetFont(maFont);
+    tools::Long nY = (nWinHeight - mxVirDev->GetTextHeight()) / 2;
+    mxVirDev->Pop();
+
     for (tools::Long nFontHeight = aFontSize.Height(); nFontHeight > 0; 
nFontHeight -= 1)
     {
         if (!rRenderContext.GetTextBoundRect(aBoundRect, aText) || 
aBoundRect.IsEmpty())
@@ -205,11 +209,11 @@ void SvxCharView::Paint(vcl::RenderContext& 
rRenderContext, const tools::Rectang
         aFontSize.setHeight(nFontHeight);
         aFont.SetFontSize(aFontSize);
         rRenderContext.SetFont(aFont);
-        mnY = (nWinHeight - rRenderContext.GetTextHeight()) / 2;
+        nY = (nWinHeight - rRenderContext.GetTextHeight()) / 2;
         bShrankFont = true;
     }
 
-    Point aPoint(2, mnY);
+    Point aPoint(2, nY);
 
     if (!bGotBoundary)
         aPoint.setX((aSize.Width() - rRenderContext.GetTextWidth(aText)) / 2);
@@ -276,11 +280,6 @@ void SvxCharView::UpdateFont(const OUString& 
rFontFamilyName)
     maFont.SetFontSize(mxVirDev->PixelToLogic(Size(0, nWinHeight / 2)));
     maFont.SetTransparent(true);
 
-    mxVirDev->Push(PUSH_ALLFONT);
-    mxVirDev->SetFont(maFont);
-    mnY = (nWinHeight - mxVirDev->GetTextHeight()) / 2;
-    mxVirDev->Pop();
-
     Invalidate();
 }
 

Reply via email to