1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: defaultfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 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 |
… | |
… | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
|
|
24 | #include "rxvtlib.h" |
24 | #include "rxvtutil.h" |
25 | #include "rxvtutil.h" |
25 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
26 | |
27 | |
27 | #include <cstdlib> |
28 | #include <cstdlib> |
28 | #include <wchar.h> |
29 | #include <wchar.h> |
29 | #include <inttypes.h> |
30 | #include <inttypes.h> |
30 | |
31 | |
31 | #define DISPLAY r->display->display |
32 | #define DISPLAY r->display->display |
32 | #define TGC r->TermWin.gc |
33 | #define TGC r->gc |
33 | |
34 | |
34 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | |
36 | |
36 | const struct rxvt_fallback_font { |
37 | const struct rxvt_fallback_font { |
37 | codeset cs; |
38 | codeset cs; |
… | |
… | |
90 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
91 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
91 | #endif |
92 | #endif |
92 | |
93 | |
93 | #if ENCODING_ZH || ENCODING_ZH_EXT |
94 | #if ENCODING_ZH || ENCODING_ZH_EXT |
94 | # if XFT |
95 | # if XFT |
|
|
96 | { CS_GBK_0, "xft:AR PL KaitiM GB" }, |
|
|
97 | { CS_GBK_0, "xft:AR PL SungtiL GB" }, |
|
|
98 | { CS_GBK_0, "xft::spacing=100:lang=zh" }, |
95 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
99 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
96 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
100 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
97 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
101 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
98 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
102 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
99 | { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, |
103 | { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, |
100 | # endif |
104 | # endif |
|
|
105 | { CS_GBK_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gbk*-0" }, |
101 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
106 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
102 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
107 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
103 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
108 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
|
|
109 | { CS_GB2312_1980_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
104 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
110 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
105 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
111 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
106 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
112 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
107 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
113 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
108 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
114 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
… | |
… | |
125 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
126 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
127 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
128 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
134 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
129 | #if XFT |
135 | #if XFT |
130 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, |
136 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
131 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
137 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
132 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
138 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
133 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
139 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
134 | |
140 | |
135 | // FreeMono is usually uglier than x fonts, so try last only. |
141 | // FreeMono is usually uglier than x fonts, so try last only. |
136 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
142 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
137 | #endif |
143 | #endif |
138 | |
144 | |
139 | { CS_UNKNOWN, 0 } |
145 | { CS_UNKNOWN, 0 } |
140 | }; |
146 | }; |
141 | |
147 | |
142 | // these characters are used to guess the font height and width |
148 | // these characters are used to guess the font height and width |
143 | // pango uses a similar algorithm and eosn't trust the font either. |
149 | // pango uses a similar algorithm and doesn't trust the font either. |
144 | static uint16_t extent_test_chars[] = { |
150 | static uint16_t extent_test_chars[] = { |
145 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
151 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
146 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
152 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
147 | 0x304c, 0x672c, // が本 |
153 | 0x304c, 0x672c, // が本 |
148 | }; |
154 | }; |
… | |
… | |
271 | rxvt_fontprop properties () |
277 | rxvt_fontprop properties () |
272 | { |
278 | { |
273 | rxvt_fontprop p; |
279 | rxvt_fontprop p; |
274 | |
280 | |
275 | p.width = p.height = 1; |
281 | p.width = p.height = 1; |
|
|
282 | p.ascent = rxvt_fontprop::unset; |
276 | p.weight = rxvt_fontprop::medium; |
283 | p.weight = rxvt_fontprop::medium; |
277 | p.slant = rxvt_fontprop::roman; |
284 | p.slant = rxvt_fontprop::roman; |
278 | |
285 | |
279 | return p; |
286 | return p; |
280 | } |
287 | } |
… | |
… | |
300 | return false; |
307 | return false; |
301 | |
308 | |
302 | if (unicode <= 0x009f) |
309 | if (unicode <= 0x009f) |
303 | return true; |
310 | return true; |
304 | |
311 | |
305 | if (unicode >= 0x2500 && unicode <= 0x259f) |
312 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
313 | !r->option (Opt_skipBuiltinGlyphs)) |
306 | return true; |
314 | return true; |
307 | |
315 | |
308 | if (IS_COMPOSE (unicode)) |
316 | if (IS_COMPOSE (unicode)) |
309 | return true; |
317 | return true; |
310 | |
318 | |
… | |
… | |
326 | void |
334 | void |
327 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
335 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
328 | const text_t *text, int len, |
336 | const text_t *text, int len, |
329 | int fg, int bg) |
337 | int fg, int bg) |
330 | { |
338 | { |
|
|
339 | Display *disp = d.display->display; |
|
|
340 | |
331 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
341 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
332 | |
342 | |
333 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
343 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
334 | |
344 | |
335 | while (len--) |
345 | while (len) |
336 | { |
346 | { |
337 | #if ENABLE_COMBINING |
347 | #if ENABLE_COMBINING |
338 | compose_char *cc; |
348 | compose_char *cc; |
339 | #endif |
349 | #endif |
|
|
350 | const text_t *tp = text; |
340 | text_t t = *text++; |
351 | text_t t = *tp; |
|
|
352 | |
|
|
353 | while (++text, --len && *text == NOCHAR) |
|
|
354 | ; |
|
|
355 | |
|
|
356 | int width = text - tp; |
|
|
357 | int fwidth = r->fwidth * width; |
341 | |
358 | |
342 | if (0x2500 <= t && t <= 0x259f) |
359 | if (0x2500 <= t && t <= 0x259f) |
343 | { |
360 | { |
344 | uint16_t offs = linedraw_offs[t - 0x2500]; |
361 | uint16_t offs = linedraw_offs[t - 0x2500]; |
345 | uint32_t *a = linedraw_command + (offs >> 4); |
362 | uint32_t *a = linedraw_command + (offs >> 4); |
346 | uint32_t *b = a + (offs & 15); |
363 | uint32_t *b = a + (offs & 15); |
347 | |
364 | |
348 | int W = r->TermWin.fwidth; |
365 | int W = fwidth; |
349 | int H = r->TermWin.fheight; |
366 | int H = r->fheight; |
350 | |
367 | |
351 | int x_[16]; |
368 | int x_[16]; |
352 | int y_[16]; |
369 | int y_[16]; |
353 | |
370 | |
354 | for (int i = 0; i <= 8; i++) |
371 | for (int i = 0; i <= 8; i++) |
… | |
… | |
362 | |
379 | |
363 | XGCValues gcv; |
380 | XGCValues gcv; |
364 | |
381 | |
365 | gcv.cap_style = CapButt; |
382 | gcv.cap_style = CapButt; |
366 | gcv.line_width = 0; |
383 | gcv.line_width = 0; |
367 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
384 | XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); |
368 | |
385 | |
369 | while (a < b) |
386 | while (a < b) |
370 | { |
387 | { |
371 | uint32_t command = *a++; |
388 | uint32_t command = *a++; |
372 | |
389 | |
… | |
… | |
379 | int y2 = y_[(command >> 0) & 15]; |
396 | int y2 = y_[(command >> 0) & 15]; |
380 | |
397 | |
381 | switch (op) |
398 | switch (op) |
382 | { |
399 | { |
383 | case 0: // line |
400 | case 0: // line |
384 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
401 | XDrawLine (disp, d, TGC, x1, y1, x2, y2); |
385 | break; |
402 | break; |
386 | |
403 | |
387 | case 1: // rectangle, possibly stippled |
404 | case 1: // rectangle, possibly stippled |
388 | if (a) |
405 | if (a) |
389 | { |
406 | { |
390 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
407 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
391 | |
408 | |
392 | gcv.fill_style = FillStippled; |
409 | gcv.fill_style = FillStippled; |
393 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
410 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
394 | gcv.ts_x_origin = x; |
411 | gcv.ts_x_origin = x; |
395 | gcv.ts_y_origin = y; |
412 | gcv.ts_y_origin = y; |
396 | |
413 | |
397 | XChangeGC (d.display->display, TGC, |
414 | XChangeGC (disp, TGC, |
398 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
415 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
399 | &gcv); |
416 | &gcv); |
400 | } |
417 | } |
401 | |
418 | |
402 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
419 | XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
403 | |
420 | |
404 | if (a) |
421 | if (a) |
405 | { |
422 | { |
406 | XFreePixmap (d.display->display, gcv.stipple); |
423 | XFreePixmap (disp, gcv.stipple); |
407 | gcv.stipple = 0; |
424 | gcv.stipple = 0; |
408 | gcv.fill_style = FillSolid; |
425 | gcv.fill_style = FillSolid; |
409 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
426 | XChangeGC (disp, TGC, GCFillStyle, &gcv); |
410 | } |
427 | } |
411 | break; |
428 | break; |
412 | case 2: // arc |
429 | case 2: // arc |
413 | XDrawArc (d.display->display, d, TGC, |
430 | XDrawArc (disp, d, TGC, |
414 | x1 - W/2, y1 - H/2, W-1, H-1, |
431 | x1 - W/2, y1 - H/2, W-1, H-1, |
415 | (a - 1) * 90*64, (b - 1) * 90*64); |
432 | (a - 1) * 90*64, (b - 1) * 90*64); |
416 | break; |
433 | break; |
417 | } |
434 | } |
418 | } |
435 | } |
419 | } |
436 | } |
420 | #if ENABLE_COMBINING |
437 | #if ENABLE_COMBINING |
421 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
438 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
422 | { |
439 | { |
423 | text_t c2[2]; |
440 | text_t chrs[2]; |
424 | int len2 = 1; |
441 | width = min (2, width); |
425 | |
442 | chrs [1] = NOCHAR; |
426 | // support double-width (but not more) combining characters |
|
|
427 | if (len && *text == NOCHAR) |
|
|
428 | { |
|
|
429 | c2[1] = *text; // not text++ to get correct x-width |
|
|
430 | len2++; |
|
|
431 | } |
|
|
432 | |
443 | |
433 | c2[0] = cc->c1; |
444 | *chrs = cc->c1; |
434 | rxvt_font *f1 = (*fs)[fs->find_font (c2[0])]; |
445 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
435 | f1->draw (d, x, y, c2, len2, fg, bg); |
446 | f1->draw (d, x, y, chrs, width, fg, bg); |
436 | |
447 | |
437 | if (cc->c2 != NOCHAR) |
448 | if (cc->c2 != NOCHAR) |
438 | { |
449 | { |
439 | bool careful; |
450 | bool careful; |
440 | |
451 | |
441 | // prefer font of first character, for no good reasons |
452 | // prefer font of first character, for no good reasons |
442 | c2[0] = cc->c2; |
453 | *chrs = cc->c2; |
443 | rxvt_font *f2 = (f1->has_char (c2[0], 0, careful) && !careful) |
454 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
444 | ? f1 |
455 | ? f1 |
445 | : (*fs)[fs->find_font (c2[0])]; |
456 | : (*fs)[fs->find_font (cc->c2)]; |
446 | |
457 | |
447 | f2->draw (d, x, y, c2, len2, fg, -1); |
458 | f2->draw (d, x, y, chrs, width, fg, -1); |
448 | } |
459 | } |
449 | } |
460 | } |
450 | #endif |
461 | #endif |
451 | else |
462 | else |
452 | switch (t) |
463 | switch (t) |
… | |
… | |
455 | case ZERO_WIDTH_CHAR: |
466 | case ZERO_WIDTH_CHAR: |
456 | case NOCHAR: |
467 | case NOCHAR: |
457 | break; |
468 | break; |
458 | |
469 | |
459 | default: |
470 | default: |
460 | int w = 0; |
|
|
461 | while (len > 0 && *text == NOCHAR) |
|
|
462 | { |
|
|
463 | ++text; |
|
|
464 | --len; |
|
|
465 | w += r->TermWin.fwidth; |
|
|
466 | } |
|
|
467 | |
|
|
468 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
471 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
469 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
472 | fwidth - 4, r->fheight - 4); |
470 | x += w; |
|
|
471 | } |
473 | } |
472 | |
474 | |
473 | x += r->TermWin.fwidth; |
475 | x += fwidth; |
474 | } |
476 | } |
475 | } |
477 | } |
476 | |
478 | |
477 | ///////////////////////////////////////////////////////////////////////////// |
479 | ///////////////////////////////////////////////////////////////////////////// |
478 | |
480 | |
… | |
… | |
524 | bool |
526 | bool |
525 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
527 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
526 | { |
528 | { |
527 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
529 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
528 | p.height = height; |
530 | p.height = height; |
|
|
531 | p.ascent = rxvt_fontprop::unset; |
529 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
532 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
530 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
533 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
531 | |
534 | |
532 | return true; |
535 | return true; |
533 | } |
536 | } |
534 | |
537 | |
535 | bool |
538 | bool |
536 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
539 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
537 | { |
540 | { |
538 | unsigned long height; |
541 | unsigned long height; |
|
|
542 | |
|
|
543 | #if 0 |
539 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
544 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
540 | return false; |
545 | return false; |
|
|
546 | #else |
|
|
547 | height = f->ascent + f->descent; |
|
|
548 | #endif |
541 | |
549 | |
542 | unsigned long avgwidth; |
550 | unsigned long avgwidth; |
543 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
551 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
544 | avgwidth = 0; |
552 | avgwidth = 0; |
545 | |
553 | |
… | |
… | |
548 | |
556 | |
549 | set_properties (p, height, weight, slant, avgwidth); |
557 | set_properties (p, height, weight, slant, avgwidth); |
550 | |
558 | |
551 | free (weight); |
559 | free (weight); |
552 | free (slant); |
560 | free (slant); |
|
|
561 | |
|
|
562 | p.ascent = f->ascent; |
553 | |
563 | |
554 | return true; |
564 | return true; |
555 | } |
565 | } |
556 | |
566 | |
557 | bool |
567 | bool |
… | |
… | |
628 | } |
638 | } |
629 | |
639 | |
630 | bool |
640 | bool |
631 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
641 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
632 | { |
642 | { |
|
|
643 | Display *disp = DISPLAY; |
|
|
644 | |
633 | clear (); |
645 | clear (); |
634 | |
646 | |
635 | char field_str[64]; // enough for 128 bits |
647 | char field_str[64]; // enough for 128 bits |
636 | |
648 | |
637 | // first morph the font if required |
649 | // first morph the font if required |
… | |
… | |
640 | { |
652 | { |
641 | char fname[1024]; |
653 | char fname[1024]; |
642 | |
654 | |
643 | if (name[0] != '-') |
655 | if (name[0] != '-') |
644 | { |
656 | { |
645 | f = XLoadQueryFont (DISPLAY, name); |
657 | f = XLoadQueryFont (disp, name); |
646 | |
658 | |
647 | if (!f) |
659 | if (!f) |
648 | return false; |
660 | return false; |
649 | |
661 | |
650 | char *new_name = get_property (f, "FONT", name); |
662 | char *new_name = get_property (f, "FONT", name); |
… | |
… | |
652 | if (new_name) |
664 | if (new_name) |
653 | set_name (new_name); |
665 | set_name (new_name); |
654 | else |
666 | else |
655 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
667 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
656 | |
668 | |
657 | XFreeFont (DISPLAY, f); |
669 | XFreeFont (disp, f); |
658 | f = 0; |
670 | f = 0; |
659 | } |
671 | } |
660 | |
672 | |
661 | if (prop.weight != rxvt_fontprop::unset) |
673 | if (prop.weight != rxvt_fontprop::unset) |
662 | { |
674 | { |
… | |
… | |
673 | ? "r" : "i"); // TODO: handle "o"blique, too |
685 | ? "r" : "i"); // TODO: handle "o"blique, too |
674 | set_name (strdup (fname)); |
686 | set_name (strdup (fname)); |
675 | } |
687 | } |
676 | } |
688 | } |
677 | |
689 | |
|
|
690 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
|
|
691 | ? 0 : prop.height); |
|
|
692 | |
|
|
693 | struct font_weight { |
|
|
694 | char *name; |
|
|
695 | int diff; |
|
|
696 | |
|
|
697 | void clear () |
|
|
698 | { |
|
|
699 | name = 0; |
|
|
700 | diff = 0x7fffffff; |
|
|
701 | } |
|
|
702 | |
|
|
703 | font_weight () { clear (); } |
|
|
704 | ~font_weight () { free (name); } |
|
|
705 | }; |
|
|
706 | |
678 | char **list; |
707 | char **list; |
679 | int count; |
708 | int count; |
680 | list = XListFonts (DISPLAY, name, 1024, &count); |
709 | list = XListFonts (disp, name, 4000, &count); |
681 | |
710 | |
682 | set_name (0); |
711 | set_name (0); |
683 | |
712 | |
684 | if (!list) |
713 | if (!list) |
685 | return false; |
714 | return false; |
686 | |
715 | |
687 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
716 | font_weight *fonts = new font_weight[count]; |
688 | ? 0 : prop.height); |
|
|
689 | |
717 | |
690 | int bestdiff = 0x7fffffff; |
|
|
691 | for (int i = 0; i < count; i++) |
718 | for (int i = 0; i < count; i++) |
692 | { |
719 | { |
693 | rxvt_fontprop p; |
720 | rxvt_fontprop p; |
694 | char fname[1024]; |
721 | char fname[1024]; |
695 | |
722 | |
696 | int diff = 0; |
723 | int diff = 0; |
697 | |
724 | |
698 | if (replace_field (fname, list[i], 6, '0', field_str)) |
725 | if (replace_field (fname, list[i], 6, '0', field_str)) |
699 | diff += 10; // slightly penalize scalable fonts |
726 | diff += 10; // slightly penalize scalable fonts |
|
|
727 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
728 | diff += 300; // more heavily penalize what looks like scaled bitmap fotns |
700 | |
729 | |
701 | if (!set_properties (p, fname)) |
730 | if (!set_properties (p, fname)) |
702 | continue; |
731 | continue; |
703 | |
732 | |
704 | if (prop.height != rxvt_fontprop::unset |
733 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
708 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
737 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
709 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
738 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
710 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
739 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
711 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
740 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
712 | |
741 | |
713 | if (!name // compare against best found so far |
742 | fonts[i].name = strdup (fname); |
714 | || diff < bestdiff) |
743 | fonts[i].diff = diff; |
715 | { |
|
|
716 | set_name (strdup (fname)); |
|
|
717 | bestdiff = diff; |
|
|
718 | } |
|
|
719 | } |
744 | } |
720 | |
745 | |
721 | XFreeFontNames (list); |
746 | XFreeFontNames (list); |
722 | |
747 | |
723 | if (!name) |
748 | // this loop only iterates when the guessed font-size is too small |
724 | return false; |
749 | for (;;) |
|
|
750 | { |
|
|
751 | font_weight *best = fonts + count - 1; |
725 | |
752 | |
726 | f = XLoadQueryFont (DISPLAY, name); |
753 | for (font_weight *w = best; w-- > fonts; ) |
|
|
754 | if (w->diff <= best->diff) |
|
|
755 | best = w; |
|
|
756 | |
|
|
757 | if (!best->name |
|
|
758 | || !(f = XLoadQueryFont (disp, best->name))) |
|
|
759 | break; |
|
|
760 | |
|
|
761 | set_name (best->name); |
|
|
762 | best->clear (); |
|
|
763 | |
|
|
764 | ascent = f->ascent; |
|
|
765 | descent = f->descent; |
|
|
766 | height = ascent + descent; |
|
|
767 | |
|
|
768 | if (prop.height == rxvt_fontprop::unset |
|
|
769 | || height <= prop.height) |
|
|
770 | break; // font is ready for use |
|
|
771 | |
|
|
772 | // PIXEL_SIZE small enough, but real height too large |
|
|
773 | clear (); |
|
|
774 | } |
|
|
775 | |
|
|
776 | delete [] fonts; |
727 | |
777 | |
728 | if (!f) |
778 | if (!f) |
729 | return false; |
779 | return false; |
730 | |
780 | |
731 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
781 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
… | |
… | |
759 | if (cs == CS_UNICODE) |
809 | if (cs == CS_UNICODE) |
760 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
810 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
761 | |
811 | |
762 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
812 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
763 | enc2b = encm || f->max_char_or_byte2 > 255; |
813 | enc2b = encm || f->max_char_or_byte2 > 255; |
764 | |
|
|
765 | ascent = f->ascent; |
|
|
766 | descent = f->descent; |
|
|
767 | height = ascent + descent; |
|
|
768 | |
814 | |
769 | slow = false; |
815 | slow = false; |
770 | |
816 | |
771 | #if 1 // only used for slow detection, TODO optimize |
817 | #if 1 // only used for slow detection, TODO optimize |
772 | if (f->min_bounds.width == f->max_bounds.width) |
818 | if (f->min_bounds.width == f->max_bounds.width) |
… | |
… | |
811 | |
857 | |
812 | XCharStruct g; |
858 | XCharStruct g; |
813 | int dir_ret, asc_ret, des_ret; |
859 | int dir_ret, asc_ret, des_ret; |
814 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
860 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
815 | |
861 | |
816 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
862 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
817 | |
863 | |
818 | if (width < g.width) width = g.width; |
864 | if (width < g.width) width = g.width; |
819 | } |
865 | } |
820 | |
866 | |
821 | if (cs == CS_UNKNOWN) |
867 | if (cs == CS_UNKNOWN) |
… | |
… | |
896 | return true; |
942 | return true; |
897 | |
943 | |
898 | // check character against base font bounding box |
944 | // check character against base font bounding box |
899 | int w = xcs->width; |
945 | int w = xcs->width; |
900 | int wcw = wcwidth (unicode); |
946 | int wcw = wcwidth (unicode); |
901 | if (wcw > 0) w /= wcw; |
947 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
902 | |
948 | |
903 | careful = w > prop->width; |
949 | careful = w > prop->width; |
904 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
950 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
905 | return false; |
951 | return false; |
906 | |
952 | |
… | |
… | |
916 | // and it is a mess /. |
962 | // and it is a mess /. |
917 | // yet we are trying to be perfect /. |
963 | // yet we are trying to be perfect /. |
918 | // but the result still isn't perfect /. |
964 | // but the result still isn't perfect /. |
919 | |
965 | |
920 | bool slow = this->slow |
966 | bool slow = this->slow |
921 | || width != r->TermWin.fwidth |
967 | || width != r->fwidth |
922 | || height != r->TermWin.fheight; |
968 | || height != r->fheight; |
923 | |
969 | |
924 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
970 | int base = ascent; // sorry, incorrect: r->fbase; |
925 | |
971 | |
926 | XGCValues v; |
972 | XGCValues v; |
927 | v.foreground = r->pix_colors[fg]; |
973 | v.foreground = r->pix_colors[fg]; |
928 | v.font = f->fid; |
974 | v.font = f->fid; |
929 | |
975 | |
… | |
… | |
937 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
983 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
938 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
984 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
939 | } |
985 | } |
940 | else |
986 | else |
941 | { |
987 | { |
942 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
988 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
943 | |
989 | |
944 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
990 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
945 | |
991 | |
946 | if (slow) |
992 | if (slow) |
947 | { |
993 | { |
948 | do |
994 | do |
949 | { |
995 | { |
950 | if (xc->byte1 || xc->byte2) |
996 | if (xc->byte1 || xc->byte2) |
951 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
997 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
952 | |
998 | |
953 | x += r->TermWin.fwidth; |
999 | x += r->fwidth; |
954 | xc++; len--; |
1000 | xc++; len--; |
955 | } |
1001 | } |
956 | while (len); |
1002 | while (len); |
957 | } |
1003 | } |
958 | else |
1004 | else |
… | |
… | |
969 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1015 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
970 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1016 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
971 | } |
1017 | } |
972 | else |
1018 | else |
973 | { |
1019 | { |
974 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1020 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
975 | |
1021 | |
976 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1022 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
977 | |
1023 | |
978 | if (slow) |
1024 | if (slow) |
979 | { |
1025 | { |
980 | do |
1026 | do |
981 | { |
1027 | { |
982 | if (*xc) |
1028 | if (*xc) |
983 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1029 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
984 | |
1030 | |
985 | x += r->TermWin.fwidth; |
1031 | x += r->fwidth; |
986 | xc++; len--; |
1032 | xc++; len--; |
987 | } |
1033 | } |
988 | while (len); |
1034 | while (len); |
989 | } |
1035 | } |
990 | else |
1036 | else |
… | |
… | |
1033 | |
1079 | |
1034 | FT_Face face = XftLockFace (f); |
1080 | FT_Face face = XftLockFace (f); |
1035 | |
1081 | |
1036 | p.width = width; |
1082 | p.width = width; |
1037 | p.height = height; |
1083 | p.height = height; |
|
|
1084 | p.ascent = ascent; |
1038 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1085 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1039 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1086 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1040 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1087 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1041 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1088 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1042 | |
1089 | |
… | |
… | |
1046 | } |
1093 | } |
1047 | |
1094 | |
1048 | bool |
1095 | bool |
1049 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1096 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1050 | { |
1097 | { |
|
|
1098 | Display *disp = DISPLAY; |
|
|
1099 | |
1051 | clear (); |
1100 | clear (); |
1052 | |
1101 | |
1053 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1102 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1054 | |
1103 | |
1055 | if (!p) |
1104 | if (!p) |
1056 | return false; |
1105 | return false; |
1057 | |
1106 | |
1058 | FcValue v; |
1107 | FcValue v; |
1059 | |
1108 | |
1060 | if (prop.height != rxvt_fontprop::unset |
1109 | if (prop.height != rxvt_fontprop::unset |
1061 | || FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch) |
1110 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
|
|
1111 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1062 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1112 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1063 | |
1113 | |
1064 | if (prop.weight != rxvt_fontprop::unset |
1114 | if (prop.weight != rxvt_fontprop::unset |
1065 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1115 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1066 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1116 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
… | |
… | |
1080 | |
1130 | |
1081 | // store generated name so iso14755 view gives better results |
1131 | // store generated name so iso14755 view gives better results |
1082 | set_name ((char *)FcNameUnparse (p)); |
1132 | set_name ((char *)FcNameUnparse (p)); |
1083 | |
1133 | |
1084 | XftResult result; |
1134 | XftResult result; |
1085 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1135 | FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); |
1086 | |
1136 | |
1087 | FcPatternDestroy (p); |
1137 | FcPatternDestroy (p); |
1088 | |
1138 | |
1089 | if (!match) |
1139 | if (!match) |
1090 | return false; |
1140 | return false; |
… | |
… | |
1092 | int ftheight = 0; |
1142 | int ftheight = 0; |
1093 | bool success = true; |
1143 | bool success = true; |
1094 | |
1144 | |
1095 | for (;;) |
1145 | for (;;) |
1096 | { |
1146 | { |
1097 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1147 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1098 | |
1148 | |
1099 | if (!f) |
1149 | if (!f) |
1100 | { |
1150 | { |
1101 | success = false; |
1151 | success = false; |
1102 | break; |
1152 | break; |
… | |
… | |
1111 | |
1161 | |
1112 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1162 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1113 | |
1163 | |
1114 | XftUnlockFace (f); |
1164 | XftUnlockFace (f); |
1115 | |
1165 | |
|
|
1166 | int glheight = height; |
|
|
1167 | |
1116 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1168 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1117 | { |
1169 | { |
1118 | FcChar16 ch = *t; |
1170 | FcChar16 ch = *t; |
1119 | |
1171 | |
1120 | if (cs != CS_UNICODE |
1172 | if (cs != CS_UNICODE |
… | |
… | |
1126 | bool careful; |
1178 | bool careful; |
1127 | if (!has_char (*t, &prop, careful)) |
1179 | if (!has_char (*t, &prop, careful)) |
1128 | continue; |
1180 | continue; |
1129 | |
1181 | |
1130 | XGlyphInfo g; |
1182 | XGlyphInfo g; |
1131 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1183 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1184 | |
|
|
1185 | g.width -= g.x; |
1132 | |
1186 | |
1133 | int wcw = wcwidth (ch); |
1187 | int wcw = wcwidth (ch); |
1134 | if (wcw > 0) g.width = g.width / wcw; |
1188 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1135 | |
1189 | |
1136 | if (width < g.width) width = g.width; |
1190 | if (width < g.width ) width = g.width; |
1137 | if (height < g.height) height = g.height; |
1191 | if (height < g.height ) height = g.height; |
|
|
1192 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1193 | } |
|
|
1194 | |
|
|
1195 | if (!width) |
|
|
1196 | { |
|
|
1197 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1198 | |
|
|
1199 | XftFontClose (disp, f); |
|
|
1200 | f = 0; |
|
|
1201 | |
|
|
1202 | success = false; |
|
|
1203 | break; |
1138 | } |
1204 | } |
1139 | |
1205 | |
1140 | if (prop.height == rxvt_fontprop::unset |
1206 | if (prop.height == rxvt_fontprop::unset |
1141 | || height <= prop.height |
1207 | || (height <= prop.height && glheight <= prop.height) |
1142 | || height <= 2 |
1208 | || height <= 2 |
1143 | || !scalable) |
1209 | || !scalable) |
1144 | break; |
1210 | break; |
1145 | |
1211 | |
1146 | if (ftheight) |
1212 | if (ftheight) |
… | |
… | |
1153 | ftheight -= height - prop.height; |
1219 | ftheight -= height - prop.height; |
1154 | } |
1220 | } |
1155 | else |
1221 | else |
1156 | ftheight = prop.height - 1; |
1222 | ftheight = prop.height - 1; |
1157 | |
1223 | |
1158 | XftFontClose (DISPLAY, f); |
1224 | XftFontClose (disp, f); |
1159 | FcPatternDel (match, FC_PIXEL_SIZE); |
1225 | FcPatternDel (match, FC_PIXEL_SIZE); |
1160 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1226 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1161 | } |
1227 | } |
1162 | |
1228 | |
1163 | FcPatternDestroy (match); |
1229 | FcPatternDestroy (match); |
1164 | |
1230 | |
1165 | #if 0 // do it per-character |
1231 | #if 0 // do it per-character |
… | |
… | |
1187 | // check character against base font bounding box |
1253 | // check character against base font bounding box |
1188 | FcChar32 ch = unicode; |
1254 | FcChar32 ch = unicode; |
1189 | XGlyphInfo g; |
1255 | XGlyphInfo g; |
1190 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1256 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1191 | |
1257 | |
1192 | int w = g.width; |
1258 | int w = g.width - g.x; |
1193 | int wcw = wcwidth (unicode); |
1259 | int wcw = wcwidth (unicode); |
1194 | if (wcw > 0) w /= wcw; |
1260 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1195 | |
1261 | |
1196 | careful = w > prop->width; |
1262 | careful = w > prop->width; |
1197 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1263 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1198 | return false; |
1264 | return false; |
1199 | |
1265 | |
… | |
… | |
1203 | void |
1269 | void |
1204 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1270 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1205 | const text_t *text, int len, |
1271 | const text_t *text, int len, |
1206 | int fg, int bg) |
1272 | int fg, int bg) |
1207 | { |
1273 | { |
1208 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1274 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1209 | |
1275 | |
1210 | int base = ascent; // should be fbase, but that is incorrect |
1276 | int base = ascent; // should be fbase, but that is incorrect |
1211 | |
1277 | |
1212 | XGlyphInfo extents; |
1278 | XGlyphInfo extents; |
1213 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1279 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1214 | FcChar32 *ep = enc; |
1280 | FcChar32 *ep = enc; |
1215 | int ewidth = 0; |
1281 | int ewidth = 0; |
1216 | int xoff = 0; |
|
|
1217 | |
1282 | |
1218 | while (len) |
1283 | while (len) |
1219 | { |
1284 | { |
1220 | int cwidth = r->TermWin.fwidth; |
1285 | int cwidth = r->fwidth; |
1221 | FcChar32 fc = *text++; len--; |
1286 | FcChar32 fc = *text++; len--; |
1222 | FT_UInt gl; |
|
|
1223 | |
1287 | |
1224 | while (len && *text == NOCHAR) |
1288 | while (len && *text == NOCHAR) |
1225 | text++, len--, cwidth += r->TermWin.fwidth; |
1289 | text++, len--, cwidth += r->fwidth; |
1226 | |
1290 | |
1227 | gl = XftCharIndex (d.display->display, f, fc); |
|
|
1228 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1229 | |
|
|
1230 | if (extents.xOff != cwidth && ep != enc) |
|
|
1231 | { |
|
|
1232 | if (xoff > ewidth) xoff = ewidth; |
|
|
1233 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1234 | x + (ewidth - xoff >> 1), |
|
|
1235 | y + base, enc, ep - enc); |
|
|
1236 | x += ewidth; |
|
|
1237 | |
|
|
1238 | ep = enc; |
|
|
1239 | ewidth = 0; |
|
|
1240 | xoff = 0; |
|
|
1241 | } |
|
|
1242 | |
|
|
1243 | if (fc == ' ' && ep == enc) // skip leading spaces |
1291 | if (fc == ' ' && ep == enc) // skip leading spaces |
1244 | { |
|
|
1245 | x += cwidth; |
1292 | x += cwidth; |
1246 | continue; |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | else |
1293 | else |
1250 | { |
1294 | { |
|
|
1295 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
|
|
1296 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1297 | |
|
|
1298 | if (extents.xOff != cwidth) |
|
|
1299 | { |
|
|
1300 | if (ewidth) |
|
|
1301 | { |
|
|
1302 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1303 | x, y + base, enc, ep - enc); |
|
|
1304 | x += ewidth; |
|
|
1305 | |
|
|
1306 | ep = enc; |
|
|
1307 | ewidth = 0; |
|
|
1308 | } |
|
|
1309 | |
|
|
1310 | if (extents.xOff > cwidth) |
|
|
1311 | extents.xOff = cwidth; |
|
|
1312 | |
|
|
1313 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1314 | x + (cwidth - extents.xOff >> 1), |
|
|
1315 | y + base, &gl, 1); |
|
|
1316 | x += cwidth; |
|
|
1317 | } |
|
|
1318 | else |
|
|
1319 | { |
1251 | *ep++ = gl; |
1320 | *ep++ = gl; |
1252 | ewidth += cwidth; |
1321 | ewidth += cwidth; |
1253 | xoff += extents.xOff; |
1322 | } |
1254 | } |
1323 | } |
1255 | } |
1324 | } |
1256 | |
1325 | |
1257 | if (ep != enc) |
1326 | if (ep != enc) |
1258 | { |
|
|
1259 | if (xoff > ewidth) xoff = ewidth; |
|
|
1260 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1327 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1261 | x + (ewidth - xoff >> 1), |
|
|
1262 | y + base, enc, ep - enc); |
1328 | x, y + base, enc, ep - enc); |
1263 | } |
|
|
1264 | } |
1329 | } |
1265 | #endif |
1330 | #endif |
1266 | |
1331 | |
1267 | ///////////////////////////////////////////////////////////////////////////// |
1332 | ///////////////////////////////////////////////////////////////////////////// |
1268 | |
1333 | |
1269 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1334 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1270 | : r (r), fontdesc (0) |
1335 | : fontdesc (0), r (r) |
1271 | { |
1336 | { |
1272 | clear (); |
1337 | clear (); |
1273 | } |
1338 | } |
1274 | |
1339 | |
1275 | rxvt_fontset::~rxvt_fontset () |
1340 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1278 | } |
1343 | } |
1279 | |
1344 | |
1280 | void |
1345 | void |
1281 | rxvt_fontset::clear () |
1346 | rxvt_fontset::clear () |
1282 | { |
1347 | { |
1283 | prop.width = prop.height = prop.weight = prop.slant |
1348 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1284 | = rxvt_fontprop::unset; |
1349 | = rxvt_fontprop::unset; |
1285 | |
1350 | |
1286 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1351 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1287 | FONT_UNREF (*i); |
1352 | FONT_UNREF (*i); |
1288 | |
1353 | |
… | |
… | |
1340 | char buf[512]; |
1405 | char buf[512]; |
1341 | const char *end; |
1406 | const char *end; |
1342 | |
1407 | |
1343 | do |
1408 | do |
1344 | { |
1409 | { |
1345 | while (*desc <= ' ') desc++; |
1410 | while (*desc && *desc <= ' ') |
|
|
1411 | desc++; |
1346 | |
1412 | |
1347 | codeset cs = CS_UNICODE; |
1413 | codeset cs = CS_UNICODE; |
1348 | |
1414 | |
1349 | if (*desc == '[') |
1415 | if (*desc == '[') |
1350 | { |
1416 | { |
… | |
… | |
1460 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1526 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1461 | goto next_font; |
1527 | goto next_font; |
1462 | |
1528 | |
1463 | if (!realize_font (i)) |
1529 | if (!realize_font (i)) |
1464 | goto next_font; |
1530 | goto next_font; |
|
|
1531 | |
|
|
1532 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1533 | max_it (f->ascent, prop.ascent); |
1465 | } |
1534 | } |
1466 | |
1535 | |
1467 | if (f->cs == CS_UNKNOWN) |
1536 | if (f->cs == CS_UNKNOWN) |
1468 | goto next_font; |
1537 | goto next_font; |
1469 | |
1538 | |
… | |
… | |
1508 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1577 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1509 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1578 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1510 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1579 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1511 | |
1580 | |
1512 | XftResult result; |
1581 | XftResult result; |
1513 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1582 | FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); |
1514 | |
1583 | |
1515 | FcPatternDestroy (p); |
1584 | FcPatternDestroy (p); |
1516 | |
1585 | |
1517 | if (match) |
1586 | if (match) |
1518 | { |
1587 | { |