The Battle for Wesnoth  1.15.0-dev
Classes | Typedefs | Enumerations | Functions | Variables
font Namespace Reference

Collection of helper functions relating to Pango formatting. More...

Classes

struct  error
 
class  floating_label
 
struct  floating_label_context
 Struct which will hide all current floating labels, and cause floating labels instantiated after it is created to be displayed. More...
 
struct  floating_label_scope_helper
 Helper struct which removes the floating label with the given id upon destruction. More...
 
struct  inverse_table
 
struct  manager
 
class  p_font
 Small helper class to make sure the pango font object is destroyed properly. More...
 
class  pango_text
 Text class. More...
 

Typedefs

using pango_text_cache_t = std::map< std::size_t, texture >
 

Enumerations

enum  ALIGN { LEFT_ALIGN, CENTER_ALIGN, RIGHT_ALIGN }
 
enum  LABEL_SCROLL_MODE { ANCHOR_LABEL_SCREEN, ANCHOR_LABEL_MAP }
 
enum  family_class { FONT_SANS_SERIF, FONT_MONOSPACE, FONT_LIGHT, FONT_SCRIPT }
 Font classes for get_font_families(). More...
 

Functions

int add_floating_label (const floating_label &flabel)
 Add a label floating on the screen above everything else. More...
 
void move_floating_label (int handle, double xmove, double ymove)
 Moves the floating label given by 'handle' by (xmove, ymove). More...
 
void scroll_floating_labels (double xmove, double ymove)
 Moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP. More...
 
void remove_floating_label (int handle)
 Removes the floating label given by 'handle' from the screen. More...
 
void show_floating_label (int handle, bool show)
 Hides or shows a floating label. More...
 
SDL_Rect get_floating_label_rect (int handle)
 
void draw_floating_labels ()
 Renders all floating labels. More...
 
int relative_size (int size)
 
bool check_font_file (std::string name)
 Test if a font file exists. More...
 
bool load_font_config ()
 
const t_stringget_font_families (family_class fclass=FONT_SANS_SERIF)
 Returns the currently defined fonts. More...
 
family_class str_to_family_class (const std::string &str)
 
bool is_cjk_char (const char32_t ch)
 Determine if a char32_t is a CJK character. More...
 
std::string escape_text (const std::string &text)
 Escapes the pango markup characters in a text. More...
 
std::string semi_escape_text (const std::string &text)
 
bool looks_like_url (utils::string_view str)
 
std::string format_as_link (const std::string &link, color_t color)
 
std::ostream & operator<< (std::ostream &s, const PangoRectangle &rect)
 
static void unpremultiply (uint8_t &value, const unsigned div)
 
static void from_cairo_format (uint32_t &c)
 Converts from cairo-format ARGB32 premultiplied alpha to plain alpha. More...
 
pango_textget_text_renderer ()
 Returns a reference to a static pango_text object. More...
 
std::string span_color (const color_t &color)
 Returns a Pango formatting string using the provided color_t object. More...
 
std::string get_pango_color_from_id (const std::string &id)
 Returns a hex color string from a color range. More...
 
std::string get_color_string_pango (const std::string &id)
 Returns the name of a color range, colored with its own color. More...
 

Variables

const int SIZE_NORMAL = 14
 
const int SIZE_TINY = 10 * SIZE_NORMAL / 14
 
const int SIZE_SMALL = 12 * SIZE_NORMAL / 14
 
const int SIZE_15 = 15 * SIZE_NORMAL / 14
 
const int SIZE_PLUS = 16 * SIZE_NORMAL / 14
 
const int SIZE_LARGE = 18 * SIZE_NORMAL / 14
 
const int SIZE_TITLE = 20 * SIZE_NORMAL / 14
 
const int SIZE_XLARGE = 24 * SIZE_NORMAL / 14
 
const std::size_t max_text_line_width = 4096
 
const std::string ellipsis = "..."
 
const std::string unicode_minus = "-"
 
const std::string unicode_en_dash = "–"
 
const std::string unicode_em_dash = "—"
 
const std::string unicode_figure_dash = "‒"
 
const std::string unicode_multiplication_sign = "×"
 
const std::string unicode_bullet = "•"
 
const std::string weapon_numbers_sep = "×"
 
const std::string weapon_details_sep = "–"
 
const color_t NORMAL_COLOR {221, 221, 221}
 
const color_t GRAY_COLOR {136, 136, 136}
 
const color_t LOBBY_COLOR {187, 187, 187}
 
