--- rxvt-unicode/src/rxvtfont.C 2009/03/29 13:36:03 1.150 +++ rxvt-unicode/src/rxvtfont.C 2010/03/30 23:38:02 1.157 @@ -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 @@ -450,7 +450,7 @@ chrs [1] = NOCHAR; *chrs = cc->c1; - rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; + rxvt_font *f1 = fs->get (cc->c1); f1->draw (d, x, y, chrs, width, fg, bg); if (cc->c2 != NOCHAR) @@ -461,7 +461,7 @@ *chrs = cc->c2; rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) ? f1 - : (*fs)[fs->find_font (cc->c2)]; + : fs->get (cc->c2); f2->draw (d, x, y, chrs, width, fg, Color_none); } @@ -794,14 +794,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 +823,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 +888,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) { @@ -1289,7 +1295,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; @@ -1582,17 +1588,23 @@ } int -rxvt_fontset::find_font (unicode_t unicode) +rxvt_fontset::find_font_idx (unicode_t unicode, bool &careful) { if (unicode >= 1<<20) return 0; unicode_t hi = unicode >> 8; - if (hi < fmap.size () - && fmap[hi] - && (*fmap[hi])[unicode & 0xff] != 0xff) - return (*fmap[hi])[unicode & 0xff]; + if (hi < fmap.size () && fmap[hi]) + { + unsigned char m = (*fmap[hi])[unicode & 0xff]; + + if (m != 0xff) + { + careful = m & 128; + return m & 127; + } + } unsigned int i; @@ -1615,14 +1627,8 @@ if (f->cs == CS_UNKNOWN) goto next_font; - bool careful; if (f->has_char (unicode, &prop, careful)) - { - if (careful) - i |= 128; - - goto found; - } + goto found; next_font: if (i == fonts.size () - 1) @@ -1671,7 +1677,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)); } @@ -1685,10 +1691,11 @@ /* we must return SOME font */ i = 0; + careful = false; found: // found a font, cache it - if (i < 255) + if (i < 127) { while (hi >= fmap.size ()) fmap.push_back (0); @@ -1699,11 +1706,18 @@ memset (fmap[hi], 0xff, sizeof (pagemap)); } - (*fmap[hi])[unicode & 0xff] = i; + (*fmap[hi])[unicode & 0xff] = i | (careful ? 128 : 0); } return i; } +int +rxvt_fontset::find_font (unicode_t unicode) +{ + bool careful; + int id = find_font_idx (unicode, careful); + return min (fontCount, id) | (careful ? Careful : 0); +}