diff options
author | Bastien Bouclet | 2018-08-02 07:09:26 +0200 |
---|---|---|
committer | Bastien Bouclet | 2018-08-03 22:35:16 +0200 |
commit | 7362060c47f5136ba8ea3cd617ef957057ac4296 (patch) | |
tree | 271a45846a267568b27b644ab2d25ca32a2c6b5d /graphics/font.cpp | |
parent | f2049d4d1ece374cbd203350190c19da2b4b58c4 (diff) | |
download | scummvm-rg350-7362060c47f5136ba8ea3cd617ef957057ac4296.tar.gz scummvm-rg350-7362060c47f5136ba8ea3cd617ef957057ac4296.tar.bz2 scummvm-rg350-7362060c47f5136ba8ea3cd617ef957057ac4296.zip |
GRAPHICS: Improve check to test if text fits in the target surface
When rendering text, especially truetype fonts, we would use the next
character avance metric to check if the character fits in the target
surface. This commit changes it to use the bounding box metric. The
bounding box represents the actual pixels that will be touched when
drawing the character.
This fixes an issue noticed on the main menu of Myst ME where the last
character of the string "OPTIONEN" would not be rendered despite there
being enough room to render it. More precisely, this ensures that
calling Font::getBoundingBox for a string, and then passing a surface
exactly the size of the returned bounding box to the draw function
actually renders all the characters.
Diffstat (limited to 'graphics/font.cpp')
-rw-r--r-- | graphics/font.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/graphics/font.cpp b/graphics/font.cpp index b84d6907c6..5f1e68c4f2 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -60,11 +60,11 @@ Common::Rect getBoundingBoxImpl(const Font &font, const StringType &str, int x, const typename StringType::unsigned_type cur = *i; x += font.getKerningOffset(last, cur); last = cur; - w = font.getCharWidth(cur); - if (x+w > rightX) + + Common::Rect charBox = font.getBoundingBox(cur); + if (x + charBox.right > rightX) break; - if (x+w >= leftX) { - Common::Rect charBox = font.getBoundingBox(cur); + if (x + charBox.right >= leftX) { charBox.translate(x, y); if (first) { bbox = charBox; @@ -73,7 +73,8 @@ Common::Rect getBoundingBoxImpl(const Font &font, const StringType &str, int x, bbox.extend(charBox); } } - x += w; + + x += font.getCharWidth(cur); } return bbox; @@ -113,12 +114,14 @@ void drawStringImpl(const Font &font, Surface *dst, const StringType &str, int x const typename StringType::unsigned_type cur = *i; x += font.getKerningOffset(last, cur); last = cur; - w = font.getCharWidth(cur); - if (x+w > rightX) + + Common::Rect charBox = font.getBoundingBox(cur); + if (x + charBox.right > rightX) break; - if (x+w >= leftX) + if (x + charBox.right >= leftX) font.drawChar(dst, cur, x, y, color); - x += w; + + x += font.getCharWidth(cur); } } |