25 #define DBG_FT LOG_STREAM(debug, log_font)
26 #define LOG_FT LOG_STREAM(info, log_font)
27 #define WRN_FT LOG_STREAM(warn, log_font)
28 #define ERR_FT LOG_STREAM(err, log_font)
34 pango_text& private_renderer()
37 static pango_text text_renderer;
45 auto& ptext = private_renderer();
47 ptext.set_text(text, use_markup);
50 .set_font_style(style)
51 .set_maximum_height(-1,
false)
52 .set_foreground_color(color)
53 .set_maximum_width(max_width)
54 .set_ellipse_mode(max_width > 0 ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE);
56 return ptext.render_and_get_texture();
61 auto& ptext = private_renderer();
63 ptext.set_text(
line,
false);
65 .set_font_size(font_size)
66 .set_font_style(font_style)
67 .set_maximum_height(-1,
false)
68 .set_maximum_width(-1)
69 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
71 auto s = ptext.get_size();
75 std::string
pango_word_wrap(
const std::string& unwrapped_text,
int font_size,
int max_width,
int max_height,
int max_lines,
bool )
83 auto& ptext = private_renderer();
85 ptext.set_text(unwrapped_text,
false);
87 .set_font_size(font_size)
89 .set_maximum_height(max_height,
true)
90 .set_maximum_width(max_width)
91 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
94 const auto& lines = ptext.get_lines();
96 for(
const auto&
line : lines) {
109 auto& ptext = private_renderer();
111 ptext.set_text(text,
false);
115 .set_maximum_width(-1)
116 .set_foreground_color(color)
117 .set_ellipse_mode(PANGO_ELLIPSIZE_END);
120 ptext.set_maximum_height(area.h,
true);
123 auto extents = ptext.get_size();
125 if(!area.
empty() && extents.x > area.w) {
126 ptext.set_maximum_width(area.w);
129 auto t = ptext.render_and_get_texture();
131 SDL_Rect res = {x, y,
t.w(),
t.h()};
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.
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.
rect pango_draw_text(bool actually_draw, const rect &area, int size, const color_t &color, const std::string &text, int x, int y)
Draws text on the screen.
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