summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tilefont.cc
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-24 00:48:02 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-24 00:48:02 +0000
commitad41d5af4c2b0379871d3ab295d57c51ae89d843 (patch)
tree9cd89273eec9dc44c692357d0d1c47f213a78dbe /crawl-ref/source/tilefont.cc
parentc2457cbc9315371f712321e7d0263883151eb196 (diff)
downloadcrawl-ref-ad41d5af4c2b0379871d3ab295d57c51ae89d843.tar.gz
crawl-ref-ad41d5af4c2b0379871d3ab295d57c51ae89d843.zip
[2021067] Fixing font centering issues.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6655 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/tilefont.cc')
-rw-r--r--crawl-ref/source/tilefont.cc28
1 files changed, 27 insertions, 1 deletions
diff --git a/crawl-ref/source/tilefont.cc b/crawl-ref/source/tilefont.cc
index fec21c1d18..f2c3c07e0f 100644
--- a/crawl-ref/source/tilefont.cc
+++ b/crawl-ref/source/tilefont.cc
@@ -376,6 +376,32 @@ static void _draw_box(int x_pos, int y_pos, float width, float height,
}
+unsigned int FTFont::string_width(const char *text)
+{
+ unsigned int base_width = std::max(-m_min_offset, 0);
+ unsigned int max_width = 0;
+
+ unsigned int width = 0;
+ unsigned int adjust = 0;
+ for (const char *itr = text; *itr; itr++)
+ {
+ if (*itr == '\n')
+ {
+ max_width = std::max(width + adjust, max_width);
+ width = base_width;
+ adjust = 0;
+ }
+ else
+ {
+ width += m_glyphs[*itr].advance;
+ adjust = std::max(0, m_glyphs[*itr].width - m_glyphs[*itr].advance);
+ }
+ }
+
+ max_width = std::max(width + adjust, max_width);
+ return max_width;
+}
+
void FTFont::render_string(unsigned int px, unsigned int py,
const char *text,
const coord_def &min_pos, const coord_def &max_pos,
@@ -429,7 +455,7 @@ void FTFont::render_string(unsigned int px, unsigned int py,
// Find a suitable location on screen
const int buffer = 5; // additional buffer size from edges
- int wx = max_cols * char_width();
+ int wx = string_width(text);
int wy = max_rows * char_height();
// text starting location