Fix #124068: Update Text Style Weights With Change of UI Font #124074
@ -110,6 +110,12 @@ void BLF_size(int fontid, float size);
|
||||
*/
|
||||
void BLF_character_weight(int fontid, int weight);
|
||||
|
||||
/* Return the font's default design weight (100-900). */
|
||||
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/* Return true if the font has a variable (multiple master) weight axis. */
|
||||
bool BLF_has_variable_weight(int fontid) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/* Goal: small but useful color API. */
|
||||
|
||||
void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
|
||||
|
@ -335,6 +335,28 @@ void BLF_character_weight(int fontid, int weight)
|
||||
}
|
||||
}
|
||||
|
||||
int BLF_default_weight(int fontid)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
if (font) {
|
||||
return font->metrics.weight;
|
||||
}
|
||||
return 400;
|
||||
}
|
||||
|
||||
bool BLF_has_variable_weight(int fontid)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
if (font && font->variations) {
|
||||
for (int i = 0; i < int(font->variations->num_axis); i++) {
|
||||
if (font->variations->axis[i].tag == BLF_VARIATION_AXIS_WEIGHT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BLF_aspect(int fontid, float x, float y, float z)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
@ -2033,6 +2033,10 @@ void UI_init_userdef();
|
||||
void UI_reinit_font();
|
||||
void UI_exit();
|
||||
|
||||
/* When changing UI font, update text style weights with default font weight
|
||||
* if non-variable. Therefore fixed weight bold font will look bold. */
|
||||
void UI_update_text_styles();
|
||||
|
||||
/* Layout
|
||||
*
|
||||
* More automated layout of buttons. Has three levels:
|
||||
|
@ -6611,6 +6611,20 @@ void UI_reinit_font()
|
||||
uiStyleInit();
|
||||
}
|
||||
|
||||
void UI_update_text_styles()
|
||||
{
|
||||
if (BLF_has_variable_weight(0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uiStyle *style = static_cast<uiStyle *>(U.uistyles.first);
|
||||
const int weight = BLF_default_weight(0);
|
||||
style->paneltitle.character_weight = weight;
|
||||
style->grouplabel.character_weight = weight;
|
||||
style->widgetlabel.character_weight = weight;
|
||||
style->widget.character_weight = weight;
|
||||
}
|
||||
|
||||
void UI_exit()
|
||||
{
|
||||
ui_resources_free();
|
||||
|
@ -314,6 +314,7 @@ static void rna_userdef_font_update(Main * /*bmain*/, Scene * /*scene*/, Pointer
|
||||
{
|
||||
BLF_cache_clear();
|
||||
UI_reinit_font();
|
||||
UI_update_text_styles();
|
||||
}
|
||||
|
||||
static void rna_userdef_language_update(Main *bmain, Scene * /*scene*/, PointerRNA * /*ptr*/)
|
||||
|
Loading…
Reference in New Issue
Block a user