From fc12c8bcc8000123064458e094ae6e29bd2bedb5 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 15 Feb 2016 17:35:05 -0500 Subject: [PATCH] Honour font scaling factor when drawing with SDL_TTF --- src/font.cpp | 2 ++ src/loadscreen.cpp | 3 ++- src/marked-up_text.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/font.cpp b/src/font.cpp index 40987679b600..3ed30f2aed7e 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -32,6 +32,7 @@ #include "serialization/preprocessor.hpp" #include "serialization/string_utils.hpp" #include "serialization/unicode.hpp" +#include "preferences.hpp" #include #include @@ -894,6 +895,7 @@ SDL_Rect draw_text_line(surface& gui_surface, const SDL_Rect& area, int size, const SDL_Color& color, const std::string& text, int x, int y, bool use_tooltips, int style) { + size = preferences::font_scaled(size); if (gui_surface.null()) { text_surface const &u = text_cache::find(text_surface(text, size, color, style)); return sdl::create_rect(0, 0, u.width(), u.height()); diff --git a/src/loadscreen.cpp b/src/loadscreen.cpp index 449b6e164871..91adf0d29feb 100644 --- a/src/loadscreen.cpp +++ b/src/loadscreen.cpp @@ -27,6 +27,7 @@ #include "video.hpp" #include "image.hpp" #include "text.hpp" +#include "preferences.hpp" #include #include @@ -281,7 +282,7 @@ void loadscreen::draw_screen(const std::string &text) { SDL_Rect oldarea = textarea_; sdl::fill_rect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0)); - textarea_ = font::line_size(text, font::SIZE_NORMAL); + textarea_ = font::line_size(text, preferences::font_scaled(font::SIZE_NORMAL)); textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2; textarea_.y = pby + pbh + 4*(bw + bispw); textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOR,text,textarea_.x,textarea_.y); diff --git a/src/marked-up_text.cpp b/src/marked-up_text.cpp index b7acd551ef23..50f4dd092614 100644 --- a/src/marked-up_text.cpp +++ b/src/marked-up_text.cpp @@ -29,6 +29,7 @@ #include "serialization/unicode.hpp" #include "video.hpp" #include "wml_exception.hpp" +#include "preferences.hpp" namespace font { @@ -323,6 +324,7 @@ static void cut_word(std::string& line, std::string& word, int font_size, int st std::string tmp = line; utf8::iterator tc(word); bool first = true; + font_size = preferences::font_scaled(font_size); for(;tc != utf8::iterator::end(word); ++tc) { tmp.append(tc.substr().first, tc.substr().second); @@ -509,7 +511,7 @@ std::string word_wrap_text(const std::string& unwrapped_text, int font_size, start_of_line = true; } else { - const size_t word_width = line_size(current_word, font_sz, style).w; + const size_t word_width = line_size(current_word, preferences::font_scaled(font_sz), style).w; line_width += word_width; @@ -528,7 +530,7 @@ std::string word_wrap_text(const std::string& unwrapped_text, int font_size, } if(line_break || (current_word.empty() && ch == end)) { - SDL_Rect size = line_size(current_line, font_sz, style); + SDL_Rect size = line_size(current_line, preferences::font_scaled(font_sz), style); if(max_height > 0 && current_height + size.h >= size_t(max_height)) { return wrapped_text; }