summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerbert Dürr <hdu@apache.org>2014-02-20 13:52:52 +0000
committerCaolán McNamara <caolanm@redhat.com>2014-02-26 09:17:38 -0600
commitac7062d7fb6e5dfe0f81d53daec7f088dc4f9e3d (patch)
tree19bd7d79c3ca4a09181b961a08cfe63427d49c09
parent392d4260a4dcde72d072ed1a8ab8dcfede18e031 (diff)
fdo#64957: #i124233# prevent the accumulation of rounding errors
in CTLayout::FillDXArry() Change-Id: Ifb4f16fb76f67d5b5c96fdb0545c64eb8316aa3c Reviewed-on: https://gerrit.libreoffice.org/8359 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-on: https://gerrit.libreoffice.org/8366 Reviewed-by: David Tardon <dtardon@redhat.com>
-rw-r--r--vcl/coretext/ctlayout.cxx16
1 files changed, 12 insertions, 4 deletions
diff --git a/vcl/coretext/ctlayout.cxx b/vcl/coretext/ctlayout.cxx
index 0e9a6e0430ac..d248c487e396 100644
--- a/vcl/coretext/ctlayout.cxx
+++ b/vcl/coretext/ctlayout.cxx
@@ -369,9 +369,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<float> aWidthVector( mnCharCount );
// handle each glyph run
CFArrayRef aGlyphRuns = CTLineGetGlyphRuns( mpCTLine );
const int nRunCount = CFArrayGetCount( aGlyphRuns );
@@ -389,9 +388,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;