From 3edcdd43f94e605c08314ab61f64c418b01f8dde Mon Sep 17 00:00:00 2001 From: Herbert Dürr Date: Thu, 20 Feb 2014 13:52:52 +0000 Subject: fdo#64957: #i124233# prevent the accumulation of rounding errors in CTLayout::FillDXArry() Change-Id: I8ee83068d71275874e4af364df253251dfb41c8c --- vcl/quartz/ctlayout.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'vcl/quartz/ctlayout.cxx') diff --git a/vcl/quartz/ctlayout.cxx b/vcl/quartz/ctlayout.cxx index 152c1b29870c..1cb8c4825745 100644 --- a/vcl/quartz/ctlayout.cxx +++ b/vcl/quartz/ctlayout.cxx @@ -368,9 +368,8 @@ long CTLayout::FillDXArray( sal_Int32* pDXArray ) const long nPixWidth = GetTextWidth(); if( pDXArray ) { - // initialize the result array - for( int i = 0; i < mnCharCount; ++i) - pDXArray[i] = 0; + // prepare the sub-pixel accurate logical-width array + ::std::vector aWidthVector( mnCharCount ); // handle each glyph run CFArrayRef aGlyphRuns = CTLineGetGlyphRuns( mpCTLine ); const int nRunCount = CFArrayGetCount( aGlyphRuns ); @@ -388,9 +387,18 @@ long CTLayout::FillDXArray( sal_Int32* pDXArray ) const CTRunGetStringIndices( pGlyphRun, aFullRange, &aIndexVec[0] ); for( int i = 0; i != nGlyphCount; ++i ) { const int nRelIdx = aIndexVec[i]; - pDXArray[ nRelIdx ] += lrint(aSizeVec[i].width); + aWidthVector[nRelIdx] += aSizeVec[i].width; } } + + // convert the sub-pixel accurate array into classic pDXArray integers + float fWidthSum = 0.0; + sal_Int32 nOldDX = 0; + for( int i = 0; i < mnCharCount; ++i) { + const sal_Int32 nNewDX = rint( fWidthSum += aWidthVector[i]); + pDXArray[i] = nNewDX - nOldDX; + nOldDX = nNewDX; + } } return nPixWidth; -- cgit