… | |
… | |
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[] = { |
… | |
… | |
150 | 0x304c, 0x672c, // が本 |
157 | 0x304c, 0x672c, // が本 |
151 | }; |
158 | }; |
152 | |
159 | |
153 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
160 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
154 | |
161 | |
155 | #define dTermDisplay Display *disp = term->display->display |
162 | #define dTermDisplay Display *disp = term->xdisp |
156 | #define dTermGC GC gc = term->gc |
163 | #define dTermGC GC gc = term->gc |
157 | |
164 | |
158 | ///////////////////////////////////////////////////////////////////////////// |
165 | ///////////////////////////////////////////////////////////////////////////// |
159 | |
166 | |
160 | #if XFT |
167 | #if XFT |
… | |
… | |
165 | } |
172 | } |
166 | |
173 | |
167 | rxvt_drawable::operator XftDraw *() |
174 | rxvt_drawable::operator XftDraw *() |
168 | { |
175 | { |
169 | if (!xftdrawable) |
176 | if (!xftdrawable) |
170 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
177 | xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap); |
171 | |
178 | |
172 | return xftdrawable; |
179 | return xftdrawable; |
173 | } |
180 | } |
174 | #endif |
181 | #endif |
175 | |
182 | |
… | |
… | |
497 | char * |
504 | char * |
498 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
505 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
499 | { |
506 | { |
500 | unsigned long value; |
507 | unsigned long value; |
501 | |
508 | |
502 | if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value)) |
509 | if (XGetFontProperty (f, XInternAtom (term->xdisp, property, 0), &value)) |
503 | return XGetAtomName (term->display->display, value); |
510 | return XGetAtomName (term->xdisp, value); |
504 | else |
511 | else |
505 | return rxvt_strdup (repl); |
512 | return rxvt_strdup (repl); |
506 | } |
513 | } |
507 | |
514 | |
508 | rxvt_fontprop |
515 | rxvt_fontprop |
… | |
… | |
529 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
536 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
530 | { |
537 | { |
531 | unsigned long height; |
538 | unsigned long height; |
532 | |
539 | |
533 | #if 0 |
540 | #if 0 |
534 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height)) |
541 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) |
535 | return false; |
542 | return false; |
536 | #else |
543 | #else |
537 | height = f->ascent + f->descent; |
544 | height = f->ascent + f->descent; |
538 | #endif |
545 | #endif |
539 | |
546 | |
540 | unsigned long avgwidth; |
547 | unsigned long avgwidth; |
541 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth)) |
548 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "AVERAGE_WIDTH", 0), &avgwidth)) |
542 | avgwidth = 0; |
549 | avgwidth = 0; |
543 | |
550 | |
544 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
551 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
545 | char *slant = get_property (f, "SLANT", "r"); |
552 | char *slant = get_property (f, "SLANT", "r"); |
546 | |
553 | |
… | |
… | |
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) |
… | |
… | |
877 | void |
884 | void |
878 | rxvt_font_x11::clear () |
885 | rxvt_font_x11::clear () |
879 | { |
886 | { |
880 | if (f) |
887 | if (f) |
881 | { |
888 | { |
882 | XFreeFont (term->display->display, f); |
889 | XFreeFont (term->xdisp, f); |
883 | f = 0; |
890 | f = 0; |
884 | } |
891 | } |
885 | } |
892 | } |
886 | |
893 | |
887 | bool |
894 | bool |
… | |
… | |
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 | |
… | |
… | |
1059 | void |
1066 | void |
1060 | rxvt_font_xft::clear () |
1067 | rxvt_font_xft::clear () |
1061 | { |
1068 | { |
1062 | if (f) |
1069 | if (f) |
1063 | { |
1070 | { |
1064 | XftFontClose (term->display->display, f); |
1071 | XftFontClose (term->xdisp, f); |
1065 | f = 0; |
1072 | f = 0; |
1066 | } |
1073 | } |
1067 | } |
1074 | } |
1068 | |
1075 | |
1069 | rxvt_fontprop |
1076 | rxvt_fontprop |
… | |
… | |
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; |
… | |
… | |
1236 | bool |
1243 | bool |
1237 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1244 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1238 | { |
1245 | { |
1239 | careful = false; |
1246 | careful = false; |
1240 | |
1247 | |
1241 | if (!XftCharExists (term->display->display, f, unicode)) |
1248 | if (!XftCharExists (term->xdisp, f, unicode)) |
1242 | return false; |
1249 | return false; |
1243 | |
1250 | |
1244 | if (!prop || prop->width == rxvt_fontprop::unset) |
1251 | if (!prop || prop->width == rxvt_fontprop::unset) |
1245 | return true; |
1252 | return true; |
1246 | |
1253 | |
1247 | // check character against base font bounding box |
1254 | // check character against base font bounding box |
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->xdisp, 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 | |
… | |
… | |
1553 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1560 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1554 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1561 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1555 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1562 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1556 | |
1563 | |
1557 | XftResult result; |
1564 | XftResult result; |
1558 | FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result); |
1565 | FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); |
1559 | |
1566 | |
1560 | FcPatternDestroy (p); |
1567 | FcPatternDestroy (p); |
1561 | |
1568 | |
1562 | if (match) |
1569 | if (match) |
1563 | { |
1570 | { |