Skip to content

Commit

Permalink
LC_CTYPE specific hints to Xft selection
Browse files Browse the repository at this point in the history
This is not as smart as libpango and similar but should instruct Xft
sufficiently to select a Sans compatible font which actually brings the
required codeset.

Closes ice-wm/icewm#149
  • Loading branch information
Code7R committed Jan 2, 2024
1 parent 16ecff9 commit 2546db0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/fontmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/yfontxft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/ylocale.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/ylocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2546db0

Please sign in to comment.