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" |
24 | #include "rxvtutil.h" |
25 | #include "rxvtutil.h" |
25 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
26 | |
27 | |
27 | #include <cstdlib> |
28 | #include <cstdlib> |
28 | #include <wchar.h> |
29 | #include <wchar.h> |
29 | #include <inttypes.h> |
30 | #include <inttypes.h> |
30 | |
|
|
31 | #define DISPLAY r->display->display |
|
|
32 | #define TGC r->TermWin.gc |
|
|
33 | |
31 | |
34 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
32 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | |
33 | |
36 | const struct rxvt_fallback_font { |
34 | const struct rxvt_fallback_font { |
37 | codeset cs; |
35 | codeset cs; |
… | |
… | |
90 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
88 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
91 | #endif |
89 | #endif |
92 | |
90 | |
93 | #if ENCODING_ZH || ENCODING_ZH_EXT |
91 | #if ENCODING_ZH || ENCODING_ZH_EXT |
94 | # if XFT |
92 | # if XFT |
|
|
93 | { CS_GBK_0, "xft:AR PL KaitiM GB" }, |
|
|
94 | { CS_GBK_0, "xft:AR PL SungtiL GB" }, |
|
|
95 | { CS_GBK_0, "xft::spacing=100:lang=zh" }, |
95 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
96 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
96 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
97 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
97 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
98 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
98 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
99 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
99 | { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, |
100 | { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, |
100 | # endif |
101 | # endif |
|
|
102 | { CS_GBK_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gbk*-0" }, |
101 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
103 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
102 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
104 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
103 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
105 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
|
|
106 | { CS_GB2312_1980_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
104 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
107 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
105 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
108 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
106 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
109 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
107 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
110 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
108 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
111 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
… | |
… | |
125 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
128 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
126 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
129 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
127 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
130 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
128 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
129 | #if XFT |
132 | #if XFT |
130 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, |
133 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
131 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
134 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
132 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
135 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
133 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
136 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
134 | |
137 | |
135 | // FreeMono is usually uglier than x fonts, so try last only. |
138 | // FreeMono is usually uglier than x fonts, so try last only. |
136 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
139 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
137 | #endif |
140 | #endif |
138 | |
141 | |
139 | { CS_UNKNOWN, 0 } |
142 | { CS_UNKNOWN, 0 } |
140 | }; |
143 | }; |
141 | |
144 | |
142 | // these characters are used to guess the font height and width |
145 | // these characters are used to guess the font height and width |
143 | // pango uses a similar algorithm and eosn't trust the font either. |
146 | // pango uses a similar algorithm and doesn't trust the font either. |
144 | static uint16_t extent_test_chars[] = { |
147 | static uint16_t extent_test_chars[] = { |
145 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
148 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
146 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
149 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
147 | 0x304c, 0x672c, // が本 |
150 | 0x304c, 0x672c, // が本 |
148 | }; |
151 | }; |
149 | |
152 | |
150 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
153 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
151 | |
154 | |
|
|
155 | #define dTermDisplay Display *disp = term->display->display |
|
|
156 | #define dTermGC GC gc = term->gc |
|
|
157 | |
152 | ///////////////////////////////////////////////////////////////////////////// |
158 | ///////////////////////////////////////////////////////////////////////////// |
153 | |
159 | |
154 | #if XFT |
160 | #if XFT |
155 | rxvt_drawable::~rxvt_drawable () |
161 | rxvt_drawable::~rxvt_drawable () |
156 | { |
162 | { |
… | |
… | |
167 | } |
173 | } |
168 | #endif |
174 | #endif |
169 | |
175 | |
170 | ///////////////////////////////////////////////////////////////////////////// |
176 | ///////////////////////////////////////////////////////////////////////////// |
171 | |
177 | |
172 | static void *enc_buf; |
|
|
173 | static uint32_t enc_len; |
|
|
174 | |
|
|
175 | static inline void * |
|
|
176 | get_enc_buf (uint32_t len) |
|
|
177 | { |
|
|
178 | if (len > enc_len) |
|
|
179 | { |
|
|
180 | free (enc_buf); |
|
|
181 | enc_buf = malloc (len); |
|
|
182 | enc_len = len; |
|
|
183 | } |
|
|
184 | |
|
|
185 | return enc_buf; |
|
|
186 | } |
|
|
187 | |
|
|
188 | static const char * |
178 | static const char * |
189 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
179 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
190 | { |
180 | { |
191 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
181 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
182 | uint8_t *res = buf; |
192 | |
183 | |
193 | while (len--) |
184 | while (len--) |
194 | { |
185 | { |
195 | uint32_t c = FROM_UNICODE (cs, *text++); |
186 | uint32_t c = FROM_UNICODE (cs, *text++); |
196 | |
187 | |
… | |
… | |
201 | } |
192 | } |
202 | |
193 | |
203 | *buf++ = c; |
194 | *buf++ = c; |
204 | } |
195 | } |
205 | |
196 | |
206 | return (const char *)enc_buf; |
197 | return (const char *)res; |
207 | } |
198 | } |
208 | |
199 | |
209 | static const XChar2b * |
200 | static const XChar2b * |
210 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
201 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
211 | { |
202 | { |
212 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
203 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
204 | XChar2b *res = buf; |
213 | |
205 | |
214 | while (len--) |
206 | while (len--) |
215 | { |
207 | { |
216 | uint32_t c = FROM_UNICODE (cs, *text++); |
208 | uint32_t c = FROM_UNICODE (cs, *text++); |
217 | |
209 | |
… | |
… | |
224 | buf->byte1 = c >> 8; |
216 | buf->byte1 = c >> 8; |
225 | buf->byte2 = c; |
217 | buf->byte2 = c; |
226 | buf++; |
218 | buf++; |
227 | } |
219 | } |
228 | |
220 | |
229 | return (XChar2b *)enc_buf; |
221 | return res; |
230 | } |
222 | } |
231 | |
223 | |
232 | ///////////////////////////////////////////////////////////////////////////// |
224 | ///////////////////////////////////////////////////////////////////////////// |
233 | |
225 | |
234 | void |
226 | void |
… | |
… | |
240 | if (this->name) free (this->name); // let the compiler optimize |
232 | if (this->name) free (this->name); // let the compiler optimize |
241 | this->name = name; |
233 | this->name = name; |
242 | } |
234 | } |
243 | |
235 | |
244 | void |
236 | void |
245 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
237 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
246 | { |
238 | { |
|
|
239 | dTermDisplay; |
|
|
240 | dTermGC; |
|
|
241 | |
247 | if (color == Color_bg) |
242 | if (color == Color_bg) |
248 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
243 | XClearArea (disp, d, x, y, w, h, FALSE); |
249 | else if (color >= 0) |
244 | else if (color >= 0) |
250 | { |
245 | { |
251 | #if XFT |
246 | #if XFT |
252 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
247 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
253 | #else |
248 | #else |
254 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
249 | XSetForeground (disp, gc, term->pix_colors[color]); |
255 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
250 | XFillRectangle (disp, d, gc, x, y, w, h); |
256 | #endif |
251 | #endif |
257 | } |
252 | } |
258 | } |
253 | } |
259 | |
254 | |
260 | #include "table/linedraw.h" |
255 | #include "table/linedraw.h" |
… | |
… | |
271 | rxvt_fontprop properties () |
266 | rxvt_fontprop properties () |
272 | { |
267 | { |
273 | rxvt_fontprop p; |
268 | rxvt_fontprop p; |
274 | |
269 | |
275 | p.width = p.height = 1; |
270 | p.width = p.height = 1; |
|
|
271 | p.ascent = rxvt_fontprop::unset; |
276 | p.weight = rxvt_fontprop::medium; |
272 | p.weight = rxvt_fontprop::medium; |
277 | p.slant = rxvt_fontprop::roman; |
273 | p.slant = rxvt_fontprop::roman; |
278 | |
274 | |
279 | return p; |
275 | return p; |
280 | } |
276 | } |
… | |
… | |
287 | set_name (strdup ("built-in support font")); |
283 | set_name (strdup ("built-in support font")); |
288 | |
284 | |
289 | return true; |
285 | return true; |
290 | } |
286 | } |
291 | |
287 | |
292 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
288 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
293 | { |
289 | { |
294 | careful = false; |
290 | careful = false; |
295 | |
291 | |
296 | if (unicode <= 0x001f) |
292 | if (unicode <= 0x001f) |
297 | return true; |
293 | return true; |
… | |
… | |
300 | return false; |
296 | return false; |
301 | |
297 | |
302 | if (unicode <= 0x009f) |
298 | if (unicode <= 0x009f) |
303 | return true; |
299 | return true; |
304 | |
300 | |
305 | if (unicode >= 0x2500 && unicode <= 0x259f) |
301 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
302 | !term->option (Opt_skipBuiltinGlyphs)) |
306 | return true; |
303 | return true; |
307 | |
304 | |
308 | if (IS_COMPOSE (unicode)) |
305 | if (IS_COMPOSE (unicode)) |
309 | return true; |
306 | return true; |
310 | |
307 | |
… | |
… | |
326 | void |
323 | void |
327 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
324 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
328 | const text_t *text, int len, |
325 | const text_t *text, int len, |
329 | int fg, int bg) |
326 | int fg, int bg) |
330 | { |
327 | { |
|
|
328 | dTermDisplay; |
|
|
329 | dTermGC; |
|
|
330 | |
331 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
331 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
332 | |
332 | |
333 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
333 | XSetForeground (disp, gc, term->pix_colors[fg]); |
334 | |
334 | |
335 | while (len--) |
335 | while (len) |
336 | { |
336 | { |
337 | #if ENABLE_COMBINING |
337 | #if ENABLE_COMBINING |
338 | compose_char *cc; |
338 | compose_char *cc; |
339 | #endif |
339 | #endif |
|
|
340 | const text_t *tp = text; |
340 | text_t t = *text++; |
341 | text_t t = *tp; |
|
|
342 | |
|
|
343 | while (++text, --len && *text == NOCHAR) |
|
|
344 | ; |
|
|
345 | |
|
|
346 | int width = text - tp; |
|
|
347 | int fwidth = term->fwidth * width; |
341 | |
348 | |
342 | if (0x2500 <= t && t <= 0x259f) |
349 | if (0x2500 <= t && t <= 0x259f) |
343 | { |
350 | { |
344 | uint16_t offs = linedraw_offs[t - 0x2500]; |
351 | uint16_t offs = linedraw_offs[t - 0x2500]; |
345 | uint32_t *a = linedraw_command + (offs >> 4); |
352 | uint32_t *a = linedraw_command + (offs >> 4); |
346 | uint32_t *b = a + (offs & 15); |
353 | uint32_t *b = a + (offs & 15); |
347 | |
354 | |
348 | int W = r->TermWin.fwidth; |
355 | int W = fwidth; |
349 | int H = r->TermWin.fheight; |
356 | int H = term->fheight; |
350 | |
357 | |
351 | int x_[16]; |
358 | int x_[16]; |
352 | int y_[16]; |
359 | int y_[16]; |
353 | |
360 | |
354 | for (int i = 0; i <= 8; i++) |
361 | for (int i = 0; i <= 8; i++) |
… | |
… | |
362 | |
369 | |
363 | XGCValues gcv; |
370 | XGCValues gcv; |
364 | |
371 | |
365 | gcv.cap_style = CapButt; |
372 | gcv.cap_style = CapButt; |
366 | gcv.line_width = 0; |
373 | gcv.line_width = 0; |
367 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
374 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
368 | |
375 | |
369 | while (a < b) |
376 | while (a < b) |
370 | { |
377 | { |
371 | uint32_t command = *a++; |
378 | uint32_t command = *a++; |
372 | |
379 | |
… | |
… | |
379 | int y2 = y_[(command >> 0) & 15]; |
386 | int y2 = y_[(command >> 0) & 15]; |
380 | |
387 | |
381 | switch (op) |
388 | switch (op) |
382 | { |
389 | { |
383 | case 0: // line |
390 | case 0: // line |
384 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
391 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
385 | break; |
392 | break; |
386 | |
393 | |
387 | case 1: // rectangle, possibly stippled |
394 | case 1: // rectangle, possibly stippled |
388 | if (a) |
395 | if (a) |
389 | { |
396 | { |
390 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
397 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
391 | |
398 | |
392 | gcv.fill_style = FillStippled; |
399 | gcv.fill_style = FillStippled; |
393 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
400 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
394 | gcv.ts_x_origin = x; |
401 | gcv.ts_x_origin = x; |
395 | gcv.ts_y_origin = y; |
402 | gcv.ts_y_origin = y; |
396 | |
403 | |
397 | XChangeGC (d.display->display, TGC, |
404 | XChangeGC (disp, gc, |
398 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
405 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
399 | &gcv); |
406 | &gcv); |
400 | } |
407 | } |
401 | |
408 | |
402 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
409 | XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
403 | |
410 | |
404 | if (a) |
411 | if (a) |
405 | { |
412 | { |
406 | XFreePixmap (d.display->display, gcv.stipple); |
413 | XFreePixmap (disp, gcv.stipple); |
407 | gcv.stipple = 0; |
414 | gcv.stipple = 0; |
408 | gcv.fill_style = FillSolid; |
415 | gcv.fill_style = FillSolid; |
409 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
416 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
410 | } |
417 | } |
411 | break; |
418 | break; |
412 | case 2: // arc |
419 | case 2: // arc |
413 | XDrawArc (d.display->display, d, TGC, |
420 | XDrawArc (disp, d, gc, |
414 | x1 - W/2, y1 - H/2, W-1, H-1, |
421 | x1 - W/2, y1 - H/2, W-1, H-1, |
415 | (a - 1) * 90*64, (b - 1) * 90*64); |
422 | (a - 1) * 90*64, (b - 1) * 90*64); |
416 | break; |
423 | break; |
417 | } |
424 | } |
418 | } |
425 | } |
419 | } |
426 | } |
420 | #if ENABLE_COMBINING |
427 | #if ENABLE_COMBINING |
421 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
428 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
422 | { |
429 | { |
423 | text_t c2[2]; |
430 | text_t chrs[2]; |
424 | int len2 = 1; |
431 | width = min (2, width); |
425 | |
432 | chrs [1] = NOCHAR; |
426 | // support double-width (but not more) combining characters |
|
|
427 | if (len && *text == NOCHAR) |
|
|
428 | { |
|
|
429 | c2[1] = *text; // not text++ to get correct x-width |
|
|
430 | len2++; |
|
|
431 | } |
|
|
432 | |
433 | |
433 | c2[0] = cc->c1; |
434 | *chrs = cc->c1; |
434 | rxvt_font *f1 = (*fs)[fs->find_font (c2[0])]; |
435 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
435 | f1->draw (d, x, y, c2, len2, fg, bg); |
436 | f1->draw (d, x, y, chrs, width, fg, bg); |
436 | |
437 | |
437 | if (cc->c2 != NOCHAR) |
438 | if (cc->c2 != NOCHAR) |
438 | { |
439 | { |
439 | bool careful; |
440 | bool careful; |
440 | |
441 | |
441 | // prefer font of first character, for no good reasons |
442 | // prefer font of first character, for no good reasons |
442 | c2[0] = cc->c2; |
443 | *chrs = cc->c2; |
443 | rxvt_font *f2 = (f1->has_char (c2[0], 0, careful) && !careful) |
444 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
444 | ? f1 |
445 | ? f1 |
445 | : (*fs)[fs->find_font (c2[0])]; |
446 | : (*fs)[fs->find_font (cc->c2)]; |
446 | |
447 | |
447 | f2->draw (d, x, y, c2, len2, fg, -1); |
448 | f2->draw (d, x, y, chrs, width, fg, -1); |
448 | } |
449 | } |
449 | } |
450 | } |
450 | #endif |
451 | #endif |
451 | else |
452 | else |
452 | switch (t) |
453 | switch (t) |
… | |
… | |
455 | case ZERO_WIDTH_CHAR: |
456 | case ZERO_WIDTH_CHAR: |
456 | case NOCHAR: |
457 | case NOCHAR: |
457 | break; |
458 | break; |
458 | |
459 | |
459 | default: |
460 | default: |
460 | int w = 0; |
|
|
461 | while (len > 0 && *text == NOCHAR) |
|
|
462 | { |
|
|
463 | ++text; |
|
|
464 | --len; |
|
|
465 | w += r->TermWin.fwidth; |
|
|
466 | } |
|
|
467 | |
|
|
468 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
461 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
469 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
462 | fwidth - 4, term->fheight - 4); |
470 | x += w; |
|
|
471 | } |
463 | } |
472 | |
464 | |
473 | x += r->TermWin.fwidth; |
465 | x += fwidth; |
474 | } |
466 | } |
475 | } |
467 | } |
476 | |
468 | |
477 | ///////////////////////////////////////////////////////////////////////////// |
469 | ///////////////////////////////////////////////////////////////////////////// |
478 | |
470 | |
… | |
… | |
483 | |
475 | |
484 | rxvt_fontprop properties (); |
476 | rxvt_fontprop properties (); |
485 | |
477 | |
486 | bool load (const rxvt_fontprop &prop); |
478 | bool load (const rxvt_fontprop &prop); |
487 | |
479 | |
488 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); |
480 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
489 | |
481 | |
490 | void draw (rxvt_drawable &d, int x, int y, |
482 | void draw (rxvt_drawable &d, int x, int y, |
491 | const text_t *text, int len, |
483 | const text_t *text, int len, |
492 | int fg, int bg); |
484 | int fg, int bg); |
493 | |
485 | |
… | |
… | |
505 | char * |
497 | char * |
506 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
498 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
507 | { |
499 | { |
508 | unsigned long value; |
500 | unsigned long value; |
509 | |
501 | |
510 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
502 | if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value)) |
511 | return XGetAtomName (DISPLAY, value); |
503 | return XGetAtomName (term->display->display, value); |
512 | else |
504 | else |
513 | return rxvt_strdup (repl); |
505 | return rxvt_strdup (repl); |
514 | } |
506 | } |
515 | |
507 | |
516 | rxvt_fontprop |
508 | rxvt_fontprop |
… | |
… | |
524 | bool |
516 | bool |
525 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
517 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
526 | { |
518 | { |
527 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
519 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
528 | p.height = height; |
520 | p.height = height; |
|
|
521 | p.ascent = rxvt_fontprop::unset; |
529 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
522 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
530 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
523 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
531 | |
524 | |
532 | return true; |
525 | return true; |
533 | } |
526 | } |
534 | |
527 | |
535 | bool |
528 | bool |
536 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
529 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
537 | { |
530 | { |
538 | unsigned long height; |
531 | unsigned long height; |
|
|
532 | |
|
|
533 | #if 0 |
539 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
534 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height)) |
540 | return false; |
535 | return false; |
|
|
536 | #else |
|
|
537 | height = f->ascent + f->descent; |
|
|
538 | #endif |
541 | |
539 | |
542 | unsigned long avgwidth; |
540 | unsigned long avgwidth; |
543 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
541 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth)) |
544 | avgwidth = 0; |
542 | avgwidth = 0; |
545 | |
543 | |
546 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
544 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
547 | char *slant = get_property (f, "SLANT", "r"); |
545 | char *slant = get_property (f, "SLANT", "r"); |
548 | |
546 | |
549 | set_properties (p, height, weight, slant, avgwidth); |
547 | set_properties (p, height, weight, slant, avgwidth); |
550 | |
548 | |
551 | free (weight); |
549 | free (weight); |
552 | free (slant); |
550 | free (slant); |
553 | |
551 | |
|
|
552 | p.ascent = f->ascent; |
|
|
553 | |
554 | return true; |
554 | return true; |
555 | } |
555 | } |
556 | |
556 | |
557 | bool |
557 | bool |
558 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
558 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
559 | { |
559 | { |
|
|
560 | dTermDisplay; |
560 | int slashes = 0; |
561 | int slashes = 0; |
561 | const char *comp[13]; |
562 | const char *comp[13]; |
562 | |
563 | |
563 | for (const char *c = name; *c; c++) |
564 | for (const char *c = name; *c; c++) |
564 | if (*c == '-') |
565 | if (*c == '-') |
… | |
… | |
572 | if (slashes >= 13 |
573 | if (slashes >= 13 |
573 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
574 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
574 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
575 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
575 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
576 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
576 | |
577 | |
577 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
578 | XFontStruct *f = XLoadQueryFont (disp, name); |
578 | |
579 | |
579 | if (f) |
580 | if (f) |
580 | { |
581 | { |
581 | // the font should really exist now. if not, we have a problem |
582 | // the font should really exist now. if not, we have a problem |
582 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
583 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
583 | // in that case, just return garbage. |
584 | // in that case, just return garbage. |
584 | bool ret = set_properties (p, f); |
585 | bool ret = set_properties (p, f); |
585 | XFreeFont (DISPLAY, f); |
586 | XFreeFont (disp, f); |
586 | return ret; |
587 | return ret; |
587 | } |
588 | } |
588 | else |
589 | else |
589 | return false; |
590 | return false; |
590 | } |
591 | } |
… | |
… | |
628 | } |
629 | } |
629 | |
630 | |
630 | bool |
631 | bool |
631 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
632 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
632 | { |
633 | { |
|
|
634 | dTermDisplay; |
|
|
635 | |
633 | clear (); |
636 | clear (); |
634 | |
637 | |
635 | char field_str[64]; // enough for 128 bits |
638 | char field_str[64]; // enough for 128 bits |
636 | |
639 | |
637 | // first morph the font if required |
640 | // first morph the font if required |
… | |
… | |
640 | { |
643 | { |
641 | char fname[1024]; |
644 | char fname[1024]; |
642 | |
645 | |
643 | if (name[0] != '-') |
646 | if (name[0] != '-') |
644 | { |
647 | { |
645 | f = XLoadQueryFont (DISPLAY, name); |
648 | f = XLoadQueryFont (disp, name); |
646 | |
649 | |
647 | if (!f) |
650 | if (!f) |
648 | return false; |
651 | return false; |
649 | |
652 | |
650 | char *new_name = get_property (f, "FONT", name); |
653 | char *new_name = get_property (f, "FONT", name); |
… | |
… | |
652 | if (new_name) |
655 | if (new_name) |
653 | set_name (new_name); |
656 | set_name (new_name); |
654 | else |
657 | else |
655 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
658 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
656 | |
659 | |
657 | XFreeFont (DISPLAY, f); |
660 | XFreeFont (disp, f); |
658 | f = 0; |
661 | f = 0; |
659 | } |
662 | } |
660 | |
663 | |
661 | if (prop.weight != rxvt_fontprop::unset) |
664 | if (prop.weight != rxvt_fontprop::unset) |
662 | { |
665 | { |
… | |
… | |
673 | ? "r" : "i"); // TODO: handle "o"blique, too |
676 | ? "r" : "i"); // TODO: handle "o"blique, too |
674 | set_name (strdup (fname)); |
677 | set_name (strdup (fname)); |
675 | } |
678 | } |
676 | } |
679 | } |
677 | |
680 | |
|
|
681 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
|
|
682 | ? 0 : prop.height); |
|
|
683 | |
|
|
684 | struct font_weight { |
|
|
685 | char *name; |
|
|
686 | int diff; |
|
|
687 | |
|
|
688 | void clear () |
|
|
689 | { |
|
|
690 | name = 0; |
|
|
691 | diff = 0x7fffffff; |
|
|
692 | } |
|
|
693 | |
|
|
694 | font_weight () { clear (); } |
|
|
695 | ~font_weight () { free (name); } |
|
|
696 | }; |
|
|
697 | |
678 | char **list; |
698 | char **list; |
679 | int count; |
699 | int count; |
680 | list = XListFonts (DISPLAY, name, 1024, &count); |
700 | list = XListFonts (disp, name, 4000, &count); |
681 | |
701 | |
682 | set_name (0); |
702 | set_name (0); |
683 | |
703 | |
684 | if (!list) |
704 | if (!list) |
685 | return false; |
705 | return false; |
686 | |
706 | |
687 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
707 | font_weight *fonts = new font_weight[count]; |
688 | ? 0 : prop.height); |
|
|
689 | |
708 | |
690 | int bestdiff = 0x7fffffff; |
|
|
691 | for (int i = 0; i < count; i++) |
709 | for (int i = 0; i < count; i++) |
692 | { |
710 | { |
693 | rxvt_fontprop p; |
711 | rxvt_fontprop p; |
694 | char fname[1024]; |
712 | char fname[1024]; |
695 | |
713 | |
696 | int diff = 0; |
714 | int diff = 0; |
697 | |
715 | |
698 | if (replace_field (fname, list[i], 6, '0', field_str)) |
716 | if (replace_field (fname, list[i], 6, '0', field_str)) |
699 | diff += 10; // slightly penalize scalable fonts |
717 | diff += 10; // slightly penalize scalable fonts |
|
|
718 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
719 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
700 | |
720 | |
701 | if (!set_properties (p, fname)) |
721 | if (!set_properties (p, fname)) |
702 | continue; |
722 | continue; |
703 | |
723 | |
704 | if (prop.height != rxvt_fontprop::unset |
724 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
708 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
728 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
709 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
729 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
710 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
730 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
711 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
731 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
712 | |
732 | |
713 | if (!name // compare against best found so far |
733 | fonts[i].name = strdup (fname); |
714 | || diff < bestdiff) |
734 | fonts[i].diff = diff; |
715 | { |
|
|
716 | set_name (strdup (fname)); |
|
|
717 | bestdiff = diff; |
|
|
718 | } |
|
|
719 | } |
735 | } |
720 | |
736 | |
721 | XFreeFontNames (list); |
737 | XFreeFontNames (list); |
722 | |
738 | |
723 | if (!name) |
739 | // this loop only iterates when the guessed font-size is too small |
724 | return false; |
740 | for (;;) |
|
|
741 | { |
|
|
742 | font_weight *best = fonts + count - 1; |
725 | |
743 | |
726 | f = XLoadQueryFont (DISPLAY, name); |
744 | for (font_weight *w = best; w-- > fonts; ) |
|
|
745 | if (w->diff <= best->diff) |
|
|
746 | best = w; |
|
|
747 | |
|
|
748 | if (!best->name |
|
|
749 | || !(f = XLoadQueryFont (disp, best->name))) |
|
|
750 | break; |
|
|
751 | |
|
|
752 | set_name (best->name); |
|
|
753 | best->clear (); |
|
|
754 | |
|
|
755 | ascent = f->ascent; |
|
|
756 | descent = f->descent; |
|
|
757 | height = ascent + descent; |
|
|
758 | |
|
|
759 | if (prop.height == rxvt_fontprop::unset |
|
|
760 | || height <= prop.height) |
|
|
761 | break; // font is ready for use |
|
|
762 | |
|
|
763 | // PIXEL_SIZE small enough, but real height too large |
|
|
764 | clear (); |
|
|
765 | } |
|
|
766 | |
|
|
767 | delete [] fonts; |
727 | |
768 | |
728 | if (!f) |
769 | if (!f) |
729 | return false; |
770 | return false; |
730 | |
771 | |
731 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
772 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
… | |
… | |
759 | if (cs == CS_UNICODE) |
800 | if (cs == CS_UNICODE) |
760 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
801 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
761 | |
802 | |
762 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
803 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
763 | enc2b = encm || f->max_char_or_byte2 > 255; |
804 | enc2b = encm || f->max_char_or_byte2 > 255; |
764 | |
|
|
765 | ascent = f->ascent; |
|
|
766 | descent = f->descent; |
|
|
767 | height = ascent + descent; |
|
|
768 | |
805 | |
769 | slow = false; |
806 | slow = false; |
770 | |
807 | |
771 | #if 1 // only used for slow detection, TODO optimize |
808 | #if 1 // only used for slow detection, TODO optimize |
772 | if (f->min_bounds.width == f->max_bounds.width) |
809 | if (f->min_bounds.width == f->max_bounds.width) |
… | |
… | |
811 | |
848 | |
812 | XCharStruct g; |
849 | XCharStruct g; |
813 | int dir_ret, asc_ret, des_ret; |
850 | int dir_ret, asc_ret, des_ret; |
814 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
851 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
815 | |
852 | |
816 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
853 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
817 | |
854 | |
818 | if (width < g.width) width = g.width; |
855 | if (width < g.width) width = g.width; |
819 | } |
856 | } |
820 | |
857 | |
821 | if (cs == CS_UNKNOWN) |
858 | if (cs == CS_UNKNOWN) |
… | |
… | |
840 | void |
877 | void |
841 | rxvt_font_x11::clear () |
878 | rxvt_font_x11::clear () |
842 | { |
879 | { |
843 | if (f) |
880 | if (f) |
844 | { |
881 | { |
845 | XFreeFont (DISPLAY, f); |
882 | XFreeFont (term->display->display, f); |
846 | f = 0; |
883 | f = 0; |
847 | } |
884 | } |
848 | } |
885 | } |
849 | |
886 | |
850 | bool |
887 | bool |
851 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
888 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
852 | { |
889 | { |
853 | uint32_t ch = FROM_UNICODE (cs, unicode); |
890 | uint32_t ch = FROM_UNICODE (cs, unicode); |
854 | |
891 | |
855 | if (ch == NOCHAR) |
892 | if (ch == NOCHAR) |
856 | return false; |
893 | return false; |
… | |
… | |
896 | return true; |
933 | return true; |
897 | |
934 | |
898 | // check character against base font bounding box |
935 | // check character against base font bounding box |
899 | int w = xcs->width; |
936 | int w = xcs->width; |
900 | int wcw = wcwidth (unicode); |
937 | int wcw = wcwidth (unicode); |
901 | if (wcw > 0) w /= wcw; |
938 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
902 | |
939 | |
903 | careful = w > prop->width; |
940 | careful = w > prop->width; |
904 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
941 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
905 | return false; |
942 | return false; |
906 | |
943 | |
… | |
… | |
915 | // this looks like a mess /. |
952 | // this looks like a mess /. |
916 | // and it is a mess /. |
953 | // and it is a mess /. |
917 | // yet we are trying to be perfect /. |
954 | // yet we are trying to be perfect /. |
918 | // but the result still isn't perfect /. |
955 | // but the result still isn't perfect /. |
919 | |
956 | |
|
|
957 | dTermDisplay; |
|
|
958 | dTermGC; |
|
|
959 | |
920 | bool slow = this->slow |
960 | bool slow = this->slow |
921 | || width != r->TermWin.fwidth |
961 | || width != term->fwidth |
922 | || height != r->TermWin.fheight; |
962 | || height != term->fheight; |
923 | |
963 | |
924 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
964 | int base = ascent; // sorry, incorrect: term->fbase; |
925 | |
965 | |
926 | XGCValues v; |
966 | XGCValues v; |
927 | v.foreground = r->pix_colors[fg]; |
967 | v.foreground = term->pix_colors[fg]; |
928 | v.font = f->fid; |
968 | v.font = f->fid; |
929 | |
969 | |
930 | if (enc2b) |
970 | if (enc2b) |
931 | { |
971 | { |
932 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
972 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
933 | |
973 | |
934 | if (bg == Color_bg && !slow) |
974 | if (bg == Color_bg && !slow) |
935 | { |
975 | { |
936 | v.background = r->pix_colors[bg]; |
976 | v.background = term->pix_colors[bg]; |
937 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
977 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
938 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
978 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
939 | } |
979 | } |
940 | else |
980 | else |
941 | { |
981 | { |
942 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
982 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
943 | |
983 | |
944 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
984 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
945 | |
985 | |
946 | if (slow) |
986 | if (slow) |
947 | { |
987 | { |
948 | do |
988 | do |
949 | { |
989 | { |
950 | if (xc->byte1 || xc->byte2) |
990 | if (xc->byte1 || xc->byte2) |
951 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
991 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
952 | |
992 | |
953 | x += r->TermWin.fwidth; |
993 | x += term->fwidth; |
954 | xc++; len--; |
994 | xc++; len--; |
955 | } |
995 | } |
956 | while (len); |
996 | while (len); |
957 | } |
997 | } |
958 | else |
998 | else |
959 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
999 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
960 | } |
1000 | } |
961 | } |
1001 | } |
962 | else |
1002 | else |
963 | { |
1003 | { |
964 | const char *xc = enc_char (text, len, cs, slow); |
1004 | const char *xc = enc_char (text, len, cs, slow); |
965 | |
1005 | |
966 | if (bg == Color_bg && !slow) |
1006 | if (bg == Color_bg && !slow) |
967 | { |
1007 | { |
968 | v.background = r->pix_colors[bg]; |
1008 | v.background = term->pix_colors[bg]; |
969 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1009 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
970 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1010 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
971 | } |
1011 | } |
972 | else |
1012 | else |
973 | { |
1013 | { |
974 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1014 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
975 | |
1015 | |
976 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1016 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
977 | |
1017 | |
978 | if (slow) |
1018 | if (slow) |
979 | { |
1019 | { |
980 | do |
1020 | do |
981 | { |
1021 | { |
982 | if (*xc) |
1022 | if (*xc) |
983 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1023 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
984 | |
1024 | |
985 | x += r->TermWin.fwidth; |
1025 | x += term->fwidth; |
986 | xc++; len--; |
1026 | xc++; len--; |
987 | } |
1027 | } |
988 | while (len); |
1028 | while (len); |
989 | } |
1029 | } |
990 | else |
1030 | else |
991 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1031 | XDrawString (disp, d, gc, x, y + base, xc, len); |
992 | } |
1032 | } |
993 | } |
1033 | } |
994 | } |
1034 | } |
995 | |
1035 | |
996 | ///////////////////////////////////////////////////////////////////////////// |
1036 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
1008 | |
1048 | |
1009 | void draw (rxvt_drawable &d, int x, int y, |
1049 | void draw (rxvt_drawable &d, int x, int y, |
1010 | const text_t *text, int len, |
1050 | const text_t *text, int len, |
1011 | int fg, int bg); |
1051 | int fg, int bg); |
1012 | |
1052 | |
1013 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); |
1053 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; |
1014 | |
1054 | |
1015 | protected: |
1055 | protected: |
1016 | XftFont *f; |
1056 | XftFont *f; |
1017 | }; |
1057 | }; |
1018 | |
1058 | |
1019 | void |
1059 | void |
1020 | rxvt_font_xft::clear () |
1060 | rxvt_font_xft::clear () |
1021 | { |
1061 | { |
1022 | if (f) |
1062 | if (f) |
1023 | { |
1063 | { |
1024 | XftFontClose (DISPLAY, f); |
1064 | XftFontClose (term->display->display, f); |
1025 | f = 0; |
1065 | f = 0; |
1026 | } |
1066 | } |
1027 | } |
1067 | } |
1028 | |
1068 | |
1029 | rxvt_fontprop |
1069 | rxvt_fontprop |
… | |
… | |
1033 | |
1073 | |
1034 | FT_Face face = XftLockFace (f); |
1074 | FT_Face face = XftLockFace (f); |
1035 | |
1075 | |
1036 | p.width = width; |
1076 | p.width = width; |
1037 | p.height = height; |
1077 | p.height = height; |
|
|
1078 | p.ascent = ascent; |
1038 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1079 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1039 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1080 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1040 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1081 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1041 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1082 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1042 | |
1083 | |
… | |
… | |
1046 | } |
1087 | } |
1047 | |
1088 | |
1048 | bool |
1089 | bool |
1049 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1090 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1050 | { |
1091 | { |
|
|
1092 | dTermDisplay; |
|
|
1093 | |
1051 | clear (); |
1094 | clear (); |
1052 | |
1095 | |
1053 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1096 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1054 | |
1097 | |
1055 | if (!p) |
1098 | if (!p) |
1056 | return false; |
1099 | return false; |
1057 | |
1100 | |
1058 | FcValue v; |
1101 | FcValue v; |
1059 | |
1102 | |
1060 | if (prop.height != rxvt_fontprop::unset |
1103 | if (prop.height != rxvt_fontprop::unset |
1061 | || FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch) |
1104 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
|
|
1105 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1062 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1106 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1063 | |
1107 | |
1064 | if (prop.weight != rxvt_fontprop::unset |
1108 | if (prop.weight != rxvt_fontprop::unset |
1065 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1109 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1066 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1110 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
… | |
… | |
1080 | |
1124 | |
1081 | // store generated name so iso14755 view gives better results |
1125 | // store generated name so iso14755 view gives better results |
1082 | set_name ((char *)FcNameUnparse (p)); |
1126 | set_name ((char *)FcNameUnparse (p)); |
1083 | |
1127 | |
1084 | XftResult result; |
1128 | XftResult result; |
1085 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1129 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
1086 | |
1130 | |
1087 | FcPatternDestroy (p); |
1131 | FcPatternDestroy (p); |
1088 | |
1132 | |
1089 | if (!match) |
1133 | if (!match) |
1090 | return false; |
1134 | return false; |
… | |
… | |
1092 | int ftheight = 0; |
1136 | int ftheight = 0; |
1093 | bool success = true; |
1137 | bool success = true; |
1094 | |
1138 | |
1095 | for (;;) |
1139 | for (;;) |
1096 | { |
1140 | { |
1097 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1141 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1098 | |
1142 | |
1099 | if (!f) |
1143 | if (!f) |
1100 | { |
1144 | { |
1101 | success = false; |
1145 | success = false; |
1102 | break; |
1146 | break; |
… | |
… | |
1111 | |
1155 | |
1112 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1156 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1113 | |
1157 | |
1114 | XftUnlockFace (f); |
1158 | XftUnlockFace (f); |
1115 | |
1159 | |
|
|
1160 | int glheight = height; |
|
|
1161 | |
1116 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1162 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1117 | { |
1163 | { |
1118 | FcChar16 ch = *t; |
1164 | FcChar16 ch = *t; |
1119 | |
1165 | |
1120 | if (cs != CS_UNICODE |
1166 | if (cs != CS_UNICODE |
… | |
… | |
1126 | bool careful; |
1172 | bool careful; |
1127 | if (!has_char (*t, &prop, careful)) |
1173 | if (!has_char (*t, &prop, careful)) |
1128 | continue; |
1174 | continue; |
1129 | |
1175 | |
1130 | XGlyphInfo g; |
1176 | XGlyphInfo g; |
1131 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1177 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1178 | |
|
|
1179 | g.width -= g.x; |
1132 | |
1180 | |
1133 | int wcw = wcwidth (ch); |
1181 | int wcw = wcwidth (ch); |
1134 | if (wcw > 0) g.width = g.width / wcw; |
1182 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1135 | |
1183 | |
1136 | if (width < g.width) width = g.width; |
1184 | if (width < g.width ) width = g.width; |
1137 | if (height < g.height) height = g.height; |
1185 | if (height < g.height ) height = g.height; |
|
|
1186 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1187 | } |
|
|
1188 | |
|
|
1189 | if (!width) |
|
|
1190 | { |
|
|
1191 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1192 | |
|
|
1193 | XftFontClose (disp, f); |
|
|
1194 | f = 0; |
|
|
1195 | |
|
|
1196 | success = false; |
|
|
1197 | break; |
1138 | } |
1198 | } |
1139 | |
1199 | |
1140 | if (prop.height == rxvt_fontprop::unset |
1200 | if (prop.height == rxvt_fontprop::unset |
1141 | || height <= prop.height |
1201 | || (height <= prop.height && glheight <= prop.height) |
1142 | || height <= 2 |
1202 | || height <= 2 |
1143 | || !scalable) |
1203 | || !scalable) |
1144 | break; |
1204 | break; |
1145 | |
1205 | |
1146 | if (ftheight) |
1206 | if (ftheight) |
… | |
… | |
1153 | ftheight -= height - prop.height; |
1213 | ftheight -= height - prop.height; |
1154 | } |
1214 | } |
1155 | else |
1215 | else |
1156 | ftheight = prop.height - 1; |
1216 | ftheight = prop.height - 1; |
1157 | |
1217 | |
1158 | XftFontClose (DISPLAY, f); |
1218 | XftFontClose (disp, f); |
1159 | FcPatternDel (match, FC_PIXEL_SIZE); |
1219 | FcPatternDel (match, FC_PIXEL_SIZE); |
1160 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1220 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1161 | } |
1221 | } |
1162 | |
1222 | |
1163 | FcPatternDestroy (match); |
1223 | FcPatternDestroy (match); |
1164 | |
1224 | |
1165 | #if 0 // do it per-character |
1225 | #if 0 // do it per-character |
… | |
… | |
1172 | |
1232 | |
1173 | return success; |
1233 | return success; |
1174 | } |
1234 | } |
1175 | |
1235 | |
1176 | bool |
1236 | bool |
1177 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
1237 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1178 | { |
1238 | { |
1179 | careful = false; |
1239 | careful = false; |
1180 | |
1240 | |
1181 | if (!XftCharExists (DISPLAY, f, unicode)) |
1241 | if (!XftCharExists (term->display->display, f, unicode)) |
1182 | return false; |
1242 | return false; |
1183 | |
1243 | |
1184 | if (!prop || prop->width == rxvt_fontprop::unset) |
1244 | if (!prop || prop->width == rxvt_fontprop::unset) |
1185 | return true; |
1245 | return true; |
1186 | |
1246 | |
1187 | // check character against base font bounding box |
1247 | // check character against base font bounding box |
1188 | FcChar32 ch = unicode; |
1248 | FcChar32 ch = unicode; |
1189 | XGlyphInfo g; |
1249 | XGlyphInfo g; |
1190 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1250 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1191 | |
1251 | |
1192 | int w = g.width; |
1252 | int w = g.width - g.x; |
1193 | int wcw = wcwidth (unicode); |
1253 | int wcw = wcwidth (unicode); |
1194 | if (wcw > 0) w /= wcw; |
1254 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1195 | |
1255 | |
1196 | careful = w > prop->width; |
1256 | careful = w > prop->width; |
1197 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1257 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1198 | return false; |
1258 | return false; |
1199 | |
1259 | |
… | |
… | |
1203 | void |
1263 | void |
1204 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1264 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1205 | const text_t *text, int len, |
1265 | const text_t *text, int len, |
1206 | int fg, int bg) |
1266 | int fg, int bg) |
1207 | { |
1267 | { |
1208 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1268 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1209 | |
|
|
1210 | int base = ascent; // should be fbase, but that is incorrect |
|
|
1211 | |
1269 | |
1212 | XGlyphInfo extents; |
1270 | XGlyphInfo extents; |
1213 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1271 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1214 | FcChar32 *ep = enc; |
1272 | XftGlyphSpec *ep = enc; |
1215 | int ewidth = 0; |
1273 | |
1216 | int xoff = 0; |
1274 | dTermDisplay; |
|
|
1275 | dTermGC; |
|
|
1276 | |
|
|
1277 | // cut trailing spaces |
|
|
1278 | while (len && text [len - 1] == ' ') |
|
|
1279 | len--; |
1217 | |
1280 | |
1218 | while (len) |
1281 | while (len) |
1219 | { |
1282 | { |
1220 | int cwidth = r->TermWin.fwidth; |
1283 | int cwidth = term->fwidth; |
1221 | FcChar32 fc = *text++; len--; |
1284 | FcChar32 fc = *text++; len--; |
1222 | FT_UInt gl; |
|
|
1223 | |
1285 | |
1224 | while (len && *text == NOCHAR) |
1286 | while (len && *text == NOCHAR) |
1225 | text++, len--, cwidth += r->TermWin.fwidth; |
1287 | text++, len--, cwidth += term->fwidth; |
1226 | |
1288 | |
1227 | gl = XftCharIndex (d.display->display, f, fc); |
1289 | if (fc != ' ') // skip spaces |
1228 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1229 | |
|
|
1230 | if (extents.xOff != cwidth && ep != enc) |
|
|
1231 | { |
|
|
1232 | if (xoff > ewidth) xoff = ewidth; |
|
|
1233 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1234 | x + (ewidth - xoff >> 1), |
|
|
1235 | y + base, enc, ep - enc); |
|
|
1236 | x += ewidth; |
|
|
1237 | |
|
|
1238 | ep = enc; |
|
|
1239 | ewidth = 0; |
|
|
1240 | xoff = 0; |
|
|
1241 | } |
1290 | { |
|
|
1291 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1292 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1242 | |
1293 | |
1243 | if (fc == ' ' && ep == enc) // skip leading spaces |
1294 | ep->glyph = glyph; |
|
|
1295 | ep->x = x + (cwidth - extents.xOff >> 1); |
|
|
1296 | ep->y = y + ascent; |
|
|
1297 | ep++; |
1244 | { |
1298 | } |
|
|
1299 | |
1245 | x += cwidth; |
1300 | x += cwidth; |
1246 | continue; |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | else |
|
|
1250 | { |
|
|
1251 | *ep++ = gl; |
|
|
1252 | ewidth += cwidth; |
|
|
1253 | xoff += extents.xOff; |
|
|
1254 | } |
|
|
1255 | } |
1301 | } |
1256 | |
1302 | |
1257 | if (ep != enc) |
1303 | if (ep != enc) |
1258 | { |
|
|
1259 | if (xoff > ewidth) xoff = ewidth; |
|
|
1260 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1304 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1261 | x + (ewidth - xoff >> 1), |
|
|
1262 | y + base, enc, ep - enc); |
|
|
1263 | } |
|
|
1264 | } |
1305 | } |
1265 | #endif |
1306 | #endif |
1266 | |
1307 | |
1267 | ///////////////////////////////////////////////////////////////////////////// |
1308 | ///////////////////////////////////////////////////////////////////////////// |
1268 | |
1309 | |
1269 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1310 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1270 | : r (r), fontdesc (0) |
1311 | : fontdesc (0), term (term) |
1271 | { |
1312 | { |
1272 | clear (); |
1313 | clear (); |
1273 | } |
1314 | } |
1274 | |
1315 | |
1275 | rxvt_fontset::~rxvt_fontset () |
1316 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1278 | } |
1319 | } |
1279 | |
1320 | |
1280 | void |
1321 | void |
1281 | rxvt_fontset::clear () |
1322 | rxvt_fontset::clear () |
1282 | { |
1323 | { |
1283 | prop.width = prop.height = prop.weight = prop.slant |
1324 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1284 | = rxvt_fontprop::unset; |
1325 | = rxvt_fontprop::unset; |
1285 | |
1326 | |
1286 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1327 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1287 | FONT_UNREF (*i); |
1328 | FONT_UNREF (*i); |
1288 | |
1329 | |
… | |
… | |
1319 | f = new rxvt_font_x11; |
1360 | f = new rxvt_font_x11; |
1320 | } |
1361 | } |
1321 | else |
1362 | else |
1322 | f = new rxvt_font_x11; |
1363 | f = new rxvt_font_x11; |
1323 | |
1364 | |
1324 | f->set_term (r); |
1365 | f->set_term (term); |
1325 | f->set_name (strdup (name)); |
1366 | f->set_name (strdup (name)); |
1326 | |
1367 | |
1327 | f->cs = cs; |
1368 | f->cs = cs; |
1328 | f->loaded = false; |
1369 | f->loaded = false; |
1329 | |
1370 | |
… | |
… | |
1340 | char buf[512]; |
1381 | char buf[512]; |
1341 | const char *end; |
1382 | const char *end; |
1342 | |
1383 | |
1343 | do |
1384 | do |
1344 | { |
1385 | { |
1345 | while (*desc <= ' ') desc++; |
1386 | while (*desc && *desc <= ' ') |
|
|
1387 | desc++; |
1346 | |
1388 | |
1347 | codeset cs = CS_UNICODE; |
1389 | codeset cs = CS_UNICODE; |
1348 | |
1390 | |
1349 | if (*desc == '[') |
1391 | if (*desc == '[') |
1350 | { |
1392 | { |
… | |
… | |
1460 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1502 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1461 | goto next_font; |
1503 | goto next_font; |
1462 | |
1504 | |
1463 | if (!realize_font (i)) |
1505 | if (!realize_font (i)) |
1464 | goto next_font; |
1506 | goto next_font; |
|
|
1507 | |
|
|
1508 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1509 | max_it (f->ascent, prop.ascent); |
1465 | } |
1510 | } |
1466 | |
1511 | |
1467 | if (f->cs == CS_UNKNOWN) |
1512 | if (f->cs == CS_UNKNOWN) |
1468 | goto next_font; |
1513 | goto next_font; |
1469 | |
1514 | |
… | |
… | |
1508 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1553 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1509 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1554 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1510 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1555 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1511 | |
1556 | |
1512 | XftResult result; |
1557 | XftResult result; |
1513 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1558 | FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result); |
1514 | |
1559 | |
1515 | FcPatternDestroy (p); |
1560 | FcPatternDestroy (p); |
1516 | |
1561 | |
1517 | if (match) |
1562 | if (match) |
1518 | { |
1563 | { |