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 |
|
|
30 | #define GC r->TermWin.gc |
29 | #define TGC r->TermWin.gc |
31 | |
30 | |
32 | const struct rxvt_fallback_font { |
31 | const struct rxvt_fallback_font { |
33 | codeset cs; |
32 | codeset cs; |
34 | const char *name; |
33 | const char *name; |
35 | } fallback_fonts[] = { |
34 | } fallback_fonts[] = { |
36 | { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
35 | { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
37 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
36 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
38 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
37 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
39 | |
38 | |
40 | #if ENCODING_EU |
39 | #if ENCODING_EU |
41 | // cyrillic |
40 | // cyrillic |
42 | { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
41 | { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
43 | { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
42 | { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
44 | |
43 | |
45 | { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
44 | { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
46 | { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
45 | { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
47 | { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
46 | { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
48 | { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
47 | { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
49 | { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
48 | { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
50 | { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, |
49 | { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, |
51 | { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, |
50 | { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, |
52 | { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, |
51 | { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, |
53 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
52 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
54 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
53 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
55 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
54 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
56 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
55 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
57 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
56 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
58 | #endif |
57 | #endif |
59 | |
58 | |
60 | // japanese |
59 | // japanese |
61 | #if ENCODING_JP || ENCODING_JP_EXT |
60 | #if ENCODING_JP || ENCODING_JP_EXT |
62 | # if XFT |
61 | # if XFT |
63 | // prefer xft for complex scripts |
62 | // prefer xft for complex scripts |
64 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
63 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
65 | # endif |
64 | # endif |
66 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
65 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
67 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
66 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
68 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
67 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
|
|
68 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
|
|
69 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
|
|
70 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
69 | #endif |
71 | #endif |
70 | |
72 | |
71 | #if ENCODING_CN || ENCODING_CN_EXT |
73 | #if ENCODING_CN || ENCODING_CN_EXT |
72 | # if XFT |
74 | # if XFT |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
75 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
76 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
77 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
78 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
77 | # endif |
79 | # endif |
|
|
80 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
|
|
81 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
|
|
82 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
|
|
83 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
84 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
79 | { CS_CNS11643_1992_2, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
85 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
80 | { CS_CNS11643_1992_3, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
86 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
81 | { CS_CNS11643_1992_4, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
87 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
82 | { CS_CNS11643_1992_5, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
88 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
83 | { CS_CNS11643_1992_6, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
89 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
84 | { CS_CNS11643_1992_7, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
90 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
85 | { CS_CNS11643_1992_F, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
91 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
86 | #endif |
92 | #endif |
87 | |
93 | |
88 | #if XFT |
94 | #if XFT |
89 | { CS_UNICODE, "xft:Andale Mono" }, |
95 | { CS_UNICODE, "xft:Andale Mono" }, |
90 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
96 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
|
|
97 | { CS_UNICODE, "xft:FreeMono" }, |
91 | #endif |
98 | #endif |
92 | { CS_UNICODE, "-*-lucidatypewriter-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
99 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
100 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
|
|
101 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
93 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
102 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
94 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
103 | |
95 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
104 | #if UNICODE_3 && XFT |
|
|
105 | { CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters |
|
|
106 | #endif |
96 | |
107 | |
97 | { CS_UNKNOWN, 0 } |
108 | { CS_UNKNOWN, 0 } |
98 | }; |
109 | }; |
99 | |
110 | |
100 | ///////////////////////////////////////////////////////////////////////////// |
111 | ///////////////////////////////////////////////////////////////////////////// |
101 | |
112 | |
|
|
113 | #if XFT |
|
|
114 | rxvt_drawable::~rxvt_drawable () |
|
|
115 | { |
|
|
116 | if (xftdrawable) |
|
|
117 | XftDrawDestroy (xftdrawable); |
|
|
118 | } |
|
|
119 | |
|
|
120 | rxvt_drawable::operator XftDraw *() |
|
|
121 | { |
|
|
122 | if (!xftdrawable) |
|
|
123 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
|
|
124 | |
|
|
125 | return xftdrawable; |
|
|
126 | } |
|
|
127 | #endif |
|
|
128 | |
|
|
129 | ///////////////////////////////////////////////////////////////////////////// |
|
|
130 | |
102 | static void *enc_buf; |
131 | static void *enc_buf; |
103 | static uint32_t enc_len; |
132 | static uint32_t enc_len; |
104 | |
133 | |
105 | static inline void * |
134 | static inline void * |
106 | get_enc_buf (int len) |
135 | get_enc_buf (uint32_t len) |
107 | { |
136 | { |
108 | if (len > enc_len) |
137 | if (len > enc_len) |
109 | { |
138 | { |
110 | free (enc_buf); |
139 | free (enc_buf); |
111 | enc_buf = malloc (len); |
140 | enc_buf = malloc (len); |
|
|
141 | enc_len = len; |
112 | } |
142 | } |
113 | |
143 | |
114 | return enc_buf; |
144 | return enc_buf; |
115 | } |
145 | } |
116 | |
146 | |
117 | static const char * |
147 | static const char * |
118 | enc_char (const text_t *text, int len, codeset cs, bool &zero) |
148 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
119 | { |
149 | { |
120 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
150 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
121 | |
151 | |
122 | while (len--) |
152 | while (len--) |
123 | { |
153 | { |
… | |
… | |
134 | |
164 | |
135 | return (const char *)enc_buf; |
165 | return (const char *)enc_buf; |
136 | } |
166 | } |
137 | |
167 | |
138 | static const XChar2b * |
168 | static const XChar2b * |
139 | enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) |
169 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
140 | { |
170 | { |
141 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
171 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
142 | |
172 | |
143 | while (len--) |
173 | while (len--) |
144 | { |
174 | { |
… | |
… | |
159 | } |
189 | } |
160 | |
190 | |
161 | ///////////////////////////////////////////////////////////////////////////// |
191 | ///////////////////////////////////////////////////////////////////////////// |
162 | |
192 | |
163 | void |
193 | void |
164 | rxvt_font::clear_rect (int x, int y, int w, int h, int color) |
194 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
165 | { |
195 | { |
166 | if (color == Color_bg) |
196 | if (color == Color_bg) |
167 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
197 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
168 | else if (color >= 0) |
198 | else if (color >= 0) |
169 | { |
199 | { |
|
|
200 | #if XFT |
|
|
201 | XftDrawRect (d, &r->PixColors[color].c, x, y, w, h); |
|
|
202 | #else |
170 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
203 | XSetForeground (d.display->display, TGC, r->PixColors[color]); |
171 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
204 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
|
|
205 | #endif |
172 | } |
206 | } |
173 | } |
207 | } |
174 | |
208 | |
175 | static const char *linedraw_cmds[128] = { |
209 | #include "table/linedraw.h" |
176 | "1hH", "2hH", "1vV", "2vV", |
|
|
177 | 0, 0, 0, 0, |
|
|
178 | 0, 0, 0, 0, |
|
|
179 | "1HV", "2H1V", "1H2V", "2HV", |
|
|
180 | |
|
|
181 | // 2510 |
|
|
182 | "1hV", "2h1V", "1h2V", "2hV", |
|
|
183 | "1Hv", "2H1v", "1H2v", "2Hv", |
|
|
184 | "1hv", "2h1v", "1h2v", "2hv", |
|
|
185 | "1HvV", "2H1vV", "1HV2v", "1Hv2V", |
|
|
186 | |
|
|
187 | // 2520 |
|
|
188 | "1H2vV", "2Hv1V", "2HV1v", "2HvV", |
|
|
189 | "1hvV", "2h1vV", "1hV2v", "1hv2V", |
|
|
190 | "1h2vV", "2hv1V", "1v2hV", "2hvV", |
|
|
191 | "1hHV", "2h1HV", "2H1hV", "2hH1V", |
|
|
192 | |
|
|
193 | // 2530 |
|
|
194 | "1hH2V", "2hV1H", "1h2HV", "2hHV", |
|
|
195 | "1hHv", "1vH2h", "1hv2H", "1v2hH", |
|
|
196 | "1hH2v", "1H2hv", "1h2Hv", "2hHv", |
|
|
197 | "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", |
|
|
198 | |
|
|
199 | // 2540 |
|
|
200 | "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", |
|
|
201 | "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", |
|
|
202 | "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", |
|
|
203 | 0, 0, 0, 0, |
|
|
204 | |
|
|
205 | // 2550 |
|
|
206 | 0, 0, 0, 0, |
|
|
207 | 0, 0, 0, 0, |
|
|
208 | 0, 0, 0, 0, |
|
|
209 | 0, 0, 0, 0, |
|
|
210 | |
|
|
211 | // 2560 |
|
|
212 | 0, 0, 0, 0, |
|
|
213 | 0, 0, 0, 0, |
|
|
214 | 0, 0, 0, 0, |
|
|
215 | 0, 0, 0, 0, |
|
|
216 | |
|
|
217 | // 2570 |
|
|
218 | 0, "1a", "1b", "1ab", |
|
|
219 | "1h", "1v", "1H", "1V", |
|
|
220 | "2h", "2v", "2H", "2V", |
|
|
221 | "1h2H", "1v2V", "1H2h", "1V2v" |
|
|
222 | |
|
|
223 | // to be done |
|
|
224 | }; |
|
|
225 | |
210 | |
226 | struct rxvt_font_default : rxvt_font { |
211 | struct rxvt_font_default : rxvt_font { |
|
|
212 | |
227 | rxvt_fontprop properties () |
213 | rxvt_fontprop properties () |
228 | { |
214 | { |
229 | rxvt_fontprop p; |
215 | rxvt_fontprop p; |
230 | |
216 | |
231 | p.height = 1; |
217 | p.width = p.height = 1; |
232 | p.weight = rxvt_fontprop::medium; |
218 | p.weight = rxvt_fontprop::medium; |
233 | p.slant = rxvt_fontprop::roman; |
219 | p.slant = rxvt_fontprop::roman; |
234 | |
220 | |
235 | return p; |
221 | return p; |
236 | } |
222 | } |
… | |
… | |
238 | bool load (const rxvt_fontprop &prop) |
224 | bool load (const rxvt_fontprop &prop) |
239 | { |
225 | { |
240 | width = 1; height = 1; |
226 | width = 1; height = 1; |
241 | ascent = 1; descent = 0; |
227 | ascent = 1; descent = 0; |
242 | |
228 | |
|
|
229 | set_name (strdup ("built-in pseudofont")); |
|
|
230 | |
243 | return true; |
231 | return true; |
244 | } |
232 | } |
245 | |
233 | |
246 | bool has_codepoint (uint32_t unicode) |
234 | bool has_codepoint (unicode_t unicode) |
247 | { |
235 | { |
248 | if (unicode <= 0x001f) |
236 | if (unicode <= 0x001f) |
249 | return true; |
237 | return true; |
250 | if (unicode >= 0x0080 && unicode <= 0x009f) |
238 | |
|
|
239 | if (unicode <= 0x007f) |
|
|
240 | return false; |
|
|
241 | |
|
|
242 | if (unicode <= 0x009f) |
251 | return true; |
243 | return true; |
252 | |
244 | |
253 | if (unicode >= 0x2500 && unicode <= 0x257f |
245 | if (unicode >= 0x2500 && unicode <= 0x259f) |
254 | && linedraw_cmds[unicode - 0x2500]) |
246 | return true; |
|
|
247 | |
|
|
248 | if (IS_COMPOSE (unicode)) |
255 | return true; |
249 | return true; |
256 | |
250 | |
257 | switch (unicode) |
251 | switch (unicode) |
258 | { |
252 | { |
259 | case ZERO_WIDTH_CHAR: |
253 | case ZERO_WIDTH_CHAR: |
… | |
… | |
261 | } |
255 | } |
262 | |
256 | |
263 | return false; |
257 | return false; |
264 | } |
258 | } |
265 | |
259 | |
266 | void draw (int x, int y, |
260 | void draw (rxvt_drawable &d, int x, int y, |
267 | const text_t *text, int len, |
261 | const text_t *text, int len, |
268 | int fg, int bg); |
262 | int fg, int bg); |
269 | }; |
263 | }; |
270 | |
264 | |
271 | void |
265 | void |
272 | rxvt_font_default::draw (int x, int y, |
266 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
273 | const text_t *text, int len, |
267 | const text_t *text, int len, |
274 | int fg, int bg) |
268 | int fg, int bg) |
275 | { |
269 | { |
276 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
270 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
277 | |
271 | |
278 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
272 | XSetForeground (d.display->display, TGC, r->PixColors[fg]); |
279 | |
273 | |
280 | while (len--) |
274 | while (len--) |
281 | { |
275 | { |
|
|
276 | #if ENABLE_COMBINING |
|
|
277 | compose_char *cc; |
|
|
278 | #endif |
282 | text_t t = *text++; |
279 | text_t t = *text++; |
283 | |
280 | |
284 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
281 | if (0x2500 <= t && t <= 0x259f) |
|
|
282 | { |
|
|
283 | uint16_t offs = linedraw_offs[t - 0x2500]; |
|
|
284 | uint32_t *a = linedraw_command + (offs >> 4); |
|
|
285 | uint32_t *b = a + (offs & 15); |
|
|
286 | |
|
|
287 | int W = r->TermWin.fwidth; |
|
|
288 | int H = r->TermWin.fheight; |
|
|
289 | |
|
|
290 | int x_[16]; |
|
|
291 | int y_[16]; |
|
|
292 | |
|
|
293 | for (int i = 0; i <= 8; i++) |
285 | { |
294 | { |
286 | const char *p = linedraw_cmds[t - 0x2500]; |
295 | x_[i] = x + ((W-1) * i + (i*7/8)) / 8; |
|
|
296 | y_[i] = y + ((H-1) * i + (i*7/8)) / 8; |
|
|
297 | } |
287 | |
298 | |
288 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
299 | x_[10] = x + (W - 1) / 2; x_[9] = x_[10] - 1; x_[11] = x_[10] + 1; |
289 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; |
300 | y_[10] = y + (H - 1) / 2; y_[9] = y_[10] - 1; y_[11] = y_[10] + 1; |
290 | |
301 | |
291 | XGCValues gcv; |
302 | XGCValues gcv; |
292 | |
303 | |
|
|
304 | gcv.cap_style = CapButt; |
|
|
305 | gcv.line_width = 0; |
|
|
306 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
|
|
307 | |
293 | while (*p) |
308 | while (a < b) |
294 | { |
309 | { |
|
|
310 | uint32_t command = *a++; |
|
|
311 | |
|
|
312 | int op = (command >> 24) & 255; |
|
|
313 | int a = (command >> 20) & 15; |
|
|
314 | int b = (command >> 16) & 15; |
|
|
315 | int x1 = x_[(command >> 12) & 15]; |
|
|
316 | int y1 = y_[(command >> 8) & 15]; |
|
|
317 | int x2 = x_[(command >> 4) & 15]; |
|
|
318 | int y2 = y_[(command >> 0) & 15]; |
|
|
319 | |
295 | switch (*p++) |
320 | switch (op) |
296 | { |
321 | { |
297 | case '1': |
322 | case 0: // line |
298 | gcv.line_width = 0; |
323 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
299 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
300 | break; |
324 | break; |
301 | |
325 | |
302 | case '2': |
326 | case 1: // rectangle, possibly stippled |
|
|
327 | if (a) |
|
|
328 | { |
|
|
329 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
|
|
330 | |
|
|
331 | gcv.fill_style = FillStippled; |
|
|
332 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
|
|
333 | gcv.ts_x_origin = x; |
|
|
334 | gcv.ts_y_origin = y; |
|
|
335 | |
|
|
336 | XChangeGC (d.display->display, TGC, |
|
|
337 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
|
|
338 | &gcv); |
|
|
339 | } |
|
|
340 | |
|
|
341 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
|
|
342 | |
|
|
343 | if (a) |
|
|
344 | { |
|
|
345 | XFreePixmap (d.display->display, gcv.stipple); |
303 | gcv.line_width = 2; |
346 | gcv.stipple = 0; |
304 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
347 | gcv.fill_style = FillSolid; |
|
|
348 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
|
|
349 | } |
305 | break; |
350 | break; |
306 | |
351 | case 2: // arc |
307 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
352 | XDrawArc (d.display->display, d, TGC, |
308 | case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
353 | x1 - W/2, y1 - H/2, W-1, H-1, |
309 | case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
354 | (a - 1) * 90*64, (b - 1) * 90*64); |
310 | case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
355 | break; |
311 | case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
|
|
312 | case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
|
|
313 | } |
356 | } |
314 | } |
357 | } |
315 | |
358 | } |
316 | gcv.line_width = 0; |
359 | #if ENABLE_COMBINING |
317 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
360 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
318 | } |
361 | { |
|
|
362 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
|
|
363 | f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg); |
|
|
364 | if (cc->c2 != NOCHAR) |
|
|
365 | { |
|
|
366 | // prefer font of first character, for no good reasons |
|
|
367 | rxvt_font *f2 = f1->has_codepoint (cc->c2) |
|
|
368 | ? f1 |
|
|
369 | : (*fs)[fs->find_font (cc->c2)]; |
|
|
370 | |
|
|
371 | f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1); |
|
|
372 | } |
|
|
373 | } |
|
|
374 | #endif |
319 | else |
375 | else |
320 | switch (*text++) |
376 | switch (t) |
321 | { |
377 | { |
322 | case NOCHAR: |
|
|
323 | case ZERO_WIDTH_CHAR: |
378 | case ZERO_WIDTH_CHAR: |
324 | break; |
379 | break; |
|
|
380 | |
325 | default: |
381 | default: |
326 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
382 | int w = 0; |
|
|
383 | while (len > 0 && *text == NOCHAR) |
|
|
384 | { |
|
|
385 | ++text; |
|
|
386 | --len; |
|
|
387 | w += r->TermWin.fwidth; |
|
|
388 | } |
|
|
389 | |
|
|
390 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
|
|
391 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
|
|
392 | x += w; |
327 | } |
393 | } |
328 | |
394 | |
329 | x += r->TermWin.fwidth; |
395 | x += r->TermWin.fwidth; |
330 | } |
396 | } |
331 | } |
397 | } |
… | |
… | |
336 | rxvt_font_x11 () { f = 0; } |
402 | rxvt_font_x11 () { f = 0; } |
337 | |
403 | |
338 | void clear (); |
404 | void clear (); |
339 | |
405 | |
340 | rxvt_fontprop properties (); |
406 | rxvt_fontprop properties (); |
341 | rxvt_fontprop properties (XFontStruct *f); |
|
|
342 | |
407 | |
343 | bool load (const rxvt_fontprop &prop); |
408 | bool load (const rxvt_fontprop &prop); |
344 | |
409 | |
345 | bool has_codepoint (uint32_t unicode); |
410 | bool has_codepoint (unicode_t unicode); |
346 | |
411 | |
347 | void draw (int x, int y, |
412 | void draw (rxvt_drawable &d, int x, int y, |
348 | const text_t *text, int len, |
413 | const text_t *text, int len, |
349 | int fg, int bg); |
414 | int fg, int bg); |
350 | |
415 | |
351 | XFontStruct *f; |
416 | XFontStruct *f; |
352 | codeset cs; |
417 | codeset cs; |
353 | bool enc2b, encm; |
418 | bool enc2b, encm; |
354 | |
419 | |
355 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
420 | char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
|
|
421 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
|
|
422 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
|
|
423 | bool set_properties (rxvt_fontprop &p, const char *name); |
356 | }; |
424 | }; |
357 | |
425 | |
358 | const char * |
426 | char * |
359 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
427 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
360 | { |
428 | { |
361 | unsigned long value; |
429 | unsigned long value; |
362 | |
430 | |
363 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
431 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
364 | return XGetAtomName (DISPLAY, value); |
432 | return XGetAtomName (DISPLAY, value); |
365 | else |
433 | else |
366 | return repl; |
434 | return rxvt_strdup (repl); |
367 | } |
435 | } |
368 | |
436 | |
369 | rxvt_fontprop |
437 | rxvt_fontprop |
370 | rxvt_font_x11::properties () |
438 | rxvt_font_x11::properties () |
371 | { |
439 | { |
372 | return properties (f); |
|
|
373 | } |
|
|
374 | |
|
|
375 | rxvt_fontprop |
|
|
376 | rxvt_font_x11::properties (XFontStruct *f) |
|
|
377 | { |
|
|
378 | rxvt_fontprop p; |
440 | rxvt_fontprop p; |
|
|
441 | set_properties (p, f); |
|
|
442 | return p; |
|
|
443 | } |
379 | |
444 | |
380 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
445 | bool |
381 | const char *slant = get_property (f, "SLANT", "r"); |
446 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
382 | |
447 | { |
|
|
448 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
383 | p.height = height; |
449 | p.height = height; |
384 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
450 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
385 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
451 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
386 | |
452 | |
387 | return p; |
453 | return true; |
|
|
454 | } |
|
|
455 | |
|
|
456 | bool |
|
|
457 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
|
|
458 | { |
|
|
459 | unsigned long height; |
|
|
460 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
|
|
461 | return false; |
|
|
462 | |
|
|
463 | unsigned long avgwidth; |
|
|
464 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
|
|
465 | avgwidth = 0; |
|
|
466 | |
|
|
467 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
468 | char *slant = get_property (f, "SLANT", "r"); |
|
|
469 | |
|
|
470 | set_properties (p, height, weight, slant, avgwidth); |
|
|
471 | |
|
|
472 | free (weight); |
|
|
473 | free (slant); |
|
|
474 | |
|
|
475 | return true; |
|
|
476 | } |
|
|
477 | |
|
|
478 | bool |
|
|
479 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
|
|
480 | { |
|
|
481 | int slashes = 0; |
|
|
482 | const char *comp[13]; |
|
|
483 | |
|
|
484 | for (const char *c = name; *c; c++) |
|
|
485 | if (*c == '-') |
|
|
486 | { |
|
|
487 | comp[slashes++] = c + 1; |
|
|
488 | if (slashes >= 13) |
|
|
489 | break; |
|
|
490 | } |
|
|
491 | |
|
|
492 | /* can we short-circuit the costly XLoadQueryFont? */ |
|
|
493 | if (slashes >= 13 |
|
|
494 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
|
|
495 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
|
|
496 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
|
|
497 | |
|
|
498 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
|
|
499 | |
|
|
500 | if (f) |
|
|
501 | { |
|
|
502 | // the font should really exist now. if not, we have a problem |
|
|
503 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
|
|
504 | // in that case, just return garbage. |
|
|
505 | bool ret = set_properties (p, f); |
|
|
506 | XFreeFont (DISPLAY, f); |
|
|
507 | return ret; |
|
|
508 | } |
|
|
509 | else |
|
|
510 | return false; |
|
|
511 | } |
|
|
512 | |
|
|
513 | // fix the size of scalable fonts |
|
|
514 | static void |
|
|
515 | fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop) |
|
|
516 | { |
|
|
517 | int slashes = 0; |
|
|
518 | const char *size; |
|
|
519 | |
|
|
520 | for (const char *c = name; *c; c++) |
|
|
521 | if (*c == '-') |
|
|
522 | { |
|
|
523 | if (slashes == 6) |
|
|
524 | size = c + 1; |
|
|
525 | |
|
|
526 | if (++slashes >= 13) |
|
|
527 | break; |
|
|
528 | } |
|
|
529 | |
|
|
530 | if (slashes >= 13 && size[0] == '0') |
|
|
531 | { |
|
|
532 | strncpy (buf, name, size - name); |
|
|
533 | buf += size - name; |
|
|
534 | buf += sprintf (buf, "%d", prop.height); |
|
|
535 | strcpy (buf, size + 1); |
|
|
536 | } |
|
|
537 | else |
|
|
538 | strcpy (buf, name); |
388 | } |
539 | } |
389 | |
540 | |
390 | bool |
541 | bool |
391 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
542 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
392 | { |
543 | { |
393 | clear (); |
544 | clear (); |
394 | |
545 | |
395 | char **list; |
546 | char **list; |
396 | int count; |
547 | int count; |
397 | XFontStruct *info; |
|
|
398 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
548 | list = XListFonts (DISPLAY, name, 512, &count); |
|
|
549 | set_name (0); |
399 | |
550 | |
400 | if (!list) |
551 | if (!list) |
401 | return false; |
552 | return false; |
402 | |
553 | |
403 | int bestdiff = 0x7fffffff; |
554 | int bestdiff = 0x7fffffff; |
404 | XFontStruct *best = 0; |
|
|
405 | for (int i = 0; i < count; i++) |
555 | for (int i = 0; i < count; i++) |
406 | { |
556 | { |
407 | XFontStruct *f = info + i; |
557 | rxvt_fontprop p; |
|
|
558 | char fname[1024]; |
|
|
559 | fix_scalable (fname, list[i], prop); |
408 | |
560 | |
|
|
561 | if (!set_properties (p, fname)) |
|
|
562 | continue; |
|
|
563 | |
409 | if (f->ascent + f->descent <= prop.height) // weed out too large fonts |
564 | if (p.height > prop.height) // weed out too large fonts |
410 | { |
565 | continue; |
411 | rxvt_fontprop p = properties (f); |
566 | |
412 | int diff = (prop.height - f->ascent + f->descent) * 32 |
567 | int diff = (prop.height - p.height) * 32 |
413 | + abs (prop.weight - p.weight) |
568 | + abs (prop.weight - p.weight) |
414 | + abs (prop.slant - p.slant ); |
569 | + abs (prop.slant - p.slant ); |
415 | |
570 | |
416 | if (!best // compare against best found so far |
571 | if (!name // compare against best found so far |
417 | || diff < bestdiff) |
572 | || diff < bestdiff) |
418 | { |
573 | { |
419 | best = f; |
574 | set_name (strdup (fname)); |
420 | bestdiff = diff; |
575 | bestdiff = diff; |
421 | } |
576 | } |
422 | } |
|
|
423 | } |
577 | } |
424 | |
578 | |
425 | set_name (strdup (list[best - info])); |
579 | XFreeFontNames (list); |
426 | |
580 | |
427 | XFreeFontInfo (list, info, count); |
581 | if (!name) |
|
|
582 | return false; |
428 | |
583 | |
429 | f = XLoadQueryFont (DISPLAY, name); |
584 | f = XLoadQueryFont (DISPLAY, name); |
430 | |
585 | |
431 | if (!f) |
586 | if (!f) |
432 | return false; |
587 | return false; |
433 | |
588 | |
434 | unsigned long value; |
|
|
435 | |
|
|
436 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
589 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
437 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
590 | char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
438 | |
591 | |
439 | if (registry && encoding) |
592 | if (registry && encoding) |
440 | { |
593 | { |
441 | char charset[64]; |
594 | char charset[64]; |
442 | snprintf (charset, 64, "%s-%s", registry, encoding); |
595 | snprintf (charset, 64, "%s-%s", registry, encoding); |
… | |
… | |
455 | if (*charset++ == '-' && !--count) |
608 | if (*charset++ == '-' && !--count) |
456 | break; |
609 | break; |
457 | |
610 | |
458 | cs = codeset_from_name (charset); |
611 | cs = codeset_from_name (charset); |
459 | } |
612 | } |
|
|
613 | |
|
|
614 | free (registry); |
|
|
615 | free (encoding); |
460 | |
616 | |
461 | if (cs == CS_UNICODE) |
617 | if (cs == CS_UNICODE) |
462 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
618 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
463 | |
619 | |
464 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
620 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
… | |
… | |
514 | f = 0; |
670 | f = 0; |
515 | } |
671 | } |
516 | } |
672 | } |
517 | |
673 | |
518 | bool |
674 | bool |
519 | rxvt_font_x11::has_codepoint (uint32_t unicode) |
675 | rxvt_font_x11::has_codepoint (unicode_t unicode) |
520 | { |
676 | { |
521 | uint32_t ch = FROM_UNICODE (cs, unicode); |
677 | uint32_t ch = FROM_UNICODE (cs, unicode); |
522 | |
678 | |
523 | if (ch == NOCHAR) |
679 | if (ch == NOCHAR) |
524 | return false; |
680 | return false; |
… | |
… | |
526 | /* check wether the character exists in _this_ font. horrible. */ |
682 | /* check wether the character exists in _this_ font. horrible. */ |
527 | XCharStruct *xcs; |
683 | XCharStruct *xcs; |
528 | |
684 | |
529 | if (encm) |
685 | if (encm) |
530 | { |
686 | { |
531 | int byte1 = ch >> 8; |
687 | unsigned char byte1 = ch >> 8; |
532 | int byte2 = ch & 255; |
688 | unsigned char byte2 = ch & 255; |
533 | |
689 | |
534 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
690 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
535 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
691 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
536 | return false; |
692 | return false; |
537 | |
693 | |
… | |
… | |
560 | |
716 | |
561 | return true; |
717 | return true; |
562 | } |
718 | } |
563 | |
719 | |
564 | void |
720 | void |
565 | rxvt_font_x11::draw (int x, int y, |
721 | rxvt_font_x11::draw (rxvt_drawable &d, int x, int y, |
566 | const text_t *text, int len, |
722 | const text_t *text, int len, |
567 | int fg, int bg) |
723 | int fg, int bg) |
568 | { |
724 | { |
569 | // this looks like a mess /. |
725 | // this looks like a mess /. |
570 | // and it is a mess /. |
726 | // and it is a mess /. |
… | |
… | |
577 | |
733 | |
578 | int base = r->TermWin.fbase; |
734 | int base = r->TermWin.fbase; |
579 | |
735 | |
580 | XGCValues v; |
736 | XGCValues v; |
581 | v.foreground = r->PixColors[fg]; |
737 | v.foreground = r->PixColors[fg]; |
582 | v.background = r->PixColors[bg]; |
|
|
583 | v.font = f->fid; |
738 | v.font = f->fid; |
584 | |
739 | |
585 | if (enc2b) |
740 | if (enc2b) |
586 | { |
741 | { |
587 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
742 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
588 | |
743 | |
589 | if (bg == Color_bg && !slow) |
744 | if (bg == Color_bg && !slow) |
590 | { |
745 | { |
|
|
746 | v.background = r->PixColors[bg]; |
591 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
747 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
592 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
748 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
593 | } |
749 | } |
594 | else |
750 | else |
595 | { |
751 | { |
596 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
752 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
597 | |
753 | |
598 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
754 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
599 | |
755 | |
600 | if (slow) |
756 | if (slow) |
601 | { |
757 | { |
602 | do |
758 | do |
603 | { |
759 | { |
604 | if (xc->byte1 || xc->byte2) |
760 | if (xc->byte1 || xc->byte2) |
605 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
761 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
606 | |
762 | |
607 | x += r->TermWin.fwidth; |
763 | x += r->TermWin.fwidth; |
608 | xc++; len--; |
764 | xc++; len--; |
609 | } |
765 | } |
610 | while (len); |
766 | while (len); |
611 | } |
767 | } |
612 | else |
768 | else |
613 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
769 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
614 | } |
770 | } |
615 | } |
771 | } |
616 | else |
772 | else |
617 | { |
773 | { |
618 | const char *xc = enc_char (text, len, cs, slow); |
774 | const char *xc = enc_char (text, len, cs, slow); |
619 | |
775 | |
620 | if (bg == Color_bg && !slow) |
776 | if (bg == Color_bg && !slow) |
621 | { |
777 | { |
|
|
778 | v.background = r->PixColors[bg]; |
622 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
779 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
623 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
780 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
624 | } |
781 | } |
625 | else |
782 | else |
626 | { |
783 | { |
627 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
784 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
628 | |
785 | |
629 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
786 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
630 | |
787 | |
631 | if (slow) |
788 | if (slow) |
632 | { |
789 | { |
633 | do |
790 | do |
634 | { |
791 | { |
635 | if (*xc) |
792 | if (*xc) |
636 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
793 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
637 | |
794 | |
638 | x += r->TermWin.fwidth; |
795 | x += r->TermWin.fwidth; |
639 | xc++; len--; |
796 | xc++; len--; |
640 | } |
797 | } |
641 | while (len); |
798 | while (len); |
642 | } |
799 | } |
643 | else |
800 | else |
644 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
801 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
645 | } |
802 | } |
646 | } |
803 | } |
647 | } |
804 | } |
648 | |
805 | |
649 | ///////////////////////////////////////////////////////////////////////////// |
806 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
654 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
811 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
655 | #define SWATHBITS 8 |
812 | #define SWATHBITS 8 |
656 | #endif |
813 | #endif |
657 | |
814 | |
658 | struct rxvt_font_xft : rxvt_font { |
815 | struct rxvt_font_xft : rxvt_font { |
659 | #if 0 |
|
|
660 | enum { |
|
|
661 | SWATHCOUNT = 1 << (21 - UNIBITS), |
|
|
662 | SWATHSIZE = 1 << (SWATHBITS - 5) |
|
|
663 | }; |
|
|
664 | typedef uint32_t swath[SWATHSIZE]; |
|
|
665 | |
|
|
666 | swath *cvr[SWATHCOUNT]; |
|
|
667 | #endif |
|
|
668 | |
|
|
669 | #if 0 |
|
|
670 | void gen_coverage_swath (unsigned int page); |
|
|
671 | |
|
|
672 | bool has_char (uint32_t ch) |
|
|
673 | { |
|
|
674 | unsigned int page = ch >> SWATHBITS; |
|
|
675 | unsigned int idx = ch & ((1 << SWATHBITS) - 1); |
|
|
676 | |
|
|
677 | if (page >= SWATHCOUNT) |
|
|
678 | return false; |
|
|
679 | |
|
|
680 | if (!cvr[page]) gen_coverage_swath (page); |
|
|
681 | |
|
|
682 | return cvr[page][idx >> 5] & (1 << (idx & 31)); |
|
|
683 | } |
|
|
684 | #endif |
|
|
685 | rxvt_font_xft () { f = 0; d = 0; } |
816 | rxvt_font_xft () { f = 0; } |
686 | |
817 | |
687 | void clear (); |
818 | void clear (); |
688 | |
819 | |
689 | rxvt_fontprop properties (); |
820 | rxvt_fontprop properties (); |
690 | |
821 | |
691 | bool load (const rxvt_fontprop &prop); |
822 | bool load (const rxvt_fontprop &prop); |
692 | |
823 | |
693 | void draw (int x, int y, |
824 | void draw (rxvt_drawable &d, int x, int y, |
694 | const text_t *text, int len, |
825 | const text_t *text, int len, |
695 | int fg, int bg); |
826 | int fg, int bg); |
696 | |
827 | |
697 | bool has_codepoint (uint32_t unicode); |
828 | bool has_codepoint (unicode_t unicode); |
698 | |
829 | |
699 | protected: |
830 | protected: |
700 | XftFont *f; |
831 | XftFont *f; |
701 | XftDraw *d; |
|
|
702 | |
|
|
703 | #if 0 |
|
|
704 | virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0; |
|
|
705 | void set_swath (uint32_t ch) |
|
|
706 | { |
|
|
707 | cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1)); |
|
|
708 | } |
|
|
709 | #endif |
|
|
710 | }; |
832 | }; |
711 | |
833 | |
712 | void |
834 | void |
713 | rxvt_font_xft::clear () |
835 | rxvt_font_xft::clear () |
714 | { |
836 | { |
715 | if (f) |
837 | if (f) |
716 | { |
838 | { |
717 | XftFontClose (DISPLAY, f); |
839 | XftFontClose (DISPLAY, f); |
718 | f = 0; |
840 | f = 0; |
719 | } |
841 | } |
720 | |
|
|
721 | if (d) |
|
|
722 | { |
|
|
723 | XftDrawDestroy (d); |
|
|
724 | d = 0; |
|
|
725 | } |
|
|
726 | |
|
|
727 | #if 0 |
|
|
728 | for (int i = 0; i < SWATHCOUNT; i++) |
|
|
729 | delete cvr[i]; |
|
|
730 | #endif |
|
|
731 | } |
842 | } |
732 | |
843 | |
733 | rxvt_fontprop |
844 | rxvt_fontprop |
734 | rxvt_font_xft::properties () |
845 | rxvt_font_xft::properties () |
735 | { |
846 | { |
736 | rxvt_fontprop p; |
847 | rxvt_fontprop p; |
737 | |
848 | |
738 | FT_Face face = XftLockFace (f); |
849 | FT_Face face = XftLockFace (f); |
739 | |
850 | |
740 | p.height = height; |
851 | p.width = width; p.height = height; |
741 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
852 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
742 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
853 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
743 | |
854 | |
744 | XftUnlockFace (f); |
855 | XftUnlockFace (f); |
745 | |
856 | |
… | |
… | |
767 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
878 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
768 | |
879 | |
769 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
880 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
770 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
881 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
771 | |
882 | |
|
|
883 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
|
|
884 | // clip width, we can't do better, or can we? |
|
|
885 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
|
|
886 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
|
|
887 | #endif |
|
|
888 | |
772 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
889 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
773 | |
890 | |
774 | XftResult result; |
891 | XftResult result; |
775 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
892 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
776 | |
893 | |
… | |
… | |
779 | if (!match) |
896 | if (!match) |
780 | return false; |
897 | return false; |
781 | |
898 | |
782 | f = XftFontOpenPattern (DISPLAY, match); |
899 | f = XftFontOpenPattern (DISPLAY, match); |
783 | |
900 | |
784 | FcPatternDestroy (match); |
|
|
785 | |
|
|
786 | if (!f) |
901 | if (!f) |
|
|
902 | { |
|
|
903 | FcPatternDestroy (match); |
787 | return false; |
904 | return false; |
|
|
905 | } |
788 | |
906 | |
789 | FT_Face face = XftLockFace (f); |
907 | FT_Face face = XftLockFace (f); |
790 | |
908 | |
791 | slow = !FT_IS_FIXED_WIDTH (face); |
909 | slow = !FT_IS_FIXED_WIDTH (face); |
792 | |
910 | |
… | |
… | |
827 | XftUnlockFace (f); |
945 | XftUnlockFace (f); |
828 | |
946 | |
829 | return true; |
947 | return true; |
830 | } |
948 | } |
831 | |
949 | |
832 | #if 0 |
|
|
833 | void rxvt_font::gen_coverage_swath (unsigned int page) |
|
|
834 | { |
|
|
835 | cvr[page] = new swath; |
|
|
836 | |
|
|
837 | for (int i = 0; i < SWATHSIZE; i++) |
|
|
838 | cvr[page][i] = 0; |
|
|
839 | |
|
|
840 | populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1); |
|
|
841 | } |
|
|
842 | #endif |
|
|
843 | |
|
|
844 | bool |
950 | bool |
845 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
951 | rxvt_font_xft::has_codepoint (unicode_t unicode) |
846 | { |
952 | { |
847 | return XftCharExists (DISPLAY, f, unicode); |
953 | return XftCharExists (DISPLAY, f, unicode); |
848 | } |
954 | } |
849 | |
955 | |
850 | void |
956 | void |
851 | rxvt_font_xft::draw (int x, int y, |
957 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
852 | const text_t *text, int len, |
958 | const text_t *text, int len, |
853 | int fg, int bg) |
959 | int fg, int bg) |
854 | { |
960 | { |
855 | if (!d) |
|
|
856 | { |
|
|
857 | dR; |
|
|
858 | d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP); |
|
|
859 | } |
|
|
860 | |
|
|
861 | if (bg >= 0 && bg != Color_bg) |
|
|
862 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
|
|
863 | else |
|
|
864 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
961 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
865 | |
962 | |
866 | if (!slow && width == r->TermWin.fwidth) |
963 | if (!slow && width == r->TermWin.fwidth && 0) |
867 | { |
964 | { |
868 | if (sizeof (text_t) == sizeof (FcChar16)) |
965 | if (sizeof (text_t) == sizeof (FcChar16)) |
869 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
966 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
870 | else |
967 | else |
871 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
968 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
… | |
… | |
874 | { |
971 | { |
875 | while (len) |
972 | while (len) |
876 | { |
973 | { |
877 | if (*text != NOCHAR && *text != ' ') |
974 | if (*text != NOCHAR && *text != ' ') |
878 | { |
975 | { |
|
|
976 | int fwidth = r->TermWin.fwidth; |
|
|
977 | if (len >= 2 && text[1] == NOCHAR) |
|
|
978 | fwidth *= 2; |
|
|
979 | |
|
|
980 | XGlyphInfo extents; |
879 | if (sizeof (text_t) == sizeof (FcChar16)) |
981 | if (sizeof (text_t) == sizeof (FcChar16)) |
880 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
982 | { |
|
|
983 | XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents); |
|
|
984 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
985 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
|
|
986 | } |
881 | else |
987 | else |
882 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
988 | { |
|
|
989 | XGlyphInfo extents; |
|
|
990 | XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents); |
|
|
991 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
992 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
|
|
993 | } |
883 | } |
994 | } |
884 | |
995 | |
885 | x += r->TermWin.fwidth; |
996 | x += r->TermWin.fwidth; |
886 | text++; |
997 | text++; |
887 | len--; |
998 | len--; |
… | |
… | |
891 | #endif |
1002 | #endif |
892 | |
1003 | |
893 | ///////////////////////////////////////////////////////////////////////////// |
1004 | ///////////////////////////////////////////////////////////////////////////// |
894 | |
1005 | |
895 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1006 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
896 | #ifdef EXPLICIT_CONTEXT |
1007 | : r (r), fontdesc (0) |
897 | : r(r) |
|
|
898 | #endif |
|
|
899 | { |
1008 | { |
900 | clear (); |
1009 | clear (); |
901 | } |
1010 | } |
902 | |
1011 | |
903 | rxvt_fontset::~rxvt_fontset () |
1012 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
906 | } |
1015 | } |
907 | |
1016 | |
908 | void |
1017 | void |
909 | rxvt_fontset::clear () |
1018 | rxvt_fontset::clear () |
910 | { |
1019 | { |
911 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
1020 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
912 | FONT_UNREF (*i); |
1021 | FONT_UNREF (*i); |
|
|
1022 | |
|
|
1023 | free (fontdesc); fontdesc = 0; |
913 | |
1024 | |
914 | fonts.clear (); |
1025 | fonts.clear (); |
915 | base_id = 0; |
1026 | base_id = 0; |
916 | base_prop.height = 0x7fffffff; |
1027 | base_prop.height = 0x7fffffff; |
917 | base_prop.weight = rxvt_fontprop::medium; |
1028 | base_prop.weight = rxvt_fontprop::medium; |
… | |
… | |
943 | f = new rxvt_font_x11; |
1054 | f = new rxvt_font_x11; |
944 | } |
1055 | } |
945 | else |
1056 | else |
946 | f = new rxvt_font_x11; |
1057 | f = new rxvt_font_x11; |
947 | |
1058 | |
|
|
1059 | f->fs = this; |
948 | f->set_term (r); |
1060 | f->set_term (r); |
949 | f->set_name (strdup (name)); |
1061 | f->set_name (strdup (name)); |
950 | |
1062 | |
951 | f->cs = cs; |
1063 | f->cs = cs; |
952 | f->loaded = false; |
1064 | f->loaded = false; |
… | |
… | |
970 | |
1082 | |
971 | if (*desc == '[') |
1083 | if (*desc == '[') |
972 | { |
1084 | { |
973 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1085 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
974 | |
1086 | |
975 | const char *extra = desc++; |
1087 | //const char *extra = desc++; // not yet used |
976 | |
1088 | |
977 | desc = strchr (desc, ']'); |
1089 | desc = strchr (desc, ']'); |
978 | |
1090 | |
979 | if (!desc) |
1091 | if (!desc) |
980 | { |
1092 | { |
… | |
… | |
1019 | } |
1131 | } |
1020 | |
1132 | |
1021 | return true; |
1133 | return true; |
1022 | } |
1134 | } |
1023 | |
1135 | |
1024 | void |
1136 | bool |
1025 | rxvt_fontset::populate (const char *desc) |
1137 | rxvt_fontset::populate (const char *desc) |
1026 | { |
1138 | { |
1027 | clear (); |
1139 | clear (); |
|
|
1140 | |
|
|
1141 | fontdesc = strdup (desc); |
1028 | |
1142 | |
1029 | fonts.push_back (new_font (0, CS_UNICODE)); |
1143 | fonts.push_back (new_font (0, CS_UNICODE)); |
1030 | realize_font (0); |
1144 | realize_font (0); |
1031 | |
1145 | |
1032 | add_fonts (desc); |
1146 | add_fonts (desc); |
1033 | |
1147 | |
1034 | if (!base_id) |
1148 | if (!base_id) |
1035 | base_id = 1; |
1149 | base_id = 1; |
1036 | |
1150 | |
1037 | // we currently need a base-font, no matter what |
1151 | // we currently need a base-font, no matter what |
1038 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1152 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1039 | { |
1153 | { |
|
|
1154 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
1040 | add_fonts ("fixed"); |
1155 | add_fonts ("fixed"); |
1041 | base_id = fonts.size () - 1; |
1156 | base_id = fonts.size () - 1; |
1042 | } |
1157 | } |
1043 | |
1158 | |
1044 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1159 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1045 | { |
1160 | return false; |
1046 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
|
|
1047 | exit (1); |
|
|
1048 | } |
|
|
1049 | |
1161 | |
1050 | base_prop = fonts[base_id]->properties (); |
1162 | base_prop = fonts[base_id]->properties (); |
|
|
1163 | |
|
|
1164 | return true; |
1051 | } |
1165 | } |
1052 | |
1166 | |
1053 | int |
1167 | int |
1054 | rxvt_fontset::find_font (uint32_t unicode) |
1168 | rxvt_fontset::find_font (unicode_t unicode, bool bold) |
1055 | { |
1169 | { |
1056 | for (int i = 0; i < fonts.size (); i++) |
1170 | for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii |
|
|
1171 | i < fonts.size (); |
|
|
1172 | i++) |
1057 | { |
1173 | { |
1058 | rxvt_font *f = fonts[i]; |
1174 | rxvt_font *f = fonts[i]; |
1059 | |
1175 | |
1060 | if (!f->loaded) |
1176 | if (!f->loaded) |
1061 | { |
1177 | { |
… | |
… | |
1064 | |
1180 | |
1065 | if (!realize_font (i)) |
1181 | if (!realize_font (i)) |
1066 | goto next_font; |
1182 | goto next_font; |
1067 | } |
1183 | } |
1068 | |
1184 | |
|
|
1185 | if (f->cs == CS_UNKNOWN) |
|
|
1186 | goto next_font; |
|
|
1187 | |
|
|
1188 | if (bold && f->properties ().weight < rxvt_fontprop::bold) |
|
|
1189 | goto next_font; |
|
|
1190 | |
1069 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
1191 | if (f->has_codepoint (unicode)) |
1070 | return i; |
1192 | return i; |
1071 | |
1193 | |
1072 | next_font: |
1194 | next_font: |
1073 | if (i == fonts.size () - 1 && fallback->name) |
1195 | if (i == fonts.size () - 1 && fallback->name) |
1074 | { |
1196 | { |
… | |
… | |
1076 | fallback++; |
1198 | fallback++; |
1077 | i = 0; |
1199 | i = 0; |
1078 | } |
1200 | } |
1079 | } |
1201 | } |
1080 | |
1202 | |
|
|
1203 | // if no bold font found, use a regular one |
|
|
1204 | if (bold) |
|
|
1205 | return find_font (unicode); |
|
|
1206 | |
1081 | return 0; /* we must return SOME font */ |
1207 | return 0; /* we must return SOME font */ |
1082 | } |
1208 | } |
1083 | |
1209 | |
1084 | |
1210 | |
1085 | |
1211 | |