The Battle for Wesnoth  1.19.0-dev
text_formatting.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "color.hpp"
18 
19 // This file isn't needed by any of these functions, but this allows any
20 // standard color to be passed to span_color without an extra include.
21 #include "font/standard_colors.hpp"
22 
23 #include <string>
24 
25 /**
26  * Collection of helper functions relating to Pango formatting.
27  */
28 
29 namespace font {
30 
31 /**
32  * Returns a Pango formatting string using the provided color_t object.
33  *
34  * The string returned will be in format: &lt;span foreground=\#color>
35  * Callers will need to manually append the closing &lt;/span>' tag.
36  *
37  * @param color The color_t object from which to retrieve the color.
38  */
39 std::string span_color(const color_t& color);
40 
41 /**
42  * Like span_color(const color_t&), but append the data string and a "</span>" tag.
43  */
44 std::string span_color(const color_t& color, const std::string& data);
45 
46 /**
47  * Returns a hex color string from a color range.
48  *
49  * @param id The id of the color range.
50  */
51 std::string get_pango_color_from_id(const std::string& id);
52 
53 /**
54  * Returns the name of a color range, colored with its own color.
55  *
56  * @param id The id of the color range.
57  */
58 std::string get_color_string_pango(const std::string& id);
59 
60 }
Collection of helper functions relating to Pango formatting.
std::string get_pango_color_from_id(const std::string &id)
Returns a hex color string from a color range.
std::string get_color_string_pango(const std::string &id)
Returns the name of a color range, colored with its own color.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
std::string_view data
Definition: picture.cpp:194
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59