--- rxvt-unicode/src/rxvtfont.C 2009/04/04 21:27:53 1.152 +++ rxvt-unicode/src/rxvtfont.C 2010/12/18 18:17:38 1.169 @@ -28,6 +28,10 @@ #include +#if XFT +# include +#endif + #define MAX_OVERLAP_ROMAN (8 + 2) // max. character width in 8ths of the base width #define MAX_OVERLAP_ITALIC (8 + 3) // max. overlap for italic fonts @@ -37,7 +41,7 @@ : ((prop)->width * (wcw) * MAX_OVERLAP_ROMAN + 7) >> 3 \ )) -const struct rxvt_fallback_font { +static const struct rxvt_fallback_font { codeset cs; const char *name; } fallback_fonts[] = { @@ -157,8 +161,6 @@ 0x304c, 0x672c, // が本 }; -#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) - #define dTermDisplay Display *disp = term->dpy #define dTermGC GC gc = term->gc @@ -450,7 +452,7 @@ chrs [1] = NOCHAR; *chrs = cc->c1; - rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; + rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; f1->draw (d, x, y, chrs, width, fg, bg); if (cc->c2 != NOCHAR) @@ -461,7 +463,7 @@ *chrs = cc->c2; rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) ? f1 - : (*fs)[fs->find_font (cc->c2)]; + : (*fs)[fs->find_font_idx (cc->c2)]; f2->draw (d, x, y, chrs, width, fg, Color_none); } @@ -484,6 +486,56 @@ } } +struct rxvt_font_overflow : rxvt_font { + struct rxvt_fontset *fs; + + rxvt_font_overflow (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 rendition overflow 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 +553,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; @@ -866,7 +918,7 @@ width = 1; - for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) + for (uint16_t *t = extent_test_chars + ARRAY_LENGTH(extent_test_chars); t-- > extent_test_chars; ) { if (FROM_UNICODE (cs, *t) == NOCHAR) continue; @@ -917,7 +969,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) @@ -957,7 +1009,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); @@ -1184,7 +1236,7 @@ int glheight = height; - for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) + for (uint16_t *t = extent_test_chars + ARRAY_LENGTH(extent_test_chars); t-- > extent_test_chars; ) { FcChar16 ch = *t; @@ -1295,7 +1347,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; @@ -1355,7 +1407,7 @@ { int src_x = x, src_y = y; - if (term->bgPixmap.is_parentOrigin ()) + if (term->bgPixmap.flags & bgPixmap_t::isTransparent) { src_x += term->window_vt_x; src_y += term->window_vt_y; @@ -1434,7 +1486,7 @@ force_prop = false; for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) - FONT_UNREF (*i); + (*i)->unref (); for (pagemap **p = fmap.begin (); p != fmap.end (); p++) delete *p; @@ -1446,6 +1498,15 @@ fallback = fallback_fonts; } +void +rxvt_fontset::prepare_font (rxvt_font *font, codeset cs) +{ + font->set_term (term); + + font->cs = cs; + font->loaded = false; +} + rxvt_font * rxvt_fontset::new_font (const char *name, codeset cs) { @@ -1471,11 +1532,8 @@ else f = new rxvt_font_x11; - f->set_term (term); f->set_name (strdup (name)); - - f->cs = cs; - f->loaded = false; + prepare_font (f, cs); return f; } @@ -1483,6 +1541,23 @@ ///////////////////////////////////////////////////////////////////////////// void +rxvt_fontset::push_font (rxvt_font *font) +{ + // the fontCount index is reserved for the overflow font, it is only + // necessary when we get fontCount or more fonts, as they cannot be + // represented in the rendition. + if (fonts.size () == fontCount) + { + rxvt_font *f = new rxvt_font_overflow (this); + + prepare_font (f, CS_UNICODE); + fonts.push_back (f); + } + + fonts.push_back (font); +} + +void rxvt_fontset::add_fonts (const char *desc) { if (desc) @@ -1531,7 +1606,7 @@ memcpy (buf, desc, end - desc); buf[end - desc] = 0; - fonts.push_back (new_font (buf, cs)); + push_font (new_font (buf, cs)); } else rxvt_warn ("fontset element too long (>511 bytes), ignored."); @@ -1569,7 +1644,7 @@ fontdesc = strdup (desc); - fonts.push_back (new_font (0, CS_UNICODE)); + push_font (new_font (0, CS_UNICODE)); realize_font (0); add_fonts (desc); @@ -1588,7 +1663,7 @@ } int -rxvt_fontset::find_font (unicode_t unicode) +rxvt_fontset::find_font_idx (unicode_t unicode) { if (unicode >= 1<<20) return 0; @@ -1624,8 +1699,7 @@ bool careful; if (f->has_char (unicode, &prop, careful)) { - if (careful) - i |= 128; + i = (i << 1) | careful; goto found; } @@ -1636,7 +1710,7 @@ if (fallback->name) { // search through the fallback list - fonts.push_back (new_font (fallback->name, fallback->cs)); + push_font (new_font (fallback->name, fallback->cs)); fallback++; } else @@ -1677,9 +1751,9 @@ 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)); + push_font (new_font (fontname, CS_UNICODE)); } free (font); @@ -1711,5 +1785,3 @@ return i; } - -