… | |
… | |
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 "rxvtutil.h" |
24 | #include "rxvtutil.h" |
… | |
… | |
27 | #include <cstdlib> |
27 | #include <cstdlib> |
28 | #include <wchar.h> |
28 | #include <wchar.h> |
29 | #include <inttypes.h> |
29 | #include <inttypes.h> |
30 | |
30 | |
31 | #define DISPLAY r->display->display |
31 | #define DISPLAY r->display->display |
32 | #define TGC r->TermWin.gc |
32 | #define TGC r->gc |
33 | |
33 | |
34 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
34 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | |
35 | |
36 | const struct rxvt_fallback_font { |
36 | const struct rxvt_fallback_font { |
37 | codeset cs; |
37 | codeset cs; |
… | |
… | |
130 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
130 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
134 | #if XFT |
134 | #if XFT |
135 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, |
135 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
136 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
136 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
137 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
137 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
138 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
138 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
139 | |
139 | |
140 | // FreeMono is usually uglier than x fonts, so try last only. |
140 | // FreeMono is usually uglier than x fonts, so try last only. |
141 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
141 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
142 | #endif |
142 | #endif |
143 | |
143 | |
… | |
… | |
276 | rxvt_fontprop properties () |
276 | rxvt_fontprop properties () |
277 | { |
277 | { |
278 | rxvt_fontprop p; |
278 | rxvt_fontprop p; |
279 | |
279 | |
280 | p.width = p.height = 1; |
280 | p.width = p.height = 1; |
|
|
281 | p.ascent = rxvt_fontprop::unset; |
281 | p.weight = rxvt_fontprop::medium; |
282 | p.weight = rxvt_fontprop::medium; |
282 | p.slant = rxvt_fontprop::roman; |
283 | p.slant = rxvt_fontprop::roman; |
283 | |
284 | |
284 | return p; |
285 | return p; |
285 | } |
286 | } |
… | |
… | |
333 | const text_t *text, int len, |
334 | const text_t *text, int len, |
334 | int fg, int bg) |
335 | int fg, int bg) |
335 | { |
336 | { |
336 | Display *disp = d.display->display; |
337 | Display *disp = d.display->display; |
337 | |
338 | |
338 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
339 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
339 | |
340 | |
340 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
341 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
341 | |
342 | |
342 | while (len) |
343 | while (len) |
343 | { |
344 | { |
… | |
… | |
349 | |
350 | |
350 | while (++text, --len && *text == NOCHAR) |
351 | while (++text, --len && *text == NOCHAR) |
351 | ; |
352 | ; |
352 | |
353 | |
353 | int width = text - tp; |
354 | int width = text - tp; |
354 | int fwidth = r->TermWin.fwidth * width; |
355 | int fwidth = r->fwidth * width; |
355 | |
356 | |
356 | if (0x2500 <= t && t <= 0x259f) |
357 | if (0x2500 <= t && t <= 0x259f) |
357 | { |
358 | { |
358 | uint16_t offs = linedraw_offs[t - 0x2500]; |
359 | uint16_t offs = linedraw_offs[t - 0x2500]; |
359 | uint32_t *a = linedraw_command + (offs >> 4); |
360 | uint32_t *a = linedraw_command + (offs >> 4); |
360 | uint32_t *b = a + (offs & 15); |
361 | uint32_t *b = a + (offs & 15); |
361 | |
362 | |
362 | int W = fwidth; |
363 | int W = fwidth; |
363 | int H = r->TermWin.fheight; |
364 | int H = r->fheight; |
364 | |
365 | |
365 | int x_[16]; |
366 | int x_[16]; |
366 | int y_[16]; |
367 | int y_[16]; |
367 | |
368 | |
368 | for (int i = 0; i <= 8; i++) |
369 | for (int i = 0; i <= 8; i++) |
… | |
… | |
464 | case NOCHAR: |
465 | case NOCHAR: |
465 | break; |
466 | break; |
466 | |
467 | |
467 | default: |
468 | default: |
468 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
469 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
469 | fwidth - 4, r->TermWin.fheight - 4); |
470 | fwidth - 4, r->fheight - 4); |
470 | } |
471 | } |
471 | |
472 | |
472 | x += fwidth; |
473 | x += fwidth; |
473 | } |
474 | } |
474 | } |
475 | } |
… | |
… | |
523 | bool |
524 | bool |
524 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
525 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
525 | { |
526 | { |
526 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
527 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
527 | p.height = height; |
528 | p.height = height; |
|
|
529 | p.ascent = rxvt_fontprop::unset; |
528 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
530 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
529 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
531 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
530 | |
532 | |
531 | return true; |
533 | return true; |
532 | } |
534 | } |
… | |
… | |
552 | |
554 | |
553 | set_properties (p, height, weight, slant, avgwidth); |
555 | set_properties (p, height, weight, slant, avgwidth); |
554 | |
556 | |
555 | free (weight); |
557 | free (weight); |
556 | free (slant); |
558 | free (slant); |
|
|
559 | |
|
|
560 | p.ascent = f->ascent; |
557 | |
561 | |
558 | return true; |
562 | return true; |
559 | } |
563 | } |
560 | |
564 | |
561 | bool |
565 | bool |
… | |
… | |
716 | |
720 | |
717 | int diff = 0; |
721 | int diff = 0; |
718 | |
722 | |
719 | if (replace_field (fname, list[i], 6, '0', field_str)) |
723 | if (replace_field (fname, list[i], 6, '0', field_str)) |
720 | diff += 10; // slightly penalize scalable fonts |
724 | diff += 10; // slightly penalize scalable fonts |
|
|
725 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
726 | diff += 300; // more heavily penalize what looks like scaled bitmap fotns |
721 | |
727 | |
722 | if (!set_properties (p, fname)) |
728 | if (!set_properties (p, fname)) |
723 | continue; |
729 | continue; |
724 | |
730 | |
725 | if (prop.height != rxvt_fontprop::unset |
731 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
741 | for (;;) |
747 | for (;;) |
742 | { |
748 | { |
743 | font_weight *best = fonts + count - 1; |
749 | font_weight *best = fonts + count - 1; |
744 | |
750 | |
745 | for (font_weight *w = best; w-- > fonts; ) |
751 | for (font_weight *w = best; w-- > fonts; ) |
746 | if (w->diff < best->diff) |
752 | if (w->diff <= best->diff) |
747 | best = w; |
753 | best = w; |
748 | |
754 | |
749 | if (!best->name |
755 | if (!best->name |
750 | || !(f = XLoadQueryFont (disp, best->name))) |
756 | || !(f = XLoadQueryFont (disp, best->name))) |
751 | break; |
757 | break; |
… | |
… | |
849 | |
855 | |
850 | XCharStruct g; |
856 | XCharStruct g; |
851 | int dir_ret, asc_ret, des_ret; |
857 | int dir_ret, asc_ret, des_ret; |
852 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
858 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
853 | |
859 | |
854 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
860 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
855 | |
861 | |
856 | if (width < g.width) width = g.width; |
862 | if (width < g.width) width = g.width; |
857 | } |
863 | } |
858 | |
864 | |
859 | if (cs == CS_UNKNOWN) |
865 | if (cs == CS_UNKNOWN) |
… | |
… | |
934 | return true; |
940 | return true; |
935 | |
941 | |
936 | // check character against base font bounding box |
942 | // check character against base font bounding box |
937 | int w = xcs->width; |
943 | int w = xcs->width; |
938 | int wcw = wcwidth (unicode); |
944 | int wcw = wcwidth (unicode); |
939 | if (wcw > 0) w /= wcw; |
945 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
940 | |
946 | |
941 | careful = w > prop->width; |
947 | careful = w > prop->width; |
942 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
948 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
943 | return false; |
949 | return false; |
944 | |
950 | |
… | |
… | |
954 | // and it is a mess /. |
960 | // and it is a mess /. |
955 | // yet we are trying to be perfect /. |
961 | // yet we are trying to be perfect /. |
956 | // but the result still isn't perfect /. |
962 | // but the result still isn't perfect /. |
957 | |
963 | |
958 | bool slow = this->slow |
964 | bool slow = this->slow |
959 | || width != r->TermWin.fwidth |
965 | || width != r->fwidth |
960 | || height != r->TermWin.fheight; |
966 | || height != r->fheight; |
961 | |
967 | |
962 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
968 | int base = ascent; // sorry, incorrect: r->fbase; |
963 | |
969 | |
964 | XGCValues v; |
970 | XGCValues v; |
965 | v.foreground = r->pix_colors[fg]; |
971 | v.foreground = r->pix_colors[fg]; |
966 | v.font = f->fid; |
972 | v.font = f->fid; |
967 | |
973 | |
… | |
… | |
975 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
981 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
976 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
982 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
977 | } |
983 | } |
978 | else |
984 | else |
979 | { |
985 | { |
980 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
986 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
981 | |
987 | |
982 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
988 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
983 | |
989 | |
984 | if (slow) |
990 | if (slow) |
985 | { |
991 | { |
986 | do |
992 | do |
987 | { |
993 | { |
988 | if (xc->byte1 || xc->byte2) |
994 | if (xc->byte1 || xc->byte2) |
989 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
995 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
990 | |
996 | |
991 | x += r->TermWin.fwidth; |
997 | x += r->fwidth; |
992 | xc++; len--; |
998 | xc++; len--; |
993 | } |
999 | } |
994 | while (len); |
1000 | while (len); |
995 | } |
1001 | } |
996 | else |
1002 | else |
… | |
… | |
1007 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1013 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1008 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1014 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1009 | } |
1015 | } |
1010 | else |
1016 | else |
1011 | { |
1017 | { |
1012 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1018 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1013 | |
1019 | |
1014 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1020 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1015 | |
1021 | |
1016 | if (slow) |
1022 | if (slow) |
1017 | { |
1023 | { |
1018 | do |
1024 | do |
1019 | { |
1025 | { |
1020 | if (*xc) |
1026 | if (*xc) |
1021 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1027 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1022 | |
1028 | |
1023 | x += r->TermWin.fwidth; |
1029 | x += r->fwidth; |
1024 | xc++; len--; |
1030 | xc++; len--; |
1025 | } |
1031 | } |
1026 | while (len); |
1032 | while (len); |
1027 | } |
1033 | } |
1028 | else |
1034 | else |
… | |
… | |
1071 | |
1077 | |
1072 | FT_Face face = XftLockFace (f); |
1078 | FT_Face face = XftLockFace (f); |
1073 | |
1079 | |
1074 | p.width = width; |
1080 | p.width = width; |
1075 | p.height = height; |
1081 | p.height = height; |
|
|
1082 | p.ascent = ascent; |
1076 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1083 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1077 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1084 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1078 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1085 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1079 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1086 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1080 | |
1087 | |
… | |
… | |
1096 | return false; |
1103 | return false; |
1097 | |
1104 | |
1098 | FcValue v; |
1105 | FcValue v; |
1099 | |
1106 | |
1100 | if (prop.height != rxvt_fontprop::unset |
1107 | if (prop.height != rxvt_fontprop::unset |
1101 | || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1108 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1102 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1109 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1103 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1110 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1104 | |
1111 | |
1105 | if (prop.weight != rxvt_fontprop::unset |
1112 | if (prop.weight != rxvt_fontprop::unset |
1106 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1113 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
… | |
… | |
1152 | |
1159 | |
1153 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1160 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1154 | |
1161 | |
1155 | XftUnlockFace (f); |
1162 | XftUnlockFace (f); |
1156 | |
1163 | |
|
|
1164 | int glheight = height; |
|
|
1165 | |
1157 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1166 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1158 | { |
1167 | { |
1159 | FcChar16 ch = *t; |
1168 | FcChar16 ch = *t; |
1160 | |
1169 | |
1161 | if (cs != CS_UNICODE |
1170 | if (cs != CS_UNICODE |
… | |
… | |
1169 | continue; |
1178 | continue; |
1170 | |
1179 | |
1171 | XGlyphInfo g; |
1180 | XGlyphInfo g; |
1172 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1181 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1173 | |
1182 | |
|
|
1183 | g.width -= g.x; |
|
|
1184 | |
1174 | int wcw = wcwidth (ch); |
1185 | int wcw = wcwidth (ch); |
1175 | if (wcw > 0) g.width = g.width / wcw; |
1186 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1176 | |
1187 | |
1177 | if (width < g.width) width = g.width; |
1188 | if (width < g.width ) width = g.width; |
1178 | if (height < g.height) height = g.height; |
1189 | if (height < g.height ) height = g.height; |
|
|
1190 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1191 | } |
|
|
1192 | |
|
|
1193 | if (!width) |
|
|
1194 | { |
|
|
1195 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1196 | |
|
|
1197 | XftFontClose (disp, f); |
|
|
1198 | f = 0; |
|
|
1199 | |
|
|
1200 | success = false; |
|
|
1201 | break; |
1179 | } |
1202 | } |
1180 | |
1203 | |
1181 | if (prop.height == rxvt_fontprop::unset |
1204 | if (prop.height == rxvt_fontprop::unset |
1182 | || height <= prop.height |
1205 | || (height <= prop.height && glheight <= prop.height) |
1183 | || height <= 2 |
1206 | || height <= 2 |
1184 | || !scalable) |
1207 | || !scalable) |
1185 | break; |
1208 | break; |
1186 | |
1209 | |
1187 | if (ftheight) |
1210 | if (ftheight) |
… | |
… | |
1194 | ftheight -= height - prop.height; |
1217 | ftheight -= height - prop.height; |
1195 | } |
1218 | } |
1196 | else |
1219 | else |
1197 | ftheight = prop.height - 1; |
1220 | ftheight = prop.height - 1; |
1198 | |
1221 | |
1199 | XftFontClose (disp, f); |
1222 | XftFontClose (disp, f); |
1200 | FcPatternDel (match, FC_PIXEL_SIZE); |
1223 | FcPatternDel (match, FC_PIXEL_SIZE); |
1201 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1224 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1202 | } |
1225 | } |
1203 | |
1226 | |
1204 | FcPatternDestroy (match); |
1227 | FcPatternDestroy (match); |
1205 | |
1228 | |
1206 | #if 0 // do it per-character |
1229 | #if 0 // do it per-character |
… | |
… | |
1228 | // check character against base font bounding box |
1251 | // check character against base font bounding box |
1229 | FcChar32 ch = unicode; |
1252 | FcChar32 ch = unicode; |
1230 | XGlyphInfo g; |
1253 | XGlyphInfo g; |
1231 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1254 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1232 | |
1255 | |
1233 | int w = g.width; |
1256 | int w = g.width - g.x; |
1234 | int wcw = wcwidth (unicode); |
1257 | int wcw = wcwidth (unicode); |
1235 | if (wcw > 0) w /= wcw; |
1258 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1236 | |
1259 | |
1237 | careful = w > prop->width; |
1260 | careful = w > prop->width; |
1238 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1261 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1239 | return false; |
1262 | return false; |
1240 | |
1263 | |
… | |
… | |
1244 | void |
1267 | void |
1245 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1268 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1246 | const text_t *text, int len, |
1269 | const text_t *text, int len, |
1247 | int fg, int bg) |
1270 | int fg, int bg) |
1248 | { |
1271 | { |
1249 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1272 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1250 | |
1273 | |
1251 | int base = ascent; // should be fbase, but that is incorrect |
1274 | int base = ascent; // should be fbase, but that is incorrect |
1252 | |
1275 | |
1253 | XGlyphInfo extents; |
1276 | XGlyphInfo extents; |
1254 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1277 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1255 | FcChar32 *ep = enc; |
1278 | FcChar32 *ep = enc; |
1256 | int ewidth = 0; |
1279 | int ewidth = 0; |
1257 | int xoff = 0; |
|
|
1258 | |
1280 | |
1259 | while (len) |
1281 | while (len) |
1260 | { |
1282 | { |
1261 | int cwidth = r->TermWin.fwidth; |
1283 | int cwidth = r->fwidth; |
1262 | FcChar32 fc = *text++; len--; |
1284 | FcChar32 fc = *text++; len--; |
1263 | FT_UInt gl; |
|
|
1264 | |
1285 | |
1265 | while (len && *text == NOCHAR) |
1286 | while (len && *text == NOCHAR) |
1266 | text++, len--, cwidth += r->TermWin.fwidth; |
1287 | text++, len--, cwidth += r->fwidth; |
1267 | |
1288 | |
1268 | gl = XftCharIndex (d.display->display, f, fc); |
|
|
1269 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1270 | |
|
|
1271 | if (extents.xOff != cwidth && ep != enc) |
|
|
1272 | { |
|
|
1273 | if (xoff > ewidth) xoff = ewidth; |
|
|
1274 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1275 | x + (ewidth - xoff >> 1), |
|
|
1276 | y + base, enc, ep - enc); |
|
|
1277 | x += ewidth; |
|
|
1278 | |
|
|
1279 | ep = enc; |
|
|
1280 | ewidth = 0; |
|
|
1281 | xoff = 0; |
|
|
1282 | } |
|
|
1283 | |
|
|
1284 | if (fc == ' ' && ep == enc) // skip leading spaces |
1289 | if (fc == ' ' && ep == enc) // skip leading spaces |
1285 | { |
|
|
1286 | x += cwidth; |
1290 | x += cwidth; |
1287 | continue; |
|
|
1288 | } |
|
|
1289 | |
|
|
1290 | else |
1291 | else |
1291 | { |
1292 | { |
|
|
1293 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
|
|
1294 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1295 | |
|
|
1296 | if (extents.xOff != cwidth) |
|
|
1297 | { |
|
|
1298 | if (ewidth) |
|
|
1299 | { |
|
|
1300 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1301 | x, y + base, enc, ep - enc); |
|
|
1302 | x += ewidth; |
|
|
1303 | |
|
|
1304 | ep = enc; |
|
|
1305 | ewidth = 0; |
|
|
1306 | } |
|
|
1307 | |
|
|
1308 | if (extents.xOff > cwidth) |
|
|
1309 | extents.xOff = cwidth; |
|
|
1310 | |
|
|
1311 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1312 | x + (cwidth - extents.xOff >> 1), |
|
|
1313 | y + base, &gl, 1); |
|
|
1314 | x += cwidth; |
|
|
1315 | } |
|
|
1316 | else |
|
|
1317 | { |
1292 | *ep++ = gl; |
1318 | *ep++ = gl; |
1293 | ewidth += cwidth; |
1319 | ewidth += cwidth; |
1294 | xoff += extents.xOff; |
1320 | } |
1295 | } |
1321 | } |
1296 | } |
1322 | } |
1297 | |
1323 | |
1298 | if (ep != enc) |
1324 | if (ep != enc) |
1299 | { |
|
|
1300 | if (xoff > ewidth) xoff = ewidth; |
|
|
1301 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1325 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1302 | x + (ewidth - xoff >> 1), |
|
|
1303 | y + base, enc, ep - enc); |
1326 | x, y + base, enc, ep - enc); |
1304 | } |
|
|
1305 | } |
1327 | } |
1306 | #endif |
1328 | #endif |
1307 | |
1329 | |
1308 | ///////////////////////////////////////////////////////////////////////////// |
1330 | ///////////////////////////////////////////////////////////////////////////// |
1309 | |
1331 | |
1310 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1332 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1311 | : r (r), fontdesc (0) |
1333 | : fontdesc (0), r (r) |
1312 | { |
1334 | { |
1313 | clear (); |
1335 | clear (); |
1314 | } |
1336 | } |
1315 | |
1337 | |
1316 | rxvt_fontset::~rxvt_fontset () |
1338 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1319 | } |
1341 | } |
1320 | |
1342 | |
1321 | void |
1343 | void |
1322 | rxvt_fontset::clear () |
1344 | rxvt_fontset::clear () |
1323 | { |
1345 | { |
1324 | prop.width = prop.height = prop.weight = prop.slant |
1346 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1325 | = rxvt_fontprop::unset; |
1347 | = rxvt_fontprop::unset; |
1326 | |
1348 | |
1327 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1349 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1328 | FONT_UNREF (*i); |
1350 | FONT_UNREF (*i); |
1329 | |
1351 | |
… | |
… | |
1381 | char buf[512]; |
1403 | char buf[512]; |
1382 | const char *end; |
1404 | const char *end; |
1383 | |
1405 | |
1384 | do |
1406 | do |
1385 | { |
1407 | { |
1386 | while (*desc <= ' ') desc++; |
1408 | while (*desc && *desc <= ' ') |
|
|
1409 | desc++; |
1387 | |
1410 | |
1388 | codeset cs = CS_UNICODE; |
1411 | codeset cs = CS_UNICODE; |
1389 | |
1412 | |
1390 | if (*desc == '[') |
1413 | if (*desc == '[') |
1391 | { |
1414 | { |
… | |
… | |
1501 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1524 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1502 | goto next_font; |
1525 | goto next_font; |
1503 | |
1526 | |
1504 | if (!realize_font (i)) |
1527 | if (!realize_font (i)) |
1505 | goto next_font; |
1528 | goto next_font; |
|
|
1529 | |
|
|
1530 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1531 | max_it (f->ascent, prop.ascent); |
1506 | } |
1532 | } |
1507 | |
1533 | |
1508 | if (f->cs == CS_UNKNOWN) |
1534 | if (f->cs == CS_UNKNOWN) |
1509 | goto next_font; |
1535 | goto next_font; |
1510 | |
1536 | |