Fonts: actually got light weight variant font support working
This replaces the broken implementation I added in fb6c85e70b
.
See documentation in data/hardwired/fonts.cfg for explanation as to why it didn't work and
why this does.
Currently "light" is set to Lato Light, which is weight 300. Regular is weight 400.
This commit is contained in:
parent
2e81aed96d
commit
6bd9740f53
6 changed files with 44 additions and 14 deletions
|
@ -1,15 +1,38 @@
|
|||
#textdomain wesnoth
|
||||
|
||||
[fonts]
|
||||
# This is marked as translatable, to allow translators to
|
||||
# provide different font orders: one just has to install the
|
||||
# missing fonts without needing to change the gmo files
|
||||
order=_ "Lato-Regular.ttf,DejaVuSans.ttf,Andagii.ttf,DroidSansJapanese.ttf,DroidSansFallbackFull.ttf,Junicode-Regular.ttf"
|
||||
family_order=_ "Lato"
|
||||
# NOTE: font order keys are marked as translatable to allow translators to
|
||||
# provide different font orders: one just has to install the missing fonts
|
||||
# or add them to wesnoth/fonts.
|
||||
|
||||
# Used by GUI2 only, hence no [font] blocks for these. The font files are
|
||||
# also automatically determined.
|
||||
family_order_monospace=_ "DejaVu Sans Mono"
|
||||
#
|
||||
# Pango text-related keys.
|
||||
#
|
||||
# All respective font files are automatically loaded.
|
||||
#
|
||||
# NOTE: these are technically supposed to be lists to provide fallbacks
|
||||
# like the SDL_TTF code does. However, there's a weird bug in Pango itself
|
||||
# where a comma seperated list of fonts will result in newlines not being
|
||||
# rendered and font space metrics being off on Windows.
|
||||
#
|
||||
# Additionally, despite what one might assume, "Lato" doesn't appear to
|
||||
# load all Lato font variants (it has a bunch of different weight ones).
|
||||
# I had thought one could specify different weights and Pango would
|
||||
# automatically use the variant for that weight, but no dice. Instead, we
|
||||
# need to set the weight variant we want as the distired font familt at
|
||||
# render time. Right now we only have use of a "light" variant, but others
|
||||
# could be added at some point.
|
||||
#
|
||||
# -- vultraz, 2018-02-14
|
||||
#
|
||||
family_order= _ "Lato"
|
||||
family_order_monospace= _ "DejaVu Sans Mono"
|
||||
family_order_light= _ "Lato Light"
|
||||
|
||||
#
|
||||
# Legagy SDL_TTF stuff.
|
||||
#
|
||||
order= _ "Lato-Regular.ttf,DejaVuSans.ttf,Andagii.ttf,DroidSansJapanese.ttf,DroidSansFallbackFull.ttf,Junicode-Regular.ttf"
|
||||
|
||||
[font]
|
||||
name="Lato-Regular.ttf"
|
||||
|
|
|
@ -99,6 +99,7 @@ static bool add_font_to_fontlist(const config &fonts_config,
|
|||
|
||||
t_string family_order_sans;
|
||||
t_string family_order_mono;
|
||||
t_string family_order_light;
|
||||
|
||||
/***
|
||||
* Public interface
|
||||
|
@ -141,12 +142,18 @@ bool load_font_config()
|
|||
|
||||
family_order_sans = fonts_config["family_order"];
|
||||
family_order_mono = fonts_config["family_order_monospace"];
|
||||
family_order_light = fonts_config["family_order_light"];
|
||||
|
||||
if(family_order_mono.empty()) {
|
||||
ERR_FT << "No monospace font family order defined, falling back to sans serif order\n";
|
||||
family_order_mono = family_order_sans;
|
||||
}
|
||||
|
||||
if(family_order_light.empty()) {
|
||||
ERR_FT << "No light font family order defined, falling back to sans serif order\n";
|
||||
family_order_light = family_order_sans;
|
||||
}
|
||||
|
||||
std::vector<font::subset_descriptor> fontlist;
|
||||
|
||||
for(auto font : utils::split(fonts_config["order"])) {
|
||||
|
@ -170,6 +177,8 @@ const t_string& get_font_families(family_class fclass)
|
|||
switch(fclass) {
|
||||
case FONT_MONOSPACE:
|
||||
return family_order_mono;
|
||||
case FONT_LIGHT:
|
||||
return family_order_light;
|
||||
default:
|
||||
return family_order_sans;
|
||||
}
|
||||
|
|
|
@ -25,13 +25,16 @@ namespace font
|
|||
enum family_class
|
||||
{
|
||||
FONT_SANS_SERIF,
|
||||
FONT_MONOSPACE
|
||||
FONT_MONOSPACE,
|
||||
FONT_LIGHT
|
||||
};
|
||||
|
||||
inline family_class str_to_family_class(const std::string& str)
|
||||
{
|
||||
if(str == "monospace") {
|
||||
return FONT_MONOSPACE;
|
||||
} else if(str == "light") {
|
||||
return FONT_LIGHT;
|
||||
}
|
||||
|
||||
return FONT_SANS_SERIF;
|
||||
|
|
|
@ -36,9 +36,6 @@ public:
|
|||
if(style & pango_text::STYLE_BOLD) {
|
||||
pango_font_description_set_weight(font_, PANGO_WEIGHT_BOLD);
|
||||
}
|
||||
if(style & pango_text::STYLE_LIGHT) {
|
||||
pango_font_description_set_weight(font_, PANGO_WEIGHT_LIGHT);
|
||||
}
|
||||
if(style & pango_text::STYLE_UNDERLINE) {
|
||||
/* Do nothing here, underline is a property of the layout. */
|
||||
}
|
||||
|
|
|
@ -140,7 +140,6 @@ public:
|
|||
STYLE_BOLD = 1,
|
||||
STYLE_ITALIC = 2,
|
||||
STYLE_UNDERLINE = 4,
|
||||
STYLE_LIGHT = 8,
|
||||
};
|
||||
|
||||
/***** ***** ***** ***** Query details ***** ***** ***** *****/
|
||||
|
|
|
@ -41,7 +41,6 @@ font::pango_text::FONT_STYLE decode_font_style(const std::string& style)
|
|||
{"bold", font::pango_text::STYLE_BOLD},
|
||||
{"italic", font::pango_text::STYLE_ITALIC},
|
||||
{"underline", font::pango_text::STYLE_UNDERLINE},
|
||||
{"light", font::pango_text::STYLE_LIGHT},
|
||||
};
|
||||
|
||||
if(style.empty()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue