--- rxvt-unicode/src/defaultfont.h 2003/11/25 11:52:42 1.4 +++ rxvt-unicode/src/defaultfont.h 2004/08/11 01:36:51 1.21 @@ -1,16 +1,17 @@ -/* - * $Id: defaultfont.h,v 1.4 2003/11/25 11:52:42 pcg Exp $ - */ +#ifndef DEFAULTFONT_H_ +#define DEFAULTFONT_H_ -#ifndef _DEFAULTFONT_H_ -#define _DEFAULTFONT_H_ +#include +#if XFT +# include +#endif #ifdef HAVE_XSETLOCALE # define X_LOCALE # include #else # ifdef HAVE_SETLOCALE -# include +# include # endif #endif /* HAVE_XLOCALE */ @@ -18,25 +19,57 @@ # include #endif +#include + #include "rxvtlib.h" #include "feature.h" #include "encoding.h" -#include "rxvtvec.h" +#include "rxvtstl.h" + +struct rxvt_fontprop { + enum { + medium = 100, bold = 200, + roman = 0, italic = 100, + }; + int width, height; + int weight, slant; +}; + +struct rxvt_drawable { + rxvt_display *display; + Drawable drawable; +#if XFT + XftDraw *xftdrawable; + operator XftDraw *(); +#endif + + rxvt_drawable (rxvt_display *display, Drawable drawable) + : display(display), +#if XFT + xftdrawable(0), +#endif + drawable(drawable) + { } + +#if XFT + ~rxvt_drawable (); +#endif + + operator Drawable() { return drawable; } +}; struct rxvt_font { + struct rxvt_fontset *fs; // managed by the fontset -#if EXPLICIT_CONTEXT - rxvt_t rxvt_term; - void set_term (pR) { this->rxvt_term = R; } -#else - void set_term (pR) { } -#endif + rxvt_t r; + void set_term (rxvt_t r) { this->r = r; } + char *name; codeset cs; - bool loaded; + bool loaded; // wether we tried loading it before (not wether it's loaded) // managed by the font object - bool prop; // wether this is a proportional font or has other funny characteristics + bool slow; // wether this is a proportional font or has other funny characteristics int ascent, descent, width, height; @@ -47,36 +80,41 @@ } rxvt_font () { name = 0; } - ~rxvt_font () { free (name); clear (); }; + ~rxvt_font () { free (name); }; - void clear_rect (int x, int y, int w, int h, int color); + void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color); virtual void clear () { }; - virtual bool load (int maxheight) = 0; + virtual rxvt_fontprop properties () = 0; + + virtual bool load (const rxvt_fontprop &prop) = 0; virtual bool has_codepoint (uint32_t unicode) = 0; - virtual void draw (int x, int y, + virtual void draw (rxvt_drawable &d, + int x, int y, const text_t *text, int len, int fg, int bg) = 0; }; -//#define FONT_REF(obj) (obj)->refcnt++ -//#define FONT_UNREF(obj) if (!--(obj)->refcnt) delete (obj) -#define FONT_UNREF(f) delete f +#define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) struct rxvt_fallback_font; struct rxvt_fontset { - rxvt_fontset (pR); + char *fontdesc; + + rxvt_fontset (rxvt_t r); ~rxvt_fontset (); rxvt_font *new_font (const char *name, codeset cs); - void populate (const char *desc); - int find_font (uint32_t unicode); + bool populate (const char *desc); + int find_font (uint32_t unicode, bool bold = false); + int find_font (const char *name) const; - rxvt_font *operator [](int id) const + // font-id's MUST fit into a signed 16 bit integer. + rxvt_font *operator [] (int id) const { return fonts[id]; } @@ -87,13 +125,11 @@ } private: -#ifdef EXPLICIT_CONTEXT - rxvt_t rxvt_term; -#endif + rxvt_t r; simplevec fonts; const rxvt_fallback_font *fallback; - int height; + rxvt_fontprop base_prop; int base_id; bool realize_font (int i);