[Libreoffice-commits] core.git: vcl/coretext
Khaled Hosny
khaledhosny at eglug.org
Sat May 11 13:51:35 PDT 2013
vcl/coretext/salcoretextlayout.cxx | 62 +++++++++++++++++--------------------
1 file changed, 30 insertions(+), 32 deletions(-)
New commits:
commit c049df6fdd14fdfd88ded76ac9396efa8877f2c5
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Sat May 11 21:04:45 2013 +0200
[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
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx
index 5599747..109900f 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 );
More information about the Libreoffice-commits
mailing list