--- rxvt-unicode/src/rxvtfont.C 2008/01/26 14:26:49 1.147 +++ rxvt-unicode/src/rxvtfont.C 2010/03/31 21:52:05 1.160 @@ -81,8 +81,8 @@ #if ENCODING_JP || ENCODING_JP_EXT # if XFT // prefer xft for complex scripts - { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" }, + { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, # endif @@ -218,13 +218,13 @@ } void -rxvt_font::set_name (char *name) +rxvt_font::set_name (char *name_) { - if (this->name == name) + if (name == name_) return; - if (this->name) free (this->name); // let the compiler optimize - this->name = name; + if (name) free (name); // let the compiler optimize + name = name_; } void @@ -484,6 +484,56 @@ } } +struct rxvt_font_meta : rxvt_font { + struct rxvt_fontset *fs; + + rxvt_font_meta (rxvt_fontset *fs) + : rxvt_font () + { + this->fs = fs; + } + + rxvt_fontprop properties () + { + rxvt_fontprop p; + + p.width = p.height = 1; + p.ascent = rxvt_fontprop::unset; + p.weight = rxvt_fontprop::medium; + p.slant = rxvt_fontprop::roman; + + return p; + } + + bool load (const rxvt_fontprop &prop, bool force_prop) + { + width = 1; height = 1; + ascent = 1; descent = 0; + + set_name (strdup ("built-in meta font")); + + return true; + } + + bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const + { + return false; + } + + void draw (rxvt_drawable &d, int x, int y, + const text_t *text, int len, + int fg, int bg) + { + while (len--) + { + int fid = fs->find_font_idx (*text); + (*fs)[fid]->draw (d, x, y, text, 1, fg, bg); + ++text; + x += term->fwidth; + } + } +}; + ///////////////////////////////////////////////////////////////////////////// struct rxvt_font_x11 : rxvt_font { @@ -501,7 +551,7 @@ const text_t *text, int len, int fg, int bg); - bool slow; // wether this is a proportional font or has other funny characteristics + bool slow; // whether this is a proportional font or has other funny characteristics XFontStruct *f; bool enc2b, encm; @@ -794,14 +844,23 @@ char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); + cs = CS_UNKNOWN; + if (registry && encoding) { char charset[64]; snprintf (charset, 64, "%s-%s", registry, encoding); cs = codeset_from_name (charset); + + if (cs == CS_UNKNOWN) + rxvt_warn ("%s: cannot deduce encoding from registry/encoding properties \"%s\", ignoring font.\n", name, charset); } - else + + free (registry); + free (encoding); + + if (cs == CS_UNKNOWN) { const char *charset = get_property (f, XA_FONT, 0); @@ -814,10 +873,15 @@ break; cs = codeset_from_name (charset); + if (cs == CS_UNKNOWN) + rxvt_warn ("%s: cannot deduce encoding from font name property \"%s\", ignoring font.\n", name, charset); } - free (registry); - free (encoding); + if (cs == CS_UNKNOWN) + { + clear (); + return false; + } if (cs == CS_UNICODE) cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font @@ -874,14 +938,6 @@ if (width < g.width) width = g.width; } - if (cs == CS_UNKNOWN) - { - fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); - - clear (); - return false; - } - #if 0 // do it per-character if (prop && width > prop->width) { @@ -911,7 +967,7 @@ if (ch == NOCHAR) return false; - /* check wether the character exists in _this_ font. horrible. */ + /* check whether the character exists in _this_ font. horrible. */ XCharStruct *xcs; if (encm) @@ -951,7 +1007,7 @@ if (!prop || prop->width == rxvt_fontprop::unset) return true; - // check wether character overlaps previous/next character + // check whether character overlaps previous/next character int w = xcs->rbearing - xcs->lbearing; int wcw = max (WCWIDTH (unicode), 1); @@ -1135,7 +1191,7 @@ #if 0 // clipping unfortunately destroys our precious double-width-characters // clip width, we can't do better, or can we? if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) - FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); + FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); #endif if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) @@ -1289,7 +1345,7 @@ int fg, int bg) { XGlyphInfo extents; - XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); + XftGlyphSpec *enc = rxvt_temp_buf (len); XftGlyphSpec *ep = enc; dTermDisplay; @@ -1299,7 +1355,7 @@ int h = term->fheight; bool buffered = bg >= Color_transparent - && term->option (Opt_buffered); + && term->option (Opt_buffered); // cut trailing spaces while (len && text [len - 1] == ' ') @@ -1582,7 +1638,7 @@ } int -rxvt_fontset::find_font (unicode_t unicode) +rxvt_fontset::find_font_idx (unicode_t unicode) { if (unicode >= 1<<20) return 0; @@ -1671,7 +1727,7 @@ if (find_font (font) < 0) { char fontname[4096]; - sprintf (fontname, "xft:%-.4090s", font); + snprintf (fontname, sizeof (fontname), "xft:%s", font); fonts.push_back (new_font (fontname, CS_UNICODE)); } @@ -1705,5 +1761,10 @@ return i; } +int +rxvt_fontset::find_font (unicode_t unicode) +{ + int id = find_font_idx (unicode); - + return min (fontCount, id & 127) | (id & 128 ? Careful : 0); +}