26 #define DBG_FT LOG_STREAM(debug, log_font)
27 #define LOG_FT LOG_STREAM(info, log_font)
28 #define WRN_FT LOG_STREAM(warn, log_font)
29 #define ERR_FT LOG_STREAM(err, log_font)
35 pango_text& private_renderer()
38 static pango_text text_renderer;
46 auto& ptext = private_renderer();
48 ptext.set_text(text, use_markup);
51 .set_font_style(style)
52 .set_maximum_height(-1,
false)
53 .set_foreground_color(color)
54 .set_maximum_width(max_width)
55 .set_ellipse_mode(max_width > 0 ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE);
57 return ptext.render_and_get_texture();
62 auto& ptext = private_renderer();
64 ptext.set_text(
line,
false);
66 .set_font_size(font_size)
67 .set_font_style(font_style)
68 .set_maximum_height(-1,
false)
69 .set_maximum_width(-1)
70 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
72 auto s = ptext.get_size();
85 std::string current_substring;
90 std::string tmp = current_substring;
97 current_substring = std::move(tmp);
100 WRN_FT <<
"Invalid UTF-8 string: \"" << text <<
"\"";
107 std::string
pango_word_wrap(
const std::string& unwrapped_text,
int font_size,
int max_width,
int max_height,
int max_lines,
bool )
115 auto& ptext = private_renderer();
117 ptext.set_text(unwrapped_text,
false);
119 .set_font_size(font_size)
121 .set_maximum_height(max_height,
true)
122 .set_maximum_width(max_width)
123 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
126 const auto& lines = ptext.get_lines();
128 for(
const auto&
line : lines) {
141 auto& ptext = private_renderer();
143 ptext.set_text(text,
false);
146 .set_font_style(style)
147 .set_maximum_width(-1)
148 .set_foreground_color(color)
149 .set_ellipse_mode(PANGO_ELLIPSIZE_END);
152 ptext.set_maximum_height(area.h,
true);
155 auto extents = ptext.get_size();
156 bool ellipsized =
false;
158 if(!area.
empty() && extents.x > area.w) {
159 ptext.set_maximum_width(area.w);
163 auto t = ptext.render_and_get_texture();
165 SDL_Rect res = {x, y,
t.w(),
t.h()};
171 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.
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(std::string_view 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