Skip to content

Commit

Permalink
Honour font scaling factor when drawing with SDL_TTF
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 18, 2016
1 parent 270d3fd commit fc12c8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/font.cpp
Expand Up @@ -32,6 +32,7 @@
#include "serialization/preprocessor.hpp"
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#include "preferences.hpp"

#include <boost/foreach.hpp>
#include <boost/optional.hpp>
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/loadscreen.cpp
Expand Up @@ -27,6 +27,7 @@
#include "video.hpp"
#include "image.hpp"
#include "text.hpp"
#include "preferences.hpp"

#include <SDL_events.h>
#include <SDL_image.h>
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/marked-up_text.cpp
Expand Up @@ -29,6 +29,7 @@
#include "serialization/unicode.hpp"
#include "video.hpp"
#include "wml_exception.hpp"
#include "preferences.hpp"

namespace font {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down

0 comments on commit fc12c8b

Please sign in to comment.