Comment 42 for bug 1772520

Revision history for this message
In , Khaled-n (khaled-n) wrote :

(In reply to خالد حسني from comment #23)
> Created attachment 182033 [details]
> Screencast comparing the cursor movement of ligated with unligated text
>
> I believe the problem is that LibreOffice (or writer) is measuring the text
> width in chunks to determine the cursor position, e.g. in the string
> “office” for the cursor at “o|ffice” it will measure the width of “o” to
> position the cursor, and in “of|fice” it will measure the width of “of” and
> so on. For ligatures where the width of the partial text is close enough to
> the with of the ligature component, things appear to work, but in the
> problematic cases here the difference is way off that the cursor appears to
> be jumping.
>
> See the cursor movement in the attached screencast and compare the cursor
> position when it jumps with the unligated text below it, the cursor jumps to
> exactly where the unligated glyph is.

I can confirm this is exactly what is happening, and here a quick patch:
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 146122841e7c..8389c39f54e3 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -1608,8 +1608,9 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
         if( !GetScrFont()->IsSameInstance( rInf.GetOut().GetFont() ) )
             rInf.GetOut().SetFont( *m_pScrFont );

+ sal_Int32 nLength(rInf.GetText().getLength() - sal_Int32(rInf.GetIdx()));
         GetTextArray(*m_pPrinter, rInf.GetText(), aKernArray,
- sal_Int32(rInf.GetIdx()), sal_Int32(nLn));
+ sal_Int32(rInf.GetIdx()), nLength);
     }
     else
     {

With this patch, the cursor no longer jumps, but it won’t “enter” the ligature either (i.e. it will remain at the end of the ligature for the number of letters in the ligature). We can improve this, but I’m not sure what this code is used also for and this change is certainly wrong in other situations.

Now I need someone who is familiar with these parts of Writer to guide me in untangling all of this.