--- rxvt-unicode/src/rxvtfont.C 2006/01/30 04:53:30 1.92 +++ rxvt-unicode/src/rxvtfont.C 2007/08/17 22:01:33 1.111 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: rxvtfont.C *----------------------------------------------------------------------* * Copyright (c) 2003-2006 Marc Lehmann @@ -160,29 +160,11 @@ #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) -#define dTermDisplay Display *disp = term->xdisp +#define dTermDisplay Display *disp = term->dpy #define dTermGC GC gc = term->gc ///////////////////////////////////////////////////////////////////////////// -#if XFT -rxvt_drawable::~rxvt_drawable () -{ - if (xftdrawable) - XftDrawDestroy (xftdrawable); -} - -rxvt_drawable::operator XftDraw *() -{ - if (!xftdrawable) - xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap); - - return xftdrawable; -} -#endif - -///////////////////////////////////////////////////////////////////////////// - static const char * enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) { @@ -252,7 +234,7 @@ dTermDisplay; dTermGC; - if (color == Color_bg) + if (color == Color_bg || color == Color_transparent) XClearArea (disp, d, x, y, w, h, false); else if (color >= 0) { @@ -290,7 +272,7 @@ return p; } - bool load (const rxvt_fontprop &prop) + bool load (const rxvt_fontprop &prop, bool force_prop) { width = 1; height = 1; ascent = 1; descent = 0; @@ -461,7 +443,7 @@ ? f1 : (*fs)[fs->find_font (cc->c2)]; - f2->draw (d, x, y, chrs, width, fg, -1); + f2->draw (d, x, y, chrs, width, fg, Color_none); } } #endif @@ -491,7 +473,7 @@ rxvt_fontprop properties (); - bool load (const rxvt_fontprop &prop); + bool load (const rxvt_fontprop &prop, bool force_prop); bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; @@ -501,7 +483,6 @@ bool slow; // wether this is a proportional font or has other funny characteristics XFontStruct *f; - codeset cs; bool enc2b, encm; char *get_property (XFontStruct *f, Atom property, const char *repl) const; @@ -516,7 +497,7 @@ unsigned long value; if (XGetFontProperty (f, property, &value)) - return XGetAtomName (term->xdisp, value); + return XGetAtomName (term->dpy, value); else return rxvt_strdup (repl); } @@ -549,7 +530,7 @@ unsigned long height; #if 0 - if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) + if (!XGetFontProperty (f, XInternAtom (term->dpy, "PIXEL_SIZE", 0), &height)) return false; #else height = f->ascent + f->descent; @@ -647,7 +628,7 @@ } bool -rxvt_font_x11::load (const rxvt_fontprop &prop) +rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop) { dTermDisplay; @@ -656,8 +637,7 @@ char field_str[64]; // enough for 128 bits // first morph the font if required - if (prop.weight != rxvt_fontprop::unset - || prop.slant != rxvt_fontprop::unset) + if (force_prop) { char fname[1024]; @@ -894,7 +874,7 @@ { if (f) { - XFreeFont (term->xdisp, f); + XFreeFont (term->dpy, f); f = 0; } } @@ -1059,7 +1039,7 @@ rxvt_fontprop properties (); - bool load (const rxvt_fontprop &prop); + bool load (const rxvt_fontprop &prop, bool force_prop); void draw (rxvt_drawable &d, int x, int y, const text_t *text, int len, @@ -1076,7 +1056,7 @@ { if (f) { - XftFontClose (term->xdisp, f); + XftFontClose (term->dpy, f); f = 0; } } @@ -1102,7 +1082,7 @@ } bool -rxvt_font_xft::load (const rxvt_fontprop &prop) +rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop) { dTermDisplay; @@ -1121,11 +1101,11 @@ FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); if (prop.weight != rxvt_fontprop::unset - && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) + && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)) FcPatternAddInteger (p, FC_WEIGHT, prop.weight); if (prop.slant != rxvt_fontprop::unset - && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) + && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)) FcPatternAddInteger (p, FC_SLANT, prop.slant); #if 0 // clipping unfortunately destroys our precious double-width-characters @@ -1253,7 +1233,7 @@ { careful = false; - if (!XftCharExists (term->xdisp, f, unicode)) + if (!XftCharExists (term->dpy, f, unicode)) return false; if (!prop || prop->width == rxvt_fontprop::unset) @@ -1262,7 +1242,7 @@ // check character against base font bounding box FcChar32 ch = unicode; XGlyphInfo g; - XftTextExtents32 (term->xdisp, f, &ch, 1, &g); + XftTextExtents32 (term->dpy, f, &ch, 1, &g); int w = g.width - g.x; int wcw = max (WCWIDTH (unicode), 1); @@ -1284,8 +1264,6 @@ const text_t *text, int len, int fg, int bg) { - clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); - XGlyphInfo extents; XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); XftGlyphSpec *ep = enc; @@ -1293,10 +1271,25 @@ dTermDisplay; dTermGC; + int w = term->fwidth * len; + int h = term->fheight; + + /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. + * Maybe make buffering into a resource flag? Compile time option doesn't seems like a + * good idea from the perspective of packaging for wide variety of user configs. + */ + bool buffered = true +#ifdef FORCE_UNBUFFERED_XFT + && bg >= 0 +#endif + ; // cut trailing spaces while (len && text [len - 1] == ' ') len--; + int x_ = buffered ? 0 : x; + int y_ = buffered ? 0 : y; + while (len) { int cwidth = term->fwidth; @@ -1310,23 +1303,90 @@ FT_UInt glyph = XftCharIndex (disp, f, fc); XftGlyphExtents (disp, f, &glyph, 1, &extents); - 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++; } - x += cwidth; + x_ += cwidth; } - if (ep != enc) - XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); + if (buffered) + { + if (ep != enc) + { + rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); + bool back_rendered = false; + +#ifdef HAVE_BG_PIXMAP + if (term->bgPixmap.pixmap && (bg < 0 || term->pix_colors[bg].c.color.alpha < 0x0ff00)) + { + if (term->bgPixmap.pmap_width >= x + term->window_vt_x+w + && term->bgPixmap.pmap_height >= y + term->window_vt_y+h) + { + XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, + x + term->window_vt_x, y + term->window_vt_y, + w, h, 0, 0); + } + else + { + XGCValues gcv; + + gcv.fill_style = FillTiled; + gcv.tile = term->bgPixmap.pixmap; + gcv.ts_x_origin = -x; + gcv.ts_y_origin = -y; + +#if 0 + GC gc2 = XCreateGC (disp, d2, + GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, + &gcv); +#endif + XChangeGC (disp, gc, + GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, + &gcv); + + XFillRectangle (disp, d2, gc/*gc2*/, 0, 0, w, h); + + gcv.fill_style = FillSolid; + XChangeGC (disp, gc, GCFillStyle, &gcv); + /* XFreeGC (disp, gc2); */ + + } + if (bg > 0) + { + Picture dst = XftDrawPicture(d2); + if (dst != 0) + { + Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); + XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); + } + } + back_rendered = true; + } +#endif + + if(bg > 0 && !back_rendered) + XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); + + XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); + XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); + } + else + clear_rect (d, x, y, w, h, bg); + } + else + { + clear_rect (d, x, y, w, h, bg); + XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); + } } + #endif ///////////////////////////////////////////////////////////////////////////// @@ -1347,6 +1407,7 @@ { prop.width = prop.height = prop.ascent = prop.weight = prop.slant = rxvt_fontprop::unset; + force_prop = false; for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) FONT_UNREF (*i); @@ -1468,7 +1529,7 @@ fonts[i]->loaded = true; - if (!fonts[i]->load (prop)) + if (!fonts[i]->load (prop, force_prop)) { fonts[i]->cs = CS_UNKNOWN; return false; @@ -1579,7 +1640,7 @@ //FcPatternAddBool (p, FC_ANTIALIAS, 1); XftResult result; - FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); + FcPattern *match = XftFontMatch (term->dpy, term->display->screen, p, &result); FcPatternDestroy (p);