28 #define DBG_FT LOG_STREAM(debug, log_font)
29 #define LOG_FT LOG_STREAM(info, log_font)
30 #define WRN_FT LOG_STREAM(warn, log_font)
31 #define ERR_FT LOG_STREAM(err, log_font)
37 pango_text& private_renderer()
40 static pango_text text_renderer;
48 auto& ptext = private_renderer();
50 ptext.set_text(text, use_markup);
53 .set_font_style(style)
54 .set_maximum_height(-1,
false)
55 .set_foreground_color(color)
56 .set_maximum_width(max_width)
57 .set_ellipse_mode(max_width > 0 ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE);
59 return ptext.render_and_get_texture();
64 auto& ptext = private_renderer();
66 ptext.set_text(
line,
false);
68 .set_font_size(font_size)
69 .set_font_style(font_style)
70 .set_maximum_height(-1,
false)
71 .set_maximum_width(-1)
72 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
74 auto s = ptext.get_size();
87 std::string current_substring;
92 std::string tmp = current_substring;
99 current_substring = std::move(tmp);
102 WRN_FT <<
"Invalid UTF-8 string: \"" << text <<
"\"";
109 std::string
pango_word_wrap(
const std::string& unwrapped_text,
int font_size,
int max_width,
int max_height,
int max_lines,
bool )
117 auto& ptext = private_renderer();
119 ptext.set_text(unwrapped_text,
false);
121 .set_font_size(font_size)
123 .set_maximum_height(max_height,
true)
124 .set_maximum_width(max_width)
125 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
128 const auto& lines = ptext.get_lines();
130 for(
const auto&
line : lines) {
143 auto& ptext = private_renderer();
145 ptext.set_text(text,
false);
148 .set_font_style(style)
149 .set_maximum_width(-1)
150 .set_foreground_color(color)
151 .set_ellipse_mode(PANGO_ELLIPSIZE_END);
154 ptext.set_maximum_height(area.h,
true);
157 auto extents = ptext.get_size();
158 bool ellipsized =
false;
160 if(!area.
empty() && extents.x > area.w) {
161 ptext.set_maximum_width(area.w);
165 auto t = ptext.render_and_get_texture();
167 SDL_Rect res = {x, y,
t.w(),
t.h()};
173 if(ellipsized && use_tooltips) {
Wrapper class to encapsulate creation and management of an SDL_Texture.
static iterator_base end(const string_type &str)
const std::pair< typename string_type::const_iterator, typename string_type::const_iterator > & substr() const
Thrown by operations encountering invalid UTF-8 data.
Drawing functions, for drawing things on the screen.
Standard logging facilities (interface).
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
Collection of helper functions relating to Pango formatting.
const std::string ellipsis
int pango_line_width(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style=font::pango_text::STYLE_NORMAL)
Determine the width of a line of text given a certain font size.
std::string pango_line_ellipsize(const std::string &text, int font_size, int max_width, font::pango_text::FONT_STYLE font_style)
If the text exceeds the specified max width, end it with an ellipsis (...)
rect pango_draw_text(bool actually_draw, const rect &area, int size, const color_t &color, const std::string &text, int x, int y, bool use_tooltips, pango_text::FONT_STYLE style)
Draws text on the screen.
std::pair< int, int > pango_line_size(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style)
Determine the width and height of a line of text given a certain font size.
texture pango_render_text(const std::string &text, int size, const color_t &color, font::pango_text::FONT_STYLE style, bool use_markup, int max_width)
Returns a SDL texture containing the rendered text.
std::string pango_word_wrap(const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool)
Uses Pango to word wrap text.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
static lg::log_domain log_font("font")
Transitional API for porting SDL_ttf-based code to Pango.
The basic class for representing 8-bit RGB or RGBA colour values.
An abstract description of a rectangle with integer coordinates.
bool empty() const
False if both w and h are > 0, true otherwise.
static map_location::DIRECTION s