--- rxvt-unicode/src/defaultfont.C 2004/03/16 06:04:28 1.47 +++ rxvt-unicode/src/defaultfont.C 2004/08/02 04:42:11 1.56 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------*; +/*--------------------------------*-C-*---------------------------------* * File: defaultfont.C *----------------------------------------------------------------------* * Copyright (c) 2003-2004 Marc Lehmann @@ -32,28 +32,28 @@ codeset cs; const char *name; } fallback_fonts[] = { - { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, - { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, - { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, - -#if ENCODING_EU - // cyrillic - { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, - { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, - - { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, - { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, - { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, - { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, - { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, - { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, - { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, - { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, - { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, - { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, - { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, - { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, - { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, + { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, + { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, + { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, + +#if ENCODING_EU + // cyrillic + { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, + { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, + + { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, + { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, + { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, + { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, + { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, + { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, + { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, + { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, + { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, + { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, + { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, + { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, + { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, #endif // japanese @@ -65,6 +65,9 @@ { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, + { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, + { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, + { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, #endif #if ENCODING_CN || ENCODING_CN_EXT @@ -91,9 +94,9 @@ #if XFT { CS_UNICODE, "xft:Andale Mono" }, { CS_UNICODE, "xft:Arial Unicode MS" }, + { CS_UNICODE, "xft:FreeMono" }, #endif { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, - { CS_UNICODE, "xft:FreeMono" }, { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, @@ -135,6 +138,7 @@ { free (enc_buf); enc_buf = malloc (len); + enc_len = len; } return enc_buf; @@ -232,7 +236,10 @@ if (unicode <= 0x001f) return true; - if (unicode >= 0x0080 && unicode <= 0x009f) + if (unicode <= 0x007f) + return false; + + if (unicode <= 0x009f) return true; if (unicode >= 0x2500 && unicode <= 0x259f) @@ -410,13 +417,13 @@ codeset cs; bool enc2b, encm; - const char *get_property (XFontStruct *f, const char *property, const char *repl) const; + char *get_property (XFontStruct *f, const char *property, const char *repl) const; bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); bool set_properties (rxvt_fontprop &p, XFontStruct *f); bool set_properties (rxvt_fontprop &p, const char *name); }; -const char * +char * rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const { unsigned long value; @@ -424,7 +431,7 @@ if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) return XGetAtomName (DISPLAY, value); else - return repl; + return rxvt_strdup (repl); } rxvt_fontprop @@ -449,9 +456,6 @@ bool rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) { - const char *weight = get_property (f, "WEIGHT_NAME", "medium"); - const char *slant = get_property (f, "SLANT", "r"); - unsigned long height; if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) return false; @@ -460,7 +464,15 @@ if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) avgwidth = 0; - return set_properties (p, height, weight, slant, avgwidth); + char *weight = get_property (f, "WEIGHT_NAME", "medium"); + char *slant = get_property (f, "SLANT", "r"); + + set_properties (p, height, weight, slant, avgwidth); + + free (weight); + free (slant); + + return true; } bool @@ -574,8 +586,8 @@ if (!f) return false; - const char *registry = get_property (f, "CHARSET_REGISTRY", 0); - const char *encoding = get_property (f, "CHARSET_ENCODING", 0); + char *registry = get_property (f, "CHARSET_REGISTRY", 0); + char *encoding = get_property (f, "CHARSET_ENCODING", 0); if (registry && encoding) { @@ -599,6 +611,9 @@ cs = codeset_from_name (charset); } + free (registry); + free (encoding); + if (cs == CS_UNICODE) cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font @@ -720,7 +735,6 @@ XGCValues v; v.foreground = r->PixColors[fg]; - v.background = r->PixColors[bg]; v.font = f->fid; if (enc2b) @@ -729,6 +743,7 @@ if (bg == Color_bg && !slow) { + v.background = r->PixColors[bg]; XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); } @@ -760,6 +775,7 @@ if (bg == Color_bg && !slow) { + v.background = r->PixColors[bg]; XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); } @@ -988,7 +1004,7 @@ ///////////////////////////////////////////////////////////////////////////// rxvt_fontset::rxvt_fontset (rxvt_t r) -: r (r) +: r (r), fontdesc (0) { clear (); } @@ -1004,6 +1020,8 @@ for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) FONT_UNREF (*i); + free (fontdesc); fontdesc = 0; + fonts.clear (); base_id = 0; base_prop.height = 0x7fffffff; @@ -1120,6 +1138,8 @@ { clear (); + fontdesc = strdup (desc); + fonts.push_back (new_font (0, CS_UNICODE)); realize_font (0); @@ -1145,9 +1165,11 @@ } int -rxvt_fontset::find_font (unicode_t unicode) +rxvt_fontset::find_font (unicode_t unicode, bool bold) { - for (unsigned int i = 0; i < fonts.size (); i++) + for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii + i < fonts.size (); + i++) { rxvt_font *f = fonts[i]; @@ -1160,7 +1182,13 @@ goto next_font; } - if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) + if (f->cs == CS_UNKNOWN) + goto next_font; + + if (bold && f->properties ().weight < rxvt_fontprop::bold) + goto next_font; + + if (f->has_codepoint (unicode)) return i; next_font: @@ -1172,6 +1200,10 @@ } } + // if no bold font found, use a regular one + if (bold) + return find_font (unicode); + return 0; /* we must return SOME font */ }