From 455e21727572d6ac123781be292053cf13c68237 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 17 May 2013 20:49:27 +0200 Subject: Fix Core Text GetCaretPositions() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- vcl/coretext/salcoretextlayout.cxx | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'vcl') 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); } } -- cgit