1 |
pcg |
1.1 |
/*--------------------------------*-C-*---------------------------------*; |
2 |
|
|
* File: defaultfont.C |
3 |
|
|
*----------------------------------------------------------------------* |
4 |
|
|
* Copyright (c) 2003 Marc Lehmann rxvt@plan9.de> |
5 |
|
|
* - 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.2 |
#define DISPLAY r->Xdisplay |
29 |
|
|
#define DRAWABLE r->TermWin.vt |
30 |
|
|
#define GC r->TermWin.gc |
31 |
pcg |
1.1 |
|
32 |
|
|
const struct rxvt_fallback_font { |
33 |
|
|
codeset cs; |
34 |
|
|
const char *name; |
35 |
|
|
} fallback_fonts[] = { |
36 |
|
|
{ CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
37 |
|
|
{ CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
38 |
|
|
{ CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
39 |
|
|
|
40 |
|
|
#if ENCODING_EU |
41 |
|
|
// cyrillic |
42 |
|
|
{ CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
43 |
|
|
{ CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
44 |
|
|
|
45 |
|
|
{ CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
46 |
|
|
{ CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
47 |
|
|
{ CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
48 |
|
|
{ CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
49 |
|
|
{ CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
50 |
|
|
{ CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, |
51 |
|
|
{ CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, |
52 |
|
|
{ CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, |
53 |
|
|
{ CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
54 |
|
|
{ CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
55 |
|
|
{ CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
56 |
|
|
{ CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
57 |
|
|
{ CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
58 |
|
|
#endif |
59 |
|
|
|
60 |
|
|
// japanese |
61 |
|
|
#if ENCODING_JP || ENCODING_JP_EXT |
62 |
|
|
# if XFT |
63 |
|
|
// prefer xft for complex scripts |
64 |
pcg |
1.9 |
{ CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
65 |
pcg |
1.1 |
# endif |
66 |
pcg |
1.9 |
{ CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
67 |
|
|
{ CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
68 |
|
|
{ CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
69 |
pcg |
1.1 |
#endif |
70 |
|
|
|
71 |
|
|
#if ENCODING_CN || ENCODING_CN_EXT |
72 |
|
|
# if XFT |
73 |
pcg |
1.9 |
{ CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
74 |
|
|
{ CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
75 |
|
|
{ CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
76 |
|
|
{ CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
77 |
pcg |
1.1 |
# endif |
78 |
pcg |
1.9 |
{ CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
79 |
|
|
{ CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
80 |
|
|
{ CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
81 |
|
|
{ CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
82 |
|
|
{ CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
83 |
|
|
{ CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
84 |
|
|
{ CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
85 |
|
|
{ CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
86 |
pcg |
1.1 |
#endif |
87 |
|
|
|
88 |
|
|
#if XFT |
89 |
pcg |
1.9 |
{ CS_UNICODE, "xft:Andale Mono" }, |
90 |
|
|
{ CS_UNICODE, "xft:Arial Unicode MS" }, |
91 |
pcg |
1.1 |
#endif |
92 |
pcg |
1.9 |
{ CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
93 |
|
|
{ CS_UNICODE, "xft:FreeMono" }, |
94 |
|
|
{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
95 |
|
|
{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
96 |
|
|
{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
97 |
pcg |
1.1 |
|
98 |
|
|
{ CS_UNKNOWN, 0 } |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////// |
102 |
|
|
|
103 |
|
|
static void *enc_buf; |
104 |
|
|
static uint32_t enc_len; |
105 |
|
|
|
106 |
|
|
static inline void * |
107 |
|
|
get_enc_buf (int len) |
108 |
|
|
{ |
109 |
|
|
if (len > enc_len) |
110 |
|
|
{ |
111 |
|
|
free (enc_buf); |
112 |
|
|
enc_buf = malloc (len); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
return enc_buf; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
static const char * |
119 |
|
|
enc_char (const text_t *text, int len, codeset cs, bool &zero) |
120 |
|
|
{ |
121 |
|
|
uint8_t *buf = (uint8_t *)get_enc_buf (len); |
122 |
|
|
|
123 |
|
|
while (len--) |
124 |
|
|
{ |
125 |
|
|
uint32_t c = FROM_UNICODE (cs, *text++); |
126 |
|
|
|
127 |
|
|
if (c == NOCHAR) |
128 |
|
|
{ |
129 |
|
|
c = 0; |
130 |
|
|
zero = true; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
*buf++ = c; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
return (const char *)enc_buf; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
static const XChar2b * |
140 |
|
|
enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) |
141 |
|
|
{ |
142 |
|
|
XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
143 |
|
|
|
144 |
|
|
while (len--) |
145 |
|
|
{ |
146 |
|
|
uint32_t c = FROM_UNICODE (cs, *text++); |
147 |
|
|
|
148 |
|
|
if (c == NOCHAR) |
149 |
|
|
{ |
150 |
|
|
c = 0; |
151 |
|
|
zero = true; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
buf->byte1 = c >> 8; |
155 |
|
|
buf->byte2 = c; |
156 |
|
|
buf++; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
return (XChar2b *)enc_buf; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
///////////////////////////////////////////////////////////////////////////// |
163 |
|
|
|
164 |
|
|
void |
165 |
|
|
rxvt_font::clear_rect (int x, int y, int w, int h, int color) |
166 |
|
|
{ |
167 |
|
|
if (color == Color_bg) |
168 |
|
|
XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
169 |
|
|
else if (color >= 0) |
170 |
|
|
{ |
171 |
pcg |
1.2 |
XSetForeground (DISPLAY, GC, r->PixColors[color]); |
172 |
pcg |
1.1 |
XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
|
|
176 |
pcg |
1.3 |
static const char *linedraw_cmds[128] = { |
177 |
|
|
"1hH", "2hH", "1vV", "2vV", |
178 |
|
|
0, 0, 0, 0, |
179 |
|
|
0, 0, 0, 0, |
180 |
|
|
"1HV", "2H1V", "1H2V", "2HV", |
181 |
|
|
|
182 |
|
|
// 2510 |
183 |
|
|
"1hV", "2h1V", "1h2V", "2hV", |
184 |
|
|
"1Hv", "2H1v", "1H2v", "2Hv", |
185 |
|
|
"1hv", "2h1v", "1h2v", "2hv", |
186 |
|
|
"1HvV", "2H1vV", "1HV2v", "1Hv2V", |
187 |
|
|
|
188 |
|
|
// 2520 |
189 |
|
|
"1H2vV", "2Hv1V", "2HV1v", "2HvV", |
190 |
|
|
"1hvV", "2h1vV", "1hV2v", "1hv2V", |
191 |
|
|
"1h2vV", "2hv1V", "1v2hV", "2hvV", |
192 |
|
|
"1hHV", "2h1HV", "2H1hV", "2hH1V", |
193 |
|
|
|
194 |
|
|
// 2530 |
195 |
|
|
"1hH2V", "2hV1H", "1h2HV", "2hHV", |
196 |
|
|
"1hHv", "1vH2h", "1hv2H", "1v2hH", |
197 |
|
|
"1hH2v", "1H2hv", "1h2Hv", "2hHv", |
198 |
|
|
"1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", |
199 |
|
|
|
200 |
|
|
// 2540 |
201 |
|
|
"1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", |
202 |
|
|
"1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", |
203 |
|
|
"1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", |
204 |
|
|
0, 0, 0, 0, |
205 |
|
|
|
206 |
|
|
// 2550 |
207 |
|
|
0, 0, 0, 0, |
208 |
|
|
0, 0, 0, 0, |
209 |
|
|
0, 0, 0, 0, |
210 |
|
|
0, 0, 0, 0, |
211 |
|
|
|
212 |
|
|
// 2560 |
213 |
|
|
0, 0, 0, 0, |
214 |
|
|
0, 0, 0, 0, |
215 |
|
|
0, 0, 0, 0, |
216 |
|
|
0, 0, 0, 0, |
217 |
|
|
|
218 |
|
|
// 2570 |
219 |
|
|
0, "1a", "1b", "1ab", |
220 |
|
|
"1h", "1v", "1H", "1V", |
221 |
|
|
"2h", "2v", "2H", "2V", |
222 |
|
|
"1h2H", "1v2V", "1H2h", "1V2v" |
223 |
|
|
|
224 |
|
|
// to be done |
225 |
|
|
}; |
226 |
|
|
|
227 |
pcg |
1.1 |
struct rxvt_font_default : rxvt_font { |
228 |
pcg |
1.7 |
rxvt_fontprop properties () |
229 |
|
|
{ |
230 |
|
|
rxvt_fontprop p; |
231 |
|
|
|
232 |
pcg |
1.10 |
p.width = p.height = 1; |
233 |
pcg |
1.7 |
p.weight = rxvt_fontprop::medium; |
234 |
|
|
p.slant = rxvt_fontprop::roman; |
235 |
|
|
|
236 |
|
|
return p; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
bool load (const rxvt_fontprop &prop) |
240 |
pcg |
1.1 |
{ |
241 |
|
|
width = 1; height = 1; |
242 |
|
|
ascent = 1; descent = 0; |
243 |
|
|
|
244 |
|
|
return true; |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
bool has_codepoint (uint32_t unicode) |
248 |
|
|
{ |
249 |
pcg |
1.3 |
if (unicode <= 0x001f) |
250 |
|
|
return true; |
251 |
|
|
if (unicode >= 0x0080 && unicode <= 0x009f) |
252 |
|
|
return true; |
253 |
|
|
|
254 |
|
|
if (unicode >= 0x2500 && unicode <= 0x257f |
255 |
|
|
&& linedraw_cmds[unicode - 0x2500]) |
256 |
pcg |
1.1 |
return true; |
257 |
|
|
|
258 |
|
|
switch (unicode) |
259 |
|
|
{ |
260 |
|
|
case ZERO_WIDTH_CHAR: |
261 |
|
|
return true; |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
return false; |
265 |
|
|
} |
266 |
|
|
|
267 |
|
|
void draw (int x, int y, |
268 |
|
|
const text_t *text, int len, |
269 |
|
|
int fg, int bg); |
270 |
|
|
}; |
271 |
|
|
|
272 |
|
|
void |
273 |
|
|
rxvt_font_default::draw (int x, int y, |
274 |
|
|
const text_t *text, int len, |
275 |
|
|
int fg, int bg) |
276 |
|
|
{ |
277 |
pcg |
1.2 |
clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
278 |
pcg |
1.1 |
|
279 |
pcg |
1.3 |
XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
280 |
|
|
|
281 |
pcg |
1.1 |
while (len--) |
282 |
|
|
{ |
283 |
pcg |
1.3 |
text_t t = *text++; |
284 |
|
|
|
285 |
|
|
if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
286 |
pcg |
1.1 |
{ |
287 |
pcg |
1.3 |
const char *p = linedraw_cmds[t - 0x2500]; |
288 |
|
|
|
289 |
pcg |
1.4 |
int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
290 |
|
|
int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; |
291 |
pcg |
1.3 |
|
292 |
|
|
XGCValues gcv; |
293 |
|
|
|
294 |
|
|
while (*p) |
295 |
|
|
{ |
296 |
|
|
switch (*p++) |
297 |
|
|
{ |
298 |
|
|
case '1': |
299 |
|
|
gcv.line_width = 0; |
300 |
|
|
XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
301 |
|
|
break; |
302 |
|
|
|
303 |
|
|
case '2': |
304 |
|
|
gcv.line_width = 2; |
305 |
|
|
XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
306 |
|
|
break; |
307 |
|
|
|
308 |
|
|
case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
309 |
|
|
case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
310 |
|
|
case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
311 |
|
|
case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
312 |
|
|
case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
313 |
|
|
case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
314 |
|
|
} |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
gcv.line_width = 0; |
318 |
|
|
XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
319 |
pcg |
1.1 |
} |
320 |
pcg |
1.3 |
else |
321 |
|
|
switch (*text++) |
322 |
|
|
{ |
323 |
|
|
case NOCHAR: |
324 |
|
|
case ZERO_WIDTH_CHAR: |
325 |
|
|
break; |
326 |
|
|
default: |
327 |
|
|
XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
328 |
|
|
} |
329 |
pcg |
1.1 |
|
330 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
331 |
pcg |
1.1 |
} |
332 |
|
|
} |
333 |
|
|
|
334 |
|
|
///////////////////////////////////////////////////////////////////////////// |
335 |
|
|
|
336 |
|
|
struct rxvt_font_x11 : rxvt_font { |
337 |
|
|
rxvt_font_x11 () { f = 0; } |
338 |
|
|
|
339 |
|
|
void clear (); |
340 |
|
|
|
341 |
pcg |
1.7 |
rxvt_fontprop properties (); |
342 |
|
|
rxvt_fontprop properties (XFontStruct *f); |
343 |
|
|
|
344 |
|
|
bool load (const rxvt_fontprop &prop); |
345 |
pcg |
1.1 |
|
346 |
|
|
bool has_codepoint (uint32_t unicode); |
347 |
|
|
|
348 |
|
|
void draw (int x, int y, |
349 |
|
|
const text_t *text, int len, |
350 |
|
|
int fg, int bg); |
351 |
|
|
|
352 |
|
|
XFontStruct *f; |
353 |
|
|
codeset cs; |
354 |
|
|
bool enc2b, encm; |
355 |
|
|
|
356 |
pcg |
1.7 |
const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
357 |
pcg |
1.1 |
}; |
358 |
|
|
|
359 |
|
|
const char * |
360 |
pcg |
1.7 |
rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
361 |
pcg |
1.1 |
{ |
362 |
|
|
unsigned long value; |
363 |
|
|
|
364 |
|
|
if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
365 |
|
|
return XGetAtomName (DISPLAY, value); |
366 |
|
|
else |
367 |
|
|
return repl; |
368 |
|
|
} |
369 |
|
|
|
370 |
pcg |
1.7 |
rxvt_fontprop |
371 |
|
|
rxvt_font_x11::properties () |
372 |
|
|
{ |
373 |
|
|
return properties (f); |
374 |
|
|
} |
375 |
|
|
|
376 |
|
|
rxvt_fontprop |
377 |
|
|
rxvt_font_x11::properties (XFontStruct *f) |
378 |
|
|
{ |
379 |
|
|
rxvt_fontprop p; |
380 |
|
|
|
381 |
|
|
const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
382 |
|
|
const char *slant = get_property (f, "SLANT", "r"); |
383 |
|
|
|
384 |
pcg |
1.10 |
unsigned long avgwidth; |
385 |
|
|
p.width = XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth) |
386 |
|
|
? avgwidth / 10 |
387 |
|
|
: (height + 1) / 2; |
388 |
pcg |
1.7 |
p.height = height; |
389 |
|
|
p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
390 |
|
|
p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
391 |
|
|
|
392 |
|
|
return p; |
393 |
|
|
} |
394 |
|
|
|
395 |
pcg |
1.1 |
bool |
396 |
pcg |
1.7 |
rxvt_font_x11::load (const rxvt_fontprop &prop) |
397 |
pcg |
1.1 |
{ |
398 |
|
|
clear (); |
399 |
|
|
|
400 |
pcg |
1.6 |
char **list; |
401 |
|
|
int count; |
402 |
|
|
XFontStruct *info; |
403 |
|
|
list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
404 |
|
|
|
405 |
|
|
if (!list) |
406 |
|
|
return false; |
407 |
|
|
|
408 |
pcg |
1.7 |
int bestdiff = 0x7fffffff; |
409 |
pcg |
1.6 |
XFontStruct *best = 0; |
410 |
|
|
for (int i = 0; i < count; i++) |
411 |
|
|
{ |
412 |
|
|
XFontStruct *f = info + i; |
413 |
pcg |
1.7 |
|
414 |
|
|
if (f->ascent + f->descent <= prop.height) // weed out too large fonts |
415 |
|
|
{ |
416 |
|
|
rxvt_fontprop p = properties (f); |
417 |
|
|
int diff = (prop.height - f->ascent + f->descent) * 32 |
418 |
|
|
+ abs (prop.weight - p.weight) |
419 |
|
|
+ abs (prop.slant - p.slant ); |
420 |
|
|
|
421 |
|
|
if (!best // compare against best found so far |
422 |
|
|
|| diff < bestdiff) |
423 |
|
|
{ |
424 |
|
|
best = f; |
425 |
|
|
bestdiff = diff; |
426 |
|
|
} |
427 |
|
|
} |
428 |
pcg |
1.6 |
} |
429 |
pcg |
1.9 |
|
430 |
|
|
if (!best) |
431 |
|
|
return false; |
432 |
pcg |
1.6 |
|
433 |
|
|
set_name (strdup (list[best - info])); |
434 |
|
|
|
435 |
|
|
XFreeFontInfo (list, info, count); |
436 |
|
|
|
437 |
pcg |
1.1 |
f = XLoadQueryFont (DISPLAY, name); |
438 |
|
|
|
439 |
|
|
if (!f) |
440 |
|
|
return false; |
441 |
|
|
|
442 |
|
|
unsigned long value; |
443 |
|
|
|
444 |
pcg |
1.7 |
const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
445 |
|
|
const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
446 |
pcg |
1.1 |
|
447 |
|
|
if (registry && encoding) |
448 |
|
|
{ |
449 |
|
|
char charset[64]; |
450 |
|
|
snprintf (charset, 64, "%s-%s", registry, encoding); |
451 |
|
|
|
452 |
|
|
cs = codeset_from_name (charset); |
453 |
|
|
} |
454 |
|
|
else |
455 |
|
|
{ |
456 |
pcg |
1.7 |
const char *charset = get_property (f, "FONT", 0); |
457 |
pcg |
1.1 |
|
458 |
|
|
if (!charset) |
459 |
|
|
charset = name; |
460 |
|
|
|
461 |
|
|
int count = 13; |
462 |
|
|
while (*charset) |
463 |
|
|
if (*charset++ == '-' && !--count) |
464 |
|
|
break; |
465 |
|
|
|
466 |
|
|
cs = codeset_from_name (charset); |
467 |
|
|
} |
468 |
|
|
|
469 |
|
|
if (cs == CS_UNICODE) |
470 |
|
|
cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
471 |
|
|
|
472 |
|
|
encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
473 |
|
|
enc2b = encm || f->max_char_or_byte2 > 255; |
474 |
|
|
|
475 |
|
|
ascent = f->ascent; |
476 |
|
|
descent = f->descent; |
477 |
|
|
height = ascent + descent; |
478 |
|
|
|
479 |
pcg |
1.7 |
slow = false; |
480 |
pcg |
1.1 |
|
481 |
|
|
if (f->min_bounds.width == f->max_bounds.width) |
482 |
|
|
width = f->min_bounds.width; |
483 |
|
|
else if (f->per_char == NULL) |
484 |
|
|
width = f->max_bounds.width; |
485 |
|
|
else |
486 |
|
|
{ |
487 |
pcg |
1.7 |
slow = true; |
488 |
pcg |
1.1 |
|
489 |
|
|
int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
490 |
|
|
|
491 |
|
|
if (encm) |
492 |
|
|
N += (f->max_byte1 - f->min_byte1) |
493 |
|
|
* (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); |
494 |
|
|
|
495 |
|
|
while (N) |
496 |
|
|
{ |
497 |
|
|
if (f->per_char[N].width > width) |
498 |
|
|
width = f->per_char[N].width; |
499 |
|
|
|
500 |
|
|
--N; |
501 |
|
|
} |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
if (cs == CS_UNKNOWN) |
505 |
|
|
{ |
506 |
|
|
fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
507 |
|
|
|
508 |
|
|
clear (); |
509 |
|
|
|
510 |
|
|
return false; |
511 |
|
|
} |
512 |
|
|
|
513 |
|
|
return true; |
514 |
|
|
} |
515 |
|
|
|
516 |
|
|
void |
517 |
|
|
rxvt_font_x11::clear () |
518 |
|
|
{ |
519 |
|
|
if (f) |
520 |
|
|
{ |
521 |
|
|
XFreeFont (DISPLAY, f); |
522 |
|
|
f = 0; |
523 |
|
|
} |
524 |
|
|
} |
525 |
|
|
|
526 |
|
|
bool |
527 |
|
|
rxvt_font_x11::has_codepoint (uint32_t unicode) |
528 |
|
|
{ |
529 |
|
|
uint32_t ch = FROM_UNICODE (cs, unicode); |
530 |
|
|
|
531 |
|
|
if (ch == NOCHAR) |
532 |
|
|
return false; |
533 |
|
|
|
534 |
|
|
/* check wether the character exists in _this_ font. horrible. */ |
535 |
|
|
XCharStruct *xcs; |
536 |
|
|
|
537 |
|
|
if (encm) |
538 |
|
|
{ |
539 |
|
|
int byte1 = ch >> 8; |
540 |
|
|
int byte2 = ch & 255; |
541 |
|
|
|
542 |
|
|
if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
543 |
|
|
|| byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
544 |
|
|
return false; |
545 |
|
|
|
546 |
|
|
if (!f->per_char) |
547 |
|
|
return true; |
548 |
|
|
|
549 |
|
|
int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1; |
550 |
|
|
int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2; |
551 |
|
|
|
552 |
|
|
xcs = f->per_char + N; |
553 |
|
|
} |
554 |
|
|
else |
555 |
|
|
{ |
556 |
|
|
if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2) |
557 |
|
|
return false; |
558 |
|
|
|
559 |
|
|
if (!f->per_char) |
560 |
|
|
return true; |
561 |
|
|
|
562 |
|
|
xcs = f->per_char + (ch - f->min_char_or_byte2); |
563 |
|
|
} |
564 |
|
|
|
565 |
|
|
if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0 |
566 |
|
|
&& xcs->ascent == 0 && xcs->descent == 0) |
567 |
|
|
return false; |
568 |
|
|
|
569 |
|
|
return true; |
570 |
|
|
} |
571 |
|
|
|
572 |
|
|
void |
573 |
|
|
rxvt_font_x11::draw (int x, int y, |
574 |
|
|
const text_t *text, int len, |
575 |
|
|
int fg, int bg) |
576 |
|
|
{ |
577 |
|
|
// this looks like a mess /. |
578 |
|
|
// and it is a mess /. |
579 |
|
|
// yet we are trying to be perfect /. |
580 |
|
|
// but the result still isn't perfect /. |
581 |
|
|
|
582 |
pcg |
1.7 |
bool slow = this->slow |
583 |
pcg |
1.2 |
|| width != r->TermWin.fwidth |
584 |
|
|
|| height != r->TermWin.fheight; |
585 |
pcg |
1.1 |
|
586 |
pcg |
1.2 |
int base = r->TermWin.fbase; |
587 |
pcg |
1.1 |
|
588 |
|
|
XGCValues v; |
589 |
pcg |
1.2 |
v.foreground = r->PixColors[fg]; |
590 |
|
|
v.background = r->PixColors[bg]; |
591 |
pcg |
1.1 |
v.font = f->fid; |
592 |
|
|
|
593 |
|
|
if (enc2b) |
594 |
|
|
{ |
595 |
|
|
const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
596 |
|
|
|
597 |
|
|
if (bg == Color_bg && !slow) |
598 |
|
|
{ |
599 |
|
|
XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
600 |
|
|
XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
601 |
|
|
} |
602 |
|
|
else |
603 |
|
|
{ |
604 |
pcg |
1.2 |
clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
605 |
pcg |
1.1 |
|
606 |
|
|
XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
607 |
|
|
|
608 |
|
|
if (slow) |
609 |
|
|
{ |
610 |
|
|
do |
611 |
|
|
{ |
612 |
|
|
if (xc->byte1 || xc->byte2) |
613 |
|
|
XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
614 |
|
|
|
615 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
616 |
pcg |
1.1 |
xc++; len--; |
617 |
|
|
} |
618 |
|
|
while (len); |
619 |
|
|
} |
620 |
|
|
else |
621 |
|
|
XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
622 |
|
|
} |
623 |
|
|
} |
624 |
|
|
else |
625 |
|
|
{ |
626 |
|
|
const char *xc = enc_char (text, len, cs, slow); |
627 |
|
|
|
628 |
|
|
if (bg == Color_bg && !slow) |
629 |
|
|
{ |
630 |
|
|
XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
631 |
|
|
XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
632 |
|
|
} |
633 |
|
|
else |
634 |
|
|
{ |
635 |
pcg |
1.2 |
clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
636 |
pcg |
1.1 |
|
637 |
|
|
XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
638 |
|
|
|
639 |
|
|
if (slow) |
640 |
|
|
{ |
641 |
|
|
do |
642 |
|
|
{ |
643 |
|
|
if (*xc) |
644 |
|
|
XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
645 |
|
|
|
646 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
647 |
pcg |
1.1 |
xc++; len--; |
648 |
|
|
} |
649 |
|
|
while (len); |
650 |
|
|
} |
651 |
|
|
else |
652 |
|
|
XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
653 |
|
|
} |
654 |
|
|
} |
655 |
|
|
} |
656 |
|
|
|
657 |
|
|
///////////////////////////////////////////////////////////////////////////// |
658 |
|
|
|
659 |
|
|
#if XFT |
660 |
|
|
#if 0 |
661 |
|
|
#define UNIBITS 21 |
662 |
|
|
//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
663 |
|
|
#define SWATHBITS 8 |
664 |
|
|
#endif |
665 |
|
|
|
666 |
|
|
struct rxvt_font_xft : rxvt_font { |
667 |
|
|
rxvt_font_xft () { f = 0; d = 0; } |
668 |
|
|
|
669 |
|
|
void clear (); |
670 |
|
|
|
671 |
pcg |
1.7 |
rxvt_fontprop properties (); |
672 |
|
|
|
673 |
|
|
bool load (const rxvt_fontprop &prop); |
674 |
pcg |
1.1 |
|
675 |
|
|
void draw (int x, int y, |
676 |
|
|
const text_t *text, int len, |
677 |
|
|
int fg, int bg); |
678 |
|
|
|
679 |
|
|
bool has_codepoint (uint32_t unicode); |
680 |
|
|
|
681 |
|
|
protected: |
682 |
|
|
XftFont *f; |
683 |
|
|
XftDraw *d; |
684 |
|
|
}; |
685 |
|
|
|
686 |
|
|
void |
687 |
|
|
rxvt_font_xft::clear () |
688 |
|
|
{ |
689 |
|
|
if (f) |
690 |
|
|
{ |
691 |
pcg |
1.2 |
XftFontClose (DISPLAY, f); |
692 |
pcg |
1.1 |
f = 0; |
693 |
|
|
} |
694 |
|
|
|
695 |
|
|
if (d) |
696 |
|
|
{ |
697 |
|
|
XftDrawDestroy (d); |
698 |
|
|
d = 0; |
699 |
|
|
} |
700 |
|
|
} |
701 |
|
|
|
702 |
pcg |
1.7 |
rxvt_fontprop |
703 |
|
|
rxvt_font_xft::properties () |
704 |
|
|
{ |
705 |
|
|
rxvt_fontprop p; |
706 |
|
|
|
707 |
|
|
FT_Face face = XftLockFace (f); |
708 |
|
|
|
709 |
pcg |
1.10 |
p.width = width; p.height = height; |
710 |
pcg |
1.7 |
p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
711 |
|
|
p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
712 |
|
|
|
713 |
|
|
XftUnlockFace (f); |
714 |
|
|
|
715 |
|
|
return p; |
716 |
|
|
} |
717 |
|
|
|
718 |
pcg |
1.1 |
bool |
719 |
pcg |
1.7 |
rxvt_font_xft::load (const rxvt_fontprop &prop) |
720 |
pcg |
1.1 |
{ |
721 |
|
|
#if 0 |
722 |
|
|
for (int i = 0; i < SWATHCOUNT; i++) |
723 |
|
|
cvr[i] = 0; |
724 |
|
|
#endif |
725 |
|
|
|
726 |
|
|
clear (); |
727 |
|
|
|
728 |
pcg |
1.7 |
FcPattern *p = FcNameParse ((FcChar8 *) name); |
729 |
|
|
|
730 |
|
|
if (!p) |
731 |
|
|
return false; |
732 |
|
|
|
733 |
|
|
FcValue v; |
734 |
|
|
|
735 |
|
|
if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
736 |
|
|
FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
737 |
|
|
|
738 |
|
|
if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
739 |
|
|
FcPatternAddInteger (p, FC_SLANT, prop.slant); |
740 |
|
|
|
741 |
pcg |
1.11 |
#if 0 // clipping unfortunately destroys our precious double-width-characters |
742 |
pcg |
1.10 |
// clip width, we can't do better, or can we? |
743 |
|
|
if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
744 |
|
|
FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
745 |
pcg |
1.11 |
#endif |
746 |
pcg |
1.10 |
|
747 |
pcg |
1.7 |
//FcPatternAddBool (p, FC_MINSPACE, 1); |
748 |
|
|
|
749 |
|
|
XftResult result; |
750 |
|
|
FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
751 |
|
|
|
752 |
|
|
FcPatternDestroy (p); |
753 |
|
|
|
754 |
|
|
if (!match) |
755 |
|
|
return false; |
756 |
|
|
|
757 |
|
|
f = XftFontOpenPattern (DISPLAY, match); |
758 |
|
|
|
759 |
pcg |
1.1 |
if (!f) |
760 |
pcg |
1.8 |
{ |
761 |
|
|
FcPatternDestroy (match); |
762 |
|
|
return false; |
763 |
|
|
} |
764 |
pcg |
1.1 |
|
765 |
|
|
FT_Face face = XftLockFace (f); |
766 |
|
|
|
767 |
pcg |
1.7 |
slow = !FT_IS_FIXED_WIDTH (face); |
768 |
pcg |
1.1 |
|
769 |
|
|
int ftheight = 0; |
770 |
|
|
|
771 |
|
|
for (;;) |
772 |
|
|
{ |
773 |
|
|
XGlyphInfo g1, g2; |
774 |
|
|
FcChar8 c; |
775 |
|
|
|
776 |
pcg |
1.2 |
c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
777 |
|
|
c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
778 |
pcg |
1.1 |
|
779 |
pcg |
1.7 |
if (g1.xOff != g2.xOff) // don't simply trust the font |
780 |
|
|
slow = true; |
781 |
pcg |
1.1 |
|
782 |
|
|
width = g2.xOff; |
783 |
|
|
ascent = (face->size->metrics.ascender + 63) >> 6; |
784 |
|
|
descent = (-face->size->metrics.descender + 63) >> 6; |
785 |
|
|
height = ascent + descent; |
786 |
|
|
|
787 |
pcg |
1.7 |
if (height <= prop.height || !prop.height) |
788 |
pcg |
1.1 |
break; |
789 |
|
|
|
790 |
|
|
if (ftheight) |
791 |
|
|
{ |
792 |
|
|
// take smaller steps near the end |
793 |
pcg |
1.7 |
if (height > prop.height + 1) ftheight++; |
794 |
|
|
if (height > prop.height + 2) ftheight++; |
795 |
|
|
if (height > prop.height + 3) ftheight++; |
796 |
pcg |
1.1 |
|
797 |
pcg |
1.7 |
FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
798 |
pcg |
1.1 |
} |
799 |
|
|
else |
800 |
pcg |
1.7 |
FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
801 |
pcg |
1.1 |
} |
802 |
|
|
|
803 |
|
|
XftUnlockFace (f); |
804 |
|
|
|
805 |
|
|
return true; |
806 |
|
|
} |
807 |
|
|
|
808 |
|
|
bool |
809 |
|
|
rxvt_font_xft::has_codepoint (uint32_t unicode) |
810 |
|
|
{ |
811 |
pcg |
1.2 |
return XftCharExists (DISPLAY, f, unicode); |
812 |
pcg |
1.1 |
} |
813 |
|
|
|
814 |
|
|
void |
815 |
|
|
rxvt_font_xft::draw (int x, int y, |
816 |
|
|
const text_t *text, int len, |
817 |
|
|
int fg, int bg) |
818 |
|
|
{ |
819 |
|
|
if (!d) |
820 |
pcg |
1.2 |
{ |
821 |
|
|
dR; |
822 |
|
|
d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP); |
823 |
|
|
} |
824 |
pcg |
1.1 |
|
825 |
|
|
if (bg >= 0 && bg != Color_bg) |
826 |
pcg |
1.2 |
XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
827 |
pcg |
1.1 |
else |
828 |
pcg |
1.2 |
clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
829 |
pcg |
1.1 |
|
830 |
pcg |
1.7 |
if (!slow && width == r->TermWin.fwidth) |
831 |
pcg |
1.1 |
{ |
832 |
|
|
if (sizeof (text_t) == sizeof (FcChar16)) |
833 |
pcg |
1.2 |
XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
834 |
pcg |
1.1 |
else |
835 |
pcg |
1.2 |
XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
836 |
pcg |
1.1 |
} |
837 |
|
|
else |
838 |
|
|
{ |
839 |
|
|
while (len) |
840 |
|
|
{ |
841 |
|
|
if (*text != NOCHAR && *text != ' ') |
842 |
|
|
{ |
843 |
|
|
if (sizeof (text_t) == sizeof (FcChar16)) |
844 |
pcg |
1.2 |
XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
845 |
pcg |
1.1 |
else |
846 |
pcg |
1.2 |
XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
847 |
pcg |
1.1 |
} |
848 |
|
|
|
849 |
pcg |
1.2 |
x += r->TermWin.fwidth; |
850 |
pcg |
1.1 |
text++; |
851 |
|
|
len--; |
852 |
|
|
} |
853 |
|
|
} |
854 |
|
|
} |
855 |
|
|
#endif |
856 |
|
|
|
857 |
|
|
///////////////////////////////////////////////////////////////////////////// |
858 |
|
|
|
859 |
pcg |
1.2 |
rxvt_fontset::rxvt_fontset (rxvt_t r) |
860 |
pcg |
1.1 |
#ifdef EXPLICIT_CONTEXT |
861 |
pcg |
1.2 |
: r(r) |
862 |
pcg |
1.1 |
#endif |
863 |
|
|
{ |
864 |
|
|
clear (); |
865 |
|
|
} |
866 |
|
|
|
867 |
|
|
rxvt_fontset::~rxvt_fontset () |
868 |
|
|
{ |
869 |
|
|
clear (); |
870 |
|
|
} |
871 |
|
|
|
872 |
|
|
void |
873 |
|
|
rxvt_fontset::clear () |
874 |
|
|
{ |
875 |
|
|
for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
876 |
|
|
FONT_UNREF (*i); |
877 |
|
|
|
878 |
|
|
fonts.clear (); |
879 |
|
|
base_id = 0; |
880 |
pcg |
1.7 |
base_prop.height = 0x7fffffff; |
881 |
|
|
base_prop.weight = rxvt_fontprop::medium; |
882 |
|
|
base_prop.slant = rxvt_fontprop::roman; |
883 |
pcg |
1.1 |
|
884 |
|
|
fallback = fallback_fonts; |
885 |
|
|
} |
886 |
|
|
|
887 |
|
|
rxvt_font * |
888 |
|
|
rxvt_fontset::new_font (const char *name, codeset cs) |
889 |
|
|
{ |
890 |
|
|
rxvt_font *f; |
891 |
|
|
|
892 |
|
|
if (!name || !*name) |
893 |
|
|
{ |
894 |
|
|
name = ""; |
895 |
|
|
f = new rxvt_font_default; |
896 |
|
|
} |
897 |
|
|
#if XFT |
898 |
|
|
else if (!strncmp (name, "xft:", 4)) |
899 |
|
|
{ |
900 |
|
|
name += 4; |
901 |
|
|
f = new rxvt_font_xft; |
902 |
|
|
} |
903 |
|
|
#endif |
904 |
|
|
else if (!strncmp (name, "x:", 2)) |
905 |
|
|
{ |
906 |
|
|
name += 2; |
907 |
|
|
f = new rxvt_font_x11; |
908 |
|
|
} |
909 |
|
|
else |
910 |
|
|
f = new rxvt_font_x11; |
911 |
|
|
|
912 |
pcg |
1.2 |
f->set_term (r); |
913 |
pcg |
1.1 |
f->set_name (strdup (name)); |
914 |
|
|
|
915 |
|
|
f->cs = cs; |
916 |
|
|
f->loaded = false; |
917 |
|
|
|
918 |
|
|
return f; |
919 |
|
|
} |
920 |
|
|
|
921 |
|
|
///////////////////////////////////////////////////////////////////////////// |
922 |
|
|
|
923 |
|
|
void |
924 |
|
|
rxvt_fontset::add_fonts (const char *desc) |
925 |
|
|
{ |
926 |
|
|
if (desc) |
927 |
|
|
{ |
928 |
|
|
char buf[512]; |
929 |
|
|
const char *end; |
930 |
|
|
|
931 |
|
|
do |
932 |
|
|
{ |
933 |
|
|
while (*desc <= ' ') desc++; |
934 |
|
|
|
935 |
|
|
if (*desc == '[') |
936 |
|
|
{ |
937 |
|
|
fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
938 |
|
|
|
939 |
|
|
const char *extra = desc++; |
940 |
|
|
|
941 |
|
|
desc = strchr (desc, ']'); |
942 |
|
|
|
943 |
|
|
if (!desc) |
944 |
|
|
{ |
945 |
|
|
fprintf (stderr, "ERROR: opening '[' without closing ']' in font specification.\n"); |
946 |
|
|
break; |
947 |
|
|
} |
948 |
|
|
|
949 |
|
|
desc++; |
950 |
|
|
while (*desc <= ' ') desc++; |
951 |
|
|
} |
952 |
|
|
|
953 |
|
|
end = strchr (desc, ','); |
954 |
|
|
if (!end) |
955 |
|
|
end = desc + strlen (desc); |
956 |
|
|
|
957 |
|
|
if (end - desc < 511) |
958 |
|
|
{ |
959 |
|
|
strncpy (buf, desc, end - desc); |
960 |
|
|
buf[end - desc] = 0; |
961 |
|
|
|
962 |
|
|
fonts.push_back (new_font (buf, CS_UNICODE)); |
963 |
|
|
} |
964 |
|
|
|
965 |
|
|
desc = end + 1; |
966 |
|
|
} |
967 |
|
|
while (*end); |
968 |
|
|
} |
969 |
|
|
} |
970 |
|
|
|
971 |
|
|
bool |
972 |
|
|
rxvt_fontset::realize_font (int i) |
973 |
|
|
{ |
974 |
|
|
if (fonts[i]->loaded) |
975 |
|
|
return true; |
976 |
|
|
|
977 |
pcg |
1.5 |
fonts[i]->loaded = true; |
978 |
pcg |
1.1 |
|
979 |
pcg |
1.7 |
if (!fonts[i]->load (base_prop)) |
980 |
pcg |
1.5 |
{ |
981 |
|
|
fonts[i]->cs = CS_UNKNOWN; |
982 |
|
|
return false; |
983 |
|
|
} |
984 |
pcg |
1.1 |
|
985 |
pcg |
1.5 |
return true; |
986 |
pcg |
1.1 |
} |
987 |
|
|
|
988 |
|
|
void |
989 |
|
|
rxvt_fontset::populate (const char *desc) |
990 |
|
|
{ |
991 |
|
|
clear (); |
992 |
|
|
|
993 |
|
|
fonts.push_back (new_font (0, CS_UNICODE)); |
994 |
|
|
realize_font (0); |
995 |
|
|
|
996 |
|
|
add_fonts (desc); |
997 |
|
|
|
998 |
|
|
if (!base_id) |
999 |
|
|
base_id = 1; |
1000 |
|
|
|
1001 |
|
|
// we currently need a base-font, no matter what |
1002 |
pcg |
1.7 |
if (fonts.size () <= base_id || !realize_font (base_id)) |
1003 |
pcg |
1.1 |
{ |
1004 |
|
|
add_fonts ("fixed"); |
1005 |
pcg |
1.7 |
base_id = fonts.size () - 1; |
1006 |
pcg |
1.1 |
} |
1007 |
|
|
|
1008 |
|
|
if (fonts.size () <= base_id || !realize_font (base_id)) |
1009 |
|
|
{ |
1010 |
|
|
fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1011 |
|
|
exit (1); |
1012 |
|
|
} |
1013 |
|
|
|
1014 |
pcg |
1.7 |
base_prop = fonts[base_id]->properties (); |
1015 |
pcg |
1.1 |
} |
1016 |
|
|
|
1017 |
|
|
int |
1018 |
|
|
rxvt_fontset::find_font (uint32_t unicode) |
1019 |
|
|
{ |
1020 |
|
|
for (int i = 0; i < fonts.size (); i++) |
1021 |
|
|
{ |
1022 |
|
|
rxvt_font *f = fonts[i]; |
1023 |
|
|
|
1024 |
|
|
if (!f->loaded) |
1025 |
|
|
{ |
1026 |
|
|
if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1027 |
|
|
goto next_font; |
1028 |
|
|
|
1029 |
|
|
if (!realize_font (i)) |
1030 |
pcg |
1.5 |
goto next_font; |
1031 |
pcg |
1.1 |
} |
1032 |
|
|
|
1033 |
pcg |
1.5 |
if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
1034 |
pcg |
1.1 |
return i; |
1035 |
|
|
|
1036 |
|
|
next_font: |
1037 |
|
|
if (i == fonts.size () - 1 && fallback->name) |
1038 |
|
|
{ |
1039 |
|
|
fonts.push_back (new_font (fallback->name, fallback->cs)); |
1040 |
|
|
fallback++; |
1041 |
pcg |
1.5 |
i = 0; |
1042 |
pcg |
1.1 |
} |
1043 |
|
|
} |
1044 |
|
|
|
1045 |
|
|
return 0; /* we must return SOME font */ |
1046 |
|
|
} |
1047 |
|
|
|
1048 |
|
|
|
1049 |
|
|
|