27 #define DBG_FT LOG_STREAM(debug, log_font) 28 #define LOG_FT LOG_STREAM(info, log_font) 29 #define WRN_FT LOG_STREAM(warn, log_font) 30 #define ERR_FT LOG_STREAM(err, log_font) 36 pango_text& private_renderer()
39 static pango_text text_renderer;
47 auto& ptext = private_renderer();
49 ptext.set_text(text, use_markup);
52 .set_font_style(style)
53 .set_maximum_height(-1,
false)
54 .set_foreground_color(color)
55 .set_maximum_width(max_width)
56 .set_ellipse_mode(max_width > 0 ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE);
58 return ptext.render().clone();
63 auto& ptext = private_renderer();
65 ptext.set_text(line,
false);
67 .set_font_size(font_size)
68 .set_font_style(font_style)
69 .set_maximum_height(-1,
false)
70 .set_maximum_width(-1)
71 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
73 auto s = ptext.get_size();
86 std::string current_substring;
91 std::string tmp = current_substring;
98 current_substring = std::move(tmp);
101 WRN_FT <<
"Invalid UTF-8 string: \"" << text <<
"\"\n";
108 std::string
pango_word_wrap(
const std::string& unwrapped_text,
int font_size,
int max_width,
int max_height,
int max_lines,
bool )
116 auto& ptext = private_renderer();
118 ptext.set_text(unwrapped_text,
false);
120 .set_font_size(font_size)
122 .set_maximum_height(max_height,
true)
123 .set_maximum_width(max_width)
124 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
127 const auto& lines = ptext.get_lines();
129 for(
const auto& line : lines) {
142 auto& ptext = private_renderer();
144 ptext.set_text(text,
false);
147 .set_font_style(style)
148 .set_maximum_width(-1)
149 .set_maximum_height(area.h,
true)
150 .set_foreground_color(color)
151 .set_ellipse_mode(PANGO_ELLIPSIZE_END);
153 auto extents = ptext.get_size();
154 bool ellipsized =
false;
156 if(extents.x > area.w) {
157 ptext.set_maximum_width(area.w);
161 auto s = ptext.render();
163 SDL_Rect res = { x, y,
s->w,
s->h };
169 if(ellipsized && use_tooltips) {
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 (...)
Collection of helper functions relating to Pango formatting.
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.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
void blit_surface(const surface &surf, SDL_Rect *dst)
Draws a surface at the given location.
const std::string ellipsis
const std::pair< typename string_type::const_iterator, typename string_type::const_iterator > & substr() const
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.
Thrown by operations encountering invalid UTF-8 data.
static map_location::DIRECTION s
static iterator_base end(const string_type &str)
Standard logging facilities (interface).
surface 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 surface containing the rendered text.
static lg::log_domain log_font("font")
SDL_Rect pango_draw_text(CVideo *video, const SDL_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.
Transitional API for porting SDL_ttf-based code to Pango.
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.