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; |
… | |
… | |
130 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
128 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
129 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
130 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
134 | #if XFT |
132 | #if XFT |
135 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, |
133 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
136 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
134 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
137 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
135 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
138 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
136 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
139 | |
137 | |
140 | // FreeMono is usually uglier than x fonts, so try last only. |
138 | // FreeMono is usually uglier than x fonts, so try last only. |
141 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
139 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
142 | #endif |
140 | #endif |
143 | |
141 | |
… | |
… | |
152 | 0x304c, 0x672c, // が本 |
150 | 0x304c, 0x672c, // が本 |
153 | }; |
151 | }; |
154 | |
152 | |
155 | #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])) |
156 | |
154 | |
|
|
155 | #define dTermDisplay Display *disp = term->display->display |
|
|
156 | #define dTermGC GC gc = term->gc |
|
|
157 | |
157 | ///////////////////////////////////////////////////////////////////////////// |
158 | ///////////////////////////////////////////////////////////////////////////// |
158 | |
159 | |
159 | #if XFT |
160 | #if XFT |
160 | rxvt_drawable::~rxvt_drawable () |
161 | rxvt_drawable::~rxvt_drawable () |
161 | { |
162 | { |
… | |
… | |
172 | } |
173 | } |
173 | #endif |
174 | #endif |
174 | |
175 | |
175 | ///////////////////////////////////////////////////////////////////////////// |
176 | ///////////////////////////////////////////////////////////////////////////// |
176 | |
177 | |
177 | static void *enc_buf; |
|
|
178 | static uint32_t enc_len; |
|
|
179 | |
|
|
180 | static inline void * |
|
|
181 | get_enc_buf (uint32_t len) |
|
|
182 | { |
|
|
183 | if (len > enc_len) |
|
|
184 | { |
|
|
185 | free (enc_buf); |
|
|
186 | enc_buf = malloc (len); |
|
|
187 | enc_len = len; |
|
|
188 | } |
|
|
189 | |
|
|
190 | return enc_buf; |
|
|
191 | } |
|
|
192 | |
|
|
193 | static const char * |
178 | static const char * |
194 | 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) |
195 | { |
180 | { |
196 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
181 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
182 | uint8_t *res = buf; |
197 | |
183 | |
198 | while (len--) |
184 | while (len--) |
199 | { |
185 | { |
200 | uint32_t c = FROM_UNICODE (cs, *text++); |
186 | uint32_t c = FROM_UNICODE (cs, *text++); |
201 | |
187 | |
… | |
… | |
206 | } |
192 | } |
207 | |
193 | |
208 | *buf++ = c; |
194 | *buf++ = c; |
209 | } |
195 | } |
210 | |
196 | |
211 | return (const char *)enc_buf; |
197 | return (const char *)res; |
212 | } |
198 | } |
213 | |
199 | |
214 | static const XChar2b * |
200 | static const XChar2b * |
215 | 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) |
216 | { |
202 | { |
217 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
203 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
204 | XChar2b *res = buf; |
218 | |
205 | |
219 | while (len--) |
206 | while (len--) |
220 | { |
207 | { |
221 | uint32_t c = FROM_UNICODE (cs, *text++); |
208 | uint32_t c = FROM_UNICODE (cs, *text++); |
222 | |
209 | |
… | |
… | |
229 | buf->byte1 = c >> 8; |
216 | buf->byte1 = c >> 8; |
230 | buf->byte2 = c; |
217 | buf->byte2 = c; |
231 | buf++; |
218 | buf++; |
232 | } |
219 | } |
233 | |
220 | |
234 | return (XChar2b *)enc_buf; |
221 | return res; |
235 | } |
222 | } |
236 | |
223 | |
237 | ///////////////////////////////////////////////////////////////////////////// |
224 | ///////////////////////////////////////////////////////////////////////////// |
238 | |
225 | |
239 | void |
226 | void |
… | |
… | |
245 | if (this->name) free (this->name); // let the compiler optimize |
232 | if (this->name) free (this->name); // let the compiler optimize |
246 | this->name = name; |
233 | this->name = name; |
247 | } |
234 | } |
248 | |
235 | |
249 | void |
236 | void |
250 | 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 |
251 | { |
238 | { |
|
|
239 | dTermDisplay; |
|
|
240 | dTermGC; |
|
|
241 | |
252 | if (color == Color_bg) |
242 | if (color == Color_bg) |
253 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
243 | XClearArea (disp, d, x, y, w, h, FALSE); |
254 | else if (color >= 0) |
244 | else if (color >= 0) |
255 | { |
245 | { |
256 | #if XFT |
246 | #if XFT |
257 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
247 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
258 | #else |
248 | #else |
259 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
249 | XSetForeground (disp, gc, term->pix_colors[color]); |
260 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
250 | XFillRectangle (disp, d, gc, x, y, w, h); |
261 | #endif |
251 | #endif |
262 | } |
252 | } |
263 | } |
253 | } |
264 | |
254 | |
265 | #include "table/linedraw.h" |
255 | #include "table/linedraw.h" |
… | |
… | |
276 | rxvt_fontprop properties () |
266 | rxvt_fontprop properties () |
277 | { |
267 | { |
278 | rxvt_fontprop p; |
268 | rxvt_fontprop p; |
279 | |
269 | |
280 | p.width = p.height = 1; |
270 | p.width = p.height = 1; |
|
|
271 | p.ascent = rxvt_fontprop::unset; |
281 | p.weight = rxvt_fontprop::medium; |
272 | p.weight = rxvt_fontprop::medium; |
282 | p.slant = rxvt_fontprop::roman; |
273 | p.slant = rxvt_fontprop::roman; |
283 | |
274 | |
284 | return p; |
275 | return p; |
285 | } |
276 | } |
… | |
… | |
292 | set_name (strdup ("built-in support font")); |
283 | set_name (strdup ("built-in support font")); |
293 | |
284 | |
294 | return true; |
285 | return true; |
295 | } |
286 | } |
296 | |
287 | |
297 | 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 |
298 | { |
289 | { |
299 | careful = false; |
290 | careful = false; |
300 | |
291 | |
301 | if (unicode <= 0x001f) |
292 | if (unicode <= 0x001f) |
302 | return true; |
293 | return true; |
… | |
… | |
305 | return false; |
296 | return false; |
306 | |
297 | |
307 | if (unicode <= 0x009f) |
298 | if (unicode <= 0x009f) |
308 | return true; |
299 | return true; |
309 | |
300 | |
310 | if (unicode >= 0x2500 && unicode <= 0x259f) |
301 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
302 | !term->option (Opt_skipBuiltinGlyphs)) |
311 | return true; |
303 | return true; |
312 | |
304 | |
313 | if (IS_COMPOSE (unicode)) |
305 | if (IS_COMPOSE (unicode)) |
314 | return true; |
306 | return true; |
315 | |
307 | |
… | |
… | |
331 | void |
323 | void |
332 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
324 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
333 | const text_t *text, int len, |
325 | const text_t *text, int len, |
334 | int fg, int bg) |
326 | int fg, int bg) |
335 | { |
327 | { |
|
|
328 | dTermDisplay; |
|
|
329 | dTermGC; |
|
|
330 | |
336 | 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); |
337 | |
332 | |
338 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
333 | XSetForeground (disp, gc, term->pix_colors[fg]); |
339 | |
334 | |
340 | while (len) |
335 | while (len) |
341 | { |
336 | { |
342 | #if ENABLE_COMBINING |
337 | #if ENABLE_COMBINING |
343 | compose_char *cc; |
338 | compose_char *cc; |
… | |
… | |
347 | |
342 | |
348 | while (++text, --len && *text == NOCHAR) |
343 | while (++text, --len && *text == NOCHAR) |
349 | ; |
344 | ; |
350 | |
345 | |
351 | int width = text - tp; |
346 | int width = text - tp; |
352 | int fwidth = r->TermWin.fwidth * width; |
347 | int fwidth = term->fwidth * width; |
353 | |
348 | |
354 | if (0x2500 <= t && t <= 0x259f) |
349 | if (0x2500 <= t && t <= 0x259f) |
355 | { |
350 | { |
356 | uint16_t offs = linedraw_offs[t - 0x2500]; |
351 | uint16_t offs = linedraw_offs[t - 0x2500]; |
357 | uint32_t *a = linedraw_command + (offs >> 4); |
352 | uint32_t *a = linedraw_command + (offs >> 4); |
358 | uint32_t *b = a + (offs & 15); |
353 | uint32_t *b = a + (offs & 15); |
359 | |
354 | |
360 | int W = fwidth; |
355 | int W = fwidth; |
361 | int H = r->TermWin.fheight; |
356 | int H = term->fheight; |
362 | |
357 | |
363 | int x_[16]; |
358 | int x_[16]; |
364 | int y_[16]; |
359 | int y_[16]; |
365 | |
360 | |
366 | for (int i = 0; i <= 8; i++) |
361 | for (int i = 0; i <= 8; i++) |
… | |
… | |
374 | |
369 | |
375 | XGCValues gcv; |
370 | XGCValues gcv; |
376 | |
371 | |
377 | gcv.cap_style = CapButt; |
372 | gcv.cap_style = CapButt; |
378 | gcv.line_width = 0; |
373 | gcv.line_width = 0; |
379 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
374 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
380 | |
375 | |
381 | while (a < b) |
376 | while (a < b) |
382 | { |
377 | { |
383 | uint32_t command = *a++; |
378 | uint32_t command = *a++; |
384 | |
379 | |
… | |
… | |
391 | int y2 = y_[(command >> 0) & 15]; |
386 | int y2 = y_[(command >> 0) & 15]; |
392 | |
387 | |
393 | switch (op) |
388 | switch (op) |
394 | { |
389 | { |
395 | case 0: // line |
390 | case 0: // line |
396 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
391 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
397 | break; |
392 | break; |
398 | |
393 | |
399 | case 1: // rectangle, possibly stippled |
394 | case 1: // rectangle, possibly stippled |
400 | if (a) |
395 | if (a) |
401 | { |
396 | { |
402 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
397 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
403 | |
398 | |
404 | gcv.fill_style = FillStippled; |
399 | gcv.fill_style = FillStippled; |
405 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
400 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
406 | gcv.ts_x_origin = x; |
401 | gcv.ts_x_origin = x; |
407 | gcv.ts_y_origin = y; |
402 | gcv.ts_y_origin = y; |
408 | |
403 | |
409 | XChangeGC (d.display->display, TGC, |
404 | XChangeGC (disp, gc, |
410 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
405 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
411 | &gcv); |
406 | &gcv); |
412 | } |
407 | } |
413 | |
408 | |
414 | 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); |
415 | |
410 | |
416 | if (a) |
411 | if (a) |
417 | { |
412 | { |
418 | XFreePixmap (d.display->display, gcv.stipple); |
413 | XFreePixmap (disp, gcv.stipple); |
419 | gcv.stipple = 0; |
414 | gcv.stipple = 0; |
420 | gcv.fill_style = FillSolid; |
415 | gcv.fill_style = FillSolid; |
421 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
416 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
422 | } |
417 | } |
423 | break; |
418 | break; |
424 | case 2: // arc |
419 | case 2: // arc |
425 | XDrawArc (d.display->display, d, TGC, |
420 | XDrawArc (disp, d, gc, |
426 | x1 - W/2, y1 - H/2, W-1, H-1, |
421 | x1 - W/2, y1 - H/2, W-1, H-1, |
427 | (a - 1) * 90*64, (b - 1) * 90*64); |
422 | (a - 1) * 90*64, (b - 1) * 90*64); |
428 | break; |
423 | break; |
429 | } |
424 | } |
430 | } |
425 | } |
… | |
… | |
461 | case ZERO_WIDTH_CHAR: |
456 | case ZERO_WIDTH_CHAR: |
462 | case NOCHAR: |
457 | case NOCHAR: |
463 | break; |
458 | break; |
464 | |
459 | |
465 | default: |
460 | default: |
466 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
461 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
467 | fwidth - 4, r->TermWin.fheight - 4); |
462 | fwidth - 4, term->fheight - 4); |
468 | } |
463 | } |
469 | |
464 | |
470 | x += fwidth; |
465 | x += fwidth; |
471 | } |
466 | } |
472 | } |
467 | } |
… | |
… | |
480 | |
475 | |
481 | rxvt_fontprop properties (); |
476 | rxvt_fontprop properties (); |
482 | |
477 | |
483 | bool load (const rxvt_fontprop &prop); |
478 | bool load (const rxvt_fontprop &prop); |
484 | |
479 | |
485 | 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; |
486 | |
481 | |
487 | void draw (rxvt_drawable &d, int x, int y, |
482 | void draw (rxvt_drawable &d, int x, int y, |
488 | const text_t *text, int len, |
483 | const text_t *text, int len, |
489 | int fg, int bg); |
484 | int fg, int bg); |
490 | |
485 | |
… | |
… | |
502 | char * |
497 | char * |
503 | 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 |
504 | { |
499 | { |
505 | unsigned long value; |
500 | unsigned long value; |
506 | |
501 | |
507 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
502 | if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value)) |
508 | return XGetAtomName (DISPLAY, value); |
503 | return XGetAtomName (term->display->display, value); |
509 | else |
504 | else |
510 | return rxvt_strdup (repl); |
505 | return rxvt_strdup (repl); |
511 | } |
506 | } |
512 | |
507 | |
513 | rxvt_fontprop |
508 | rxvt_fontprop |
… | |
… | |
521 | bool |
516 | bool |
522 | 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) |
523 | { |
518 | { |
524 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
519 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
525 | p.height = height; |
520 | p.height = height; |
|
|
521 | p.ascent = rxvt_fontprop::unset; |
526 | 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; |
527 | 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; |
528 | |
524 | |
529 | return true; |
525 | return true; |
530 | } |
526 | } |
… | |
… | |
533 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
529 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
534 | { |
530 | { |
535 | unsigned long height; |
531 | unsigned long height; |
536 | |
532 | |
537 | #if 0 |
533 | #if 0 |
538 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
534 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height)) |
539 | return false; |
535 | return false; |
540 | #else |
536 | #else |
541 | height = f->ascent + f->descent; |
537 | height = f->ascent + f->descent; |
542 | #endif |
538 | #endif |
543 | |
539 | |
544 | unsigned long avgwidth; |
540 | unsigned long avgwidth; |
545 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
541 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth)) |
546 | avgwidth = 0; |
542 | avgwidth = 0; |
547 | |
543 | |
548 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
544 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
549 | char *slant = get_property (f, "SLANT", "r"); |
545 | char *slant = get_property (f, "SLANT", "r"); |
550 | |
546 | |
551 | set_properties (p, height, weight, slant, avgwidth); |
547 | set_properties (p, height, weight, slant, avgwidth); |
552 | |
548 | |
553 | free (weight); |
549 | free (weight); |
554 | free (slant); |
550 | free (slant); |
555 | |
551 | |
|
|
552 | p.ascent = f->ascent; |
|
|
553 | |
556 | return true; |
554 | return true; |
557 | } |
555 | } |
558 | |
556 | |
559 | bool |
557 | bool |
560 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
558 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
561 | { |
559 | { |
|
|
560 | dTermDisplay; |
562 | int slashes = 0; |
561 | int slashes = 0; |
563 | const char *comp[13]; |
562 | const char *comp[13]; |
564 | |
563 | |
565 | for (const char *c = name; *c; c++) |
564 | for (const char *c = name; *c; c++) |
566 | if (*c == '-') |
565 | if (*c == '-') |
… | |
… | |
574 | if (slashes >= 13 |
573 | if (slashes >= 13 |
575 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
574 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
576 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
575 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
577 | 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])); |
578 | |
577 | |
579 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
578 | XFontStruct *f = XLoadQueryFont (disp, name); |
580 | |
579 | |
581 | if (f) |
580 | if (f) |
582 | { |
581 | { |
583 | // 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 |
584 | // (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). |
585 | // in that case, just return garbage. |
584 | // in that case, just return garbage. |
586 | bool ret = set_properties (p, f); |
585 | bool ret = set_properties (p, f); |
587 | XFreeFont (DISPLAY, f); |
586 | XFreeFont (disp, f); |
588 | return ret; |
587 | return ret; |
589 | } |
588 | } |
590 | else |
589 | else |
591 | return false; |
590 | return false; |
592 | } |
591 | } |
… | |
… | |
630 | } |
629 | } |
631 | |
630 | |
632 | bool |
631 | bool |
633 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
632 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
634 | { |
633 | { |
|
|
634 | dTermDisplay; |
|
|
635 | |
635 | clear (); |
636 | clear (); |
636 | |
637 | |
637 | char field_str[64]; // enough for 128 bits |
638 | char field_str[64]; // enough for 128 bits |
638 | |
639 | |
639 | // first morph the font if required |
640 | // first morph the font if required |
… | |
… | |
642 | { |
643 | { |
643 | char fname[1024]; |
644 | char fname[1024]; |
644 | |
645 | |
645 | if (name[0] != '-') |
646 | if (name[0] != '-') |
646 | { |
647 | { |
647 | f = XLoadQueryFont (DISPLAY, name); |
648 | f = XLoadQueryFont (disp, name); |
648 | |
649 | |
649 | if (!f) |
650 | if (!f) |
650 | return false; |
651 | return false; |
651 | |
652 | |
652 | char *new_name = get_property (f, "FONT", name); |
653 | char *new_name = get_property (f, "FONT", name); |
… | |
… | |
654 | if (new_name) |
655 | if (new_name) |
655 | set_name (new_name); |
656 | set_name (new_name); |
656 | else |
657 | else |
657 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
658 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
658 | |
659 | |
659 | XFreeFont (DISPLAY, f); |
660 | XFreeFont (disp, f); |
660 | f = 0; |
661 | f = 0; |
661 | } |
662 | } |
662 | |
663 | |
663 | if (prop.weight != rxvt_fontprop::unset) |
664 | if (prop.weight != rxvt_fontprop::unset) |
664 | { |
665 | { |
… | |
… | |
694 | ~font_weight () { free (name); } |
695 | ~font_weight () { free (name); } |
695 | }; |
696 | }; |
696 | |
697 | |
697 | char **list; |
698 | char **list; |
698 | int count; |
699 | int count; |
699 | list = XListFonts (DISPLAY, name, 4000, &count); |
700 | list = XListFonts (disp, name, 4000, &count); |
700 | |
701 | |
701 | set_name (0); |
702 | set_name (0); |
702 | |
703 | |
703 | if (!list) |
704 | if (!list) |
704 | return false; |
705 | return false; |
… | |
… | |
712 | |
713 | |
713 | int diff = 0; |
714 | int diff = 0; |
714 | |
715 | |
715 | if (replace_field (fname, list[i], 6, '0', field_str)) |
716 | if (replace_field (fname, list[i], 6, '0', field_str)) |
716 | 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 |
717 | |
720 | |
718 | if (!set_properties (p, fname)) |
721 | if (!set_properties (p, fname)) |
719 | continue; |
722 | continue; |
720 | |
723 | |
721 | if (prop.height != rxvt_fontprop::unset |
724 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
737 | for (;;) |
740 | for (;;) |
738 | { |
741 | { |
739 | font_weight *best = fonts + count - 1; |
742 | font_weight *best = fonts + count - 1; |
740 | |
743 | |
741 | for (font_weight *w = best; w-- > fonts; ) |
744 | for (font_weight *w = best; w-- > fonts; ) |
742 | if (w->diff < best->diff) |
745 | if (w->diff <= best->diff) |
743 | best = w; |
746 | best = w; |
744 | |
747 | |
745 | if (!best->name |
748 | if (!best->name |
746 | || !(f = XLoadQueryFont (DISPLAY, best->name))) |
749 | || !(f = XLoadQueryFont (disp, best->name))) |
747 | break; |
750 | break; |
748 | |
751 | |
749 | set_name (best->name); |
752 | set_name (best->name); |
750 | best->clear (); |
753 | best->clear (); |
751 | |
754 | |
… | |
… | |
845 | |
848 | |
846 | XCharStruct g; |
849 | XCharStruct g; |
847 | int dir_ret, asc_ret, des_ret; |
850 | int dir_ret, asc_ret, des_ret; |
848 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
851 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
849 | |
852 | |
850 | 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; |
851 | |
854 | |
852 | if (width < g.width) width = g.width; |
855 | if (width < g.width) width = g.width; |
853 | } |
856 | } |
854 | |
857 | |
855 | if (cs == CS_UNKNOWN) |
858 | if (cs == CS_UNKNOWN) |
… | |
… | |
874 | void |
877 | void |
875 | rxvt_font_x11::clear () |
878 | rxvt_font_x11::clear () |
876 | { |
879 | { |
877 | if (f) |
880 | if (f) |
878 | { |
881 | { |
879 | XFreeFont (DISPLAY, f); |
882 | XFreeFont (term->display->display, f); |
880 | f = 0; |
883 | f = 0; |
881 | } |
884 | } |
882 | } |
885 | } |
883 | |
886 | |
884 | bool |
887 | bool |
885 | 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 |
886 | { |
889 | { |
887 | uint32_t ch = FROM_UNICODE (cs, unicode); |
890 | uint32_t ch = FROM_UNICODE (cs, unicode); |
888 | |
891 | |
889 | if (ch == NOCHAR) |
892 | if (ch == NOCHAR) |
890 | return false; |
893 | return false; |
… | |
… | |
930 | return true; |
933 | return true; |
931 | |
934 | |
932 | // check character against base font bounding box |
935 | // check character against base font bounding box |
933 | int w = xcs->width; |
936 | int w = xcs->width; |
934 | int wcw = wcwidth (unicode); |
937 | int wcw = wcwidth (unicode); |
935 | if (wcw > 0) w /= wcw; |
938 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
936 | |
939 | |
937 | careful = w > prop->width; |
940 | careful = w > prop->width; |
938 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
941 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
939 | return false; |
942 | return false; |
940 | |
943 | |
… | |
… | |
949 | // this looks like a mess /. |
952 | // this looks like a mess /. |
950 | // and it is a mess /. |
953 | // and it is a mess /. |
951 | // yet we are trying to be perfect /. |
954 | // yet we are trying to be perfect /. |
952 | // but the result still isn't perfect /. |
955 | // but the result still isn't perfect /. |
953 | |
956 | |
|
|
957 | dTermDisplay; |
|
|
958 | dTermGC; |
|
|
959 | |
954 | bool slow = this->slow |
960 | bool slow = this->slow |
955 | || width != r->TermWin.fwidth |
961 | || width != term->fwidth |
956 | || height != r->TermWin.fheight; |
962 | || height != term->fheight; |
957 | |
963 | |
958 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
964 | int base = ascent; // sorry, incorrect: term->fbase; |
959 | |
965 | |
960 | XGCValues v; |
966 | XGCValues v; |
961 | v.foreground = r->pix_colors[fg]; |
967 | v.foreground = term->pix_colors[fg]; |
962 | v.font = f->fid; |
968 | v.font = f->fid; |
963 | |
969 | |
964 | if (enc2b) |
970 | if (enc2b) |
965 | { |
971 | { |
966 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
972 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
967 | |
973 | |
968 | if (bg == Color_bg && !slow) |
974 | if (bg == Color_bg && !slow) |
969 | { |
975 | { |
970 | v.background = r->pix_colors[bg]; |
976 | v.background = term->pix_colors[bg]; |
971 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
977 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
972 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
978 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
973 | } |
979 | } |
974 | else |
980 | else |
975 | { |
981 | { |
976 | 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); |
977 | |
983 | |
978 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
984 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
979 | |
985 | |
980 | if (slow) |
986 | if (slow) |
981 | { |
987 | { |
982 | do |
988 | do |
983 | { |
989 | { |
984 | if (xc->byte1 || xc->byte2) |
990 | if (xc->byte1 || xc->byte2) |
985 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
991 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
986 | |
992 | |
987 | x += r->TermWin.fwidth; |
993 | x += term->fwidth; |
988 | xc++; len--; |
994 | xc++; len--; |
989 | } |
995 | } |
990 | while (len); |
996 | while (len); |
991 | } |
997 | } |
992 | else |
998 | else |
993 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
999 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
994 | } |
1000 | } |
995 | } |
1001 | } |
996 | else |
1002 | else |
997 | { |
1003 | { |
998 | const char *xc = enc_char (text, len, cs, slow); |
1004 | const char *xc = enc_char (text, len, cs, slow); |
999 | |
1005 | |
1000 | if (bg == Color_bg && !slow) |
1006 | if (bg == Color_bg && !slow) |
1001 | { |
1007 | { |
1002 | v.background = r->pix_colors[bg]; |
1008 | v.background = term->pix_colors[bg]; |
1003 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1009 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
1004 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1010 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
1005 | } |
1011 | } |
1006 | else |
1012 | else |
1007 | { |
1013 | { |
1008 | 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); |
1009 | |
1015 | |
1010 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1016 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1011 | |
1017 | |
1012 | if (slow) |
1018 | if (slow) |
1013 | { |
1019 | { |
1014 | do |
1020 | do |
1015 | { |
1021 | { |
1016 | if (*xc) |
1022 | if (*xc) |
1017 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1023 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
1018 | |
1024 | |
1019 | x += r->TermWin.fwidth; |
1025 | x += term->fwidth; |
1020 | xc++; len--; |
1026 | xc++; len--; |
1021 | } |
1027 | } |
1022 | while (len); |
1028 | while (len); |
1023 | } |
1029 | } |
1024 | else |
1030 | else |
1025 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1031 | XDrawString (disp, d, gc, x, y + base, xc, len); |
1026 | } |
1032 | } |
1027 | } |
1033 | } |
1028 | } |
1034 | } |
1029 | |
1035 | |
1030 | ///////////////////////////////////////////////////////////////////////////// |
1036 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
1042 | |
1048 | |
1043 | void draw (rxvt_drawable &d, int x, int y, |
1049 | void draw (rxvt_drawable &d, int x, int y, |
1044 | const text_t *text, int len, |
1050 | const text_t *text, int len, |
1045 | int fg, int bg); |
1051 | int fg, int bg); |
1046 | |
1052 | |
1047 | 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; |
1048 | |
1054 | |
1049 | protected: |
1055 | protected: |
1050 | XftFont *f; |
1056 | XftFont *f; |
1051 | }; |
1057 | }; |
1052 | |
1058 | |
1053 | void |
1059 | void |
1054 | rxvt_font_xft::clear () |
1060 | rxvt_font_xft::clear () |
1055 | { |
1061 | { |
1056 | if (f) |
1062 | if (f) |
1057 | { |
1063 | { |
1058 | XftFontClose (DISPLAY, f); |
1064 | XftFontClose (term->display->display, f); |
1059 | f = 0; |
1065 | f = 0; |
1060 | } |
1066 | } |
1061 | } |
1067 | } |
1062 | |
1068 | |
1063 | rxvt_fontprop |
1069 | rxvt_fontprop |
… | |
… | |
1067 | |
1073 | |
1068 | FT_Face face = XftLockFace (f); |
1074 | FT_Face face = XftLockFace (f); |
1069 | |
1075 | |
1070 | p.width = width; |
1076 | p.width = width; |
1071 | p.height = height; |
1077 | p.height = height; |
|
|
1078 | p.ascent = ascent; |
1072 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1079 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1073 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1080 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1074 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1081 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1075 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1082 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1076 | |
1083 | |
… | |
… | |
1080 | } |
1087 | } |
1081 | |
1088 | |
1082 | bool |
1089 | bool |
1083 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1090 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1084 | { |
1091 | { |
|
|
1092 | dTermDisplay; |
|
|
1093 | |
1085 | clear (); |
1094 | clear (); |
1086 | |
1095 | |
1087 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1096 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1088 | |
1097 | |
1089 | if (!p) |
1098 | if (!p) |
1090 | return false; |
1099 | return false; |
1091 | |
1100 | |
1092 | FcValue v; |
1101 | FcValue v; |
1093 | |
1102 | |
1094 | if (prop.height != rxvt_fontprop::unset |
1103 | if (prop.height != rxvt_fontprop::unset |
1095 | || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1104 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1096 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1105 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1097 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1106 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1098 | |
1107 | |
1099 | if (prop.weight != rxvt_fontprop::unset |
1108 | if (prop.weight != rxvt_fontprop::unset |
1100 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1109 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
… | |
… | |
1115 | |
1124 | |
1116 | // store generated name so iso14755 view gives better results |
1125 | // store generated name so iso14755 view gives better results |
1117 | set_name ((char *)FcNameUnparse (p)); |
1126 | set_name ((char *)FcNameUnparse (p)); |
1118 | |
1127 | |
1119 | XftResult result; |
1128 | XftResult result; |
1120 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1129 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
1121 | |
1130 | |
1122 | FcPatternDestroy (p); |
1131 | FcPatternDestroy (p); |
1123 | |
1132 | |
1124 | if (!match) |
1133 | if (!match) |
1125 | return false; |
1134 | return false; |
… | |
… | |
1127 | int ftheight = 0; |
1136 | int ftheight = 0; |
1128 | bool success = true; |
1137 | bool success = true; |
1129 | |
1138 | |
1130 | for (;;) |
1139 | for (;;) |
1131 | { |
1140 | { |
1132 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1141 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1133 | |
1142 | |
1134 | if (!f) |
1143 | if (!f) |
1135 | { |
1144 | { |
1136 | success = false; |
1145 | success = false; |
1137 | break; |
1146 | break; |
… | |
… | |
1146 | |
1155 | |
1147 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1156 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1148 | |
1157 | |
1149 | XftUnlockFace (f); |
1158 | XftUnlockFace (f); |
1150 | |
1159 | |
|
|
1160 | int glheight = height; |
|
|
1161 | |
1151 | 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; ) |
1152 | { |
1163 | { |
1153 | FcChar16 ch = *t; |
1164 | FcChar16 ch = *t; |
1154 | |
1165 | |
1155 | if (cs != CS_UNICODE |
1166 | if (cs != CS_UNICODE |
… | |
… | |
1161 | bool careful; |
1172 | bool careful; |
1162 | if (!has_char (*t, &prop, careful)) |
1173 | if (!has_char (*t, &prop, careful)) |
1163 | continue; |
1174 | continue; |
1164 | |
1175 | |
1165 | XGlyphInfo g; |
1176 | XGlyphInfo g; |
1166 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1177 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1178 | |
|
|
1179 | g.width -= g.x; |
1167 | |
1180 | |
1168 | int wcw = wcwidth (ch); |
1181 | int wcw = wcwidth (ch); |
1169 | if (wcw > 0) g.width = g.width / wcw; |
1182 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1170 | |
1183 | |
1171 | if (width < g.width) width = g.width; |
1184 | if (width < g.width ) width = g.width; |
1172 | 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; |
1173 | } |
1198 | } |
1174 | |
1199 | |
1175 | if (prop.height == rxvt_fontprop::unset |
1200 | if (prop.height == rxvt_fontprop::unset |
1176 | || height <= prop.height |
1201 | || (height <= prop.height && glheight <= prop.height) |
1177 | || height <= 2 |
1202 | || height <= 2 |
1178 | || !scalable) |
1203 | || !scalable) |
1179 | break; |
1204 | break; |
1180 | |
1205 | |
1181 | if (ftheight) |
1206 | if (ftheight) |
… | |
… | |
1188 | ftheight -= height - prop.height; |
1213 | ftheight -= height - prop.height; |
1189 | } |
1214 | } |
1190 | else |
1215 | else |
1191 | ftheight = prop.height - 1; |
1216 | ftheight = prop.height - 1; |
1192 | |
1217 | |
1193 | XftFontClose (DISPLAY, f); |
1218 | XftFontClose (disp, f); |
1194 | FcPatternDel (match, FC_PIXEL_SIZE); |
1219 | FcPatternDel (match, FC_PIXEL_SIZE); |
1195 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1220 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1196 | } |
1221 | } |
1197 | |
1222 | |
1198 | FcPatternDestroy (match); |
1223 | FcPatternDestroy (match); |
1199 | |
1224 | |
1200 | #if 0 // do it per-character |
1225 | #if 0 // do it per-character |
… | |
… | |
1207 | |
1232 | |
1208 | return success; |
1233 | return success; |
1209 | } |
1234 | } |
1210 | |
1235 | |
1211 | bool |
1236 | bool |
1212 | 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 |
1213 | { |
1238 | { |
1214 | careful = false; |
1239 | careful = false; |
1215 | |
1240 | |
1216 | if (!XftCharExists (DISPLAY, f, unicode)) |
1241 | if (!XftCharExists (term->display->display, f, unicode)) |
1217 | return false; |
1242 | return false; |
1218 | |
1243 | |
1219 | if (!prop || prop->width == rxvt_fontprop::unset) |
1244 | if (!prop || prop->width == rxvt_fontprop::unset) |
1220 | return true; |
1245 | return true; |
1221 | |
1246 | |
1222 | // check character against base font bounding box |
1247 | // check character against base font bounding box |
1223 | FcChar32 ch = unicode; |
1248 | FcChar32 ch = unicode; |
1224 | XGlyphInfo g; |
1249 | XGlyphInfo g; |
1225 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1250 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1226 | |
1251 | |
1227 | int w = g.width; |
1252 | int w = g.width - g.x; |
1228 | int wcw = wcwidth (unicode); |
1253 | int wcw = wcwidth (unicode); |
1229 | if (wcw > 0) w /= wcw; |
1254 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1230 | |
1255 | |
1231 | careful = w > prop->width; |
1256 | careful = w > prop->width; |
1232 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1257 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1233 | return false; |
1258 | return false; |
1234 | |
1259 | |
… | |
… | |
1238 | void |
1263 | void |
1239 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1264 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1240 | const text_t *text, int len, |
1265 | const text_t *text, int len, |
1241 | int fg, int bg) |
1266 | int fg, int bg) |
1242 | { |
1267 | { |
1243 | 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); |
1244 | |
|
|
1245 | int base = ascent; // should be fbase, but that is incorrect |
|
|
1246 | |
1269 | |
1247 | XGlyphInfo extents; |
1270 | XGlyphInfo extents; |
1248 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1271 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1249 | FcChar32 *ep = enc; |
1272 | XftGlyphSpec *ep = enc; |
1250 | int ewidth = 0; |
1273 | |
1251 | int xoff = 0; |
1274 | dTermDisplay; |
|
|
1275 | dTermGC; |
|
|
1276 | |
|
|
1277 | // cut trailing spaces |
|
|
1278 | while (len && text [len - 1] == ' ') |
|
|
1279 | len--; |
1252 | |
1280 | |
1253 | while (len) |
1281 | while (len) |
1254 | { |
1282 | { |
1255 | int cwidth = r->TermWin.fwidth; |
1283 | int cwidth = term->fwidth; |
1256 | FcChar32 fc = *text++; len--; |
1284 | FcChar32 fc = *text++; len--; |
1257 | FT_UInt gl; |
|
|
1258 | |
1285 | |
1259 | while (len && *text == NOCHAR) |
1286 | while (len && *text == NOCHAR) |
1260 | text++, len--, cwidth += r->TermWin.fwidth; |
1287 | text++, len--, cwidth += term->fwidth; |
1261 | |
1288 | |
1262 | gl = XftCharIndex (d.display->display, f, fc); |
1289 | if (fc != ' ') // skip spaces |
1263 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1264 | |
|
|
1265 | if (extents.xOff != cwidth && ep != enc) |
|
|
1266 | { |
|
|
1267 | if (xoff > ewidth) xoff = ewidth; |
|
|
1268 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1269 | x + (ewidth - xoff >> 1), |
|
|
1270 | y + base, enc, ep - enc); |
|
|
1271 | x += ewidth; |
|
|
1272 | |
|
|
1273 | ep = enc; |
|
|
1274 | ewidth = 0; |
|
|
1275 | xoff = 0; |
|
|
1276 | } |
1290 | { |
|
|
1291 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1292 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1277 | |
1293 | |
1278 | 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++; |
1279 | { |
1298 | } |
|
|
1299 | |
1280 | x += cwidth; |
1300 | x += cwidth; |
1281 | continue; |
|
|
1282 | } |
|
|
1283 | |
|
|
1284 | else |
|
|
1285 | { |
|
|
1286 | *ep++ = gl; |
|
|
1287 | ewidth += cwidth; |
|
|
1288 | xoff += extents.xOff; |
|
|
1289 | } |
|
|
1290 | } |
1301 | } |
1291 | |
1302 | |
1292 | if (ep != enc) |
1303 | if (ep != enc) |
1293 | { |
|
|
1294 | if (xoff > ewidth) xoff = ewidth; |
|
|
1295 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1304 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1296 | x + (ewidth - xoff >> 1), |
|
|
1297 | y + base, enc, ep - enc); |
|
|
1298 | } |
|
|
1299 | } |
1305 | } |
1300 | #endif |
1306 | #endif |
1301 | |
1307 | |
1302 | ///////////////////////////////////////////////////////////////////////////// |
1308 | ///////////////////////////////////////////////////////////////////////////// |
1303 | |
1309 | |
1304 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1310 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1305 | : r (r), fontdesc (0) |
1311 | : fontdesc (0), term (term) |
1306 | { |
1312 | { |
1307 | clear (); |
1313 | clear (); |
1308 | } |
1314 | } |
1309 | |
1315 | |
1310 | rxvt_fontset::~rxvt_fontset () |
1316 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1313 | } |
1319 | } |
1314 | |
1320 | |
1315 | void |
1321 | void |
1316 | rxvt_fontset::clear () |
1322 | rxvt_fontset::clear () |
1317 | { |
1323 | { |
1318 | prop.width = prop.height = prop.weight = prop.slant |
1324 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1319 | = rxvt_fontprop::unset; |
1325 | = rxvt_fontprop::unset; |
1320 | |
1326 | |
1321 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1327 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1322 | FONT_UNREF (*i); |
1328 | FONT_UNREF (*i); |
1323 | |
1329 | |
… | |
… | |
1354 | f = new rxvt_font_x11; |
1360 | f = new rxvt_font_x11; |
1355 | } |
1361 | } |
1356 | else |
1362 | else |
1357 | f = new rxvt_font_x11; |
1363 | f = new rxvt_font_x11; |
1358 | |
1364 | |
1359 | f->set_term (r); |
1365 | f->set_term (term); |
1360 | f->set_name (strdup (name)); |
1366 | f->set_name (strdup (name)); |
1361 | |
1367 | |
1362 | f->cs = cs; |
1368 | f->cs = cs; |
1363 | f->loaded = false; |
1369 | f->loaded = false; |
1364 | |
1370 | |
… | |
… | |
1375 | char buf[512]; |
1381 | char buf[512]; |
1376 | const char *end; |
1382 | const char *end; |
1377 | |
1383 | |
1378 | do |
1384 | do |
1379 | { |
1385 | { |
1380 | while (*desc <= ' ') desc++; |
1386 | while (*desc && *desc <= ' ') |
|
|
1387 | desc++; |
1381 | |
1388 | |
1382 | codeset cs = CS_UNICODE; |
1389 | codeset cs = CS_UNICODE; |
1383 | |
1390 | |
1384 | if (*desc == '[') |
1391 | if (*desc == '[') |
1385 | { |
1392 | { |
… | |
… | |
1495 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1502 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1496 | goto next_font; |
1503 | goto next_font; |
1497 | |
1504 | |
1498 | if (!realize_font (i)) |
1505 | if (!realize_font (i)) |
1499 | goto next_font; |
1506 | goto next_font; |
|
|
1507 | |
|
|
1508 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1509 | max_it (f->ascent, prop.ascent); |
1500 | } |
1510 | } |
1501 | |
1511 | |
1502 | if (f->cs == CS_UNKNOWN) |
1512 | if (f->cs == CS_UNKNOWN) |
1503 | goto next_font; |
1513 | goto next_font; |
1504 | |
1514 | |
… | |
… | |
1543 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1553 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1544 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1554 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1545 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1555 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1546 | |
1556 | |
1547 | XftResult result; |
1557 | XftResult result; |
1548 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1558 | FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result); |
1549 | |
1559 | |
1550 | FcPatternDestroy (p); |
1560 | FcPatternDestroy (p); |
1551 | |
1561 | |
1552 | if (match) |
1562 | if (match) |
1553 | { |
1563 | { |