vcl/source/gdi/impglyphitem.cxx |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

New commits:
commit 7b7d2f4a3e96e771e125c95a7d262b20f6dc9ecc
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Wed Apr 27 22:40:43 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Thu Apr 28 07:21:46 2022 +0200

    don't cut a glyph subset inside a composed glyph
    
    A glyph may may composed from several characters, when asked to make
    a glyph subset for a character range, make sure the end of the range
    is not inside this character group.
    
    Change-Id: I41d82b432858a87e103dcb0d2fac6a11f25a32dc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133530
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx
index 5896d5bfeb7c..8ea80293ee08 100644
--- a/vcl/source/gdi/impglyphitem.cxx
+++ b/vcl/source/gdi/impglyphitem.cxx
@@ -113,7 +113,13 @@ SalLayoutGlyphsImpl* 
SalLayoutGlyphsImpl::cloneCharRange(sal_Int32 index, sal_In
     // that's how it's computed in GenericSalLayout::LayoutText().
     DevicePoint zeroPoint = pos->linearPos() - DevicePoint(pos->xOffset(), 
pos->yOffset());
     // Add and adjust all glyphs until the given length.
-    while (pos != end() && pos->charPos() < index + length)
+    // The check is written as 'charPos + charCount <= index + length' rather 
than
+    // 'charPos < index + length' to make sure we include complete glyphs. If 
a glyph is composed
+    // from several characters, we should not cut in the middle of those 
characters, so this
+    // checks the glyph is entirely in the given character range. If it is 
not, this will end
+    // the loop and the later 'pos->charPos() != endPos' check will fail and 
bail out.
+    // CppunitTest_sw_layoutwriter's testCombiningCharacterCursorPosition 
would fail without this.
+    while (pos != end() && pos->charPos() + pos->charCount() <= index + length)
     {
         if (pos->IsRTLGlyph())
             return nullptr; // Don't mix RTL and non-RTL runs.

Reply via email to