… | |
… | |
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 | |
176 | ///////////////////////////////////////////////////////////////////////////// |
183 | ///////////////////////////////////////////////////////////////////////////// |
177 | |
|
|
178 | static void *enc_buf; |
|
|
179 | static uint32_t enc_len; |
|
|
180 | |
|
|
181 | static inline void * |
|
|
182 | get_enc_buf (uint32_t len) |
|
|
183 | { |
|
|
184 | if (len > enc_len) |
|
|
185 | { |
|
|
186 | free (enc_buf); |
|
|
187 | enc_buf = malloc (len); |
|
|
188 | enc_len = len; |
|
|
189 | } |
|
|
190 | |
|
|
191 | return enc_buf; |
|
|
192 | } |
|
|
193 | |
184 | |
194 | static const char * |
185 | static const char * |
195 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
186 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
196 | { |
187 | { |
197 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
188 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
189 | uint8_t *res = buf; |
198 | |
190 | |
199 | while (len--) |
191 | while (len--) |
200 | { |
192 | { |
201 | uint32_t c = FROM_UNICODE (cs, *text++); |
193 | uint32_t c = FROM_UNICODE (cs, *text++); |
202 | |
194 | |
… | |
… | |
207 | } |
199 | } |
208 | |
200 | |
209 | *buf++ = c; |
201 | *buf++ = c; |
210 | } |
202 | } |
211 | |
203 | |
212 | return (const char *)enc_buf; |
204 | return (const char *)res; |
213 | } |
205 | } |
214 | |
206 | |
215 | static const XChar2b * |
207 | static const XChar2b * |
216 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
208 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
217 | { |
209 | { |
218 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
210 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
211 | XChar2b *res = buf; |
219 | |
212 | |
220 | while (len--) |
213 | while (len--) |
221 | { |
214 | { |
222 | uint32_t c = FROM_UNICODE (cs, *text++); |
215 | uint32_t c = FROM_UNICODE (cs, *text++); |
223 | |
216 | |
… | |
… | |
230 | buf->byte1 = c >> 8; |
223 | buf->byte1 = c >> 8; |
231 | buf->byte2 = c; |
224 | buf->byte2 = c; |
232 | buf++; |
225 | buf++; |
233 | } |
226 | } |
234 | |
227 | |
235 | return (XChar2b *)enc_buf; |
228 | return res; |
236 | } |
229 | } |
237 | |
230 | |
238 | ///////////////////////////////////////////////////////////////////////////// |
231 | ///////////////////////////////////////////////////////////////////////////// |
239 | |
232 | |
240 | void |
233 | void |
… | |
… | |
511 | char * |
504 | char * |
512 | 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 |
513 | { |
506 | { |
514 | unsigned long value; |
507 | unsigned long value; |
515 | |
508 | |
516 | if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value)) |
509 | if (XGetFontProperty (f, XInternAtom (term->xdisp, property, 0), &value)) |
517 | return XGetAtomName (term->display->display, value); |
510 | return XGetAtomName (term->xdisp, value); |
518 | else |
511 | else |
519 | return rxvt_strdup (repl); |
512 | return rxvt_strdup (repl); |
520 | } |
513 | } |
521 | |
514 | |
522 | rxvt_fontprop |
515 | rxvt_fontprop |
… | |
… | |
543 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
536 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
544 | { |
537 | { |
545 | unsigned long height; |
538 | unsigned long height; |
546 | |
539 | |
547 | #if 0 |
540 | #if 0 |
548 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height)) |
541 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) |
549 | return false; |
542 | return false; |
550 | #else |
543 | #else |
551 | height = f->ascent + f->descent; |
544 | height = f->ascent + f->descent; |
552 | #endif |
545 | #endif |
553 | |
546 | |
554 | unsigned long avgwidth; |
547 | unsigned long avgwidth; |
555 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth)) |
548 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "AVERAGE_WIDTH", 0), &avgwidth)) |
556 | avgwidth = 0; |
549 | avgwidth = 0; |
557 | |
550 | |
558 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
551 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
559 | char *slant = get_property (f, "SLANT", "r"); |
552 | char *slant = get_property (f, "SLANT", "r"); |
560 | |
553 | |
… | |
… | |
862 | |
855 | |
863 | XCharStruct g; |
856 | XCharStruct g; |
864 | int dir_ret, asc_ret, des_ret; |
857 | int dir_ret, asc_ret, des_ret; |
865 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
858 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
866 | |
859 | |
867 | 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; |
868 | |
861 | |
869 | if (width < g.width) width = g.width; |
862 | if (width < g.width) width = g.width; |
870 | } |
863 | } |
871 | |
864 | |
872 | if (cs == CS_UNKNOWN) |
865 | if (cs == CS_UNKNOWN) |
… | |
… | |
891 | void |
884 | void |
892 | rxvt_font_x11::clear () |
885 | rxvt_font_x11::clear () |
893 | { |
886 | { |
894 | if (f) |
887 | if (f) |
895 | { |
888 | { |
896 | XFreeFont (term->display->display, f); |
889 | XFreeFont (term->xdisp, f); |
897 | f = 0; |
890 | f = 0; |
898 | } |
891 | } |
899 | } |
892 | } |
900 | |
893 | |
901 | bool |
894 | bool |
… | |
… | |
945 | |
938 | |
946 | if (!prop || prop->width == rxvt_fontprop::unset) |
939 | if (!prop || prop->width == rxvt_fontprop::unset) |
947 | return true; |
940 | return true; |
948 | |
941 | |
949 | // check character against base font bounding box |
942 | // check character against base font bounding box |
950 | int w = xcs->width; |
943 | int w = xcs->rbearing - xcs->lbearing; |
951 | int wcw = wcwidth (unicode); |
944 | int wcw = WCWIDTH (unicode); |
952 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
945 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
953 | |
946 | |
954 | careful = w > prop->width; |
947 | careful = w > prop->width; |
955 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
948 | if (careful && OVERLAP_OK (w, prop)) |
956 | return false; |
949 | return false; |
957 | |
950 | |
958 | return true; |
951 | return true; |
959 | } |
952 | } |
960 | |
953 | |
… | |
… | |
1073 | void |
1066 | void |
1074 | rxvt_font_xft::clear () |
1067 | rxvt_font_xft::clear () |
1075 | { |
1068 | { |
1076 | if (f) |
1069 | if (f) |
1077 | { |
1070 | { |
1078 | XftFontClose (term->display->display, f); |
1071 | XftFontClose (term->xdisp, f); |
1079 | f = 0; |
1072 | f = 0; |
1080 | } |
1073 | } |
1081 | } |
1074 | } |
1082 | |
1075 | |
1083 | rxvt_fontprop |
1076 | rxvt_fontprop |
… | |
… | |
1190 | XGlyphInfo g; |
1183 | XGlyphInfo g; |
1191 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1184 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1192 | |
1185 | |
1193 | g.width -= g.x; |
1186 | g.width -= g.x; |
1194 | |
1187 | |
1195 | int wcw = wcwidth (ch); |
1188 | int wcw = WCWIDTH (ch); |
1196 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1189 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1197 | |
1190 | |
1198 | if (width < g.width ) width = g.width; |
1191 | if (width < g.width ) width = g.width; |
1199 | if (height < g.height ) height = g.height; |
1192 | if (height < g.height ) height = g.height; |
1200 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1193 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
… | |
… | |
1250 | bool |
1243 | bool |
1251 | 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 |
1252 | { |
1245 | { |
1253 | careful = false; |
1246 | careful = false; |
1254 | |
1247 | |
1255 | if (!XftCharExists (term->display->display, f, unicode)) |
1248 | if (!XftCharExists (term->xdisp, f, unicode)) |
1256 | return false; |
1249 | return false; |
1257 | |
1250 | |
1258 | if (!prop || prop->width == rxvt_fontprop::unset) |
1251 | if (!prop || prop->width == rxvt_fontprop::unset) |
1259 | return true; |
1252 | return true; |
1260 | |
1253 | |
1261 | // check character against base font bounding box |
1254 | // check character against base font bounding box |
1262 | FcChar32 ch = unicode; |
1255 | FcChar32 ch = unicode; |
1263 | XGlyphInfo g; |
1256 | XGlyphInfo g; |
1264 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1257 | XftTextExtents32 (term->xdisp, f, &ch, 1, &g); |
1265 | |
1258 | |
1266 | int w = g.width - g.x; |
1259 | int w = g.width - g.x; |
1267 | int wcw = wcwidth (unicode); |
1260 | int wcw = WCWIDTH (unicode); |
1268 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1261 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1269 | |
1262 | |
1270 | careful = w > prop->width; |
1263 | careful = w > prop->width; |
1271 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1264 | if (careful && OVERLAP_OK (w, prop)) |
1272 | return false; |
1265 | return false; |
1273 | |
1266 | |
1274 | return true; |
1267 | return true; |
1275 | } |
1268 | } |
1276 | |
1269 | |
… | |
… | |
1280 | int fg, int bg) |
1273 | int fg, int bg) |
1281 | { |
1274 | { |
1282 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1275 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1283 | |
1276 | |
1284 | XGlyphInfo extents; |
1277 | XGlyphInfo extents; |
1285 | XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); |
1278 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1286 | XftGlyphSpec *ep = enc; |
1279 | XftGlyphSpec *ep = enc; |
1287 | |
1280 | |
1288 | dTermDisplay; |
1281 | dTermDisplay; |
1289 | dTermGC; |
1282 | dTermGC; |
1290 | |
1283 | |
… | |
… | |
1567 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1560 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1568 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1561 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1569 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1562 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1570 | |
1563 | |
1571 | XftResult result; |
1564 | XftResult result; |
1572 | FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result); |
1565 | FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); |
1573 | |
1566 | |
1574 | FcPatternDestroy (p); |
1567 | FcPatternDestroy (p); |
1575 | |
1568 | |
1576 | if (match) |
1569 | if (match) |
1577 | { |
1570 | { |