From 72a4ec927033d0886d52dcd58d776d923202c411 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 13 Mar 2025 01:19:02 -0400 Subject: [PATCH] Font: make family_class a scoped enum --- src/display.cpp | 4 ++-- src/floating_label.cpp | 2 +- src/font/attributes.cpp | 1 - src/font/font_config.cpp | 4 ++-- src/font/font_config.hpp | 2 +- src/font/font_options.hpp | 21 +++++++++------------ src/font/sdl_ttf_compat.cpp | 8 ++++---- src/font/text.cpp | 2 +- src/font/text.hpp | 2 +- src/gui/core/canvas.cpp | 4 ++-- src/gui/core/widget_definition.cpp | 2 +- 11 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index c83f693b98b..764a1c30708 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1425,7 +1425,7 @@ void display::draw_label(const theme::label& label) } else if(text.empty() == false) { font::pango_text& renderer = font::get_text_renderer(); renderer.set_text(text, false); - renderer.set_family_class(font::FONT_SANS_SERIF); + renderer.set_family_class(font::family_class::sans_serif); renderer.set_font_size(label.font_size()); renderer.set_font_style(font::pango_text::STYLE_NORMAL); renderer.set_foreground_color(text_color); @@ -2960,7 +2960,7 @@ void display::draw_report(const std::string& report_name, bool tooltip_test) } text.set_link_aware(false) .set_text(t, true); - text.set_family_class(font::FONT_SANS_SERIF) + text.set_family_class(font::family_class::sans_serif) .set_font_size(item->font_size()) .set_font_style(font::pango_text::STYLE_NORMAL) .set_alignment(PANGO_ALIGN_LEFT) diff --git a/src/floating_label.cpp b/src/floating_label.cpp index 156fa498f13..63132ef04b4 100644 --- a/src/floating_label.cpp +++ b/src/floating_label.cpp @@ -123,7 +123,7 @@ bool floating_label::create_texture() font::pango_text& text = font::get_text_renderer(); text.set_link_aware(false) - .set_family_class(font::FONT_SANS_SERIF) + .set_family_class(font::family_class::sans_serif) .set_font_size(font_size_) .set_font_style(font::pango_text::STYLE_NORMAL) .set_alignment(PANGO_ALIGN_LEFT) diff --git a/src/font/attributes.cpp b/src/font/attributes.cpp index 6f2e3af6c12..82de9d12b8a 100644 --- a/src/font/attributes.cpp +++ b/src/font/attributes.cpp @@ -166,7 +166,6 @@ void add_attribute_font_family(attribute_list& list, unsigned offset_start, unsi DBG_GUI_D << "attribute: font family"; DBG_GUI_D << "attribute start: " << offset_start << " end : " << offset_end; - DBG_GUI_D << "font family: " << family; attr.add_to(list); } diff --git a/src/font/font_config.cpp b/src/font/font_config.cpp index 6df9d01fe8f..ad19ccfa966 100644 --- a/src/font/font_config.cpp +++ b/src/font/font_config.cpp @@ -95,9 +95,9 @@ bool load_font_config() const t_string& get_font_families(family_class fclass) { switch(fclass) { - case FONT_MONOSPACE: + case family_class::monospace: return family_order_mono; - case FONT_SCRIPT: + case family_class::script: return family_order_script; default: return family_order_sans; diff --git a/src/font/font_config.hpp b/src/font/font_config.hpp index 20278d8c0a8..9a93a3a9124 100644 --- a/src/font/font_config.hpp +++ b/src/font/font_config.hpp @@ -51,6 +51,6 @@ struct manager { bool load_font_config(); /** Returns the currently defined fonts. */ -const t_string& get_font_families(family_class fclass = FONT_SANS_SERIF); +const t_string& get_font_families(family_class fclass); } // end namespace font diff --git a/src/font/font_options.hpp b/src/font/font_options.hpp index 14b4da281ee..2338a1f069e 100644 --- a/src/font/font_options.hpp +++ b/src/font/font_options.hpp @@ -20,25 +20,22 @@ namespace font { -/** - * Font classes for get_font_families(). - */ -enum family_class +enum class family_class { - FONT_SANS_SERIF, - FONT_MONOSPACE, - FONT_SCRIPT, + sans_serif, + monospace, + script, }; -inline family_class str_to_family_class(const std::string& str) +inline family_class decode_family_class(const std::string& str) { if(str == "monospace") { - return FONT_MONOSPACE; + return family_class::monospace; } else if(str == "script") { - return FONT_SCRIPT; + return family_class::script; + } else { + return family_class::sans_serif; } - - return FONT_SANS_SERIF; } } // end namespace font diff --git a/src/font/sdl_ttf_compat.cpp b/src/font/sdl_ttf_compat.cpp index d1032eb790c..4ef22b0392e 100644 --- a/src/font/sdl_ttf_compat.cpp +++ b/src/font/sdl_ttf_compat.cpp @@ -46,7 +46,7 @@ texture pango_render_text(const std::string& text, int size, const color_t& colo auto& ptext = private_renderer(); ptext.set_text(text, use_markup); - ptext.set_family_class(font::FONT_SANS_SERIF) + ptext.set_family_class(font::family_class::sans_serif) .set_font_size(size) .set_font_style(style) .set_maximum_height(-1, false) @@ -62,7 +62,7 @@ std::pair pango_line_size(const std::string& line, int font_size, font auto& ptext = private_renderer(); ptext.set_text(line, false); - ptext.set_family_class(font::FONT_SANS_SERIF) + ptext.set_family_class(font::family_class::sans_serif) .set_font_size(font_size) .set_font_style(font_style) .set_maximum_height(-1, false) @@ -84,7 +84,7 @@ std::string pango_word_wrap(const std::string& unwrapped_text, int font_size, in auto& ptext = private_renderer(); ptext.set_text(unwrapped_text, false); - ptext.set_family_class(font::FONT_SANS_SERIF) + ptext.set_family_class(font::family_class::sans_serif) .set_font_size(font_size) .set_font_style(font::pango_text::STYLE_NORMAL) .set_maximum_height(max_height, true) @@ -110,7 +110,7 @@ rect pango_draw_text(bool actually_draw, const rect& area, int size, const color auto& ptext = private_renderer(); ptext.set_text(text, false); - ptext.set_family_class(font::FONT_SANS_SERIF) + ptext.set_family_class(font::family_class::sans_serif) .set_font_size(size) .set_font_style(style) .set_maximum_width(-1) diff --git a/src/font/text.cpp b/src/font/text.cpp index d1b97167ec7..505b84d2fce 100644 --- a/src/font/text.cpp +++ b/src/font/text.cpp @@ -51,7 +51,7 @@ pango_text::pango_text() , markedup_text_(false) , link_aware_(false) , link_color_() - , font_class_(font::FONT_SANS_SERIF) + , font_class_(font::family_class::sans_serif) , font_size_(14) , font_style_(STYLE_NORMAL) , foreground_color_() // solid white diff --git a/src/font/text.hpp b/src/font/text.hpp index e146fe9a8d6..98c929e3066 100644 --- a/src/font/text.hpp +++ b/src/font/text.hpp @@ -534,7 +534,7 @@ pango_text& get_text_renderer(); * font. More specifically, the result is the sum of the maximum * ascent and descent lengths. */ -int get_max_height(unsigned size, font::family_class fclass = font::FONT_SANS_SERIF, pango_text::FONT_STYLE style = pango_text::STYLE_NORMAL); +int get_max_height(unsigned size, font::family_class fclass = font::family_class::sans_serif, pango_text::FONT_STYLE style = pango_text::STYLE_NORMAL); /* Returns the default line spacing factor * For now hardcoded here */ diff --git a/src/gui/core/canvas.cpp b/src/gui/core/canvas.cpp index eb317368e14..5d32620a9fb 100644 --- a/src/gui/core/canvas.cpp +++ b/src/gui/core/canvas.cpp @@ -415,7 +415,7 @@ auto parse_attributes(const config::const_child_itors& range) } else if (name == "font_size" || name == "size") { add_attribute_size(text_attributes, start, end, attr["value"].to_int(font::SIZE_NORMAL)); } else if (name == "font_family" || name == "face") { - add_attribute_font_family(text_attributes, start, end, font::str_to_family_class(attr["value"])); + add_attribute_font_family(text_attributes, start, end, font::decode_family_class(attr["value"])); } else if (name == "weight") { add_attribute_weight(text_attributes, start, end, decode_text_weight(attr["value"])); } else if (name == "style") { @@ -440,7 +440,7 @@ auto parse_attributes(const config::const_child_itors& range) text_shape::text_shape(const config& cfg, wfl::action_function_symbol_table& functions) : rect_bounded_shape(cfg) - , font_family_(font::str_to_family_class(cfg["font_family"])) + , font_family_(font::decode_family_class(cfg["font_family"])) , font_size_(cfg["font_size"], font::SIZE_NORMAL) , font_style_(decode_font_style(cfg["font_style"])) , text_alignment_(cfg["text_alignment"]) diff --git a/src/gui/core/widget_definition.cpp b/src/gui/core/widget_definition.cpp index 2be139bf01f..0d323e9a3b4 100644 --- a/src/gui/core/widget_definition.cpp +++ b/src/gui/core/widget_definition.cpp @@ -42,7 +42,7 @@ resolution_definition::resolution_definition(const config& cfg) , text_extra_width(cfg["text_extra_width"].to_unsigned()) , text_extra_height(cfg["text_extra_height"].to_unsigned()) , text_font_size(cfg["text_font_size"]) - , text_font_family(font::str_to_family_class(cfg["text_font_family"])) + , text_font_family(font::decode_family_class(cfg["text_font_family"])) , text_font_style(decode_font_style(cfg["text_font_style"])) , state() {