diff options
author | Alexander Toresson <alexander.toresson@sonymobile.com> | 2013-08-28 16:13:06 +0200 |
---|---|---|
committer | Johan Redestig <johan.redestig@sonymobile.com> | 2014-01-23 13:31:15 +0100 |
commit | 3ed192760314dc976cd02f62ac49798daa89b4b1 (patch) | |
tree | d1c1e5797f4dad52e2369afe6a27b3033609747e | |
parent | c9a60b0f77525244ac4f970258703b8dc62ee140 (diff) | |
download | frameworks_base-3ed192760314dc976cd02f62ac49798daa89b4b1.zip frameworks_base-3ed192760314dc976cd02f62ac49798daa89b4b1.tar.gz frameworks_base-3ed192760314dc976cd02f62ac49798daa89b4b1.tar.bz2 |
Fix for positioning of glyphs within a bitmap
For positioning of glyphs within a bitmap, roundf(int + float) is used,
where the float is the glyph position and the int is the text position.
When the text position is varied, this may lead to the sum being rounded
in different directions, due to floating point rounding, caused by that
floating point numbers have different precision in different ranges.
This may therefore lead to slightly different positioning for glyphs and
therefore slightly different widths and heights for text strings,
depending on the position they are rendered at.
The solution in this patch is to use int + (int) roundf(float), which
has consistent rounding, and also enables us to use the full range of
ints.
Change-Id: Id1143cdfcbdfa9915ced878ae04df589a3e03cee
-rw-r--r-- | libs/hwui/font/Font.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp index 18983d8..8f5beb8 100644 --- a/libs/hwui/font/Font.cpp +++ b/libs/hwui/font/Font.cpp @@ -404,10 +404,10 @@ void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len // If it's still not valid, we couldn't cache it, so we shouldn't // draw garbage; also skip empty glyphs (spaces) if (cachedGlyph->mIsValid && cachedGlyph->mCacheTexture) { - float penX = x + positions[(glyphsCount << 1)]; - float penY = y + positions[(glyphsCount << 1) + 1]; + int penX = x + (int) roundf(positions[(glyphsCount << 1)]); + int penY = y + (int) roundf(positions[(glyphsCount << 1) + 1]); - (*this.*render)(cachedGlyph, roundf(penX), roundf(penY), + (*this.*render)(cachedGlyph, penX, penY, bitmap, bitmapW, bitmapH, bounds, positions); } |