--- rxvt-unicode/src/rxvtfont.C 2021/06/17 11:45:19 1.204 +++ rxvt-unicode/src/rxvtfont.C 2021/06/18 01:50:14 1.208 @@ -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,40 +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; - - // some fonts claim they can render private use chars and then - // render them as boxes. - if (ecb_expect_false (IS_COMPOSE (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; } @@ -1408,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; @@ -1431,30 +1404,51 @@ 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 0 + FT_UInt glyphs [decltype (exp)::max_size]; - ep->glyph = glyph; - ep->x = x_ + (cwidth - extents.xOff >> 1); - ep->y = y_ + ascent; + for (int i = 0; i < nchrs; ++i) + glyphs [i] = XftCharIndex (disp, f, chrs [i]); - if (extents.xOff == 0) - ep->x = x_ + cwidth; + for (int i = 0; i < nchrs; ++i) + { + XGlyphInfo ep; + XftGlyphExtents (disp, f, glyphs+i, 1, &ep); + printf ("gs %x g %x + %d,%d o %d,%d wh %d,%d\n", chrs[i],glyphs[i],ep.x,ep.y,ep.xOff,ep.yOff,ep.width,ep.height); + } + #endif + + for (int i = 0; i < nchrs; ++i) + { + FT_UInt glyph = XftCharIndex (disp, f, chrs [i]); + XGlyphInfo extents; + XftGlyphExtents (disp, f, &glyph, 1, &extents); + + XftGlyphSpec ep; - ep++; + int cx = x_ + (cwidth - extents.xOff >> 1); + int cy = y_ + ascent; + + // lone combining char + if (extents.xOff == 0) + cx = x_ + cwidth; + + ep.glyph = glyph; + ep.x = cx + extents.x; + ep.y = cy; + + enc.push_back (ep); + } } x_ += cwidth; @@ -1462,7 +1456,7 @@ if (buffered) { - if (ep != enc) + if (!enc.empty ()) { rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); @@ -1518,7 +1512,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 @@ -1527,7 +1521,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 ()); } }