ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/defaultfont.C
Revision: 1.44
Committed: Tue Mar 16 04:52:20 2004 UTC (20 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.43: +69 -95 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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     struct rxvt_font_default : rxvt_font {
206 pcg 1.7 rxvt_fontprop properties ()
207     {
208     rxvt_fontprop p;
209    
210 pcg 1.10 p.width = p.height = 1;
211 pcg 1.7 p.weight = rxvt_fontprop::medium;
212     p.slant = rxvt_fontprop::roman;
213    
214     return p;
215     }
216    
217     bool load (const rxvt_fontprop &prop)
218 pcg 1.1 {
219     width = 1; height = 1;
220     ascent = 1; descent = 0;
221    
222 pcg 1.38 set_name ("built-in pseudofont");
223    
224 pcg 1.1 return true;
225     }
226    
227 pcg 1.40 bool has_codepoint (unicode_t unicode)
228 pcg 1.1 {
229 pcg 1.3 if (unicode <= 0x001f)
230     return true;
231 pcg 1.34
232 pcg 1.3 if (unicode >= 0x0080 && unicode <= 0x009f)
233     return true;
234    
235 pcg 1.44 if (unicode >= 0x2500 && unicode <= 0x259f)
236 pcg 1.43 return true;
237    
238 pcg 1.35 if (IS_COMPOSE (unicode))
239 pcg 1.34 return true;
240    
241 pcg 1.1 switch (unicode)
242     {
243     case ZERO_WIDTH_CHAR:
244     return true;
245     }
246    
247     return false;
248     }
249    
250 pcg 1.24 void draw (rxvt_drawable &d, int x, int y,
251 pcg 1.1 const text_t *text, int len,
252     int fg, int bg);
253     };
254    
255 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)
256     {
257     XGCValues gcv;
258     char bm[2] = { s1, s2 };
259    
260     gcv.fill_style = FillStippled;
261     gcv.stipple = XCreateBitmapFromData (display, d, bm, 2, 2);
262     gcv.ts_x_origin = x;
263     gcv.ts_y_origin = y;
264    
265     if (!gcv.stipple)
266     return;
267    
268     XChangeGC (display, gc, GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
269     XFillRectangle (display, d, gc, x, y, w, h);
270    
271     XFreePixmap (display, gcv.stipple);
272    
273     gcv.fill_style = FillSolid;
274     XChangeGC (display, gc, GCFillStyle, &gcv);
275     }
276    
277 pcg 1.44 #include "table/linedraw.h"
278    
279 pcg 1.1 void
280 pcg 1.24 rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
281 pcg 1.1 const text_t *text, int len,
282     int fg, int bg)
283     {
284 pcg 1.24 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
285 pcg 1.1
286 pcg 1.43 XSetForeground (d.display->display, TGC, r->PixColors[fg]);
287 pcg 1.3
288 pcg 1.1 while (len--)
289     {
290 pcg 1.39 #if ENABLE_COMBINING
291 pcg 1.36 compose_char *cc;
292 pcg 1.39 #endif
293 pcg 1.3 text_t t = *text++;
294    
295 pcg 1.44 int x_[16];
296     int y_[16];
297    
298 pcg 1.43 int W = r->TermWin.fwidth , w = (W - 1) / 2;
299     int H = r->TermWin.fheight, h = (H - 1) / 2;
300     int x0 = x, x1 = x + w, x2 = x + r->TermWin.fwidth ;
301     int y0 = y, y1 = y + h, y2 = y + r->TermWin.fheight;
302    
303 pcg 1.44 for (int i = 0; i <= 8; i++)
304 pcg 1.1 {
305 pcg 1.44 x_[i] = x + ((W-1) * i + (i*7/8)) / 8;
306     y_[i] = y + ((H-1) * i + (i*7/8)) / 8;
307     }
308    
309     x_[10] = x + (W - 1) / 2; x_[9] = x_[10] - 1; x_[11] = x_[10] + 1;
310     y_[10] = y + (H - 1) / 2; y_[9] = y_[10] - 1; y_[11] = y_[10] + 1;
311 pcg 1.3
312 pcg 1.44 int i1 = linedraw_offs[t - 0x2500];
313     int i2 = linedraw_offs[t - 0x2500 + 1];
314 pcg 1.3
315 pcg 1.44 XGCValues gcv;
316 pcg 1.42
317 pcg 1.44 gcv.cap_style = CapButt;
318     gcv.line_width = 0;
319     XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv);
320    
321     if (i1 != i2)
322     {
323     while (i1 < i2)
324 pcg 1.3 {
325 pcg 1.44 uint32_t command = linedraw_command [i1++];
326    
327     int op = (command >> 24) & 255;
328     int a = (command >> 20) & 15;
329     int b = (command >> 16) & 15;
330     int x1 = x_[(command >> 12) & 15];
331     int y1 = y_[(command >> 8) & 15];
332     int x2 = x_[(command >> 4) & 15];
333     int y2 = y_[(command >> 0) & 15];
334    
335     switch (op)
336 pcg 1.3 {
337 pcg 1.44 case 0: // line
338     XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2);
339 pcg 1.3 break;
340    
341 pcg 1.44 case 1: // rectangle, possibly stippled
342     if (a)
343     {
344     static char bm[] = { 0,0 , 1,3 , 2,1 , 0,1 };
345    
346     gcv.fill_style = FillStippled;
347     gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2);
348     gcv.ts_x_origin = x;
349     gcv.ts_y_origin = y;
350    
351     XChangeGC (d.display->display, TGC,
352     GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
353     &gcv);
354     }
355    
356    
357     XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
358    
359     if (a)
360     {
361     XFreePixmap (d.display->display, gcv.stipple);
362     gcv.fill_style = FillSolid;
363     XChangeGC (d.display->display, TGC, GCFillStyle, &gcv);
364     }
365    
366     break;
367     case 2: // arc
368 pcg 1.3 break;
369 pcg 1.44 }
370     }
371 pcg 1.3
372 pcg 1.44 #if 0
373 pcg 1.43 case 'A': XDrawArc (d.display->display, d, TGC, x1 , y1 , W-1, H-1, 90*64, 90*64); break;
374     case 'B': XDrawArc (d.display->display, d, TGC, x1-W+1, y1 , W-1, H-1, 0*64, 90*64); break;
375     case 'C': XDrawArc (d.display->display, d, TGC, x1-W+1, y1-H+1, W-1, H-1, 0*64, -90*64); break;
376     case 'D': XDrawArc (d.display->display, d, TGC, x1 , y1-H+1, W-1, H-1, -90*64, -90*64); break;
377    
378     case 'i': XFillRectangle (d.display->display, d, TGC, x0, y0, x1 - x0 + 1, y1 - y0 + 1); break;
379     case 'j': XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, y1 - y0 + 1); break;
380     case 'k': XFillRectangle (d.display->display, d, TGC, x0, y1, x1 - x0 + 1, y2 - y1); break;
381     case 'l': XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1, y2 - y1); break;
382 pcg 1.3 }
383     }
384 pcg 1.44 #endif
385 pcg 1.3
386 pcg 1.1 }
387 pcg 1.39 #if ENABLE_COMBINING
388 pcg 1.36 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
389 pcg 1.34 {
390 pcg 1.37 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)];
391     f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg);
392 pcg 1.36 if (cc->c2 != NOCHAR)
393 pcg 1.37 {
394     // prefer font of first character, for no good reasons
395     rxvt_font *f2 = f1->has_codepoint (cc->c2)
396     ? f1
397     : (*fs)[fs->find_font (cc->c2)];
398    
399     f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1);
400     }
401 pcg 1.34 }
402 pcg 1.39 #endif
403 pcg 1.3 else
404 pcg 1.27 switch (t)
405 pcg 1.3 {
406     case ZERO_WIDTH_CHAR:
407     break;
408 pcg 1.43
409 pcg 1.44 #if 0
410 pcg 1.43 case 0x2580: XFillRectangle (d.display->display, d, TGC, x0, y0, W, y1 - y0 + 1); break;
411     case 0x2581: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 7 - 1) / 8, W, H - (H * 7 - 1) / 8); break;
412     case 0x2582: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 6 - 2) / 8, W, H - (H * 6 - 2) / 8); break;
413     case 0x2583: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 5 - 3) / 8, W, H - (H * 5 - 3) / 8); break;
414     case 0x2584: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 4 - 4) / 8, W, H - (H * 4 - 4) / 8); break;
415     case 0x2585: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 3 - 5) / 8, W, H - (H * 3 - 5) / 8); break;
416     case 0x2586: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 2 - 6) / 8, W, H - (H * 2 - 6) / 8); break;
417     case 0x2587: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 1 - 7) / 8, W, H - (H * 1 - 7) / 8); break;
418     case 0x2588: XFillRectangle (d.display->display, d, TGC, x0, y0, W, H); break;
419     case 0x2589: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 7 - 1) / 8, H); break;
420     case 0x258a: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 6 - 2) / 8, H); break;
421     case 0x258b: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 5 - 3) / 8, H); break;
422     case 0x258c: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 4 - 4) / 8, H); break;
423     case 0x258d: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 3 - 5) / 8, H); break;
424     case 0x258e: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 2 - 6) / 8, H); break;
425     case 0x258f: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 1 - 7) / 8, H); break;
426     case 0x2590: XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, H); break;
427    
428     case 0x2591: rect_stipple (d.display->display, d, TGC, 0x00, 0x01, x0, y0, W, H); break;
429     case 0x2592: rect_stipple (d.display->display, d, TGC, 0x02, 0x01, x0, y0, W, H); break;
430     case 0x2593: rect_stipple (d.display->display, d, TGC, 0x01, 0x03, x0, y0, W, H); break;
431    
432     case 0x2594: XFillRectangle (d.display->display, d, TGC, x0, y0, W, (H * 1 - 7) / 8); break;
433     case 0x2595: XFillRectangle (d.display->display, d, TGC, x0 + (W * 7 - 1) / 8, y0, W - (W * 7 - 1) / 8, H); break;
434 pcg 1.44 #endif
435 pcg 1.43
436 pcg 1.3 default:
437 pcg 1.27 int w = 0;
438     while (len > 0 && *text == NOCHAR)
439     {
440     ++text;
441     --len;
442     w += r->TermWin.fwidth;
443     }
444    
445 pcg 1.43 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2,
446     w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4);
447 pcg 1.27 x += w;
448 pcg 1.3 }
449 pcg 1.1
450 pcg 1.2 x += r->TermWin.fwidth;
451 pcg 1.1 }
452     }
453    
454     /////////////////////////////////////////////////////////////////////////////
455    
456     struct rxvt_font_x11 : rxvt_font {
457     rxvt_font_x11 () { f = 0; }
458    
459     void clear ();
460    
461 pcg 1.7 rxvt_fontprop properties ();
462    
463     bool load (const rxvt_fontprop &prop);
464 pcg 1.1
465 pcg 1.40 bool has_codepoint (unicode_t unicode);
466 pcg 1.1
467 pcg 1.24 void draw (rxvt_drawable &d, int x, int y,
468 pcg 1.1 const text_t *text, int len,
469     int fg, int bg);
470    
471     XFontStruct *f;
472     codeset cs;
473     bool enc2b, encm;
474    
475 pcg 1.7 const char *get_property (XFontStruct *f, const char *property, const char *repl) const;
476 pcg 1.12 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
477     bool set_properties (rxvt_fontprop &p, XFontStruct *f);
478     bool set_properties (rxvt_fontprop &p, const char *name);
479 pcg 1.1 };
480    
481     const char *
482 pcg 1.7 rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
483 pcg 1.1 {
484     unsigned long value;
485    
486     if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
487     return XGetAtomName (DISPLAY, value);
488     else
489     return repl;
490     }
491    
492 pcg 1.7 rxvt_fontprop
493     rxvt_font_x11::properties ()
494     {
495 pcg 1.12 rxvt_fontprop p;
496     set_properties (p, f);
497     return p;
498 pcg 1.7 }
499    
500 pcg 1.12 bool
501     rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth)
502 pcg 1.7 {
503 pcg 1.12 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2;
504     p.height = height;
505     p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium;
506     p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic;
507    
508     return true;
509     }
510 pcg 1.7
511 pcg 1.12 bool
512     rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
513     {
514 pcg 1.7 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
515     const char *slant = get_property (f, "SLANT", "r");
516    
517 pcg 1.12 unsigned long height;
518     if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
519     return false;
520    
521 pcg 1.10 unsigned long avgwidth;
522 pcg 1.12 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
523     avgwidth = 0;
524    
525     return set_properties (p, height, weight, slant, avgwidth);
526     }
527    
528     bool
529     rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
530     {
531     int slashes = 0;
532 pcg 1.29 const char *comp[13];
533 pcg 1.12
534     for (const char *c = name; *c; c++)
535     if (*c == '-')
536     {
537     comp[slashes++] = c + 1;
538     if (slashes >= 13)
539     break;
540     }
541    
542     /* can we short-circuit the costly XLoadQueryFont? */
543     if (slashes >= 13
544     && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
545     && (*comp[11] >= '0' && *comp[11] <= '9'))
546     return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
547    
548     XFontStruct *f = XLoadQueryFont (DISPLAY, name);
549    
550     if (f)
551     {
552 pcg 1.19 // the font should really exist now. if not, we have a problem
553 pcg 1.12 // (e.g. if the user did xset fp rehash just when we were searching fonts).
554     // in that case, just return garbage.
555     bool ret = set_properties (p, f);
556     XFreeFont (DISPLAY, f);
557     return ret;
558     }
559     else
560     return false;
561     }
562    
563     // fix the size of scalable fonts
564     static void
565     fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop)
566     {
567     int slashes = 0;
568     const char *size;
569    
570     for (const char *c = name; *c; c++)
571     if (*c == '-')
572     {
573     if (slashes == 6)
574     size = c + 1;
575    
576     if (++slashes >= 13)
577     break;
578     }
579 pcg 1.7
580 pcg 1.12 if (slashes >= 13 && size[0] == '0')
581     {
582     strncpy (buf, name, size - name);
583     buf += size - name;
584     buf += sprintf (buf, "%d", prop.height);
585     strcpy (buf, size + 1);
586     }
587     else
588     strcpy (buf, name);
589 pcg 1.7 }
590    
591 pcg 1.1 bool
592 pcg 1.7 rxvt_font_x11::load (const rxvt_fontprop &prop)
593 pcg 1.1 {
594     clear ();
595    
596 pcg 1.6 char **list;
597     int count;
598 pcg 1.12 list = XListFonts (DISPLAY, name, 512, &count);
599     set_name (0);
600 pcg 1.6
601     if (!list)
602     return false;
603    
604 pcg 1.7 int bestdiff = 0x7fffffff;
605 pcg 1.6 for (int i = 0; i < count; i++)
606     {
607 pcg 1.12 rxvt_fontprop p;
608     char fname[1024];
609     fix_scalable (fname, list[i], prop);
610    
611     if (!set_properties (p, fname))
612     continue;
613    
614     if (p.height > prop.height) // weed out too large fonts
615     continue;
616    
617     int diff = (prop.height - p.height) * 32
618     + abs (prop.weight - p.weight)
619     + abs (prop.slant - p.slant );
620 pcg 1.7
621 pcg 1.12 if (!name // compare against best found so far
622     || diff < bestdiff)
623 pcg 1.7 {
624 pcg 1.12 set_name (strdup (fname));
625     bestdiff = diff;
626 pcg 1.7 }
627 pcg 1.6 }
628 pcg 1.9
629 pcg 1.12 XFreeFontNames (list);
630    
631     if (!name)
632 pcg 1.9 return false;
633 pcg 1.6
634 pcg 1.1 f = XLoadQueryFont (DISPLAY, name);
635    
636     if (!f)
637     return false;
638    
639 pcg 1.7 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
640     const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
641 pcg 1.1
642     if (registry && encoding)
643     {
644     char charset[64];
645     snprintf (charset, 64, "%s-%s", registry, encoding);
646    
647     cs = codeset_from_name (charset);
648     }
649     else
650     {
651 pcg 1.7 const char *charset = get_property (f, "FONT", 0);
652 pcg 1.1
653     if (!charset)
654     charset = name;
655    
656     int count = 13;
657     while (*charset)
658     if (*charset++ == '-' && !--count)
659     break;
660    
661     cs = codeset_from_name (charset);
662     }
663    
664     if (cs == CS_UNICODE)
665     cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
666    
667     encm = f->min_byte1 != 0 || f->max_byte1 != 0;
668     enc2b = encm || f->max_char_or_byte2 > 255;
669    
670     ascent = f->ascent;
671     descent = f->descent;
672     height = ascent + descent;
673    
674 pcg 1.7 slow = false;
675 pcg 1.1
676     if (f->min_bounds.width == f->max_bounds.width)
677     width = f->min_bounds.width;
678     else if (f->per_char == NULL)
679     width = f->max_bounds.width;
680     else
681     {
682 pcg 1.7 slow = true;
683 pcg 1.1
684     int N = f->max_char_or_byte2 - f->min_char_or_byte2;
685    
686     if (encm)
687     N += (f->max_byte1 - f->min_byte1)
688     * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1);
689    
690     while (N)
691     {
692     if (f->per_char[N].width > width)
693     width = f->per_char[N].width;
694    
695     --N;
696     }
697     }
698    
699     if (cs == CS_UNKNOWN)
700     {
701     fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name);
702    
703     clear ();
704    
705     return false;
706     }
707    
708     return true;
709     }
710    
711     void
712     rxvt_font_x11::clear ()
713     {
714     if (f)
715     {
716     XFreeFont (DISPLAY, f);
717     f = 0;
718     }
719     }
720    
721     bool
722 pcg 1.40 rxvt_font_x11::has_codepoint (unicode_t unicode)
723 pcg 1.1 {
724     uint32_t ch = FROM_UNICODE (cs, unicode);
725    
726     if (ch == NOCHAR)
727     return false;
728    
729     /* check wether the character exists in _this_ font. horrible. */
730     XCharStruct *xcs;
731    
732     if (encm)
733     {
734 pcg 1.16 unsigned char byte1 = ch >> 8;
735     unsigned char byte2 = ch & 255;
736 pcg 1.1
737     if (byte1 < f->min_byte1 || byte1 > f->max_byte1
738     || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2)
739     return false;
740    
741     if (!f->per_char)
742     return true;
743    
744     int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1;
745     int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2;
746    
747     xcs = f->per_char + N;
748     }
749     else
750     {
751     if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2)
752     return false;
753    
754     if (!f->per_char)
755     return true;
756    
757     xcs = f->per_char + (ch - f->min_char_or_byte2);
758     }
759    
760     if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0
761     && xcs->ascent == 0 && xcs->descent == 0)
762     return false;
763    
764     return true;
765     }
766    
767     void
768 pcg 1.24 rxvt_font_x11::draw (rxvt_drawable &d, int x, int y,
769 pcg 1.1 const text_t *text, int len,
770     int fg, int bg)
771     {
772     // this looks like a mess /.
773     // and it is a mess /.
774     // yet we are trying to be perfect /.
775     // but the result still isn't perfect /.
776    
777 pcg 1.7 bool slow = this->slow
778 pcg 1.2 || width != r->TermWin.fwidth
779     || height != r->TermWin.fheight;
780 pcg 1.1
781 pcg 1.2 int base = r->TermWin.fbase;
782 pcg 1.1
783     XGCValues v;
784 pcg 1.2 v.foreground = r->PixColors[fg];
785     v.background = r->PixColors[bg];
786 pcg 1.1 v.font = f->fid;
787    
788     if (enc2b)
789     {
790     const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
791    
792     if (bg == Color_bg && !slow)
793     {
794 pcg 1.43 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
795     XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
796 pcg 1.1 }
797     else
798     {
799 pcg 1.24 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
800 pcg 1.1
801 pcg 1.43 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
802 pcg 1.1
803     if (slow)
804     {
805     do
806     {
807     if (xc->byte1 || xc->byte2)
808 pcg 1.43 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1);
809 pcg 1.1
810 pcg 1.2 x += r->TermWin.fwidth;
811 pcg 1.1 xc++; len--;
812     }
813     while (len);
814     }
815     else
816 pcg 1.43 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len);
817 pcg 1.1 }
818     }
819     else
820     {
821     const char *xc = enc_char (text, len, cs, slow);
822    
823     if (bg == Color_bg && !slow)
824     {
825 pcg 1.43 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
826     XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
827 pcg 1.1 }
828     else
829     {
830 pcg 1.24 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
831 pcg 1.1
832 pcg 1.43 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
833 pcg 1.1
834     if (slow)
835     {
836     do
837     {
838     if (*xc)
839 pcg 1.43 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1);
840 pcg 1.1
841 pcg 1.2 x += r->TermWin.fwidth;
842 pcg 1.1 xc++; len--;
843     }
844     while (len);
845     }
846     else
847 pcg 1.43 XDrawString (d.display->display, d, TGC, x, y + base, xc, len);
848 pcg 1.1 }
849     }
850     }
851    
852     /////////////////////////////////////////////////////////////////////////////
853    
854     #if XFT
855     #if 0
856     #define UNIBITS 21
857     //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
858     #define SWATHBITS 8
859     #endif
860    
861     struct rxvt_font_xft : rxvt_font {
862 pcg 1.24 rxvt_font_xft () { f = 0; }
863 pcg 1.1
864     void clear ();
865    
866 pcg 1.7 rxvt_fontprop properties ();
867    
868     bool load (const rxvt_fontprop &prop);
869 pcg 1.1
870 pcg 1.24 void draw (rxvt_drawable &d, int x, int y,
871 pcg 1.1 const text_t *text, int len,
872     int fg, int bg);
873    
874 pcg 1.40 bool has_codepoint (unicode_t unicode);
875 pcg 1.1
876     protected:
877     XftFont *f;
878     };
879    
880     void
881     rxvt_font_xft::clear ()
882     {
883     if (f)
884     {
885 pcg 1.2 XftFontClose (DISPLAY, f);
886 pcg 1.1 f = 0;
887     }
888     }
889    
890 pcg 1.7 rxvt_fontprop
891     rxvt_font_xft::properties ()
892     {
893     rxvt_fontprop p;
894    
895     FT_Face face = XftLockFace (f);
896    
897 pcg 1.10 p.width = width; p.height = height;
898 pcg 1.7 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium;
899     p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman;
900    
901     XftUnlockFace (f);
902    
903     return p;
904     }
905    
906 pcg 1.1 bool
907 pcg 1.7 rxvt_font_xft::load (const rxvt_fontprop &prop)
908 pcg 1.1 {
909     #if 0
910     for (int i = 0; i < SWATHCOUNT; i++)
911     cvr[i] = 0;
912     #endif
913    
914     clear ();
915    
916 pcg 1.7 FcPattern *p = FcNameParse ((FcChar8 *) name);
917    
918     if (!p)
919     return false;
920    
921     FcValue v;
922    
923     if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
924     FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
925    
926     if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)
927     FcPatternAddInteger (p, FC_SLANT, prop.slant);
928    
929 pcg 1.11 #if 0 // clipping unfortunately destroys our precious double-width-characters
930 pcg 1.10 // clip width, we can't do better, or can we?
931     if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
932     FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
933 pcg 1.11 #endif
934 pcg 1.10
935 pcg 1.7 //FcPatternAddBool (p, FC_MINSPACE, 1);
936    
937     XftResult result;
938     FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result);
939    
940     FcPatternDestroy (p);
941    
942     if (!match)
943     return false;
944    
945     f = XftFontOpenPattern (DISPLAY, match);
946    
947 pcg 1.1 if (!f)
948 pcg 1.8 {
949     FcPatternDestroy (match);
950     return false;
951     }
952 pcg 1.1
953     FT_Face face = XftLockFace (f);
954    
955 pcg 1.7 slow = !FT_IS_FIXED_WIDTH (face);
956 pcg 1.1
957     int ftheight = 0;
958    
959     for (;;)
960     {
961     XGlyphInfo g1, g2;
962     FcChar8 c;
963    
964 pcg 1.2 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1);
965     c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2);
966 pcg 1.1
967 pcg 1.7 if (g1.xOff != g2.xOff) // don't simply trust the font
968     slow = true;
969 pcg 1.1
970     width = g2.xOff;
971     ascent = (face->size->metrics.ascender + 63) >> 6;
972     descent = (-face->size->metrics.descender + 63) >> 6;
973     height = ascent + descent;
974    
975 pcg 1.7 if (height <= prop.height || !prop.height)
976 pcg 1.1 break;
977    
978     if (ftheight)
979     {
980     // take smaller steps near the end
981 pcg 1.7 if (height > prop.height + 1) ftheight++;
982     if (height > prop.height + 2) ftheight++;
983     if (height > prop.height + 3) ftheight++;
984 pcg 1.1
985 pcg 1.7 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height);
986 pcg 1.1 }
987     else
988 pcg 1.7 FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height);
989 pcg 1.1 }
990    
991     XftUnlockFace (f);
992    
993     return true;
994     }
995    
996     bool
997 pcg 1.40 rxvt_font_xft::has_codepoint (unicode_t unicode)
998 pcg 1.1 {
999 pcg 1.2 return XftCharExists (DISPLAY, f, unicode);
1000 pcg 1.1 }
1001    
1002     void
1003 pcg 1.24 rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1004 pcg 1.1 const text_t *text, int len,
1005     int fg, int bg)
1006     {
1007 pcg 1.24 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
1008 pcg 1.1
1009 pcg 1.12 if (!slow && width == r->TermWin.fwidth && 0)
1010 pcg 1.1 {
1011     if (sizeof (text_t) == sizeof (FcChar16))
1012 pcg 1.2 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
1013 pcg 1.1 else
1014 pcg 1.2 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len);
1015 pcg 1.1 }
1016     else
1017     {
1018     while (len)
1019     {
1020     if (*text != NOCHAR && *text != ' ')
1021     {
1022 pcg 1.13 int fwidth = r->TermWin.fwidth;
1023     if (len >= 2 && text[1] == NOCHAR)
1024     fwidth *= 2;
1025    
1026 pcg 1.12 XGlyphInfo extents;
1027 pcg 1.1 if (sizeof (text_t) == sizeof (FcChar16))
1028 pcg 1.12 {
1029 pcg 1.24 XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents);
1030 pcg 1.13 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
1031 pcg 1.12 y + r->TermWin.fbase, (const FcChar16 *)text, 1);
1032     }
1033 pcg 1.1 else
1034 pcg 1.12 {
1035     XGlyphInfo extents;
1036 pcg 1.24 XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents);
1037 pcg 1.13 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
1038 pcg 1.12 y + r->TermWin.fbase, (const FcChar32 *)text, 1);
1039     }
1040 pcg 1.1 }
1041    
1042 pcg 1.2 x += r->TermWin.fwidth;
1043 pcg 1.1 text++;
1044     len--;
1045     }
1046     }
1047     }
1048     #endif
1049    
1050     /////////////////////////////////////////////////////////////////////////////
1051    
1052 pcg 1.2 rxvt_fontset::rxvt_fontset (rxvt_t r)
1053 pcg 1.18 : r (r)
1054 pcg 1.1 {
1055     clear ();
1056     }
1057    
1058     rxvt_fontset::~rxvt_fontset ()
1059     {
1060     clear ();
1061     }
1062    
1063     void
1064     rxvt_fontset::clear ()
1065     {
1066 pcg 1.18 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1067 pcg 1.1 FONT_UNREF (*i);
1068    
1069     fonts.clear ();
1070     base_id = 0;
1071 pcg 1.7 base_prop.height = 0x7fffffff;
1072     base_prop.weight = rxvt_fontprop::medium;
1073     base_prop.slant = rxvt_fontprop::roman;
1074 pcg 1.1
1075     fallback = fallback_fonts;
1076     }
1077    
1078     rxvt_font *
1079     rxvt_fontset::new_font (const char *name, codeset cs)
1080     {
1081     rxvt_font *f;
1082    
1083     if (!name || !*name)
1084     {
1085     name = "";
1086     f = new rxvt_font_default;
1087     }
1088     #if XFT
1089     else if (!strncmp (name, "xft:", 4))
1090     {
1091     name += 4;
1092     f = new rxvt_font_xft;
1093     }
1094     #endif
1095     else if (!strncmp (name, "x:", 2))
1096     {
1097     name += 2;
1098     f = new rxvt_font_x11;
1099     }
1100     else
1101     f = new rxvt_font_x11;
1102    
1103 pcg 1.36 f->fs = this;
1104 pcg 1.2 f->set_term (r);
1105 pcg 1.1 f->set_name (strdup (name));
1106    
1107     f->cs = cs;
1108     f->loaded = false;
1109    
1110     return f;
1111     }
1112    
1113     /////////////////////////////////////////////////////////////////////////////
1114    
1115     void
1116     rxvt_fontset::add_fonts (const char *desc)
1117     {
1118     if (desc)
1119     {
1120     char buf[512];
1121     const char *end;
1122    
1123     do
1124     {
1125     while (*desc <= ' ') desc++;
1126    
1127     if (*desc == '[')
1128     {
1129     fprintf (stderr, "extra font parameters not yet supported, skipping.\n");
1130    
1131 pcg 1.16 //const char *extra = desc++; // not yet used
1132 pcg 1.1
1133     desc = strchr (desc, ']');
1134    
1135     if (!desc)
1136     {
1137     fprintf (stderr, "ERROR: opening '[' without closing ']' in font specification.\n");
1138     break;
1139     }
1140    
1141     desc++;
1142     while (*desc <= ' ') desc++;
1143     }
1144    
1145     end = strchr (desc, ',');
1146     if (!end)
1147     end = desc + strlen (desc);
1148    
1149     if (end - desc < 511)
1150     {
1151     strncpy (buf, desc, end - desc);
1152     buf[end - desc] = 0;
1153    
1154     fonts.push_back (new_font (buf, CS_UNICODE));
1155     }
1156    
1157     desc = end + 1;
1158     }
1159     while (*end);
1160     }
1161     }
1162    
1163     bool
1164     rxvt_fontset::realize_font (int i)
1165     {
1166     if (fonts[i]->loaded)
1167     return true;
1168    
1169 pcg 1.5 fonts[i]->loaded = true;
1170 pcg 1.1
1171 pcg 1.7 if (!fonts[i]->load (base_prop))
1172 pcg 1.5 {
1173     fonts[i]->cs = CS_UNKNOWN;
1174     return false;
1175     }
1176 pcg 1.1
1177 pcg 1.5 return true;
1178 pcg 1.1 }
1179    
1180 pcg 1.23 bool
1181 pcg 1.1 rxvt_fontset::populate (const char *desc)
1182     {
1183     clear ();
1184    
1185     fonts.push_back (new_font (0, CS_UNICODE));
1186     realize_font (0);
1187    
1188     add_fonts (desc);
1189    
1190     if (!base_id)
1191     base_id = 1;
1192    
1193     // we currently need a base-font, no matter what
1194 pcg 1.16 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1195 pcg 1.1 {
1196 pcg 1.18 puts ("unable to load specified font (s), falling back to 'fixed'\n");
1197 pcg 1.1 add_fonts ("fixed");
1198 pcg 1.7 base_id = fonts.size () - 1;
1199 pcg 1.1 }
1200    
1201 pcg 1.16 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1202 pcg 1.23 return false;
1203 pcg 1.1
1204 pcg 1.7 base_prop = fonts[base_id]->properties ();
1205 pcg 1.23
1206     return true;
1207 pcg 1.1 }
1208    
1209     int
1210 pcg 1.40 rxvt_fontset::find_font (unicode_t unicode)
1211 pcg 1.1 {
1212 pcg 1.16 for (unsigned int i = 0; i < fonts.size (); i++)
1213 pcg 1.1 {
1214     rxvt_font *f = fonts[i];
1215    
1216     if (!f->loaded)
1217     {
1218     if (FROM_UNICODE (f->cs, unicode) == NOCHAR)
1219     goto next_font;
1220    
1221     if (!realize_font (i))
1222 pcg 1.5 goto next_font;
1223 pcg 1.1 }
1224    
1225 pcg 1.5 if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode))
1226 pcg 1.1 return i;
1227    
1228     next_font:
1229     if (i == fonts.size () - 1 && fallback->name)
1230     {
1231     fonts.push_back (new_font (fallback->name, fallback->cs));
1232     fallback++;
1233 pcg 1.5 i = 0;
1234 pcg 1.1 }
1235     }
1236    
1237     return 0; /* we must return SOME font */
1238     }
1239    
1240    
1241