*** 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 #include <inttypes.h>
10
11 #include "feature.h"
12 #include "encoding.h"
13 #include "rxvtutil.h"
14 #include "rxvttoolkit.h"
15
16 struct rxvt_term;
17
18 struct rxvt_fontprop
19 {
20   enum {
21     unset  = -1,
22     medium = 100, bold = 200,
23     roman  = 0, italic = 100,
24   };
25   int width, height, ascent;
26   int weight, slant;
27 };
28
29 struct rxvt_font
30 {
31   // managed by the fontset
32   rxvt_term *term;
33   void set_term (rxvt_term *term) { this->term = term; }
34
35   char *name;
36   codeset cs;
37   bool loaded; // wether we tried loading it before (not wether it's loaded)
38
39   // managed by the font object
40   int ascent, descent,
41       width, height;
42
43   void set_name (char *name_);
44
45   rxvt_font ();
46   virtual ~rxvt_font () { free (name); };
47
48   virtual void clear () { };
49
50   void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const;
51
52   virtual rxvt_fontprop properties () = 0;
53
54   virtual bool load (const rxvt_fontprop &morph, bool force_prop) = 0;
55   virtual bool has_char (uint32_t unicode, const rxvt_fontprop *prop, bool &careful) const = 0;
56
57   virtual void draw (rxvt_drawable &d,
58                      int x, int y,
59                      const text_t *text, int len,
60                      int fg, int bg) = 0;
61 };
62
63 #define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0)
64
65 struct rxvt_fallback_font;
66
67 struct rxvt_fontset
68 {
69   char *fontdesc;
70
71   enum { fontCount = 3 }; // must be power-of-two - 1, also has to match RS_fontMask in rxvt.h
72   enum { Careful = fontCount + 1 };
73
74   rxvt_fontset (rxvt_term *term);
75   ~rxvt_fontset ();
76
77   bool populate (const char *desc);
78   void set_prop (const rxvt_fontprop &prop, bool force_prop) { this->prop = prop; this->force_prop = force_prop; }
79   int find_font (uint32_t unicode);
80   int find_font (const char *name) const;
81   bool realize_font (int i);
82
83   // font-id's MUST fit into a signed 16 bit integer, and within 0..255
84   rxvt_font *get (uint32_t unicode, int id = fontCount)
85   {
86     bool dummy;
87
88     id &= fontCount;
89
90     return fonts[id == fontCount ? find_font_idx (unicode, dummy) : id];
91   }
92
93 private:
94   rxvt_term *term;
95   rxvt_fontprop prop;
96   bool force_prop;
97   simplevec<rxvt_font *> fonts;
98   const rxvt_fallback_font *fallback;
99
100   typedef unsigned char pagemap[256];
101   vector<pagemap *> fmap;
102
103   void clear ();
104   rxvt_font *new_font (const char *name, codeset cs);
105   void add_fonts (const char *desc);
106   int find_font_idx (uint32_t unicode, bool &careful); // same as find_font, but does not limit index
107 };
108
109 #endif /* _DEFAULTFONT_H_ */
110