--- rxvt-unicode/src/rxvtfont.C 2014/11/14 11:06:49 1.194 +++ rxvt-unicode/src/rxvtfont.C 2021/06/18 21:58:03 1.209 @@ -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,28 +1340,38 @@ { careful = false; - 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; } @@ -1360,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; @@ -1383,24 +1404,55 @@ 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); + #if 1 + 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 %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; + + XftGlyphSpec ep; + ep.glyph = glyph; + ep.x = cx + (extents0.xOff ? 0 : extents0.xOff); + ep.y = cy; + + 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; @@ -1408,11 +1460,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 +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 @@ -1473,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 ()); } } @@ -1608,7 +1660,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 +1731,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 +1774,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 +1794,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 ();