--- rxvt-unicode/src/rxvtfont.C 2021/06/17 14:55:05 1.205 +++ rxvt-unicode/src/rxvtfont.C 2021/06/19 10:08:10 1.216 @@ -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,32 +1340,32 @@ { careful = false; + // handle non-bmp chars when text_t is 16 bit #if ENABLE_COMBINING && !UNICODE_3 - // handle non-BMP characters when our storage uses 16 bit if (ecb_expect_false (IS_COMPOSE (unicode))) - if (compose_char *cc = rxvt_composite[unicode]) + if (compose_char *cc = rxvt_composite [unicode]) if (cc->c2 == NOCHAR) unicode = cc->c1; + else + return false; + else + return false; #endif - if (!XftCharExists (term->dpy, f, unicode)) - return false; + FcChar32 chr = unicode; - // some fonts claim they can render private use chars and then - // render them as boxes. - if (ecb_expect_false (IS_COMPOSE (unicode))) + if (!XftCharExists (term->dpy, f, chr)) return false; if (!prop || prop->width == rxvt_fontprop::unset) return true; - // check character against base font bounding box - FcChar32 ch = unicode; + int wcw = max (WCWIDTH (chr), 1); + XGlyphInfo g; - XftTextExtents32 (term->dpy, f, &ch, 1, &g); + XftTextExtents32 (term->dpy, f, &chr, 1, &g); int w = g.width - g.x; - int wcw = max (WCWIDTH (unicode), 1); careful = g.x > 0 || w > prop->width * wcw; @@ -1409,7 +1384,6 @@ const text_t *text, int len, int fg, int bg) { - XGlyphInfo extents; XftGlyphSpec *enc = rxvt_temp_buf (len); XftGlyphSpec *ep = enc; @@ -1432,31 +1406,57 @@ while (len) { int cwidth = term->fwidth; - FcChar32 fc = *text++; len--; - -#if ENABLE_COMBINING && !UNICODE_3 - // handle non-BMP characters when our storage uses 16 bit - 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 + FcChar32 chr = *text++; len--; while (len && *text == NOCHAR) text++, len--, cwidth += term->fwidth; - if (fc != ' ') // skip spaces + if (chr != ' ') // skip spaces { - FT_UInt glyph = XftCharIndex (disp, f, fc); + // 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) + 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, chr); + XGlyphInfo extents; XftGlyphExtents (disp, f, &glyph, 1, &extents); ep->glyph = glyph; - ep->x = x_ + (cwidth - extents.xOff >> 1); + ep->x = x_; ep->y = y_ + ascent; - if (extents.xOff == 0) - ep->x = x_ + cwidth; + // the xft font cell might differ from the terminal font cell, + // in which case we use the average between the two. + ep->x += extents.xOff ? cwidth - extents.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 += extents.xOff ? 0 : cwidth; - ep++; + ++ep; } x_ += cwidth; @@ -1735,7 +1735,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;