--- rxvt-unicode/src/rxvtfont.C 2021/06/18 21:58:03 1.209 +++ rxvt-unicode/src/rxvtfont.C 2021/07/03 04:47:08 1.220 @@ -136,10 +136,10 @@ //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs. #if XFT - { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, - { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, - { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, - { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, + { CS_UNICODE, "xft:DejaVu Sans Mono:antialias=false:autohint=true" }, + { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, + { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, + { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, // FreeMono is usually uglier than x fonts, so try after the others { CS_UNICODE, "xft:FreeMono:autohint=true" }, @@ -1139,6 +1139,17 @@ struct rxvt_font_xft : rxvt_font { +#if XFT_CHAR_CACHE + // we cache the qascii range xoffsets in the name of speed, + // expecting terminals to deal mostly with these characters + // we also assume the xoff always fits into uint8_t, + // which is questionable, but let's see... + // also, it is uncomfortably big, due to the uints. + enum { char_cache_min = 0x20, char_cache_max = 0x7e }; + uint8_t xoff_cache [char_cache_max - char_cache_min + 1]; + FT_UInt glyph_cache [char_cache_max - char_cache_min + 1]; +#endif + rxvt_font_xft () { f = 0; @@ -1332,6 +1343,19 @@ } #endif +#if XFT_CHAR_CACHE + // populate char cache + for (FcChar16 ch = char_cache_min; ch <= char_cache_max; ++ch) + { + FT_UInt glyph = XftCharIndex (disp, f, ch); + glyph_cache [ch - char_cache_min] = glyph; + + XGlyphInfo g; + XftGlyphExtents (disp, f, &glyph, 1, &g); + xoff_cache [ch - char_cache_min] = g.xOff; + } +#endif + return success; } @@ -1340,38 +1364,47 @@ { careful = false; - rxvt_compose_expand_static exp; - FcChar32 *chrs = exp (unicode); - int nchrs = exp.length (chrs); - - // allm chars in sequence must be available - for (int i = 0; i < nchrs; ++i) - if (!XftCharExists (term->dpy, f, chrs [i])) + // handle non-bmp chars when text_t is 16 bit +#if ENABLE_COMBINING && !UNICODE_3 + if (ecb_expect_false (IS_COMPOSE (unicode))) + if (compose_char *cc = rxvt_composite [unicode]) + if (cc->c2 == NOCHAR) + unicode = cc->c1; + else + return false; + else return false; +#endif + + FcChar32 chr = unicode; + + if (!XftCharExists (term->dpy, f, chr)) + return false; if (!prop || prop->width == rxvt_fontprop::unset) return true; - int wcw = max (WCWIDTH (chrs [0]), 1); + int wcw = max (WCWIDTH (chr), 1); - // we check against all glyph sizes. this is probably wrong, - // due to the way ->draw positions these glyphs. - for (int i = 0; i < nchrs; ++i) - { - XGlyphInfo g; - XftTextExtents32 (term->dpy, f, chrs + i, 1, &g); + XGlyphInfo g; + XftTextExtents32 (term->dpy, f, &chr, 1, &g); - int w = g.width - g.x; + int cwidth = prop->width * wcw; - careful = g.x > 0 || w > prop->width * wcw; + // use same adjustments as in ->draw, see there + g.x += g.xOff ? cwidth - g.xOff >> 1 : 0; + g.x += g.xOff ? 0 : cwidth; - if (careful && !OVERLAP_OK (w, wcw, prop)) - return false; + int w = g.width - g.x; - // this weeds out _totally_ broken fonts, or glyphs - if (!OVERLAP_OK (g.xOff, wcw, prop)) - return false; - } + careful = g.x > 0 || w > cwidth; + + if (careful && !OVERLAP_OK (w, wcw, prop)) + return false; + + // this weeds out _totally_ broken fonts, or glyphs + if (!OVERLAP_OK (g.xOff, wcw, prop)) + return false; return true; } @@ -1381,9 +1414,8 @@ const text_t *text, int len, int fg, int bg) { - //XftGlyphSpec *enc = rxvt_temp_buf (len);//D - //XftGlyphSpec *ep = enc;//D - static vector enc; enc.resize (0); // static to avoid malloc, still slow + XftGlyphSpec *enc = rxvt_temp_buf (len); + XftGlyphSpec *ep = enc; dTermDisplay; dTermGC; @@ -1404,17 +1436,22 @@ while (len) { int cwidth = term->fwidth; - - rxvt_compose_expand_static exp; - FcChar32 *chrs = exp (*text++); len--; - int nchrs = exp.length (chrs); + FcChar32 chr = *text++; len--; while (len && *text == NOCHAR) text++, len--, cwidth += term->fwidth; - if (chrs [0] != ' ') // skip spaces + if (chr != ' ') // skip spaces { - #if 1 + // handle non-bmp chars when text_t is 16 bit + #if ENABLE_COMBINING && !UNICODE_3 + if (ecb_expect_false (IS_COMPOSE (chr))) + if (compose_char *cc = rxvt_composite [chr]) + if (cc->c2 == NOCHAR) + chr = cc->c1; + #endif + + #if 0 FT_UInt glyphs [decltype (exp)::max_size]; for (int i = 0; i < nchrs; ++i) @@ -1428,31 +1465,42 @@ } #endif - FT_UInt glyph = XftCharIndex (disp, f, chrs [0]); - XGlyphInfo extents0; - XftGlyphExtents (disp, f, &glyph, 1, &extents0); + FT_UInt glyph; + int xOff; - int cx = x_ + (cwidth - extents0.xOff >> 1); - int cy = y_ + ascent; - - XftGlyphSpec ep; - ep.glyph = glyph; - ep.x = cx + (extents0.xOff ? 0 : extents0.xOff); - ep.y = cy; - - enc.push_back (ep); - - for (int i = 1; ecb_expect_false (i < nchrs); ++i) + #if XFT_CHAR_CACHE + if (ecb_expect_true (IN_RANGE_INC (chr, char_cache_min, char_cache_max))) { - FT_UInt glyph = XftCharIndex (disp, f, chrs [i]); + glyph = glyph_cache [chr - char_cache_min]; + xOff = xoff_cache [chr - char_cache_min]; + } + else + #endif + { + glyph = XftCharIndex (disp, f, chr); XGlyphInfo extents; XftGlyphExtents (disp, f, &glyph, 1, &extents); + xOff = extents.xOff; + } - ep.glyph = glyph; - ep.x = cx + (extents.xOff ? 0 : extents0.xOff); + ep->glyph = glyph; + ep->x = x_; + ep->y = y_ + ascent; + + // the xft font cell might differ from the terminal font cell, + // in which case we use the average between the two. + ep->x += xOff ? cwidth - xOff >> 1 : 0; + + // xft/freetype represent combining characters as characters with zero + // width rendered over the previous character with some fonts, while + // in other fonts, they are considered normal characters, while yet + // in other fonts, they are shifted all over the place. + // we handle the first two cases by keying off on xOff being 0 + // for zero-width chars. normally, we would add extents.xOff + // of the base character here, but we don't have that, so we use cwidth. + ep->x += xOff ? 0 : cwidth; - enc.push_back (ep); - } + ++ep; } x_ += cwidth; @@ -1460,7 +1508,7 @@ if (buffered) { - if (!enc.empty ()) + if (ep != enc) { rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); @@ -1516,7 +1564,7 @@ #endif XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); - XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); + XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); } else @@ -1525,7 +1573,7 @@ else { clear_rect (d, x, y, w, h, bg); - XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); + XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); } } @@ -1731,7 +1779,7 @@ int rxvt_fontset::find_font_idx (unicode_t unicode) { - // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 + // this limits fmap size. it has to accommodate COMPOSE_HI when UNICODE_3 if (unicode > 0x1fffff) return 0;