The Battle for Wesnoth
1.17.17+dev
font
text_formatting.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2023
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
#include "
font/text_formatting.hpp
"
15
16
#include "
formatter.hpp
"
17
#include "
game_config.hpp
"
18
#include "
gettext.hpp
"
19
#include "
color.hpp
"
20
21
#include <iomanip>
22
23
namespace
font
{
24
25
std::string
span_color
(
const
color_t
& color)
26
{
27
return
formatter
() <<
"<span color='"
<< color.
to_hex_string
() <<
"'>"
;
28
}
29
30
std::string
span_color
(
const
color_t
& color,
const
std::string&
data
)
31
{
32
return
span_color
(color) +
data
+
"</span>"
;
33
}
34
35
std::string
get_pango_color_from_id
(
const
std::string&
id
)
36
{
37
const
auto
color =
game_config::team_rgb_colors
.find(
id
);
38
if
(color !=
game_config::team_rgb_colors
.end()) {
39
return
(color->second[0]).to_hex_string();
40
}
41
42
return
""
;
43
}
44
45
std::string
get_color_string_pango
(
const
std::string&
id
)
46
{
47
const
auto
name =
game_config::team_rgb_name
.find(
id
);
48
if
(name !=
game_config::team_rgb_name
.end()) {
49
return
formatter
() <<
"<span color='"
<<
get_pango_color_from_id
(
id
) <<
"'>"
<< name->second <<
"</span>"
;
50
}
51
52
return
_
(
"Invalid Color"
);
53
}
54
55
}
formatter
std::ostringstream wrapper.
Definition:
formatter.hpp:40
color.hpp
formatter.hpp
game_config.hpp
gettext.hpp
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
font
Collection of helper functions relating to Pango formatting.
Definition:
editor_controller.hpp:39
font::get_pango_color_from_id
std::string get_pango_color_from_id(const std::string &id)
Returns a hex color string from a color range.
Definition:
text_formatting.cpp:35
font::get_color_string_pango
std::string get_color_string_pango(const std::string &id)
Returns the name of a color range, colored with its own color.
Definition:
text_formatting.cpp:45
font::span_color
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
Definition:
text_formatting.cpp:25
game_config::team_rgb_name
std::map< std::string, t_string > team_rgb_name
Definition:
game_config.cpp:142
game_config::team_rgb_colors
std::map< std::string, std::vector< color_t > > team_rgb_colors
Definition:
game_config.cpp:144
data
std::string_view data
Definition:
picture.cpp:199
color_t
The basic class for representing 8-bit RGB or RGBA colour values.
Definition:
color.hpp:59
color_t::to_hex_string
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
Definition:
color.cpp:78
text_formatting.hpp
Generated by
1.9.1