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-2004 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
7 | * This program is free software; you can redistribute it and/or modify |
… | |
… | |
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; |
… | |
… | |
88 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
89 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
89 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
90 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
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_CN || ENCODING_CN_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"}, |
136 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
131 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
|
|
132 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
|
|
133 | { CS_UNICODE, "xft:Courier New:antialias=false" }, |
137 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
|
|
138 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=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" }, |
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 | ! OPTION_R (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; |
341 | |
352 | |
|
|
353 | while (++text, --len && *text == NOCHAR) |
|
|
354 | ; |
|
|
355 | |
|
|
356 | int width = text - tp; |
|
|
357 | int fwidth = r->fwidth * width; |
|
|
358 | |
342 | if (0x2500 <= t && t <= 0x259f) |
359 | if (0x2500 <= t && t <= 0x259f && |
|
|
360 | ! OPTION_R (Opt_skipBuiltinGlyphs)) |
343 | { |
361 | { |
344 | uint16_t offs = linedraw_offs[t - 0x2500]; |
362 | uint16_t offs = linedraw_offs[t - 0x2500]; |
345 | uint32_t *a = linedraw_command + (offs >> 4); |
363 | uint32_t *a = linedraw_command + (offs >> 4); |
346 | uint32_t *b = a + (offs & 15); |
364 | uint32_t *b = a + (offs & 15); |
347 | |
365 | |
348 | int W = r->TermWin.fwidth; |
366 | int W = fwidth; |
349 | int H = r->TermWin.fheight; |
367 | int H = r->fheight; |
350 | |
368 | |
351 | int x_[16]; |
369 | int x_[16]; |
352 | int y_[16]; |
370 | int y_[16]; |
353 | |
371 | |
354 | for (int i = 0; i <= 8; i++) |
372 | for (int i = 0; i <= 8; i++) |
… | |
… | |
362 | |
380 | |
363 | XGCValues gcv; |
381 | XGCValues gcv; |
364 | |
382 | |
365 | gcv.cap_style = CapButt; |
383 | gcv.cap_style = CapButt; |
366 | gcv.line_width = 0; |
384 | gcv.line_width = 0; |
367 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
385 | XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); |
368 | |
386 | |
369 | while (a < b) |
387 | while (a < b) |
370 | { |
388 | { |
371 | uint32_t command = *a++; |
389 | uint32_t command = *a++; |
372 | |
390 | |
… | |
… | |
379 | int y2 = y_[(command >> 0) & 15]; |
397 | int y2 = y_[(command >> 0) & 15]; |
380 | |
398 | |
381 | switch (op) |
399 | switch (op) |
382 | { |
400 | { |
383 | case 0: // line |
401 | case 0: // line |
384 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
402 | XDrawLine (disp, d, TGC, x1, y1, x2, y2); |
385 | break; |
403 | break; |
386 | |
404 | |
387 | case 1: // rectangle, possibly stippled |
405 | case 1: // rectangle, possibly stippled |
388 | if (a) |
406 | if (a) |
389 | { |
407 | { |
390 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
408 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
391 | |
409 | |
392 | gcv.fill_style = FillStippled; |
410 | gcv.fill_style = FillStippled; |
393 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
411 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
394 | gcv.ts_x_origin = x; |
412 | gcv.ts_x_origin = x; |
395 | gcv.ts_y_origin = y; |
413 | gcv.ts_y_origin = y; |
396 | |
414 | |
397 | XChangeGC (d.display->display, TGC, |
415 | XChangeGC (disp, TGC, |
398 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
416 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
399 | &gcv); |
417 | &gcv); |
400 | } |
418 | } |
401 | |
419 | |
402 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
420 | XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
403 | |
421 | |
404 | if (a) |
422 | if (a) |
405 | { |
423 | { |
406 | XFreePixmap (d.display->display, gcv.stipple); |
424 | XFreePixmap (disp, gcv.stipple); |
407 | gcv.stipple = 0; |
425 | gcv.stipple = 0; |
408 | gcv.fill_style = FillSolid; |
426 | gcv.fill_style = FillSolid; |
409 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
427 | XChangeGC (disp, TGC, GCFillStyle, &gcv); |
410 | } |
428 | } |
411 | break; |
429 | break; |
412 | case 2: // arc |
430 | case 2: // arc |
413 | XDrawArc (d.display->display, d, TGC, |
431 | XDrawArc (disp, d, TGC, |
414 | x1 - W/2, y1 - H/2, W-1, H-1, |
432 | x1 - W/2, y1 - H/2, W-1, H-1, |
415 | (a - 1) * 90*64, (b - 1) * 90*64); |
433 | (a - 1) * 90*64, (b - 1) * 90*64); |
416 | break; |
434 | break; |
417 | } |
435 | } |
418 | } |
436 | } |
419 | } |
437 | } |
420 | #if ENABLE_COMBINING |
438 | #if ENABLE_COMBINING |
421 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
439 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
422 | { |
440 | { |
|
|
441 | text_t chrs[2]; |
|
|
442 | width = min (2, width); |
|
|
443 | chrs [1] = NOCHAR; |
|
|
444 | |
|
|
445 | *chrs = cc->c1; |
423 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
446 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
424 | f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg); |
447 | f1->draw (d, x, y, chrs, width, fg, bg); |
|
|
448 | |
425 | if (cc->c2 != NOCHAR) |
449 | if (cc->c2 != NOCHAR) |
426 | { |
450 | { |
|
|
451 | bool careful; |
|
|
452 | |
427 | // prefer font of first character, for no good reasons |
453 | // prefer font of first character, for no good reasons |
428 | bool careful; |
454 | *chrs = cc->c2; |
429 | rxvt_font *f2 = f1->has_char (cc->c2, 0, careful) |
455 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
430 | ? f1 |
456 | ? f1 |
431 | : (*fs)[fs->find_font (cc->c2)]; |
457 | : (*fs)[fs->find_font (cc->c2)]; |
432 | |
458 | |
433 | f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1); |
459 | f2->draw (d, x, y, chrs, width, fg, -1); |
434 | } |
460 | } |
435 | } |
461 | } |
436 | #endif |
462 | #endif |
437 | else |
463 | else |
438 | switch (t) |
464 | switch (t) |
… | |
… | |
441 | case ZERO_WIDTH_CHAR: |
467 | case ZERO_WIDTH_CHAR: |
442 | case NOCHAR: |
468 | case NOCHAR: |
443 | break; |
469 | break; |
444 | |
470 | |
445 | default: |
471 | default: |
446 | int w = 0; |
|
|
447 | while (len > 0 && *text == NOCHAR) |
|
|
448 | { |
|
|
449 | ++text; |
|
|
450 | --len; |
|
|
451 | w += r->TermWin.fwidth; |
|
|
452 | } |
|
|
453 | |
|
|
454 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
472 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
455 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
473 | fwidth - 4, r->fheight - 4); |
456 | x += w; |
|
|
457 | } |
474 | } |
458 | |
475 | |
459 | x += r->TermWin.fwidth; |
476 | x += fwidth; |
460 | } |
477 | } |
461 | } |
478 | } |
462 | |
479 | |
463 | ///////////////////////////////////////////////////////////////////////////// |
480 | ///////////////////////////////////////////////////////////////////////////// |
464 | |
481 | |
… | |
… | |
510 | bool |
527 | bool |
511 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
528 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
512 | { |
529 | { |
513 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
530 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
514 | p.height = height; |
531 | p.height = height; |
|
|
532 | p.ascent = rxvt_fontprop::unset; |
515 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
533 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
516 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
534 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
517 | |
535 | |
518 | return true; |
536 | return true; |
519 | } |
537 | } |
520 | |
538 | |
521 | bool |
539 | bool |
522 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
540 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
523 | { |
541 | { |
524 | unsigned long height; |
542 | unsigned long height; |
|
|
543 | |
|
|
544 | #if 0 |
525 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
545 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
526 | return false; |
546 | return false; |
|
|
547 | #else |
|
|
548 | height = f->ascent + f->descent; |
|
|
549 | #endif |
527 | |
550 | |
528 | unsigned long avgwidth; |
551 | unsigned long avgwidth; |
529 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
552 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
530 | avgwidth = 0; |
553 | avgwidth = 0; |
531 | |
554 | |
… | |
… | |
534 | |
557 | |
535 | set_properties (p, height, weight, slant, avgwidth); |
558 | set_properties (p, height, weight, slant, avgwidth); |
536 | |
559 | |
537 | free (weight); |
560 | free (weight); |
538 | free (slant); |
561 | free (slant); |
|
|
562 | |
|
|
563 | p.ascent = f->ascent; |
539 | |
564 | |
540 | return true; |
565 | return true; |
541 | } |
566 | } |
542 | |
567 | |
543 | bool |
568 | bool |
… | |
… | |
614 | } |
639 | } |
615 | |
640 | |
616 | bool |
641 | bool |
617 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
642 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
618 | { |
643 | { |
|
|
644 | Display *disp = DISPLAY; |
|
|
645 | |
619 | clear (); |
646 | clear (); |
620 | |
647 | |
621 | char field_str[64]; // enough for 128 bits |
648 | char field_str[64]; // enough for 128 bits |
622 | |
649 | |
623 | // first morph the font if required |
650 | // first morph the font if required |
… | |
… | |
626 | { |
653 | { |
627 | char fname[1024]; |
654 | char fname[1024]; |
628 | |
655 | |
629 | if (name[0] != '-') |
656 | if (name[0] != '-') |
630 | { |
657 | { |
631 | f = XLoadQueryFont (DISPLAY, name); |
658 | f = XLoadQueryFont (disp, name); |
632 | |
659 | |
633 | if (!f) |
660 | if (!f) |
634 | return false; |
661 | return false; |
635 | |
662 | |
636 | char *new_name = get_property (f, "FONT", name); |
663 | char *new_name = get_property (f, "FONT", name); |
… | |
… | |
638 | if (new_name) |
665 | if (new_name) |
639 | set_name (new_name); |
666 | set_name (new_name); |
640 | else |
667 | else |
641 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
668 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
642 | |
669 | |
643 | XFreeFont (DISPLAY, f); |
670 | XFreeFont (disp, f); |
644 | f = 0; |
671 | f = 0; |
645 | } |
672 | } |
646 | |
673 | |
647 | if (prop.weight != rxvt_fontprop::unset) |
674 | if (prop.weight != rxvt_fontprop::unset) |
648 | { |
675 | { |
… | |
… | |
659 | ? "r" : "i"); // TODO: handle "o"blique, too |
686 | ? "r" : "i"); // TODO: handle "o"blique, too |
660 | set_name (strdup (fname)); |
687 | set_name (strdup (fname)); |
661 | } |
688 | } |
662 | } |
689 | } |
663 | |
690 | |
|
|
691 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
|
|
692 | ? 0 : prop.height); |
|
|
693 | |
|
|
694 | struct font_weight { |
|
|
695 | char *name; |
|
|
696 | int diff; |
|
|
697 | |
|
|
698 | void clear () |
|
|
699 | { |
|
|
700 | name = 0; |
|
|
701 | diff = 0x7fffffff; |
|
|
702 | } |
|
|
703 | |
|
|
704 | font_weight () { clear (); } |
|
|
705 | ~font_weight () { free (name); } |
|
|
706 | }; |
|
|
707 | |
664 | char **list; |
708 | char **list; |
665 | int count; |
709 | int count; |
666 | list = XListFonts (DISPLAY, name, 1024, &count); |
710 | list = XListFonts (disp, name, 4000, &count); |
667 | |
711 | |
668 | set_name (0); |
712 | set_name (0); |
669 | |
713 | |
670 | if (!list) |
714 | if (!list) |
671 | return false; |
715 | return false; |
672 | |
716 | |
673 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
717 | font_weight *fonts = new font_weight[count]; |
674 | ? 0 : prop.height); |
|
|
675 | |
718 | |
676 | int bestdiff = 0x7fffffff; |
|
|
677 | for (int i = 0; i < count; i++) |
719 | for (int i = 0; i < count; i++) |
678 | { |
720 | { |
679 | rxvt_fontprop p; |
721 | rxvt_fontprop p; |
680 | char fname[1024]; |
722 | char fname[1024]; |
681 | |
723 | |
682 | int diff = 0; |
724 | int diff = 0; |
683 | |
725 | |
684 | if (replace_field (fname, list[i], 6, '0', field_str)) |
726 | if (replace_field (fname, list[i], 6, '0', field_str)) |
685 | diff += 10; // slightly penalize scalable fonts |
727 | diff += 10; // slightly penalize scalable fonts |
|
|
728 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
729 | diff += 300; // more heavily penalize what looks like scaled bitmap fotns |
686 | |
730 | |
687 | if (!set_properties (p, fname)) |
731 | if (!set_properties (p, fname)) |
688 | continue; |
732 | continue; |
689 | |
733 | |
690 | if (prop.height != rxvt_fontprop::unset |
734 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
694 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
738 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
695 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
739 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
696 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
740 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
697 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
741 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
698 | |
742 | |
699 | if (!name // compare against best found so far |
743 | fonts[i].name = strdup (fname); |
700 | || diff < bestdiff) |
744 | fonts[i].diff = diff; |
701 | { |
|
|
702 | set_name (strdup (fname)); |
|
|
703 | bestdiff = diff; |
|
|
704 | } |
|
|
705 | } |
745 | } |
706 | |
746 | |
707 | XFreeFontNames (list); |
747 | XFreeFontNames (list); |
708 | |
748 | |
709 | if (!name) |
749 | // this loop only iterates when the guessed font-size is too small |
710 | return false; |
750 | for (;;) |
|
|
751 | { |
|
|
752 | font_weight *best = fonts + count - 1; |
711 | |
753 | |
712 | f = XLoadQueryFont (DISPLAY, name); |
754 | for (font_weight *w = best; w-- > fonts; ) |
|
|
755 | if (w->diff <= best->diff) |
|
|
756 | best = w; |
|
|
757 | |
|
|
758 | if (!best->name |
|
|
759 | || !(f = XLoadQueryFont (disp, best->name))) |
|
|
760 | break; |
|
|
761 | |
|
|
762 | set_name (best->name); |
|
|
763 | best->clear (); |
|
|
764 | |
|
|
765 | ascent = f->ascent; |
|
|
766 | descent = f->descent; |
|
|
767 | height = ascent + descent; |
|
|
768 | |
|
|
769 | if (prop.height == rxvt_fontprop::unset |
|
|
770 | || height <= prop.height) |
|
|
771 | break; // font is ready for use |
|
|
772 | |
|
|
773 | // PIXEL_SIZE small enough, but real height too large |
|
|
774 | clear (); |
|
|
775 | } |
|
|
776 | |
|
|
777 | delete [] fonts; |
713 | |
778 | |
714 | if (!f) |
779 | if (!f) |
715 | return false; |
780 | return false; |
716 | |
781 | |
717 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
782 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
… | |
… | |
745 | if (cs == CS_UNICODE) |
810 | if (cs == CS_UNICODE) |
746 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
811 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
747 | |
812 | |
748 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
813 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
749 | enc2b = encm || f->max_char_or_byte2 > 255; |
814 | enc2b = encm || f->max_char_or_byte2 > 255; |
750 | |
|
|
751 | ascent = f->ascent; |
|
|
752 | descent = f->descent; |
|
|
753 | height = ascent + descent; |
|
|
754 | |
815 | |
755 | slow = false; |
816 | slow = false; |
756 | |
817 | |
757 | #if 1 // only used for slow detection, TODO optimize |
818 | #if 1 // only used for slow detection, TODO optimize |
758 | if (f->min_bounds.width == f->max_bounds.width) |
819 | if (f->min_bounds.width == f->max_bounds.width) |
… | |
… | |
797 | |
858 | |
798 | XCharStruct g; |
859 | XCharStruct g; |
799 | int dir_ret, asc_ret, des_ret; |
860 | int dir_ret, asc_ret, des_ret; |
800 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
861 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
801 | |
862 | |
802 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
863 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
803 | |
864 | |
804 | if (width < g.width) width = g.width; |
865 | if (width < g.width) width = g.width; |
805 | } |
866 | } |
806 | |
867 | |
807 | if (cs == CS_UNKNOWN) |
868 | if (cs == CS_UNKNOWN) |
… | |
… | |
882 | return true; |
943 | return true; |
883 | |
944 | |
884 | // check character against base font bounding box |
945 | // check character against base font bounding box |
885 | int w = xcs->width; |
946 | int w = xcs->width; |
886 | int wcw = wcwidth (unicode); |
947 | int wcw = wcwidth (unicode); |
887 | if (wcw > 0) w /= wcw; |
948 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
888 | |
949 | |
889 | careful = w > prop->width; |
950 | careful = w > prop->width; |
890 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
951 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
891 | return false; |
952 | return false; |
892 | |
953 | |
… | |
… | |
902 | // and it is a mess /. |
963 | // and it is a mess /. |
903 | // yet we are trying to be perfect /. |
964 | // yet we are trying to be perfect /. |
904 | // but the result still isn't perfect /. |
965 | // but the result still isn't perfect /. |
905 | |
966 | |
906 | bool slow = this->slow |
967 | bool slow = this->slow |
907 | || width != r->TermWin.fwidth |
968 | || width != r->fwidth |
908 | || height != r->TermWin.fheight; |
969 | || height != r->fheight; |
909 | |
970 | |
910 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
971 | int base = ascent; // sorry, incorrect: r->fbase; |
911 | |
972 | |
912 | XGCValues v; |
973 | XGCValues v; |
913 | v.foreground = r->pix_colors[fg]; |
974 | v.foreground = r->pix_colors[fg]; |
914 | v.font = f->fid; |
975 | v.font = f->fid; |
915 | |
976 | |
… | |
… | |
923 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
984 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
924 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
985 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
925 | } |
986 | } |
926 | else |
987 | else |
927 | { |
988 | { |
928 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
989 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
929 | |
990 | |
930 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
991 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
931 | |
992 | |
932 | if (slow) |
993 | if (slow) |
933 | { |
994 | { |
934 | do |
995 | do |
935 | { |
996 | { |
936 | if (xc->byte1 || xc->byte2) |
997 | if (xc->byte1 || xc->byte2) |
937 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
998 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
938 | |
999 | |
939 | x += r->TermWin.fwidth; |
1000 | x += r->fwidth; |
940 | xc++; len--; |
1001 | xc++; len--; |
941 | } |
1002 | } |
942 | while (len); |
1003 | while (len); |
943 | } |
1004 | } |
944 | else |
1005 | else |
… | |
… | |
955 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1016 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
956 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1017 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
957 | } |
1018 | } |
958 | else |
1019 | else |
959 | { |
1020 | { |
960 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1021 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
961 | |
1022 | |
962 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1023 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
963 | |
1024 | |
964 | if (slow) |
1025 | if (slow) |
965 | { |
1026 | { |
966 | do |
1027 | do |
967 | { |
1028 | { |
968 | if (*xc) |
1029 | if (*xc) |
969 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1030 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
970 | |
1031 | |
971 | x += r->TermWin.fwidth; |
1032 | x += r->fwidth; |
972 | xc++; len--; |
1033 | xc++; len--; |
973 | } |
1034 | } |
974 | while (len); |
1035 | while (len); |
975 | } |
1036 | } |
976 | else |
1037 | else |
… | |
… | |
1019 | |
1080 | |
1020 | FT_Face face = XftLockFace (f); |
1081 | FT_Face face = XftLockFace (f); |
1021 | |
1082 | |
1022 | p.width = width; |
1083 | p.width = width; |
1023 | p.height = height; |
1084 | p.height = height; |
|
|
1085 | p.ascent = ascent; |
1024 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1086 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1025 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1087 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1026 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1088 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1027 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1089 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1028 | |
1090 | |
… | |
… | |
1032 | } |
1094 | } |
1033 | |
1095 | |
1034 | bool |
1096 | bool |
1035 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1097 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1036 | { |
1098 | { |
|
|
1099 | Display *disp = DISPLAY; |
|
|
1100 | |
1037 | clear (); |
1101 | clear (); |
1038 | |
1102 | |
1039 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1103 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1040 | |
1104 | |
1041 | if (!p) |
1105 | if (!p) |
1042 | return false; |
1106 | return false; |
1043 | |
1107 | |
1044 | FcValue v; |
1108 | FcValue v; |
1045 | |
1109 | |
1046 | if (prop.height != rxvt_fontprop::unset |
1110 | if (prop.height != rxvt_fontprop::unset |
1047 | && FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch) |
1111 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
|
|
1112 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1048 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1113 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1049 | |
1114 | |
1050 | if (prop.weight != rxvt_fontprop::unset |
1115 | if (prop.weight != rxvt_fontprop::unset |
1051 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1116 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1052 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1117 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
… | |
… | |
1066 | |
1131 | |
1067 | // store generated name so iso14755 view gives better results |
1132 | // store generated name so iso14755 view gives better results |
1068 | set_name ((char *)FcNameUnparse (p)); |
1133 | set_name ((char *)FcNameUnparse (p)); |
1069 | |
1134 | |
1070 | XftResult result; |
1135 | XftResult result; |
1071 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1136 | FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); |
1072 | |
1137 | |
1073 | FcPatternDestroy (p); |
1138 | FcPatternDestroy (p); |
1074 | |
1139 | |
1075 | if (!match) |
1140 | if (!match) |
1076 | return false; |
1141 | return false; |
… | |
… | |
1078 | int ftheight = 0; |
1143 | int ftheight = 0; |
1079 | bool success = true; |
1144 | bool success = true; |
1080 | |
1145 | |
1081 | for (;;) |
1146 | for (;;) |
1082 | { |
1147 | { |
1083 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1148 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1084 | |
1149 | |
1085 | if (!f) |
1150 | if (!f) |
1086 | { |
1151 | { |
1087 | success = false; |
1152 | success = false; |
1088 | break; |
1153 | break; |
… | |
… | |
1097 | |
1162 | |
1098 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1163 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1099 | |
1164 | |
1100 | XftUnlockFace (f); |
1165 | XftUnlockFace (f); |
1101 | |
1166 | |
|
|
1167 | int glheight = height; |
|
|
1168 | |
1102 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1169 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1103 | { |
1170 | { |
1104 | FcChar16 ch = *t; |
1171 | FcChar16 ch = *t; |
1105 | |
1172 | |
1106 | if (cs != CS_UNICODE |
1173 | if (cs != CS_UNICODE |
… | |
… | |
1112 | bool careful; |
1179 | bool careful; |
1113 | if (!has_char (*t, &prop, careful)) |
1180 | if (!has_char (*t, &prop, careful)) |
1114 | continue; |
1181 | continue; |
1115 | |
1182 | |
1116 | XGlyphInfo g; |
1183 | XGlyphInfo g; |
1117 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1184 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1185 | |
|
|
1186 | g.width -= g.x; |
1118 | |
1187 | |
1119 | int wcw = wcwidth (ch); |
1188 | int wcw = wcwidth (ch); |
1120 | if (wcw > 0) g.width = g.width / wcw; |
1189 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1121 | |
1190 | |
1122 | if (width < g.width) width = g.width; |
1191 | if (width < g.width ) width = g.width; |
1123 | if (height < g.height) height = g.height; |
1192 | if (height < g.height ) height = g.height; |
|
|
1193 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1194 | } |
|
|
1195 | |
|
|
1196 | if (!width) |
|
|
1197 | { |
|
|
1198 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1199 | |
|
|
1200 | XftFontClose (disp, f); |
|
|
1201 | f = 0; |
|
|
1202 | |
|
|
1203 | success = false; |
|
|
1204 | break; |
1124 | } |
1205 | } |
1125 | |
1206 | |
1126 | if (prop.height == rxvt_fontprop::unset |
1207 | if (prop.height == rxvt_fontprop::unset |
1127 | || height <= prop.height |
1208 | || (height <= prop.height && glheight <= prop.height) |
1128 | || height <= 2 |
1209 | || height <= 2 |
1129 | || !scalable) |
1210 | || !scalable) |
1130 | break; |
1211 | break; |
1131 | |
1212 | |
1132 | if (ftheight) |
1213 | if (ftheight) |
… | |
… | |
1139 | ftheight -= height - prop.height; |
1220 | ftheight -= height - prop.height; |
1140 | } |
1221 | } |
1141 | else |
1222 | else |
1142 | ftheight = prop.height - 1; |
1223 | ftheight = prop.height - 1; |
1143 | |
1224 | |
1144 | XftFontClose (DISPLAY, f); |
1225 | XftFontClose (disp, f); |
1145 | FcPatternDel (match, FC_PIXEL_SIZE); |
1226 | FcPatternDel (match, FC_PIXEL_SIZE); |
1146 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1227 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1147 | } |
1228 | } |
1148 | |
1229 | |
1149 | FcPatternDestroy (match); |
1230 | FcPatternDestroy (match); |
1150 | |
1231 | |
1151 | #if 0 // do it per-character |
1232 | #if 0 // do it per-character |
… | |
… | |
1173 | // check character against base font bounding box |
1254 | // check character against base font bounding box |
1174 | FcChar32 ch = unicode; |
1255 | FcChar32 ch = unicode; |
1175 | XGlyphInfo g; |
1256 | XGlyphInfo g; |
1176 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1257 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1177 | |
1258 | |
1178 | int w = g.width; |
1259 | int w = g.width - g.x; |
1179 | int wcw = wcwidth (unicode); |
1260 | int wcw = wcwidth (unicode); |
1180 | if (wcw > 0) w /= wcw; |
1261 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1181 | |
1262 | |
1182 | careful = w > prop->width; |
1263 | careful = w > prop->width; |
1183 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1264 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1184 | return false; |
1265 | return false; |
1185 | |
1266 | |
… | |
… | |
1189 | void |
1270 | void |
1190 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1271 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1191 | const text_t *text, int len, |
1272 | const text_t *text, int len, |
1192 | int fg, int bg) |
1273 | int fg, int bg) |
1193 | { |
1274 | { |
1194 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1275 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1195 | |
1276 | |
1196 | int base = ascent; // should be fbase, but that is incorrect |
1277 | int base = ascent; // should be fbase, but that is incorrect |
1197 | |
1278 | |
1198 | XGlyphInfo extents; |
1279 | XGlyphInfo extents; |
1199 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1280 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1200 | FcChar32 *ep = enc; |
1281 | FcChar32 *ep = enc; |
1201 | int ewidth = 0; |
1282 | int ewidth = 0; |
1202 | int xoff = 0; |
|
|
1203 | |
1283 | |
1204 | while (len) |
1284 | while (len) |
1205 | { |
1285 | { |
1206 | int cwidth = r->TermWin.fwidth; |
1286 | int cwidth = r->fwidth; |
1207 | FcChar32 fc = *text++; len--; |
1287 | FcChar32 fc = *text++; len--; |
1208 | FT_UInt gl; |
|
|
1209 | |
1288 | |
1210 | while (len && *text == NOCHAR) |
1289 | while (len && *text == NOCHAR) |
1211 | text++, len--, cwidth += r->TermWin.fwidth; |
1290 | text++, len--, cwidth += r->fwidth; |
1212 | |
1291 | |
1213 | gl = XftCharIndex (d.display->display, f, fc); |
|
|
1214 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1215 | |
|
|
1216 | if (extents.xOff != cwidth && ep != enc) |
|
|
1217 | { |
|
|
1218 | if (xoff > ewidth) xoff = ewidth; |
|
|
1219 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1220 | x + (ewidth - xoff >> 1), |
|
|
1221 | y + base, enc, ep - enc); |
|
|
1222 | x += ewidth; |
|
|
1223 | |
|
|
1224 | ep = enc; |
|
|
1225 | ewidth = 0; |
|
|
1226 | xoff = 0; |
|
|
1227 | } |
|
|
1228 | |
|
|
1229 | if (fc == ' ' && ep == enc) // skip leading spaces |
1292 | if (fc == ' ' && ep == enc) // skip leading spaces |
1230 | { |
|
|
1231 | x += cwidth; |
1293 | x += cwidth; |
1232 | continue; |
|
|
1233 | } |
|
|
1234 | |
|
|
1235 | else |
1294 | else |
1236 | { |
1295 | { |
|
|
1296 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
|
|
1297 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1298 | |
|
|
1299 | if (extents.xOff != cwidth) |
|
|
1300 | { |
|
|
1301 | if (ewidth) |
|
|
1302 | { |
|
|
1303 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1304 | x, y + base, enc, ep - enc); |
|
|
1305 | x += ewidth; |
|
|
1306 | |
|
|
1307 | ep = enc; |
|
|
1308 | ewidth = 0; |
|
|
1309 | } |
|
|
1310 | |
|
|
1311 | if (extents.xOff > cwidth) |
|
|
1312 | extents.xOff = cwidth; |
|
|
1313 | |
|
|
1314 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1315 | x + (cwidth - extents.xOff >> 1), |
|
|
1316 | y + base, &gl, 1); |
|
|
1317 | x += cwidth; |
|
|
1318 | } |
|
|
1319 | else |
|
|
1320 | { |
1237 | *ep++ = gl; |
1321 | *ep++ = gl; |
1238 | ewidth += cwidth; |
1322 | ewidth += cwidth; |
1239 | xoff += extents.xOff; |
1323 | } |
1240 | } |
1324 | } |
1241 | } |
1325 | } |
1242 | |
1326 | |
1243 | if (ep != enc) |
1327 | if (ep != enc) |
1244 | { |
|
|
1245 | if (xoff > ewidth) xoff = ewidth; |
|
|
1246 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1328 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1247 | x + (ewidth - xoff >> 1), |
|
|
1248 | y + base, enc, ep - enc); |
1329 | x, y + base, enc, ep - enc); |
1249 | } |
|
|
1250 | } |
1330 | } |
1251 | #endif |
1331 | #endif |
1252 | |
1332 | |
1253 | ///////////////////////////////////////////////////////////////////////////// |
1333 | ///////////////////////////////////////////////////////////////////////////// |
1254 | |
1334 | |
1255 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1335 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1256 | : r (r), fontdesc (0) |
1336 | : fontdesc (0), r (r) |
1257 | { |
1337 | { |
1258 | clear (); |
1338 | clear (); |
1259 | } |
1339 | } |
1260 | |
1340 | |
1261 | rxvt_fontset::~rxvt_fontset () |
1341 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1264 | } |
1344 | } |
1265 | |
1345 | |
1266 | void |
1346 | void |
1267 | rxvt_fontset::clear () |
1347 | rxvt_fontset::clear () |
1268 | { |
1348 | { |
|
|
1349 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
|
|
1350 | = rxvt_fontprop::unset; |
|
|
1351 | |
1269 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1352 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1270 | FONT_UNREF (*i); |
1353 | FONT_UNREF (*i); |
1271 | |
1354 | |
1272 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1355 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1273 | delete *p; |
1356 | delete *p; |
… | |
… | |
1323 | char buf[512]; |
1406 | char buf[512]; |
1324 | const char *end; |
1407 | const char *end; |
1325 | |
1408 | |
1326 | do |
1409 | do |
1327 | { |
1410 | { |
1328 | while (*desc <= ' ') desc++; |
1411 | while (*desc && *desc <= ' ') |
|
|
1412 | desc++; |
1329 | |
1413 | |
1330 | codeset cs = CS_UNICODE; |
1414 | codeset cs = CS_UNICODE; |
1331 | |
1415 | |
1332 | if (*desc == '[') |
1416 | if (*desc == '[') |
1333 | { |
1417 | { |
… | |
… | |
1393 | |
1477 | |
1394 | return true; |
1478 | return true; |
1395 | } |
1479 | } |
1396 | |
1480 | |
1397 | bool |
1481 | bool |
1398 | rxvt_fontset::populate (const char *desc, const rxvt_fontprop &prop) |
1482 | rxvt_fontset::populate (const char *desc) |
1399 | { |
1483 | { |
1400 | clear (); |
1484 | clear (); |
1401 | |
1485 | |
1402 | fontdesc = strdup (desc); |
1486 | fontdesc = strdup (desc); |
1403 | |
1487 | |
1404 | fonts.push_back (new_font (0, CS_UNICODE)); |
1488 | fonts.push_back (new_font (0, CS_UNICODE)); |
1405 | realize_font (0); |
1489 | realize_font (0); |
1406 | |
|
|
1407 | this->prop = prop; |
|
|
1408 | |
1490 | |
1409 | add_fonts (desc); |
1491 | add_fonts (desc); |
1410 | |
1492 | |
1411 | return true; |
1493 | return true; |
1412 | } |
1494 | } |
… | |
… | |
1445 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1527 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1446 | goto next_font; |
1528 | goto next_font; |
1447 | |
1529 | |
1448 | if (!realize_font (i)) |
1530 | if (!realize_font (i)) |
1449 | goto next_font; |
1531 | goto next_font; |
|
|
1532 | |
|
|
1533 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1534 | max_it (f->ascent, prop.ascent); |
1450 | } |
1535 | } |
1451 | |
1536 | |
1452 | if (f->cs == CS_UNKNOWN) |
1537 | if (f->cs == CS_UNKNOWN) |
1453 | goto next_font; |
1538 | goto next_font; |
1454 | |
1539 | |
… | |
… | |
1493 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1578 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1494 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1579 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1495 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1580 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1496 | |
1581 | |
1497 | XftResult result; |
1582 | XftResult result; |
1498 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1583 | FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); |
1499 | |
1584 | |
1500 | FcPatternDestroy (p); |
1585 | FcPatternDestroy (p); |
1501 | |
1586 | |
1502 | if (match) |
1587 | if (match) |
1503 | { |
1588 | { |