aboutsummaryrefslogtreecommitdiff
path: root/graphics/fonts
diff options
context:
space:
mode:
authorJohannes Schickel2014-06-09 18:54:49 +0200
committerJohannes Schickel2014-09-03 22:55:48 +0200
commitd55cd8f3b44de42d9be09280634584b6424945f9 (patch)
tree3f4b89405c8d4dd8e34f46382ebb2f13d4dfd998 /graphics/fonts
parent58bfb3b43588152490efc55c24ca8c94e8f39e38 (diff)
downloadscummvm-rg350-d55cd8f3b44de42d9be09280634584b6424945f9.tar.gz
scummvm-rg350-d55cd8f3b44de42d9be09280634584b6424945f9.tar.bz2
scummvm-rg350-d55cd8f3b44de42d9be09280634584b6424945f9.zip
GRAPHICS: Allow to query the bounding box of chars/strings drawn with Font API.
Diffstat (limited to 'graphics/fonts')
-rw-r--r--graphics/fonts/ttf.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index 09a00672e3..4b63c6c60f 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -111,6 +111,8 @@ public:
virtual int getKerningOffset(uint32 left, uint32 right) const;
+ virtual Common::Rect getBoundingBox(uint32 chr) const;
+
virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
private:
bool _initialized;
@@ -309,6 +311,19 @@ int TTFFont::getKerningOffset(uint32 left, uint32 right) const {
return (kerningVector.x / 64);
}
+Common::Rect TTFFont::getBoundingBox(uint32 chr) const {
+ assureCached(chr);
+ GlyphCache::const_iterator glyphEntry = _glyphs.find(chr);
+ if (glyphEntry == _glyphs.end()) {
+ return Common::Rect();
+ } else {
+ const int xOffset = glyphEntry->_value.xOffset;
+ const int yOffset = glyphEntry->_value.yOffset;
+ const Graphics::Surface &image = glyphEntry->_value.image;
+ return Common::Rect(xOffset, yOffset, xOffset + image.w, yOffset + image.h);
+ }
+}
+
namespace {
template<typename ColorType>