The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
3 by Mark de Wever <koraq@xs4all.nl>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include "font/font_options.hpp"
19#include "color.hpp"
20#include "sdl/surface.hpp"
21#include "sdl/texture.hpp"
23
24#include <pango/pangocairo.h>
25
26
27#include <functional>
28#include <memory>
29#include <string>
30#include <vector>
31
32/***
33 * Note: This is the cairo-pango code path, not the SDL_TTF code path.
34 */
35
36struct point;
37
38namespace font
39{
40class attribute_list;
41
42// add background color and also font markup.
43
44/**
45 * Text class.
46 *
47 * This class represents text which is rendered using Pango.
48 *
49 * It takes text, as a utf-8 std::string, plus formatting options including
50 * font and color. It provides a surface object which holds the rendered text.
51 *
52 * Besides this, it can do some additional calculations using the font layout.
53 *
54 * It can take an index into the text, and convert it to pixel coordinates,
55 * so that if we want to draw a cursor in an editbox, we know where to draw it.
56 *
57 * It can also take a pixel coordinate with respect to the text layout, and
58 * translate it back to an index into the original text. This is useful if the
59 * user clicks on the text, and we want to know where to move the cursor.
60 *
61 * The get_token method takes a pixel coordinate, which we assume represents a
62 * click position, and gets the corresponding "token" from the string. The default
63 * token delimiters are whitespace " \n\r\t". So, this returns the "word" that the
64 * user clicked on.
65 *
66 * Finally, the get_link method represents special support for hyperlinks in text.
67 * A token "looks like a link" if it begins "http://" or "https://".
68 * If a text has link_aware enabled, then any such token is rendered with an
69 * underline and in a special color, see `link_color`.
70 * The get_link method calls get_token and further checks if the clicked token
71 * looks like a link.
72 *
73 * This class stores the text to draw and uses pango with the cairo backend to
74 * render the text. See http://pango.org for more info.
75 *
76 */
78{
79public:
80 pango_text();
81
82 pango_text(const pango_text&) = delete;
83 pango_text& operator=(const pango_text&) = delete;
84
85 /**
86 * Returns the cached texture, or creates a new one otherwise.
87 *
88 * texture::w() and texture::h() methods will return the expected
89 * width and height of the texture in draw space. This may differ
90 * from the real value returned by texture::get_info().
91 *
92 * In almost all cases, use w() and h() to get the size of the
93 * rendered text for drawing.
94 */
96
97 /**
98 * Renders only part of the text.
99 *
100 * Use this when only a small part of a large text will be visible, as
101 * rendering all of it may exceed the maximum size of a cairo surface or
102 * an SDL texture.
103 *
104 * @param viewport The area to render, in drawing co-ordinates relative to
105 * the text's origin. It is clipped to the extent of the text, so the
106 * returned texture may be smaller than requested.
107 *
108 * @returns A texture whose origin corresponds to viewport.x and
109 * viewport.y, or an empty texture if nothing is visible.
110 */
111 texture render_and_get_texture(const rect& viewport);
112
113private:
114 /**
115 * Wrapper around render_surface which sets texture::w() and texture::h()
116 * in the same way that render_and_get_texture does.
117 *
118 * The viewport rect is interpreted at the scale of render-space, not
119 * drawing-space. This function has only been made private to preserve
120 * the drawing-space encapsulation.
121 */
122 texture render_texture(const rect& viewport);
123
124 /**
125 * Returns the rendered text.
126 *
127 * The viewport rect is interpreted at the scale of render-space, not
128 * drawing-space. This function has only been made private to preserve
129 * the drawing-space encapsulation.
130 *
131 * @param viewport Only this area needs to be drawn - the returned
132 * surface's origin will correspond to viewport.x and viewport.y, the
133 * width and height will be at least viewport.w and viewport.h (although
134 * they may be larger).
135 */
136 surface render_surface(const rect& viewport);
137
138public:
139 /** Returns the size of the text, in drawing coordinates. */
140 point get_size();
141
142 /** Has the text been truncated? This happens if it exceeds max width or height. */
143 bool is_truncated() const;
144
145 /**
146 * Inserts UTF-8 text.
147 *
148 * @param offset The position to insert the text.
149 * @param text The UTF-8 text to insert.
150 * @param use_markup If the text is formatted or not.
151 *
152 * @returns The number of characters inserted.
153 */
154 unsigned insert_text(const unsigned offset, const std::string& text, const bool use_markup = false);
155
156 /***** ***** ***** ***** Font flags ***** ***** ***** *****/
157
158 // NOTE: these values must be powers of 2 in order to be bit-unique
165
166 /***** ***** ***** ***** Query details ***** ***** ***** *****/
167
168 /**
169 * Returns the maximum glyph height of a font, in drawing coordinates.
170 *
171 * @returns The height of the tallest possible glyph for the selected
172 * font. More specifically, the result is the sum of the maximum
173 * ascent and descent lengths.
174 */
175 int get_max_glyph_height() const;
176
177 /**
178 * Given a character index and optionally the starting line,
179 * returns the corresponding byte index.
180 * @param offset The character index of the cursor position.
181 * Can be bigger than the line, in which case it
182 * spills over to the next line and so on.
183 * @param line The line from which the offset counting should start.
184 *
185 * @returns The corresponding byte index.
186 */
187 unsigned get_byte_index(const unsigned offset, const unsigned line = 0) const;
188
189 /**
190 * Gets the location for the cursor, in drawing coordinates.
191 *
192 * @param offset The character index of the cursor position.
193 * Can be bigger than the line, in which case it
194 * spills over to the next line and so on.
195 * @param line The line from which the offset counting should start.
196 *
197 * @returns The position of the top of the cursor. It the
198 * requested location is out of range 0,0 is
199 * returned.
200 */
201 point get_cursor_position(const unsigned offset, const unsigned line = 0) const;
202
203 /**
204 * Gets the location for the cursor, in drawing coordinates.
205 *
206 * @param offset The byte index corresponding to the cursor position.
207 *
208 * @returns The position of the top of the cursor. It the
209 * requested location is out of range 0,0 is
210 * returned.
211 */
212 point get_cursor_pos_from_index(const unsigned offset) const;
213
214 /**
215 * Gets where a range of characters lies on each line it spans.
216 *
217 * @param start The character index of the first character.
218 * @param end The character index after the last character.
219 *
220 * @returns For each line, a pair of the cursor position
221 * before the range's first character on that line
222 * and the x position after its last character,
223 * ignoring whitespace where the line wraps, in
224 * drawing co-ordinates.
225 */
226 std::vector<std::pair<point, int>> get_line_spans(const unsigned start, const unsigned end) const;
227
228 /**
229 * Get maximum length.
230 *
231 * @returns The maximum length of the text. The length of text
232 * should not exceed this value.
233 */
234 std::size_t get_maximum_length() const;
235
236 /**
237 * Gets the largest collection of characters, including the token at position,
238 * and not including any characters from the delimiters set.
239 *
240 * @param position The pixel position in the text area.
241 * @param delimiters
242 *
243 * @returns The token containing position, and none of the
244 * delimiter characters. If position is out of bounds,
245 * it returns the empty string.
246 */
247 std::string get_token(const point& position, std::string_view delimiters = " \n\r\t") const;
248
249 /**
250 * Checks if position points to a character in a link in the text, returns it
251 * if so, empty string otherwise. Link-awareness must be enabled to get results.
252 * @param position The pixel position in the text area.
253 *
254 * @returns The link if one is found, the empty string otherwise.
255 */
256 std::string get_link(const point& position) const;
257
258 /**
259 * Gets the column of line of the character at the position.
260 *
261 * @param position The pixel position in the text area.
262 *
263 * @returns A point with the x value the column and the y
264 * value the line of the character found (or last
265 * character if not found.
266 */
267 point get_column_line(const point& position) const;
268
269 /**
270 * Wrapper function around `pango_layout_xy_to_index`.
271 *
272 * @param position The pixel position in the text area.
273 *
274 * @returns A tuple of the format `{index, trailing, inside_bounds}`
275 * where `index` and `trailing` are as described in
276 * <a href='https://docs.gtk.org/Pango/method.Layout.xy_to_index.html'>Pango documention</a>
277 * for `pango_layout_xy_to_index`, and `inside_bounds`
278 * is `true` if the given position is inside the pango layout,
279 * and `false` otherwise.
280 */
281 std::tuple<int, int, bool> xy_to_index(const point& position) const;
282
283 /**
284 * Retrieves a list of strings with contents for each rendered line.
285 *
286 * This method is not const because it requires rendering the text.
287 *
288 * @note This is only intended for renderer implementation details. This
289 * is a rather expensive function because it copies everything at
290 * least once.
291 */
292 std::vector<std::string> get_lines() const;
293
294 /**
295 * Get a specific line from the pango layout
296 *
297 * @param index the line number of the line to retrieve
298 *
299 * @returns the PangoLayoutLine* corresponding to line number index
300 */
301 PangoLayoutLine* get_line(int index);
302
303 /**
304 * Given a byte index, find out at which line the corresponding character
305 * is located. Wrapper for `pango_layout_index_to_line_x`.
306 *
307 * @param offset the byte index
308 *
309 * @param trailing which edge the counting starts from
310 * true: trailing edge, false: leading edge.
311 *
312 * @returns a pair of the form `{line, xpos}`
313 * where `line` is the line number corresponding to the given index
314 * and `xpos` is the resulting x position.
315 */
316 std::pair<int, int> index_to_line_x(const unsigned offset, const bool trailing = 0) const;
317
318 /**
319 * Get number of lines in the text.
320 *
321 * @returns The number of lines in the text.
322 *
323 */
324 unsigned get_lines_count() const {
325 return pango_layout_get_line_count(layout_.get());
326 };
327
328 /**
329 * Gets the length of the text in bytes.
330 *
331 * The text set is UTF-8 so the length of the string might not be the length
332 * of the text.
333 */
334 std::size_t get_length() const { return length_; }
335
336 /**
337 * Sets the text to render.
338 *
339 * @param text The text to render.
340 * @param markedup Should the text be rendered with pango
341 * markup. If the markup is invalid it's
342 * rendered as text without markup.
343 *
344 * @returns The status, if rendered as markup and the
345 * markup contains errors, false is returned
346 * else true.
347 */
348 bool set_text(const std::string& text, const bool markedup);
349
350 /***** ***** ***** ***** Setters / getters ***** ***** ***** *****/
351
352 const std::string& text() const { return text_; }
353
355
356 pango_text& set_font_size(unsigned font_size);
357
358 pango_text& set_font_style(const FONT_STYLE font_style);
359
361
362 pango_text& set_maximum_width(int width);
363
364 pango_text& set_characters_per_line(const unsigned characters_per_line);
365
366 pango_text& set_maximum_height(int height, bool multiline);
367
368 pango_text& set_ellipse_mode(const PangoEllipsizeMode ellipse_mode);
369
370 pango_text& set_alignment(const PangoAlignment alignment);
371
372 pango_text& set_maximum_length(const std::size_t maximum_length);
373
374 bool link_aware() const { return link_aware_; }
375
377
378 pango_text& set_link_color(const color_t& color);
379
380 pango_text& set_add_outline(bool do_add);
381
382 pango_text& set_line_spacing(float line_spacing)
383 {
384 pango_layout_set_line_spacing(layout_.get(), line_spacing);
385 return *this;
386 }
387
388 void clear_attributes();
389 void apply_attributes(const font::attribute_list& attrs);
390
391private:
392
393 /*
394 * Const member functions don't change the text or any of its settings,
395 * but they may lay out the text again if it's out of date. The layout is
396 * changed through its pointer, and the mutable members are only values
397 * cached from it, plus the pixel scale, which is read from the video
398 * settings.
399 */
400
401 /***** ***** ***** ***** Pango variables ***** ***** ***** *****/
402 std::unique_ptr<PangoContext, std::function<void(void*)>> context_;
403 std::unique_ptr<PangoLayout, std::function<void(void*)>> layout_;
404 mutable PangoRectangle rect_;
405
406 /** The text to draw (stored as UTF-8). */
407 std::string text_;
408
409 /** Does the text contain pango markup? If different render routines must be used. */
411
412 /** Are hyperlinks in the text marked-up, and will get_link return them. */
414
415 /**
416 * The color to render links in.
417 *
418 * Links are formatted using pango &lt;span> as follows:
419 *
420 * &lt;span underline="single" color=" + link_color_ + ">
421 */
423
424 /** The font family class used. */
426
427 /** The font size to draw, in draw-space (before pixel scaling). */
428 unsigned font_size_;
429
430 /** The style of the font, this is an orred mask of the font flags. */
432
433 /** The foreground color. */
435
436 /** Whether to add an outline effect. */
438
439 /**
440 * The maximum width of the text.
441 *
442 * Values less or equal to 0 mean no maximum and are internally stored as
443 * -1, since that's the value pango uses for it.
444 *
445 * This is in draw-space (before pixel scaling).
446 *
447 * See @ref characters_per_line_.
448 */
450
451 /**
452 * The number of characters per line.
453 *
454 * This can be used as an alternative of @ref maximum_width_. The user can
455 * select a number of characters on a line for wrapping. When the value is
456 * non-zero it determines the maximum width based on the average character
457 * width.
458 *
459 * If both @ref maximum_width_ and @ref characters_per_line_ are set the
460 * minimum of the two will be the maximum.
461 *
462 * @note Long lines are often harder to read, setting this value can
463 * automatically wrap on a number of characters regardless of the font
464 * size. Often 66 characters is considered the optimal value for a one
465 * column text.
466 */
468
469 /**
470 * The maximum height of the text.
471 *
472 * Values less or equal to 0 mean no maximum and are internally stored as
473 * -1, since that's the value pango uses for it.
474 *
475 * This is in draw-space (before pixel scaling).
476 */
478
479 /** Whether the maximum height is also passed to the layout. */
481
482 /** The way too long text is shown depends on this mode. */
483 PangoEllipsizeMode ellipse_mode_;
484
485 /** The alignment of the text. */
486 PangoAlignment alignment_;
487
488 /** The maximum length of the text. */
489 std::size_t maximum_length_;
490
491 /**
492 * The text has two dirty states:
493 * - The setting of the state and the size calculations.
494 * - The rendering of the surface.
495 */
496
497 /** The dirty state of the calculations. */
498 mutable bool calculation_dirty_;
499
500 /** Length of the text. */
501 std::size_t length_;
502
503 /** The pixel scale, used to render high-DPI text. */
504 mutable int pixel_scale_;
505
506 /** Recalculates the text layout. */
507 void recalculate() const;
508
509 /** Calculates surface size. */
510 PangoRectangle calculate_size(PangoLayout& layout) const;
511
512 /**
513 * Equivalent to create_surface(viewport), where the viewport's top-left is
514 * at (0,0) and the area is large enough to contain the full text.
515 *
516 * The top-left of the viewport will be at (0,0), regardless of the values
517 * of x and y in the rect_ member variable. If the x or y co-ordinates are
518 * non-zero, then x columns and y rows of blank space are included in the
519 * amount of memory allocated.
520 */
522
523 /**
524 * Renders the text to a surface that uses surface_buffer_ as its data store,
525 * the buffer will be allocated or reallocated as necessary.
526 *
527 * The surface's origin will correspond to viewport.x and viewport.y, the
528 * width and height will be at least viewport.w and viewport.h (although
529 * they may be larger).
530 *
531 * @param viewport The area to draw, which can be a subset of the text. This
532 * rectangle's coordinates use render-space's scale.
533 */
534 surface create_surface(const rect& viewport);
535
536 /**
537 * This is part of create_surface(viewport). The separation is a legacy
538 * from workarounds to the size limits of cairo_surface_t.
539 */
540 void render(PangoLayout& layout, const rect& viewport);
541
542 /**
543 * Buffer to store the image on.
544 *
545 * We use a cairo surface to draw on this buffer and then use the buffer as
546 * data source for the SDL_Surface. This means the buffer needs to be stored
547 * in the object, since SDL_Surface doesn't own its buffer.
548 */
549 mutable std::vector<uint8_t> surface_buffer_;
550
551 /**
552 * Sets the markup'ed text.
553 *
554 * It tries to set the text as markup. If the markup is invalid it will try
555 * a bit harder to recover from the errors and still set the markup.
556 *
557 * @param text The text to set as markup.
558 * @param layout
559 *
560 * @returns Whether the markup was set or an
561 * unrecoverable error occurred and the text is
562 * set as plain text with an error message.
563 */
564 bool set_markup(std::string_view text, PangoLayout& layout);
565
566 bool validate_markup(std::string_view text, std::string& semi_escaped) const;
567
568 std::string format_links(std::string_view text) const;
569
570 /**
571 * Adjust a texture's draw-width and height according to pixel scale.
572 *
573 * As fonts are rendered at output-scale, we need to do this just
574 * before returning the rendered texture. These attributes are stored
575 * as part of the returned texture object.
576 */
577 texture with_draw_scale(const texture& t) const;
578
579 /** Scale the given render-space size to draw-space, rounding up. */
580 int to_draw_scale(int s) const;
581
582 /** Scale the given render-space point to draw-space, rounding up. */
583 point to_draw_scale(const point& p) const;
584
585 /** Update pixel scale, if necessary. */
586 void update_pixel_scale() const;
587};
588
589/**
590 * Returns a reference to a static pango_text object.
591 *
592 * Since the class is essentially a render pipeline, there's no need for individual
593 * areas of the game to own their own renderers. Not to mention it isn't a trivial
594 * class; constructing one is likely to be expensive.
595 */
597
598/**
599 * Returns the maximum glyph height of a font, in pixels.
600 *
601 * @param size Desired font size in pixels.
602 * @param fclass Font family to use for measurement.
603 * @param style Font style to select the correct variant for measurement.
604 *
605 * @returns The height of the tallest possible glyph for the selected
606 * font. More specifically, the result is the sum of the maximum
607 * ascent and descent lengths.
608 */
610
611/* Returns the default line spacing factor
612 * For now hardcoded here */
613constexpr float get_line_spacing_factor() { return 1.3f; };
614
615} // namespace font
double t
Helper class to encapsulate the management of a PangoAttrList.
Text class.
Definition text.hpp:78
unsigned get_lines_count() const
Get number of lines in the text.
Definition text.hpp:324
const std::string & text() const
Definition text.hpp:352
int pixel_scale_
The pixel scale, used to render high-DPI text.
Definition text.hpp:504
bool validate_markup(std::string_view text, std::string &semi_escaped) const
Definition text.cpp:995
pango_text & set_font_style(const FONT_STYLE font_style)
Definition text.cpp:453
PangoEllipsizeMode ellipse_mode_
The way too long text is shown depends on this mode.
Definition text.hpp:483
bool multiline_
Whether the maximum height is also passed to the layout.
Definition text.hpp:480
bool add_outline_
Whether to add an outline effect.
Definition text.hpp:437
void clear_attributes()
Definition text.cpp:391
bool set_markup(std::string_view text, PangoLayout &layout)
Sets the markup'ed text.
Definition text.cpp:933
std::size_t get_length() const
Gets the length of the text in bytes.
Definition text.hpp:334
pango_text & set_maximum_length(const std::size_t maximum_length)
Definition text.cpp:537
pango_text & operator=(const pango_text &)=delete
surface create_surface()
Equivalent to create_surface(viewport), where the viewport's top-left is at (0,0) and the area is lar...
Definition text.cpp:884
pango_text & set_line_spacing(float line_spacing)
Definition text.hpp:382
PangoAlignment alignment_
The alignment of the text.
Definition text.hpp:486
PangoRectangle rect_
Definition text.hpp:404
int maximum_height_
The maximum height of the text.
Definition text.hpp:477
point get_size()
Returns the size of the text, in drawing coordinates.
Definition text.cpp:176
pango_text & set_characters_per_line(const unsigned characters_per_line)
Definition text.cpp:486
color_t link_color_
The color to render links in.
Definition text.hpp:422
unsigned insert_text(const unsigned offset, const std::string &text, const bool use_markup=false)
Inserts UTF-8 text.
Definition text.cpp:190
void recalculate() const
Recalculates the text layout.
Definition text.cpp:609
color_t foreground_color_
The foreground color.
Definition text.hpp:434
point get_column_line(const point &position) const
Gets the column of line of the character at the position.
Definition text.cpp:345
std::unique_ptr< PangoContext, std::function< void(void *)> > context_
Definition text.hpp:402
bool link_aware_
Are hyperlinks in the text marked-up, and will get_link return them.
Definition text.hpp:413
pango_text & set_foreground_color(const color_t &color)
Definition text.cpp:463
int to_draw_scale(int s) const
Scale the given render-space size to draw-space, rounding up.
Definition text.cpp:165
texture render_texture(const rect &viewport)
Wrapper around render_surface which sets texture::w() and texture::h() in the same way that render_an...
Definition text.cpp:121
std::string format_links(std::string_view text) const
Replaces all instances of URLs in a given string with formatted links and returns the result.
Definition text.cpp:957
pango_text(const pango_text &)=delete
unsigned get_byte_index(const unsigned offset, const unsigned line=0) const
Given a character index and optionally the starting line, returns the corresponding byte index.
Definition text.cpp:210
std::string get_token(const point &position, std::string_view delimiters=" \n\r\t") const
Gets the largest collection of characters, including the token at position, and not including any cha...
Definition text.cpp:312
PangoLayoutLine * get_line(int index)
Get a specific line from the pango layout.
Definition text.cpp:1059
unsigned characters_per_line_
The number of characters per line.
Definition text.hpp:467
bool markedup_text_
Does the text contain pango markup? If different render routines must be used.
Definition text.hpp:410
pango_text & set_family_class(font::family_class fclass)
Definition text.cpp:431
void update_pixel_scale() const
Update pixel scale, if necessary.
Definition text.cpp:600
font::family_class font_class_
The font family class used.
Definition text.hpp:425
void apply_attributes(const font::attribute_list &attrs)
Definition text.cpp:396
std::vector< std::string > get_lines() const
Retrieves a list of strings with contents for each rendered line.
Definition text.cpp:1033
bool link_aware() const
Definition text.hpp:374
std::tuple< int, int, bool > xy_to_index(const point &position) const
Wrapper function around pango_layout_xy_to_index.
Definition text.cpp:378
unsigned font_size_
The font size to draw, in draw-space (before pixel scaling).
Definition text.hpp:428
std::vector< uint8_t > surface_buffer_
Buffer to store the image on.
Definition text.hpp:549
pango_text & set_add_outline(bool do_add)
Definition text.cpp:569
point get_cursor_position(const unsigned offset, const unsigned line=0) const
Gets the location for the cursor, in drawing coordinates.
Definition text.cpp:246
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
Definition text.cpp:514
PangoRectangle calculate_size(PangoLayout &layout) const
Calculates surface size.
Definition text.cpp:625
pango_text & set_alignment(const PangoAlignment alignment)
Definition text.cpp:527
std::string text_
The text to draw (stored as UTF-8).
Definition text.hpp:407
std::pair< int, int > index_to_line_x(const unsigned offset, const bool trailing=0) const
Given a byte index, find out at which line the corresponding character is located.
Definition text.cpp:1064
bool calculation_dirty_
The text has two dirty states:
Definition text.hpp:498
std::unique_ptr< PangoLayout, std::function< void(void *)> > layout_
Definition text.hpp:403
pango_text & set_font_size(unsigned font_size)
Definition text.cpp:441
pango_text & set_link_aware(bool b)
Definition text.cpp:550
void render(PangoLayout &layout, const rect &viewport)
This is part of create_surface(viewport).
Definition text.cpp:826
FONT_STYLE font_style_
The style of the font, this is an orred mask of the font flags.
Definition text.hpp:431
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
Definition text.cpp:405
bool is_truncated() const
Has the text been truncated? This happens if it exceeds max width or height.
Definition text.cpp:183
texture with_draw_scale(const texture &t) const
Adjust a texture's draw-width and height according to pixel scale.
Definition text.cpp:158
surface render_surface(const rect &viewport)
Returns the rendered text.
Definition text.cpp:152
std::size_t maximum_length_
The maximum length of the text.
Definition text.hpp:489
point get_cursor_pos_from_index(const unsigned offset) const
Gets the location for the cursor, in drawing coordinates.
Definition text.cpp:252
pango_text & set_maximum_height(int height, bool multiline)
Definition text.cpp:497
pango_text & set_maximum_width(int width)
Definition text.cpp:472
std::size_t get_maximum_length() const
Get maximum length.
Definition text.cpp:307
texture render_and_get_texture()
Returns the cached texture, or creates a new one otherwise.
Definition text.cpp:126
std::vector< std::pair< point, int > > get_line_spans(const unsigned start, const unsigned end) const
Gets where a range of characters lies on each line it spans.
Definition text.cpp:261
pango_text & set_link_color(const color_t &color)
Definition text.cpp:559
std::string get_link(const point &position) const
Checks if position points to a character in a link in the text, returns it if so, empty string otherw...
Definition text.cpp:335
std::size_t length_
Length of the text.
Definition text.hpp:501
int get_max_glyph_height() const
Returns the maximum glyph height of a font, in drawing coordinates.
Definition text.cpp:579
int maximum_width_
The maximum width of the text.
Definition text.hpp:449
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition texture.hpp:33
Graphical text output.
pango_text & get_text_renderer()
Returns a reference to a static pango_text object.
Definition text.cpp:1071
constexpr float get_line_spacing_factor()
Definition text.hpp:613
int get_max_height(unsigned size, font::family_class fclass, pango_text::FONT_STYLE style)
Returns the maximum glyph height of a font, in pixels.
Definition text.cpp:1077
The basic class for representing 8-bit RGB or RGBA colour values.
Definition color.hpp:51
Holds a 2D point.
Definition point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition rect.hpp:49
mock_party p
static map_location::direction s
#define b