1 | /*--------------------------------*-C-*---------------------------------*; |
1 | /*--------------------------------*-C-*---------------------------------*; |
2 | * File: defaultfont.C |
2 | * File: defaultfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003 Marc Lehmann rxvt@plan9.de> |
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 |
8 | * it under the terms of the GNU General Public License as published by |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
9 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
26 | #include <cstdlib> |
26 | #include <cstdlib> |
27 | |
27 | |
28 | #define DISPLAY r->Xdisplay |
28 | #define DISPLAY r->display->display |
29 | #define DRAWABLE r->TermWin.vt |
29 | #define DRAWABLE r->TermWin.vt |
30 | #define GC r->TermWin.gc |
30 | #define GC r->TermWin.gc |
31 | |
31 | |
32 | const struct rxvt_fallback_font { |
32 | const struct rxvt_fallback_font { |
33 | codeset cs; |
33 | codeset cs; |
… | |
… | |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
77 | # endif |
77 | # endif |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0 }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
79 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
79 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
80 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
80 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
81 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
81 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
82 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
82 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
83 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
83 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
… | |
… | |
103 | |
103 | |
104 | static void *enc_buf; |
104 | static void *enc_buf; |
105 | static uint32_t enc_len; |
105 | static uint32_t enc_len; |
106 | |
106 | |
107 | static inline void * |
107 | static inline void * |
108 | get_enc_buf (int len) |
108 | get_enc_buf (uint32_t len) |
109 | { |
109 | { |
110 | if (len > enc_len) |
110 | if (len > enc_len) |
111 | { |
111 | { |
112 | free (enc_buf); |
112 | free (enc_buf); |
113 | enc_buf = malloc (len); |
113 | enc_buf = malloc (len); |
… | |
… | |
115 | |
115 | |
116 | return enc_buf; |
116 | return enc_buf; |
117 | } |
117 | } |
118 | |
118 | |
119 | static const char * |
119 | static const char * |
120 | enc_char (const text_t *text, int len, codeset cs, bool &zero) |
120 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
121 | { |
121 | { |
122 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
122 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
123 | |
123 | |
124 | while (len--) |
124 | while (len--) |
125 | { |
125 | { |
… | |
… | |
136 | |
136 | |
137 | return (const char *)enc_buf; |
137 | return (const char *)enc_buf; |
138 | } |
138 | } |
139 | |
139 | |
140 | static const XChar2b * |
140 | static const XChar2b * |
141 | enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) |
141 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
142 | { |
142 | { |
143 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
143 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
144 | |
144 | |
145 | while (len--) |
145 | while (len--) |
146 | { |
146 | { |
… | |
… | |
428 | |
428 | |
429 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
429 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
430 | |
430 | |
431 | if (f) |
431 | if (f) |
432 | { |
432 | { |
433 | // the font should really exists now. if not, we have a problem |
433 | // the font should really exist now. if not, we have a problem |
434 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
434 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
435 | // in that case, just return garbage. |
435 | // in that case, just return garbage. |
436 | bool ret = set_properties (p, f); |
436 | bool ret = set_properties (p, f); |
437 | XFreeFont (DISPLAY, f); |
437 | XFreeFont (DISPLAY, f); |
438 | return ret; |
438 | return ret; |
… | |
… | |
515 | f = XLoadQueryFont (DISPLAY, name); |
515 | f = XLoadQueryFont (DISPLAY, name); |
516 | |
516 | |
517 | if (!f) |
517 | if (!f) |
518 | return false; |
518 | return false; |
519 | |
519 | |
520 | unsigned long value; |
|
|
521 | |
|
|
522 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
520 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
523 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
521 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
524 | |
522 | |
525 | if (registry && encoding) |
523 | if (registry && encoding) |
526 | { |
524 | { |
… | |
… | |
612 | /* check wether the character exists in _this_ font. horrible. */ |
610 | /* check wether the character exists in _this_ font. horrible. */ |
613 | XCharStruct *xcs; |
611 | XCharStruct *xcs; |
614 | |
612 | |
615 | if (encm) |
613 | if (encm) |
616 | { |
614 | { |
617 | int byte1 = ch >> 8; |
615 | unsigned char byte1 = ch >> 8; |
618 | int byte2 = ch & 255; |
616 | unsigned char byte2 = ch & 255; |
619 | |
617 | |
620 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
618 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
621 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
619 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
622 | return false; |
620 | return false; |
623 | |
621 | |
… | |
… | |
762 | }; |
760 | }; |
763 | |
761 | |
764 | void |
762 | void |
765 | rxvt_font_xft::clear () |
763 | rxvt_font_xft::clear () |
766 | { |
764 | { |
|
|
765 | if (d) |
|
|
766 | { |
|
|
767 | XftDrawDestroy (d); |
|
|
768 | d = 0; |
|
|
769 | } |
|
|
770 | |
767 | if (f) |
771 | if (f) |
768 | { |
772 | { |
769 | XftFontClose (DISPLAY, f); |
773 | XftFontClose (DISPLAY, f); |
770 | f = 0; |
774 | f = 0; |
771 | } |
|
|
772 | |
|
|
773 | if (d) |
|
|
774 | { |
|
|
775 | XftDrawDestroy (d); |
|
|
776 | d = 0; |
|
|
777 | } |
775 | } |
778 | } |
776 | } |
779 | |
777 | |
780 | rxvt_fontprop |
778 | rxvt_fontprop |
781 | rxvt_font_xft::properties () |
779 | rxvt_font_xft::properties () |
… | |
… | |
892 | void |
890 | void |
893 | rxvt_font_xft::draw (int x, int y, |
891 | rxvt_font_xft::draw (int x, int y, |
894 | const text_t *text, int len, |
892 | const text_t *text, int len, |
895 | int fg, int bg) |
893 | int fg, int bg) |
896 | { |
894 | { |
897 | if (!d) |
895 | d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap); |
898 | { |
|
|
899 | dR; |
|
|
900 | d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP); |
|
|
901 | } |
|
|
902 | |
896 | |
903 | if (bg >= 0 && bg != Color_bg) |
897 | if (bg >= 0 && bg != Color_bg) |
904 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
898 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
905 | else |
899 | else |
906 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
900 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
… | |
… | |
947 | #endif |
941 | #endif |
948 | |
942 | |
949 | ///////////////////////////////////////////////////////////////////////////// |
943 | ///////////////////////////////////////////////////////////////////////////// |
950 | |
944 | |
951 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
945 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
952 | #ifdef EXPLICIT_CONTEXT |
|
|
953 | : r(r) |
946 | : r (r) |
954 | #endif |
|
|
955 | { |
947 | { |
956 | clear (); |
948 | clear (); |
957 | } |
949 | } |
958 | |
950 | |
959 | rxvt_fontset::~rxvt_fontset () |
951 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
962 | } |
954 | } |
963 | |
955 | |
964 | void |
956 | void |
965 | rxvt_fontset::clear () |
957 | rxvt_fontset::clear () |
966 | { |
958 | { |
967 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
959 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
968 | FONT_UNREF (*i); |
960 | FONT_UNREF (*i); |
969 | |
961 | |
970 | fonts.clear (); |
962 | fonts.clear (); |
971 | base_id = 0; |
963 | base_id = 0; |
972 | base_prop.height = 0x7fffffff; |
964 | base_prop.height = 0x7fffffff; |
… | |
… | |
1026 | |
1018 | |
1027 | if (*desc == '[') |
1019 | if (*desc == '[') |
1028 | { |
1020 | { |
1029 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1021 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1030 | |
1022 | |
1031 | const char *extra = desc++; |
1023 | //const char *extra = desc++; // not yet used |
1032 | |
1024 | |
1033 | desc = strchr (desc, ']'); |
1025 | desc = strchr (desc, ']'); |
1034 | |
1026 | |
1035 | if (!desc) |
1027 | if (!desc) |
1036 | { |
1028 | { |
… | |
… | |
1089 | |
1081 | |
1090 | if (!base_id) |
1082 | if (!base_id) |
1091 | base_id = 1; |
1083 | base_id = 1; |
1092 | |
1084 | |
1093 | // we currently need a base-font, no matter what |
1085 | // we currently need a base-font, no matter what |
1094 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1086 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1095 | { |
1087 | { |
1096 | puts ("unable to load specified font(s), falling back to 'fixed'\n"); |
1088 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
1097 | add_fonts ("fixed"); |
1089 | add_fonts ("fixed"); |
1098 | base_id = fonts.size () - 1; |
1090 | base_id = fonts.size () - 1; |
1099 | } |
1091 | } |
1100 | |
1092 | |
1101 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1093 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1102 | { |
1094 | { |
1103 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1095 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1104 | exit (1); |
1096 | exit (1); |
1105 | } |
1097 | } |
1106 | |
1098 | |
… | |
… | |
1108 | } |
1100 | } |
1109 | |
1101 | |
1110 | int |
1102 | int |
1111 | rxvt_fontset::find_font (uint32_t unicode) |
1103 | rxvt_fontset::find_font (uint32_t unicode) |
1112 | { |
1104 | { |
1113 | for (int i = 0; i < fonts.size (); i++) |
1105 | for (unsigned int i = 0; i < fonts.size (); i++) |
1114 | { |
1106 | { |
1115 | rxvt_font *f = fonts[i]; |
1107 | rxvt_font *f = fonts[i]; |
1116 | |
1108 | |
1117 | if (!f->loaded) |
1109 | if (!f->loaded) |
1118 | { |
1110 | { |