… | |
… | |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
|
|
26 | #include <cstdlib> |
|
|
27 | |
26 | #define DISPLAY r->Xdisplay |
28 | #define DISPLAY r->Xdisplay |
27 | #define DRAWABLE r->TermWin.vt |
29 | #define DRAWABLE r->TermWin.vt |
28 | #define GC r->TermWin.gc |
30 | #define GC r->TermWin.gc |
29 | |
31 | |
30 | const struct rxvt_fallback_font { |
32 | const struct rxvt_fallback_font { |
… | |
… | |
57 | |
59 | |
58 | // japanese |
60 | // japanese |
59 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | #if ENCODING_JP || ENCODING_JP_EXT |
60 | # if XFT |
62 | # if XFT |
61 | // prefer xft for complex scripts |
63 | // prefer xft for complex scripts |
62 | { CS_UNICODE, "xft:Kochi Gothic" }, |
64 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
63 | # endif |
65 | # endif |
64 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
65 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
66 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
67 | #endif |
69 | #endif |
68 | |
70 | |
69 | #if ENCODING_CN || ENCODING_CN_EXT |
71 | #if ENCODING_CN || ENCODING_CN_EXT |
70 | # if XFT |
72 | # if XFT |
71 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
72 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
73 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
74 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
75 | # endif |
77 | # endif |
76 | { CS_CNS11643_1992_1, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
77 | { CS_CNS11643_1992_2, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
79 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
78 | { CS_CNS11643_1992_3, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
80 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
79 | { CS_CNS11643_1992_4, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
81 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
80 | { CS_CNS11643_1992_5, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
82 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
81 | { CS_CNS11643_1992_6, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
83 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
82 | { CS_CNS11643_1992_7, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
84 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
83 | { CS_CNS11643_1992_F, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
85 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
84 | #endif |
86 | #endif |
85 | |
87 | |
86 | #if XFT |
88 | #if XFT |
87 | { CS_UNICODE, "xft:Andale Mono" }, |
89 | { CS_UNICODE, "xft:Andale Mono" }, |
88 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
90 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
89 | #endif |
91 | #endif |
90 | { CS_UNICODE, "-*-lucidatypewriter-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
92 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
93 | { CS_UNICODE, "xft:FreeMono" }, |
|
|
94 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
|
|
95 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
91 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
96 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
92 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
93 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
94 | |
97 | |
95 | { CS_UNKNOWN, 0 } |
98 | { CS_UNKNOWN, 0 } |
96 | }; |
99 | }; |
97 | |
100 | |
98 | ///////////////////////////////////////////////////////////////////////////// |
101 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
220 | |
223 | |
221 | // to be done |
224 | // to be done |
222 | }; |
225 | }; |
223 | |
226 | |
224 | struct rxvt_font_default : rxvt_font { |
227 | struct rxvt_font_default : rxvt_font { |
225 | bool load (int maxheight) |
228 | rxvt_fontprop properties () |
|
|
229 | { |
|
|
230 | rxvt_fontprop p; |
|
|
231 | |
|
|
232 | p.width = p.height = 1; |
|
|
233 | p.weight = rxvt_fontprop::medium; |
|
|
234 | p.slant = rxvt_fontprop::roman; |
|
|
235 | |
|
|
236 | return p; |
|
|
237 | } |
|
|
238 | |
|
|
239 | bool load (const rxvt_fontprop &prop) |
226 | { |
240 | { |
227 | width = 1; height = 1; |
241 | width = 1; height = 1; |
228 | ascent = 1; descent = 0; |
242 | ascent = 1; descent = 0; |
229 | |
243 | |
230 | return true; |
244 | return true; |
… | |
… | |
322 | struct rxvt_font_x11 : rxvt_font { |
336 | struct rxvt_font_x11 : rxvt_font { |
323 | rxvt_font_x11 () { f = 0; } |
337 | rxvt_font_x11 () { f = 0; } |
324 | |
338 | |
325 | void clear (); |
339 | void clear (); |
326 | |
340 | |
327 | bool load (int maxheight); |
341 | rxvt_fontprop properties (); |
|
|
342 | rxvt_fontprop properties (XFontStruct *f); |
|
|
343 | |
|
|
344 | bool load (const rxvt_fontprop &prop); |
328 | |
345 | |
329 | bool has_codepoint (uint32_t unicode); |
346 | bool has_codepoint (uint32_t unicode); |
330 | |
347 | |
331 | void draw (int x, int y, |
348 | void draw (int x, int y, |
332 | const text_t *text, int len, |
349 | const text_t *text, int len, |
… | |
… | |
334 | |
351 | |
335 | XFontStruct *f; |
352 | XFontStruct *f; |
336 | codeset cs; |
353 | codeset cs; |
337 | bool enc2b, encm; |
354 | bool enc2b, encm; |
338 | |
355 | |
339 | const char *get_property (const char *property, const char *repl) const; |
356 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
340 | }; |
357 | }; |
341 | |
358 | |
342 | const char * |
359 | const char * |
343 | rxvt_font_x11::get_property (const char *property, const char *repl) const |
360 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
344 | { |
361 | { |
345 | unsigned long value; |
362 | unsigned long value; |
346 | |
363 | |
347 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
364 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
348 | return XGetAtomName (DISPLAY, value); |
365 | return XGetAtomName (DISPLAY, value); |
349 | else |
366 | else |
350 | return repl; |
367 | return repl; |
351 | } |
368 | } |
352 | |
369 | |
|
|
370 | rxvt_fontprop |
|
|
371 | rxvt_font_x11::properties () |
|
|
372 | { |
|
|
373 | return properties (f); |
|
|
374 | } |
|
|
375 | |
|
|
376 | rxvt_fontprop |
|
|
377 | rxvt_font_x11::properties (XFontStruct *f) |
|
|
378 | { |
|
|
379 | rxvt_fontprop p; |
|
|
380 | |
|
|
381 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
382 | const char *slant = get_property (f, "SLANT", "r"); |
|
|
383 | |
|
|
384 | unsigned long avgwidth; |
|
|
385 | p.width = XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth) |
|
|
386 | ? avgwidth / 10 |
|
|
387 | : (height + 1) / 2; |
|
|
388 | p.height = height; |
|
|
389 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
390 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
|
|
391 | |
|
|
392 | return p; |
|
|
393 | } |
|
|
394 | |
353 | bool |
395 | bool |
354 | rxvt_font_x11::load (int maxheight) |
396 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
355 | { |
397 | { |
356 | clear (); |
398 | clear (); |
357 | |
399 | |
358 | char **list; |
400 | char **list; |
359 | int count; |
401 | int count; |
… | |
… | |
361 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
403 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
362 | |
404 | |
363 | if (!list) |
405 | if (!list) |
364 | return false; |
406 | return false; |
365 | |
407 | |
|
|
408 | int bestdiff = 0x7fffffff; |
366 | XFontStruct *best = 0; |
409 | XFontStruct *best = 0; |
367 | for (int i = 0; i < count; i++) |
410 | for (int i = 0; i < count; i++) |
368 | { |
411 | { |
369 | XFontStruct *f = info + i; |
412 | XFontStruct *f = info + i; |
|
|
413 | |
370 | if (f->ascent + f->descent <= maxheight) // weed out too large fonts |
414 | if (f->ascent + f->descent <= prop.height) // weed out too large fonts |
|
|
415 | { |
|
|
416 | rxvt_fontprop p = properties (f); |
|
|
417 | int diff = (prop.height - f->ascent + f->descent) * 32 |
|
|
418 | + abs (prop.weight - p.weight) |
|
|
419 | + abs (prop.slant - p.slant ); |
|
|
420 | |
371 | if (!best // compare against best found so far |
421 | if (!best // compare against best found so far |
372 | || best->ascent + best->descent < f->ascent + f->descent) |
422 | || diff < bestdiff) |
|
|
423 | { |
373 | best = f; |
424 | best = f; |
|
|
425 | bestdiff = diff; |
|
|
426 | } |
|
|
427 | } |
374 | } |
428 | } |
|
|
429 | |
|
|
430 | if (!best) |
|
|
431 | return false; |
375 | |
432 | |
376 | set_name (strdup (list[best - info])); |
433 | set_name (strdup (list[best - info])); |
377 | |
434 | |
378 | XFreeFontInfo (list, info, count); |
435 | XFreeFontInfo (list, info, count); |
379 | |
436 | |
… | |
… | |
382 | if (!f) |
439 | if (!f) |
383 | return false; |
440 | return false; |
384 | |
441 | |
385 | unsigned long value; |
442 | unsigned long value; |
386 | |
443 | |
387 | const char *registry = get_property ("CHARSET_REGISTRY", 0); |
444 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
388 | const char *encoding = get_property ("CHARSET_ENCODING", 0); |
445 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
389 | |
446 | |
390 | if (registry && encoding) |
447 | if (registry && encoding) |
391 | { |
448 | { |
392 | char charset[64]; |
449 | char charset[64]; |
393 | snprintf (charset, 64, "%s-%s", registry, encoding); |
450 | snprintf (charset, 64, "%s-%s", registry, encoding); |
394 | |
451 | |
395 | cs = codeset_from_name (charset); |
452 | cs = codeset_from_name (charset); |
396 | } |
453 | } |
397 | else |
454 | else |
398 | { |
455 | { |
399 | const char *charset = get_property ("FONT", 0); |
456 | const char *charset = get_property (f, "FONT", 0); |
400 | |
457 | |
401 | if (!charset) |
458 | if (!charset) |
402 | charset = name; |
459 | charset = name; |
403 | |
460 | |
404 | int count = 13; |
461 | int count = 13; |
… | |
… | |
417 | |
474 | |
418 | ascent = f->ascent; |
475 | ascent = f->ascent; |
419 | descent = f->descent; |
476 | descent = f->descent; |
420 | height = ascent + descent; |
477 | height = ascent + descent; |
421 | |
478 | |
422 | prop = false; |
479 | slow = false; |
423 | |
480 | |
424 | if (f->min_bounds.width == f->max_bounds.width) |
481 | if (f->min_bounds.width == f->max_bounds.width) |
425 | width = f->min_bounds.width; |
482 | width = f->min_bounds.width; |
426 | else if (f->per_char == NULL) |
483 | else if (f->per_char == NULL) |
427 | width = f->max_bounds.width; |
484 | width = f->max_bounds.width; |
428 | else |
485 | else |
429 | { |
486 | { |
430 | prop = true; |
487 | slow = true; |
431 | |
488 | |
432 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
489 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
433 | |
490 | |
434 | if (encm) |
491 | if (encm) |
435 | N += (f->max_byte1 - f->min_byte1) |
492 | N += (f->max_byte1 - f->min_byte1) |
… | |
… | |
520 | // this looks like a mess /. |
577 | // this looks like a mess /. |
521 | // and it is a mess /. |
578 | // and it is a mess /. |
522 | // yet we are trying to be perfect /. |
579 | // yet we are trying to be perfect /. |
523 | // but the result still isn't perfect /. |
580 | // but the result still isn't perfect /. |
524 | |
581 | |
525 | bool slow = prop |
582 | bool slow = this->slow |
526 | || width != r->TermWin.fwidth |
583 | || width != r->TermWin.fwidth |
527 | || height != r->TermWin.fheight; |
584 | || height != r->TermWin.fheight; |
528 | |
585 | |
529 | int base = r->TermWin.fbase; |
586 | int base = r->TermWin.fbase; |
530 | |
587 | |
… | |
… | |
605 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
662 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
606 | #define SWATHBITS 8 |
663 | #define SWATHBITS 8 |
607 | #endif |
664 | #endif |
608 | |
665 | |
609 | struct rxvt_font_xft : rxvt_font { |
666 | struct rxvt_font_xft : rxvt_font { |
610 | #if 0 |
|
|
611 | enum { |
|
|
612 | SWATHCOUNT = 1 << (21 - UNIBITS), |
|
|
613 | SWATHSIZE = 1 << (SWATHBITS - 5) |
|
|
614 | }; |
|
|
615 | typedef uint32_t swath[SWATHSIZE]; |
|
|
616 | |
|
|
617 | swath *cvr[SWATHCOUNT]; |
|
|
618 | #endif |
|
|
619 | |
|
|
620 | #if 0 |
|
|
621 | void gen_coverage_swath (unsigned int page); |
|
|
622 | |
|
|
623 | bool has_char (uint32_t ch) |
|
|
624 | { |
|
|
625 | unsigned int page = ch >> SWATHBITS; |
|
|
626 | unsigned int idx = ch & ((1 << SWATHBITS) - 1); |
|
|
627 | |
|
|
628 | if (page >= SWATHCOUNT) |
|
|
629 | return false; |
|
|
630 | |
|
|
631 | if (!cvr[page]) gen_coverage_swath (page); |
|
|
632 | |
|
|
633 | return cvr[page][idx >> 5] & (1 << (idx & 31)); |
|
|
634 | } |
|
|
635 | #endif |
|
|
636 | rxvt_font_xft () { f = 0; d = 0; } |
667 | rxvt_font_xft () { f = 0; d = 0; } |
637 | |
668 | |
638 | void clear (); |
669 | void clear (); |
639 | |
670 | |
640 | bool load (int maxheight); |
671 | rxvt_fontprop properties (); |
|
|
672 | |
|
|
673 | bool load (const rxvt_fontprop &prop); |
641 | |
674 | |
642 | void draw (int x, int y, |
675 | void draw (int x, int y, |
643 | const text_t *text, int len, |
676 | const text_t *text, int len, |
644 | int fg, int bg); |
677 | int fg, int bg); |
645 | |
678 | |
646 | bool has_codepoint (uint32_t unicode); |
679 | bool has_codepoint (uint32_t unicode); |
647 | |
680 | |
648 | protected: |
681 | protected: |
649 | XftFont *f; |
682 | XftFont *f; |
650 | XftDraw *d; |
683 | XftDraw *d; |
651 | |
|
|
652 | #if 0 |
|
|
653 | virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0; |
|
|
654 | void set_swath (uint32_t ch) |
|
|
655 | { |
|
|
656 | cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1)); |
|
|
657 | } |
|
|
658 | #endif |
|
|
659 | }; |
684 | }; |
660 | |
685 | |
661 | void |
686 | void |
662 | rxvt_font_xft::clear () |
687 | rxvt_font_xft::clear () |
663 | { |
688 | { |
… | |
… | |
670 | if (d) |
695 | if (d) |
671 | { |
696 | { |
672 | XftDrawDestroy (d); |
697 | XftDrawDestroy (d); |
673 | d = 0; |
698 | d = 0; |
674 | } |
699 | } |
|
|
700 | } |
675 | |
701 | |
676 | #if 0 |
702 | rxvt_fontprop |
677 | for (int i = 0; i < SWATHCOUNT; i++) |
703 | rxvt_font_xft::properties () |
678 | delete cvr[i]; |
704 | { |
679 | #endif |
705 | rxvt_fontprop p; |
|
|
706 | |
|
|
707 | FT_Face face = XftLockFace (f); |
|
|
708 | |
|
|
709 | p.width = width; p.height = height; |
|
|
710 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
711 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
|
|
712 | |
|
|
713 | XftUnlockFace (f); |
|
|
714 | |
|
|
715 | return p; |
680 | } |
716 | } |
681 | |
717 | |
682 | bool |
718 | bool |
683 | rxvt_font_xft::load (int maxheight) |
719 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
684 | { |
720 | { |
685 | #if 0 |
721 | #if 0 |
686 | for (int i = 0; i < SWATHCOUNT; i++) |
722 | for (int i = 0; i < SWATHCOUNT; i++) |
687 | cvr[i] = 0; |
723 | cvr[i] = 0; |
688 | #endif |
724 | #endif |
689 | |
725 | |
690 | clear (); |
726 | clear (); |
691 | |
727 | |
692 | f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); |
728 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
|
|
729 | |
|
|
730 | if (!p) |
|
|
731 | return false; |
|
|
732 | |
|
|
733 | FcValue v; |
|
|
734 | |
|
|
735 | if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
|
|
736 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
|
|
737 | |
|
|
738 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
|
|
739 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
|
|
740 | |
|
|
741 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
|
|
742 | // clip width, we can't do better, or can we? |
|
|
743 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
|
|
744 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
|
|
745 | #endif |
|
|
746 | |
|
|
747 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
748 | |
|
|
749 | XftResult result; |
|
|
750 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
|
|
751 | |
|
|
752 | FcPatternDestroy (p); |
|
|
753 | |
|
|
754 | if (!match) |
|
|
755 | return false; |
|
|
756 | |
|
|
757 | f = XftFontOpenPattern (DISPLAY, match); |
693 | |
758 | |
694 | if (!f) |
759 | if (!f) |
|
|
760 | { |
|
|
761 | FcPatternDestroy (match); |
695 | return false; |
762 | return false; |
|
|
763 | } |
696 | |
764 | |
697 | FT_Face face = XftLockFace (f); |
765 | FT_Face face = XftLockFace (f); |
698 | |
766 | |
699 | prop = !FT_IS_FIXED_WIDTH (face); |
767 | slow = !FT_IS_FIXED_WIDTH (face); |
700 | |
768 | |
701 | int ftheight = 0; |
769 | int ftheight = 0; |
702 | |
770 | |
703 | for (;;) |
771 | for (;;) |
704 | { |
772 | { |
… | |
… | |
706 | FcChar8 c; |
774 | FcChar8 c; |
707 | |
775 | |
708 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
776 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
709 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
777 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
710 | |
778 | |
711 | prop = prop || g1.xOff != g2.xOff; // don't simply trust the font |
779 | if (g1.xOff != g2.xOff) // don't simply trust the font |
|
|
780 | slow = true; |
712 | |
781 | |
713 | width = g2.xOff; |
782 | width = g2.xOff; |
714 | ascent = (face->size->metrics.ascender + 63) >> 6; |
783 | ascent = (face->size->metrics.ascender + 63) >> 6; |
715 | descent = (-face->size->metrics.descender + 63) >> 6; |
784 | descent = (-face->size->metrics.descender + 63) >> 6; |
716 | height = ascent + descent; |
785 | height = ascent + descent; |
717 | |
786 | |
718 | if (height <= maxheight || !maxheight) |
787 | if (height <= prop.height || !prop.height) |
719 | break; |
788 | break; |
720 | |
789 | |
721 | if (ftheight) |
790 | if (ftheight) |
722 | { |
791 | { |
723 | // take smaller steps near the end |
792 | // take smaller steps near the end |
724 | if (height > maxheight + 1) ftheight++; |
793 | if (height > prop.height + 1) ftheight++; |
725 | if (height > maxheight + 2) ftheight++; |
794 | if (height > prop.height + 2) ftheight++; |
726 | if (height > maxheight + 3) ftheight++; |
795 | if (height > prop.height + 3) ftheight++; |
727 | |
796 | |
728 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); |
797 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
729 | } |
798 | } |
730 | else |
799 | else |
731 | FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); |
800 | FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
732 | } |
801 | } |
733 | |
802 | |
734 | XftUnlockFace (f); |
803 | XftUnlockFace (f); |
735 | |
804 | |
736 | return true; |
805 | return true; |
737 | } |
806 | } |
738 | |
|
|
739 | #if 0 |
|
|
740 | void rxvt_font::gen_coverage_swath (unsigned int page) |
|
|
741 | { |
|
|
742 | cvr[page] = new swath; |
|
|
743 | |
|
|
744 | for (int i = 0; i < SWATHSIZE; i++) |
|
|
745 | cvr[page][i] = 0; |
|
|
746 | |
|
|
747 | populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1); |
|
|
748 | } |
|
|
749 | #endif |
|
|
750 | |
807 | |
751 | bool |
808 | bool |
752 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
809 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
753 | { |
810 | { |
754 | return XftCharExists (DISPLAY, f, unicode); |
811 | return XftCharExists (DISPLAY, f, unicode); |
… | |
… | |
768 | if (bg >= 0 && bg != Color_bg) |
825 | if (bg >= 0 && bg != Color_bg) |
769 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
826 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
770 | else |
827 | else |
771 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
828 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
772 | |
829 | |
773 | if (!prop && width == r->TermWin.fwidth) |
830 | if (!slow && width == r->TermWin.fwidth) |
774 | { |
831 | { |
775 | if (sizeof (text_t) == sizeof (FcChar16)) |
832 | if (sizeof (text_t) == sizeof (FcChar16)) |
776 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
833 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
777 | else |
834 | else |
778 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
835 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
… | |
… | |
818 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
875 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
819 | FONT_UNREF (*i); |
876 | FONT_UNREF (*i); |
820 | |
877 | |
821 | fonts.clear (); |
878 | fonts.clear (); |
822 | base_id = 0; |
879 | base_id = 0; |
823 | height = 0x7fffffff; |
880 | base_prop.height = 0x7fffffff; |
|
|
881 | base_prop.weight = rxvt_fontprop::medium; |
|
|
882 | base_prop.slant = rxvt_fontprop::roman; |
824 | |
883 | |
825 | fallback = fallback_fonts; |
884 | fallback = fallback_fonts; |
826 | } |
885 | } |
827 | |
886 | |
828 | rxvt_font * |
887 | rxvt_font * |
… | |
… | |
915 | if (fonts[i]->loaded) |
974 | if (fonts[i]->loaded) |
916 | return true; |
975 | return true; |
917 | |
976 | |
918 | fonts[i]->loaded = true; |
977 | fonts[i]->loaded = true; |
919 | |
978 | |
920 | if (!fonts[i]->load (height)) |
979 | if (!fonts[i]->load (base_prop)) |
921 | { |
980 | { |
922 | fonts[i]->cs = CS_UNKNOWN; |
981 | fonts[i]->cs = CS_UNKNOWN; |
923 | return false; |
982 | return false; |
924 | } |
983 | } |
925 | |
984 | |
… | |
… | |
938 | |
997 | |
939 | if (!base_id) |
998 | if (!base_id) |
940 | base_id = 1; |
999 | base_id = 1; |
941 | |
1000 | |
942 | // we currently need a base-font, no matter what |
1001 | // we currently need a base-font, no matter what |
943 | if (fonts.size () <= base_id) |
1002 | if (fonts.size () <= base_id || !realize_font (base_id)) |
944 | { |
1003 | { |
945 | add_fonts ("fixed"); |
1004 | add_fonts ("fixed"); |
946 | base_id = 1; |
1005 | base_id = fonts.size () - 1; |
947 | } |
1006 | } |
948 | |
1007 | |
949 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1008 | if (fonts.size () <= base_id || !realize_font (base_id)) |
950 | { |
1009 | { |
951 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1010 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
952 | exit (1); |
1011 | exit (1); |
953 | } |
1012 | } |
954 | |
1013 | |
955 | height = fonts[base_id]->height; |
1014 | base_prop = fonts[base_id]->properties (); |
956 | |
|
|
957 | /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/ |
|
|
958 | } |
1015 | } |
959 | |
1016 | |
960 | int |
1017 | int |
961 | rxvt_fontset::find_font (uint32_t unicode) |
1018 | rxvt_fontset::find_font (uint32_t unicode) |
962 | { |
1019 | { |