vcl/qa/cppunit/complextext.cxx |    5 ++---
 vcl/source/gdi/sallayout.cxx   |    9 +++------
 2 files changed, 5 insertions(+), 9 deletions(-)

New commits:
commit ce7c1c608fa99c86c8f2380cd8b82d02123f514e
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Wed Aug 31 07:07:54 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Wed Aug 31 08:47:16 2022 +0200

    vcl: Fix GenericSalLayout::GetTextWidth()
    
    There was a mismatch between text width calculated in
    GenericSalLayout::GetTextWidth() and last glyph width calculated in
    GenericSalLayout::GetCharWidths(), with the later using the sum of
    GlyphItem::newWidth() and the later using the GlyphItem::linearPos(),
    but linearPos() includes glyph offset and it should be subtracted from
    it to get actual width and we were subtracting it in the wrong place.
    
    I fixed where the xOffset() is subtracted but didn’t change it to simply
    sum GlyphItem::newWidth() though that is simpler so that we continue to
    test that linearPos() is correctly set.
    
    Change-Id: I40d6be6d1c82ed0ca1ce04bf792adf72faa0d787
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139071
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index fb25459bb737..d052564d638b 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -287,9 +287,8 @@ void VclComplexTextTest::testCaret()
     CPPUNIT_ASSERT_EQUAL(aCharWidths[6], aCharWidths[7]);
     CPPUNIT_ASSERT_EQUAL(aCharWidths[8], aCharWidths[9]);
     CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
-    // FIXME: this should be 353, and the next assert should be true as well.
-    CPPUNIT_ASSERT_EQUAL(tools::Long(388), nTextWidth2);
-    //CPPUNIT_ASSERT_EQUAL(nTextWidth, nTextWidth2);
+    CPPUNIT_ASSERT_EQUAL(tools::Long(353), nTextWidth2);
+    CPPUNIT_ASSERT_EQUAL(nTextWidth, nTextWidth2);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(nTextWidth), aCharWidths.back());
 
     // B. LTR text
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 6d22b302b6c5..de5385f93ac2 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -286,12 +286,9 @@ DeviceCoordinate GenericSalLayout::GetTextWidth() const
     for (auto const& aGlyphItem : m_GlyphItems)
     {
         // update the text extent with the glyph extent
-        DeviceCoordinate nXPos = aGlyphItem.linearPos().getX();
-        if( nMinPos > nXPos )
-            nMinPos = nXPos;
-        nXPos += aGlyphItem.newWidth() - aGlyphItem.xOffset();
-        if( nMaxPos < nXPos )
-            nMaxPos = nXPos;
+        DeviceCoordinate nXPos = aGlyphItem.linearPos().getX() - 
aGlyphItem.xOffset();
+        nMinPos = std::min(nMinPos, nXPos);
+        nMaxPos = std::max(nMaxPos, nXPos + aGlyphItem.newWidth());
     }
 
     DeviceCoordinate nWidth = nMaxPos - nMinPos;

Reply via email to