diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2013-05-11 21:04:45 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2013-05-11 22:48:17 +0200 |
commit | c049df6fdd14fdfd88ded76ac9396efa8877f2c5 (patch) | |
tree | ce8ef46f821463545943d84970e058e5ee012a16 /vcl | |
parent | b9d460f18bc0144452a5fa9a4da85b5f5827d21b (diff) |
[coretext] Attempt to fix jumping lines
No more jumping and spaces between text runs are not eaten, but text
selection is still broken, as well as editing.
Change-Id: Ic9d2a6df0add20b63d6edf0ddf84b7d6f8de0983
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/coretext/salcoretextlayout.cxx | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx index 559974748bdc..109900faece4 100644 --- a/vcl/coretext/salcoretextlayout.cxx +++ b/vcl/coretext/salcoretextlayout.cxx @@ -308,34 +308,37 @@ void CoreTextLayout::DropGlyph( int /*nStart*/ ) long CoreTextLayout::FillDXArray( sal_Int32* pDXArray ) const { - // Short circuit requests which don't need full details - if( !pDXArray ) { - return GetTextWidth(); - } + if (pDXArray) + { + for (int i = 0; i < mnCharCount; i++) + pDXArray[i] = 0; - // Distribute the widths among the string elements - long width = 0; - float scale = mpStyle->GetFontStretchFactor(); - CGFloat accumulatedWidth = 0; - - std::ostringstream DXArrayInfo; - for( int i = 0; i < mnCharCount; ++i ) { - // Convert and adjust for accumulated rounding errors - accumulatedWidth += mpCharWidths[ i ]; - const long old_width = width; - width = round_to_long( accumulatedWidth * scale ); - pDXArray[i] = width - old_width; -#ifdef SAL_LOG_INFO - if ( i < 7 ) - DXArrayInfo << " " << pDXArray[i]; - else if ( i == 7 ) - DXArrayInfo << "..."; -#endif - } + CFArrayRef runs = CTLineGetGlyphRuns(mpLine); + const CFIndex nRuns = CFArrayGetCount(runs); + + for (CFIndex runIndex = 0; runIndex < nRuns; runIndex++) + { + CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runs, runIndex); + if (!run) + continue; - SAL_INFO( "vcl.coretext.layout", "FillDXArray(" << this << "):" << DXArrayInfo.str() << ", result=" << width ); + const CFIndex runGlyphCount = CTRunGetGlyphCount(run); + if (runGlyphCount) + { + CFIndex runStringIndices[runGlyphCount]; + CGSize runGlyphAdvances[runGlyphCount]; + CTRunGetStringIndices(run, CFRangeMake(0, 0), runStringIndices); + CTRunGetAdvances(run, CFRangeMake(0, 0), runGlyphAdvances); + for (int i = 0; i < runGlyphCount; i++) + { + const CFIndex charIndex = runStringIndices[i]; + pDXArray[charIndex] += runGlyphAdvances[i].width; + } + } + } + } - return width; + return GetTextWidth(); } bool CoreTextLayout::GetBoundRect( SalGraphics& rGraphics, Rectangle& rVCLRect ) const @@ -508,13 +511,8 @@ int CoreTextLayout::GetTextBreak( long nMaxWidth, long nCharExtra, int nFactor ) long CoreTextLayout::GetTextWidth() const { - CGContextRef context = mpGraphics->GetContext(); - if (!context) { - SAL_INFO( "vcl.coretext.layout", "GetTextWidth(): no context!?"); - return 0; - } - CGRect bound_rect = CTLineGetImageBounds(mpLine, context); - long w = round_to_long((bound_rect.size.width + CTLineGetTrailingWhitespaceWidth(mpLine)) * mpStyle->GetFontStretchFactor()); + double width = CTLineGetTypographicBounds(mpLine, NULL, NULL, NULL); + long w = round_to_long(width + CTLineGetTrailingWhitespaceWidth(mpLine)); SAL_INFO( "vcl.coretext.layout", "GetTextWidth(" << this << ") returning " << w ); |