--- rxvt-unicode/src/rxvtfont.h 2006/01/17 05:47:42 1.18 +++ rxvt-unicode/src/rxvtfont.h 2021/06/17 19:37:28 1.46 @@ -6,29 +6,16 @@ # include #endif -#ifdef HAVE_XSETLOCALE -# define X_LOCALE -# include -#else -# ifdef HAVE_SETLOCALE -# include -# endif -#endif /* HAVE_XLOCALE */ - -#ifdef HAVE_NL_LANGINFO -# include -#endif - #include -#include "feature.h" #include "encoding.h" #include "rxvtutil.h" #include "rxvttoolkit.h" struct rxvt_term; -struct rxvt_fontprop { +struct rxvt_fontprop +{ enum { unset = -1, medium = 100, bold = 200, @@ -38,45 +25,23 @@ int weight, slant; }; -struct rxvt_drawable { - rxvt_display *display; -#if XFT - XftDraw *xftdrawable; - operator XftDraw *(); -#endif - Drawable drawable; - - 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_font +{ // managed by the fontset rxvt_term *term; void set_term (rxvt_term *term) { this->term = term; } char *name; codeset cs; - bool loaded; // wether we tried loading it before (not wether it's loaded) + bool loaded; // whether we tried loading it before (not whether it's loaded) // managed by the font object int ascent, descent, width, height; - void set_name (char *name); + void set_name (char *name_); - rxvt_font () { name = 0; } + rxvt_font (); virtual ~rxvt_font () { free (name); }; virtual void clear () { }; @@ -85,49 +50,92 @@ virtual rxvt_fontprop properties () = 0; - virtual bool load (const rxvt_fontprop &morph) = 0; + virtual bool load (const rxvt_fontprop &morph, bool force_prop) = 0; virtual bool has_char (uint32_t unicode, const rxvt_fontprop *prop, bool &careful) const = 0; virtual void draw (rxvt_drawable &d, int x, int y, const text_t *text, int len, int fg, int bg) = 0; -}; -#define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) + void unref () + { + clear (); + delete this; + } +}; struct rxvt_fallback_font; -struct rxvt_fontset { +struct rxvt_fontset +{ char *fontdesc; + // must be power-of-two - 1, also has to match RS_fontMask in rxvt.h +#if USE_256_COLORS + enum { fontCount = 7 }; // 2 extra colors bits, 2 fewer fontcount bits +#else + enum { fontCount = 31 }; +#endif + + // index of first font in set + enum { firstFont = 2 }; + rxvt_fontset (rxvt_term *term); ~rxvt_fontset (); bool populate (const char *desc); - void set_prop (const rxvt_fontprop &prop) { this->prop = prop; } - int find_font (uint32_t unicode); + void set_prop (const rxvt_fontprop &prop, bool force_prop) { this->prop = prop; this->force_prop = force_prop; } + int find_font_idx (uint32_t unicode); int find_font (const char *name) const; bool realize_font (int i); - // font-id's MUST fit into a signed 16 bit integer, and within 0..255 rxvt_font *operator [] (int id) const { - return fonts[id & 0x7f]; + return fonts[id >> 1]; + } + + int + find_font (unicode_t unicode) + { + return min ((fontCount << 1) | 1, find_font_idx (unicode)); + } + + // find the font containing ' ' - we always assume this is font 1, as + // every font should contain space, and font 1 is our base font. + // pango assumes this, so it must be correct! + int + find_space_font () + { + return 1 << 1; } private: rxvt_term *term; rxvt_fontprop prop; + bool force_prop; simplevec fonts; const rxvt_fallback_font *fallback; - typedef unsigned char pagemap[256]; + // this once was a "typedef xxx pagemap[256] + // but c++ arrays are not normal types, and cannot be + // put into containers, new doesn't work for them etc. etc. + // so we wrap out array into an object that acts like one. doh. + // example: C++ has no separate new and new [] forms, + // and if pagemap is char[256], new incorrectly assumes we want to + // allocate an array of chars instead of a single pagemap. + struct pagemap + { + unsigned char cppsucks[256]; + unsigned char &operator [](int i) { return cppsucks [i]; }; + }; vector fmap; void clear (); rxvt_font *new_font (const char *name, codeset cs); + void prepare_font (rxvt_font *font, codeset cs); void add_fonts (const char *desc); + void push_font (rxvt_font *font); }; #endif /* _DEFAULTFONT_H_ */