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.23 by pcg, Sun Feb 22 08:28:36 2004 UTC vs.
Revision 1.43 by pcg, Mon Mar 15 07:10:47 2004 UTC

24#include "defaultfont.h" 24#include "defaultfont.h"
25 25
26#include <cstdlib> 26#include <cstdlib>
27 27
28#define DISPLAY r->display->display 28#define DISPLAY r->display->display
29#define DRAWABLE r->TermWin.vt
30#define GC r->TermWin.gc 29#define TGC r->TermWin.gc
31 30
32const struct rxvt_fallback_font { 31const struct rxvt_fallback_font {
33 codeset cs; 32 codeset cs;
34 const char *name; 33 const char *name;
35} fallback_fonts[] = { 34} fallback_fonts[] = {
62# if XFT 61# if XFT
63 // prefer xft for complex scripts 62 // prefer xft for complex scripts
64 { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, 63 { CS_UNICODE, "xft:Kochi Gothic:antialias=false" },
65# endif 64# endif
66 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, 65 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
67 { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, 66 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
68 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, 67 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" },
69#endif 68#endif
70 69
71#if ENCODING_CN || ENCODING_CN_EXT 70#if ENCODING_CN || ENCODING_CN_EXT
72# if XFT 71# if XFT
73 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 72 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
74 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, 73 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" },
75 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, 74 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" },
76 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, 75 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" },
77# endif 76# endif
77 { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" },
78 { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" },
79 { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" },
78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, 80 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
79 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, 81 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" },
80 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, 82 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" },
81 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, 83 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" },
82 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, 84 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" },
83 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, 85 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" },
84 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, 86 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" },
85 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, 87 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" },
86 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, 88 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" },
87#endif 89#endif
88 90
89#if XFT 91#if XFT
90 { CS_UNICODE, "xft:Andale Mono" }, 92 { CS_UNICODE, "xft:Andale Mono" },
91 { CS_UNICODE, "xft:Arial Unicode MS" }, 93 { CS_UNICODE, "xft:Arial Unicode MS" },
94 { CS_UNICODE, "xft:FreeMono" }, 96 { CS_UNICODE, "xft:FreeMono" },
95 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 97 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
96 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 98 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
97 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 99 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
98 100
101#if UNICODE_3 && XFT
102 { CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters
103#endif
104
99 { CS_UNKNOWN, 0 } 105 { CS_UNKNOWN, 0 }
100}; 106};
107
108/////////////////////////////////////////////////////////////////////////////
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
101 125
102///////////////////////////////////////////////////////////////////////////// 126/////////////////////////////////////////////////////////////////////////////
103 127
104static void *enc_buf; 128static void *enc_buf;
105static uint32_t enc_len; 129static uint32_t enc_len;
161} 185}
162 186
163///////////////////////////////////////////////////////////////////////////// 187/////////////////////////////////////////////////////////////////////////////
164 188
165void 189void
166rxvt_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)
167{ 191{
168 if (color == Color_bg) 192 if (color == Color_bg)
169 XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); 193 XClearArea (d.display->display, d, x, y, w, h, FALSE);
170 else if (color >= 0) 194 else if (color >= 0)
171 { 195 {
196#if XFT
197 XftDrawRect (d, &r->PixColors[color].c, x, y, w, h);
198#else
172 XSetForeground (DISPLAY, GC, r->PixColors[color]); 199 XSetForeground (d.display->display, TGC, r->PixColors[color]);
173 XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); 200 XFillRectangle (d.display->display, d, TGC, x, y, w, h);
201#endif
174 } 202 }
175} 203}
176 204
177static const char *linedraw_cmds[128] = { 205static const char *linedraw_cmds[128 + 32] = {
178 "1hH", "2hH", "1vV", "2vV", 206 "1-", "2-", "1|", "2|",
179 0, 0, 0, 0, 207 0, 0, 0, 0,
180 0, 0, 0, 0, 208 0, 0, 0, 0,
181 "1HV", "2H1V", "1H2V", "2HV", 209 "1HV", "2H1V", "1H2V", "2HV",
182 210
183 // 2510 211 // 2510
184 "1hV", "2h1V", "1h2V", "2hV", 212 "1hV", "2h1V", "1h2V", "2hV",
185 "1Hv", "2H1v", "1H2v", "2Hv", 213 "1Hv", "2H1v", "1H2v", "2Hv",
186 "1hv", "2h1v", "1h2v", "2hv", 214 "1hv", "2h1v", "1h2v", "2hv",
187 "1HvV", "2H1vV", "1HV2v", "1Hv2V", 215 "1H|", "2H1|", "1HV2v", "1Hv2V",
188 216
189 // 2520 217 // 2520
190 "1H2vV", "2Hv1V", "2HV1v", "2HvV", 218 "1H2|", "2Hv1V", "2HV1v", "2H|",
191 "1hvV", "2h1vV", "1hV2v", "1hv2V", 219 "1h|", "2h1|", "1hV2v", "1hv2V",
192 "1h2vV", "2hv1V", "1v2hV", "2hvV", 220 "1h2|", "2hv1V", "1v2hV", "2h|",
193 "1hHV", "2h1HV", "2H1hV", "2hH1V", 221 "1-V", "2h1HV", "2H1hV", "2-1V",
194 222
195 // 2530 223 // 2530
196 "1hH2V", "2hV1H", "1h2HV", "2hHV", 224 "1-2V", "2hV1H", "1h2HV", "2-V",
197 "1hHv", "1vH2h", "1hv2H", "1v2hH", 225 "1-v", "1vH2h", "1hv2H", "1v2-",
198 "1hH2v", "1H2hv", "1h2Hv", "2hHv", 226 "1-2v", "1H2hv", "1h2Hv", "2-v",
199 "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", 227 "1-|", "1|H2h", "1h|2H", "1|2-",
200 228
201 // 2540 229 // 2540
202 "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", 230 "1-V2v", "1-v2V", "1-2|", "1HV2hv",
203 "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", 231 "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2-v",
204 "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", 232 "1v2-V", "1H2h|", "1h2H|", "2-|",
205 0, 0, 0, 0, 233 0, 0, 0, 0,
206 234
207 // 2550 235 // 2550
208 0, 0, 0, 0, 236 0, 0, 0, 0,
209 0, 0, 0, 0, 237 0, 0, 0, 0,
212 240
213 // 2560 241 // 2560
214 0, 0, 0, 0, 242 0, 0, 0, 0,
215 0, 0, 0, 0, 243 0, 0, 0, 0,
216 0, 0, 0, 0, 244 0, 0, 0, 0,
217 0, 0, 0, 0, 245 0, "A", "B", "C",
218 246
219 // 2570 247 // 2570
220 0, "1a", "1b", "1ab", 248 "D", "1/", "1\\", "1/\\",
221 "1h", "1v", "1H", "1V", 249 "1h", "1v", "1H", "1V",
222 "2h", "2v", "2H", "2V", 250 "2h", "2v", "2H", "2V",
223 "1h2H", "1v2V", "1H2h", "1V2v" 251 "1h2H", "1v2V", "1H2h", "1V2v",
252
253 // 2580
254 0, 0, 0, 0,
255 0, 0, 0, 0,
256 0, 0, 0, 0,
257 0, 0, 0, 0,
258
259 // 2590
260 0, 0, 0, 0,
261 0, 0, "k", "l",
262 "i", "ikl", "il", "ijk",
263 "ijl", "j", "jk", "jkl",
224 264
225 // to be done 265 // to be done
226}; 266};
227 267
228struct rxvt_font_default : rxvt_font { 268struct rxvt_font_default : rxvt_font {
240 bool load (const rxvt_fontprop &prop) 280 bool load (const rxvt_fontprop &prop)
241 { 281 {
242 width = 1; height = 1; 282 width = 1; height = 1;
243 ascent = 1; descent = 0; 283 ascent = 1; descent = 0;
244 284
285 set_name ("built-in pseudofont");
286
245 return true; 287 return true;
246 } 288 }
247 289
248 bool has_codepoint (uint32_t unicode) 290 bool has_codepoint (unicode_t unicode)
249 { 291 {
250 if (unicode <= 0x001f) 292 if (unicode <= 0x001f)
251 return true; 293 return true;
294
252 if (unicode >= 0x0080 && unicode <= 0x009f) 295 if (unicode >= 0x0080 && unicode <= 0x009f)
253 return true; 296 return true;
254 297
255 if (unicode >= 0x2500 && unicode <= 0x257f 298 if (unicode >= 0x2500 && unicode <= 0x257f
256 && linedraw_cmds[unicode - 0x2500]) 299 && linedraw_cmds[unicode - 0x2500])
300 return true;
301
302 if (unicode >= 0x2580 && unicode <= 0x259f)
303 return true;
304
305 if (IS_COMPOSE (unicode))
257 return true; 306 return true;
258 307
259 switch (unicode) 308 switch (unicode)
260 { 309 {
261 case ZERO_WIDTH_CHAR: 310 case ZERO_WIDTH_CHAR:
263 } 312 }
264 313
265 return false; 314 return false;
266 } 315 }
267 316
268 void draw (int x, int y, 317 void draw (rxvt_drawable &d, int x, int y,
269 const text_t *text, int len, 318 const text_t *text, int len,
270 int fg, int bg); 319 int fg, int bg);
271}; 320};
272 321
322static void rect_stipple (Display *display, Drawable d, GC gc, int s1, int s2, int x, int y, int w, int h)
323{
324 XGCValues gcv;
325 char bm[2] = { s1, s2 };
326
327 gcv.fill_style = FillStippled;
328 gcv.stipple = XCreateBitmapFromData (display, d, bm, 2, 2);
329 gcv.ts_x_origin = x;
330 gcv.ts_y_origin = y;
331
332 if (!gcv.stipple)
333 return;
334
335 XChangeGC (display, gc, GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
336 XFillRectangle (display, d, gc, x, y, w, h);
337
338 XFreePixmap (display, gcv.stipple);
339
340 gcv.fill_style = FillSolid;
341 XChangeGC (display, gc, GCFillStyle, &gcv);
342}
343
273void 344void
274rxvt_font_default::draw (int x, int y, 345rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
275 const text_t *text, int len, 346 const text_t *text, int len,
276 int fg, int bg) 347 int fg, int bg)
277{ 348{
278 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 349 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
279 350
280 XSetForeground (DISPLAY, GC, r->PixColors[fg]); 351 XSetForeground (d.display->display, TGC, r->PixColors[fg]);
281 352
282 while (len--) 353 while (len--)
283 { 354 {
355#if ENABLE_COMBINING
356 compose_char *cc;
357#endif
284 text_t t = *text++; 358 text_t t = *text++;
285 359
360 int W = r->TermWin.fwidth , w = (W - 1) / 2;
361 int H = r->TermWin.fheight, h = (H - 1) / 2;
362 int x0 = x, x1 = x + w, x2 = x + r->TermWin.fwidth ;
363 int y0 = y, y1 = y + h, y2 = y + r->TermWin.fheight;
364
365 // is it in our linedrawing table?
286 if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) 366 if (t >= 0x2500 & t <= 0x259f && linedraw_cmds[t - 0x2500])
287 { 367 {
288 const char *p = linedraw_cmds[t - 0x2500]; 368 const char *p = linedraw_cmds[t - 0x2500];
289 369
290 int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ;
291 int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight;
292
293 XGCValues gcv; 370 XGCValues gcv;
371
372 gcv.cap_style = CapNotLast;
373 XChangeGC (d.display->display, TGC, GCCapStyle, &gcv);
294 374
295 while (*p) 375 while (*p)
296 { 376 {
297 switch (*p++) 377 switch (*p++)
298 { 378 {
299 case '1': 379 case '1':
300 gcv.line_width = 0; 380 gcv.line_width = 0;
301 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 381 XChangeGC (d.display->display, TGC, GCLineWidth, &gcv);
302 break; 382 break;
303 383
304 case '2': 384 case '2':
305 gcv.line_width = 2; 385 gcv.line_width = 3;
306 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 386 XChangeGC (d.display->display, TGC, GCLineWidth, &gcv);
307 break; 387 break;
308 388
309 case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; 389 case 'h': XDrawLine (d.display->display, d, TGC, x0, y1, x1+1, y1 ); break;
310 case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; 390 case 'H': XDrawLine (d.display->display, d, TGC, x1, y1, x2 , y1 ); break;
391 case '-': XDrawLine (d.display->display, d, TGC, x0, y1, x2 , y1 ); break;
311 case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; 392 case 'v': XDrawLine (d.display->display, d, TGC, x1, y0, x1 , y1+1); break;
312 case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; 393 case 'V': XDrawLine (d.display->display, d, TGC, x1, y1, x1 , y2 ); break;
394 case '|': XDrawLine (d.display->display, d, TGC, x1, y0, x1 , y2 ); break;
395
313 case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; 396 case '/' : XDrawLine (d.display->display, d, TGC, x0, y2, x2 , y0 ); break;
314 case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; 397 case '\\': XDrawLine (d.display->display, d, TGC, x0, y0, x2 , y2 ); break;
398
399 case 'A': XDrawArc (d.display->display, d, TGC, x1 , y1 , W-1, H-1, 90*64, 90*64); break;
400 case 'B': XDrawArc (d.display->display, d, TGC, x1-W+1, y1 , W-1, H-1, 0*64, 90*64); break;
401 case 'C': XDrawArc (d.display->display, d, TGC, x1-W+1, y1-H+1, W-1, H-1, 0*64, -90*64); break;
402 case 'D': XDrawArc (d.display->display, d, TGC, x1 , y1-H+1, W-1, H-1, -90*64, -90*64); break;
403
404 case 'i': XFillRectangle (d.display->display, d, TGC, x0, y0, x1 - x0 + 1, y1 - y0 + 1); break;
405 case 'j': XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, y1 - y0 + 1); break;
406 case 'k': XFillRectangle (d.display->display, d, TGC, x0, y1, x1 - x0 + 1, y2 - y1); break;
407 case 'l': XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1, y2 - y1); break;
315 } 408 }
316 } 409 }
317 410
318 gcv.line_width = 0; 411 gcv.line_width = 0;
319 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 412 XChangeGC (d.display->display, TGC, GCLineWidth, &gcv);
413 }
414
415#if ENABLE_COMBINING
416 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
320 } 417 {
418 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)];
419 f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg);
420 if (cc->c2 != NOCHAR)
421 {
422 // prefer font of first character, for no good reasons
423 rxvt_font *f2 = f1->has_codepoint (cc->c2)
424 ? f1
425 : (*fs)[fs->find_font (cc->c2)];
426
427 f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1);
428 }
429 }
430#endif
321 else 431 else
322 switch (*text++) 432 switch (t)
323 { 433 {
324 case NOCHAR:
325 case ZERO_WIDTH_CHAR: 434 case ZERO_WIDTH_CHAR:
326 break; 435 break;
436
437 case 0x2580: XFillRectangle (d.display->display, d, TGC, x0, y0, W, y1 - y0 + 1); break;
438 case 0x2581: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 7 - 1) / 8, W, H - (H * 7 - 1) / 8); break;
439 case 0x2582: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 6 - 2) / 8, W, H - (H * 6 - 2) / 8); break;
440 case 0x2583: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 5 - 3) / 8, W, H - (H * 5 - 3) / 8); break;
441 case 0x2584: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 4 - 4) / 8, W, H - (H * 4 - 4) / 8); break;
442 case 0x2585: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 3 - 5) / 8, W, H - (H * 3 - 5) / 8); break;
443 case 0x2586: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 2 - 6) / 8, W, H - (H * 2 - 6) / 8); break;
444 case 0x2587: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 1 - 7) / 8, W, H - (H * 1 - 7) / 8); break;
445 case 0x2588: XFillRectangle (d.display->display, d, TGC, x0, y0, W, H); break;
446 case 0x2589: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 7 - 1) / 8, H); break;
447 case 0x258a: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 6 - 2) / 8, H); break;
448 case 0x258b: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 5 - 3) / 8, H); break;
449 case 0x258c: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 4 - 4) / 8, H); break;
450 case 0x258d: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 3 - 5) / 8, H); break;
451 case 0x258e: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 2 - 6) / 8, H); break;
452 case 0x258f: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 1 - 7) / 8, H); break;
453 case 0x2590: XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, H); break;
454
455 case 0x2591: rect_stipple (d.display->display, d, TGC, 0x00, 0x01, x0, y0, W, H); break;
456 case 0x2592: rect_stipple (d.display->display, d, TGC, 0x02, 0x01, x0, y0, W, H); break;
457 case 0x2593: rect_stipple (d.display->display, d, TGC, 0x01, 0x03, x0, y0, W, H); break;
458
459 case 0x2594: XFillRectangle (d.display->display, d, TGC, x0, y0, W, (H * 1 - 7) / 8); break;
460 case 0x2595: XFillRectangle (d.display->display, d, TGC, x0 + (W * 7 - 1) / 8, y0, W - (W * 7 - 1) / 8, H); break;
461
327 default: 462 default:
328 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); 463 int w = 0;
464 while (len > 0 && *text == NOCHAR)
465 {
466 ++text;
467 --len;
468 w += r->TermWin.fwidth;
469 }
470
471 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2,
472 w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4);
473 x += w;
329 } 474 }
330 475
331 x += r->TermWin.fwidth; 476 x += r->TermWin.fwidth;
332 } 477 }
333} 478}
341 486
342 rxvt_fontprop properties (); 487 rxvt_fontprop properties ();
343 488
344 bool load (const rxvt_fontprop &prop); 489 bool load (const rxvt_fontprop &prop);
345 490
346 bool has_codepoint (uint32_t unicode); 491 bool has_codepoint (unicode_t unicode);
347 492
348 void draw (int x, int y, 493 void draw (rxvt_drawable &d, int x, int y,
349 const text_t *text, int len, 494 const text_t *text, int len,
350 int fg, int bg); 495 int fg, int bg);
351 496
352 XFontStruct *f; 497 XFontStruct *f;
353 codeset cs; 498 codeset cs;
408 553
409bool 554bool
410rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 555rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
411{ 556{
412 int slashes = 0; 557 int slashes = 0;
413 const char *comp[12]; 558 const char *comp[13];
414 559
415 for (const char *c = name; *c; c++) 560 for (const char *c = name; *c; c++)
416 if (*c == '-') 561 if (*c == '-')
417 { 562 {
418 comp[slashes++] = c + 1; 563 comp[slashes++] = c + 1;
598 f = 0; 743 f = 0;
599 } 744 }
600} 745}
601 746
602bool 747bool
603rxvt_font_x11::has_codepoint (uint32_t unicode) 748rxvt_font_x11::has_codepoint (unicode_t unicode)
604{ 749{
605 uint32_t ch = FROM_UNICODE (cs, unicode); 750 uint32_t ch = FROM_UNICODE (cs, unicode);
606 751
607 if (ch == NOCHAR) 752 if (ch == NOCHAR)
608 return false; 753 return false;
644 789
645 return true; 790 return true;
646} 791}
647 792
648void 793void
649rxvt_font_x11::draw (int x, int y, 794rxvt_font_x11::draw (rxvt_drawable &d, int x, int y,
650 const text_t *text, int len, 795 const text_t *text, int len,
651 int fg, int bg) 796 int fg, int bg)
652{ 797{
653 // this looks like a mess /. 798 // this looks like a mess /.
654 // and it is a mess /. 799 // and it is a mess /.
670 { 815 {
671 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 816 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
672 817
673 if (bg == Color_bg && !slow) 818 if (bg == Color_bg && !slow)
674 { 819 {
675 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 820 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
676 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 821 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
677 } 822 }
678 else 823 else
679 { 824 {
680 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 825 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
681 826
682 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 827 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
683 828
684 if (slow) 829 if (slow)
685 { 830 {
686 do 831 do
687 { 832 {
688 if (xc->byte1 || xc->byte2) 833 if (xc->byte1 || xc->byte2)
689 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 834 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1);
690 835
691 x += r->TermWin.fwidth; 836 x += r->TermWin.fwidth;
692 xc++; len--; 837 xc++; len--;
693 } 838 }
694 while (len); 839 while (len);
695 } 840 }
696 else 841 else
697 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 842 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len);
698 } 843 }
699 } 844 }
700 else 845 else
701 { 846 {
702 const char *xc = enc_char (text, len, cs, slow); 847 const char *xc = enc_char (text, len, cs, slow);
703 848
704 if (bg == Color_bg && !slow) 849 if (bg == Color_bg && !slow)
705 { 850 {
706 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 851 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
707 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 852 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
708 } 853 }
709 else 854 else
710 { 855 {
711 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 856 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
712 857
713 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 858 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
714 859
715 if (slow) 860 if (slow)
716 { 861 {
717 do 862 do
718 { 863 {
719 if (*xc) 864 if (*xc)
720 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 865 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1);
721 866
722 x += r->TermWin.fwidth; 867 x += r->TermWin.fwidth;
723 xc++; len--; 868 xc++; len--;
724 } 869 }
725 while (len); 870 while (len);
726 } 871 }
727 else 872 else
728 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 873 XDrawString (d.display->display, d, TGC, x, y + base, xc, len);
729 } 874 }
730 } 875 }
731} 876}
732 877
733///////////////////////////////////////////////////////////////////////////// 878/////////////////////////////////////////////////////////////////////////////
738//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables 883//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
739#define SWATHBITS 8 884#define SWATHBITS 8
740#endif 885#endif
741 886
742struct rxvt_font_xft : rxvt_font { 887struct rxvt_font_xft : rxvt_font {
743 rxvt_font_xft () { f = 0; d = 0; } 888 rxvt_font_xft () { f = 0; }
744 889
745 void clear (); 890 void clear ();
746 891
747 rxvt_fontprop properties (); 892 rxvt_fontprop properties ();
748 893
749 bool load (const rxvt_fontprop &prop); 894 bool load (const rxvt_fontprop &prop);
750 895
751 void draw (int x, int y, 896 void draw (rxvt_drawable &d, int x, int y,
752 const text_t *text, int len, 897 const text_t *text, int len,
753 int fg, int bg); 898 int fg, int bg);
754 899
755 bool has_codepoint (uint32_t unicode); 900 bool has_codepoint (unicode_t unicode);
756 901
757protected: 902protected:
758 XftFont *f; 903 XftFont *f;
759 XftDraw *d;
760}; 904};
761 905
762void 906void
763rxvt_font_xft::clear () 907rxvt_font_xft::clear ()
764{ 908{
765 if (d)
766 {
767 XftDrawDestroy (d);
768 d = 0;
769 }
770
771 if (f) 909 if (f)
772 { 910 {
773 XftFontClose (DISPLAY, f); 911 XftFontClose (DISPLAY, f);
774 f = 0; 912 f = 0;
775 } 913 }
880 1018
881 return true; 1019 return true;
882} 1020}
883 1021
884bool 1022bool
885rxvt_font_xft::has_codepoint (uint32_t unicode) 1023rxvt_font_xft::has_codepoint (unicode_t unicode)
886{ 1024{
887 return XftCharExists (DISPLAY, f, unicode); 1025 return XftCharExists (DISPLAY, f, unicode);
888} 1026}
889 1027
890void 1028void
891rxvt_font_xft::draw (int x, int y, 1029rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
892 const text_t *text, int len, 1030 const text_t *text, int len,
893 int fg, int bg) 1031 int fg, int bg)
894{ 1032{
895 d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap);
896
897 if (bg >= 0 && bg != Color_bg)
898 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
899 else
900 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 1033 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
901 1034
902 if (!slow && width == r->TermWin.fwidth && 0) 1035 if (!slow && width == r->TermWin.fwidth && 0)
903 { 1036 {
904 if (sizeof (text_t) == sizeof (FcChar16)) 1037 if (sizeof (text_t) == sizeof (FcChar16))
905 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); 1038 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
917 fwidth *= 2; 1050 fwidth *= 2;
918 1051
919 XGlyphInfo extents; 1052 XGlyphInfo extents;
920 if (sizeof (text_t) == sizeof (FcChar16)) 1053 if (sizeof (text_t) == sizeof (FcChar16))
921 { 1054 {
922 XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); 1055 XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents);
923 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, 1056 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
924 y + r->TermWin.fbase, (const FcChar16 *)text, 1); 1057 y + r->TermWin.fbase, (const FcChar16 *)text, 1);
925 } 1058 }
926 else 1059 else
927 { 1060 {
928 XGlyphInfo extents; 1061 XGlyphInfo extents;
929 XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); 1062 XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents);
930 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, 1063 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
931 y + r->TermWin.fbase, (const FcChar32 *)text, 1); 1064 y + r->TermWin.fbase, (const FcChar32 *)text, 1);
932 } 1065 }
933 } 1066 }
934 1067
991 f = new rxvt_font_x11; 1124 f = new rxvt_font_x11;
992 } 1125 }
993 else 1126 else
994 f = new rxvt_font_x11; 1127 f = new rxvt_font_x11;
995 1128
1129 f->fs = this;
996 f->set_term (r); 1130 f->set_term (r);
997 f->set_name (strdup (name)); 1131 f->set_name (strdup (name));
998 1132
999 f->cs = cs; 1133 f->cs = cs;
1000 f->loaded = false; 1134 f->loaded = false;
1097 1231
1098 return true; 1232 return true;
1099} 1233}
1100 1234
1101int 1235int
1102rxvt_fontset::find_font (uint32_t unicode) 1236rxvt_fontset::find_font (unicode_t unicode)
1103{ 1237{
1104 for (unsigned int i = 0; i < fonts.size (); i++) 1238 for (unsigned int i = 0; i < fonts.size (); i++)
1105 { 1239 {
1106 rxvt_font *f = fonts[i]; 1240 rxvt_font *f = fonts[i];
1107 1241

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines