--- rxvt-unicode/src/rxvtfont.C 2021/06/17 11:21:52 1.203 +++ rxvt-unicode/src/rxvtfont.C 2021/06/18 21:58:03 1.209 @@ -214,7 +214,7 @@ ///////////////////////////////////////////////////////////////////////////// rxvt_font::rxvt_font () -: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset), can_compose(false) +: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) { } @@ -447,29 +447,6 @@ else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) { min_it (width, 2); // we only support wcwidth up to 2 - - #if NOT_YET - vector chrs; - chrs.reserve (rxvt_composite.expand (t)); - rxvt_composite.expand (t, &chrs[0]); - - while (!chrs.empty ()) - { - rxvt_font *f1 = fs->find_font_idx (chrs[0]) - - int i = 0; - while (i < chrs.size () - 1 - && f1->can_combine - && f1->has-char (chrs[i + 1], careful) - && !careful - ++i; - - (*fs)[f1]->draw (d, x, y, &chrs[0], width, fg, bg); - chrs.erase (&chrs[0], &chrs[i]); - } - #endif - - #if 1 text_t chrs[2]; chrs [1] = NOCHAR; @@ -489,7 +466,6 @@ f2->draw (d, x, y, chrs, width, fg, Color_none); } - #endif } #endif else @@ -1165,7 +1141,6 @@ { rxvt_font_xft () { - can_compose = true; f = 0; } @@ -1365,35 +1340,38 @@ { careful = false; -#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; -#endif - - if (!XftCharExists (term->dpy, f, unicode)) - return 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])) + return false; if (!prop || prop->width == rxvt_fontprop::unset) return true; - // check character against base font bounding box - FcChar32 ch = unicode; - XGlyphInfo g; - XftTextExtents32 (term->dpy, f, &ch, 1, &g); + int wcw = max (WCWIDTH (chrs [0]), 1); - int w = g.width - g.x; - int wcw = max (WCWIDTH (unicode), 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); - careful = g.x > 0 || w > prop->width * wcw; + int w = g.width - g.x; - if (careful && !OVERLAP_OK (w, wcw, prop)) - return false; + careful = g.x > 0 || w > prop->width * wcw; - // this weeds out _totally_ broken fonts, or glyphs - if (!OVERLAP_OK (g.xOff, wcw, prop)) - return false; + 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; } @@ -1403,9 +1381,9 @@ const text_t *text, int len, int fg, int bg) { - XGlyphInfo extents; - XftGlyphSpec *enc = rxvt_temp_buf (len); - XftGlyphSpec *ep = enc; + //XftGlyphSpec *enc = rxvt_temp_buf (len);//D + //XftGlyphSpec *ep = enc;//D + static vector enc; enc.resize (0); // static to avoid malloc, still slow dTermDisplay; dTermGC; @@ -1426,30 +1404,55 @@ while (len) { int cwidth = term->fwidth; - FcChar32 fc = *text++; len--; -#if ENABLE_COMBINING && !UNICODE_3 - if (ecb_expect_false (IS_COMPOSE (fc))) - if (compose_char *cc = rxvt_composite[fc]) // should always be true, but better be safe than sorry - fc = cc->c1; // c2 must be NOCHAR, as has_char handles it that way -#endif + rxvt_compose_expand_static exp; + FcChar32 *chrs = exp (*text++); len--; + int nchrs = exp.length (chrs); while (len && *text == NOCHAR) text++, len--, cwidth += term->fwidth; - if (fc != ' ') // skip spaces + if (chrs [0] != ' ') // skip spaces { - FT_UInt glyph = XftCharIndex (disp, f, fc); - XftGlyphExtents (disp, f, &glyph, 1, &extents); + #if 1 + FT_UInt glyphs [decltype (exp)::max_size]; + + for (int i = 0; i < nchrs; ++i) + glyphs [i] = XftCharIndex (disp, f, chrs [i]); + + for (int i = 0; i < nchrs; ++i) + { + 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, chrs [0]); + XGlyphInfo extents0; + XftGlyphExtents (disp, f, &glyph, 1, &extents0); + + int cx = x_ + (cwidth - extents0.xOff >> 1); + int cy = y_ + ascent; - ep->glyph = glyph; - ep->x = x_ + (cwidth - extents.xOff >> 1); - ep->y = y_ + ascent; + XftGlyphSpec ep; + ep.glyph = glyph; + ep.x = cx + (extents0.xOff ? 0 : extents0.xOff); + ep.y = cy; - if (extents.xOff == 0) - ep->x = x_ + cwidth; + enc.push_back (ep); - ep++; + for (int i = 1; ecb_expect_false (i < nchrs); ++i) + { + FT_UInt glyph = XftCharIndex (disp, f, chrs [i]); + XGlyphInfo extents; + XftGlyphExtents (disp, f, &glyph, 1, &extents); + + ep.glyph = glyph; + ep.x = cx + (extents.xOff ? 0 : extents0.xOff); + + enc.push_back (ep); + } } x_ += cwidth; @@ -1457,7 +1460,7 @@ if (buffered) { - if (ep != enc) + if (!enc.empty ()) { rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); @@ -1513,7 +1516,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, ep - enc); + XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); } else @@ -1522,7 +1525,7 @@ else { clear_rect (d, x, y, w, h, bg); - XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); + XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); } }