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 | |
31 | #define DISPLAY r->display->display |
32 | #define DISPLAY r->display->display |
32 | #define TGC r->TermWin.gc |
33 | #define TGC r->gc |
33 | |
34 | |
34 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | |
36 | |
36 | const struct rxvt_fallback_font { |
37 | const struct rxvt_fallback_font { |
37 | codeset cs; |
38 | codeset cs; |
… | |
… | |
130 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
134 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
134 | #if XFT |
135 | #if XFT |
135 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, |
136 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
136 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
137 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
137 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
138 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
138 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
139 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
139 | |
140 | |
140 | // FreeMono is usually uglier than x fonts, so try last only. |
141 | // FreeMono is usually uglier than x fonts, so try last only. |
141 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
142 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
142 | #endif |
143 | #endif |
143 | |
144 | |
… | |
… | |
276 | rxvt_fontprop properties () |
277 | rxvt_fontprop properties () |
277 | { |
278 | { |
278 | rxvt_fontprop p; |
279 | rxvt_fontprop p; |
279 | |
280 | |
280 | p.width = p.height = 1; |
281 | p.width = p.height = 1; |
|
|
282 | p.ascent = rxvt_fontprop::unset; |
281 | p.weight = rxvt_fontprop::medium; |
283 | p.weight = rxvt_fontprop::medium; |
282 | p.slant = rxvt_fontprop::roman; |
284 | p.slant = rxvt_fontprop::roman; |
283 | |
285 | |
284 | return p; |
286 | return p; |
285 | } |
287 | } |
… | |
… | |
305 | return false; |
307 | return false; |
306 | |
308 | |
307 | if (unicode <= 0x009f) |
309 | if (unicode <= 0x009f) |
308 | return true; |
310 | return true; |
309 | |
311 | |
310 | if (unicode >= 0x2500 && unicode <= 0x259f) |
312 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
313 | !r->option (Opt_skipBuiltinGlyphs)) |
311 | return true; |
314 | return true; |
312 | |
315 | |
313 | if (IS_COMPOSE (unicode)) |
316 | if (IS_COMPOSE (unicode)) |
314 | return true; |
317 | return true; |
315 | |
318 | |
… | |
… | |
331 | void |
334 | void |
332 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
335 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
333 | const text_t *text, int len, |
336 | const text_t *text, int len, |
334 | int fg, int bg) |
337 | int fg, int bg) |
335 | { |
338 | { |
|
|
339 | Display *disp = d.display->display; |
|
|
340 | |
336 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
341 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
337 | |
342 | |
338 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
343 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
339 | |
344 | |
340 | while (len) |
345 | while (len) |
341 | { |
346 | { |
342 | #if ENABLE_COMBINING |
347 | #if ENABLE_COMBINING |
343 | compose_char *cc; |
348 | compose_char *cc; |
… | |
… | |
347 | |
352 | |
348 | while (++text, --len && *text == NOCHAR) |
353 | while (++text, --len && *text == NOCHAR) |
349 | ; |
354 | ; |
350 | |
355 | |
351 | int width = text - tp; |
356 | int width = text - tp; |
352 | int fwidth = r->TermWin.fwidth * width; |
357 | int fwidth = r->fwidth * width; |
353 | |
358 | |
354 | if (0x2500 <= t && t <= 0x259f) |
359 | if (0x2500 <= t && t <= 0x259f) |
355 | { |
360 | { |
356 | uint16_t offs = linedraw_offs[t - 0x2500]; |
361 | uint16_t offs = linedraw_offs[t - 0x2500]; |
357 | uint32_t *a = linedraw_command + (offs >> 4); |
362 | uint32_t *a = linedraw_command + (offs >> 4); |
358 | uint32_t *b = a + (offs & 15); |
363 | uint32_t *b = a + (offs & 15); |
359 | |
364 | |
360 | int W = fwidth; |
365 | int W = fwidth; |
361 | int H = r->TermWin.fheight; |
366 | int H = r->fheight; |
362 | |
367 | |
363 | int x_[16]; |
368 | int x_[16]; |
364 | int y_[16]; |
369 | int y_[16]; |
365 | |
370 | |
366 | for (int i = 0; i <= 8; i++) |
371 | for (int i = 0; i <= 8; i++) |
… | |
… | |
374 | |
379 | |
375 | XGCValues gcv; |
380 | XGCValues gcv; |
376 | |
381 | |
377 | gcv.cap_style = CapButt; |
382 | gcv.cap_style = CapButt; |
378 | gcv.line_width = 0; |
383 | gcv.line_width = 0; |
379 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
384 | XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); |
380 | |
385 | |
381 | while (a < b) |
386 | while (a < b) |
382 | { |
387 | { |
383 | uint32_t command = *a++; |
388 | uint32_t command = *a++; |
384 | |
389 | |
… | |
… | |
391 | int y2 = y_[(command >> 0) & 15]; |
396 | int y2 = y_[(command >> 0) & 15]; |
392 | |
397 | |
393 | switch (op) |
398 | switch (op) |
394 | { |
399 | { |
395 | case 0: // line |
400 | case 0: // line |
396 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
401 | XDrawLine (disp, d, TGC, x1, y1, x2, y2); |
397 | break; |
402 | break; |
398 | |
403 | |
399 | case 1: // rectangle, possibly stippled |
404 | case 1: // rectangle, possibly stippled |
400 | if (a) |
405 | if (a) |
401 | { |
406 | { |
402 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
407 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
403 | |
408 | |
404 | gcv.fill_style = FillStippled; |
409 | gcv.fill_style = FillStippled; |
405 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
410 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
406 | gcv.ts_x_origin = x; |
411 | gcv.ts_x_origin = x; |
407 | gcv.ts_y_origin = y; |
412 | gcv.ts_y_origin = y; |
408 | |
413 | |
409 | XChangeGC (d.display->display, TGC, |
414 | XChangeGC (disp, TGC, |
410 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
415 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
411 | &gcv); |
416 | &gcv); |
412 | } |
417 | } |
413 | |
418 | |
414 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
419 | XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
415 | |
420 | |
416 | if (a) |
421 | if (a) |
417 | { |
422 | { |
418 | XFreePixmap (d.display->display, gcv.stipple); |
423 | XFreePixmap (disp, gcv.stipple); |
419 | gcv.stipple = 0; |
424 | gcv.stipple = 0; |
420 | gcv.fill_style = FillSolid; |
425 | gcv.fill_style = FillSolid; |
421 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
426 | XChangeGC (disp, TGC, GCFillStyle, &gcv); |
422 | } |
427 | } |
423 | break; |
428 | break; |
424 | case 2: // arc |
429 | case 2: // arc |
425 | XDrawArc (d.display->display, d, TGC, |
430 | XDrawArc (disp, d, TGC, |
426 | x1 - W/2, y1 - H/2, W-1, H-1, |
431 | x1 - W/2, y1 - H/2, W-1, H-1, |
427 | (a - 1) * 90*64, (b - 1) * 90*64); |
432 | (a - 1) * 90*64, (b - 1) * 90*64); |
428 | break; |
433 | break; |
429 | } |
434 | } |
430 | } |
435 | } |
… | |
… | |
461 | case ZERO_WIDTH_CHAR: |
466 | case ZERO_WIDTH_CHAR: |
462 | case NOCHAR: |
467 | case NOCHAR: |
463 | break; |
468 | break; |
464 | |
469 | |
465 | default: |
470 | default: |
466 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
471 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
467 | fwidth - 4, r->TermWin.fheight - 4); |
472 | fwidth - 4, r->fheight - 4); |
468 | } |
473 | } |
469 | |
474 | |
470 | x += fwidth; |
475 | x += fwidth; |
471 | } |
476 | } |
472 | } |
477 | } |
… | |
… | |
521 | bool |
526 | bool |
522 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
527 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
523 | { |
528 | { |
524 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
529 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
525 | p.height = height; |
530 | p.height = height; |
|
|
531 | p.ascent = rxvt_fontprop::unset; |
526 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
532 | 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; |
533 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
528 | |
534 | |
529 | return true; |
535 | return true; |
530 | } |
536 | } |
… | |
… | |
550 | |
556 | |
551 | set_properties (p, height, weight, slant, avgwidth); |
557 | set_properties (p, height, weight, slant, avgwidth); |
552 | |
558 | |
553 | free (weight); |
559 | free (weight); |
554 | free (slant); |
560 | free (slant); |
|
|
561 | |
|
|
562 | p.ascent = f->ascent; |
555 | |
563 | |
556 | return true; |
564 | return true; |
557 | } |
565 | } |
558 | |
566 | |
559 | bool |
567 | bool |
… | |
… | |
630 | } |
638 | } |
631 | |
639 | |
632 | bool |
640 | bool |
633 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
641 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
634 | { |
642 | { |
|
|
643 | Display *disp = DISPLAY; |
|
|
644 | |
635 | clear (); |
645 | clear (); |
636 | |
646 | |
637 | char field_str[64]; // enough for 128 bits |
647 | char field_str[64]; // enough for 128 bits |
638 | |
648 | |
639 | // first morph the font if required |
649 | // first morph the font if required |
… | |
… | |
642 | { |
652 | { |
643 | char fname[1024]; |
653 | char fname[1024]; |
644 | |
654 | |
645 | if (name[0] != '-') |
655 | if (name[0] != '-') |
646 | { |
656 | { |
647 | f = XLoadQueryFont (DISPLAY, name); |
657 | f = XLoadQueryFont (disp, name); |
648 | |
658 | |
649 | if (!f) |
659 | if (!f) |
650 | return false; |
660 | return false; |
651 | |
661 | |
652 | char *new_name = get_property (f, "FONT", name); |
662 | char *new_name = get_property (f, "FONT", name); |
… | |
… | |
654 | if (new_name) |
664 | if (new_name) |
655 | set_name (new_name); |
665 | set_name (new_name); |
656 | else |
666 | else |
657 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
667 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
658 | |
668 | |
659 | XFreeFont (DISPLAY, f); |
669 | XFreeFont (disp, f); |
660 | f = 0; |
670 | f = 0; |
661 | } |
671 | } |
662 | |
672 | |
663 | if (prop.weight != rxvt_fontprop::unset) |
673 | if (prop.weight != rxvt_fontprop::unset) |
664 | { |
674 | { |
… | |
… | |
694 | ~font_weight () { free (name); } |
704 | ~font_weight () { free (name); } |
695 | }; |
705 | }; |
696 | |
706 | |
697 | char **list; |
707 | char **list; |
698 | int count; |
708 | int count; |
699 | list = XListFonts (DISPLAY, name, 4000, &count); |
709 | list = XListFonts (disp, name, 4000, &count); |
700 | |
710 | |
701 | set_name (0); |
711 | set_name (0); |
702 | |
712 | |
703 | if (!list) |
713 | if (!list) |
704 | return false; |
714 | return false; |
… | |
… | |
712 | |
722 | |
713 | int diff = 0; |
723 | int diff = 0; |
714 | |
724 | |
715 | if (replace_field (fname, list[i], 6, '0', field_str)) |
725 | if (replace_field (fname, list[i], 6, '0', field_str)) |
716 | diff += 10; // slightly penalize scalable fonts |
726 | diff += 10; // slightly penalize scalable fonts |
|
|
727 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
728 | diff += 300; // more heavily penalize what looks like scaled bitmap fotns |
717 | |
729 | |
718 | if (!set_properties (p, fname)) |
730 | if (!set_properties (p, fname)) |
719 | continue; |
731 | continue; |
720 | |
732 | |
721 | if (prop.height != rxvt_fontprop::unset |
733 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
737 | for (;;) |
749 | for (;;) |
738 | { |
750 | { |
739 | font_weight *best = fonts + count - 1; |
751 | font_weight *best = fonts + count - 1; |
740 | |
752 | |
741 | for (font_weight *w = best; w-- > fonts; ) |
753 | for (font_weight *w = best; w-- > fonts; ) |
742 | if (w->diff < best->diff) |
754 | if (w->diff <= best->diff) |
743 | best = w; |
755 | best = w; |
744 | |
756 | |
745 | if (!best->name |
757 | if (!best->name |
746 | || !(f = XLoadQueryFont (DISPLAY, best->name))) |
758 | || !(f = XLoadQueryFont (disp, best->name))) |
747 | break; |
759 | break; |
748 | |
760 | |
749 | set_name (best->name); |
761 | set_name (best->name); |
750 | best->clear (); |
762 | best->clear (); |
751 | |
763 | |
… | |
… | |
845 | |
857 | |
846 | XCharStruct g; |
858 | XCharStruct g; |
847 | int dir_ret, asc_ret, des_ret; |
859 | int dir_ret, asc_ret, des_ret; |
848 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
860 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
849 | |
861 | |
850 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
862 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
851 | |
863 | |
852 | if (width < g.width) width = g.width; |
864 | if (width < g.width) width = g.width; |
853 | } |
865 | } |
854 | |
866 | |
855 | if (cs == CS_UNKNOWN) |
867 | if (cs == CS_UNKNOWN) |
… | |
… | |
930 | return true; |
942 | return true; |
931 | |
943 | |
932 | // check character against base font bounding box |
944 | // check character against base font bounding box |
933 | int w = xcs->width; |
945 | int w = xcs->width; |
934 | int wcw = wcwidth (unicode); |
946 | int wcw = wcwidth (unicode); |
935 | if (wcw > 0) w /= wcw; |
947 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
936 | |
948 | |
937 | careful = w > prop->width; |
949 | careful = w > prop->width; |
938 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
950 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
939 | return false; |
951 | return false; |
940 | |
952 | |
… | |
… | |
950 | // and it is a mess /. |
962 | // and it is a mess /. |
951 | // yet we are trying to be perfect /. |
963 | // yet we are trying to be perfect /. |
952 | // but the result still isn't perfect /. |
964 | // but the result still isn't perfect /. |
953 | |
965 | |
954 | bool slow = this->slow |
966 | bool slow = this->slow |
955 | || width != r->TermWin.fwidth |
967 | || width != r->fwidth |
956 | || height != r->TermWin.fheight; |
968 | || height != r->fheight; |
957 | |
969 | |
958 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
970 | int base = ascent; // sorry, incorrect: r->fbase; |
959 | |
971 | |
960 | XGCValues v; |
972 | XGCValues v; |
961 | v.foreground = r->pix_colors[fg]; |
973 | v.foreground = r->pix_colors[fg]; |
962 | v.font = f->fid; |
974 | v.font = f->fid; |
963 | |
975 | |
… | |
… | |
971 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
983 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
972 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
984 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
973 | } |
985 | } |
974 | else |
986 | else |
975 | { |
987 | { |
976 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
988 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
977 | |
989 | |
978 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
990 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
979 | |
991 | |
980 | if (slow) |
992 | if (slow) |
981 | { |
993 | { |
982 | do |
994 | do |
983 | { |
995 | { |
984 | if (xc->byte1 || xc->byte2) |
996 | if (xc->byte1 || xc->byte2) |
985 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
997 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
986 | |
998 | |
987 | x += r->TermWin.fwidth; |
999 | x += r->fwidth; |
988 | xc++; len--; |
1000 | xc++; len--; |
989 | } |
1001 | } |
990 | while (len); |
1002 | while (len); |
991 | } |
1003 | } |
992 | else |
1004 | else |
… | |
… | |
1003 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1015 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1004 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1016 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1005 | } |
1017 | } |
1006 | else |
1018 | else |
1007 | { |
1019 | { |
1008 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1020 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1009 | |
1021 | |
1010 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1022 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1011 | |
1023 | |
1012 | if (slow) |
1024 | if (slow) |
1013 | { |
1025 | { |
1014 | do |
1026 | do |
1015 | { |
1027 | { |
1016 | if (*xc) |
1028 | if (*xc) |
1017 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1029 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1018 | |
1030 | |
1019 | x += r->TermWin.fwidth; |
1031 | x += r->fwidth; |
1020 | xc++; len--; |
1032 | xc++; len--; |
1021 | } |
1033 | } |
1022 | while (len); |
1034 | while (len); |
1023 | } |
1035 | } |
1024 | else |
1036 | else |
… | |
… | |
1067 | |
1079 | |
1068 | FT_Face face = XftLockFace (f); |
1080 | FT_Face face = XftLockFace (f); |
1069 | |
1081 | |
1070 | p.width = width; |
1082 | p.width = width; |
1071 | p.height = height; |
1083 | p.height = height; |
|
|
1084 | p.ascent = ascent; |
1072 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1085 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1073 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1086 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1074 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1087 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1075 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1088 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1076 | |
1089 | |
… | |
… | |
1080 | } |
1093 | } |
1081 | |
1094 | |
1082 | bool |
1095 | bool |
1083 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1096 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1084 | { |
1097 | { |
|
|
1098 | Display *disp = DISPLAY; |
|
|
1099 | |
1085 | clear (); |
1100 | clear (); |
1086 | |
1101 | |
1087 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1102 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1088 | |
1103 | |
1089 | if (!p) |
1104 | if (!p) |
1090 | return false; |
1105 | return false; |
1091 | |
1106 | |
1092 | FcValue v; |
1107 | FcValue v; |
1093 | |
1108 | |
1094 | if (prop.height != rxvt_fontprop::unset |
1109 | if (prop.height != rxvt_fontprop::unset |
1095 | || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1110 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1096 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1111 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1097 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1112 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1098 | |
1113 | |
1099 | if (prop.weight != rxvt_fontprop::unset |
1114 | if (prop.weight != rxvt_fontprop::unset |
1100 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1115 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
… | |
… | |
1115 | |
1130 | |
1116 | // store generated name so iso14755 view gives better results |
1131 | // store generated name so iso14755 view gives better results |
1117 | set_name ((char *)FcNameUnparse (p)); |
1132 | set_name ((char *)FcNameUnparse (p)); |
1118 | |
1133 | |
1119 | XftResult result; |
1134 | XftResult result; |
1120 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1135 | FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); |
1121 | |
1136 | |
1122 | FcPatternDestroy (p); |
1137 | FcPatternDestroy (p); |
1123 | |
1138 | |
1124 | if (!match) |
1139 | if (!match) |
1125 | return false; |
1140 | return false; |
… | |
… | |
1127 | int ftheight = 0; |
1142 | int ftheight = 0; |
1128 | bool success = true; |
1143 | bool success = true; |
1129 | |
1144 | |
1130 | for (;;) |
1145 | for (;;) |
1131 | { |
1146 | { |
1132 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1147 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1133 | |
1148 | |
1134 | if (!f) |
1149 | if (!f) |
1135 | { |
1150 | { |
1136 | success = false; |
1151 | success = false; |
1137 | break; |
1152 | break; |
… | |
… | |
1146 | |
1161 | |
1147 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1162 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1148 | |
1163 | |
1149 | XftUnlockFace (f); |
1164 | XftUnlockFace (f); |
1150 | |
1165 | |
|
|
1166 | int glheight = height; |
|
|
1167 | |
1151 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1168 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1152 | { |
1169 | { |
1153 | FcChar16 ch = *t; |
1170 | FcChar16 ch = *t; |
1154 | |
1171 | |
1155 | if (cs != CS_UNICODE |
1172 | if (cs != CS_UNICODE |
… | |
… | |
1161 | bool careful; |
1178 | bool careful; |
1162 | if (!has_char (*t, &prop, careful)) |
1179 | if (!has_char (*t, &prop, careful)) |
1163 | continue; |
1180 | continue; |
1164 | |
1181 | |
1165 | XGlyphInfo g; |
1182 | XGlyphInfo g; |
1166 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1183 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1184 | |
|
|
1185 | g.width -= g.x; |
1167 | |
1186 | |
1168 | int wcw = wcwidth (ch); |
1187 | int wcw = wcwidth (ch); |
1169 | if (wcw > 0) g.width = g.width / wcw; |
1188 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1170 | |
1189 | |
1171 | if (width < g.width) width = g.width; |
1190 | if (width < g.width ) width = g.width; |
1172 | if (height < g.height) height = g.height; |
1191 | if (height < g.height ) height = g.height; |
|
|
1192 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1193 | } |
|
|
1194 | |
|
|
1195 | if (!width) |
|
|
1196 | { |
|
|
1197 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1198 | |
|
|
1199 | XftFontClose (disp, f); |
|
|
1200 | f = 0; |
|
|
1201 | |
|
|
1202 | success = false; |
|
|
1203 | break; |
1173 | } |
1204 | } |
1174 | |
1205 | |
1175 | if (prop.height == rxvt_fontprop::unset |
1206 | if (prop.height == rxvt_fontprop::unset |
1176 | || height <= prop.height |
1207 | || (height <= prop.height && glheight <= prop.height) |
1177 | || height <= 2 |
1208 | || height <= 2 |
1178 | || !scalable) |
1209 | || !scalable) |
1179 | break; |
1210 | break; |
1180 | |
1211 | |
1181 | if (ftheight) |
1212 | if (ftheight) |
… | |
… | |
1188 | ftheight -= height - prop.height; |
1219 | ftheight -= height - prop.height; |
1189 | } |
1220 | } |
1190 | else |
1221 | else |
1191 | ftheight = prop.height - 1; |
1222 | ftheight = prop.height - 1; |
1192 | |
1223 | |
1193 | XftFontClose (DISPLAY, f); |
1224 | XftFontClose (disp, f); |
1194 | FcPatternDel (match, FC_PIXEL_SIZE); |
1225 | FcPatternDel (match, FC_PIXEL_SIZE); |
1195 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1226 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1196 | } |
1227 | } |
1197 | |
1228 | |
1198 | FcPatternDestroy (match); |
1229 | FcPatternDestroy (match); |
1199 | |
1230 | |
1200 | #if 0 // do it per-character |
1231 | #if 0 // do it per-character |
… | |
… | |
1222 | // check character against base font bounding box |
1253 | // check character against base font bounding box |
1223 | FcChar32 ch = unicode; |
1254 | FcChar32 ch = unicode; |
1224 | XGlyphInfo g; |
1255 | XGlyphInfo g; |
1225 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1256 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1226 | |
1257 | |
1227 | int w = g.width; |
1258 | int w = g.width - g.x; |
1228 | int wcw = wcwidth (unicode); |
1259 | int wcw = wcwidth (unicode); |
1229 | if (wcw > 0) w /= wcw; |
1260 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1230 | |
1261 | |
1231 | careful = w > prop->width; |
1262 | careful = w > prop->width; |
1232 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1263 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1233 | return false; |
1264 | return false; |
1234 | |
1265 | |
… | |
… | |
1238 | void |
1269 | void |
1239 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1270 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1240 | const text_t *text, int len, |
1271 | const text_t *text, int len, |
1241 | int fg, int bg) |
1272 | int fg, int bg) |
1242 | { |
1273 | { |
1243 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1274 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1244 | |
|
|
1245 | int base = ascent; // should be fbase, but that is incorrect |
|
|
1246 | |
1275 | |
1247 | XGlyphInfo extents; |
1276 | XGlyphInfo extents; |
1248 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1277 | XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); |
1249 | FcChar32 *ep = enc; |
1278 | XftGlyphSpec *ep = enc; |
1250 | int ewidth = 0; |
1279 | |
1251 | int xoff = 0; |
1280 | // cut trailing spaces |
|
|
1281 | while (len && text [len - 1] == ' ') |
|
|
1282 | len--; |
1252 | |
1283 | |
1253 | while (len) |
1284 | while (len) |
1254 | { |
1285 | { |
1255 | int cwidth = r->TermWin.fwidth; |
1286 | int cwidth = r->fwidth; |
1256 | FcChar32 fc = *text++; len--; |
1287 | FcChar32 fc = *text++; len--; |
1257 | FT_UInt gl; |
|
|
1258 | |
1288 | |
1259 | while (len && *text == NOCHAR) |
1289 | while (len && *text == NOCHAR) |
1260 | text++, len--, cwidth += r->TermWin.fwidth; |
1290 | text++, len--, cwidth += r->fwidth; |
1261 | |
1291 | |
|
|
1292 | if (fc != ' ') // skip spaces |
|
|
1293 | { |
1262 | gl = XftCharIndex (d.display->display, f, fc); |
1294 | FT_UInt glyph = XftCharIndex (d.display->display, f, fc); |
1263 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
1295 | XftGlyphExtents (d.display->display, f, &glyph, 1, &extents); |
1264 | |
1296 | |
1265 | if (extents.xOff != cwidth && ep != enc) |
1297 | ep->glyph = glyph; |
|
|
1298 | ep->x = x + (cwidth - extents.xOff >> 1); |
|
|
1299 | ep->y = y + ascent; |
|
|
1300 | ep++; |
1266 | { |
1301 | } |
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 | |
1302 | |
1273 | ep = enc; |
|
|
1274 | ewidth = 0; |
|
|
1275 | xoff = 0; |
|
|
1276 | } |
|
|
1277 | |
|
|
1278 | if (fc == ' ' && ep == enc) // skip leading spaces |
|
|
1279 | { |
|
|
1280 | x += cwidth; |
1303 | x += cwidth; |
1281 | continue; |
|
|
1282 | } |
|
|
1283 | |
|
|
1284 | else |
|
|
1285 | { |
|
|
1286 | *ep++ = gl; |
|
|
1287 | ewidth += cwidth; |
|
|
1288 | xoff += extents.xOff; |
|
|
1289 | } |
|
|
1290 | } |
1304 | } |
1291 | |
1305 | |
1292 | if (ep != enc) |
1306 | if (ep != enc) |
1293 | { |
|
|
1294 | if (xoff > ewidth) xoff = ewidth; |
|
|
1295 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1307 | XftDrawGlyphSpec (d, &r->pix_colors[fg].c, f, enc, ep - enc); |
1296 | x + (ewidth - xoff >> 1), |
|
|
1297 | y + base, enc, ep - enc); |
|
|
1298 | } |
|
|
1299 | } |
1308 | } |
1300 | #endif |
1309 | #endif |
1301 | |
1310 | |
1302 | ///////////////////////////////////////////////////////////////////////////// |
1311 | ///////////////////////////////////////////////////////////////////////////// |
1303 | |
1312 | |
1304 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1313 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1305 | : r (r), fontdesc (0) |
1314 | : fontdesc (0), r (r) |
1306 | { |
1315 | { |
1307 | clear (); |
1316 | clear (); |
1308 | } |
1317 | } |
1309 | |
1318 | |
1310 | rxvt_fontset::~rxvt_fontset () |
1319 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1313 | } |
1322 | } |
1314 | |
1323 | |
1315 | void |
1324 | void |
1316 | rxvt_fontset::clear () |
1325 | rxvt_fontset::clear () |
1317 | { |
1326 | { |
1318 | prop.width = prop.height = prop.weight = prop.slant |
1327 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1319 | = rxvt_fontprop::unset; |
1328 | = rxvt_fontprop::unset; |
1320 | |
1329 | |
1321 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1330 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1322 | FONT_UNREF (*i); |
1331 | FONT_UNREF (*i); |
1323 | |
1332 | |
… | |
… | |
1375 | char buf[512]; |
1384 | char buf[512]; |
1376 | const char *end; |
1385 | const char *end; |
1377 | |
1386 | |
1378 | do |
1387 | do |
1379 | { |
1388 | { |
1380 | while (*desc <= ' ') desc++; |
1389 | while (*desc && *desc <= ' ') |
|
|
1390 | desc++; |
1381 | |
1391 | |
1382 | codeset cs = CS_UNICODE; |
1392 | codeset cs = CS_UNICODE; |
1383 | |
1393 | |
1384 | if (*desc == '[') |
1394 | if (*desc == '[') |
1385 | { |
1395 | { |
… | |
… | |
1495 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1505 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1496 | goto next_font; |
1506 | goto next_font; |
1497 | |
1507 | |
1498 | if (!realize_font (i)) |
1508 | if (!realize_font (i)) |
1499 | goto next_font; |
1509 | goto next_font; |
|
|
1510 | |
|
|
1511 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1512 | max_it (f->ascent, prop.ascent); |
1500 | } |
1513 | } |
1501 | |
1514 | |
1502 | if (f->cs == CS_UNKNOWN) |
1515 | if (f->cs == CS_UNKNOWN) |
1503 | goto next_font; |
1516 | goto next_font; |
1504 | |
1517 | |
… | |
… | |
1543 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1556 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1544 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1557 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1545 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1558 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1546 | |
1559 | |
1547 | XftResult result; |
1560 | XftResult result; |
1548 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1561 | FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); |
1549 | |
1562 | |
1550 | FcPatternDestroy (p); |
1563 | FcPatternDestroy (p); |
1551 | |
1564 | |
1552 | if (match) |
1565 | if (match) |
1553 | { |
1566 | { |