summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2013-05-17 20:49:27 +0200
committerKhaled Hosny <khaledhosny@eglug.org>2013-05-18 00:35:52 +0200
commit455e21727572d6ac123781be292053cf13c68237 (patch)
treedfecdfc7a47a64833687c29965b92fbe691b9076 /vcl
parent0ac4451161f404665f35d2b3c82a507f8238bb14 (diff)
Fix Core Text GetCaretPositions()
The secondary caret is a special caret that is inserted when the text changes its direction e.g. between an RTL and LTR segments, not whatever who wrote this code thought it is. This should now be more or less the same as ATSUI version (for better or worse), though it probably makes no difference anyway since GetCaretPositions(), despite its name, is *not* used for determining caret positions but only for drawing mnemonic underlines, and we don’t draw any menus by ourselves on Mac. While at it, adopt variable naming used in the rest of the code (not the spacing, though. Why any sane person would want no space before opening parenthesis and space after it!). Change-Id: I3e8d1db33c899d0c69f65b57f0a52d10cbed1025
Diffstat (limited to 'vcl')
-rw-r--r--vcl/coretext/salcoretextlayout.cxx31
1 files changed, 18 insertions, 13 deletions
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx
index f1944be556c8..03750bc1e6d2 100644
--- a/vcl/coretext/salcoretextlayout.cxx
+++ b/vcl/coretext/salcoretextlayout.cxx
@@ -373,20 +373,25 @@ bool CoreTextLayout::GetBoundRect( SalGraphics& rGraphics, Rectangle& rVCLRect )
return true;
}
-void CoreTextLayout::GetCaretPositions( int max_index, sal_Int32* caret_position ) const
+void CoreTextLayout::GetCaretPositions(int nMaxIndex, sal_Int32* pCaretXArray) const
{
- SAL_INFO( "vcl.coretext.layout", "GetCaretPositions(" << this << ",max_index=" << max_index << ")" );
-
- int local_max = max_index < mnCharCount * 2 ? max_index : mnCharCount;
- for( int i = 0 ; i < max_index - 1; i+=2 ) {
- CGFloat primary, secondary;
- primary = CTLineGetOffsetForStringIndex(mpLine, i >> 1, &secondary);
- caret_position[i] = round_to_long(mnBaseAdvance + primary);
- caret_position[i+1] = round_to_long(mnBaseAdvance + secondary);
- i += 2;
- }
- for( int i = local_max ; i < max_index ; ++i ) {
- caret_position[i] = -1;
+ SAL_INFO( "vcl.coretext.layout", "GetCaretPositions(" << this << ",nMaxIndex=" << nMaxIndex << ")" );
+
+ // initialize the caret positions
+ for (int i = 0; i < nMaxIndex; ++i)
+ pCaretXArray[i] = -1;
+
+ for (int i = 0 ; i < mnCharCount; i++)
+ {
+ CGFloat fPrimary, fSecondary;
+ fPrimary = CTLineGetOffsetForStringIndex(mpLine, i, &fSecondary);
+ // update previous trailing position
+ if (i > 0)
+ pCaretXArray[2*i-1] = round_to_long(mnBaseAdvance + fPrimary);
+ // update current leading position
+ if (2*i >= nMaxIndex)
+ break;
+ pCaretXArray[2*i+0] = round_to_long(mnBaseAdvance + fPrimary);
}
}