*** empty log message ***
[dana/urxvt.git] / src / rxvtfont.h
1 #ifndef DEFAULTFONT_H_
2 #define DEFAULTFONT_H_
3
4 #include <X11/Xlib.h>
5 #if XFT
6 # include <X11/Xft/Xft.h>
7 #endif
8
9 #ifdef HAVE_XSETLOCALE
10 # define X_LOCALE
11 # include <X11/Xlocale.h>
12 #else
13 # ifdef HAVE_SETLOCALE
14 #  include <clocale>
15 # endif
16 #endif                          /* HAVE_XLOCALE */
17
18 #ifdef HAVE_NL_LANGINFO
19 # include <langinfo.h>
20 #endif
21
22 #include <inttypes.h>
23
24 #include "feature.h"
25 #include "encoding.h"
26 #include "rxvtutil.h"
27 #include "rxvttoolkit.h"
28
29 struct rxvt_term;
30
31 struct rxvt_fontprop {
32   enum {
33     unset  = -1,
34     medium = 100, bold = 200,
35     roman  = 0, italic = 100,
36   };
37   int width, height;
38   int weight, slant;
39 };
40
41 struct rxvt_drawable {
42   rxvt_display *display;
43   Drawable drawable;
44 #if XFT
45   XftDraw *xftdrawable;
46   operator XftDraw *();
47 #endif
48
49   rxvt_drawable (rxvt_display *display, Drawable drawable)
50   : display(display),
51 #if XFT
52     xftdrawable(0),
53 #endif
54     drawable(drawable)
55   { }
56
57 #if XFT
58   ~rxvt_drawable ();
59 #endif
60
61   operator Drawable() { return drawable; }
62 };
63
64 struct rxvt_font {
65   // managed by the fontset
66   rxvt_term *r;
67   void set_term (rxvt_term *r) { this->r = r; }
68
69   char *name;
70   codeset cs;
71   bool loaded; // wether we tried loading it before (not wether it's loaded)
72
73   // managed by the font object
74   int ascent, descent,
75       width, height;
76
77   void set_name (char *name);
78
79   rxvt_font () { name = 0; }
80   virtual ~rxvt_font () { free (name); };
81
82   virtual void clear () { };
83
84   void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color);
85
86   virtual rxvt_fontprop properties () = 0;
87
88   virtual bool load (const rxvt_fontprop &morph) = 0;
89   virtual bool has_char (uint32_t unicode, const rxvt_fontprop *prop, bool &careful) = 0;
90
91   virtual void draw (rxvt_drawable &d,
92                      int x, int y,
93                      const text_t *text, int len,
94                      int fg, int bg) = 0;
95 };
96
97 #define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0)
98
99 struct rxvt_fallback_font;
100
101 struct rxvt_fontset {
102   char *fontdesc;
103
104   rxvt_fontset (rxvt_term *r);
105   ~rxvt_fontset ();
106
107   bool populate (const char *desc);
108   void set_prop (const rxvt_fontprop &prop) { this->prop = prop; }
109   int find_font (uint32_t unicode);
110   int find_font (const char *name) const;
111   bool realize_font (int i);
112
113   // font-id's MUST fit into a signed 16 bit integer, and within 0..255
114   rxvt_font *operator [] (int id) const
115   {
116     return fonts[id & 0x7f];
117   }
118
119 private:
120   rxvt_term *r;
121   rxvt_fontprop prop;
122   simplevec<rxvt_font *> fonts;
123   const rxvt_fallback_font *fallback;
124
125   typedef unsigned char pagemap[256];
126   vector<pagemap *> fmap;
127
128   void clear ();
129   rxvt_font *new_font (const char *name, codeset cs);
130   void add_fonts (const char *desc);
131 };
132
133 #endif /* _DEFAULTFONT_H_ */
134