… | |
… | |
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; |
… | |
… | |
333 | const text_t *text, int len, |
333 | const text_t *text, int len, |
334 | int fg, int bg) |
334 | int fg, int bg) |
335 | { |
335 | { |
336 | Display *disp = d.display->display; |
336 | Display *disp = d.display->display; |
337 | |
337 | |
338 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
338 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
339 | |
339 | |
340 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
340 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
341 | |
341 | |
342 | while (len) |
342 | while (len) |
343 | { |
343 | { |
… | |
… | |
349 | |
349 | |
350 | while (++text, --len && *text == NOCHAR) |
350 | while (++text, --len && *text == NOCHAR) |
351 | ; |
351 | ; |
352 | |
352 | |
353 | int width = text - tp; |
353 | int width = text - tp; |
354 | int fwidth = r->TermWin.fwidth * width; |
354 | int fwidth = r->fwidth * width; |
355 | |
355 | |
356 | if (0x2500 <= t && t <= 0x259f) |
356 | if (0x2500 <= t && t <= 0x259f) |
357 | { |
357 | { |
358 | uint16_t offs = linedraw_offs[t - 0x2500]; |
358 | uint16_t offs = linedraw_offs[t - 0x2500]; |
359 | uint32_t *a = linedraw_command + (offs >> 4); |
359 | uint32_t *a = linedraw_command + (offs >> 4); |
360 | uint32_t *b = a + (offs & 15); |
360 | uint32_t *b = a + (offs & 15); |
361 | |
361 | |
362 | int W = fwidth; |
362 | int W = fwidth; |
363 | int H = r->TermWin.fheight; |
363 | int H = r->fheight; |
364 | |
364 | |
365 | int x_[16]; |
365 | int x_[16]; |
366 | int y_[16]; |
366 | int y_[16]; |
367 | |
367 | |
368 | for (int i = 0; i <= 8; i++) |
368 | for (int i = 0; i <= 8; i++) |
… | |
… | |
464 | case NOCHAR: |
464 | case NOCHAR: |
465 | break; |
465 | break; |
466 | |
466 | |
467 | default: |
467 | default: |
468 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
468 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
469 | fwidth - 4, r->TermWin.fheight - 4); |
469 | fwidth - 4, r->fheight - 4); |
470 | } |
470 | } |
471 | |
471 | |
472 | x += fwidth; |
472 | x += fwidth; |
473 | } |
473 | } |
474 | } |
474 | } |
… | |
… | |
956 | // and it is a mess /. |
956 | // and it is a mess /. |
957 | // yet we are trying to be perfect /. |
957 | // yet we are trying to be perfect /. |
958 | // but the result still isn't perfect /. |
958 | // but the result still isn't perfect /. |
959 | |
959 | |
960 | bool slow = this->slow |
960 | bool slow = this->slow |
961 | || width != r->TermWin.fwidth |
961 | || width != r->fwidth |
962 | || height != r->TermWin.fheight; |
962 | || height != r->fheight; |
963 | |
963 | |
964 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
964 | int base = ascent; // sorry, incorrect: r->fbase; |
965 | |
965 | |
966 | XGCValues v; |
966 | XGCValues v; |
967 | v.foreground = r->pix_colors[fg]; |
967 | v.foreground = r->pix_colors[fg]; |
968 | v.font = f->fid; |
968 | v.font = f->fid; |
969 | |
969 | |
… | |
… | |
977 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
977 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
978 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
978 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
979 | } |
979 | } |
980 | else |
980 | else |
981 | { |
981 | { |
982 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
982 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
983 | |
983 | |
984 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
984 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
985 | |
985 | |
986 | if (slow) |
986 | if (slow) |
987 | { |
987 | { |
988 | do |
988 | do |
989 | { |
989 | { |
990 | if (xc->byte1 || xc->byte2) |
990 | if (xc->byte1 || xc->byte2) |
991 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
991 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
992 | |
992 | |
993 | x += r->TermWin.fwidth; |
993 | x += r->fwidth; |
994 | xc++; len--; |
994 | xc++; len--; |
995 | } |
995 | } |
996 | while (len); |
996 | while (len); |
997 | } |
997 | } |
998 | else |
998 | else |
… | |
… | |
1009 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1009 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1010 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1010 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1011 | } |
1011 | } |
1012 | else |
1012 | else |
1013 | { |
1013 | { |
1014 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1014 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1015 | |
1015 | |
1016 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1016 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1017 | |
1017 | |
1018 | if (slow) |
1018 | if (slow) |
1019 | { |
1019 | { |
1020 | do |
1020 | do |
1021 | { |
1021 | { |
1022 | if (*xc) |
1022 | if (*xc) |
1023 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1023 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1024 | |
1024 | |
1025 | x += r->TermWin.fwidth; |
1025 | x += r->fwidth; |
1026 | xc++; len--; |
1026 | xc++; len--; |
1027 | } |
1027 | } |
1028 | while (len); |
1028 | while (len); |
1029 | } |
1029 | } |
1030 | else |
1030 | else |
… | |
… | |
1183 | if (width < g.width ) width = g.width; |
1183 | if (width < g.width ) width = g.width; |
1184 | if (height < g.height ) height = g.height; |
1184 | if (height < g.height ) height = g.height; |
1185 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1185 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1186 | } |
1186 | } |
1187 | |
1187 | |
|
|
1188 | if (!width) |
|
|
1189 | { |
|
|
1190 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1191 | |
|
|
1192 | XftFontClose (disp, f); |
|
|
1193 | f = 0; |
|
|
1194 | |
|
|
1195 | success = false; |
|
|
1196 | break; |
|
|
1197 | } |
|
|
1198 | |
1188 | if (prop.height == rxvt_fontprop::unset |
1199 | if (prop.height == rxvt_fontprop::unset |
1189 | || (height <= prop.height && glheight <= prop.height) |
1200 | || (height <= prop.height && glheight <= prop.height) |
1190 | || height <= 2 |
1201 | || height <= 2 |
1191 | || !scalable) |
1202 | || !scalable) |
1192 | break; |
1203 | break; |
… | |
… | |
1201 | ftheight -= height - prop.height; |
1212 | ftheight -= height - prop.height; |
1202 | } |
1213 | } |
1203 | else |
1214 | else |
1204 | ftheight = prop.height - 1; |
1215 | ftheight = prop.height - 1; |
1205 | |
1216 | |
1206 | XftFontClose (disp, f); |
1217 | XftFontClose (disp, f); |
1207 | FcPatternDel (match, FC_PIXEL_SIZE); |
1218 | FcPatternDel (match, FC_PIXEL_SIZE); |
1208 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1219 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1209 | } |
1220 | } |
1210 | |
1221 | |
1211 | FcPatternDestroy (match); |
1222 | FcPatternDestroy (match); |
1212 | |
1223 | |
1213 | #if 0 // do it per-character |
1224 | #if 0 // do it per-character |
… | |
… | |
1251 | void |
1262 | void |
1252 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1263 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1253 | const text_t *text, int len, |
1264 | const text_t *text, int len, |
1254 | int fg, int bg) |
1265 | int fg, int bg) |
1255 | { |
1266 | { |
1256 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1267 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1257 | |
1268 | |
1258 | int base = ascent; // should be fbase, but that is incorrect |
1269 | int base = ascent; // should be fbase, but that is incorrect |
1259 | |
1270 | |
1260 | XGlyphInfo extents; |
1271 | XGlyphInfo extents; |
1261 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1272 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1262 | FcChar32 *ep = enc; |
1273 | FcChar32 *ep = enc; |
1263 | int ewidth = 0; |
1274 | int ewidth = 0; |
1264 | |
1275 | |
1265 | while (len) |
1276 | while (len) |
1266 | { |
1277 | { |
1267 | int cwidth = r->TermWin.fwidth; |
1278 | int cwidth = r->fwidth; |
1268 | FcChar32 fc = *text++; len--; |
1279 | FcChar32 fc = *text++; len--; |
1269 | |
1280 | |
1270 | while (len && *text == NOCHAR) |
1281 | while (len && *text == NOCHAR) |
1271 | text++, len--, cwidth += r->TermWin.fwidth; |
1282 | text++, len--, cwidth += r->fwidth; |
1272 | |
1283 | |
1273 | if (fc == ' ' && ep == enc) // skip leading spaces |
1284 | if (fc == ' ' && ep == enc) // skip leading spaces |
1274 | x += cwidth; |
1285 | x += cwidth; |
1275 | else |
1286 | else |
1276 | { |
1287 | { |