1 |
pcg |
1.1 |
/*--------------------------------*-C-*---------------------------------*; |
2 |
|
|
* File: defaultfont.C |
3 |
|
|
*----------------------------------------------------------------------* |
4 |
pcg |
1.22 |
* Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
5 |
pcg |
1.1 |
* - original version. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
*---------------------------------------------------------------------*/ |
21 |
|
|
|
22 |
|
|
#include "../config.h" |
23 |
|
|
#include "rxvt.h" |
24 |
|
|
#include "defaultfont.h" |
25 |
|
|
|
26 |
pcg |
1.7 |
#include <cstdlib> |
27 |
|
|
|
28 |
pcg |
1.17 |
#define DISPLAY r->display->display |
29 |
pcg |
1.43 |
#define TGC r->TermWin.gc |
30 |
pcg |
1.1 |
|
31 |
|
|
const struct rxvt_fallback_font { |
32 |
|
|
codeset cs; |
33 |
|
|
const char *name; |
34 |
|
|
} fallback_fonts[] = { |
35 |
|
|
{ CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
36 |
|
|
{ CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
37 |
|
|
{ CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
38 |
|
|
|
39 |
|
|
#if ENCODING_EU |
40 |
|
|
// cyrillic |
41 |
|
|
{ CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
42 |
|
|
{ CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
43 |
|
|
|
44 |
|
|
{ CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
45 |
|
|
{ CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
46 |
|
|
{ CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
47 |
|
|
{ CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
48 |
|
|
{ CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
49 |
|
|
{ CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, |
50 |
|
|
{ CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, |
51 |
|
|
{ CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, |
52 |
|
|
{ CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
53 |
|
|
{ CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
54 |
|
|
{ CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
55 |
|
|
{ CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
56 |
|
|
{ CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
57 |
|
|
#endif |
58 |
|
|
|
59 |
|
|
// japanese |
60 |
|
|
#if ENCODING_JP || ENCODING_JP_EXT |
61 |
|
|
# if XFT |
62 |
|
|
// prefer xft for complex scripts |
63 |
pcg |
1.9 |
{ CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
64 |
pcg |
1.1 |
# endif |
65 |
pcg |
1.9 |
{ CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 |
pcg |
1.41 |
{ CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 |
pcg |
1.9 |
{ CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 |
pcg |
1.1 |
#endif |
69 |
|
|
|
70 |
|
|
#if ENCODING_CN || ENCODING_CN_EXT |
71 |
|
|
# if XFT |
72 |
pcg |
1.9 |
{ CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
73 |
|
|
{ CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
74 |
|
|
{ CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
75 |
|
|
{ CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
76 |
pcg |
1.1 |
# endif |
77 |
pcg |
1.28 |
{ CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
78 |
|
|
{ CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
79 |
|
|
{ CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
80 |
pcg |
1.27 |
{ CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
81 |
|
|
{ CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
82 |
|
|
{ CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
83 |
|
|
{ CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
84 |
|
|
{ CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
85 |
|
|
{ CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
86 |
|
|
{ CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
87 |
|
|
{ CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
88 |
|
|
{ CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
89 |
pcg |
1.1 |
#endif |
90 |
|
|
|
91 |
|
|
#if XFT |
92 |
pcg |
1.9 |
{ CS_UNICODE, "xft:Andale Mono" }, |
93 |
|
|
{ CS_UNICODE, "xft:Arial Unicode MS" }, |
94 |
pcg |
1.1 |
#endif |
95 |
pcg |
1.9 |
{ CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
96 |
|
|
{ CS_UNICODE, "xft:FreeMono" }, |
97 |
|
|
{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
98 |
|
|
{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
99 |
|
|
{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
100 |
pcg |
1.1 |
|
101 |
pcg |
1.30 |
#if UNICODE_3 && XFT |
102 |
|
|
{ CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters |
103 |
|
|
#endif |
104 |
|
|
|
105 |
pcg |
1.1 |
{ CS_UNKNOWN, 0 } |
106 |
|
|
}; |
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////// |
109 |
|
|
|
110 |
pcg |
1.26 |
#if XFT |
111 |
pcg |
1.24 |
rxvt_drawable::~rxvt_drawable () |
112 |
|
|
{ |
113 |
|
|
if (xftdrawable) |
114 |
|
|
XftDrawDestroy (xftdrawable); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
rxvt_drawable::operator XftDraw *() |
118 |
|
|
{ |
119 |
|
|
if (!xftdrawable) |
120 |
|
|
xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
121 |
|
|
|
122 |
|
|
return xftdrawable; |
123 |
|
|
} |
124 |
pcg |
1.26 |
#endif |
125 |
pcg |
1.24 |
|
126 |
|
|
///////////////////////////////////////////////////////////////////////////// |
127 |
|
|
|
128 |
pcg |
1.1 |
static void *enc_buf; |
129 |
|
|
static uint32_t enc_len; |
130 |
|
|
|
131 |
|
|
static inline void * |
132 |
pcg |
1.16 |
get_enc_buf (uint32_t len) |
133 |
pcg |
1.1 |
{ |
134 |
|
|
if (len > enc_len) |
135 |
|
|
{ |
136 |
|
|
free (enc_buf); |
137 |
|
|
enc_buf = malloc (len); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
return enc_buf; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
static const char * |
144 |
pcg |
1.16 |
enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
145 |
pcg |
1.1 |
{ |
146 |
|
|
uint8_t *buf = (uint8_t *)get_enc_buf (len); |
147 |
|
|
|
148 |
|
|
while (len--) |
149 |
|
|
{ |
150 |
|
|
uint32_t c = FROM_UNICODE (cs, *text++); |
151 |
|
|
|
152 |
|
|
if (c == NOCHAR) |
153 |
|
|
{ |
154 |
|
|
c = 0; |
155 |
|
|
zero = true; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
*buf++ = c; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
return (const char *)enc_buf; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
static const XChar2b * |
165 |
pcg |
1.16 |
enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
166 |
pcg |
1.1 |
{ |
167 |
|
|
XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
168 |
|
|
|
169 |
|
|
while (len--) |
170 |
|
|
{ |
171 |
|
|
uint32_t c = FROM_UNICODE (cs, *text++); |
172 |
|
|
|
173 |
|
|
if (c == NOCHAR) |
174 |
|
|
{ |
175 |
|
|
c = 0; |
176 |
|
|
zero = true; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
buf->byte1 = c >> 8; |
180 |
|
|
buf->byte2 = c; |
181 |
|
|
buf++; |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
return (XChar2b *)enc_buf; |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
///////////////////////////////////////////////////////////////////////////// |
188 |
|
|
|
189 |
|
|
void |
190 |
pcg |
1.24 |
rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
191 |
pcg |
1.1 |
{ |
192 |
|
|
if (color == Color_bg) |
193 |
pcg |
1.24 |
XClearArea (d.display->display, d, x, y, w, h, FALSE); |
194 |
pcg |
1.1 |
else if (color >= 0) |
195 |
|
|
{ |
196 |
pcg |
1.24 |
#if XFT |
197 |
|
|
XftDrawRect (d, &r->PixColors[color].c, x, y, w, h); |
198 |
|
|
#else |
199 |
pcg |
1.43 |
XSetForeground (d.display->display, TGC, r->PixColors[color]); |
200 |
|
|
XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
201 |
pcg |
1.24 |
#endif |
202 |
pcg |
1.1 |
} |
203 |
|
|
} |
204 |
|
|
|
205 |
pcg |
1.43 |
static const char *linedraw_cmds[128 + 32] = { |
206 |
pcg |
1.42 |
"1-", "2-", "1|", "2|", |
207 |
pcg |
1.3 |
0, 0, 0, 0, |
208 |
|
|
0, 0, 0, 0, |
209 |
|
|
"1HV", "2H1V", "1H2V", "2HV", |
210 |
|
|
|
211 |
|
|
// 2510 |
212 |
|
|
"1hV", "2h1V", "1h2V", "2hV", |
213 |
|
|
"1Hv", "2H1v", "1H2v", "2Hv", |
214 |
|
|
"1hv", "2h1v", "1h2v", "2hv", |
215 |
pcg |
1.42 |
"1H|", "2H1|", "1HV2v", "1Hv2V", |
216 |
pcg |
1.3 |
|
217 |
|
|
// 2520 |
218 |
pcg |
1.42 |
"1H2|", "2Hv1V", "2HV1v", "2H|", |
219 |
|
|
"1h|", "2h1|", "1hV2v", "1hv2V", |
220 |
|
|
"1h2|", "2hv1V", "1v2hV", "2h|", |
221 |
|
|
"1-V", "2h1HV", "2H1hV", "2-1V", |
222 |
pcg |
1.3 |
|
223 |
|
|
// 2530 |
224 |
pcg |
1.42 |
"1-2V", "2hV1H", "1h2HV", "2-V", |
225 |
|
|
"1-v", "1vH2h", "1hv2H", "1v2-", |
226 |
|
|
"1-2v", "1H2hv", "1h2Hv", "2-v", |
227 |
|
|
"1-|", "1|H2h", "1h|2H", "1|2-", |
228 |
pcg |
1.3 |
|
229 |
|
|
// 2540 |
230 |
pcg |
1.42 |
"1-V2v", "1-v2V", "1-2|", "1HV2hv", |
231 |
|
|
"1hV2Hv", "1Hv2hV", "1hv2HV", "1V2-v", |
232 |
|
|
"1v2-V", "1H2h|", "1h2H|", "2-|", |
233 |
pcg |
1.3 |
0, 0, 0, 0, |
234 |
|
|
|
235 |
|
|
// 2550 |
236 |
|
|
0, 0, 0, 0, |
237 |
|
|
0, 0, 0, 0, |
238 |
|
|
0, 0, 0, 0, |
239 |
|
|
0, 0, 0, 0, |
240 |
|
|
|
241 |
|
|
// 2560 |
242 |
|
|
0, 0, 0, 0, |
243 |
|
|
0, 0, 0, 0, |
244 |
|
|
0, 0, 0, 0, |
245 |
pcg |
1.42 |
0, "A", "B", "C", |
246 |
pcg |
1.3 |
|
247 |
|
|
// 2570 |
248 |
pcg |
1.42 |
"D", "1/", "1\\", "1/\\", |
249 |
pcg |
1.3 |
"1h", "1v", "1H", "1V", |
250 |
|
|
"2h", "2v", "2H", "2V", |
251 |
pcg |
1.43 |
"1h2H", "1v2V", "1H2h", "1V2v", |
252 |
|
|
|
253 |
|
|
// 2580 |
254 |
|
|
0, 0, 0, 0, |
255 |
|
|
0, 0, 0, 0, |
256 |
|
|
0, 0, 0, 0, |
257 |
|
|
0, 0, 0, 0, |
258 |
|
|
|
259 |
|
|
// 2590 |
260 |
|
|
0, 0, 0, 0, |
261 |
|
|
0, 0, "k", "l", |
262 |
|
|
"i", "ikl", "il", "ijk", |
263 |
|
|
"ijl", "j", "jk", "jkl", |
264 |
pcg |
1.3 |
|
265 |
|
|
// to be done |
266 |
|
|
}; |
267 |
|
|
|
268 |
pcg |
1.1 |
struct rxvt_font_default : rxvt_font { |
269 |
pcg |
1.7 |
rxvt_fontprop properties () |
270 |
|
|
{ |
271 |
|
|
rxvt_fontprop p; |
272 |
|
|
|
273 |
pcg |
1.10 |
p.width = p.height = 1; |
274 |
pcg |
1.7 |
p.weight = rxvt_fontprop::medium; |
275 |
|
|
p.slant = rxvt_fontprop::roman; |
276 |
|
|
|
277 |
|
|
return p; |
278 |
|
|
} |
279 |
|
|
|
280 |
|
|
bool load (const rxvt_fontprop &prop) |
281 |
pcg |
1.1 |
{ |
282 |
|
|
width = 1; height = 1; |
283 |
|
|
ascent = 1; descent = 0; |
284 |
|
|
|
285 |
pcg |
1.38 |
set_name ("built-in pseudofont"); |
286 |
|
|
|
287 |
pcg |
1.1 |
return true; |
288 |
|
|
} |
289 |
|
|
|
290 |
pcg |
1.40 |
bool has_codepoint (unicode_t unicode) |
291 |
pcg |
1.1 |
{ |
292 |
pcg |
1.3 |
if (unicode <= 0x001f) |
293 |
|
|
return true; |
294 |
pcg |
1.34 |
|
295 |
pcg |
1.3 |
if (unicode >= 0x0080 && unicode <= 0x009f) |
296 |
|
|
return true; |
297 |
|
|
|
298 |
|
|
if (unicode >= 0x2500 && unicode <= 0x257f |
299 |
|
|
&& linedraw_cmds[unicode - 0x2500]) |
300 |
pcg |
1.1 |
return true; |
301 |
|
|
|
302 |
pcg |
1.43 |
if (unicode >= 0x2580 && unicode <= 0x259f) |
303 |
|
|
return true; |
304 |
|
|
|
305 |
pcg |
1.35 |
if (IS_COMPOSE (unicode)) |
306 |
pcg |
1.34 |
return true; |
307 |
|
|
|
308 |
pcg |
1.1 |
switch (unicode) |
309 |
|
|
{ |
310 |
|
|
case ZERO_WIDTH_CHAR: |
311 |
|
|
return true; |
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
return false; |
315 |
|
|
} |
316 |
|
|
|
317 |
pcg |
1.24 |
void draw (rxvt_drawable &d, int x, int y, |
318 |
pcg |
1.1 |
const text_t *text, int len, |
319 |
|
|
int fg, int bg); |
320 |
|
|
}; |
321 |
|
|
|
322 |
pcg |
1.43 |
static void rect_stipple (Display *display, Drawable d, GC gc, int s1, int s2, int x, int y, int w, int h) |
323 |
|
|
{ |
324 |
|
|
XGCValues gcv; |
325 |
|
|
char bm[2] = { s1, s2 }; |
326 |
|
|
|
327 |
|
|
gcv.fill_style = FillStippled; |
328 |
|
|
gcv.stipple = XCreateBitmapFromData (display, d, bm, 2, 2); |
329 |
|
|
gcv.ts_x_origin = x; |
330 |
|
|
gcv.ts_y_origin = y; |
331 |
|
|
|
332 |
|
|
if (!gcv.stipple) |
333 |
|
|
return; |
334 |
|
|
|
335 |
|
|
XChangeGC (display, gc, GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
336 |
|
|
XFillRectangle (display, d, gc, x, y, w, h); |
337 |
|
|
|
338 |
|
|
XFreePixmap (display, gcv.stipple); |
339 |
|
|
|
340 |
|
|
gcv.fill_style = FillSolid; |
341 |
|
|
XChangeGC (display, gc, GCFillStyle, &gcv); |
342 |
|
|
} |
343 |
|
|
|
344 |
pcg |
1.1 |
void |
345 |
pcg |
1.24 |
rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
346 |
pcg |
1.1 |
const text_t *text, int len, |
347 |
|
|
int fg, int bg) |
348 |
|
|
{ |
349 |
pcg |
1.24 |
clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
350 |
pcg |
1.1 |
|
351 |
pcg |
1.43 |
XSetForeground (d.display->display, TGC, r->PixColors[fg]); |
352 |
pcg |
1.3 |
|
353 |
pcg |
1.1 |
while (len--) |
354 |
|
|
{ |
355 |
pcg |
1.39 |
#if ENABLE_COMBINING |
356 |
pcg |
1.36 |
compose_char *cc; |
357 |
pcg |
1.39 |
#endif |
358 |
pcg |
1.3 |
text_t t = *text++; |
359 |
|
|
|
360 |
pcg |
1.43 |
int W = r->TermWin.fwidth , w = (W - 1) / 2; |
361 |
|
|
int H = r->TermWin.fheight, h = (H - 1) / 2; |
362 |
|
|
int x0 = x, x1 = x + w, x2 = x + r->TermWin.fwidth ; |
363 |
|
|
int y0 = y, y1 = y + h, y2 = y + r->TermWin.fheight; |
364 |
|
|
|
365 |
pcg |
1.27 |
// is it in our linedrawing table? |
366 |
pcg |
1.43 |
if (t >= 0x2500 & t <= 0x259f && linedraw_cmds[t - 0x2500]) |
367 |
pcg |
1.1 |
{ |
368 |
pcg |
1.3 |
const char *p = linedraw_cmds[t - 0x2500]; |
369 |
|
|
|
370 |
|
|
XGCValues gcv; |
371 |
|
|
|
372 |
pcg |
1.42 |
gcv.cap_style = CapNotLast; |
373 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCCapStyle, &gcv); |
374 |
pcg |
1.42 |
|
375 |
pcg |
1.3 |
while (*p) |
376 |
|
|
{ |
377 |
|
|
switch (*p++) |
378 |
|
|
{ |
379 |
|
|
case '1': |
380 |
|
|
gcv.line_width = 0; |
381 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCLineWidth, &gcv); |
382 |
pcg |
1.3 |
break; |
383 |
|
|
|
384 |
|
|
case '2': |
385 |
pcg |
1.42 |
gcv.line_width = 3; |
386 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCLineWidth, &gcv); |
387 |
pcg |
1.3 |
break; |
388 |
|
|
|
389 |
pcg |
1.43 |
case 'h': XDrawLine (d.display->display, d, TGC, x0, y1, x1+1, y1 ); break; |
390 |
|
|
case 'H': XDrawLine (d.display->display, d, TGC, x1, y1, x2 , y1 ); break; |
391 |
|
|
case '-': XDrawLine (d.display->display, d, TGC, x0, y1, x2 , y1 ); break; |
392 |
|
|
case 'v': XDrawLine (d.display->display, d, TGC, x1, y0, x1 , y1+1); break; |
393 |
|
|
case 'V': XDrawLine (d.display->display, d, TGC, x1, y1, x1 , y2 ); break; |
394 |
|
|
case '|': XDrawLine (d.display->display, d, TGC, x1, y0, x1 , y2 ); break; |
395 |
|
|
|
396 |
|
|
case '/' : XDrawLine (d.display->display, d, TGC, x0, y2, x2 , y0 ); break; |
397 |
|
|
case '\\': XDrawLine (d.display->display, d, TGC, x0, y0, x2 , y2 ); break; |
398 |
|
|
|
399 |
|
|
case 'A': XDrawArc (d.display->display, d, TGC, x1 , y1 , W-1, H-1, 90*64, 90*64); break; |
400 |
|
|
case 'B': XDrawArc (d.display->display, d, TGC, x1-W+1, y1 , W-1, H-1, 0*64, 90*64); break; |
401 |
|
|
case 'C': XDrawArc (d.display->display, d, TGC, x1-W+1, y1-H+1, W-1, H-1, 0*64, -90*64); break; |
402 |
|
|
case 'D': XDrawArc (d.display->display, d, TGC, x1 , y1-H+1, W-1, H-1, -90*64, -90*64); break; |
403 |
|
|
|
404 |
|
|
case 'i': XFillRectangle (d.display->display, d, TGC, x0, y0, x1 - x0 + 1, y1 - y0 + 1); break; |
405 |
|
|
case 'j': XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, y1 - y0 + 1); break; |
406 |
|
|
case 'k': XFillRectangle (d.display->display, d, TGC, x0, y1, x1 - x0 + 1, y2 - y1); break; |
407 |
|
|
case 'l': XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1, y2 - y1); break; |
408 |
pcg |
1.3 |
} |
409 |
|
|
} |
410 |
|
|
|
411 |
|
|
gcv.line_width = 0; |
412 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCLineWidth, &gcv); |
413 |
pcg |
1.1 |
} |
414 |
pcg |
1.42 |
|
415 |
pcg |
1.39 |
#if ENABLE_COMBINING |
416 |
pcg |
1.36 |
else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
417 |
pcg |
1.34 |
{ |
418 |
pcg |
1.37 |
rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
419 |
|
|
f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg); |
420 |
pcg |
1.36 |
if (cc->c2 != NOCHAR) |
421 |
pcg |
1.37 |
{ |
422 |
|
|
// prefer font of first character, for no good reasons |
423 |
|
|
rxvt_font *f2 = f1->has_codepoint (cc->c2) |
424 |
|
|
? f1 |
425 |
|
|
: (*fs)[fs->find_font (cc->c2)]; |
426 |
|
|
|
427 |
|
|
f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1); |
428 |
|
|
} |
429 |
pcg |
1.34 |
} |
430 |
pcg |
1.39 |
#endif |
431 |
pcg |
1.3 |
else |
432 |
pcg |
1.27 |
switch (t) |
433 |
pcg |
1.3 |
{ |
434 |
|
|
case ZERO_WIDTH_CHAR: |
435 |
|
|
break; |
436 |
pcg |
1.43 |
|
437 |
|
|
case 0x2580: XFillRectangle (d.display->display, d, TGC, x0, y0, W, y1 - y0 + 1); break; |
438 |
|
|
case 0x2581: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 7 - 1) / 8, W, H - (H * 7 - 1) / 8); break; |
439 |
|
|
case 0x2582: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 6 - 2) / 8, W, H - (H * 6 - 2) / 8); break; |
440 |
|
|
case 0x2583: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 5 - 3) / 8, W, H - (H * 5 - 3) / 8); break; |
441 |
|
|
case 0x2584: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 4 - 4) / 8, W, H - (H * 4 - 4) / 8); break; |
442 |
|
|
case 0x2585: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 3 - 5) / 8, W, H - (H * 3 - 5) / 8); break; |
443 |
|
|
case 0x2586: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 2 - 6) / 8, W, H - (H * 2 - 6) / 8); break; |
444 |
|
|
case 0x2587: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 1 - 7) / 8, W, H - (H * 1 - 7) / 8); break; |
445 |
|
|
case 0x2588: XFillRectangle (d.display->display, d, TGC, x0, y0, W, H); break; |
446 |
|
|
case 0x2589: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 7 - 1) / 8, H); break; |
447 |
|
|
case 0x258a: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 6 - 2) / 8, H); break; |
448 |
|
|
case 0x258b: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 5 - 3) / 8, H); break; |
449 |
|
|
case 0x258c: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 4 - 4) / 8, H); break; |
450 |
|
|
case 0x258d: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 3 - 5) / 8, H); break; |
451 |
|
|
case 0x258e: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 2 - 6) / 8, H); break; |
452 |
|
|
case 0x258f: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 1 - 7) / 8, H); break; |
453 |
|
|
case 0x2590: XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, H); break; |
454 |
|
|
|
455 |
|
|
case 0x2591: rect_stipple (d.display->display, d, TGC, 0x00, 0x01, x0, y0, W, H); break; |
456 |
|
|
case 0x2592: rect_stipple (d.display->display, d, TGC, 0x02, 0x01, x0, y0, W, H); break; |
457 |
|
|
case 0x2593: rect_stipple (d.display->display, d, TGC, 0x01, 0x03, x0, y0, W, H); break; |
458 |
|
|
|
459 |
|
|
case 0x2594: XFillRectangle (d.display->display, d, TGC, x0, y0, W, (H * 1 - 7) / 8); break; |
460 |
|
|
case 0x2595: XFillRectangle (d.display->display, d, TGC, x0 + (W * 7 - 1) / 8, y0, W - (W * 7 - 1) / 8, H); break; |
461 |
|
|
|
462 |
pcg |
1.3 |
default: |
463 |
pcg |
1.27 |
int w = 0; |
464 |
|
|
while (len > 0 && *text == NOCHAR) |
465 |
|
|
{ |
466 |
|
|
++text; |
467 |
|
|
--len; |
468 |
|
|
w += r->TermWin.fwidth; |
469 |
|
|
} |
470 |
|
|
|
471 |
pcg |
1.43 |
XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
472 |
|
|
w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
473 |
pcg |
1.27 |
x += w; |
474 |
pcg |
1.3 |
} |
475 |
pcg |
1.1 |
|
476 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
477 |
pcg |
1.1 |
} |
478 |
|
|
} |
479 |
|
|
|
480 |
|
|
///////////////////////////////////////////////////////////////////////////// |
481 |
|
|
|
482 |
|
|
struct rxvt_font_x11 : rxvt_font { |
483 |
|
|
rxvt_font_x11 () { f = 0; } |
484 |
|
|
|
485 |
|
|
void clear (); |
486 |
|
|
|
487 |
pcg |
1.7 |
rxvt_fontprop properties (); |
488 |
|
|
|
489 |
|
|
bool load (const rxvt_fontprop &prop); |
490 |
pcg |
1.1 |
|
491 |
pcg |
1.40 |
bool has_codepoint (unicode_t unicode); |
492 |
pcg |
1.1 |
|
493 |
pcg |
1.24 |
void draw (rxvt_drawable &d, int x, int y, |
494 |
pcg |
1.1 |
const text_t *text, int len, |
495 |
|
|
int fg, int bg); |
496 |
|
|
|
497 |
|
|
XFontStruct *f; |
498 |
|
|
codeset cs; |
499 |
|
|
bool enc2b, encm; |
500 |
|
|
|
501 |
pcg |
1.7 |
const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
502 |
pcg |
1.12 |
bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
503 |
|
|
bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
504 |
|
|
bool set_properties (rxvt_fontprop &p, const char *name); |
505 |
pcg |
1.1 |
}; |
506 |
|
|
|
507 |
|
|
const char * |
508 |
pcg |
1.7 |
rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
509 |
pcg |
1.1 |
{ |
510 |
|
|
unsigned long value; |
511 |
|
|
|
512 |
|
|
if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
513 |
|
|
return XGetAtomName (DISPLAY, value); |
514 |
|
|
else |
515 |
|
|
return repl; |
516 |
|
|
} |
517 |
|
|
|
518 |
pcg |
1.7 |
rxvt_fontprop |
519 |
|
|
rxvt_font_x11::properties () |
520 |
|
|
{ |
521 |
pcg |
1.12 |
rxvt_fontprop p; |
522 |
|
|
set_properties (p, f); |
523 |
|
|
return p; |
524 |
pcg |
1.7 |
} |
525 |
|
|
|
526 |
pcg |
1.12 |
bool |
527 |
|
|
rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
528 |
pcg |
1.7 |
{ |
529 |
pcg |
1.12 |
p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
530 |
|
|
p.height = height; |
531 |
|
|
p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
532 |
|
|
p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
533 |
|
|
|
534 |
|
|
return true; |
535 |
|
|
} |
536 |
pcg |
1.7 |
|
537 |
pcg |
1.12 |
bool |
538 |
|
|
rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
539 |
|
|
{ |
540 |
pcg |
1.7 |
const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
541 |
|
|
const char *slant = get_property (f, "SLANT", "r"); |
542 |
|
|
|
543 |
pcg |
1.12 |
unsigned long height; |
544 |
|
|
if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
545 |
|
|
return false; |
546 |
|
|
|
547 |
pcg |
1.10 |
unsigned long avgwidth; |
548 |
pcg |
1.12 |
if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
549 |
|
|
avgwidth = 0; |
550 |
|
|
|
551 |
|
|
return set_properties (p, height, weight, slant, avgwidth); |
552 |
|
|
} |
553 |
|
|
|
554 |
|
|
bool |
555 |
|
|
rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
556 |
|
|
{ |
557 |
|
|
int slashes = 0; |
558 |
pcg |
1.29 |
const char *comp[13]; |
559 |
pcg |
1.12 |
|
560 |
|
|
for (const char *c = name; *c; c++) |
561 |
|
|
if (*c == '-') |
562 |
|
|
{ |
563 |
|
|
comp[slashes++] = c + 1; |
564 |
|
|
if (slashes >= 13) |
565 |
|
|
break; |
566 |
|
|
} |
567 |
|
|
|
568 |
|
|
/* can we short-circuit the costly XLoadQueryFont? */ |
569 |
|
|
if (slashes >= 13 |
570 |
|
|
&& (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
571 |
|
|
&& (*comp[11] >= '0' && *comp[11] <= '9')) |
572 |
|
|
return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
573 |
|
|
|
574 |
|
|
XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
575 |
|
|
|
576 |
|
|
if (f) |
577 |
|
|
{ |
578 |
pcg |
1.19 |
// the font should really exist now. if not, we have a problem |
579 |
pcg |
1.12 |
// (e.g. if the user did xset fp rehash just when we were searching fonts). |
580 |
|
|
// in that case, just return garbage. |
581 |
|
|
bool ret = set_properties (p, f); |
582 |
|
|
XFreeFont (DISPLAY, f); |
583 |
|
|
return ret; |
584 |
|
|
} |
585 |
|
|
else |
586 |
|
|
return false; |
587 |
|
|
} |
588 |
|
|
|
589 |
|
|
// fix the size of scalable fonts |
590 |
|
|
static void |
591 |
|
|
fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop) |
592 |
|
|
{ |
593 |
|
|
int slashes = 0; |
594 |
|
|
const char *size; |
595 |
|
|
|
596 |
|
|
for (const char *c = name; *c; c++) |
597 |
|
|
if (*c == '-') |
598 |
|
|
{ |
599 |
|
|
if (slashes == 6) |
600 |
|
|
size = c + 1; |
601 |
|
|
|
602 |
|
|
if (++slashes >= 13) |
603 |
|
|
break; |
604 |
|
|
} |
605 |
pcg |
1.7 |
|
606 |
pcg |
1.12 |
if (slashes >= 13 && size[0] == '0') |
607 |
|
|
{ |
608 |
|
|
strncpy (buf, name, size - name); |
609 |
|
|
buf += size - name; |
610 |
|
|
buf += sprintf (buf, "%d", prop.height); |
611 |
|
|
strcpy (buf, size + 1); |
612 |
|
|
} |
613 |
|
|
else |
614 |
|
|
strcpy (buf, name); |
615 |
pcg |
1.7 |
} |
616 |
|
|
|
617 |
pcg |
1.1 |
bool |
618 |
pcg |
1.7 |
rxvt_font_x11::load (const rxvt_fontprop &prop) |
619 |
pcg |
1.1 |
{ |
620 |
|
|
clear (); |
621 |
|
|
|
622 |
pcg |
1.6 |
char **list; |
623 |
|
|
int count; |
624 |
pcg |
1.12 |
list = XListFonts (DISPLAY, name, 512, &count); |
625 |
|
|
set_name (0); |
626 |
pcg |
1.6 |
|
627 |
|
|
if (!list) |
628 |
|
|
return false; |
629 |
|
|
|
630 |
pcg |
1.7 |
int bestdiff = 0x7fffffff; |
631 |
pcg |
1.6 |
for (int i = 0; i < count; i++) |
632 |
|
|
{ |
633 |
pcg |
1.12 |
rxvt_fontprop p; |
634 |
|
|
char fname[1024]; |
635 |
|
|
fix_scalable (fname, list[i], prop); |
636 |
|
|
|
637 |
|
|
if (!set_properties (p, fname)) |
638 |
|
|
continue; |
639 |
|
|
|
640 |
|
|
if (p.height > prop.height) // weed out too large fonts |
641 |
|
|
continue; |
642 |
|
|
|
643 |
|
|
int diff = (prop.height - p.height) * 32 |
644 |
|
|
+ abs (prop.weight - p.weight) |
645 |
|
|
+ abs (prop.slant - p.slant ); |
646 |
pcg |
1.7 |
|
647 |
pcg |
1.12 |
if (!name // compare against best found so far |
648 |
|
|
|| diff < bestdiff) |
649 |
pcg |
1.7 |
{ |
650 |
pcg |
1.12 |
set_name (strdup (fname)); |
651 |
|
|
bestdiff = diff; |
652 |
pcg |
1.7 |
} |
653 |
pcg |
1.6 |
} |
654 |
pcg |
1.9 |
|
655 |
pcg |
1.12 |
XFreeFontNames (list); |
656 |
|
|
|
657 |
|
|
if (!name) |
658 |
pcg |
1.9 |
return false; |
659 |
pcg |
1.6 |
|
660 |
pcg |
1.1 |
f = XLoadQueryFont (DISPLAY, name); |
661 |
|
|
|
662 |
|
|
if (!f) |
663 |
|
|
return false; |
664 |
|
|
|
665 |
pcg |
1.7 |
const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
666 |
|
|
const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
667 |
pcg |
1.1 |
|
668 |
|
|
if (registry && encoding) |
669 |
|
|
{ |
670 |
|
|
char charset[64]; |
671 |
|
|
snprintf (charset, 64, "%s-%s", registry, encoding); |
672 |
|
|
|
673 |
|
|
cs = codeset_from_name (charset); |
674 |
|
|
} |
675 |
|
|
else |
676 |
|
|
{ |
677 |
pcg |
1.7 |
const char *charset = get_property (f, "FONT", 0); |
678 |
pcg |
1.1 |
|
679 |
|
|
if (!charset) |
680 |
|
|
charset = name; |
681 |
|
|
|
682 |
|
|
int count = 13; |
683 |
|
|
while (*charset) |
684 |
|
|
if (*charset++ == '-' && !--count) |
685 |
|
|
break; |
686 |
|
|
|
687 |
|
|
cs = codeset_from_name (charset); |
688 |
|
|
} |
689 |
|
|
|
690 |
|
|
if (cs == CS_UNICODE) |
691 |
|
|
cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
692 |
|
|
|
693 |
|
|
encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
694 |
|
|
enc2b = encm || f->max_char_or_byte2 > 255; |
695 |
|
|
|
696 |
|
|
ascent = f->ascent; |
697 |
|
|
descent = f->descent; |
698 |
|
|
height = ascent + descent; |
699 |
|
|
|
700 |
pcg |
1.7 |
slow = false; |
701 |
pcg |
1.1 |
|
702 |
|
|
if (f->min_bounds.width == f->max_bounds.width) |
703 |
|
|
width = f->min_bounds.width; |
704 |
|
|
else if (f->per_char == NULL) |
705 |
|
|
width = f->max_bounds.width; |
706 |
|
|
else |
707 |
|
|
{ |
708 |
pcg |
1.7 |
slow = true; |
709 |
pcg |
1.1 |
|
710 |
|
|
int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
711 |
|
|
|
712 |
|
|
if (encm) |
713 |
|
|
N += (f->max_byte1 - f->min_byte1) |
714 |
|
|
* (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); |
715 |
|
|
|
716 |
|
|
while (N) |
717 |
|
|
{ |
718 |
|
|
if (f->per_char[N].width > width) |
719 |
|
|
width = f->per_char[N].width; |
720 |
|
|
|
721 |
|
|
--N; |
722 |
|
|
} |
723 |
|
|
} |
724 |
|
|
|
725 |
|
|
if (cs == CS_UNKNOWN) |
726 |
|
|
{ |
727 |
|
|
fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
728 |
|
|
|
729 |
|
|
clear (); |
730 |
|
|
|
731 |
|
|
return false; |
732 |
|
|
} |
733 |
|
|
|
734 |
|
|
return true; |
735 |
|
|
} |
736 |
|
|
|
737 |
|
|
void |
738 |
|
|
rxvt_font_x11::clear () |
739 |
|
|
{ |
740 |
|
|
if (f) |
741 |
|
|
{ |
742 |
|
|
XFreeFont (DISPLAY, f); |
743 |
|
|
f = 0; |
744 |
|
|
} |
745 |
|
|
} |
746 |
|
|
|
747 |
|
|
bool |
748 |
pcg |
1.40 |
rxvt_font_x11::has_codepoint (unicode_t unicode) |
749 |
pcg |
1.1 |
{ |
750 |
|
|
uint32_t ch = FROM_UNICODE (cs, unicode); |
751 |
|
|
|
752 |
|
|
if (ch == NOCHAR) |
753 |
|
|
return false; |
754 |
|
|
|
755 |
|
|
/* check wether the character exists in _this_ font. horrible. */ |
756 |
|
|
XCharStruct *xcs; |
757 |
|
|
|
758 |
|
|
if (encm) |
759 |
|
|
{ |
760 |
pcg |
1.16 |
unsigned char byte1 = ch >> 8; |
761 |
|
|
unsigned char byte2 = ch & 255; |
762 |
pcg |
1.1 |
|
763 |
|
|
if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
764 |
|
|
|| byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
765 |
|
|
return false; |
766 |
|
|
|
767 |
|
|
if (!f->per_char) |
768 |
|
|
return true; |
769 |
|
|
|
770 |
|
|
int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1; |
771 |
|
|
int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2; |
772 |
|
|
|
773 |
|
|
xcs = f->per_char + N; |
774 |
|
|
} |
775 |
|
|
else |
776 |
|
|
{ |
777 |
|
|
if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2) |
778 |
|
|
return false; |
779 |
|
|
|
780 |
|
|
if (!f->per_char) |
781 |
|
|
return true; |
782 |
|
|
|
783 |
|
|
xcs = f->per_char + (ch - f->min_char_or_byte2); |
784 |
|
|
} |
785 |
|
|
|
786 |
|
|
if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0 |
787 |
|
|
&& xcs->ascent == 0 && xcs->descent == 0) |
788 |
|
|
return false; |
789 |
|
|
|
790 |
|
|
return true; |
791 |
|
|
} |
792 |
|
|
|
793 |
|
|
void |
794 |
pcg |
1.24 |
rxvt_font_x11::draw (rxvt_drawable &d, int x, int y, |
795 |
pcg |
1.1 |
const text_t *text, int len, |
796 |
|
|
int fg, int bg) |
797 |
|
|
{ |
798 |
|
|
// this looks like a mess /. |
799 |
|
|
// and it is a mess /. |
800 |
|
|
// yet we are trying to be perfect /. |
801 |
|
|
// but the result still isn't perfect /. |
802 |
|
|
|
803 |
pcg |
1.7 |
bool slow = this->slow |
804 |
pcg |
1.2 |
|| width != r->TermWin.fwidth |
805 |
|
|
|| height != r->TermWin.fheight; |
806 |
pcg |
1.1 |
|
807 |
pcg |
1.2 |
int base = r->TermWin.fbase; |
808 |
pcg |
1.1 |
|
809 |
|
|
XGCValues v; |
810 |
pcg |
1.2 |
v.foreground = r->PixColors[fg]; |
811 |
|
|
v.background = r->PixColors[bg]; |
812 |
pcg |
1.1 |
v.font = f->fid; |
813 |
|
|
|
814 |
|
|
if (enc2b) |
815 |
|
|
{ |
816 |
|
|
const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
817 |
|
|
|
818 |
|
|
if (bg == Color_bg && !slow) |
819 |
|
|
{ |
820 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
821 |
|
|
XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
822 |
pcg |
1.1 |
} |
823 |
|
|
else |
824 |
|
|
{ |
825 |
pcg |
1.24 |
clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
826 |
pcg |
1.1 |
|
827 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
828 |
pcg |
1.1 |
|
829 |
|
|
if (slow) |
830 |
|
|
{ |
831 |
|
|
do |
832 |
|
|
{ |
833 |
|
|
if (xc->byte1 || xc->byte2) |
834 |
pcg |
1.43 |
XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
835 |
pcg |
1.1 |
|
836 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
837 |
pcg |
1.1 |
xc++; len--; |
838 |
|
|
} |
839 |
|
|
while (len); |
840 |
|
|
} |
841 |
|
|
else |
842 |
pcg |
1.43 |
XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
843 |
pcg |
1.1 |
} |
844 |
|
|
} |
845 |
|
|
else |
846 |
|
|
{ |
847 |
|
|
const char *xc = enc_char (text, len, cs, slow); |
848 |
|
|
|
849 |
|
|
if (bg == Color_bg && !slow) |
850 |
|
|
{ |
851 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
852 |
|
|
XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
853 |
pcg |
1.1 |
} |
854 |
|
|
else |
855 |
|
|
{ |
856 |
pcg |
1.24 |
clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
857 |
pcg |
1.1 |
|
858 |
pcg |
1.43 |
XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
859 |
pcg |
1.1 |
|
860 |
|
|
if (slow) |
861 |
|
|
{ |
862 |
|
|
do |
863 |
|
|
{ |
864 |
|
|
if (*xc) |
865 |
pcg |
1.43 |
XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
866 |
pcg |
1.1 |
|
867 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
868 |
pcg |
1.1 |
xc++; len--; |
869 |
|
|
} |
870 |
|
|
while (len); |
871 |
|
|
} |
872 |
|
|
else |
873 |
pcg |
1.43 |
XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
874 |
pcg |
1.1 |
} |
875 |
|
|
} |
876 |
|
|
} |
877 |
|
|
|
878 |
|
|
///////////////////////////////////////////////////////////////////////////// |
879 |
|
|
|
880 |
|
|
#if XFT |
881 |
|
|
#if 0 |
882 |
|
|
#define UNIBITS 21 |
883 |
|
|
//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
884 |
|
|
#define SWATHBITS 8 |
885 |
|
|
#endif |
886 |
|
|
|
887 |
|
|
struct rxvt_font_xft : rxvt_font { |
888 |
pcg |
1.24 |
rxvt_font_xft () { f = 0; } |
889 |
pcg |
1.1 |
|
890 |
|
|
void clear (); |
891 |
|
|
|
892 |
pcg |
1.7 |
rxvt_fontprop properties (); |
893 |
|
|
|
894 |
|
|
bool load (const rxvt_fontprop &prop); |
895 |
pcg |
1.1 |
|
896 |
pcg |
1.24 |
void draw (rxvt_drawable &d, int x, int y, |
897 |
pcg |
1.1 |
const text_t *text, int len, |
898 |
|
|
int fg, int bg); |
899 |
|
|
|
900 |
pcg |
1.40 |
bool has_codepoint (unicode_t unicode); |
901 |
pcg |
1.1 |
|
902 |
|
|
protected: |
903 |
|
|
XftFont *f; |
904 |
|
|
}; |
905 |
|
|
|
906 |
|
|
void |
907 |
|
|
rxvt_font_xft::clear () |
908 |
|
|
{ |
909 |
|
|
if (f) |
910 |
|
|
{ |
911 |
pcg |
1.2 |
XftFontClose (DISPLAY, f); |
912 |
pcg |
1.1 |
f = 0; |
913 |
|
|
} |
914 |
|
|
} |
915 |
|
|
|
916 |
pcg |
1.7 |
rxvt_fontprop |
917 |
|
|
rxvt_font_xft::properties () |
918 |
|
|
{ |
919 |
|
|
rxvt_fontprop p; |
920 |
|
|
|
921 |
|
|
FT_Face face = XftLockFace (f); |
922 |
|
|
|
923 |
pcg |
1.10 |
p.width = width; p.height = height; |
924 |
pcg |
1.7 |
p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
925 |
|
|
p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
926 |
|
|
|
927 |
|
|
XftUnlockFace (f); |
928 |
|
|
|
929 |
|
|
return p; |
930 |
|
|
} |
931 |
|
|
|
932 |
pcg |
1.1 |
bool |
933 |
pcg |
1.7 |
rxvt_font_xft::load (const rxvt_fontprop &prop) |
934 |
pcg |
1.1 |
{ |
935 |
|
|
#if 0 |
936 |
|
|
for (int i = 0; i < SWATHCOUNT; i++) |
937 |
|
|
cvr[i] = 0; |
938 |
|
|
#endif |
939 |
|
|
|
940 |
|
|
clear (); |
941 |
|
|
|
942 |
pcg |
1.7 |
FcPattern *p = FcNameParse ((FcChar8 *) name); |
943 |
|
|
|
944 |
|
|
if (!p) |
945 |
|
|
return false; |
946 |
|
|
|
947 |
|
|
FcValue v; |
948 |
|
|
|
949 |
|
|
if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
950 |
|
|
FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
951 |
|
|
|
952 |
|
|
if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
953 |
|
|
FcPatternAddInteger (p, FC_SLANT, prop.slant); |
954 |
|
|
|
955 |
pcg |
1.11 |
#if 0 // clipping unfortunately destroys our precious double-width-characters |
956 |
pcg |
1.10 |
// clip width, we can't do better, or can we? |
957 |
|
|
if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
958 |
|
|
FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
959 |
pcg |
1.11 |
#endif |
960 |
pcg |
1.10 |
|
961 |
pcg |
1.7 |
//FcPatternAddBool (p, FC_MINSPACE, 1); |
962 |
|
|
|
963 |
|
|
XftResult result; |
964 |
|
|
FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
965 |
|
|
|
966 |
|
|
FcPatternDestroy (p); |
967 |
|
|
|
968 |
|
|
if (!match) |
969 |
|
|
return false; |
970 |
|
|
|
971 |
|
|
f = XftFontOpenPattern (DISPLAY, match); |
972 |
|
|
|
973 |
pcg |
1.1 |
if (!f) |
974 |
pcg |
1.8 |
{ |
975 |
|
|
FcPatternDestroy (match); |
976 |
|
|
return false; |
977 |
|
|
} |
978 |
pcg |
1.1 |
|
979 |
|
|
FT_Face face = XftLockFace (f); |
980 |
|
|
|
981 |
pcg |
1.7 |
slow = !FT_IS_FIXED_WIDTH (face); |
982 |
pcg |
1.1 |
|
983 |
|
|
int ftheight = 0; |
984 |
|
|
|
985 |
|
|
for (;;) |
986 |
|
|
{ |
987 |
|
|
XGlyphInfo g1, g2; |
988 |
|
|
FcChar8 c; |
989 |
|
|
|
990 |
pcg |
1.2 |
c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
991 |
|
|
c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
992 |
pcg |
1.1 |
|
993 |
pcg |
1.7 |
if (g1.xOff != g2.xOff) // don't simply trust the font |
994 |
|
|
slow = true; |
995 |
pcg |
1.1 |
|
996 |
|
|
width = g2.xOff; |
997 |
|
|
ascent = (face->size->metrics.ascender + 63) >> 6; |
998 |
|
|
descent = (-face->size->metrics.descender + 63) >> 6; |
999 |
|
|
height = ascent + descent; |
1000 |
|
|
|
1001 |
pcg |
1.7 |
if (height <= prop.height || !prop.height) |
1002 |
pcg |
1.1 |
break; |
1003 |
|
|
|
1004 |
|
|
if (ftheight) |
1005 |
|
|
{ |
1006 |
|
|
// take smaller steps near the end |
1007 |
pcg |
1.7 |
if (height > prop.height + 1) ftheight++; |
1008 |
|
|
if (height > prop.height + 2) ftheight++; |
1009 |
|
|
if (height > prop.height + 3) ftheight++; |
1010 |
pcg |
1.1 |
|
1011 |
pcg |
1.7 |
FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
1012 |
pcg |
1.1 |
} |
1013 |
|
|
else |
1014 |
pcg |
1.7 |
FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
1015 |
pcg |
1.1 |
} |
1016 |
|
|
|
1017 |
|
|
XftUnlockFace (f); |
1018 |
|
|
|
1019 |
|
|
return true; |
1020 |
|
|
} |
1021 |
|
|
|
1022 |
|
|
bool |
1023 |
pcg |
1.40 |
rxvt_font_xft::has_codepoint (unicode_t unicode) |
1024 |
pcg |
1.1 |
{ |
1025 |
pcg |
1.2 |
return XftCharExists (DISPLAY, f, unicode); |
1026 |
pcg |
1.1 |
} |
1027 |
|
|
|
1028 |
|
|
void |
1029 |
pcg |
1.24 |
rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1030 |
pcg |
1.1 |
const text_t *text, int len, |
1031 |
|
|
int fg, int bg) |
1032 |
|
|
{ |
1033 |
pcg |
1.24 |
clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1034 |
pcg |
1.1 |
|
1035 |
pcg |
1.12 |
if (!slow && width == r->TermWin.fwidth && 0) |
1036 |
pcg |
1.1 |
{ |
1037 |
|
|
if (sizeof (text_t) == sizeof (FcChar16)) |
1038 |
pcg |
1.2 |
XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
1039 |
pcg |
1.1 |
else |
1040 |
pcg |
1.2 |
XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
1041 |
pcg |
1.1 |
} |
1042 |
|
|
else |
1043 |
|
|
{ |
1044 |
|
|
while (len) |
1045 |
|
|
{ |
1046 |
|
|
if (*text != NOCHAR && *text != ' ') |
1047 |
|
|
{ |
1048 |
pcg |
1.13 |
int fwidth = r->TermWin.fwidth; |
1049 |
|
|
if (len >= 2 && text[1] == NOCHAR) |
1050 |
|
|
fwidth *= 2; |
1051 |
|
|
|
1052 |
pcg |
1.12 |
XGlyphInfo extents; |
1053 |
pcg |
1.1 |
if (sizeof (text_t) == sizeof (FcChar16)) |
1054 |
pcg |
1.12 |
{ |
1055 |
pcg |
1.24 |
XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents); |
1056 |
pcg |
1.13 |
XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
1057 |
pcg |
1.12 |
y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
1058 |
|
|
} |
1059 |
pcg |
1.1 |
else |
1060 |
pcg |
1.12 |
{ |
1061 |
|
|
XGlyphInfo extents; |
1062 |
pcg |
1.24 |
XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents); |
1063 |
pcg |
1.13 |
XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
1064 |
pcg |
1.12 |
y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
1065 |
|
|
} |
1066 |
pcg |
1.1 |
} |
1067 |
|
|
|
1068 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
1069 |
pcg |
1.1 |
text++; |
1070 |
|
|
len--; |
1071 |
|
|
} |
1072 |
|
|
} |
1073 |
|
|
} |
1074 |
|
|
#endif |
1075 |
|
|
|
1076 |
|
|
///////////////////////////////////////////////////////////////////////////// |
1077 |
|
|
|
1078 |
pcg |
1.2 |
rxvt_fontset::rxvt_fontset (rxvt_t r) |
1079 |
pcg |
1.18 |
: r (r) |
1080 |
pcg |
1.1 |
{ |
1081 |
|
|
clear (); |
1082 |
|
|
} |
1083 |
|
|
|
1084 |
|
|
rxvt_fontset::~rxvt_fontset () |
1085 |
|
|
{ |
1086 |
|
|
clear (); |
1087 |
|
|
} |
1088 |
|
|
|
1089 |
|
|
void |
1090 |
|
|
rxvt_fontset::clear () |
1091 |
|
|
{ |
1092 |
pcg |
1.18 |
for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1093 |
pcg |
1.1 |
FONT_UNREF (*i); |
1094 |
|
|
|
1095 |
|
|
fonts.clear (); |
1096 |
|
|
base_id = 0; |
1097 |
pcg |
1.7 |
base_prop.height = 0x7fffffff; |
1098 |
|
|
base_prop.weight = rxvt_fontprop::medium; |
1099 |
|
|
base_prop.slant = rxvt_fontprop::roman; |
1100 |
pcg |
1.1 |
|
1101 |
|
|
fallback = fallback_fonts; |
1102 |
|
|
} |
1103 |
|
|
|
1104 |
|
|
rxvt_font * |
1105 |
|
|
rxvt_fontset::new_font (const char *name, codeset cs) |
1106 |
|
|
{ |
1107 |
|
|
rxvt_font *f; |
1108 |
|
|
|
1109 |
|
|
if (!name || !*name) |
1110 |
|
|
{ |
1111 |
|
|
name = ""; |
1112 |
|
|
f = new rxvt_font_default; |
1113 |
|
|
} |
1114 |
|
|
#if XFT |
1115 |
|
|
else if (!strncmp (name, "xft:", 4)) |
1116 |
|
|
{ |
1117 |
|
|
name += 4; |
1118 |
|
|
f = new rxvt_font_xft; |
1119 |
|
|
} |
1120 |
|
|
#endif |
1121 |
|
|
else if (!strncmp (name, "x:", 2)) |
1122 |
|
|
{ |
1123 |
|
|
name += 2; |
1124 |
|
|
f = new rxvt_font_x11; |
1125 |
|
|
} |
1126 |
|
|
else |
1127 |
|
|
f = new rxvt_font_x11; |
1128 |
|
|
|
1129 |
pcg |
1.36 |
f->fs = this; |
1130 |
pcg |
1.2 |
f->set_term (r); |
1131 |
pcg |
1.1 |
f->set_name (strdup (name)); |
1132 |
|
|
|
1133 |
|
|
f->cs = cs; |
1134 |
|
|
f->loaded = false; |
1135 |
|
|
|
1136 |
|
|
return f; |
1137 |
|
|
} |
1138 |
|
|
|
1139 |
|
|
///////////////////////////////////////////////////////////////////////////// |
1140 |
|
|
|
1141 |
|
|
void |
1142 |
|
|
rxvt_fontset::add_fonts (const char *desc) |
1143 |
|
|
{ |
1144 |
|
|
if (desc) |
1145 |
|
|
{ |
1146 |
|
|
char buf[512]; |
1147 |
|
|
const char *end; |
1148 |
|
|
|
1149 |
|
|
do |
1150 |
|
|
{ |
1151 |
|
|
while (*desc <= ' ') desc++; |
1152 |
|
|
|
1153 |
|
|
if (*desc == '[') |
1154 |
|
|
{ |
1155 |
|
|
fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1156 |
|
|
|
1157 |
pcg |
1.16 |
//const char *extra = desc++; // not yet used |
1158 |
pcg |
1.1 |
|
1159 |
|
|
desc = strchr (desc, ']'); |
1160 |
|
|
|
1161 |
|
|
if (!desc) |
1162 |
|
|
{ |
1163 |
|
|
fprintf (stderr, "ERROR: opening '[' without closing ']' in font specification.\n"); |
1164 |
|
|
break; |
1165 |
|
|
} |
1166 |
|
|
|
1167 |
|
|
desc++; |
1168 |
|
|
while (*desc <= ' ') desc++; |
1169 |
|
|
} |
1170 |
|
|
|
1171 |
|
|
end = strchr (desc, ','); |
1172 |
|
|
if (!end) |
1173 |
|
|
end = desc + strlen (desc); |
1174 |
|
|
|
1175 |
|
|
if (end - desc < 511) |
1176 |
|
|
{ |
1177 |
|
|
strncpy (buf, desc, end - desc); |
1178 |
|
|
buf[end - desc] = 0; |
1179 |
|
|
|
1180 |
|
|
fonts.push_back (new_font (buf, CS_UNICODE)); |
1181 |
|
|
} |
1182 |
|
|
|
1183 |
|
|
desc = end + 1; |
1184 |
|
|
} |
1185 |
|
|
while (*end); |
1186 |
|
|
} |
1187 |
|
|
} |
1188 |
|
|
|
1189 |
|
|
bool |
1190 |
|
|
rxvt_fontset::realize_font (int i) |
1191 |
|
|
{ |
1192 |
|
|
if (fonts[i]->loaded) |
1193 |
|
|
return true; |
1194 |
|
|
|
1195 |
pcg |
1.5 |
fonts[i]->loaded = true; |
1196 |
pcg |
1.1 |
|
1197 |
pcg |
1.7 |
if (!fonts[i]->load (base_prop)) |
1198 |
pcg |
1.5 |
{ |
1199 |
|
|
fonts[i]->cs = CS_UNKNOWN; |
1200 |
|
|
return false; |
1201 |
|
|
} |
1202 |
pcg |
1.1 |
|
1203 |
pcg |
1.5 |
return true; |
1204 |
pcg |
1.1 |
} |
1205 |
|
|
|
1206 |
pcg |
1.23 |
bool |
1207 |
pcg |
1.1 |
rxvt_fontset::populate (const char *desc) |
1208 |
|
|
{ |
1209 |
|
|
clear (); |
1210 |
|
|
|
1211 |
|
|
fonts.push_back (new_font (0, CS_UNICODE)); |
1212 |
|
|
realize_font (0); |
1213 |
|
|
|
1214 |
|
|
add_fonts (desc); |
1215 |
|
|
|
1216 |
|
|
if (!base_id) |
1217 |
|
|
base_id = 1; |
1218 |
|
|
|
1219 |
|
|
// we currently need a base-font, no matter what |
1220 |
pcg |
1.16 |
if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1221 |
pcg |
1.1 |
{ |
1222 |
pcg |
1.18 |
puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
1223 |
pcg |
1.1 |
add_fonts ("fixed"); |
1224 |
pcg |
1.7 |
base_id = fonts.size () - 1; |
1225 |
pcg |
1.1 |
} |
1226 |
|
|
|
1227 |
pcg |
1.16 |
if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1228 |
pcg |
1.23 |
return false; |
1229 |
pcg |
1.1 |
|
1230 |
pcg |
1.7 |
base_prop = fonts[base_id]->properties (); |
1231 |
pcg |
1.23 |
|
1232 |
|
|
return true; |
1233 |
pcg |
1.1 |
} |
1234 |
|
|
|
1235 |
|
|
int |
1236 |
pcg |
1.40 |
rxvt_fontset::find_font (unicode_t unicode) |
1237 |
pcg |
1.1 |
{ |
1238 |
pcg |
1.16 |
for (unsigned int i = 0; i < fonts.size (); i++) |
1239 |
pcg |
1.1 |
{ |
1240 |
|
|
rxvt_font *f = fonts[i]; |
1241 |
|
|
|
1242 |
|
|
if (!f->loaded) |
1243 |
|
|
{ |
1244 |
|
|
if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1245 |
|
|
goto next_font; |
1246 |
|
|
|
1247 |
|
|
if (!realize_font (i)) |
1248 |
pcg |
1.5 |
goto next_font; |
1249 |
pcg |
1.1 |
} |
1250 |
|
|
|
1251 |
pcg |
1.5 |
if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
1252 |
pcg |
1.1 |
return i; |
1253 |
|
|
|
1254 |
|
|
next_font: |
1255 |
|
|
if (i == fonts.size () - 1 && fallback->name) |
1256 |
|
|
{ |
1257 |
|
|
fonts.push_back (new_font (fallback->name, fallback->cs)); |
1258 |
|
|
fallback++; |
1259 |
pcg |
1.5 |
i = 0; |
1260 |
pcg |
1.1 |
} |
1261 |
|
|
} |
1262 |
|
|
|
1263 |
|
|
return 0; /* we must return SOME font */ |
1264 |
|
|
} |
1265 |
|
|
|
1266 |
|
|
|
1267 |
|
|
|