const color_t GOOD_COLOR {0 , 181, 26 }
 
const color_t BAD_COLOR {255, 0 , 0 }
 
const color_t BLACK_COLOR {0 , 0 , 0 }
 
const color_t YELLOW_COLOR {255, 255, 0 }
 
const color_t BUTTON_COLOR {186, 172, 125}
 
const color_t PETRIFIED_COLOR {160, 160, 160}
 
const color_t TITLE_COLOR {186, 172, 125}
 
const color_t LABEL_COLOR {107, 140, 255}
 
const color_t BIGMAP_COLOR {255, 255, 255}
 
const color_t DISABLED_COLOR = PETRIFIED_COLOR.inverse()
 
const color_t weapon_color {245, 230, 193}
 
const color_t good_dmg_color {130, 240, 50 }
 
const color_t bad_dmg_color {250, 140, 80 }
 
const color_t weapon_details_color {166, 146, 117}
 
const color_t inactive_details_color {146, 146, 146}
 
const color_t inactive_ability_color {146, 146, 146}
 
const color_t unit_type_color {245, 230, 193}
 
const color_t race_color {166, 146, 117}
 
static const inverse_table inverse_table_
 
static pango_text_cache_t rendered_text_cache
 The text texture cache. More...
 

Detailed Description

Collection of helper functions relating to Pango formatting.

Graphical text output.

This module is used to display and measure text. Text can optionally contain special characters, which may change specified display properties such as colour or font size. If special characters are turned on, they can be escaped, C-style, using backslashes.

Typedef Documentation

◆ pango_text_cache_t

using font::pango_text_cache_t = typedef std::map<std::size_t, texture>

Definition at line 473 of file text.hpp.

Enumeration Type Documentation

◆ ALIGN

Enumerator
LEFT_ALIGN 
CENTER_ALIGN 
RIGHT_ALIGN 

Definition at line 43 of file floating_label.hpp.

◆ family_class

Font classes for get_font_families().

Enumerator
FONT_SANS_SERIF 
FONT_MONOSPACE 
FONT_LIGHT 
FONT_SCRIPT 

Definition at line 25 of file font_options.hpp.

◆ LABEL_SCROLL_MODE

Enumerator
ANCHOR_LABEL_SCREEN 
ANCHOR_LABEL_MAP 

Definition at line 45 of file floating_label.hpp.

Function Documentation

◆ add_floating_label()

int font::add_floating_label ( const floating_label flabel)

Add a label floating on the screen above everything else.

Returns
a handle to the label which can be used with other label functions

Definition at line 168 of file floating_label.cpp.

Referenced by display_chat_manager::add_chat_message(), display::announce(), terrain_label::draw(), display::draw_debugging_aids(), display::draw_text_in_hex(), game_display::float_label(), game_lua_kernel::intf_print(), playmp_controller::play_human_turn(), display::set_diagnostic(), and show_tooltip().

◆ check_font_file()

bool font::check_font_file ( std::string  name)

Test if a font file exists.

Definition at line 61 of file font_config.cpp.

References filesystem::ends_with(), filesystem::file_exists(), game_config::path, and WRN_FT.

◆ draw_floating_labels()

void font::draw_floating_labels ( )

Renders all floating labels.

Definition at line 261 of file floating_label.cpp.

◆ escape_text()

std::string font::escape_text ( const std::string &  text)
inline

◆ format_as_link()

std::string font::format_as_link ( const std::string &  link,
color_t  color 
)
inline

◆ from_cairo_format()

static void font::from_cairo_format ( uint32_t &  c)
static

Converts from cairo-format ARGB32 premultiplied alpha to plain alpha.

Parameters
ca uint32 representing the color

Definition at line 611 of file text.cpp.

References a, b, g, and unpremultiply().

Referenced by font::pango_text::rerender().

◆ get_color_string_pango()

std::string font::get_color_string_pango ( const std::string &  id)

Returns the name of a color range, colored with its own color.

Parameters
idThe id of the color range.

Definition at line 40 of file text_formatting.cpp.

References _(), get_pango_color_from_id(), name, and game_config::team_rgb_name.

Referenced by gui2::dialogs::mp_staging::add_side_node().

◆ get_floating_label_rect()

SDL_Rect font::get_floating_label_rect ( int  handle)

◆ get_font_families()

const t_string & font::get_font_families ( family_class  fclass = FONT_SANS_SERIF)

Returns the currently defined fonts.

