… | |
… | |
90 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
90 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
91 | #endif |
91 | #endif |
92 | |
92 | |
93 | #if ENCODING_ZH || ENCODING_ZH_EXT |
93 | #if ENCODING_ZH || ENCODING_ZH_EXT |
94 | # if XFT |
94 | # if XFT |
|
|
95 | { CS_GBK_0, "xft:AR PL KaitiM GB" }, |
|
|
96 | { CS_GBK_0, "xft:AR PL SungtiL GB" }, |
|
|
97 | { CS_GBK_0, "xft::spacing=100:lang=zh" }, |
95 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
98 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
96 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
99 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
97 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
100 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
98 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
101 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
99 | { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, |
102 | { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, |
100 | # endif |
103 | # endif |
|
|
104 | { CS_GBK_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gbk*-0" }, |
101 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
105 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
102 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
106 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
103 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
107 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
|
|
108 | { CS_GB2312_1980_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
104 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
109 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
105 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
110 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
106 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
111 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
107 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
112 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
108 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
113 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
… | |
… | |
138 | |
143 | |
139 | { CS_UNKNOWN, 0 } |
144 | { CS_UNKNOWN, 0 } |
140 | }; |
145 | }; |
141 | |
146 | |
142 | // these characters are used to guess the font height and width |
147 | // these characters are used to guess the font height and width |
143 | // pango uses a similar algorithm and eosn't trust the font either. |
148 | // pango uses a similar algorithm and doesn't trust the font either. |
144 | static uint16_t extent_test_chars[] = { |
149 | static uint16_t extent_test_chars[] = { |
145 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
150 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
146 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
151 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
147 | 0x304c, 0x672c, // が本 |
152 | 0x304c, 0x672c, // が本 |
148 | }; |
153 | }; |
… | |
… | |
330 | { |
335 | { |
331 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
336 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
332 | |
337 | |
333 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
338 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
334 | |
339 | |
335 | while (len--) |
340 | while (len) |
336 | { |
341 | { |
337 | #if ENABLE_COMBINING |
342 | #if ENABLE_COMBINING |
338 | compose_char *cc; |
343 | compose_char *cc; |
339 | #endif |
344 | #endif |
|
|
345 | const text_t *tp = text; |
340 | text_t t = *text++; |
346 | text_t t = *tp; |
|
|
347 | |
|
|
348 | while (++text, --len && *text == NOCHAR) |
|
|
349 | ; |
|
|
350 | |
|
|
351 | int width = text - tp; |
|
|
352 | int fwidth = r->TermWin.fwidth * width; |
341 | |
353 | |
342 | if (0x2500 <= t && t <= 0x259f) |
354 | if (0x2500 <= t && t <= 0x259f) |
343 | { |
355 | { |
344 | uint16_t offs = linedraw_offs[t - 0x2500]; |
356 | uint16_t offs = linedraw_offs[t - 0x2500]; |
345 | uint32_t *a = linedraw_command + (offs >> 4); |
357 | uint32_t *a = linedraw_command + (offs >> 4); |
346 | uint32_t *b = a + (offs & 15); |
358 | uint32_t *b = a + (offs & 15); |
347 | |
359 | |
348 | int W = r->TermWin.fwidth; |
360 | int W = fwidth; |
349 | int H = r->TermWin.fheight; |
361 | int H = r->TermWin.fheight; |
350 | |
362 | |
351 | int x_[16]; |
363 | int x_[16]; |
352 | int y_[16]; |
364 | int y_[16]; |
353 | |
365 | |
… | |
… | |
418 | } |
430 | } |
419 | } |
431 | } |
420 | #if ENABLE_COMBINING |
432 | #if ENABLE_COMBINING |
421 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
433 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
422 | { |
434 | { |
423 | text_t c2[2]; |
435 | text_t chrs[2]; |
424 | int len2 = 1; |
436 | width = min (2, width); |
425 | |
437 | chrs [1] = NOCHAR; |
426 | // support double-width (but not more) combining characters |
|
|
427 | if (len && *text == NOCHAR) |
|
|
428 | { |
|
|
429 | c2[1] = *text; // not text++ to get correct x-width |
|
|
430 | len2++; |
|
|
431 | } |
|
|
432 | |
438 | |
433 | c2[0] = cc->c1; |
439 | *chrs = cc->c1; |
434 | rxvt_font *f1 = (*fs)[fs->find_font (c2[0])]; |
440 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
435 | f1->draw (d, x, y, c2, len2, fg, bg); |
441 | f1->draw (d, x, y, chrs, width, fg, bg); |
436 | |
442 | |
437 | if (cc->c2 != NOCHAR) |
443 | if (cc->c2 != NOCHAR) |
438 | { |
444 | { |
439 | bool careful; |
445 | bool careful; |
440 | |
446 | |
441 | // prefer font of first character, for no good reasons |
447 | // prefer font of first character, for no good reasons |
442 | c2[0] = cc->c2; |
448 | *chrs = cc->c2; |
443 | rxvt_font *f2 = (f1->has_char (c2[0], 0, careful) && !careful) |
449 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
444 | ? f1 |
450 | ? f1 |
445 | : (*fs)[fs->find_font (c2[0])]; |
451 | : (*fs)[fs->find_font (cc->c2)]; |
446 | |
452 | |
447 | f2->draw (d, x, y, c2, len2, fg, -1); |
453 | f2->draw (d, x, y, chrs, width, fg, -1); |
448 | } |
454 | } |
449 | } |
455 | } |
450 | #endif |
456 | #endif |
451 | else |
457 | else |
452 | switch (t) |
458 | switch (t) |
… | |
… | |
455 | case ZERO_WIDTH_CHAR: |
461 | case ZERO_WIDTH_CHAR: |
456 | case NOCHAR: |
462 | case NOCHAR: |
457 | break; |
463 | break; |
458 | |
464 | |
459 | default: |
465 | default: |
460 | int w = 0; |
|
|
461 | while (len > 0 && *text == NOCHAR) |
|
|
462 | { |
|
|
463 | ++text; |
|
|
464 | --len; |
|
|
465 | w += r->TermWin.fwidth; |
|
|
466 | } |
|
|
467 | |
|
|
468 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
466 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
469 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
467 | fwidth - 4, r->TermWin.fheight - 4); |
470 | x += w; |
|
|
471 | } |
468 | } |
472 | |
469 | |
473 | x += r->TermWin.fwidth; |
470 | x += fwidth; |
474 | } |
471 | } |
475 | } |
472 | } |
476 | |
473 | |
477 | ///////////////////////////////////////////////////////////////////////////// |
474 | ///////////////////////////////////////////////////////////////////////////// |
478 | |
475 | |
… | |
… | |
534 | |
531 | |
535 | bool |
532 | bool |
536 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
533 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
537 | { |
534 | { |
538 | unsigned long height; |
535 | unsigned long height; |
|
|
536 | |
|
|
537 | #if 0 |
539 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
538 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
540 | return false; |
539 | return false; |
|
|
540 | #else |
|
|
541 | height = f->ascent + f->descent; |
|
|
542 | #endif |
541 | |
543 | |
542 | unsigned long avgwidth; |
544 | unsigned long avgwidth; |
543 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
545 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
544 | avgwidth = 0; |
546 | avgwidth = 0; |
545 | |
547 | |
… | |
… | |
673 | ? "r" : "i"); // TODO: handle "o"blique, too |
675 | ? "r" : "i"); // TODO: handle "o"blique, too |
674 | set_name (strdup (fname)); |
676 | set_name (strdup (fname)); |
675 | } |
677 | } |
676 | } |
678 | } |
677 | |
679 | |
|
|
680 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
|
|
681 | ? 0 : prop.height); |
|
|
682 | |
|
|
683 | struct font_weight { |
|
|
684 | char *name; |
|
|
685 | int diff; |
|
|
686 | |
|
|
687 | void clear () |
|
|
688 | { |
|
|
689 | name = 0; |
|
|
690 | diff = 0x7fffffff; |
|
|
691 | } |
|
|
692 | |
|
|
693 | font_weight () { clear (); } |
|
|
694 | ~font_weight () { free (name); } |
|
|
695 | }; |
|
|
696 | |
678 | char **list; |
697 | char **list; |
679 | int count; |
698 | int count; |
680 | list = XListFonts (DISPLAY, name, 1024, &count); |
699 | list = XListFonts (DISPLAY, name, 4000, &count); |
681 | |
700 | |
682 | set_name (0); |
701 | set_name (0); |
683 | |
702 | |
684 | if (!list) |
703 | if (!list) |
685 | return false; |
704 | return false; |
686 | |
705 | |
687 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
706 | font_weight *fonts = new font_weight[count]; |
688 | ? 0 : prop.height); |
|
|
689 | |
707 | |
690 | int bestdiff = 0x7fffffff; |
|
|
691 | for (int i = 0; i < count; i++) |
708 | for (int i = 0; i < count; i++) |
692 | { |
709 | { |
693 | rxvt_fontprop p; |
710 | rxvt_fontprop p; |
694 | char fname[1024]; |
711 | char fname[1024]; |
695 | |
712 | |
696 | int diff = 0; |
713 | int diff = 0; |
697 | |
714 | |
698 | if (replace_field (fname, list[i], 6, '0', field_str)) |
715 | if (replace_field (fname, list[i], 6, '0', field_str)) |
699 | diff += 10; // slightly penalize scalable fonts |
716 | diff += 10; // slightly penalize scalable fonts |
700 | |
717 | |
701 | if (!set_properties (p, fname)) |
718 | if (!set_properties (p, fname)) |
702 | continue; |
719 | continue; |
… | |
… | |
708 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
725 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
709 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
726 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
710 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
727 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
711 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
728 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
712 | |
729 | |
713 | if (!name // compare against best found so far |
730 | fonts[i].name = strdup (fname); |
714 | || diff < bestdiff) |
731 | fonts[i].diff = diff; |
715 | { |
|
|
716 | set_name (strdup (fname)); |
|
|
717 | bestdiff = diff; |
|
|
718 | } |
|
|
719 | } |
732 | } |
720 | |
733 | |
721 | XFreeFontNames (list); |
734 | XFreeFontNames (list); |
722 | |
735 | |
723 | if (!name) |
736 | // this loop only iterates when the guessed font-size is too small |
724 | return false; |
737 | for (;;) |
|
|
738 | { |
|
|
739 | font_weight *best = fonts + count - 1; |
725 | |
740 | |
|
|
741 | for (font_weight *w = best; w-- > fonts; ) |
|
|
742 | if (w->diff < best->diff) |
|
|
743 | best = w; |
|
|
744 | |
|
|
745 | if (!best->name |
726 | f = XLoadQueryFont (DISPLAY, name); |
746 | || !(f = XLoadQueryFont (DISPLAY, best->name))) |
|
|
747 | break; |
|
|
748 | |
|
|
749 | set_name (best->name); |
|
|
750 | best->clear (); |
|
|
751 | |
|
|
752 | ascent = f->ascent; |
|
|
753 | descent = f->descent; |
|
|
754 | height = ascent + descent; |
|
|
755 | |
|
|
756 | if (prop.height == rxvt_fontprop::unset |
|
|
757 | || height <= prop.height) |
|
|
758 | break; // font is ready for use |
|
|
759 | |
|
|
760 | // PIXEL_SIZE small enough, but real height too large |
|
|
761 | clear (); |
|
|
762 | } |
|
|
763 | |
|
|
764 | delete [] fonts; |
727 | |
765 | |
728 | if (!f) |
766 | if (!f) |
729 | return false; |
767 | return false; |
730 | |
768 | |
731 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
769 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
… | |
… | |
759 | if (cs == CS_UNICODE) |
797 | if (cs == CS_UNICODE) |
760 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
798 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
761 | |
799 | |
762 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
800 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
763 | enc2b = encm || f->max_char_or_byte2 > 255; |
801 | enc2b = encm || f->max_char_or_byte2 > 255; |
764 | |
|
|
765 | ascent = f->ascent; |
|
|
766 | descent = f->descent; |
|
|
767 | height = ascent + descent; |
|
|
768 | |
802 | |
769 | slow = false; |
803 | slow = false; |
770 | |
804 | |
771 | #if 1 // only used for slow detection, TODO optimize |
805 | #if 1 // only used for slow detection, TODO optimize |
772 | if (f->min_bounds.width == f->max_bounds.width) |
806 | if (f->min_bounds.width == f->max_bounds.width) |
… | |
… | |
1056 | return false; |
1090 | return false; |
1057 | |
1091 | |
1058 | FcValue v; |
1092 | FcValue v; |
1059 | |
1093 | |
1060 | if (prop.height != rxvt_fontprop::unset |
1094 | if (prop.height != rxvt_fontprop::unset |
1061 | && FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch) |
1095 | || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
|
|
1096 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1062 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1097 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1063 | |
1098 | |
1064 | if (prop.weight != rxvt_fontprop::unset |
1099 | if (prop.weight != rxvt_fontprop::unset |
1065 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1100 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1066 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1101 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |