#include <wchar.h>
#include <inttypes.h>
-#define DISPLAY r->display->display
-#define TGC r->gc
-
#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width
const struct rxvt_fallback_font {
#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
+#define dTermDisplay Display *disp = term->display->display
+#define dTermGC GC gc = term->gc
+
/////////////////////////////////////////////////////////////////////////////
#if XFT
}
void
-rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color)
+rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
{
+ dTermDisplay;
+ dTermGC;
+
if (color == Color_bg)
- XClearArea (d.display->display, d, x, y, w, h, FALSE);
+ XClearArea (disp, d, x, y, w, h, FALSE);
else if (color >= 0)
{
#if XFT
- XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h);
+ XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
#else
- XSetForeground (d.display->display, TGC, r->pix_colors[color]);
- XFillRectangle (d.display->display, d, TGC, x, y, w, h);
+ XSetForeground (disp, gc, term->pix_colors[color]);
+ XFillRectangle (disp, d, gc, x, y, w, h);
#endif
}
}
return true;
}
- bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful)
+ bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
{
careful = false;
return true;
if (unicode >= 0x2500 && unicode <= 0x259f &&
- !r->option (Opt_skipBuiltinGlyphs))
+ !term->option (Opt_skipBuiltinGlyphs))
return true;
if (IS_COMPOSE (unicode))
const text_t *text, int len,
int fg, int bg)
{
- Display *disp = d.display->display;
+ dTermDisplay;
+ dTermGC;
- clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
+ clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
- XSetForeground (disp, TGC, r->pix_colors[fg]);
+ XSetForeground (disp, gc, term->pix_colors[fg]);
while (len)
{
;
int width = text - tp;
- int fwidth = r->fwidth * width;
+ int fwidth = term->fwidth * width;
if (0x2500 <= t && t <= 0x259f)
{
uint32_t *b = a + (offs & 15);
int W = fwidth;
- int H = r->fheight;
+ int H = term->fheight;
int x_[16];
int y_[16];
gcv.cap_style = CapButt;
gcv.line_width = 0;
- XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv);
+ XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
while (a < b)
{
switch (op)
{
case 0: // line
- XDrawLine (disp, d, TGC, x1, y1, x2, y2);
+ XDrawLine (disp, d, gc, x1, y1, x2, y2);
break;
case 1: // rectangle, possibly stippled
gcv.ts_x_origin = x;
gcv.ts_y_origin = y;
- XChangeGC (disp, TGC,
+ XChangeGC (disp, gc,
GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
&gcv);
}
- XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
+ XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
if (a)
{
XFreePixmap (disp, gcv.stipple);
gcv.stipple = 0;
gcv.fill_style = FillSolid;
- XChangeGC (disp, TGC, GCFillStyle, &gcv);
+ XChangeGC (disp, gc, GCFillStyle, &gcv);
}
break;
case 2: // arc
- XDrawArc (disp, d, TGC,
+ XDrawArc (disp, d, gc,
x1 - W/2, y1 - H/2, W-1, H-1,
(a - 1) * 90*64, (b - 1) * 90*64);
break;
break;
default:
- XDrawRectangle (disp, d, TGC, x + 2, y + 2,
- fwidth - 4, r->fheight - 4);
+ XDrawRectangle (disp, d, gc, x + 2, y + 2,
+ fwidth - 4, term->fheight - 4);
}
x += fwidth;
bool load (const rxvt_fontprop &prop);
- bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful);
+ bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
void draw (rxvt_drawable &d, int x, int y,
const text_t *text, int len,
{
unsigned long value;
- if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
- return XGetAtomName (DISPLAY, value);
+ if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
+ return XGetAtomName (term->display->display, value);
else
return rxvt_strdup (repl);
}
unsigned long height;
#if 0
- if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
+ if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
return false;
#else
height = f->ascent + f->descent;
#endif
unsigned long avgwidth;
- if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
+ if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
avgwidth = 0;
char *weight = get_property (f, "WEIGHT_NAME", "medium");
bool
rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
{
+ dTermDisplay;
int slashes = 0;
const char *comp[13];
&& (*comp[11] >= '0' && *comp[11] <= '9'))
return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
- XFontStruct *f = XLoadQueryFont (DISPLAY, name);
+ XFontStruct *f = XLoadQueryFont (disp, name);
if (f)
{
// (e.g. if the user did xset fp rehash just when we were searching fonts).
// in that case, just return garbage.
bool ret = set_properties (p, f);
- XFreeFont (DISPLAY, f);
+ XFreeFont (disp, f);
return ret;
}
else
bool
rxvt_font_x11::load (const rxvt_fontprop &prop)
{
- Display *disp = DISPLAY;
+ dTermDisplay;
clear ();
if (replace_field (fname, list[i], 6, '0', field_str))
diff += 10; // slightly penalize scalable fonts
else if (replace_field (fname, list[i], 11, '0', "0"))
- diff += 300; // more heavily penalize what looks like scaled bitmap fotns
+ diff += 300; // more heavily penalize what looks like scaled bitmap fonts
if (!set_properties (p, fname))
continue;
{
if (f)
{
- XFreeFont (DISPLAY, f);
+ XFreeFont (term->display->display, f);
f = 0;
}
}
bool
-rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful)
+rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
{
uint32_t ch = FROM_UNICODE (cs, unicode);
// yet we are trying to be perfect /.
// but the result still isn't perfect /.
+ dTermDisplay;
+ dTermGC;
+
bool slow = this->slow
- || width != r->fwidth
- || height != r->fheight;
+ || width != term->fwidth
+ || height != term->fheight;
- int base = ascent; // sorry, incorrect: r->fbase;
+ int base = ascent; // sorry, incorrect: term->fbase;
XGCValues v;
- v.foreground = r->pix_colors[fg];
+ v.foreground = term->pix_colors[fg];
v.font = f->fid;
if (enc2b)
if (bg == Color_bg && !slow)
{
- v.background = r->pix_colors[bg];
- XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
- XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
+ v.background = term->pix_colors[bg];
+ XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
+ XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
}
else
{
- clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
+ clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
- XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
+ XChangeGC (disp, gc, GCForeground | GCFont, &v);
if (slow)
{
do
{
if (xc->byte1 || xc->byte2)
- XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1);
+ XDrawString16 (disp, d, gc, x, y + base, xc, 1);
- x += r->fwidth;
+ x += term->fwidth;
xc++; len--;
}
while (len);
}
else
- XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len);
+ XDrawString16 (disp, d, gc, x, y + base, xc, len);
}
}
else
if (bg == Color_bg && !slow)
{
- v.background = r->pix_colors[bg];
- XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
- XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
+ v.background = term->pix_colors[bg];
+ XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
+ XDrawImageString (disp, d, gc, x, y + base, xc, len);
}
else
{
- clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
+ clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
- XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
+ XChangeGC (disp, gc, GCForeground | GCFont, &v);
if (slow)
{
do
{
if (*xc)
- XDrawString (d.display->display, d, TGC, x, y + base, xc, 1);
+ XDrawString (disp, d, gc, x, y + base, xc, 1);
- x += r->fwidth;
+ x += term->fwidth;
xc++; len--;
}
while (len);
}
else
- XDrawString (d.display->display, d, TGC, x, y + base, xc, len);
+ XDrawString (disp, d, gc, x, y + base, xc, len);
}
}
}
const text_t *text, int len,
int fg, int bg);
- bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull);
+ bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
protected:
XftFont *f;
{
if (f)
{
- XftFontClose (DISPLAY, f);
+ XftFontClose (term->display->display, f);
f = 0;
}
}
bool
rxvt_font_xft::load (const rxvt_fontprop &prop)
{
- Display *disp = DISPLAY;
+ dTermDisplay;
clear ();
set_name ((char *)FcNameUnparse (p));
XftResult result;
- FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result);
+ FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
FcPatternDestroy (p);
}
bool
-rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful)
+rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
{
careful = false;
- if (!XftCharExists (DISPLAY, f, unicode))
+ if (!XftCharExists (term->display->display, f, unicode))
return false;
if (!prop || prop->width == rxvt_fontprop::unset)
// check character against base font bounding box
FcChar32 ch = unicode;
XGlyphInfo g;
- XftTextExtents32 (DISPLAY, f, &ch, 1, &g);
+ XftTextExtents32 (term->display->display, f, &ch, 1, &g);
int w = g.width - g.x;
int wcw = wcwidth (unicode);
const text_t *text, int len,
int fg, int bg)
{
- clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
+ clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
XGlyphInfo extents;
XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec));
XftGlyphSpec *ep = enc;
+ dTermDisplay;
+ dTermGC;
+
// cut trailing spaces
while (len && text [len - 1] == ' ')
len--;
while (len)
{
- int cwidth = r->fwidth;
+ int cwidth = term->fwidth;
FcChar32 fc = *text++; len--;
while (len && *text == NOCHAR)
- text++, len--, cwidth += r->fwidth;
+ text++, len--, cwidth += term->fwidth;
if (fc != ' ') // skip spaces
{
- FT_UInt glyph = XftCharIndex (d.display->display, f, fc);
- XftGlyphExtents (d.display->display, f, &glyph, 1, &extents);
+ FT_UInt glyph = XftCharIndex (disp, f, fc);
+ XftGlyphExtents (disp, f, &glyph, 1, &extents);
ep->glyph = glyph;
ep->x = x + (cwidth - extents.xOff >> 1);
}
if (ep != enc)
- XftDrawGlyphSpec (d, &r->pix_colors[fg].c, f, enc, ep - enc);
+ XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
}
#endif
/////////////////////////////////////////////////////////////////////////////
-rxvt_fontset::rxvt_fontset (rxvt_t r)
-: fontdesc (0), r (r)
+rxvt_fontset::rxvt_fontset (rxvt_term *term)
+: fontdesc (0), term (term)
{
clear ();
}
else
f = new rxvt_font_x11;
- f->set_term (r);
+ f->set_term (term);
f->set_name (strdup (name));
f->cs = cs;
//FcPatternAddBool (p, FC_ANTIALIAS, 1);
XftResult result;
- FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result);
+ FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
FcPatternDestroy (p);