Definition at line 159 of file font_config.cpp.

References FONT_LIGHT, FONT_MONOSPACE, and FONT_SCRIPT.

Referenced by font::pango_text::calculate_size().

◆ get_pango_color_from_id()

std::string font::get_pango_color_from_id ( const std::string &  id)

Returns a hex color string from a color range.

Parameters
idThe id of the color range.

Definition at line 30 of file text_formatting.cpp.

References game_config::team_rgb_colors.

Referenced by gui2::dialogs::mp_join_game::generate_side_list(), and get_color_string_pango().

◆ get_text_renderer()

pango_text & font::get_text_renderer ( )

Returns a reference to a static pango_text object.

Since the class is essentially a render pipeline, there's no need for individual areas of the game to own their own renderers. Not to mention it isn't a trivial class; constructing one is likely to be expensive.

Definition at line 893 of file text.cpp.

Referenced by gui2::text_shape::draw().

◆ is_cjk_char()

bool font::is_cjk_char ( const char32_t  ch)

Determine if a char32_t is a CJK character.

Return values
trueInput-char is a CJK char
falseInput-char is a not CJK char.

You can check these range at http://unicode.org/charts/ see the "East Asian Scripts" part. Notice that not all characters in that part is still in use today, so don't list them all here. Below are characters that I guess may be used in wesnoth translations.

Definition at line 25 of file marked-up_text.cpp.

◆ load_font_config()

bool font::load_font_config ( )

◆ looks_like_url()

bool font::looks_like_url ( utils::string_view  str)
inline

◆ move_floating_label()

void font::move_floating_label ( int  handle,
double  xmove,
double  ymove 
)

Moves the floating label given by 'handle' by (xmove, ymove).

Definition at line 180 of file floating_label.cpp.

References i.

Referenced by display_chat_manager::prune_chat_messages(), and show_tooltip().

◆ operator<<()

std::ostream& font::operator<< ( std::ostream &  s,
const PangoRectangle &  rect 
)
inline

Definition at line 22 of file stream_ops.hpp.

References s.

◆ relative_size()

int font::relative_size ( int  size)
inline

◆ remove_floating_label()

void font::remove_floating_label ( int  handle)

◆ scroll_floating_labels()

void font::scroll_floating_labels ( double  xmove,
double  ymove 
)

Moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP.

Definition at line 188 of file floating_label.cpp.

References ANCHOR_LABEL_MAP.

Referenced by display::scroll().

◆ semi_escape_text()

std::string font::semi_escape_text ( const std::string &  text)
inline

Definition at line 51 of file escape.hpp.

References c.

Referenced by font::pango_text::validate_markup().

◆ show_floating_label()

void font::show_floating_label ( int  handle,
bool  show 
)

Hides or shows a floating label.

Definition at line 209 of file floating_label.cpp.

References i.

Referenced by terrain_label::calculate_shroud().

◆ span_color()

std::string font::span_color ( const color_t color)

◆ str_to_family_class()

family_class font::str_to_family_class ( const std::string &  str)
inline

Definition at line 33 of file font_options.hpp.

References FONT_LIGHT, FONT_MONOSPACE, FONT_SANS_SERIF, and FONT_SCRIPT.

◆ unpremultiply()

static void font::unpremultiply ( uint8_t &  value,
const unsigned  div 
)
static

Definition at line 595 of file text.cpp.

Referenced by from_cairo_format().

Variable Documentation

◆ BAD_COLOR

const color_t font::BAD_COLOR {255, 0 , 0 }

◆ bad_dmg_color

const color_t font::bad_dmg_color {250, 140, 80 }

◆ BIGMAP_COLOR

const color_t font::BIGMAP_COLOR {255, 255, 255}

Definition at line 31 of file standard_colors.cpp.

◆ BLACK_COLOR

const color_t font::BLACK_COLOR {0 , 0 , 0 }

Definition at line 25 of file standard_colors.cpp.

◆ BUTTON_COLOR

const color_t font::BUTTON_COLOR {186, 172, 125}

Definition at line 27 of file standard_colors.cpp.

◆ DISABLED_COLOR

const color_t font::DISABLED_COLOR = PETRIFIED_COLOR.inverse()

Definition at line 33 of file standard_colors.cpp.

◆ ellipsis

const std::string font::ellipsis = "..."

Definition at line 35 of file constants.cpp.

Referenced by utils::ellipsis_truncate(), and relative_size().

◆ GOOD_COLOR

