1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 01:57:09 +00:00

Fix displaying UTF-8 without XFT

This commit is contained in:
Nikolas Garofil 2010-11-26 17:59:07 +01:00
parent 7310bff162
commit 99c359b212
3 changed files with 35 additions and 12 deletions

View File

@ -879,7 +879,7 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root)
} }
#ifdef BUILD_X11 #ifdef BUILD_X11
/* load any new fonts we may have had */ /* load any new fonts we may have had */
load_fonts(); load_fonts(utf8_mode.get(*state));
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
#ifdef BUILD_ICONV #ifdef BUILD_ICONV
free(buff_in); free(buff_in);
@ -1366,9 +1366,14 @@ static void draw_string(const char *s)
} else } else
#endif #endif
{ {
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, XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
strlen(s)); strlen(s));
} }
}
cur_x += width_of_s; cur_x += width_of_s;
} }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
@ -2514,7 +2519,7 @@ void clean_up_x11(void)
text_height + 2*border_total, 0); text_height + 2*border_total, 0);
} }
destroy_window(); destroy_window();
free_fonts(); free_fonts(utf8_mode.get(*state));
if(x11_stuff.region) { if(x11_stuff.region) {
XDestroyRegion(x11_stuff.region); XDestroyRegion(x11_stuff.region);
x11_stuff.region = NULL; x11_stuff.region = NULL;
@ -2628,7 +2633,7 @@ static void X11_create_window(void)
{ {
if (out_to_x.get(*state)) { if (out_to_x.get(*state)) {
setup_fonts(); setup_fonts();
load_fonts(); load_fonts(utf8_mode.get(*state));
update_text_area(); /* to position text/window on screen */ update_text_area(); /* to position text/window on screen */
#ifdef OWN_WINDOW #ifdef OWN_WINDOW

View File

@ -120,8 +120,7 @@ int add_font(const char *data_in)
return fonts.size()-1; return fonts.size()-1;
} }
void free_fonts(void) void free_fonts(bool utf8) {
{
if (not out_to_x.get(*state)) { if (not out_to_x.get(*state)) {
return; return;
} }
@ -141,6 +140,9 @@ void free_fonts(void)
if (fonts[i].font) { if (fonts[i].font) {
XFreeFont(display, fonts[i].font); XFreeFont(display, fonts[i].font);
} }
if (utf8 && fonts[i].fontset) {
XFreeFontSet(display, fonts[i].fontset);
}
} }
} }
fonts.clear(); fonts.clear();
@ -153,8 +155,7 @@ void free_fonts(void)
#endif /* BUILD_XFT */ #endif /* BUILD_XFT */
} }
void load_fonts(void) void load_fonts(bool utf8) {
{
if (not out_to_x.get(*state)) if (not out_to_x.get(*state))
return; return;
for (size_t i = 0; i < fonts.size(); i++) { for (size_t i = 0; i < fonts.size(); i++) {
@ -179,6 +180,20 @@ void load_fonts(void)
continue; continue;
} }
#endif #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 */ /* load normal font */
if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name.c_str())) == NULL) { 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()); NORM_ERR("can't load font '%s'", fonts[i].name.c_str());

View File

@ -40,6 +40,7 @@ struct font_list {
std::string name; std::string name;
XFontStruct *font; XFontStruct *font;
XFontSet fontset;
#ifdef BUILD_XFT #ifdef BUILD_XFT
XftFont *xftfont; XftFont *xftfont;
@ -51,7 +52,9 @@ struct font_list {
#ifdef BUILD_XFT #ifdef BUILD_XFT
, xftfont(NULL), font_alpha(0xffff) , xftfont(NULL), font_alpha(0xffff)
#endif #endif
{} {
fontset = NULL;
}
}; };
#ifdef BUILD_XFT #ifdef BUILD_XFT
@ -81,8 +84,8 @@ extern int selected_font;
void setup_fonts(void); void setup_fonts(void);
void set_font(void); void set_font(void);
int add_font(const char *); int add_font(const char *);
void free_fonts(void); void free_fonts(bool utf8);
void load_fonts(void); void load_fonts(bool utf8);
class font_setting: public conky::simple_config_setting<std::string> { class font_setting: public conky::simple_config_setting<std::string> {
typedef conky::simple_config_setting<std::string> Base; typedef conky::simple_config_setting<std::string> Base;