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; |
… | |
… | |
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 | ! 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 | |
|
|
351 | // support double-width (but not more) graphics chars |
|
|
352 | // TODO: do this outside the if/elsif.. statement for all cases |
|
|
353 | if (len && *text == NOCHAR) |
|
|
354 | W += r->TermWin.fwidth; |
|
|
355 | |
368 | |
356 | int x_[16]; |
369 | int x_[16]; |
357 | int y_[16]; |
370 | int y_[16]; |
358 | |
371 | |
359 | for (int i = 0; i <= 8; i++) |
372 | for (int i = 0; i <= 8; i++) |
… | |
… | |
367 | |
380 | |
368 | XGCValues gcv; |
381 | XGCValues gcv; |
369 | |
382 | |
370 | gcv.cap_style = CapButt; |
383 | gcv.cap_style = CapButt; |
371 | gcv.line_width = 0; |
384 | gcv.line_width = 0; |
372 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
385 | XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); |
373 | |
386 | |
374 | while (a < b) |
387 | while (a < b) |
375 | { |
388 | { |
376 | uint32_t command = *a++; |
389 | uint32_t command = *a++; |
377 | |
390 | |
… | |
… | |
384 | int y2 = y_[(command >> 0) & 15]; |
397 | int y2 = y_[(command >> 0) & 15]; |
385 | |
398 | |
386 | switch (op) |
399 | switch (op) |
387 | { |
400 | { |
388 | case 0: // line |
401 | case 0: // line |
389 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
402 | XDrawLine (disp, d, TGC, x1, y1, x2, y2); |
390 | break; |
403 | break; |
391 | |
404 | |
392 | case 1: // rectangle, possibly stippled |
405 | case 1: // rectangle, possibly stippled |
393 | if (a) |
406 | if (a) |
394 | { |
407 | { |
395 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
408 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
396 | |
409 | |
397 | gcv.fill_style = FillStippled; |
410 | gcv.fill_style = FillStippled; |
398 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
411 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
399 | gcv.ts_x_origin = x; |
412 | gcv.ts_x_origin = x; |
400 | gcv.ts_y_origin = y; |
413 | gcv.ts_y_origin = y; |
401 | |
414 | |
402 | XChangeGC (d.display->display, TGC, |
415 | XChangeGC (disp, TGC, |
403 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
416 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
404 | &gcv); |
417 | &gcv); |
405 | } |
418 | } |
406 | |
419 | |
407 | 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); |
408 | |
421 | |
409 | if (a) |
422 | if (a) |
410 | { |
423 | { |
411 | XFreePixmap (d.display->display, gcv.stipple); |
424 | XFreePixmap (disp, gcv.stipple); |
412 | gcv.stipple = 0; |
425 | gcv.stipple = 0; |
413 | gcv.fill_style = FillSolid; |
426 | gcv.fill_style = FillSolid; |
414 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
427 | XChangeGC (disp, TGC, GCFillStyle, &gcv); |
415 | } |
428 | } |
416 | break; |
429 | break; |
417 | case 2: // arc |
430 | case 2: // arc |
418 | XDrawArc (d.display->display, d, TGC, |
431 | XDrawArc (disp, d, TGC, |
419 | x1 - W/2, y1 - H/2, W-1, H-1, |
432 | x1 - W/2, y1 - H/2, W-1, H-1, |
420 | (a - 1) * 90*64, (b - 1) * 90*64); |
433 | (a - 1) * 90*64, (b - 1) * 90*64); |
421 | break; |
434 | break; |
422 | } |
435 | } |
423 | } |
436 | } |
424 | } |
437 | } |
425 | #if ENABLE_COMBINING |
438 | #if ENABLE_COMBINING |
426 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
439 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
427 | { |
440 | { |
428 | text_t c2[2]; |
441 | text_t chrs[2]; |
429 | int len2 = 1; |
442 | width = min (2, width); |
430 | |
443 | chrs [1] = NOCHAR; |
431 | // support double-width (but not more) combining characters |
|
|
432 | if (len && *text == NOCHAR) |
|
|
433 | { |
|
|
434 | c2[1] = *text; // not text++ to get correct x-width |
|
|
435 | len2++; |
|
|
436 | } |
|
|
437 | |
444 | |
438 | c2[0] = cc->c1; |
445 | *chrs = cc->c1; |
439 | rxvt_font *f1 = (*fs)[fs->find_font (c2[0])]; |
446 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
440 | f1->draw (d, x, y, c2, len2, fg, bg); |
447 | f1->draw (d, x, y, chrs, width, fg, bg); |
441 | |
448 | |
442 | if (cc->c2 != NOCHAR) |
449 | if (cc->c2 != NOCHAR) |
443 | { |
450 | { |
444 | bool careful; |
451 | bool careful; |
445 | |
452 | |
446 | // prefer font of first character, for no good reasons |
453 | // prefer font of first character, for no good reasons |
447 | c2[0] = cc->c2; |
454 | *chrs = cc->c2; |
448 | rxvt_font *f2 = (f1->has_char (c2[0], 0, careful) && !careful) |
455 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
449 | ? f1 |
456 | ? f1 |
450 | : (*fs)[fs->find_font (c2[0])]; |
457 | : (*fs)[fs->find_font (cc->c2)]; |
451 | |
458 | |
452 | f2->draw (d, x, y, c2, len2, fg, -1); |
459 | f2->draw (d, x, y, chrs, width, fg, -1); |
453 | } |
460 | } |
454 | } |
461 | } |
455 | #endif |
462 | #endif |
456 | else |
463 | else |
457 | switch (t) |
464 | switch (t) |
… | |
… | |
460 | case ZERO_WIDTH_CHAR: |
467 | case ZERO_WIDTH_CHAR: |
461 | case NOCHAR: |
468 | case NOCHAR: |
462 | break; |
469 | break; |
463 | |
470 | |
464 | default: |
471 | default: |
465 | int w = 0; |
|
|
466 | while (len > 0 && *text == NOCHAR) |
|
|
467 | { |
|
|
468 | ++text; |
|
|
469 | --len; |
|
|
470 | w += r->TermWin.fwidth; |
|
|
471 | } |
|
|
472 | |
|
|
473 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
472 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
474 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
473 | fwidth - 4, r->fheight - 4); |
475 | x += w; |
|
|
476 | } |
474 | } |
477 | |
475 | |
478 | x += r->TermWin.fwidth; |
476 | x += fwidth; |
479 | } |
477 | } |
480 | } |
478 | } |
481 | |
479 | |
482 | ///////////////////////////////////////////////////////////////////////////// |
480 | ///////////////////////////////////////////////////////////////////////////// |
483 | |
481 | |
… | |
… | |
529 | bool |
527 | bool |
530 | 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) |
531 | { |
529 | { |
532 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
530 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
533 | p.height = height; |
531 | p.height = height; |
|
|
532 | p.ascent = rxvt_fontprop::unset; |
534 | 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; |
535 | 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; |
536 | |
535 | |
537 | return true; |
536 | return true; |
538 | } |
537 | } |
539 | |
538 | |
540 | bool |
539 | bool |
541 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
540 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
542 | { |
541 | { |
543 | unsigned long height; |
542 | unsigned long height; |
|
|
543 | |
|
|
544 | #if 0 |
544 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
545 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
545 | return false; |
546 | return false; |
|
|
547 | #else |
|
|
548 | height = f->ascent + f->descent; |
|
|
549 | #endif |
546 | |
550 | |
547 | unsigned long avgwidth; |
551 | unsigned long avgwidth; |
548 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
552 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
549 | avgwidth = 0; |
553 | avgwidth = 0; |
550 | |
554 | |
… | |
… | |
553 | |
557 | |
554 | set_properties (p, height, weight, slant, avgwidth); |
558 | set_properties (p, height, weight, slant, avgwidth); |
555 | |
559 | |
556 | free (weight); |
560 | free (weight); |
557 | free (slant); |
561 | free (slant); |
|
|
562 | |
|
|
563 | p.ascent = f->ascent; |
558 | |
564 | |
559 | return true; |
565 | return true; |
560 | } |
566 | } |
561 | |
567 | |
562 | bool |
568 | bool |
… | |
… | |
633 | } |
639 | } |
634 | |
640 | |
635 | bool |
641 | bool |
636 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
642 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
637 | { |
643 | { |
|
|
644 | Display *disp = DISPLAY; |
|
|
645 | |
638 | clear (); |
646 | clear (); |
639 | |
647 | |
640 | char field_str[64]; // enough for 128 bits |
648 | char field_str[64]; // enough for 128 bits |
641 | |
649 | |
642 | // first morph the font if required |
650 | // first morph the font if required |
… | |
… | |
645 | { |
653 | { |
646 | char fname[1024]; |
654 | char fname[1024]; |
647 | |
655 | |
648 | if (name[0] != '-') |
656 | if (name[0] != '-') |
649 | { |
657 | { |
650 | f = XLoadQueryFont (DISPLAY, name); |
658 | f = XLoadQueryFont (disp, name); |
651 | |
659 | |
652 | if (!f) |
660 | if (!f) |
653 | return false; |
661 | return false; |
654 | |
662 | |
655 | char *new_name = get_property (f, "FONT", name); |
663 | char *new_name = get_property (f, "FONT", name); |
… | |
… | |
657 | if (new_name) |
665 | if (new_name) |
658 | set_name (new_name); |
666 | set_name (new_name); |
659 | else |
667 | else |
660 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
668 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
661 | |
669 | |
662 | XFreeFont (DISPLAY, f); |
670 | XFreeFont (disp, f); |
663 | f = 0; |
671 | f = 0; |
664 | } |
672 | } |
665 | |
673 | |
666 | if (prop.weight != rxvt_fontprop::unset) |
674 | if (prop.weight != rxvt_fontprop::unset) |
667 | { |
675 | { |
… | |
… | |
678 | ? "r" : "i"); // TODO: handle "o"blique, too |
686 | ? "r" : "i"); // TODO: handle "o"blique, too |
679 | set_name (strdup (fname)); |
687 | set_name (strdup (fname)); |
680 | } |
688 | } |
681 | } |
689 | } |
682 | |
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 | |
683 | char **list; |
708 | char **list; |
684 | int count; |
709 | int count; |
685 | list = XListFonts (DISPLAY, name, 1024, &count); |
710 | list = XListFonts (disp, name, 4000, &count); |
686 | |
711 | |
687 | set_name (0); |
712 | set_name (0); |
688 | |
713 | |
689 | if (!list) |
714 | if (!list) |
690 | return false; |
715 | return false; |
691 | |
716 | |
692 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
717 | font_weight *fonts = new font_weight[count]; |
693 | ? 0 : prop.height); |
|
|
694 | |
718 | |
695 | int bestdiff = 0x7fffffff; |
|
|
696 | for (int i = 0; i < count; i++) |
719 | for (int i = 0; i < count; i++) |
697 | { |
720 | { |
698 | rxvt_fontprop p; |
721 | rxvt_fontprop p; |
699 | char fname[1024]; |
722 | char fname[1024]; |
700 | |
723 | |
701 | int diff = 0; |
724 | int diff = 0; |
702 | |
725 | |
703 | if (replace_field (fname, list[i], 6, '0', field_str)) |
726 | if (replace_field (fname, list[i], 6, '0', field_str)) |
704 | 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 |
705 | |
730 | |
706 | if (!set_properties (p, fname)) |
731 | if (!set_properties (p, fname)) |
707 | continue; |
732 | continue; |
708 | |
733 | |
709 | if (prop.height != rxvt_fontprop::unset |
734 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
713 | 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; |
714 | 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); |
715 | 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); |
716 | //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); |
717 | |
742 | |
718 | if (!name // compare against best found so far |
743 | fonts[i].name = strdup (fname); |
719 | || diff < bestdiff) |
744 | fonts[i].diff = diff; |
720 | { |
|
|
721 | set_name (strdup (fname)); |
|
|
722 | bestdiff = diff; |
|
|
723 | } |
|
|
724 | } |
745 | } |
725 | |
746 | |
726 | XFreeFontNames (list); |
747 | XFreeFontNames (list); |
727 | |
748 | |
728 | if (!name) |
749 | // this loop only iterates when the guessed font-size is too small |
729 | return false; |
750 | for (;;) |
|
|
751 | { |
|
|
752 | font_weight *best = fonts + count - 1; |
730 | |
753 | |
731 | 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; |
732 | |
778 | |
733 | if (!f) |
779 | if (!f) |
734 | return false; |
780 | return false; |
735 | |
781 | |
736 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
782 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
… | |
… | |
764 | if (cs == CS_UNICODE) |
810 | if (cs == CS_UNICODE) |
765 | 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 |
766 | |
812 | |
767 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
813 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
768 | enc2b = encm || f->max_char_or_byte2 > 255; |
814 | enc2b = encm || f->max_char_or_byte2 > 255; |
769 | |
|
|
770 | ascent = f->ascent; |
|
|
771 | descent = f->descent; |
|
|
772 | height = ascent + descent; |
|
|
773 | |
815 | |
774 | slow = false; |
816 | slow = false; |
775 | |
817 | |
776 | #if 1 // only used for slow detection, TODO optimize |
818 | #if 1 // only used for slow detection, TODO optimize |
777 | if (f->min_bounds.width == f->max_bounds.width) |
819 | if (f->min_bounds.width == f->max_bounds.width) |
… | |
… | |
816 | |
858 | |
817 | XCharStruct g; |
859 | XCharStruct g; |
818 | int dir_ret, asc_ret, des_ret; |
860 | int dir_ret, asc_ret, des_ret; |
819 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
861 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
820 | |
862 | |
821 | 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; |
822 | |
864 | |
823 | if (width < g.width) width = g.width; |
865 | if (width < g.width) width = g.width; |
824 | } |
866 | } |
825 | |
867 | |
826 | if (cs == CS_UNKNOWN) |
868 | if (cs == CS_UNKNOWN) |
… | |
… | |
901 | return true; |
943 | return true; |
902 | |
944 | |
903 | // check character against base font bounding box |
945 | // check character against base font bounding box |
904 | int w = xcs->width; |
946 | int w = xcs->width; |
905 | int wcw = wcwidth (unicode); |
947 | int wcw = wcwidth (unicode); |
906 | if (wcw > 0) w /= wcw; |
948 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
907 | |
949 | |
908 | careful = w > prop->width; |
950 | careful = w > prop->width; |
909 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
951 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
910 | return false; |
952 | return false; |
911 | |
953 | |
… | |
… | |
921 | // and it is a mess /. |
963 | // and it is a mess /. |
922 | // yet we are trying to be perfect /. |
964 | // yet we are trying to be perfect /. |
923 | // but the result still isn't perfect /. |
965 | // but the result still isn't perfect /. |
924 | |
966 | |
925 | bool slow = this->slow |
967 | bool slow = this->slow |
926 | || width != r->TermWin.fwidth |
968 | || width != r->fwidth |
927 | || height != r->TermWin.fheight; |
969 | || height != r->fheight; |
928 | |
970 | |
929 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
971 | int base = ascent; // sorry, incorrect: r->fbase; |
930 | |
972 | |
931 | XGCValues v; |
973 | XGCValues v; |
932 | v.foreground = r->pix_colors[fg]; |
974 | v.foreground = r->pix_colors[fg]; |
933 | v.font = f->fid; |
975 | v.font = f->fid; |
934 | |
976 | |
… | |
… | |
942 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
984 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
943 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
985 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
944 | } |
986 | } |
945 | else |
987 | else |
946 | { |
988 | { |
947 | 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); |
948 | |
990 | |
949 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
991 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
950 | |
992 | |
951 | if (slow) |
993 | if (slow) |
952 | { |
994 | { |
953 | do |
995 | do |
954 | { |
996 | { |
955 | if (xc->byte1 || xc->byte2) |
997 | if (xc->byte1 || xc->byte2) |
956 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
998 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
957 | |
999 | |
958 | x += r->TermWin.fwidth; |
1000 | x += r->fwidth; |
959 | xc++; len--; |
1001 | xc++; len--; |
960 | } |
1002 | } |
961 | while (len); |
1003 | while (len); |
962 | } |
1004 | } |
963 | else |
1005 | else |
… | |
… | |
974 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1016 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
975 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1017 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
976 | } |
1018 | } |
977 | else |
1019 | else |
978 | { |
1020 | { |
979 | 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); |
980 | |
1022 | |
981 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1023 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
982 | |
1024 | |
983 | if (slow) |
1025 | if (slow) |
984 | { |
1026 | { |
985 | do |
1027 | do |
986 | { |
1028 | { |
987 | if (*xc) |
1029 | if (*xc) |
988 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1030 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
989 | |
1031 | |
990 | x += r->TermWin.fwidth; |
1032 | x += r->fwidth; |
991 | xc++; len--; |
1033 | xc++; len--; |
992 | } |
1034 | } |
993 | while (len); |
1035 | while (len); |
994 | } |
1036 | } |
995 | else |
1037 | else |
… | |
… | |
1038 | |
1080 | |
1039 | FT_Face face = XftLockFace (f); |
1081 | FT_Face face = XftLockFace (f); |
1040 | |
1082 | |
1041 | p.width = width; |
1083 | p.width = width; |
1042 | p.height = height; |
1084 | p.height = height; |
|
|
1085 | p.ascent = ascent; |
1043 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1086 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1044 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1087 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1045 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1088 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1046 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1089 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1047 | |
1090 | |
… | |
… | |
1051 | } |
1094 | } |
1052 | |
1095 | |
1053 | bool |
1096 | bool |
1054 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1097 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1055 | { |
1098 | { |
|
|
1099 | Display *disp = DISPLAY; |
|
|
1100 | |
1056 | clear (); |
1101 | clear (); |
1057 | |
1102 | |
1058 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1103 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1059 | |
1104 | |
1060 | if (!p) |
1105 | if (!p) |
1061 | return false; |
1106 | return false; |
1062 | |
1107 | |
1063 | FcValue v; |
1108 | FcValue v; |
1064 | |
1109 | |
1065 | if (prop.height != rxvt_fontprop::unset |
1110 | if (prop.height != rxvt_fontprop::unset |
1066 | || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1111 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1067 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1112 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1068 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1113 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1069 | |
1114 | |
1070 | if (prop.weight != rxvt_fontprop::unset |
1115 | if (prop.weight != rxvt_fontprop::unset |
1071 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1116 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
… | |
… | |
1086 | |
1131 | |
1087 | // store generated name so iso14755 view gives better results |
1132 | // store generated name so iso14755 view gives better results |
1088 | set_name ((char *)FcNameUnparse (p)); |
1133 | set_name ((char *)FcNameUnparse (p)); |
1089 | |
1134 | |
1090 | XftResult result; |
1135 | XftResult result; |
1091 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1136 | FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); |
1092 | |
1137 | |
1093 | FcPatternDestroy (p); |
1138 | FcPatternDestroy (p); |
1094 | |
1139 | |
1095 | if (!match) |
1140 | if (!match) |
1096 | return false; |
1141 | return false; |
… | |
… | |
1098 | int ftheight = 0; |
1143 | int ftheight = 0; |
1099 | bool success = true; |
1144 | bool success = true; |
1100 | |
1145 | |
1101 | for (;;) |
1146 | for (;;) |
1102 | { |
1147 | { |
1103 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1148 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1104 | |
1149 | |
1105 | if (!f) |
1150 | if (!f) |
1106 | { |
1151 | { |
1107 | success = false; |
1152 | success = false; |
1108 | break; |
1153 | break; |
… | |
… | |
1117 | |
1162 | |
1118 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1163 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1119 | |
1164 | |
1120 | XftUnlockFace (f); |
1165 | XftUnlockFace (f); |
1121 | |
1166 | |
|
|
1167 | int glheight = height; |
|
|
1168 | |
1122 | 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; ) |
1123 | { |
1170 | { |
1124 | FcChar16 ch = *t; |
1171 | FcChar16 ch = *t; |
1125 | |
1172 | |
1126 | if (cs != CS_UNICODE |
1173 | if (cs != CS_UNICODE |
… | |
… | |
1132 | bool careful; |
1179 | bool careful; |
1133 | if (!has_char (*t, &prop, careful)) |
1180 | if (!has_char (*t, &prop, careful)) |
1134 | continue; |
1181 | continue; |
1135 | |
1182 | |
1136 | XGlyphInfo g; |
1183 | XGlyphInfo g; |
1137 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1184 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1185 | |
|
|
1186 | g.width -= g.x; |
1138 | |
1187 | |
1139 | int wcw = wcwidth (ch); |
1188 | int wcw = wcwidth (ch); |
1140 | if (wcw > 0) g.width = g.width / wcw; |
1189 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1141 | |
1190 | |
1142 | if (width < g.width) width = g.width; |
1191 | if (width < g.width ) width = g.width; |
1143 | 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; |
1144 | } |
1205 | } |
1145 | |
1206 | |
1146 | if (prop.height == rxvt_fontprop::unset |
1207 | if (prop.height == rxvt_fontprop::unset |
1147 | || height <= prop.height |
1208 | || (height <= prop.height && glheight <= prop.height) |
1148 | || height <= 2 |
1209 | || height <= 2 |
1149 | || !scalable) |
1210 | || !scalable) |
1150 | break; |
1211 | break; |
1151 | |
1212 | |
1152 | if (ftheight) |
1213 | if (ftheight) |
… | |
… | |
1159 | ftheight -= height - prop.height; |
1220 | ftheight -= height - prop.height; |
1160 | } |
1221 | } |
1161 | else |
1222 | else |
1162 | ftheight = prop.height - 1; |
1223 | ftheight = prop.height - 1; |
1163 | |
1224 | |
1164 | XftFontClose (DISPLAY, f); |
1225 | XftFontClose (disp, f); |
1165 | FcPatternDel (match, FC_PIXEL_SIZE); |
1226 | FcPatternDel (match, FC_PIXEL_SIZE); |
1166 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1227 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1167 | } |
1228 | } |
1168 | |
1229 | |
1169 | FcPatternDestroy (match); |
1230 | FcPatternDestroy (match); |
1170 | |
1231 | |
1171 | #if 0 // do it per-character |
1232 | #if 0 // do it per-character |
… | |
… | |
1193 | // check character against base font bounding box |
1254 | // check character against base font bounding box |
1194 | FcChar32 ch = unicode; |
1255 | FcChar32 ch = unicode; |
1195 | XGlyphInfo g; |
1256 | XGlyphInfo g; |
1196 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1257 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1197 | |
1258 | |
1198 | int w = g.width; |
1259 | int w = g.width - g.x; |
1199 | int wcw = wcwidth (unicode); |
1260 | int wcw = wcwidth (unicode); |
1200 | if (wcw > 0) w /= wcw; |
1261 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1201 | |
1262 | |
1202 | careful = w > prop->width; |
1263 | careful = w > prop->width; |
1203 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1264 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1204 | return false; |
1265 | return false; |
1205 | |
1266 | |
… | |
… | |
1209 | void |
1270 | void |
1210 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1271 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1211 | const text_t *text, int len, |
1272 | const text_t *text, int len, |
1212 | int fg, int bg) |
1273 | int fg, int bg) |
1213 | { |
1274 | { |
1214 | 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); |
1215 | |
1276 | |
1216 | int base = ascent; // should be fbase, but that is incorrect |
1277 | int base = ascent; // should be fbase, but that is incorrect |
1217 | |
1278 | |
1218 | XGlyphInfo extents; |
1279 | XGlyphInfo extents; |
1219 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1280 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1220 | FcChar32 *ep = enc; |
1281 | FcChar32 *ep = enc; |
1221 | int ewidth = 0; |
1282 | int ewidth = 0; |
1222 | int xoff = 0; |
|
|
1223 | |
1283 | |
1224 | while (len) |
1284 | while (len) |
1225 | { |
1285 | { |
1226 | int cwidth = r->TermWin.fwidth; |
1286 | int cwidth = r->fwidth; |
1227 | FcChar32 fc = *text++; len--; |
1287 | FcChar32 fc = *text++; len--; |
1228 | FT_UInt gl; |
|
|
1229 | |
1288 | |
1230 | while (len && *text == NOCHAR) |
1289 | while (len && *text == NOCHAR) |
1231 | text++, len--, cwidth += r->TermWin.fwidth; |
1290 | text++, len--, cwidth += r->fwidth; |
1232 | |
1291 | |
1233 | gl = XftCharIndex (d.display->display, f, fc); |
|
|
1234 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1235 | |
|
|
1236 | if (extents.xOff != cwidth && ep != enc) |
|
|
1237 | { |
|
|
1238 | if (xoff > ewidth) xoff = ewidth; |
|
|
1239 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1240 | x + (ewidth - xoff >> 1), |
|
|
1241 | y + base, enc, ep - enc); |
|
|
1242 | x += ewidth; |
|
|
1243 | |
|
|
1244 | ep = enc; |
|
|
1245 | ewidth = 0; |
|
|
1246 | xoff = 0; |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | if (fc == ' ' && ep == enc) // skip leading spaces |
1292 | if (fc == ' ' && ep == enc) // skip leading spaces |
1250 | { |
|
|
1251 | x += cwidth; |
1293 | x += cwidth; |
1252 | continue; |
|
|
1253 | } |
|
|
1254 | |
|
|
1255 | else |
1294 | else |
1256 | { |
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 | { |
1257 | *ep++ = gl; |
1321 | *ep++ = gl; |
1258 | ewidth += cwidth; |
1322 | ewidth += cwidth; |
1259 | xoff += extents.xOff; |
1323 | } |
1260 | } |
1324 | } |
1261 | } |
1325 | } |
1262 | |
1326 | |
1263 | if (ep != enc) |
1327 | if (ep != enc) |
1264 | { |
|
|
1265 | if (xoff > ewidth) xoff = ewidth; |
|
|
1266 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1328 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1267 | x + (ewidth - xoff >> 1), |
|
|
1268 | y + base, enc, ep - enc); |
1329 | x, y + base, enc, ep - enc); |
1269 | } |
|
|
1270 | } |
1330 | } |
1271 | #endif |
1331 | #endif |
1272 | |
1332 | |
1273 | ///////////////////////////////////////////////////////////////////////////// |
1333 | ///////////////////////////////////////////////////////////////////////////// |
1274 | |
1334 | |
1275 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1335 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1276 | : r (r), fontdesc (0) |
1336 | : fontdesc (0), r (r) |
1277 | { |
1337 | { |
1278 | clear (); |
1338 | clear (); |
1279 | } |
1339 | } |
1280 | |
1340 | |
1281 | rxvt_fontset::~rxvt_fontset () |
1341 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1284 | } |
1344 | } |
1285 | |
1345 | |
1286 | void |
1346 | void |
1287 | rxvt_fontset::clear () |
1347 | rxvt_fontset::clear () |
1288 | { |
1348 | { |
1289 | prop.width = prop.height = prop.weight = prop.slant |
1349 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1290 | = rxvt_fontprop::unset; |
1350 | = rxvt_fontprop::unset; |
1291 | |
1351 | |
1292 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1352 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1293 | FONT_UNREF (*i); |
1353 | FONT_UNREF (*i); |
1294 | |
1354 | |
… | |
… | |
1346 | char buf[512]; |
1406 | char buf[512]; |
1347 | const char *end; |
1407 | const char *end; |
1348 | |
1408 | |
1349 | do |
1409 | do |
1350 | { |
1410 | { |
1351 | while (*desc <= ' ') desc++; |
1411 | while (*desc && *desc <= ' ') |
|
|
1412 | desc++; |
1352 | |
1413 | |
1353 | codeset cs = CS_UNICODE; |
1414 | codeset cs = CS_UNICODE; |
1354 | |
1415 | |
1355 | if (*desc == '[') |
1416 | if (*desc == '[') |
1356 | { |
1417 | { |
… | |
… | |
1466 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1527 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1467 | goto next_font; |
1528 | goto next_font; |
1468 | |
1529 | |
1469 | if (!realize_font (i)) |
1530 | if (!realize_font (i)) |
1470 | goto next_font; |
1531 | goto next_font; |
|
|
1532 | |
|
|
1533 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1534 | max_it (f->ascent, prop.ascent); |
1471 | } |
1535 | } |
1472 | |
1536 | |
1473 | if (f->cs == CS_UNKNOWN) |
1537 | if (f->cs == CS_UNKNOWN) |
1474 | goto next_font; |
1538 | goto next_font; |
1475 | |
1539 | |
… | |
… | |
1514 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1578 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1515 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1579 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1516 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1580 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1517 | |
1581 | |
1518 | XftResult result; |
1582 | XftResult result; |
1519 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1583 | FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); |
1520 | |
1584 | |
1521 | FcPatternDestroy (p); |
1585 | FcPatternDestroy (p); |
1522 | |
1586 | |
1523 | if (match) |
1587 | if (match) |
1524 | { |
1588 | { |