--- rxvt-unicode/src/rxvtfont.C 2021/06/17 19:42:55 1.207 +++ rxvt-unicode/src/rxvtfont.C 2021/06/18 22:12:30 1.211 @@ -1340,26 +1340,32 @@ { careful = false; - rxvt_compose_expand_static exp; - FcChar32 *chrs = exp (unicode); - int nchrs = exp.length (chrs); + // 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; - // we handle the sequence if the first char is available - if (!XftCharExists (term->dpy, f, chrs [0])) + if (!XftCharExists (term->dpy, f, chr)) return false; if (!prop || prop->width == rxvt_fontprop::unset) return true; - // but we check against the whole sequence bounding box + int wcw = max (WCWIDTH (chr), 1); - // check character against base font bounding box - FcChar32 ch = unicode; XGlyphInfo g; - XftTextExtents32 (term->dpy, f, chrs, nchrs, &g); + XftTextExtents32 (term->dpy, f, &chr, 1, &g); int w = g.width - g.x; - int wcw = max (WCWIDTH (chrs [0]), 1); careful = g.x > 0 || w > prop->width * wcw; @@ -1378,10 +1384,8 @@ const text_t *text, int len, int fg, int bg) { - XGlyphInfo extents; - //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; @@ -1402,36 +1406,57 @@ while (len) { int cwidth = term->fwidth; + FcChar32 chr = *text++; len--; - rxvt_compose_expand_static exp; - FcChar32 *chrs = exp (*text++); len--; - int nchrs = exp.length (chrs); + // 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 while (len && *text == NOCHAR) text++, len--, cwidth += term->fwidth; - if (chrs [0] != ' ') // skip spaces + if (chr != ' ') // skip spaces { - FT_UInt glyphs [rxvt_compose_expand_static::max_size]; + #if 0 + FT_UInt glyphs [decltype (exp)::max_size]; for (int i = 0; i < nchrs; ++i) glyphs [i] = XftCharIndex (disp, f, chrs [i]); - XftGlyphExtents (disp, f, glyphs, nchrs, &extents); - - XftGlyphSpec ep; - - ep.x = x_ + (cwidth - extents.xOff >> 1); - ep.y = y_ + ascent; - - if (extents.xOff == 0) - ep.x = x_ + cwidth; - for (int i = 0; i < nchrs; ++i) { - ep.glyph = glyphs [i]; - enc.push_back (ep); + XGlyphInfo ep; + XftGlyphExtents (disp, f, glyphs+i, 1, &ep); + printf ("gs %4x g %4x + %3d,%3d o %3d,%3d wh %3d,%3d\n", chrs[i],glyphs[i],ep.x,ep.y,ep.xOff,ep.yOff,ep.width,ep.height); } + #endif + + FT_UInt glyph = XftCharIndex (disp, f, chr); + XGlyphInfo extents; + XftGlyphExtents (disp, f, &glyph, 1, &extents); + + ep->glyph = glyph; + ep->x = x_; + ep->y = y_ + ascent; + + // the xft font cell might differ from the terminal font cell, + // in which we use the average between the two + ep->x += cwidth - extents.xOff >> 1; + + // 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 chaarcter here, but we don't have that, so we use cwidth. + ep->x += extents.xOff ? 0 : cwidth; + + ++ep; } x_ += cwidth; @@ -1439,7 +1464,7 @@ if (buffered) { - if (!enc.empty ()) + if (ep != enc) { rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); @@ -1495,7 +1520,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 @@ -1504,7 +1529,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); } }