ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/defaultfont.C
(Generate patch)

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.2 by pcg, Tue Nov 25 15:25:17 2003 UTC vs.
Revision 1.44 by pcg, Tue Mar 16 04:52:20 2004 UTC

1/*--------------------------------*-C-*---------------------------------*; 1/*--------------------------------*-C-*---------------------------------*;
2 * File: defaultfont.C 2 * File: defaultfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003 Marc Lehmann rxvt@plan9.de> 4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 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 9 * the Free Software Foundation; either version 2 of the License, or
21 21
22#include "../config.h" 22#include "../config.h"
23#include "rxvt.h" 23#include "rxvt.h"
24#include "defaultfont.h" 24#include "defaultfont.h"
25 25
26#include <cstdlib>
27
26#define DISPLAY r->Xdisplay 28#define DISPLAY r->display->display
27#define DRAWABLE r->TermWin.vt
28#define GC r->TermWin.gc 29#define TGC r->TermWin.gc
29 30
30const struct rxvt_fallback_font { 31const struct rxvt_fallback_font {
31 codeset cs; 32 codeset cs;
32 const char *name; 33 const char *name;
33} fallback_fonts[] = { 34} fallback_fonts[] = {
57 58
58 // japanese 59 // japanese
59#if ENCODING_JP || ENCODING_JP_EXT 60#if ENCODING_JP || ENCODING_JP_EXT
60# if XFT 61# if XFT
61 // prefer xft for complex scripts 62 // prefer xft for complex scripts
62 { CS_UNICODE, "xft:Kochi Gothic" }, 63 { CS_UNICODE, "xft:Kochi Gothic:antialias=false" },
63# endif 64# endif
64 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, 65 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
65 { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, 66 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
66 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, 67 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" },
67#endif 68#endif
68 69
69#if ENCODING_CN || ENCODING_CN_EXT 70#if ENCODING_CN || ENCODING_CN_EXT
70# if XFT 71# if XFT
71 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 72 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
72 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, 73 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" },
73 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, 74 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" },
74 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, 75 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" },
75# endif 76# endif
77 { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" },
78 { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" },
79 { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" },
80 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
76 { CS_CNS11643_1992_1, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-1" }, 81 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" },
77 { CS_CNS11643_1992_2, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-2" }, 82 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" },
78 { CS_CNS11643_1992_3, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-3" }, 83 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" },
79 { CS_CNS11643_1992_4, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-4" }, 84 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" },
80 { CS_CNS11643_1992_5, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-5" }, 85 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" },
81 { CS_CNS11643_1992_6, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-6" }, 86 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" },
82 { CS_CNS11643_1992_7, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-7" }, 87 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" },
83 { CS_CNS11643_1992_F, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-f" }, 88 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" },
84#endif 89#endif
85 90
86#if XFT 91#if XFT
87 { CS_UNICODE, "xft:Andale Mono" }, 92 { CS_UNICODE, "xft:Andale Mono" },
88 { CS_UNICODE, "xft:Arial Unicode MS" }, 93 { CS_UNICODE, "xft:Arial Unicode MS" },
89#endif 94#endif
90 { CS_UNICODE, "-*-lucidatypewriter-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 95 { 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" },
91 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 99 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
92 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 100
93 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 101#if UNICODE_3 && XFT
102 { CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters
103#endif
94 104
95 { CS_UNKNOWN, 0 } 105 { CS_UNKNOWN, 0 }
96}; 106};
97 107
98///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
99 109
110#if XFT
111rxvt_drawable::~rxvt_drawable ()
112{
113 if (xftdrawable)
114 XftDrawDestroy (xftdrawable);
115}
116
117rxvt_drawable::operator XftDraw *()
118{
119 if (!xftdrawable)
120 xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap);
121
122 return xftdrawable;
123}
124#endif
125
126/////////////////////////////////////////////////////////////////////////////
127
100static void *enc_buf; 128static void *enc_buf;
101static uint32_t enc_len; 129static uint32_t enc_len;
102 130
103static inline void * 131static inline void *
104get_enc_buf (int len) 132get_enc_buf (uint32_t len)
105{ 133{
106 if (len > enc_len) 134 if (len > enc_len)
107 { 135 {
108 free (enc_buf); 136 free (enc_buf);
109 enc_buf = malloc (len); 137 enc_buf = malloc (len);
111 139
112 return enc_buf; 140 return enc_buf;
113} 141}
114 142
115static const char * 143static const char *
116enc_char (const text_t *text, int len, codeset cs, bool &zero) 144enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
117{ 145{
118 uint8_t *buf = (uint8_t *)get_enc_buf (len); 146 uint8_t *buf = (uint8_t *)get_enc_buf (len);
119 147
120 while (len--) 148 while (len--)
121 { 149 {
132 160
133 return (const char *)enc_buf; 161 return (const char *)enc_buf;
134} 162}
135 163
136static const XChar2b * 164static const XChar2b *
137enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) 165enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
138{ 166{
139 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 167 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b));
140 168
141 while (len--) 169 while (len--)
142 { 170 {
157} 185}
158 186
159///////////////////////////////////////////////////////////////////////////// 187/////////////////////////////////////////////////////////////////////////////
160 188
161void 189void
162rxvt_font::clear_rect (int x, int y, int w, int h, int color) 190rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color)
163{ 191{
164 if (color == Color_bg) 192 if (color == Color_bg)
165 XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); 193 XClearArea (d.display->display, d, x, y, w, h, FALSE);
166 else if (color >= 0) 194 else if (color >= 0)
167 { 195 {
196#if XFT
197 XftDrawRect (d, &r->PixColors[color].c, x, y, w, h);
198#else
168 XSetForeground (DISPLAY, GC, r->PixColors[color]); 199 XSetForeground (d.display->display, TGC, r->PixColors[color]);
169 XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); 200 XFillRectangle (d.display->display, d, TGC, x, y, w, h);
201#endif
170 } 202 }
171} 203}
172 204
173struct rxvt_font_default : rxvt_font { 205struct rxvt_font_default : rxvt_font {
174 bool load (int maxheight) 206 rxvt_fontprop properties ()
207 {
208 rxvt_fontprop p;
209
210 p.width = p.height = 1;
211 p.weight = rxvt_fontprop::medium;
212 p.slant = rxvt_fontprop::roman;
213
214 return p;
215 }
216
217 bool load (const rxvt_fontprop &prop)
175 { 218 {
176 width = 1; height = 1; 219 width = 1; height = 1;
177 ascent = 1; descent = 0; 220 ascent = 1; descent = 0;
178 221
222 set_name ("built-in pseudofont");
223
179 return true; 224 return true;
180 } 225 }
181 226
182 bool has_codepoint (uint32_t unicode) 227 bool has_codepoint (unicode_t unicode)
183 { 228 {
184 if (unicode <= 0x001f 229 if (unicode <= 0x001f)
230 return true;
231
185 || (unicode >= 0x80 && unicode <= 0x9f)) 232 if (unicode >= 0x0080 && unicode <= 0x009f)
233 return true;
234
235 if (unicode >= 0x2500 && unicode <= 0x259f)
236 return true;
237
238 if (IS_COMPOSE (unicode))
186 return true; 239 return true;
187 240
188 switch (unicode) 241 switch (unicode)
189 { 242 {
190 case ZERO_WIDTH_CHAR: 243 case ZERO_WIDTH_CHAR:
192 } 245 }
193 246
194 return false; 247 return false;
195 } 248 }
196 249
197 void draw (int x, int y, 250 void draw (rxvt_drawable &d, int x, int y,
198 const text_t *text, int len, 251 const text_t *text, int len,
199 int fg, int bg); 252 int fg, int bg);
200}; 253};
201 254
255static 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#include "table/linedraw.h"
278
202void 279void
203rxvt_font_default::draw (int x, int y, 280rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
204 const text_t *text, int len, 281 const text_t *text, int len,
205 int fg, int bg) 282 int fg, int bg)
206{ 283{
207 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 284 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
285
286 XSetForeground (d.display->display, TGC, r->PixColors[fg]);
208 287
209 while (len--) 288 while (len--)
210 { 289 {
290#if ENABLE_COMBINING
291 compose_char *cc;
292#endif
293 text_t t = *text++;
294
295 int x_[16];
296 int y_[16];
297
298 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 for (int i = 0; i <= 8; i++)
304 {
305 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
312 int i1 = linedraw_offs[t - 0x2500];
313 int i2 = linedraw_offs[t - 0x2500 + 1];
314
315 XGCValues gcv;
316
317 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 {
325 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 {
337 case 0: // line
338 XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2);
339 break;
340
341 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 break;
369 }
370 }
371
372#if 0
373 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 }
383 }
384#endif
385
386 }
387#if ENABLE_COMBINING
388 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
389 {
390 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)];
391 f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg);
392 if (cc->c2 != NOCHAR)
393 {
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 }
402#endif
403 else
211 switch (*text++) 404 switch (t)
212 { 405 {
213 case NOCHAR:
214 case ZERO_WIDTH_CHAR: 406 case ZERO_WIDTH_CHAR:
215 break; 407 break;
408
409#if 0
410 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#endif
435
216 default: 436 default:
217 XSetForeground (DISPLAY, GC, r->PixColors[fg]); 437 int w = 0;
218 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); 438 while (len > 0 && *text == NOCHAR)
439 {
440 ++text;
441 --len;
442 w += r->TermWin.fwidth;
443 }
444
445 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2,
446 w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4);
447 x += w;
219 } 448 }
220 449
221 x += r->TermWin.fwidth; 450 x += r->TermWin.fwidth;
222 } 451 }
223} 452}
224 453
227struct rxvt_font_x11 : rxvt_font { 456struct rxvt_font_x11 : rxvt_font {
228 rxvt_font_x11 () { f = 0; } 457 rxvt_font_x11 () { f = 0; }
229 458
230 void clear (); 459 void clear ();
231 460
232 bool load (int maxheight); 461 rxvt_fontprop properties ();
233 462
463 bool load (const rxvt_fontprop &prop);
464
234 bool has_codepoint (uint32_t unicode); 465 bool has_codepoint (unicode_t unicode);
235 466
236 void draw (int x, int y, 467 void draw (rxvt_drawable &d, int x, int y,
237 const text_t *text, int len, 468 const text_t *text, int len,
238 int fg, int bg); 469 int fg, int bg);
239 470
240 XFontStruct *f; 471 XFontStruct *f;
241 codeset cs; 472 codeset cs;
242 bool enc2b, encm; 473 bool enc2b, encm;
243 474
244 const char *get_property (const char *property, const char *repl) const; 475 const char *get_property (XFontStruct *f, const char *property, const char *repl) const;
476 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);
245}; 479};
246 480
247const char * 481const char *
248rxvt_font_x11::get_property (const char *property, const char *repl) const 482rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
249{ 483{
250 unsigned long value; 484 unsigned long value;
251 485
252 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 486 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
253 return XGetAtomName (DISPLAY, value); 487 return XGetAtomName (DISPLAY, value);
254 else 488 else
255 return repl; 489 return repl;
256} 490}
257 491
492rxvt_fontprop
493rxvt_font_x11::properties ()
494{
495 rxvt_fontprop p;
496 set_properties (p, f);
497 return p;
498}
499
258bool 500bool
259rxvt_font_x11::load (int maxheight) 501rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth)
502{
503 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
511bool
512rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
513{
514 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
515 const char *slant = get_property (f, "SLANT", "r");
516
517 unsigned long height;
518 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
519 return false;
520
521 unsigned long avgwidth;
522 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
523 avgwidth = 0;
524
525 return set_properties (p, height, weight, slant, avgwidth);
526}
527
528bool
529rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
530{
531 int slashes = 0;
532 const char *comp[13];
533
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 // the font should really exist now. if not, we have a problem
553 // (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
564static void
565fix_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
580 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}
590
591bool
592rxvt_font_x11::load (const rxvt_fontprop &prop)
260{ 593{
261 clear (); 594 clear ();
595
596 char **list;
597 int count;
598 list = XListFonts (DISPLAY, name, 512, &count);
599 set_name (0);
600
601 if (!list)
602 return false;
603
604 int bestdiff = 0x7fffffff;
605 for (int i = 0; i < count; i++)
606 {
607 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
621 if (!name // compare against best found so far
622 || diff < bestdiff)
623 {
624 set_name (strdup (fname));
625 bestdiff = diff;
626 }
627 }
628
629 XFreeFontNames (list);
630
631 if (!name)
632 return false;
262 633
263 f = XLoadQueryFont (DISPLAY, name); 634 f = XLoadQueryFont (DISPLAY, name);
264 635
265 if (!f) 636 if (!f)
266 return false; 637 return false;
267 638
268 unsigned long value;
269
270 const char *registry = get_property ("CHARSET_REGISTRY", 0); 639 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
271 const char *encoding = get_property ("CHARSET_ENCODING", 0); 640 const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
272 641
273 if (registry && encoding) 642 if (registry && encoding)
274 { 643 {
275 char charset[64]; 644 char charset[64];
276 snprintf (charset, 64, "%s-%s", registry, encoding); 645 snprintf (charset, 64, "%s-%s", registry, encoding);
277 646
278 cs = codeset_from_name (charset); 647 cs = codeset_from_name (charset);
279 } 648 }
280 else 649 else
281 { 650 {
282 const char *charset = get_property ("FONT", 0); 651 const char *charset = get_property (f, "FONT", 0);
283 652
284 if (!charset) 653 if (!charset)
285 charset = name; 654 charset = name;
286 655
287 int count = 13; 656 int count = 13;
300 669
301 ascent = f->ascent; 670 ascent = f->ascent;
302 descent = f->descent; 671 descent = f->descent;
303 height = ascent + descent; 672 height = ascent + descent;
304 673
305 prop = false; 674 slow = false;
306 675
307 if (f->min_bounds.width == f->max_bounds.width) 676 if (f->min_bounds.width == f->max_bounds.width)
308 width = f->min_bounds.width; 677 width = f->min_bounds.width;
309 else if (f->per_char == NULL) 678 else if (f->per_char == NULL)
310 width = f->max_bounds.width; 679 width = f->max_bounds.width;
311 else 680 else
312 { 681 {
313 prop = true; 682 slow = true;
314 683
315 int N = f->max_char_or_byte2 - f->min_char_or_byte2; 684 int N = f->max_char_or_byte2 - f->min_char_or_byte2;
316 685
317 if (encm) 686 if (encm)
318 N += (f->max_byte1 - f->min_byte1) 687 N += (f->max_byte1 - f->min_byte1)
348 f = 0; 717 f = 0;
349 } 718 }
350} 719}
351 720
352bool 721bool
353rxvt_font_x11::has_codepoint (uint32_t unicode) 722rxvt_font_x11::has_codepoint (unicode_t unicode)
354{ 723{
355 uint32_t ch = FROM_UNICODE (cs, unicode); 724 uint32_t ch = FROM_UNICODE (cs, unicode);
356 725
357 if (ch == NOCHAR) 726 if (ch == NOCHAR)
358 return false; 727 return false;
360 /* check wether the character exists in _this_ font. horrible. */ 729 /* check wether the character exists in _this_ font. horrible. */
361 XCharStruct *xcs; 730 XCharStruct *xcs;
362 731
363 if (encm) 732 if (encm)
364 { 733 {
365 int byte1 = ch >> 8; 734 unsigned char byte1 = ch >> 8;
366 int byte2 = ch & 255; 735 unsigned char byte2 = ch & 255;
367 736
368 if (byte1 < f->min_byte1 || byte1 > f->max_byte1 737 if (byte1 < f->min_byte1 || byte1 > f->max_byte1
369 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) 738 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2)
370 return false; 739 return false;
371 740
394 763
395 return true; 764 return true;
396} 765}
397 766
398void 767void
399rxvt_font_x11::draw (int x, int y, 768rxvt_font_x11::draw (rxvt_drawable &d, int x, int y,
400 const text_t *text, int len, 769 const text_t *text, int len,
401 int fg, int bg) 770 int fg, int bg)
402{ 771{
403 // this looks like a mess /. 772 // this looks like a mess /.
404 // and it is a mess /. 773 // and it is a mess /.
405 // yet we are trying to be perfect /. 774 // yet we are trying to be perfect /.
406 // but the result still isn't perfect /. 775 // but the result still isn't perfect /.
407 776
408 bool slow = prop 777 bool slow = this->slow
409 || width != r->TermWin.fwidth 778 || width != r->TermWin.fwidth
410 || height != r->TermWin.fheight; 779 || height != r->TermWin.fheight;
411 780
412 int base = r->TermWin.fbase; 781 int base = r->TermWin.fbase;
413 782
420 { 789 {
421 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 790 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
422 791
423 if (bg == Color_bg && !slow) 792 if (bg == Color_bg && !slow)
424 { 793 {
425 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 794 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
426 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 795 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
427 } 796 }
428 else 797 else
429 { 798 {
430 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 799 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
431 800
432 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 801 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
433 802
434 if (slow) 803 if (slow)
435 { 804 {
436 do 805 do
437 { 806 {
438 if (xc->byte1 || xc->byte2) 807 if (xc->byte1 || xc->byte2)
439 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 808 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1);
440 809
441 x += r->TermWin.fwidth; 810 x += r->TermWin.fwidth;
442 xc++; len--; 811 xc++; len--;
443 } 812 }
444 while (len); 813 while (len);
445 } 814 }
446 else 815 else
447 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 816 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len);
448 } 817 }
449 } 818 }
450 else 819 else
451 { 820 {
452 const char *xc = enc_char (text, len, cs, slow); 821 const char *xc = enc_char (text, len, cs, slow);
453 822
454 if (bg == Color_bg && !slow) 823 if (bg == Color_bg && !slow)
455 { 824 {
456 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 825 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
457 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 826 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
458 } 827 }
459 else 828 else
460 { 829 {
461 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 830 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
462 831
463 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 832 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
464 833
465 if (slow) 834 if (slow)
466 { 835 {
467 do 836 do
468 { 837 {
469 if (*xc) 838 if (*xc)
470 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 839 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1);
471 840
472 x += r->TermWin.fwidth; 841 x += r->TermWin.fwidth;
473 xc++; len--; 842 xc++; len--;
474 } 843 }
475 while (len); 844 while (len);
476 } 845 }
477 else 846 else
478 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 847 XDrawString (d.display->display, d, TGC, x, y + base, xc, len);
479 } 848 }
480 } 849 }
481} 850}
482 851
483///////////////////////////////////////////////////////////////////////////// 852/////////////////////////////////////////////////////////////////////////////
488//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables 857//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
489#define SWATHBITS 8 858#define SWATHBITS 8
490#endif 859#endif
491 860
492struct rxvt_font_xft : rxvt_font { 861struct rxvt_font_xft : rxvt_font {
493#if 0
494 enum {
495 SWATHCOUNT = 1 << (21 - UNIBITS),
496 SWATHSIZE = 1 << (SWATHBITS - 5)
497 };
498 typedef uint32_t swath[SWATHSIZE];
499
500 swath *cvr[SWATHCOUNT];
501#endif
502
503#if 0
504 void gen_coverage_swath (unsigned int page);
505
506 bool has_char (uint32_t ch)
507 {
508 unsigned int page = ch >> SWATHBITS;
509 unsigned int idx = ch & ((1 << SWATHBITS) - 1);
510
511 if (page >= SWATHCOUNT)
512 return false;
513
514 if (!cvr[page]) gen_coverage_swath (page);
515
516 return cvr[page][idx >> 5] & (1 << (idx & 31));
517 }
518#endif
519 rxvt_font_xft () { f = 0; d = 0; } 862 rxvt_font_xft () { f = 0; }
520 863
521 void clear (); 864 void clear ();
522 865
523 bool load (int maxheight); 866 rxvt_fontprop properties ();
524 867
525 void draw (int x, int y, 868 bool load (const rxvt_fontprop &prop);
869
870 void draw (rxvt_drawable &d, int x, int y,
526 const text_t *text, int len, 871 const text_t *text, int len,
527 int fg, int bg); 872 int fg, int bg);
528 873
529 bool has_codepoint (uint32_t unicode); 874 bool has_codepoint (unicode_t unicode);
530 875
531protected: 876protected:
532 XftFont *f; 877 XftFont *f;
533 XftDraw *d;
534
535#if 0
536 virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0;
537 void set_swath (uint32_t ch)
538 {
539 cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1));
540 }
541#endif
542}; 878};
543 879
544void 880void
545rxvt_font_xft::clear () 881rxvt_font_xft::clear ()
546{ 882{
547 if (f) 883 if (f)
548 { 884 {
549 XftFontClose (DISPLAY, f); 885 XftFontClose (DISPLAY, f);
550 f = 0; 886 f = 0;
551 } 887 }
888}
552 889
553 if (d) 890rxvt_fontprop
554 { 891rxvt_font_xft::properties ()
555 XftDrawDestroy (d); 892{
556 d = 0; 893 rxvt_fontprop p;
557 }
558 894
559#if 0 895 FT_Face face = XftLockFace (f);
560 for (int i = 0; i < SWATHCOUNT; i++) 896
561 delete cvr[i]; 897 p.width = width; p.height = height;
562#endif 898 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;
563} 904}
564 905
565bool 906bool
566rxvt_font_xft::load (int maxheight) 907rxvt_font_xft::load (const rxvt_fontprop &prop)
567{ 908{
568#if 0 909#if 0
569 for (int i = 0; i < SWATHCOUNT; i++) 910 for (int i = 0; i < SWATHCOUNT; i++)
570 cvr[i] = 0; 911 cvr[i] = 0;
571#endif 912#endif
572 913
573 clear (); 914 clear ();
574 915
575 f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); 916 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#if 0 // clipping unfortunately destroys our precious double-width-characters
930 // 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#endif
934
935 //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);
576 946
577 if (!f) 947 if (!f)
948 {
949 FcPatternDestroy (match);
578 return false; 950 return false;
951 }
579 952
580 FT_Face face = XftLockFace (f); 953 FT_Face face = XftLockFace (f);
581 954
582 prop = !FT_IS_FIXED_WIDTH (face); 955 slow = !FT_IS_FIXED_WIDTH (face);
583 956
584 int ftheight = 0; 957 int ftheight = 0;
585 958
586 for (;;) 959 for (;;)
587 { 960 {
589 FcChar8 c; 962 FcChar8 c;
590 963
591 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); 964 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1);
592 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); 965 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2);
593 966
594 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font 967 if (g1.xOff != g2.xOff) // don't simply trust the font
968 slow = true;
595 969
596 width = g2.xOff; 970 width = g2.xOff;
597 ascent = (face->size->metrics.ascender + 63) >> 6; 971 ascent = (face->size->metrics.ascender + 63) >> 6;
598 descent = (-face->size->metrics.descender + 63) >> 6; 972 descent = (-face->size->metrics.descender + 63) >> 6;
599 height = ascent + descent; 973 height = ascent + descent;
600 974
601 if (height <= maxheight || !maxheight) 975 if (height <= prop.height || !prop.height)
602 break; 976 break;
603 977
604 if (ftheight) 978 if (ftheight)
605 { 979 {
606 // take smaller steps near the end 980 // take smaller steps near the end
607 if (height > maxheight + 1) ftheight++; 981 if (height > prop.height + 1) ftheight++;
608 if (height > maxheight + 2) ftheight++; 982 if (height > prop.height + 2) ftheight++;
609 if (height > maxheight + 3) ftheight++; 983 if (height > prop.height + 3) ftheight++;
610 984
611 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); 985 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height);
612 } 986 }
613 else 987 else
614 FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); 988 FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height);
615 } 989 }
616 990
617 XftUnlockFace (f); 991 XftUnlockFace (f);
618 992
619 return true; 993 return true;
620} 994}
621 995
622#if 0
623void rxvt_font::gen_coverage_swath (unsigned int page)
624{
625 cvr[page] = new swath;
626
627 for (int i = 0; i < SWATHSIZE; i++)
628 cvr[page][i] = 0;
629
630 populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1);
631}
632#endif
633
634bool 996bool
635rxvt_font_xft::has_codepoint (uint32_t unicode) 997rxvt_font_xft::has_codepoint (unicode_t unicode)
636{ 998{
637 return XftCharExists (DISPLAY, f, unicode); 999 return XftCharExists (DISPLAY, f, unicode);
638} 1000}
639 1001
640void 1002void
641rxvt_font_xft::draw (int x, int y, 1003rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
642 const text_t *text, int len, 1004 const text_t *text, int len,
643 int fg, int bg) 1005 int fg, int bg)
644{ 1006{
645 if (!d)
646 {
647 dR;
648 d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP);
649 }
650
651 if (bg >= 0 && bg != Color_bg)
652 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
653 else
654 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 1007 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
655 1008
656 if (!prop && width == r->TermWin.fwidth) 1009 if (!slow && width == r->TermWin.fwidth && 0)
657 { 1010 {
658 if (sizeof (text_t) == sizeof (FcChar16)) 1011 if (sizeof (text_t) == sizeof (FcChar16))
659 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); 1012 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
660 else 1013 else
661 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); 1014 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len);
664 { 1017 {
665 while (len) 1018 while (len)
666 { 1019 {
667 if (*text != NOCHAR && *text != ' ') 1020 if (*text != NOCHAR && *text != ' ')
668 { 1021 {
1022 int fwidth = r->TermWin.fwidth;
1023 if (len >= 2 && text[1] == NOCHAR)
1024 fwidth *= 2;
1025
1026 XGlyphInfo extents;
669 if (sizeof (text_t) == sizeof (FcChar16)) 1027 if (sizeof (text_t) == sizeof (FcChar16))
670 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); 1028 {
1029 XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents);
1030 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
1031 y + r->TermWin.fbase, (const FcChar16 *)text, 1);
1032 }
671 else 1033 else
672 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); 1034 {
1035 XGlyphInfo extents;
1036 XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents);
1037 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
1038 y + r->TermWin.fbase, (const FcChar32 *)text, 1);
1039 }
673 } 1040 }
674 1041
675 x += r->TermWin.fwidth; 1042 x += r->TermWin.fwidth;
676 text++; 1043 text++;
677 len--; 1044 len--;
681#endif 1048#endif
682 1049
683///////////////////////////////////////////////////////////////////////////// 1050/////////////////////////////////////////////////////////////////////////////
684 1051
685rxvt_fontset::rxvt_fontset (rxvt_t r) 1052rxvt_fontset::rxvt_fontset (rxvt_t r)
686#ifdef EXPLICIT_CONTEXT
687: r(r) 1053: r (r)
688#endif
689{ 1054{
690 clear (); 1055 clear ();
691} 1056}
692 1057
693rxvt_fontset::~rxvt_fontset () 1058rxvt_fontset::~rxvt_fontset ()
696} 1061}
697 1062
698void 1063void
699rxvt_fontset::clear () 1064rxvt_fontset::clear ()
700{ 1065{
701 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) 1066 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
702 FONT_UNREF (*i); 1067 FONT_UNREF (*i);
703 1068
704 fonts.clear (); 1069 fonts.clear ();
705 base_id = 0; 1070 base_id = 0;
706 height = 0x7fffffff; 1071 base_prop.height = 0x7fffffff;
1072 base_prop.weight = rxvt_fontprop::medium;
1073 base_prop.slant = rxvt_fontprop::roman;
707 1074
708 fallback = fallback_fonts; 1075 fallback = fallback_fonts;
709} 1076}
710 1077
711rxvt_font * 1078rxvt_font *
731 f = new rxvt_font_x11; 1098 f = new rxvt_font_x11;
732 } 1099 }
733 else 1100 else
734 f = new rxvt_font_x11; 1101 f = new rxvt_font_x11;
735 1102
1103 f->fs = this;
736 f->set_term (r); 1104 f->set_term (r);
737 f->set_name (strdup (name)); 1105 f->set_name (strdup (name));
738 1106
739 f->cs = cs; 1107 f->cs = cs;
740 f->loaded = false; 1108 f->loaded = false;
758 1126
759 if (*desc == '[') 1127 if (*desc == '[')
760 { 1128 {
761 fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); 1129 fprintf (stderr, "extra font parameters not yet supported, skipping.\n");
762 1130
763 const char *extra = desc++; 1131 //const char *extra = desc++; // not yet used
764 1132
765 desc = strchr (desc, ']'); 1133 desc = strchr (desc, ']');
766 1134
767 if (!desc) 1135 if (!desc)
768 { 1136 {
796rxvt_fontset::realize_font (int i) 1164rxvt_fontset::realize_font (int i)
797{ 1165{
798 if (fonts[i]->loaded) 1166 if (fonts[i]->loaded)
799 return true; 1167 return true;
800 1168
801 if (fonts[i]->load (height))
802 return fonts[i]->loaded = true; 1169 fonts[i]->loaded = true;
803 1170
804 delete fonts[i]; 1171 if (!fonts[i]->load (base_prop))
805 fonts.erase (fonts.begin () + i); 1172 {
806 1173 fonts[i]->cs = CS_UNKNOWN;
807 return false; 1174 return false;
808} 1175 }
809 1176
810void 1177 return true;
1178}
1179
1180bool
811rxvt_fontset::populate (const char *desc) 1181rxvt_fontset::populate (const char *desc)
812{ 1182{
813 clear (); 1183 clear ();
814 1184
815 fonts.push_back (new_font (0, CS_UNICODE)); 1185 fonts.push_back (new_font (0, CS_UNICODE));
819 1189
820 if (!base_id) 1190 if (!base_id)
821 base_id = 1; 1191 base_id = 1;
822 1192
823 // we currently need a base-font, no matter what 1193 // we currently need a base-font, no matter what
824 if (fonts.size () <= base_id) 1194 if ((int)fonts.size () <= base_id || !realize_font (base_id))
825 { 1195 {
1196 puts ("unable to load specified font (s), falling back to 'fixed'\n");
826 add_fonts ("fixed"); 1197 add_fonts ("fixed");
827 base_id = 1; 1198 base_id = fonts.size () - 1;
828 } 1199 }
829 1200
830 if (fonts.size () <= base_id || !realize_font (base_id)) 1201 if ((int)fonts.size () <= base_id || !realize_font (base_id))
831 { 1202 return false;
832 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n");
833 exit (1);
834 }
835 1203
836 height = fonts[base_id]->height; 1204 base_prop = fonts[base_id]->properties ();
837 1205
838 /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/ 1206 return true;
839} 1207}
840 1208
841int 1209int
842rxvt_fontset::find_font (uint32_t unicode) 1210rxvt_fontset::find_font (unicode_t unicode)
843{ 1211{
844 for (int i = 0; i < fonts.size (); i++) 1212 for (unsigned int i = 0; i < fonts.size (); i++)
845 { 1213 {
846 rxvt_font *f = fonts[i]; 1214 rxvt_font *f = fonts[i];
847 1215
848 if (!f->loaded) 1216 if (!f->loaded)
849 { 1217 {
850 if (FROM_UNICODE (f->cs, unicode) == NOCHAR) 1218 if (FROM_UNICODE (f->cs, unicode) == NOCHAR)
851 goto next_font; 1219 goto next_font;
852 1220
853 if (!realize_font (i)) 1221 if (!realize_font (i))
854 {
855 --i;
856 goto next_font; 1222 goto next_font;
857 } 1223 }
858 1224
859 //printf ("added font %s for %04lx\n", f->name, unicode);
860 }
861
862 if (f->has_codepoint (unicode)) 1225 if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode))
863 return i; 1226 return i;
864 1227
865 next_font: 1228 next_font:
866 if (i == fonts.size () - 1 && fallback->name) 1229 if (i == fonts.size () - 1 && fallback->name)
867 { 1230 {
868 fonts.push_back (new_font (fallback->name, fallback->cs)); 1231 fonts.push_back (new_font (fallback->name, fallback->cs));
869 fallback++; 1232 fallback++;
1233 i = 0;
870 } 1234 }
871 } 1235 }
872 1236
873 return 0; /* we must return SOME font */ 1237 return 0; /* we must return SOME font */
874} 1238}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines