1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: defaultfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 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 |
… | |
… | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
|
|
24 | #include "rxvtlib.h" |
|
|
25 | #include "rxvtutil.h" |
24 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
25 | |
27 | |
26 | #include <cstdlib> |
28 | #include <cstdlib> |
27 | |
29 | |
28 | #define DISPLAY r->display->display |
30 | #include <inttypes.h> |
29 | #define TGC r->TermWin.gc |
31 | |
|
|
32 | #define MAX_OVERLAP_ROMAN (8 + 2) // max. character width in 8ths of the base width |
|
|
33 | #define MAX_OVERLAP_ITALIC (8 + 3) // max. overlap for italic fonts |
|
|
34 | |
|
|
35 | #define OVERLAP_OK(w,wcw,prop) ((w) <= ( \ |
|
|
36 | (prop)->slant >= rxvt_fontprop::italic \ |
|
|
37 | ? ((prop)->width * (wcw) * MAX_OVERLAP_ITALIC + 7) >> 3 \ |
|
|
38 | : ((prop)->width * (wcw) * MAX_OVERLAP_ROMAN + 7) >> 3 \ |
|
|
39 | )) |
30 | |
40 | |
31 | const struct rxvt_fallback_font { |
41 | const struct rxvt_fallback_font { |
32 | codeset cs; |
42 | codeset cs; |
33 | const char *name; |
43 | const char *name; |
34 | } fallback_fonts[] = { |
44 | } fallback_fonts[] = { |
… | |
… | |
52 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
62 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
53 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
63 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
54 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
64 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
55 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
65 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
56 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
66 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
|
|
67 | |
|
|
68 | # if XFT |
|
|
69 | { CS_KOI8_U, "xft::lang=ru" }, |
|
|
70 | |
|
|
71 | { CS_ISO8859_5, "xft::lang=ru" }, |
|
|
72 | { CS_ISO8859_6, "xft::lang=ar" }, |
|
|
73 | { CS_ISO8859_7, "xft::lang=el" }, |
|
|
74 | { CS_ISO8859_8, "xft::lang=he" }, |
|
|
75 | { CS_ISO8859_9, "xft::lang=tr" }, |
|
|
76 | { CS_ISO8859_10, "xft::lang=se" }, |
|
|
77 | { CS_ISO8859_11, "xft::lang=th" }, |
|
|
78 | # endif |
57 | #endif |
79 | #endif |
58 | |
80 | |
59 | // japanese |
81 | // japanese |
60 | #if ENCODING_JP || ENCODING_JP_EXT |
82 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | # if XFT |
83 | # if XFT |
62 | // prefer xft for complex scripts |
84 | // prefer xft for complex scripts |
63 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
85 | { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, |
|
|
86 | { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" }, |
|
|
87 | { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, |
|
|
88 | { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, |
64 | # endif |
89 | # endif |
65 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
90 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
91 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
92 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
93 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
69 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
94 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
70 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
95 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
71 | #endif |
96 | #endif |
72 | |
97 | |
73 | #if ENCODING_CN || ENCODING_CN_EXT |
98 | #if ENCODING_ZH || ENCODING_ZH_EXT |
74 | # if XFT |
99 | # if XFT |
|
|
100 | { CS_GBK_0, "xft:AR PL KaitiM GB" }, |
|
|
101 | { CS_GBK_0, "xft:AR PL SungtiL GB" }, |
|
|
102 | { CS_GBK_0, "xft::lang=zh" }, |
75 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
103 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
76 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
104 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
77 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
105 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
78 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
106 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
|
|
107 | { CS_GB2312_1980_0, "xft::lang=zh" }, |
79 | # endif |
108 | # endif |
|
|
109 | { CS_GBK_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gbk*-0" }, |
80 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
110 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
81 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
111 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
82 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
112 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
|
|
113 | { CS_GB2312_1980_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
83 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
114 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
84 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
115 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
85 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
116 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
86 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
117 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
87 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
118 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
… | |
… | |
89 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
120 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
90 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
121 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
91 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
122 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
92 | #endif |
123 | #endif |
93 | |
124 | |
|
|
125 | #if ENCODING_KR |
|
|
126 | { CS_KSC5601_1987_0, "-baekmuk-gulim-*-*-*-*-*-*-*-*-c-*-ksc5601*" }, |
|
|
127 | { CS_KSC5601_1987_0, "-*-*-*-*-*-*-*-*-*-*-c-*-ksc5601*" }, |
94 | #if XFT |
128 | # if XFT |
95 | { CS_UNICODE, "xft:Andale Mono" }, |
129 | { CS_KSC5601_1987_0, "xft:Baekmuk Gulim:antialias=false" }, |
96 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
130 | { CS_KSC5601_1987_0, "xft::lang=ko:antialias=false" }, |
|
|
131 | # endif |
97 | #endif |
132 | #endif |
|
|
133 | |
|
|
134 | // generic font fallback |
98 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
135 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
99 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
136 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
100 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
137 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
101 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
138 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
102 | #if XFT |
139 | #if XFT |
|
|
140 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
|
|
141 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
|
|
142 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
|
|
143 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
|
|
144 | |
103 | // FreeMono is usually uglier than x fonts, so try last only. |
145 | // FreeMono is usually uglier than x fonts, so try last only. |
104 | //{ CS_UNICODE, "xft:FreeMono" }, |
146 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
105 | #endif |
147 | #endif |
106 | |
148 | |
107 | { CS_UNKNOWN, 0 } |
149 | { CS_UNKNOWN, 0 } |
108 | }; |
150 | }; |
109 | |
151 | |
|
|
152 | // these characters are used to guess the font height and width |
|
|
153 | // pango uses a similar algorithm and doesn't trust the font either. |
|
|
154 | static uint16_t extent_test_chars[] = { |
|
|
155 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
|
|
156 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
|
|
157 | 0x304c, 0x672c, // が本 |
|
|
158 | }; |
|
|
159 | |
|
|
160 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
|
|
161 | |
|
|
162 | #define dTermDisplay Display *disp = term->xdisp |
|
|
163 | #define dTermGC GC gc = term->gc |
|
|
164 | |
110 | ///////////////////////////////////////////////////////////////////////////// |
165 | ///////////////////////////////////////////////////////////////////////////// |
111 | |
166 | |
112 | #if XFT |
167 | #if XFT |
113 | rxvt_drawable::~rxvt_drawable () |
168 | rxvt_drawable::~rxvt_drawable () |
114 | { |
169 | { |
… | |
… | |
117 | } |
172 | } |
118 | |
173 | |
119 | rxvt_drawable::operator XftDraw *() |
174 | rxvt_drawable::operator XftDraw *() |
120 | { |
175 | { |
121 | if (!xftdrawable) |
176 | if (!xftdrawable) |
122 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
177 | xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap); |
123 | |
178 | |
124 | return xftdrawable; |
179 | return xftdrawable; |
125 | } |
180 | } |
126 | #endif |
181 | #endif |
127 | |
182 | |
128 | ///////////////////////////////////////////////////////////////////////////// |
183 | ///////////////////////////////////////////////////////////////////////////// |
129 | |
|
|
130 | static void *enc_buf; |
|
|
131 | static uint32_t enc_len; |
|
|
132 | |
|
|
133 | static inline void * |
|
|
134 | get_enc_buf (uint32_t len) |
|
|
135 | { |
|
|
136 | if (len > enc_len) |
|
|
137 | { |
|
|
138 | free (enc_buf); |
|
|
139 | enc_buf = malloc (len); |
|
|
140 | enc_len = len; |
|
|
141 | } |
|
|
142 | |
|
|
143 | return enc_buf; |
|
|
144 | } |
|
|
145 | |
184 | |
146 | static const char * |
185 | static const char * |
147 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
186 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
148 | { |
187 | { |
149 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
188 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
189 | uint8_t *res = buf; |
150 | |
190 | |
151 | while (len--) |
191 | while (len--) |
152 | { |
192 | { |
153 | uint32_t c = FROM_UNICODE (cs, *text++); |
193 | uint32_t c = FROM_UNICODE (cs, *text++); |
154 | |
194 | |
… | |
… | |
159 | } |
199 | } |
160 | |
200 | |
161 | *buf++ = c; |
201 | *buf++ = c; |
162 | } |
202 | } |
163 | |
203 | |
164 | return (const char *)enc_buf; |
204 | return (const char *)res; |
165 | } |
205 | } |
166 | |
206 | |
167 | static const XChar2b * |
207 | static const XChar2b * |
168 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
208 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
169 | { |
209 | { |
170 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
210 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
211 | XChar2b *res = buf; |
171 | |
212 | |
172 | while (len--) |
213 | while (len--) |
173 | { |
214 | { |
174 | uint32_t c = FROM_UNICODE (cs, *text++); |
215 | uint32_t c = FROM_UNICODE (cs, *text++); |
175 | |
216 | |
… | |
… | |
182 | buf->byte1 = c >> 8; |
223 | buf->byte1 = c >> 8; |
183 | buf->byte2 = c; |
224 | buf->byte2 = c; |
184 | buf++; |
225 | buf++; |
185 | } |
226 | } |
186 | |
227 | |
187 | return (XChar2b *)enc_buf; |
228 | return res; |
188 | } |
229 | } |
189 | |
230 | |
190 | ///////////////////////////////////////////////////////////////////////////// |
231 | ///////////////////////////////////////////////////////////////////////////// |
191 | |
232 | |
|
|
233 | rxvt_font::rxvt_font () |
|
|
234 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
|
|
235 | { |
|
|
236 | } |
|
|
237 | |
192 | void |
238 | void |
|
|
239 | rxvt_font::set_name (char *name) |
|
|
240 | { |
|
|
241 | if (this->name == name) |
|
|
242 | return; |
|
|
243 | |
|
|
244 | if (this->name) free (this->name); // let the compiler optimize |
|
|
245 | this->name = name; |
|
|
246 | } |
|
|
247 | |
|
|
248 | void |
193 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
249 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
194 | { |
250 | { |
|
|
251 | dTermDisplay; |
|
|
252 | dTermGC; |
|
|
253 | |
195 | if (color == Color_bg) |
254 | if (color == Color_bg) |
196 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
255 | XClearArea (disp, d, x, y, w, h, false); |
197 | else if (color >= 0) |
256 | else if (color >= 0) |
198 | { |
257 | { |
199 | #if XFT |
258 | #if XFT |
200 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
259 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
201 | #else |
260 | #else |
202 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
261 | XSetForeground (disp, gc, term->pix_colors[color]); |
203 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
262 | XFillRectangle (disp, d, gc, x, y, w, h); |
204 | #endif |
263 | #endif |
205 | } |
264 | } |
206 | } |
265 | } |
207 | |
266 | |
|
|
267 | ///////////////////////////////////////////////////////////////////////////// |
|
|
268 | |
208 | #include "table/linedraw.h" |
269 | #include "table/linedraw.h" |
209 | |
270 | |
210 | struct rxvt_font_default : rxvt_font { |
271 | struct rxvt_font_default : rxvt_font { |
|
|
272 | struct rxvt_fontset *fs; |
|
|
273 | |
|
|
274 | rxvt_font_default (rxvt_fontset *fs) |
|
|
275 | : rxvt_font () |
|
|
276 | { |
|
|
277 | this->fs = fs; |
|
|
278 | } |
211 | |
279 | |
212 | rxvt_fontprop properties () |
280 | rxvt_fontprop properties () |
213 | { |
281 | { |
214 | rxvt_fontprop p; |
282 | rxvt_fontprop p; |
215 | |
283 | |
216 | p.width = p.height = 1; |
284 | p.width = p.height = 1; |
|
|
285 | p.ascent = rxvt_fontprop::unset; |
217 | p.weight = rxvt_fontprop::medium; |
286 | p.weight = rxvt_fontprop::medium; |
218 | p.slant = rxvt_fontprop::roman; |
287 | p.slant = rxvt_fontprop::roman; |
219 | |
288 | |
220 | return p; |
289 | return p; |
221 | } |
290 | } |
… | |
… | |
223 | bool load (const rxvt_fontprop &prop) |
292 | bool load (const rxvt_fontprop &prop) |
224 | { |
293 | { |
225 | width = 1; height = 1; |
294 | width = 1; height = 1; |
226 | ascent = 1; descent = 0; |
295 | ascent = 1; descent = 0; |
227 | |
296 | |
228 | set_name (strdup ("built-in pseudofont")); |
297 | set_name (strdup ("built-in support font")); |
229 | |
298 | |
230 | return true; |
299 | return true; |
231 | } |
300 | } |
232 | |
301 | |
233 | bool has_codepoint (unicode_t unicode) |
302 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
234 | { |
303 | { |
|
|
304 | careful = false; |
|
|
305 | |
235 | if (unicode <= 0x001f) |
306 | if (unicode <= 0x001f) |
236 | return true; |
307 | return true; |
237 | |
308 | |
238 | if (unicode <= 0x007f) |
309 | if (unicode <= 0x007f) |
239 | return false; |
310 | return false; |
240 | |
311 | |
241 | if (unicode <= 0x009f) |
312 | if (unicode <= 0x009f) |
242 | return true; |
313 | return true; |
243 | |
314 | |
244 | if (unicode >= 0x2500 && unicode <= 0x259f) |
315 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
316 | !term->option (Opt_skipBuiltinGlyphs)) |
245 | return true; |
317 | return true; |
246 | |
318 | |
247 | if (IS_COMPOSE (unicode)) |
319 | if (IS_COMPOSE (unicode)) |
248 | return true; |
320 | return true; |
249 | |
321 | |
250 | switch (unicode) |
322 | switch (unicode) |
251 | { |
323 | { |
252 | case ZERO_WIDTH_CHAR: |
324 | case ZERO_WIDTH_CHAR: |
|
|
325 | case NOCHAR: |
253 | return true; |
326 | return true; |
254 | } |
327 | } |
255 | |
328 | |
256 | return false; |
329 | return false; |
257 | } |
330 | } |
… | |
… | |
264 | void |
337 | void |
265 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
338 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
266 | const text_t *text, int len, |
339 | const text_t *text, int len, |
267 | int fg, int bg) |
340 | int fg, int bg) |
268 | { |
341 | { |
|
|
342 | dTermDisplay; |
|
|
343 | dTermGC; |
|
|
344 | |
269 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
345 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
270 | |
346 | |
271 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
347 | XSetForeground (disp, gc, term->pix_colors[fg]); |
272 | |
348 | |
273 | while (len--) |
349 | while (len) |
274 | { |
350 | { |
275 | #if ENABLE_COMBINING |
351 | #if ENABLE_COMBINING |
276 | compose_char *cc; |
352 | compose_char *cc; |
277 | #endif |
353 | #endif |
|
|
354 | const text_t *tp = text; |
278 | text_t t = *text++; |
355 | text_t t = *tp; |
|
|
356 | |
|
|
357 | while (++text, --len && *text == NOCHAR) |
|
|
358 | ; |
|
|
359 | |
|
|
360 | int width = text - tp; |
|
|
361 | int fwidth = term->fwidth * width; |
279 | |
362 | |
280 | if (0x2500 <= t && t <= 0x259f) |
363 | if (0x2500 <= t && t <= 0x259f) |
281 | { |
364 | { |
282 | uint16_t offs = linedraw_offs[t - 0x2500]; |
365 | uint16_t offs = linedraw_offs[t - 0x2500]; |
283 | uint32_t *a = linedraw_command + (offs >> 4); |
366 | uint32_t *a = linedraw_command + (offs >> 4); |
284 | uint32_t *b = a + (offs & 15); |
367 | uint32_t *b = a + (offs & 15); |
285 | |
368 | |
286 | int W = r->TermWin.fwidth; |
369 | int W = fwidth; |
287 | int H = r->TermWin.fheight; |
370 | int H = term->fheight; |
288 | |
371 | |
289 | int x_[16]; |
372 | int x_[16]; |
290 | int y_[16]; |
373 | int y_[16]; |
291 | |
374 | |
292 | for (int i = 0; i <= 8; i++) |
375 | for (int i = 0; i <= 8; i++) |
… | |
… | |
300 | |
383 | |
301 | XGCValues gcv; |
384 | XGCValues gcv; |
302 | |
385 | |
303 | gcv.cap_style = CapButt; |
386 | gcv.cap_style = CapButt; |
304 | gcv.line_width = 0; |
387 | gcv.line_width = 0; |
305 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
388 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
306 | |
389 | |
307 | while (a < b) |
390 | while (a < b) |
308 | { |
391 | { |
309 | uint32_t command = *a++; |
392 | uint32_t command = *a++; |
310 | |
393 | |
… | |
… | |
317 | int y2 = y_[(command >> 0) & 15]; |
400 | int y2 = y_[(command >> 0) & 15]; |
318 | |
401 | |
319 | switch (op) |
402 | switch (op) |
320 | { |
403 | { |
321 | case 0: // line |
404 | case 0: // line |
322 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
405 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
323 | break; |
406 | break; |
324 | |
407 | |
325 | case 1: // rectangle, possibly stippled |
408 | case 1: // rectangle, possibly stippled |
326 | if (a) |
409 | if (a) |
327 | { |
410 | { |
328 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
411 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
329 | |
412 | |
330 | gcv.fill_style = FillStippled; |
413 | gcv.fill_style = FillStippled; |
331 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
414 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
332 | gcv.ts_x_origin = x; |
415 | gcv.ts_x_origin = x; |
333 | gcv.ts_y_origin = y; |
416 | gcv.ts_y_origin = y; |
334 | |
417 | |
335 | XChangeGC (d.display->display, TGC, |
418 | XChangeGC (disp, gc, |
336 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
419 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
337 | &gcv); |
420 | &gcv); |
338 | } |
421 | } |
339 | |
422 | |
340 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
423 | XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
341 | |
424 | |
342 | if (a) |
425 | if (a) |
343 | { |
426 | { |
344 | XFreePixmap (d.display->display, gcv.stipple); |
427 | XFreePixmap (disp, gcv.stipple); |
345 | gcv.stipple = 0; |
428 | gcv.stipple = 0; |
346 | gcv.fill_style = FillSolid; |
429 | gcv.fill_style = FillSolid; |
347 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
430 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
348 | } |
431 | } |
349 | break; |
432 | break; |
350 | case 2: // arc |
433 | case 2: // arc |
351 | XDrawArc (d.display->display, d, TGC, |
434 | XDrawArc (disp, d, gc, |
352 | x1 - W/2, y1 - H/2, W-1, H-1, |
435 | x1 - W/2, y1 - H/2, W-1, H-1, |
353 | (a - 1) * 90*64, (b - 1) * 90*64); |
436 | (a - 1) * 90*64, (b - 1) * 90*64); |
354 | break; |
437 | break; |
355 | } |
438 | } |
356 | } |
439 | } |
357 | } |
440 | } |
358 | #if ENABLE_COMBINING |
441 | #if ENABLE_COMBINING |
359 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
442 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
360 | { |
443 | { |
|
|
444 | min_it (width, 2); // we only support wcwidth up to 2 |
|
|
445 | |
|
|
446 | text_t chrs[2]; |
|
|
447 | chrs [1] = NOCHAR; |
|
|
448 | |
|
|
449 | *chrs = cc->c1; |
361 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
450 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
362 | f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg); |
451 | f1->draw (d, x, y, chrs, width, fg, bg); |
|
|
452 | |
363 | if (cc->c2 != NOCHAR) |
453 | if (cc->c2 != NOCHAR) |
364 | { |
454 | { |
|
|
455 | bool careful; |
|
|
456 | |
365 | // prefer font of first character, for no good reasons |
457 | // prefer font of first character, for no good reasons |
366 | rxvt_font *f2 = f1->has_codepoint (cc->c2) |
458 | *chrs = cc->c2; |
|
|
459 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
367 | ? f1 |
460 | ? f1 |
368 | : (*fs)[fs->find_font (cc->c2)]; |
461 | : (*fs)[fs->find_font (cc->c2)]; |
369 | |
462 | |
370 | f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1); |
463 | f2->draw (d, x, y, chrs, width, fg, -1); |
371 | } |
464 | } |
372 | } |
465 | } |
373 | #endif |
466 | #endif |
374 | else |
467 | else |
375 | switch (t) |
468 | switch (t) |
376 | { |
469 | { |
|
|
470 | case '\t': |
377 | case ZERO_WIDTH_CHAR: |
471 | case ZERO_WIDTH_CHAR: |
|
|
472 | case NOCHAR: |
378 | break; |
473 | break; |
379 | |
474 | |
380 | default: |
475 | default: |
381 | int w = 0; |
|
|
382 | while (len > 0 && *text == NOCHAR) |
|
|
383 | { |
|
|
384 | ++text; |
|
|
385 | --len; |
|
|
386 | w += r->TermWin.fwidth; |
|
|
387 | } |
|
|
388 | |
|
|
389 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
476 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
390 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
477 | fwidth - 4, term->fheight - 4); |
391 | x += w; |
|
|
392 | } |
478 | } |
393 | |
479 | |
394 | x += r->TermWin.fwidth; |
480 | x += fwidth; |
395 | } |
481 | } |
396 | } |
482 | } |
397 | |
483 | |
398 | ///////////////////////////////////////////////////////////////////////////// |
484 | ///////////////////////////////////////////////////////////////////////////// |
399 | |
485 | |
… | |
… | |
404 | |
490 | |
405 | rxvt_fontprop properties (); |
491 | rxvt_fontprop properties (); |
406 | |
492 | |
407 | bool load (const rxvt_fontprop &prop); |
493 | bool load (const rxvt_fontprop &prop); |
408 | |
494 | |
409 | bool has_codepoint (unicode_t unicode); |
495 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
410 | |
496 | |
411 | void draw (rxvt_drawable &d, int x, int y, |
497 | void draw (rxvt_drawable &d, int x, int y, |
412 | const text_t *text, int len, |
498 | const text_t *text, int len, |
413 | int fg, int bg); |
499 | int fg, int bg); |
414 | |
500 | |
|
|
501 | bool slow; // wether this is a proportional font or has other funny characteristics |
415 | XFontStruct *f; |
502 | XFontStruct *f; |
416 | codeset cs; |
503 | codeset cs; |
417 | bool enc2b, encm; |
504 | bool enc2b, encm; |
418 | |
505 | |
419 | char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
506 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
420 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
507 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
421 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
508 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
422 | bool set_properties (rxvt_fontprop &p, const char *name); |
509 | bool set_properties (rxvt_fontprop &p, const char *name); |
423 | }; |
510 | }; |
424 | |
511 | |
425 | char * |
512 | char * |
426 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
513 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
427 | { |
514 | { |
428 | unsigned long value; |
515 | unsigned long value; |
429 | |
516 | |
430 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
517 | if (XGetFontProperty (f, property, &value)) |
431 | return XGetAtomName (DISPLAY, value); |
518 | return XGetAtomName (term->xdisp, value); |
432 | else |
519 | else |
433 | return rxvt_strdup (repl); |
520 | return rxvt_strdup (repl); |
434 | } |
521 | } |
435 | |
522 | |
436 | rxvt_fontprop |
523 | rxvt_fontprop |
… | |
… | |
442 | } |
529 | } |
443 | |
530 | |
444 | bool |
531 | bool |
445 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
532 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
446 | { |
533 | { |
447 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
534 | p.width = width != rxvt_fontprop::unset ? width |
|
|
535 | : avgwidth ? (avgwidth + 1) / 10 |
|
|
536 | : (height + 1) / 2; |
448 | p.height = height; |
537 | p.height = height; |
|
|
538 | p.ascent = rxvt_fontprop::unset; |
449 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
539 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
450 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
540 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
451 | |
541 | |
452 | return true; |
542 | return true; |
453 | } |
543 | } |
454 | |
544 | |
455 | bool |
545 | bool |
456 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
546 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
457 | { |
547 | { |
458 | unsigned long height; |
548 | unsigned long height; |
|
|
549 | |
|
|
550 | #if 0 |
459 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
551 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) |
460 | return false; |
552 | return false; |
|
|
553 | #else |
|
|
554 | height = f->ascent + f->descent; |
|
|
555 | #endif |
461 | |
556 | |
462 | unsigned long avgwidth; |
557 | unsigned long avgwidth; |
463 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
558 | if (!XGetFontProperty (f, term->xa [XA_AVERAGE_WIDTH], &avgwidth)) |
464 | avgwidth = 0; |
559 | avgwidth = 0; |
465 | |
560 | |
466 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
561 | char *weight = get_property (f, term->xa [XA_WEIGHT_NAME], "medium"); |
467 | char *slant = get_property (f, "SLANT", "r"); |
562 | char *slant = get_property (f, term->xa [XA_SLANT], "r"); |
468 | |
563 | |
469 | set_properties (p, height, weight, slant, avgwidth); |
564 | set_properties (p, height, weight, slant, avgwidth); |
470 | |
565 | |
471 | free (weight); |
566 | free (weight); |
472 | free (slant); |
567 | free (slant); |
473 | |
568 | |
|
|
569 | p.ascent = f->ascent; |
|
|
570 | |
474 | return true; |
571 | return true; |
475 | } |
572 | } |
476 | |
573 | |
477 | bool |
574 | bool |
478 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
575 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
479 | { |
576 | { |
|
|
577 | dTermDisplay; |
480 | int slashes = 0; |
578 | int slashes = 0; |
481 | const char *comp[13]; |
579 | const char *comp[13]; |
482 | |
580 | |
483 | for (const char *c = name; *c; c++) |
581 | for (const char *c = name; *c; c++) |
484 | if (*c == '-') |
582 | if (*c == '-') |
… | |
… | |
492 | if (slashes >= 13 |
590 | if (slashes >= 13 |
493 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
591 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
494 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
592 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
495 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
593 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
496 | |
594 | |
497 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
595 | XFontStruct *f = XLoadQueryFont (disp, name); |
498 | |
596 | |
499 | if (f) |
597 | if (f) |
500 | { |
598 | { |
501 | // the font should really exist now. if not, we have a problem |
599 | // the font should really exist now. if not, we have a problem |
502 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
600 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
503 | // in that case, just return garbage. |
601 | // in that case, just return garbage. |
504 | bool ret = set_properties (p, f); |
602 | bool ret = set_properties (p, f); |
505 | XFreeFont (DISPLAY, f); |
603 | XFreeFont (disp, f); |
506 | return ret; |
604 | return ret; |
507 | } |
605 | } |
508 | else |
606 | else |
509 | return false; |
607 | return false; |
510 | } |
608 | } |
511 | |
609 | |
512 | // fix the size of scalable fonts |
610 | // fix the size of scalable fonts |
513 | static void |
611 | static bool |
514 | fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop) |
612 | replace_field (char *buf, const char *name, int index, const char old, const char *replace) |
515 | { |
613 | { |
516 | int slashes = 0; |
614 | int slashes = 0; |
517 | const char *size; |
615 | const char *field, *end; |
518 | |
616 | |
519 | for (const char *c = name; *c; c++) |
617 | for (const char *c = name; *c; c++) |
520 | if (*c == '-') |
618 | if (*c == '-') |
521 | { |
619 | { |
522 | if (slashes == 6) |
620 | if (slashes == index) |
523 | size = c + 1; |
621 | field = c + 1; |
|
|
622 | |
|
|
623 | if (slashes == index + 1) |
|
|
624 | end = c; |
524 | |
625 | |
525 | if (++slashes >= 13) |
626 | if (++slashes >= 13) |
526 | break; |
627 | break; |
527 | } |
628 | } |
528 | |
629 | |
529 | if (slashes >= 13 && size[0] == '0') |
630 | if (slashes >= 13 && (!old || *field == old)) |
530 | { |
631 | { |
|
|
632 | // TODO: check for overflow in font-name |
531 | strncpy (buf, name, size - name); |
633 | strncpy (buf, name, field - name); |
532 | buf += size - name; |
634 | buf += field - name; |
533 | buf += sprintf (buf, "%d", prop.height); |
|
|
534 | strcpy (buf, size + 1); |
635 | strcpy (buf, replace); |
|
|
636 | strcat (buf, end); |
|
|
637 | |
|
|
638 | return true; |
535 | } |
639 | } |
536 | else |
640 | else |
|
|
641 | { |
537 | strcpy (buf, name); |
642 | strcpy (buf, name); |
|
|
643 | |
|
|
644 | return false; |
|
|
645 | } |
538 | } |
646 | } |
539 | |
647 | |
540 | bool |
648 | bool |
541 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
649 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
542 | { |
650 | { |
|
|
651 | dTermDisplay; |
|
|
652 | |
543 | clear (); |
653 | clear (); |
|
|
654 | |
|
|
655 | char field_str[64]; // enough for 128 bits |
|
|
656 | |
|
|
657 | // first morph the font if required |
|
|
658 | if (prop.weight != rxvt_fontprop::unset |
|
|
659 | || prop.slant != rxvt_fontprop::unset) |
|
|
660 | { |
|
|
661 | char fname[1024]; |
|
|
662 | |
|
|
663 | if (name[0] != '-') |
|
|
664 | { |
|
|
665 | f = XLoadQueryFont (disp, name); |
|
|
666 | |
|
|
667 | if (!f) |
|
|
668 | return false; |
|
|
669 | |
|
|
670 | char *new_name = get_property (f, XA_FONT, name); |
|
|
671 | |
|
|
672 | if (new_name) |
|
|
673 | set_name (new_name); |
|
|
674 | else |
|
|
675 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
|
|
676 | |
|
|
677 | XFreeFont (disp, f); |
|
|
678 | f = 0; |
|
|
679 | } |
|
|
680 | |
|
|
681 | if (prop.weight != rxvt_fontprop::unset) |
|
|
682 | { |
|
|
683 | replace_field (fname, name, 2, 0, |
|
|
684 | prop.weight < rxvt_fontprop::bold |
|
|
685 | ? "medium" : "bold"); |
|
|
686 | set_name (strdup (fname)); |
|
|
687 | } |
|
|
688 | |
|
|
689 | if (prop.slant != rxvt_fontprop::unset) |
|
|
690 | { |
|
|
691 | replace_field (fname, name, 3, 0, |
|
|
692 | prop.slant < rxvt_fontprop::italic |
|
|
693 | ? "r" : "i"); // TODO: handle "o"blique, too |
|
|
694 | set_name (strdup (fname)); |
|
|
695 | } |
|
|
696 | } |
|
|
697 | |
|
|
698 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
|
|
699 | ? 0 : prop.height); |
|
|
700 | |
|
|
701 | struct font_weight { |
|
|
702 | char *name; |
|
|
703 | int diff; |
|
|
704 | |
|
|
705 | void clear () |
|
|
706 | { |
|
|
707 | name = 0; |
|
|
708 | diff = 0x7fffffff; |
|
|
709 | } |
|
|
710 | |
|
|
711 | font_weight () { clear (); } |
|
|
712 | ~font_weight () { free (name); } |
|
|
713 | }; |
544 | |
714 | |
545 | char **list; |
715 | char **list; |
546 | int count; |
716 | int count; |
547 | list = XListFonts (DISPLAY, name, 1024, &count); |
717 | list = XListFonts (disp, name, 4000, &count); |
|
|
718 | |
548 | set_name (0); |
719 | set_name (0); |
549 | |
720 | |
550 | if (!list) |
721 | if (!list) |
551 | return false; |
722 | return false; |
552 | |
723 | |
553 | int bestdiff = 0x7fffffff; |
724 | font_weight *fonts = new font_weight[count]; |
|
|
725 | |
554 | for (int i = 0; i < count; i++) |
726 | for (int i = 0; i < count; i++) |
555 | { |
727 | { |
556 | rxvt_fontprop p; |
728 | rxvt_fontprop p; |
557 | char fname[1024]; |
729 | char fname[1024]; |
558 | fix_scalable (fname, list[i], prop); |
730 | |
|
|
731 | int diff = 0; |
|
|
732 | |
|
|
733 | if (replace_field (fname, list[i], 6, '0', field_str)) |
|
|
734 | diff += 10; // slightly penalize scalable fonts |
|
|
735 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
736 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
559 | |
737 | |
560 | if (!set_properties (p, fname)) |
738 | if (!set_properties (p, fname)) |
561 | continue; |
739 | continue; |
562 | |
740 | |
|
|
741 | if (prop.height != rxvt_fontprop::unset |
563 | if (p.height > prop.height) // weed out too large fonts |
742 | && p.height > prop.height) // weed out too large fonts |
564 | continue; |
743 | continue; |
565 | |
744 | |
566 | int diff = (prop.height - p.height) * 32 |
745 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
567 | + abs (prop.weight - p.weight) |
746 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
568 | + abs (prop.slant - p.slant ); |
747 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
|
|
748 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
569 | |
749 | |
570 | if (!name // compare against best found so far |
750 | fonts[i].name = strdup (fname); |
571 | || diff < bestdiff) |
751 | fonts[i].diff = diff; |
572 | { |
|
|
573 | set_name (strdup (fname)); |
|
|
574 | bestdiff = diff; |
|
|
575 | } |
|
|
576 | } |
752 | } |
577 | |
753 | |
578 | XFreeFontNames (list); |
754 | XFreeFontNames (list); |
579 | |
755 | |
580 | if (!name) |
756 | // this loop only iterates when the guessed font-size is too small |
581 | return false; |
757 | for (;;) |
|
|
758 | { |
|
|
759 | font_weight *best = fonts + count - 1; |
582 | |
760 | |
583 | f = XLoadQueryFont (DISPLAY, name); |
761 | for (font_weight *w = best; w-- > fonts; ) |
|
|
762 | if (w->diff <= best->diff) |
|
|
763 | best = w; |
|
|
764 | |
|
|
765 | if (!best->name |
|
|
766 | || !(f = XLoadQueryFont (disp, best->name))) |
|
|
767 | break; |
|
|
768 | |
|
|
769 | set_name (best->name); |
|
|
770 | best->clear (); |
|
|
771 | |
|
|
772 | ascent = f->ascent; |
|
|
773 | descent = f->descent; |
|
|
774 | height = ascent + descent; |
|
|
775 | |
|
|
776 | if (prop.height == rxvt_fontprop::unset |
|
|
777 | || height <= prop.height) |
|
|
778 | break; // font is ready for use |
|
|
779 | |
|
|
780 | // PIXEL_SIZE small enough, but real height too large |
|
|
781 | clear (); |
|
|
782 | } |
|
|
783 | |
|
|
784 | delete [] fonts; |
584 | |
785 | |
585 | if (!f) |
786 | if (!f) |
586 | return false; |
787 | return false; |
587 | |
788 | |
588 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
789 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
589 | char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
790 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
590 | |
791 | |
591 | if (registry && encoding) |
792 | if (registry && encoding) |
592 | { |
793 | { |
593 | char charset[64]; |
794 | char charset[64]; |
594 | snprintf (charset, 64, "%s-%s", registry, encoding); |
795 | snprintf (charset, 64, "%s-%s", registry, encoding); |
595 | |
796 | |
596 | cs = codeset_from_name (charset); |
797 | cs = codeset_from_name (charset); |
597 | } |
798 | } |
598 | else |
799 | else |
599 | { |
800 | { |
600 | const char *charset = get_property (f, "FONT", 0); |
801 | const char *charset = get_property (f, XA_FONT, 0); |
601 | |
802 | |
602 | if (!charset) |
803 | if (!charset) |
603 | charset = name; |
804 | charset = name; |
604 | |
805 | |
605 | int count = 13; |
806 | int count = 13; |
… | |
… | |
617 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
818 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
618 | |
819 | |
619 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
820 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
620 | enc2b = encm || f->max_char_or_byte2 > 255; |
821 | enc2b = encm || f->max_char_or_byte2 > 255; |
621 | |
822 | |
622 | ascent = f->ascent; |
|
|
623 | descent = f->descent; |
|
|
624 | height = ascent + descent; |
|
|
625 | |
|
|
626 | slow = false; |
823 | slow = false; |
627 | |
824 | |
|
|
825 | #if 1 // only used for slow detection, TODO optimize |
628 | if (f->min_bounds.width == f->max_bounds.width) |
826 | if (f->min_bounds.width == f->max_bounds.width || !f->per_char) |
629 | width = f->min_bounds.width; |
|
|
630 | else if (f->per_char == NULL) |
|
|
631 | width = f->max_bounds.width; |
827 | width = f->max_bounds.width; |
632 | else |
828 | else |
633 | { |
829 | { |
634 | slow = true; |
830 | slow = true; |
635 | |
831 | |
… | |
… | |
645 | width = f->per_char[N].width; |
841 | width = f->per_char[N].width; |
646 | |
842 | |
647 | --N; |
843 | --N; |
648 | } |
844 | } |
649 | } |
845 | } |
|
|
846 | #endif |
|
|
847 | |
|
|
848 | width = 1; |
|
|
849 | |
|
|
850 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
|
|
851 | { |
|
|
852 | if (FROM_UNICODE (cs, *t) == NOCHAR) |
|
|
853 | continue; |
|
|
854 | |
|
|
855 | // ignore characters we wouldn't use anyways |
|
|
856 | bool careful; |
|
|
857 | if (!has_char (*t, &prop, careful)) |
|
|
858 | continue; |
|
|
859 | |
|
|
860 | XChar2b ch = { *t >> 8, *t }; |
|
|
861 | |
|
|
862 | XCharStruct g; |
|
|
863 | int dir_ret, asc_ret, des_ret; |
|
|
864 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
|
|
865 | |
|
|
866 | int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
|
|
867 | |
|
|
868 | if (width < g.width) width = g.width; |
|
|
869 | } |
650 | |
870 | |
651 | if (cs == CS_UNKNOWN) |
871 | if (cs == CS_UNKNOWN) |
652 | { |
872 | { |
653 | fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
873 | fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
654 | |
874 | |
655 | clear (); |
875 | clear (); |
656 | |
|
|
657 | return false; |
876 | return false; |
658 | } |
877 | } |
|
|
878 | |
|
|
879 | #if 0 // do it per-character |
|
|
880 | if (prop && width > prop->width) |
|
|
881 | { |
|
|
882 | clear (); |
|
|
883 | return false; |
|
|
884 | } |
|
|
885 | #endif |
659 | |
886 | |
660 | return true; |
887 | return true; |
661 | } |
888 | } |
662 | |
889 | |
663 | void |
890 | void |
664 | rxvt_font_x11::clear () |
891 | rxvt_font_x11::clear () |
665 | { |
892 | { |
666 | if (f) |
893 | if (f) |
667 | { |
894 | { |
668 | XFreeFont (DISPLAY, f); |
895 | XFreeFont (term->xdisp, f); |
669 | f = 0; |
896 | f = 0; |
670 | } |
897 | } |
671 | } |
898 | } |
672 | |
899 | |
673 | bool |
900 | bool |
674 | rxvt_font_x11::has_codepoint (unicode_t unicode) |
901 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
675 | { |
902 | { |
676 | uint32_t ch = FROM_UNICODE (cs, unicode); |
903 | uint32_t ch = FROM_UNICODE (cs, unicode); |
677 | |
904 | |
678 | if (ch == NOCHAR) |
905 | if (ch == NOCHAR) |
679 | return false; |
906 | return false; |
… | |
… | |
688 | |
915 | |
689 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
916 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
690 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
917 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
691 | return false; |
918 | return false; |
692 | |
919 | |
693 | if (!f->per_char) |
920 | if (f->per_char) |
694 | return true; |
921 | { |
695 | |
|
|
696 | int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1; |
922 | int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1; |
697 | int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2; |
923 | int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2; |
698 | |
924 | |
699 | xcs = f->per_char + N; |
925 | xcs = f->per_char + N; |
|
|
926 | } |
|
|
927 | else |
|
|
928 | xcs = &f->max_bounds; |
700 | } |
929 | } |
701 | else |
930 | else |
702 | { |
931 | { |
703 | if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2) |
932 | if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2) |
704 | return false; |
933 | return false; |
705 | |
934 | |
706 | if (!f->per_char) |
935 | if (f->per_char) |
707 | return true; |
|
|
708 | |
|
|
709 | xcs = f->per_char + (ch - f->min_char_or_byte2); |
936 | xcs = f->per_char + (ch - f->min_char_or_byte2); |
|
|
937 | else |
|
|
938 | xcs = &f->max_bounds; |
710 | } |
939 | } |
711 | |
940 | |
712 | if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0 |
941 | if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0 |
713 | && xcs->ascent == 0 && xcs->descent == 0) |
942 | && xcs->ascent == 0 && xcs->descent == 0) |
|
|
943 | return false; |
|
|
944 | |
|
|
945 | if (!prop || prop->width == rxvt_fontprop::unset) |
|
|
946 | return true; |
|
|
947 | |
|
|
948 | // check wether character overlaps previous/next character |
|
|
949 | int w = xcs->rbearing - xcs->lbearing; |
|
|
950 | int wcw = WCWIDTH (unicode); |
|
|
951 | |
|
|
952 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
|
|
953 | |
|
|
954 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
714 | return false; |
955 | return false; |
715 | |
956 | |
716 | return true; |
957 | return true; |
717 | } |
958 | } |
718 | |
959 | |
… | |
… | |
724 | // this looks like a mess /. |
965 | // this looks like a mess /. |
725 | // and it is a mess /. |
966 | // and it is a mess /. |
726 | // yet we are trying to be perfect /. |
967 | // yet we are trying to be perfect /. |
727 | // but the result still isn't perfect /. |
968 | // but the result still isn't perfect /. |
728 | |
969 | |
|
|
970 | dTermDisplay; |
|
|
971 | dTermGC; |
|
|
972 | |
729 | bool slow = this->slow |
973 | bool slow = this->slow |
730 | || width != r->TermWin.fwidth |
974 | || width != term->fwidth |
731 | || height != r->TermWin.fheight; |
975 | || height != term->fheight; |
732 | |
976 | |
733 | int base = r->TermWin.fbase; |
977 | int base = ascent; // sorry, incorrect: term->fbase; |
734 | |
978 | |
735 | XGCValues v; |
979 | XGCValues v; |
736 | v.foreground = r->pix_colors[fg]; |
980 | v.foreground = term->pix_colors[fg]; |
737 | v.font = f->fid; |
981 | v.font = f->fid; |
738 | |
982 | |
739 | if (enc2b) |
983 | if (enc2b) |
740 | { |
984 | { |
741 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
985 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
742 | |
986 | |
743 | if (bg == Color_bg && !slow) |
987 | if (bg == Color_bg && !slow) |
744 | { |
988 | { |
745 | v.background = r->pix_colors[bg]; |
989 | v.background = term->pix_colors[bg]; |
746 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
990 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
747 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
991 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
748 | } |
992 | } |
749 | else |
993 | else |
750 | { |
994 | { |
751 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
995 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
752 | |
996 | |
753 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
997 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
754 | |
998 | |
755 | if (slow) |
999 | if (slow) |
756 | { |
1000 | { |
757 | do |
1001 | do |
758 | { |
1002 | { |
759 | if (xc->byte1 || xc->byte2) |
1003 | if (xc->byte1 || xc->byte2) |
760 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
1004 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
761 | |
1005 | |
762 | x += r->TermWin.fwidth; |
1006 | x += term->fwidth; |
763 | xc++; len--; |
1007 | xc++; len--; |
764 | } |
1008 | } |
765 | while (len); |
1009 | while (len); |
766 | } |
1010 | } |
767 | else |
1011 | else |
768 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
1012 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
769 | } |
1013 | } |
770 | } |
1014 | } |
771 | else |
1015 | else |
772 | { |
1016 | { |
773 | const char *xc = enc_char (text, len, cs, slow); |
1017 | const char *xc = enc_char (text, len, cs, slow); |
774 | |
1018 | |
775 | if (bg == Color_bg && !slow) |
1019 | if (bg == Color_bg && !slow) |
776 | { |
1020 | { |
777 | v.background = r->pix_colors[bg]; |
1021 | v.background = term->pix_colors[bg]; |
778 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1022 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
779 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1023 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
780 | } |
1024 | } |
781 | else |
1025 | else |
782 | { |
1026 | { |
783 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1027 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
784 | |
1028 | |
785 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1029 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
786 | |
1030 | |
787 | if (slow) |
1031 | if (slow) |
788 | { |
1032 | { |
789 | do |
1033 | do |
790 | { |
1034 | { |
791 | if (*xc) |
1035 | if (*xc) |
792 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1036 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
793 | |
1037 | |
794 | x += r->TermWin.fwidth; |
1038 | x += term->fwidth; |
795 | xc++; len--; |
1039 | xc++; len--; |
796 | } |
1040 | } |
797 | while (len); |
1041 | while (len); |
798 | } |
1042 | } |
799 | else |
1043 | else |
800 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1044 | XDrawString (disp, d, gc, x, y + base, xc, len); |
801 | } |
1045 | } |
802 | } |
1046 | } |
803 | } |
1047 | } |
804 | |
1048 | |
805 | ///////////////////////////////////////////////////////////////////////////// |
1049 | ///////////////////////////////////////////////////////////////////////////// |
806 | |
1050 | |
807 | #if XFT |
1051 | #if XFT |
808 | #if 0 |
|
|
809 | #define UNIBITS 21 |
|
|
810 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
|
|
811 | #define SWATHBITS 8 |
|
|
812 | #endif |
|
|
813 | |
1052 | |
814 | struct rxvt_font_xft : rxvt_font { |
1053 | struct rxvt_font_xft : rxvt_font { |
815 | rxvt_font_xft () { f = 0; } |
1054 | rxvt_font_xft () { f = 0; } |
816 | |
1055 | |
817 | void clear (); |
1056 | void clear (); |
… | |
… | |
822 | |
1061 | |
823 | void draw (rxvt_drawable &d, int x, int y, |
1062 | void draw (rxvt_drawable &d, int x, int y, |
824 | const text_t *text, int len, |
1063 | const text_t *text, int len, |
825 | int fg, int bg); |
1064 | int fg, int bg); |
826 | |
1065 | |
827 | bool has_codepoint (unicode_t unicode); |
1066 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; |
828 | |
1067 | |
829 | protected: |
1068 | protected: |
830 | XftFont *f; |
1069 | XftFont *f; |
831 | }; |
1070 | }; |
832 | |
1071 | |
833 | void |
1072 | void |
834 | rxvt_font_xft::clear () |
1073 | rxvt_font_xft::clear () |
835 | { |
1074 | { |
836 | if (f) |
1075 | if (f) |
837 | { |
1076 | { |
838 | XftFontClose (DISPLAY, f); |
1077 | XftFontClose (term->xdisp, f); |
839 | f = 0; |
1078 | f = 0; |
840 | } |
1079 | } |
841 | } |
1080 | } |
842 | |
1081 | |
843 | rxvt_fontprop |
1082 | rxvt_fontprop |
… | |
… | |
847 | |
1086 | |
848 | FT_Face face = XftLockFace (f); |
1087 | FT_Face face = XftLockFace (f); |
849 | |
1088 | |
850 | p.width = width; |
1089 | p.width = width; |
851 | p.height = height; |
1090 | p.height = height; |
|
|
1091 | p.ascent = ascent; |
852 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1092 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
853 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1093 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
854 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1094 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
855 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1095 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
856 | |
1096 | |
… | |
… | |
860 | } |
1100 | } |
861 | |
1101 | |
862 | bool |
1102 | bool |
863 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1103 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
864 | { |
1104 | { |
865 | #if 0 |
1105 | dTermDisplay; |
866 | for (int i = 0; i < SWATHCOUNT; i++) |
|
|
867 | cvr[i] = 0; |
|
|
868 | #endif |
|
|
869 | |
1106 | |
870 | clear (); |
1107 | clear (); |
871 | |
1108 | |
872 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1109 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
873 | |
1110 | |
874 | if (!p) |
1111 | if (!p) |
875 | return false; |
1112 | return false; |
876 | |
1113 | |
877 | FcValue v; |
1114 | FcValue v; |
878 | |
1115 | |
|
|
1116 | if (prop.height != rxvt_fontprop::unset |
879 | if (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch) |
1117 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
|
|
1118 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
880 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1119 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
881 | |
1120 | |
|
|
1121 | if (prop.weight != rxvt_fontprop::unset |
882 | if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1122 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
883 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1123 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
884 | |
1124 | |
|
|
1125 | if (prop.slant != rxvt_fontprop::unset |
885 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
1126 | && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
886 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1127 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
887 | |
|
|
888 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
|
|
889 | FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
890 | |
1128 | |
891 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1129 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
892 | // clip width, we can't do better, or can we? |
1130 | // clip width, we can't do better, or can we? |
893 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1131 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
894 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
1132 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); |
895 | #endif |
1133 | #endif |
896 | |
1134 | |
|
|
1135 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
|
|
1136 | FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
1137 | |
|
|
1138 | // store generated name so iso14755 view gives better results |
|
|
1139 | set_name ((char *)FcNameUnparse (p)); |
|
|
1140 | |
897 | XftResult result; |
1141 | XftResult result; |
898 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1142 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
899 | |
1143 | |
900 | FcPatternDestroy (p); |
1144 | FcPatternDestroy (p); |
901 | |
1145 | |
902 | if (!match) |
1146 | if (!match) |
903 | return false; |
1147 | return false; |
904 | |
1148 | |
905 | f = XftFontOpenPattern (DISPLAY, match); |
|
|
906 | |
|
|
907 | if (!f) |
|
|
908 | { |
|
|
909 | FcPatternDestroy (match); |
|
|
910 | return false; |
|
|
911 | } |
|
|
912 | |
|
|
913 | FT_Face face = XftLockFace (f); |
|
|
914 | |
|
|
915 | slow = !FT_IS_FIXED_WIDTH (face); |
|
|
916 | |
|
|
917 | int ftheight = 0; |
1149 | int ftheight = 0; |
|
|
1150 | bool success = true; |
918 | |
1151 | |
919 | for (;;) |
1152 | for (;;) |
920 | { |
1153 | { |
921 | XGlyphInfo g1, g2; |
1154 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
922 | FcChar8 c; |
|
|
923 | |
1155 | |
924 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
1156 | if (!f) |
925 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
1157 | { |
|
|
1158 | success = false; |
|
|
1159 | break; |
|
|
1160 | } |
926 | |
1161 | |
927 | if (g1.xOff != g2.xOff) // don't simply trust the font |
1162 | FT_Face face = XftLockFace (f); |
928 | slow = true; |
|
|
929 | |
1163 | |
930 | width = g2.xOff; |
|
|
931 | ascent = (face->size->metrics.ascender + 63) >> 6; |
1164 | ascent = (face->size->metrics.ascender + 63) >> 6; |
932 | descent = (-face->size->metrics.descender + 63) >> 6; |
1165 | descent = (-face->size->metrics.descender + 63) >> 6; |
933 | height = ascent + descent; |
1166 | height = max (ascent + descent, (face->size->metrics.height + 63) >> 6); |
|
|
1167 | width = 0; |
934 | |
1168 | |
|
|
1169 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
|
|
1170 | |
|
|
1171 | XftUnlockFace (f); |
|
|
1172 | |
|
|
1173 | int glheight = height; |
|
|
1174 | |
|
|
1175 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
|
|
1176 | { |
|
|
1177 | FcChar16 ch = *t; |
|
|
1178 | |
|
|
1179 | if (cs != CS_UNICODE |
|
|
1180 | && ch > 0x100 |
|
|
1181 | && FROM_UNICODE (cs, ch) == NOCHAR) |
|
|
1182 | continue; |
|
|
1183 | |
|
|
1184 | // ignore characters we wouldn't use anyways |
|
|
1185 | bool careful; |
|
|
1186 | if (!has_char (*t, &prop, careful)) |
|
|
1187 | continue; |
|
|
1188 | |
|
|
1189 | XGlyphInfo g; |
|
|
1190 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1191 | |
|
|
1192 | g.width -= g.x; |
|
|
1193 | |
|
|
1194 | int wcw = WCWIDTH (ch); |
|
|
1195 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
|
|
1196 | |
|
|
1197 | if (width < g.width ) width = g.width; |
|
|
1198 | if (height < g.height ) height = g.height; |
|
|
1199 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1200 | } |
|
|
1201 | |
|
|
1202 | if (!width) |
|
|
1203 | { |
|
|
1204 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1205 | |
|
|
1206 | XftFontClose (disp, f); |
|
|
1207 | f = 0; |
|
|
1208 | |
|
|
1209 | success = false; |
|
|
1210 | break; |
|
|
1211 | } |
|
|
1212 | |
|
|
1213 | if (prop.height == rxvt_fontprop::unset |
935 | if (height <= prop.height || !prop.height) |
1214 | || (height <= prop.height && glheight <= prop.height) |
|
|
1215 | || height <= 2 |
|
|
1216 | || !scalable) |
936 | break; |
1217 | break; |
937 | |
1218 | |
938 | if (ftheight) |
1219 | if (ftheight) |
939 | { |
1220 | { |
940 | // take smaller steps near the end |
1221 | // take smaller steps near the end |
941 | if (height > prop.height + 1) ftheight++; |
1222 | if (height > prop.height + 1) ftheight++; |
942 | if (height > prop.height + 2) ftheight++; |
1223 | if (height > prop.height + 2) ftheight++; |
943 | if (height > prop.height + 3) ftheight++; |
1224 | if (height > prop.height + 3) ftheight++; |
944 | |
1225 | |
945 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
1226 | ftheight -= height - prop.height; |
946 | } |
1227 | } |
947 | else |
1228 | else |
948 | FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
1229 | ftheight = prop.height - 1; |
|
|
1230 | |
|
|
1231 | XftFontClose (disp, f); |
|
|
1232 | FcPatternDel (match, FC_PIXEL_SIZE); |
|
|
1233 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
|
|
1234 | } |
|
|
1235 | |
|
|
1236 | FcPatternDestroy (match); |
|
|
1237 | |
|
|
1238 | #if 0 // do it per-character |
|
|
1239 | if (prop.width != rxvt_fontprop::unset && width > prop.width) |
949 | } |
1240 | { |
|
|
1241 | clear (); |
|
|
1242 | success = false; |
|
|
1243 | } |
|
|
1244 | #endif |
950 | |
1245 | |
951 | XftUnlockFace (f); |
1246 | return success; |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | bool |
|
|
1250 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
|
|
1251 | { |
|
|
1252 | careful = false; |
|
|
1253 | |
|
|
1254 | if (!XftCharExists (term->xdisp, f, unicode)) |
|
|
1255 | return false; |
|
|
1256 | |
|
|
1257 | if (!prop || prop->width == rxvt_fontprop::unset) |
|
|
1258 | return true; |
|
|
1259 | |
|
|
1260 | // check character against base font bounding box |
|
|
1261 | FcChar32 ch = unicode; |
|
|
1262 | XGlyphInfo g; |
|
|
1263 | XftTextExtents32 (term->xdisp, f, &ch, 1, &g); |
|
|
1264 | |
|
|
1265 | int w = g.width - g.x; |
|
|
1266 | int wcw = WCWIDTH (unicode); |
|
|
1267 | |
|
|
1268 | careful = g.x > 0 || w > prop->width * wcw; |
|
|
1269 | |
|
|
1270 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
|
|
1271 | return false; |
|
|
1272 | |
|
|
1273 | // this weeds out _totally_ broken fonts, or glyphs |
|
|
1274 | if (!OVERLAP_OK (g.xOff, wcw, prop)) |
|
|
1275 | return false; |
952 | |
1276 | |
953 | return true; |
1277 | return true; |
954 | } |
|
|
955 | |
|
|
956 | bool |
|
|
957 | rxvt_font_xft::has_codepoint (unicode_t unicode) |
|
|
958 | { |
|
|
959 | return XftCharExists (DISPLAY, f, unicode); |
|
|
960 | } |
1278 | } |
961 | |
1279 | |
962 | void |
1280 | void |
963 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1281 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
964 | const text_t *text, int len, |
1282 | const text_t *text, int len, |
965 | int fg, int bg) |
1283 | int fg, int bg) |
966 | { |
1284 | { |
967 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1285 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
968 | |
1286 | |
969 | if (!slow && width == r->TermWin.fwidth && 0) |
1287 | XGlyphInfo extents; |
970 | { |
1288 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
971 | if (sizeof (text_t) == sizeof (FcChar16)) |
1289 | XftGlyphSpec *ep = enc; |
972 | XftDrawString16 (d, &r->pix_colors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
1290 | |
973 | else |
1291 | dTermDisplay; |
974 | XftDrawString32 (d, &r->pix_colors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
1292 | dTermGC; |
975 | } |
1293 | |
976 | else |
1294 | // cut trailing spaces |
977 | { |
1295 | while (len && text [len - 1] == ' ') |
|
|
1296 | len--; |
|
|
1297 | |
978 | while (len) |
1298 | while (len) |
|
|
1299 | { |
|
|
1300 | int cwidth = term->fwidth; |
|
|
1301 | FcChar32 fc = *text++; len--; |
|
|
1302 | |
|
|
1303 | while (len && *text == NOCHAR) |
|
|
1304 | text++, len--, cwidth += term->fwidth; |
979 | { |
1305 | |
980 | if (*text != NOCHAR && *text != ' ') |
1306 | if (fc != ' ') // skip spaces |
981 | { |
|
|
982 | int fwidth = r->TermWin.fwidth; |
|
|
983 | if (len >= 2 && text[1] == NOCHAR) |
|
|
984 | fwidth *= 2; |
|
|
985 | |
|
|
986 | XGlyphInfo extents; |
|
|
987 | if (sizeof (text_t) == sizeof (FcChar16)) |
|
|
988 | { |
|
|
989 | XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents); |
|
|
990 | XftDrawString16 (d, &r->pix_colors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
991 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
|
|
992 | } |
|
|
993 | else |
|
|
994 | { |
|
|
995 | XGlyphInfo extents; |
|
|
996 | XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents); |
|
|
997 | XftDrawString32 (d, &r->pix_colors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
998 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
|
|
999 | } |
|
|
1000 | } |
|
|
1001 | |
|
|
1002 | x += r->TermWin.fwidth; |
|
|
1003 | text++; |
|
|
1004 | len--; |
|
|
1005 | } |
1307 | { |
|
|
1308 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1309 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
|
|
1310 | |
|
|
1311 | |
|
|
1312 | ep->glyph = glyph; |
|
|
1313 | ep->x = x + (cwidth - extents.xOff >> 1); |
|
|
1314 | ep->y = y + ascent; |
|
|
1315 | |
|
|
1316 | if (extents.xOff == 0) |
|
|
1317 | ep->x = x + cwidth; |
|
|
1318 | |
|
|
1319 | ep++; |
|
|
1320 | } |
|
|
1321 | |
|
|
1322 | x += cwidth; |
1006 | } |
1323 | } |
|
|
1324 | |
|
|
1325 | if (ep != enc) |
|
|
1326 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1007 | } |
1327 | } |
1008 | #endif |
1328 | #endif |
1009 | |
1329 | |
1010 | ///////////////////////////////////////////////////////////////////////////// |
1330 | ///////////////////////////////////////////////////////////////////////////// |
1011 | |
1331 | |
1012 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1332 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1013 | : r (r), fontdesc (0) |
1333 | : fontdesc (0), term (term) |
1014 | { |
1334 | { |
1015 | clear (); |
1335 | clear (); |
1016 | } |
1336 | } |
1017 | |
1337 | |
1018 | rxvt_fontset::~rxvt_fontset () |
1338 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1021 | } |
1341 | } |
1022 | |
1342 | |
1023 | void |
1343 | void |
1024 | rxvt_fontset::clear () |
1344 | rxvt_fontset::clear () |
1025 | { |
1345 | { |
|
|
1346 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
|
|
1347 | = rxvt_fontprop::unset; |
|
|
1348 | |
1026 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1349 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1027 | FONT_UNREF (*i); |
1350 | FONT_UNREF (*i); |
1028 | |
1351 | |
|
|
1352 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
|
|
1353 | delete *p; |
|
|
1354 | |
1029 | free (fontdesc); fontdesc = 0; |
1355 | free (fontdesc); fontdesc = 0; |
1030 | |
1356 | |
1031 | fonts.clear (); |
1357 | fonts.clear (); |
1032 | base_id = 0; |
|
|
1033 | base_prop.height = 0x7fffffff; |
|
|
1034 | base_prop.weight = rxvt_fontprop::medium; |
|
|
1035 | base_prop.slant = rxvt_fontprop::roman; |
|
|
1036 | |
1358 | |
1037 | fallback = fallback_fonts; |
1359 | fallback = fallback_fonts; |
1038 | } |
1360 | } |
1039 | |
1361 | |
1040 | rxvt_font * |
1362 | rxvt_font * |
… | |
… | |
1043 | rxvt_font *f; |
1365 | rxvt_font *f; |
1044 | |
1366 | |
1045 | if (!name || !*name) |
1367 | if (!name || !*name) |
1046 | { |
1368 | { |
1047 | name = ""; |
1369 | name = ""; |
1048 | f = new rxvt_font_default; |
1370 | f = new rxvt_font_default (this); |
1049 | } |
1371 | } |
1050 | #if XFT |
1372 | #if XFT |
1051 | else if (!strncmp (name, "xft:", 4)) |
1373 | else if (!strncmp (name, "xft:", 4)) |
1052 | { |
1374 | { |
1053 | name += 4; |
1375 | name += 4; |
1054 | f = new rxvt_font_xft; |
1376 | f = new rxvt_font_xft (); |
1055 | } |
1377 | } |
1056 | #endif |
1378 | #endif |
1057 | else if (!strncmp (name, "x:", 2)) |
1379 | else if (!strncmp (name, "x:", 2)) |
1058 | { |
1380 | { |
1059 | name += 2; |
1381 | name += 2; |
1060 | f = new rxvt_font_x11; |
1382 | f = new rxvt_font_x11; |
1061 | } |
1383 | } |
1062 | else |
1384 | else |
1063 | f = new rxvt_font_x11; |
1385 | f = new rxvt_font_x11; |
1064 | |
1386 | |
1065 | f->fs = this; |
|
|
1066 | f->set_term (r); |
1387 | f->set_term (term); |
1067 | f->set_name (strdup (name)); |
1388 | f->set_name (strdup (name)); |
1068 | |
1389 | |
1069 | f->cs = cs; |
1390 | f->cs = cs; |
1070 | f->loaded = false; |
1391 | f->loaded = false; |
1071 | |
1392 | |
… | |
… | |
1082 | char buf[512]; |
1403 | char buf[512]; |
1083 | const char *end; |
1404 | const char *end; |
1084 | |
1405 | |
1085 | do |
1406 | do |
1086 | { |
1407 | { |
1087 | while (*desc <= ' ') desc++; |
1408 | while (*desc && *desc <= ' ') |
|
|
1409 | desc++; |
|
|
1410 | |
|
|
1411 | codeset cs = CS_UNICODE; |
1088 | |
1412 | |
1089 | if (*desc == '[') |
1413 | if (*desc == '[') |
1090 | { |
1414 | { |
1091 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1415 | char spec[256]; |
1092 | |
|
|
1093 | //const char *extra = desc++; // not yet used |
1416 | const char *extra = ++desc; // not yet used |
1094 | |
1417 | |
1095 | desc = strchr (desc, ']'); |
1418 | desc = strchr (desc, ']'); |
1096 | |
1419 | |
1097 | if (!desc) |
1420 | if (!desc) |
1098 | { |
1421 | { |
1099 | fprintf (stderr, "ERROR: opening '[' without closing ']' in font specification.\n"); |
1422 | rxvt_warn ("ERROR: opening '[' without closing ']' in font specification, trying to continue.\n"); |
1100 | break; |
1423 | break; |
1101 | } |
1424 | } |
|
|
1425 | |
|
|
1426 | memcpy (spec, extra, min (desc - extra, 255)); |
|
|
1427 | spec[min (desc - extra, 255)] = 0; |
|
|
1428 | |
|
|
1429 | if (!strncmp (extra, "codeset=", sizeof ("codeset=") - 1)) |
|
|
1430 | cs = codeset_from_name (spec + sizeof ("codeset=") - 1); |
|
|
1431 | else |
|
|
1432 | rxvt_warn ("unknown parameter '%s' in font specification, skipping.\n", spec); |
1102 | |
1433 | |
1103 | desc++; |
1434 | desc++; |
1104 | while (*desc <= ' ') desc++; |
1435 | while (*desc <= ' ') desc++; |
1105 | } |
1436 | } |
1106 | |
1437 | |
… | |
… | |
1111 | if (end - desc < 511) |
1442 | if (end - desc < 511) |
1112 | { |
1443 | { |
1113 | strncpy (buf, desc, end - desc); |
1444 | strncpy (buf, desc, end - desc); |
1114 | buf[end - desc] = 0; |
1445 | buf[end - desc] = 0; |
1115 | |
1446 | |
1116 | fonts.push_back (new_font (buf, CS_UNICODE)); |
1447 | fonts.push_back (new_font (buf, cs)); |
1117 | } |
1448 | } |
|
|
1449 | else |
|
|
1450 | rxvt_warn ("fontset element too long (>511 bytes), ignored."); |
1118 | |
1451 | |
1119 | desc = end + 1; |
1452 | desc = end + 1; |
1120 | } |
1453 | } |
1121 | while (*end); |
1454 | while (*end); |
1122 | } |
1455 | } |
1123 | } |
1456 | } |
1124 | |
1457 | |
1125 | bool |
1458 | bool |
1126 | rxvt_fontset::realize_font (int i) |
1459 | rxvt_fontset::realize_font (int i) |
1127 | { |
1460 | { |
|
|
1461 | if (i < 0 || i >= fonts.size ()) |
|
|
1462 | return false; |
|
|
1463 | |
1128 | if (fonts[i]->loaded) |
1464 | if (fonts[i]->loaded) |
1129 | return true; |
1465 | return true; |
1130 | |
1466 | |
1131 | fonts[i]->loaded = true; |
1467 | fonts[i]->loaded = true; |
1132 | |
1468 | |
1133 | if (!fonts[i]->load (base_prop)) |
1469 | if (!fonts[i]->load (prop)) |
1134 | { |
1470 | { |
1135 | fonts[i]->cs = CS_UNKNOWN; |
1471 | fonts[i]->cs = CS_UNKNOWN; |
1136 | return false; |
1472 | return false; |
1137 | } |
1473 | } |
1138 | |
1474 | |
… | |
… | |
1148 | |
1484 | |
1149 | fonts.push_back (new_font (0, CS_UNICODE)); |
1485 | fonts.push_back (new_font (0, CS_UNICODE)); |
1150 | realize_font (0); |
1486 | realize_font (0); |
1151 | |
1487 | |
1152 | add_fonts (desc); |
1488 | add_fonts (desc); |
1153 | |
|
|
1154 | if (!base_id) |
|
|
1155 | base_id = 1; |
|
|
1156 | |
|
|
1157 | // we currently need a base-font, no matter what |
|
|
1158 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
|
|
1159 | { |
|
|
1160 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
|
|
1161 | add_fonts ("fixed"); |
|
|
1162 | base_id = fonts.size () - 1; |
|
|
1163 | } |
|
|
1164 | |
|
|
1165 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
|
|
1166 | return false; |
|
|
1167 | |
|
|
1168 | base_prop = fonts[base_id]->properties (); |
|
|
1169 | |
1489 | |
1170 | return true; |
1490 | return true; |
1171 | } |
1491 | } |
1172 | |
1492 | |
1173 | int |
1493 | int |
… | |
… | |
1179 | |
1499 | |
1180 | return -1; |
1500 | return -1; |
1181 | } |
1501 | } |
1182 | |
1502 | |
1183 | int |
1503 | int |
1184 | rxvt_fontset::find_font (unicode_t unicode, bool bold) |
1504 | rxvt_fontset::find_font (unicode_t unicode) |
1185 | { |
1505 | { |
|
|
1506 | if (unicode >= 1<<20) |
|
|
1507 | return 0; |
1186 | |
1508 | |
1187 | for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii |
1509 | unicode_t hi = unicode >> 8; |
1188 | i < fonts.size (); |
1510 | |
1189 | i++) |
1511 | if (hi < fmap.size () |
|
|
1512 | && fmap[hi] |
|
|
1513 | && (*fmap[hi])[unicode & 0xff] != 0xff) |
|
|
1514 | return (*fmap[hi])[unicode & 0xff]; |
|
|
1515 | |
|
|
1516 | unsigned int i; |
|
|
1517 | |
|
|
1518 | for (i = 0; i < fonts.size (); i++) |
1190 | { |
1519 | { |
1191 | rxvt_font *f = fonts[i]; |
1520 | rxvt_font *f = fonts[i]; |
1192 | |
1521 | |
1193 | if (!f->loaded) |
1522 | if (!f->loaded) |
1194 | { |
1523 | { |
1195 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1524 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1196 | goto next_font; |
1525 | goto next_font; |
1197 | |
1526 | |
1198 | if (!realize_font (i)) |
1527 | if (!realize_font (i)) |
1199 | goto next_font; |
1528 | goto next_font; |
|
|
1529 | |
|
|
1530 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1531 | max_it (f->ascent, prop.ascent); |
1200 | } |
1532 | } |
1201 | |
1533 | |
1202 | if (f->cs == CS_UNKNOWN) |
1534 | if (f->cs == CS_UNKNOWN) |
1203 | goto next_font; |
1535 | goto next_font; |
1204 | |
1536 | |
1205 | if (bold && f->properties ().weight < rxvt_fontprop::bold) |
1537 | bool careful; |
|
|
1538 | if (f->has_char (unicode, &prop, careful)) |
|
|
1539 | { |
|
|
1540 | if (careful) |
|
|
1541 | i |= 128; |
|
|
1542 | |
1206 | goto next_font; |
1543 | goto found; |
1207 | |
1544 | } |
1208 | if (f->has_codepoint (unicode)) |
|
|
1209 | return i; |
|
|
1210 | |
1545 | |
1211 | next_font: |
1546 | next_font: |
1212 | if (i == fonts.size () - 1) |
1547 | if (i == fonts.size () - 1) |
1213 | { |
1548 | { |
1214 | if (fallback->name) |
1549 | if (fallback->name) |
1215 | { |
1550 | { |
1216 | // search through the fallback list |
1551 | // search through the fallback list |
1217 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1552 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1218 | fallback++; |
1553 | fallback++; |
1219 | } |
1554 | } |
1220 | else if (!bold) |
1555 | else |
1221 | { |
1556 | { |
1222 | // try to find a new font. |
1557 | // try to find a new font. |
1223 | // only xft currently supported, as there is no |
1558 | // only xft currently supported, as there is no |
1224 | // way to configure this and xft is easier to hack in, |
1559 | // way to configure this and xft is easier to hack in, |
1225 | // while x11 has more framework in place already. |
1560 | // while x11 has more framework in place already. |
1226 | #if XFT |
1561 | // TODO: this is a real resource hog, xft takes ages(?) |
|
|
1562 | #if XFT && USE_SLOW_LOOKUP |
1227 | // grab the first xft font that seems suitable |
1563 | // grab the first xft font that seems suitable |
1228 | FcPattern *p = FcPatternCreate (); |
1564 | FcPattern *p = FcPatternCreate (); |
1229 | |
1565 | |
1230 | FcCharSet *s = FcCharSetCreate (); |
1566 | FcCharSet *s = FcCharSetCreate (); |
1231 | FcCharSetAddChar (s, unicode); |
1567 | FcCharSetAddChar (s, unicode); |
1232 | FcPatternAddCharSet (p, FC_CHARSET, s); |
1568 | FcPatternAddCharSet (p, FC_CHARSET, s); |
1233 | // charsets don't help that much, as xft might return |
1569 | // charsets don't help that much, as xft might return |
1234 | // a non-matching font even if a better font is available :/ |
1570 | // a non-matching font even if a better font is available :/ |
1235 | |
1571 | |
|
|
1572 | x x x x TODO prop might have unset contents |
1236 | FcPatternAddInteger (p, FC_PIXEL_SIZE, base_prop.height); |
1573 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1237 | FcPatternAddInteger (p, FC_WEIGHT, base_prop.weight); |
1574 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1238 | FcPatternAddInteger (p, FC_SLANT, base_prop.slant); |
1575 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1239 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1576 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1240 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1577 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1241 | |
1578 | |
1242 | XftResult result; |
1579 | XftResult result; |
1243 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1580 | FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); |
1244 | |
1581 | |
1245 | FcPatternDestroy (p); |
1582 | FcPatternDestroy (p); |
1246 | |
1583 | |
1247 | if (match) |
1584 | if (match) |
1248 | { |
1585 | { |
… | |
… | |
1263 | #endif |
1600 | #endif |
1264 | } |
1601 | } |
1265 | } |
1602 | } |
1266 | } |
1603 | } |
1267 | |
1604 | |
1268 | // if no bold font found, use a regular one |
1605 | /* we must return SOME font */ |
1269 | if (bold) |
1606 | i = 0; |
1270 | return find_font (unicode); |
|
|
1271 | |
1607 | |
1272 | return 0; /* we must return SOME font */ |
1608 | found: |
1273 | } |
1609 | // found a font, cache it |
|
|
1610 | if (i < 255) |
|
|
1611 | { |
|
|
1612 | while (hi >= fmap.size ()) |
|
|
1613 | fmap.push_back (0); |
1274 | |
1614 | |
|
|
1615 | if (!fmap[hi]) |
|
|
1616 | { |
|
|
1617 | fmap[hi] = (pagemap *)new pagemap; |
|
|
1618 | memset (fmap[hi], 0xff, sizeof (pagemap)); |
|
|
1619 | } |
1275 | |
1620 | |
|
|
1621 | (*fmap[hi])[unicode & 0xff] = i; |
|
|
1622 | } |
1276 | |
1623 | |
|
|
1624 | return i; |
|
|
1625 | } |
|
|
1626 | |
|
|
1627 | |
|
|
1628 | |