From 50977ad9ce8767562903cacf6084323ab4a21202 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 8 Apr 2013 16:47:03 +0300 Subject: More fixes to the CoreText code Disregard trailing whitespace from the target width when justifying. Justifying can change the number of glyps (especially with complex scripts). Now it works much better than before. Still a small amount of character dance. Change-Id: I7ca87e6c767ada257cc072d1dfbbe3f7d4354e42 --- vcl/coretext/salcoretextlayout.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx index 4dd4ff469d16..6832bdb08fe6 100644 --- a/vcl/coretext/salcoretextlayout.cxx +++ b/vcl/coretext/salcoretextlayout.cxx @@ -165,15 +165,19 @@ void CoreTextLayout::ApplyDXArray( ImplLayoutArgs& rArgs ) void CoreTextLayout::Justify( long nNewWidth ) { - CTLineRef justifiedLine = CTLineCreateJustifiedLine( mpLine, 1.0, nNewWidth ); + CTLineRef justifiedLine = CTLineCreateJustifiedLine( mpLine, 1.0, nNewWidth - CTLineGetTrailingWhitespaceWidth( mpLine ) ); if ( !justifiedLine ) { - SAL_INFO( "vcl.coretext.layout", "ApplyDXArray(): CTLineCreateJustifiedLine() failed" ); + SAL_INFO( "vcl.coretext.layout", "Justify(): CTLineCreateJustifiedLine() failed" ); } else { CFRelease( mpLine ); mpLine = justifiedLine; + // Justification can change the number of glyphs! + int oldGLyphCount = mnGlyphCount; + mnGlyphCount = CTLineGetGlyphCount( mpLine ); + if ( mnGlyphCount != oldGLyphCount ) + SAL_INFO( "vcl.coretext.layout", " glyph count changed, mnGlyphCount=" << mnGlyphCount ); + GetMeasurements(); } - - GetMeasurements(); } void CoreTextLayout::InvalidateMeasurements() @@ -375,7 +379,7 @@ int CoreTextLayout::GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIDs, Point& rPos if( !mpRuns ) { mpRuns = CTLineGetGlyphRuns(mpLine); } - CFIndex nb_runs = CFArrayGetCount( mpRuns ); + CFIndex nRuns = CFArrayGetCount( mpRuns ); CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex( mpRuns, mnCurrentRunIndex ); CFIndex nb_glyphs = CTRunGetGlyphCount( run ); @@ -384,7 +388,7 @@ int CoreTextLayout::GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIDs, Point& rPos while( i < nLen ) { if( mnCurrentGlyphRunIndex >= nb_glyphs ) { mnCurrentRunIndex += 1; - if( mnCurrentRunIndex >= nb_runs ) { + if( mnCurrentRunIndex >= nRuns ) { break; } run = (CTRunRef)CFArrayGetValueAtIndex( mpRuns, mnCurrentRunIndex ); @@ -568,10 +572,10 @@ void CoreTextLayout::GetMeasurements() mpGlyphPositions = new CGPoint[ mnGlyphCount ]; CFArrayRef runs = CTLineGetGlyphRuns( mpLine ); - CFIndex nb_runs = CFArrayGetCount( runs ); + const CFIndex nRuns = CFArrayGetCount( runs ); CFIndex lineGlyphIx = 0; - for ( CFIndex runIx = 0; runIx < nb_runs; runIx++ ) + for ( CFIndex runIx = 0; runIx < nRuns; runIx++ ) { CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex( runs, runIx ); if ( !run ) -- cgit