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.44 by pcg, Tue Mar 16 04:52:20 2004 UTC vs.
Revision 1.55 by root, Mon Jul 26 14:57:12 2004 UTC

1/*--------------------------------*-C-*---------------------------------*; 1/*--------------------------------*-C-*---------------------------------*
2 * File: defaultfont.C 2 * File: defaultfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
30 30
31const struct rxvt_fallback_font { 31const struct rxvt_fallback_font {
32 codeset cs; 32 codeset cs;
33 const char *name; 33 const char *name;
34} fallback_fonts[] = { 34} fallback_fonts[] = {
35 { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, 35 { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" },
36 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, 36 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" },
37 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, 37 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" },
38 38
39#if ENCODING_EU 39#if ENCODING_EU
40 // cyrillic 40 // cyrillic
41 { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, 41 { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" },
42 { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, 42 { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" },
43 43
44 { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, 44 { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" },
45 { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, 45 { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" },
46 { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, 46 { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" },
47 { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, 47 { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" },
48 { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, 48 { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" },
49 { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, 49 { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" },
50 { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, 50 { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" },
51 { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, 51 { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" },
52 { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, 52 { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" },
53 { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, 53 { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" },
54 { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, 54 { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" },
55 { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, 55 { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" },
56 { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, 56 { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" },
57#endif 57#endif
58 58
59 // japanese 59 // japanese
60#if ENCODING_JP || ENCODING_JP_EXT 60#if ENCODING_JP || ENCODING_JP_EXT
61# if XFT 61# if XFT
63 { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, 63 { CS_UNICODE, "xft:Kochi Gothic:antialias=false" },
64# endif 64# endif
65 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, 65 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
66 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, 66 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
67 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, 67 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" },
68 { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
69 { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
70 { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" },
68#endif 71#endif
69 72
70#if ENCODING_CN || ENCODING_CN_EXT 73#if ENCODING_CN || ENCODING_CN_EXT
71# if XFT 74# if XFT
72 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 75 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
89#endif 92#endif
90 93
91#if XFT 94#if XFT
92 { CS_UNICODE, "xft:Andale Mono" }, 95 { CS_UNICODE, "xft:Andale Mono" },
93 { CS_UNICODE, "xft:Arial Unicode MS" }, 96 { CS_UNICODE, "xft:Arial Unicode MS" },
97 { CS_UNICODE, "xft:FreeMono" },
94#endif 98#endif
95 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, 99 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
96 { CS_UNICODE, "xft:FreeMono" },
97 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 100 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
98 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 101 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
99 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 102 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
100 103
101#if UNICODE_3 && XFT 104#if UNICODE_3 && XFT
200 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 203 XFillRectangle (d.display->display, d, TGC, x, y, w, h);
201#endif 204#endif
202 } 205 }
203} 206}
204 207
208#include "table/linedraw.h"
209
205struct rxvt_font_default : rxvt_font { 210struct rxvt_font_default : rxvt_font {
211
206 rxvt_fontprop properties () 212 rxvt_fontprop properties ()
207 { 213 {
208 rxvt_fontprop p; 214 rxvt_fontprop p;
209 215
210 p.width = p.height = 1; 216 p.width = p.height = 1;
217 bool load (const rxvt_fontprop &prop) 223 bool load (const rxvt_fontprop &prop)
218 { 224 {
219 width = 1; height = 1; 225 width = 1; height = 1;
220 ascent = 1; descent = 0; 226 ascent = 1; descent = 0;
221 227
222 set_name ("built-in pseudofont"); 228 set_name (strdup ("built-in pseudofont"));
223 229
224 return true; 230 return true;
225 } 231 }
226 232
227 bool has_codepoint (unicode_t unicode) 233 bool has_codepoint (unicode_t unicode)
228 { 234 {
229 if (unicode <= 0x001f) 235 if (unicode <= 0x001f)
230 return true; 236 return true;
231 237
232 if (unicode >= 0x0080 && unicode <= 0x009f) 238 if (unicode <= 0x007f)
239 return false;
240
241 if (unicode <= 0x009f)
233 return true; 242 return true;
234 243
235 if (unicode >= 0x2500 && unicode <= 0x259f) 244 if (unicode >= 0x2500 && unicode <= 0x259f)
236 return true; 245 return true;
237 246
250 void draw (rxvt_drawable &d, int x, int y, 259 void draw (rxvt_drawable &d, int x, int y,
251 const text_t *text, int len, 260 const text_t *text, int len,
252 int fg, int bg); 261 int fg, int bg);
253}; 262};
254 263
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
279void 264void
280rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 265rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
281 const text_t *text, int len, 266 const text_t *text, int len,
282 int fg, int bg) 267 int fg, int bg)
283{ 268{
290#if ENABLE_COMBINING 275#if ENABLE_COMBINING
291 compose_char *cc; 276 compose_char *cc;
292#endif 277#endif
293 text_t t = *text++; 278 text_t t = *text++;
294 279
280 if (0x2500 <= t && t <= 0x259f)
281 {
282 uint16_t offs = linedraw_offs[t - 0x2500];
283 uint32_t *a = linedraw_command + (offs >> 4);
284 uint32_t *b = a + (offs & 15);
285
286 int W = r->TermWin.fwidth;
287 int H = r->TermWin.fheight;
288
295 int x_[16]; 289 int x_[16];
296 int y_[16]; 290 int y_[16];
297 291
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++) 292 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 { 293 {
294 x_[i] = x + ((W-1) * i + (i*7/8)) / 8;
295 y_[i] = y + ((H-1) * i + (i*7/8)) / 8;
296 }
297
298 x_[10] = x + (W - 1) / 2; x_[9] = x_[10] - 1; x_[11] = x_[10] + 1;
299 y_[10] = y + (H - 1) / 2; y_[9] = y_[10] - 1; y_[11] = y_[10] + 1;
300
301 XGCValues gcv;
302
303 gcv.cap_style = CapButt;
304 gcv.line_width = 0;
305 XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv);
306
307 while (a < b)
308 {
325 uint32_t command = linedraw_command [i1++]; 309 uint32_t command = *a++;
326 310
327 int op = (command >> 24) & 255; 311 int op = (command >> 24) & 255;
328 int a = (command >> 20) & 15; 312 int a = (command >> 20) & 15;
329 int b = (command >> 16) & 15; 313 int b = (command >> 16) & 15;
330 int x1 = x_[(command >> 12) & 15]; 314 int x1 = x_[(command >> 12) & 15];
339 break; 323 break;
340 324
341 case 1: // rectangle, possibly stippled 325 case 1: // rectangle, possibly stippled
342 if (a) 326 if (a)
343 { 327 {
344 static char bm[] = { 0,0 , 1,3 , 2,1 , 0,1 }; 328 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
345 329
346 gcv.fill_style = FillStippled; 330 gcv.fill_style = FillStippled;
347 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); 331 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2);
348 gcv.ts_x_origin = x; 332 gcv.ts_x_origin = x;
349 gcv.ts_y_origin = y; 333 gcv.ts_y_origin = y;
351 XChangeGC (d.display->display, TGC, 335 XChangeGC (d.display->display, TGC,
352 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 336 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
353 &gcv); 337 &gcv);
354 } 338 }
355 339
356
357 XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 340 XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
358 341
359 if (a) 342 if (a)
360 { 343 {
361 XFreePixmap (d.display->display, gcv.stipple); 344 XFreePixmap (d.display->display, gcv.stipple);
345 gcv.stipple = 0;
362 gcv.fill_style = FillSolid; 346 gcv.fill_style = FillSolid;
363 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); 347 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv);
364 } 348 }
365
366 break; 349 break;
367 case 2: // arc 350 case 2: // arc
351 XDrawArc (d.display->display, d, TGC,
352 x1 - W/2, y1 - H/2, W-1, H-1,
353 (a - 1) * 90*64, (b - 1) * 90*64);
368 break; 354 break;
369 } 355 }
370 } 356 }
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 } 357 }
387#if ENABLE_COMBINING 358#if ENABLE_COMBINING
388 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 359 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
389 { 360 {
390 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; 361 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)];
404 switch (t) 375 switch (t)
405 { 376 {
406 case ZERO_WIDTH_CHAR: 377 case ZERO_WIDTH_CHAR:
407 break; 378 break;
408 379
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
436 default: 380 default:
437 int w = 0; 381 int w = 0;
438 while (len > 0 && *text == NOCHAR) 382 while (len > 0 && *text == NOCHAR)
439 { 383 {
440 ++text; 384 ++text;
470 414
471 XFontStruct *f; 415 XFontStruct *f;
472 codeset cs; 416 codeset cs;
473 bool enc2b, encm; 417 bool enc2b, encm;
474 418
475 const char *get_property (XFontStruct *f, const char *property, const char *repl) const; 419 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); 420 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); 421 bool set_properties (rxvt_fontprop &p, XFontStruct *f);
478 bool set_properties (rxvt_fontprop &p, const char *name); 422 bool set_properties (rxvt_fontprop &p, const char *name);
479}; 423};
480 424
481const char * 425char *
482rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 426rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
483{ 427{
484 unsigned long value; 428 unsigned long value;
485 429
486 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 430 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
487 return XGetAtomName (DISPLAY, value); 431 return XGetAtomName (DISPLAY, value);
488 else 432 else
489 return repl; 433 return rxvt_strdup (repl);
490} 434}
491 435
492rxvt_fontprop 436rxvt_fontprop
493rxvt_font_x11::properties () 437rxvt_font_x11::properties ()
494{ 438{
509} 453}
510 454
511bool 455bool
512rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 456rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
513{ 457{
514 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
515 const char *slant = get_property (f, "SLANT", "r");
516
517 unsigned long height; 458 unsigned long height;
518 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 459 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
519 return false; 460 return false;
520 461
521 unsigned long avgwidth; 462 unsigned long avgwidth;
522 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 463 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
523 avgwidth = 0; 464 avgwidth = 0;
524 465
466 char *weight = get_property (f, "WEIGHT_NAME", "medium");
467 char *slant = get_property (f, "SLANT", "r");
468
525 return set_properties (p, height, weight, slant, avgwidth); 469 set_properties (p, height, weight, slant, avgwidth);
470
471 free (weight);
472 free (slant);
473
474 return true;
526} 475}
527 476
528bool 477bool
529rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 478rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
530{ 479{
634 f = XLoadQueryFont (DISPLAY, name); 583 f = XLoadQueryFont (DISPLAY, name);
635 584
636 if (!f) 585 if (!f)
637 return false; 586 return false;
638 587
639 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 588 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
640 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 589 char *encoding = get_property (f, "CHARSET_ENCODING", 0);
641 590
642 if (registry && encoding) 591 if (registry && encoding)
643 { 592 {
644 char charset[64]; 593 char charset[64];
645 snprintf (charset, 64, "%s-%s", registry, encoding); 594 snprintf (charset, 64, "%s-%s", registry, encoding);
658 if (*charset++ == '-' && !--count) 607 if (*charset++ == '-' && !--count)
659 break; 608 break;
660 609
661 cs = codeset_from_name (charset); 610 cs = codeset_from_name (charset);
662 } 611 }
612
613 free (registry);
614 free (encoding);
663 615
664 if (cs == CS_UNICODE) 616 if (cs == CS_UNICODE)
665 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 617 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
666 618
667 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 619 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
780 732
781 int base = r->TermWin.fbase; 733 int base = r->TermWin.fbase;
782 734
783 XGCValues v; 735 XGCValues v;
784 v.foreground = r->PixColors[fg]; 736 v.foreground = r->PixColors[fg];
785 v.background = r->PixColors[bg];
786 v.font = f->fid; 737 v.font = f->fid;
787 738
788 if (enc2b) 739 if (enc2b)
789 { 740 {
790 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 741 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
791 742
792 if (bg == Color_bg && !slow) 743 if (bg == Color_bg && !slow)
793 { 744 {
745 v.background = r->PixColors[bg];
794 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 746 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
795 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 747 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
796 } 748 }
797 else 749 else
798 { 750 {
820 { 772 {
821 const char *xc = enc_char (text, len, cs, slow); 773 const char *xc = enc_char (text, len, cs, slow);
822 774
823 if (bg == Color_bg && !slow) 775 if (bg == Color_bg && !slow)
824 { 776 {
777 v.background = r->PixColors[bg];
825 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 778 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
826 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 779 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
827 } 780 }
828 else 781 else
829 { 782 {
1048#endif 1001#endif
1049 1002
1050///////////////////////////////////////////////////////////////////////////// 1003/////////////////////////////////////////////////////////////////////////////
1051 1004
1052rxvt_fontset::rxvt_fontset (rxvt_t r) 1005rxvt_fontset::rxvt_fontset (rxvt_t r)
1053: r (r) 1006: r (r), fontdesc (0)
1054{ 1007{
1055 clear (); 1008 clear ();
1056} 1009}
1057 1010
1058rxvt_fontset::~rxvt_fontset () 1011rxvt_fontset::~rxvt_fontset ()
1063void 1016void
1064rxvt_fontset::clear () 1017rxvt_fontset::clear ()
1065{ 1018{
1066 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1019 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1067 FONT_UNREF (*i); 1020 FONT_UNREF (*i);
1021
1022 free (fontdesc); fontdesc = 0;
1068 1023
1069 fonts.clear (); 1024 fonts.clear ();
1070 base_id = 0; 1025 base_id = 0;
1071 base_prop.height = 0x7fffffff; 1026 base_prop.height = 0x7fffffff;
1072 base_prop.weight = rxvt_fontprop::medium; 1027 base_prop.weight = rxvt_fontprop::medium;
1180bool 1135bool
1181rxvt_fontset::populate (const char *desc) 1136rxvt_fontset::populate (const char *desc)
1182{ 1137{
1183 clear (); 1138 clear ();
1184 1139
1140 fontdesc = strdup (desc);
1141
1185 fonts.push_back (new_font (0, CS_UNICODE)); 1142 fonts.push_back (new_font (0, CS_UNICODE));
1186 realize_font (0); 1143 realize_font (0);
1187 1144
1188 add_fonts (desc); 1145 add_fonts (desc);
1189 1146
1205 1162
1206 return true; 1163 return true;
1207} 1164}
1208 1165
1209int 1166int
1210rxvt_fontset::find_font (unicode_t unicode) 1167rxvt_fontset::find_font (unicode_t unicode, bool bold)
1211{ 1168{
1212 for (unsigned int i = 0; i < fonts.size (); i++) 1169 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii
1170 i < fonts.size ();
1171 i++)
1213 { 1172 {
1214 rxvt_font *f = fonts[i]; 1173 rxvt_font *f = fonts[i];
1215 1174
1216 if (!f->loaded) 1175 if (!f->loaded)
1217 { 1176 {
1220 1179
1221 if (!realize_font (i)) 1180 if (!realize_font (i))
1222 goto next_font; 1181 goto next_font;
1223 } 1182 }
1224 1183
1184 if (f->cs == CS_UNKNOWN)
1185 goto next_font;
1186
1187 if (bold && f->properties ().weight < rxvt_fontprop::bold)
1188 goto next_font;
1189
1225 if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) 1190 if (f->has_codepoint (unicode))
1226 return i; 1191 return i;
1227 1192
1228 next_font: 1193 next_font:
1229 if (i == fonts.size () - 1 && fallback->name) 1194 if (i == fonts.size () - 1 && fallback->name)
1230 { 1195 {
1232 fallback++; 1197 fallback++;
1233 i = 0; 1198 i = 0;
1234 } 1199 }
1235 } 1200 }
1236 1201
1202 // if no bold font found, use a regular one
1203 if (bold)
1204 return find_font (unicode);
1205
1237 return 0; /* we must return SOME font */ 1206 return 0; /* we must return SOME font */
1238} 1207}
1239 1208
1240 1209
1241 1210

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines