--- rxvt-unicode/src/rxvtfont.C 2014/11/14 11:06:49 1.194 +++ rxvt-unicode/src/rxvtfont.C 2021/06/17 19:37:28 1.206 @@ -241,7 +241,7 @@ #if XFT Picture dst; -# ifdef HAVE_BG_PIXMAP +# ifdef HAVE_IMG if (term->bg_img && !term->pix_colors[color].is_opaque () && ((dst = XftDrawPicture (d)))) @@ -264,7 +264,8 @@ ///////////////////////////////////////////////////////////////////////////// -struct rxvt_font_default : rxvt_font { +struct rxvt_font_default : rxvt_font +{ struct rxvt_fontset *fs; rxvt_font_default (rxvt_fontset *fs) @@ -314,8 +315,8 @@ return true; #endif - if (IS_COMPOSE (unicode)) - return true; + // we do not check for IS_COMPOSE here, as this would + // rob other fonts from taking over. switch (unicode) { @@ -346,15 +347,15 @@ while (len) { -#if ENABLE_COMBINING - compose_char *cc; -#endif const text_t *tp = text; text_t t = *tp; while (++text, --len && *text == NOCHAR) ; +#if ENABLE_COMBINING + compose_char *cc; +#endif int width = text - tp; int fwidth = term->fwidth * width; @@ -446,7 +447,6 @@ else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) { min_it (width, 2); // we only support wcwidth up to 2 - text_t chrs[2]; chrs [1] = NOCHAR; @@ -476,6 +476,15 @@ case NOCHAR: break; + /* + * If the base font does not support variation selectors, treat them as ZWC. + * a point could be made to do this for all wcwidth == 0 characters, but I + * decided against that until more data is available. + */ + case 0xfe00: case 0xfe01: case 0xfe02: case 0xfe03: case 0xfe04: case 0xfe05: case 0xfe06: case 0xfe07: + case 0xfe08: case 0xfe09: case 0xfe0a: case 0xfe0b: case 0xfe0c: case 0xfe0d: case 0xfe0e: case 0xfe0f: + break; + default: XDrawRectangle (disp, d, gc, x + 2, y + 2, fwidth - 4, term->fheight - 4); @@ -485,7 +494,8 @@ } } -struct rxvt_font_overflow : rxvt_font { +struct rxvt_font_overflow : rxvt_font +{ struct rxvt_fontset *fs; rxvt_font_overflow (rxvt_fontset *fs) @@ -541,7 +551,8 @@ ///////////////////////////////////////////////////////////////////////////// -struct rxvt_font_x11 : rxvt_font { +struct rxvt_font_x11 : rxvt_font +{ rxvt_font_x11 () { f = 0; } void clear (); @@ -1126,8 +1137,12 @@ #if XFT -struct rxvt_font_xft : rxvt_font { - rxvt_font_xft () { f = 0; } +struct rxvt_font_xft : rxvt_font +{ + rxvt_font_xft () + { + f = 0; + } void clear (); @@ -1279,12 +1294,8 @@ if (!width) { - rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); - - XftFontClose (disp, f); - f = 0; - - success = false; + rxvt_warn ("unable to calculate font width for '%s', using max_advance_width.\n", name); + width = f->max_advance_width; break; } @@ -1329,19 +1340,26 @@ { careful = false; - if (!XftCharExists (term->dpy, f, unicode)) + rxvt_compose_expand_static exp; + FcChar32 *chrs = exp (unicode); + int nchrs = exp.length (chrs); + + // we handle the sequence if the first char is available + if (!XftCharExists (term->dpy, f, chrs [0])) return false; if (!prop || prop->width == rxvt_fontprop::unset) return true; + // but we check against the whoile sequence bounding box + // check character against base font bounding box FcChar32 ch = unicode; XGlyphInfo g; - XftTextExtents32 (term->dpy, f, &ch, 1, &g); + XftTextExtents32 (term->dpy, f, chrs, nchrs, &g); int w = g.width - g.x; - int wcw = max (WCWIDTH (unicode), 1); + int wcw = max (WCWIDTH (chrs [0]), 1); careful = g.x > 0 || w > prop->width * wcw; @@ -1361,8 +1379,9 @@ 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; @@ -1383,24 +1402,36 @@ while (len) { int cwidth = term->fwidth; - FcChar32 fc = *text++; len--; + + 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); + FT_UInt glyphs [rxvt_compose_expand_static::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->glyph = glyph; - ep->x = x_ + (cwidth - extents.xOff >> 1); - ep->y = y_ + ascent; + ep.x = x_ + (cwidth - extents.xOff >> 1); + ep.y = y_ + ascent; if (extents.xOff == 0) - ep->x = x_ + cwidth; + ep.x = x_ + cwidth; - ep++; + for (int i = 0; i < nchrs; ++i) + { + ep.glyph = glyphs [i]; + enc.push_back (ep); + } } x_ += cwidth; @@ -1408,11 +1439,11 @@ if (buffered) { - if (ep != enc) + if (!enc.empty ()) { rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); -#ifdef HAVE_BG_PIXMAP +#ifdef HAVE_IMG Picture dst = 0; // the only assignment is done conditionally in the following if condition if (term->bg_img @@ -1464,7 +1495,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 @@ -1473,7 +1504,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 ()); } } @@ -1608,7 +1639,7 @@ rxvt_warn ("unknown parameter '%s' in font specification, skipping.\n", spec); desc++; - while (*desc <= ' ') desc++; + while (*desc <= ' ' && *desc) desc++; } end = strchr (desc, ','); @@ -1679,15 +1710,16 @@ int rxvt_fontset::find_font_idx (unicode_t unicode) { - if (unicode >= 1<<20) + // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 + if (unicode > 0x1fffff) return 0; unicode_t hi = unicode >> 8; - if (hi < fmap.size () - && fmap[hi] - && (*fmap[hi])[unicode & 0xff] != 0xff) - return (*fmap[hi])[unicode & 0xff]; + if (hi < fmap.size ()) + if (pagemap *pm = fmap[hi]) + if ((*pm)[unicode & 0xff] != 0xff) + return (*pm)[unicode & 0xff]; unsigned int i; @@ -1721,6 +1753,11 @@ next_font: if (i == fonts.size () - 1) { + // compose characters are handled by the default font, unless another font takes over + // we do not go via the fallback list for speed reasons. + if (IS_COMPOSE (unicode)) + return 0; + if (fallback->name) { // search through the fallback list @@ -1736,6 +1773,7 @@ // TODO: this is a real resource hog, xft takes ages(?) #if XFT && USE_SLOW_LOOKUP // grab the first xft font that seems suitable + // TOOD: should go first for cellchar (spacing 110) then mono, then else FcPattern *p = FcPatternCreate (); FcCharSet *s = FcCharSetCreate ();