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();
76 std::string
pango_word_wrap(
const std::string& unwrapped_text,
int font_size,
int max_width,
int max_height,
int max_lines,
bool )
84 auto& ptext = private_renderer();
86 ptext.set_text(unwrapped_text,
false);
88 .set_font_size(font_size)
90 .set_maximum_height(max_height,
true)
91 .set_maximum_width(max_width)
92 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
95 const auto& lines = ptext.get_lines();
97 for(
const auto&
line : lines) {
110 auto& ptext = private_renderer();
112 ptext.set_text(text,
false);
115 .set_font_style(style)
116 .set_maximum_width(-1)
117 .set_foreground_color(color)
118 .set_ellipse_mode(PANGO_ELLIPSIZE_END);
121 ptext.set_maximum_height(area.h,
true);
124 auto extents = ptext.get_size();
125 bool ellipsized =
false;
127 if(!area.
empty() && extents.x > area.w) {
128 ptext.set_maximum_width(area.w);
132 auto t = ptext.render_and_get_texture();
134 SDL_Rect res = {x, y,
t.w(),
t.h()};
140 if(ellipsized && use_tooltips) {
Wrapper class to encapsulate creation and management of an SDL_Texture.
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.
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