diff --git a/src/fontmacro.h b/src/fontmacro.h index bf1dca4fb..d8f530e65 100644 --- a/src/fontmacro.h +++ b/src/fontmacro.h @@ -43,12 +43,17 @@ #endif +// Prefer DejaVu but fallback to some other Sans provider if needed, +// influenced by :lang= later in yfontxft.cc. + #define FQUOT(x) #x #define FSIZE(x) ":size=" FQUOT(x) -#define FSANS "DejaVu Sans" FSIZE(12) -#define FBOLD FSANS ":bold" -#define FSMAL "DejaVu Sans" FSIZE(10) ":bold" -#define FMONO "DejaVu Sans Mono:monospace" FSIZE(12) -#define FMONB FMONO ":bold" +#define FSANSTOK "DejaVu Sans,Sans" +#define FBOLDTOK ":bold" +#define FSANS FSANSTOK FSIZE(12) +#define FBOLD FSANS FBOLDTOK +#define FSMAL FSANSTOK FSIZE(10) FBOLDTOK +#define FMONO "DejaVu Sans Mono,Sans Mono:monospace" FSIZE(12) +#define FMONB FMONO FBOLDTOK #endif diff --git a/src/yfontxft.cc b/src/yfontxft.cc index 4d09c9d33..0c2837026 100644 --- a/src/yfontxft.cc +++ b/src/yfontxft.cc @@ -109,6 +109,16 @@ YXftFont::YXftFont(mstring name, bool use_xlfd): if (use_xlfd) { font = XftFontOpenXlfd(xapp->display(), xapp->screen(), fname); } else { + + if (fname.find(":lang=") < 0) + { + auto lclocale = mstring(YLocale::getLcType()).lower(); + if (lclocale.length() >= 5 && lclocale[2] == '_') { + fname = fname + ":lang=" + lclocale.substring(0,2) + "-" + + lclocale.substring(3,2); + } + } + font = XftFontOpenName(xapp->display(), xapp->screen(), fname); } if (font) { diff --git a/src/ylocale.cc b/src/ylocale.cc index 73198c26d..945f5cfdf 100644 --- a/src/ylocale.cc +++ b/src/ylocale.cc @@ -322,6 +322,15 @@ char* YLocale::narrowString(const wchar_t* uStr, size_t uLen, size_t& lLen) { return dest; } +const char *YLocale::getLcType() +{ + auto cur_lctype = setlocale(LC_CTYPE, NULL); + if (cur_lctype == NULL) { + return "C"; + } + return cur_lctype; +} + const char *YLocale::getLocaleName() { #ifdef CONFIG_I18N return instance->converter->localeName(); diff --git a/src/ylocale.h b/src/ylocale.h index 75c2ef9dc..c02f9078e 100644 --- a/src/ylocale.h +++ b/src/ylocale.h @@ -27,6 +27,7 @@ class YLocale { static wchar_t* wideCharString(const char* str, size_t len, size_t& out); #endif static char* narrowString(const wchar_t* uStr, size_t uLen, size_t& lLen); + static const char* getLcType(); private: class YConverter* converter;