diff --git a/src/conky.cc b/src/conky.cc index e6eae18f..ce9ee7df 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -879,7 +879,7 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root) } #ifdef BUILD_X11 /* load any new fonts we may have had */ - load_fonts(); + load_fonts(utf8_mode.get(*state)); #endif /* BUILD_X11 */ #ifdef BUILD_ICONV free(buff_in); @@ -1366,8 +1366,13 @@ static void draw_string(const char *s) } else #endif { - XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s, - strlen(s)); + if (utf8_mode.get(*state)) { + Xutf8DrawString(display, window.drawable, fonts[selected_font].fontset, window.gc, cur_x, cur_y, s, + strlen(s)); + } else { + XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s, + strlen(s)); + } } cur_x += width_of_s; } @@ -2514,7 +2519,7 @@ void clean_up_x11(void) text_height + 2*border_total, 0); } destroy_window(); - free_fonts(); + free_fonts(utf8_mode.get(*state)); if(x11_stuff.region) { XDestroyRegion(x11_stuff.region); x11_stuff.region = NULL; @@ -2628,7 +2633,7 @@ static void X11_create_window(void) { if (out_to_x.get(*state)) { setup_fonts(); - load_fonts(); + load_fonts(utf8_mode.get(*state)); update_text_area(); /* to position text/window on screen */ #ifdef OWN_WINDOW diff --git a/src/fonts.cc b/src/fonts.cc index 4d325d06..8d4178b9 100644 --- a/src/fonts.cc +++ b/src/fonts.cc @@ -120,8 +120,7 @@ int add_font(const char *data_in) return fonts.size()-1; } -void free_fonts(void) -{ +void free_fonts(bool utf8) { if (not out_to_x.get(*state)) { return; } @@ -141,6 +140,9 @@ void free_fonts(void) if (fonts[i].font) { XFreeFont(display, fonts[i].font); } + if (utf8 && fonts[i].fontset) { + XFreeFontSet(display, fonts[i].fontset); + } } } fonts.clear(); @@ -153,8 +155,7 @@ void free_fonts(void) #endif /* BUILD_XFT */ } -void load_fonts(void) -{ +void load_fonts(bool utf8) { if (not out_to_x.get(*state)) return; for (size_t i = 0; i < fonts.size(); i++) { @@ -179,6 +180,20 @@ void load_fonts(void) continue; } #endif + if(utf8 && fonts[i].fontset == NULL) { + char** missing; + int missingnum; + char* missingdrawn; + fonts[i].fontset = XCreateFontSet(display, fonts[i].name.c_str(), &missing, &missingnum, &missingdrawn); + XFreeStringList(missing); + if(fonts[i].fontset == NULL) { + NORM_ERR("can't load font '%s'", fonts[i].name.c_str()); + fonts[i].fontset = XCreateFontSet(display, "fixed", &missing, &missingnum, &missingdrawn); + if(fonts[i].fontset == NULL) { + CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); + } + } + } /* load normal font */ if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name.c_str())) == NULL) { NORM_ERR("can't load font '%s'", fonts[i].name.c_str()); diff --git a/src/fonts.h b/src/fonts.h index 5ac3c4f8..bacdffa6 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -40,6 +40,7 @@ struct font_list { std::string name; XFontStruct *font; + XFontSet fontset; #ifdef BUILD_XFT XftFont *xftfont; @@ -51,7 +52,9 @@ struct font_list { #ifdef BUILD_XFT , xftfont(NULL), font_alpha(0xffff) #endif - {} + { + fontset = NULL; + } }; #ifdef BUILD_XFT @@ -81,8 +84,8 @@ extern int selected_font; void setup_fonts(void); void set_font(void); int add_font(const char *); -void free_fonts(void); -void load_fonts(void); +void free_fonts(bool utf8); +void load_fonts(bool utf8); class font_setting: public conky::simple_config_setting { typedef conky::simple_config_setting Base;