--- rxvt-unicode/src/rxvtfont.C 2006/01/30 04:27:17 1.91 +++ rxvt-unicode/src/rxvtfont.C 2007/06/26 00:40:19 1.108 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: rxvtfont.C *----------------------------------------------------------------------* * Copyright (c) 2003-2006 Marc Lehmann @@ -131,21 +131,22 @@ # endif #endif - // generic font fallback { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, - { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, - { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, - { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, + //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs. #if XFT { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, - // FreeMono is usually uglier than x fonts, so try last only. + // FreeMono is usually uglier than x fonts, so try after the others { CS_UNICODE, "xft:FreeMono:autohint=true" }, #endif + // generic font fallback, put this last, as many iso10646 fonts have extents + // specified for all glyphs in the range they cover, but most are simply empty + //{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, + //{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, { CS_UNKNOWN, 0 } }; @@ -159,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) { @@ -251,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) { @@ -289,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; @@ -460,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 @@ -490,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; @@ -500,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; @@ -515,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); } @@ -548,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; @@ -646,7 +628,7 @@ } bool -rxvt_font_x11::load (const rxvt_fontprop &prop) +rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop) { dTermDisplay; @@ -655,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]; @@ -863,7 +844,8 @@ int dir_ret, asc_ret, des_ret; XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); - int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; + int wcw = WCWIDTH (*t); + if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; if (width < g.width) width = g.width; } @@ -892,7 +874,7 @@ { if (f) { - XFreeFont (term->xdisp, f); + XFreeFont (term->dpy, f); f = 0; } } @@ -947,7 +929,7 @@ // check wether character overlaps previous/next character int w = xcs->rbearing - xcs->lbearing; - int wcw = WCWIDTH (unicode); + int wcw = max (WCWIDTH (unicode), 1); careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; @@ -1057,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, @@ -1074,7 +1056,7 @@ { if (f) { - XftFontClose (term->xdisp, f); + XftFontClose (term->dpy, f); f = 0; } } @@ -1100,7 +1082,7 @@ } bool -rxvt_font_xft::load (const rxvt_fontprop &prop) +rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop) { dTermDisplay; @@ -1119,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 @@ -1251,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) @@ -1260,10 +1242,10 @@ // 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 = WCWIDTH (unicode); + int wcw = max (WCWIDTH (unicode), 1); careful = g.x > 0 || w > prop->width * wcw; @@ -1282,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; @@ -1291,10 +1271,24 @@ dTermDisplay; dTermGC; + int w = term->fwidth * len; + int h = term->fheight; + + bool buffered = bg >= 0 // we don't use a transparent bg +#ifndef FORCE_UNBUFFERED_XFT +# ifdef ENABLE_TRANSPARENCY + || !term->am_transparent // we aren't transparent +# endif +#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; @@ -1308,23 +1302,68 @@ 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); + + if (0) + ; +#ifdef ENABLE_TRANSPARENCY + else if (bg < 0 && term->am_pixmap_trans) + XCopyArea (disp, term->pixmap, d2, gc, + x + term->window_vt_x, y + term->window_vt_y, + w, h, 0, 0); +#endif +#ifdef XPM_BACKGROUND + else if (bg < 0 && term->bgPixmap.pixmap) + { + XGCValues gcv; + + gcv.fill_style = FillTiled; + gcv.tile = term->pixmap; + gcv.ts_x_origin = -x; + gcv.ts_y_origin = -y; + + GC gc2 = XCreateGC (disp, d2, + GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, + &gcv); + + XFillRectangle (disp, d2, gc2, 0, 0, w, h); + + XFreeGC (disp, gc2); + } +#endif + else + 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 ///////////////////////////////////////////////////////////////////////////// @@ -1345,6 +1384,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); @@ -1466,7 +1506,7 @@ fonts[i]->loaded = true; - if (!fonts[i]->load (prop)) + if (!fonts[i]->load (prop, force_prop)) { fonts[i]->cs = CS_UNKNOWN; return false; @@ -1577,7 +1617,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);