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 "encoding.h" |
12 |
#include "rxvtutil.h" |
13 |
#include "rxvttoolkit.h" |
14 |
|
15 |
struct rxvt_term; |
16 |
|
17 |
struct rxvt_fontprop |
18 |
{ |
19 |
enum { |
20 |
unset = -1, |
21 |
medium = 100, bold = 200, |
22 |
roman = 0, italic = 100, |
23 |
}; |
24 |
int width, height, ascent; |
25 |
int weight, slant; |
26 |
}; |
27 |
|
28 |
struct rxvt_font |
29 |
{ |
30 |
// managed by the fontset |
31 |
rxvt_term *term; |
32 |
void set_term (rxvt_term *term) { this->term = term; } |
33 |
|
34 |
char *name; |
35 |
codeset cs; |
36 |
bool loaded; // whether we tried loading it before (not whether it's loaded) |
37 |
bool can_compose; // whether the font composes glyphs itself or not, should be a class method, but.. speed.... |
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 |
void unref () |
63 |
{ |
64 |
clear (); |
65 |
delete this; |
66 |
} |
67 |
}; |
68 |
|
69 |
struct rxvt_fallback_font; |
70 |
|
71 |
struct rxvt_fontset |
72 |
{ |
73 |
char *fontdesc; |
74 |
|
75 |
// must be power-of-two - 1, also has to match RS_fontMask in rxvt.h |
76 |
#if USE_256_COLORS |
77 |
enum { fontCount = 7 }; // 2 extra colors bits, 2 fewer fontcount bits |
78 |
#else |
79 |
enum { fontCount = 31 }; |
80 |
#endif |
81 |
|
82 |
// index of first font in set |
83 |
enum { firstFont = 2 }; |
84 |
|
85 |
rxvt_fontset (rxvt_term *term); |
86 |
~rxvt_fontset (); |
87 |
|
88 |
bool populate (const char *desc); |
89 |
void set_prop (const rxvt_fontprop &prop, bool force_prop) { this->prop = prop; this->force_prop = force_prop; } |
90 |
int find_font_idx (uint32_t unicode); |
91 |
int find_font (const char *name) const; |
92 |
bool realize_font (int i); |
93 |
|
94 |
rxvt_font *operator [] (int id) const |
95 |
{ |
96 |
return fonts[id >> 1]; |
97 |
} |
98 |
|
99 |
int |
100 |
find_font (unicode_t unicode) |
101 |
{ |
102 |
return min<int> ((fontCount << 1) | 1, find_font_idx (unicode)); |
103 |
} |
104 |
|
105 |
// find the font containing ' ' - we always assume this is font 1, as |
106 |
// every font should contain space, and font 1 is our base font. |
107 |
// pango assumes this, so it must be correct! |
108 |
int |
109 |
find_space_font () |
110 |
{ |
111 |
return 1 << 1; |
112 |
} |
113 |
|
114 |
private: |
115 |
rxvt_term *term; |
116 |
rxvt_fontprop prop; |
117 |
bool force_prop; |
118 |
simplevec<rxvt_font *> fonts; |
119 |
const rxvt_fallback_font *fallback; |
120 |
|
121 |
// this once was a "typedef xxx pagemap[256] |
122 |
// but c++ arrays are not normal types, and cannot be |
123 |
// put into containers, new doesn't work for them etc. etc. |
124 |
// so we wrap out array into an object that acts like one. doh. |
125 |
// example: C++ has no separate new and new [] forms, |
126 |
// and if pagemap is char[256], new incorrectly assumes we want to |
127 |
// allocate an array of chars instead of a single pagemap. |
128 |
struct pagemap |
129 |
{ |
130 |
unsigned char cppsucks[256]; |
131 |
unsigned char &operator [](int i) { return cppsucks [i]; }; |
132 |
}; |
133 |
vector<pagemap *> fmap; |
134 |
|
135 |
void clear (); |
136 |
rxvt_font *new_font (const char *name, codeset cs); |
137 |
void prepare_font (rxvt_font *font, codeset cs); |
138 |
void add_fonts (const char *desc); |
139 |
void push_font (rxvt_font *font); |
140 |
}; |
141 |
|
142 |
#endif /* _DEFAULTFONT_H_ */ |
143 |
|