… | |
… | |
27 | |
27 | |
28 | #include <cstdlib> |
28 | #include <cstdlib> |
29 | #include <wchar.h> |
29 | #include <wchar.h> |
30 | #include <inttypes.h> |
30 | #include <inttypes.h> |
31 | |
31 | |
32 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
32 | #define MAX_OVERLAP_ROMAN (8 + 2) // max. character width in 8ths of the base width |
|
|
33 | #define MAX_OVERLAP_ITALIC (8 + 3) // max. overlap for italic fonts |
|
|
34 | |
|
|
35 | #define OVERLAP_OK(w,prop) (w) > ( \ |
|
|
36 | prop->slant >= rxvt_fontprop::italic \ |
|
|
37 | ? (prop->width * MAX_OVERLAP_ITALIC + 7) >> 3 \ |
|
|
38 | : (prop->width * MAX_OVERLAP_ROMAN + 7) >> 3 \ |
|
|
39 | ) |
33 | |
40 | |
34 | const struct rxvt_fallback_font { |
41 | const struct rxvt_fallback_font { |
35 | codeset cs; |
42 | codeset cs; |
36 | const char *name; |
43 | const char *name; |
37 | } fallback_fonts[] = { |
44 | } fallback_fonts[] = { |
… | |
… | |
848 | |
855 | |
849 | XCharStruct g; |
856 | XCharStruct g; |
850 | int dir_ret, asc_ret, des_ret; |
857 | int dir_ret, asc_ret, des_ret; |
851 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
858 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
852 | |
859 | |
853 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
860 | int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
854 | |
861 | |
855 | if (width < g.width) width = g.width; |
862 | if (width < g.width) width = g.width; |
856 | } |
863 | } |
857 | |
864 | |
858 | if (cs == CS_UNKNOWN) |
865 | if (cs == CS_UNKNOWN) |
… | |
… | |
931 | |
938 | |
932 | if (!prop || prop->width == rxvt_fontprop::unset) |
939 | if (!prop || prop->width == rxvt_fontprop::unset) |
933 | return true; |
940 | return true; |
934 | |
941 | |
935 | // check character against base font bounding box |
942 | // check character against base font bounding box |
936 | int w = xcs->width; |
943 | int w = xcs->rbearing - xcs->lbearing; |
937 | int wcw = wcwidth (unicode); |
944 | int wcw = WCWIDTH (unicode); |
938 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
945 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
939 | |
946 | |
940 | careful = w > prop->width; |
947 | careful = w > prop->width; |
941 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
948 | if (careful && OVERLAP_OK (w, prop)) |
942 | return false; |
949 | return false; |
943 | |
950 | |
944 | return true; |
951 | return true; |
945 | } |
952 | } |
946 | |
953 | |
… | |
… | |
1176 | XGlyphInfo g; |
1183 | XGlyphInfo g; |
1177 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1184 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1178 | |
1185 | |
1179 | g.width -= g.x; |
1186 | g.width -= g.x; |
1180 | |
1187 | |
1181 | int wcw = wcwidth (ch); |
1188 | int wcw = WCWIDTH (ch); |
1182 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1189 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1183 | |
1190 | |
1184 | if (width < g.width ) width = g.width; |
1191 | if (width < g.width ) width = g.width; |
1185 | if (height < g.height ) height = g.height; |
1192 | if (height < g.height ) height = g.height; |
1186 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1193 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
… | |
… | |
1248 | FcChar32 ch = unicode; |
1255 | FcChar32 ch = unicode; |
1249 | XGlyphInfo g; |
1256 | XGlyphInfo g; |
1250 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1257 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1251 | |
1258 | |
1252 | int w = g.width - g.x; |
1259 | int w = g.width - g.x; |
1253 | int wcw = wcwidth (unicode); |
1260 | int wcw = WCWIDTH (unicode); |
1254 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1261 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1255 | |
1262 | |
1256 | careful = w > prop->width; |
1263 | careful = w > prop->width; |
1257 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1264 | if (careful && OVERLAP_OK (w, prop)) |
1258 | return false; |
1265 | return false; |
1259 | |
1266 | |
1260 | return true; |
1267 | return true; |
1261 | } |
1268 | } |
1262 | |
1269 | |