const color_t font::GOOD_COLOR {0 , 181, 26 }

◆ good_dmg_color

const color_t font::good_dmg_color {130, 240, 50 }

◆ GRAY_COLOR

const color_t font::GRAY_COLOR {136, 136, 136}

◆ inactive_ability_color

const color_t font::inactive_ability_color {146, 146, 146}

Definition at line 41 of file standard_colors.cpp.

Referenced by unit_abilities().

◆ inactive_details_color

const color_t font::inactive_details_color {146, 146, 146}

Definition at line 40 of file standard_colors.cpp.

Referenced by attack_info().

◆ inverse_table_

const inverse_table font::inverse_table_
static

Definition at line 589 of file text.cpp.

◆ LABEL_COLOR

const color_t font::LABEL_COLOR {107, 140, 255}

◆ LOBBY_COLOR

const color_t font::LOBBY_COLOR {187, 187, 187}

Definition at line 22 of file standard_colors.cpp.

◆ max_text_line_width

const std::size_t font::max_text_line_width = 4096

Definition at line 32 of file constants.cpp.

Referenced by relative_size().

◆ NORMAL_COLOR

const color_t font::NORMAL_COLOR {221, 221, 221}

◆ PETRIFIED_COLOR

const color_t font::PETRIFIED_COLOR {160, 160, 160}

Definition at line 28 of file standard_colors.cpp.

◆ race_color

const color_t font::race_color {166, 146, 117}

Definition at line 43 of file standard_colors.cpp.

◆ rendered_text_cache

pango_text_cache_t font::rendered_text_cache
static

The text texture cache.

Each time a specific bit of text is rendered, a corresponding texture is created and added to the cache. We don't store the surface since there isn't really any use for it. If we need texture size that can be easily queried.

Todo:
Figure out how this can be optimized with a texture atlas. It should be possible to store smaller bits of text in the atlas and construct new textures from them.

Definition at line 485 of file text.hpp.

Referenced by font::pango_text::render_and_get_texture(), and font::pango_text::rerender().

◆ SIZE_15

const int font::SIZE_15 = 15 * SIZE_NORMAL / 14

Definition at line 25 of file constants.cpp.

Referenced by display_chat_manager::add_chat_message().

◆ SIZE_LARGE

const int font::SIZE_LARGE = 18 * SIZE_NORMAL / 14

Definition at line 27 of file constants.cpp.

◆ SIZE_NORMAL

const int font::SIZE_NORMAL = 14

Definition at line 19 of file constants.cpp.

Referenced by terrain_label::draw().

◆ SIZE_PLUS

const int font::SIZE_PLUS = 16 * SIZE_NORMAL / 14

Definition at line 26 of file constants.cpp.

Referenced by display::set_diagnostic().

◆ SIZE_SMALL

const int font::SIZE_SMALL = 12 * SIZE_NORMAL / 14

◆ SIZE_TINY

const int font::SIZE_TINY = 10 * SIZE_NORMAL / 14

Definition at line 22 of file constants.cpp.

◆ SIZE_TITLE

const int font::SIZE_TITLE = 20 * SIZE_NORMAL / 14

Definition at line 28 of file constants.cpp.

◆ SIZE_XLARGE

const int font::SIZE_XLARGE = 24 * SIZE_NORMAL / 14

Definition at line 29 of file constants.cpp.

Referenced by display::announce(), and game_display::float_label().

◆ TITLE_COLOR

const color_t font::TITLE_COLOR {186, 172, 125}

◆ unicode_bullet

const std::string font::unicode_bullet = "•"

◆ unicode_em_dash

const std::string font::unicode_em_dash = "—"

◆ unicode_en_dash

const std::string font::unicode_en_dash = "–"

◆ unicode_figure_dash

const std::string font::unicode_figure_dash = "‒"

◆ unicode_minus

const std::string font::unicode_minus = "-"

◆ unicode_multiplication_sign

const std::string font::unicode_multiplication_sign = "×"

◆ unit_type_color

const color_t font::unit_type_color {245, 230, 193}

◆ weapon_color

const color_t font::weapon_color {245, 230, 193}

◆ weapon_details_color

const color_t font::weapon_details_color {166, 146, 117}

◆ weapon_details_sep

const std::string font::weapon_details_sep = "–"

◆ weapon_numbers_sep

const std::string font::weapon_numbers_sep = "×"

◆ YELLOW_COLOR

const color_t font::YELLOW_COLOR {255, 255, 0 }