1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
… | |
… | |
158 | 0x304c, 0x672c, // が本 |
158 | 0x304c, 0x672c, // が本 |
159 | }; |
159 | }; |
160 | |
160 | |
161 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
161 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
162 | |
162 | |
163 | #define dTermDisplay Display *disp = term->xdisp |
163 | #define dTermDisplay Display *disp = term->dpy |
164 | #define dTermGC GC gc = term->gc |
164 | #define dTermGC GC gc = term->gc |
165 | |
|
|
166 | ///////////////////////////////////////////////////////////////////////////// |
|
|
167 | |
|
|
168 | #if XFT |
|
|
169 | rxvt_drawable::~rxvt_drawable () |
|
|
170 | { |
|
|
171 | if (xftdrawable) |
|
|
172 | XftDrawDestroy (xftdrawable); |
|
|
173 | } |
|
|
174 | |
|
|
175 | rxvt_drawable::operator XftDraw *() |
|
|
176 | { |
|
|
177 | if (!xftdrawable) |
|
|
178 | xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap); |
|
|
179 | |
|
|
180 | return xftdrawable; |
|
|
181 | } |
|
|
182 | #endif |
|
|
183 | |
165 | |
184 | ///////////////////////////////////////////////////////////////////////////// |
166 | ///////////////////////////////////////////////////////////////////////////// |
185 | |
167 | |
186 | static const char * |
168 | static const char * |
187 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
169 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
… | |
… | |
250 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
232 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
251 | { |
233 | { |
252 | dTermDisplay; |
234 | dTermDisplay; |
253 | dTermGC; |
235 | dTermGC; |
254 | |
236 | |
255 | if (color == Color_bg) |
237 | if (color < 0 || color == Color_bg) |
256 | XClearArea (disp, d, x, y, w, h, false); |
238 | XClearArea (disp, d, x, y, w, h, false); |
257 | else if (color >= 0) |
239 | else |
258 | { |
240 | { |
259 | #if XFT |
241 | #if XFT |
260 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
242 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
261 | #else |
243 | #else |
262 | XSetForeground (disp, gc, term->pix_colors[color]); |
244 | XSetForeground (disp, gc, term->pix_colors[color]); |
… | |
… | |
514 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
496 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
515 | { |
497 | { |
516 | unsigned long value; |
498 | unsigned long value; |
517 | |
499 | |
518 | if (XGetFontProperty (f, property, &value)) |
500 | if (XGetFontProperty (f, property, &value)) |
519 | return XGetAtomName (term->xdisp, value); |
501 | return XGetAtomName (term->dpy, value); |
520 | else |
502 | else |
521 | return rxvt_strdup (repl); |
503 | return rxvt_strdup (repl); |
522 | } |
504 | } |
523 | |
505 | |
524 | rxvt_fontprop |
506 | rxvt_fontprop |
… | |
… | |
547 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
529 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
548 | { |
530 | { |
549 | unsigned long height; |
531 | unsigned long height; |
550 | |
532 | |
551 | #if 0 |
533 | #if 0 |
552 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) |
534 | if (!XGetFontProperty (f, XInternAtom (term->dpy, "PIXEL_SIZE", 0), &height)) |
553 | return false; |
535 | return false; |
554 | #else |
536 | #else |
555 | height = f->ascent + f->descent; |
537 | height = f->ascent + f->descent; |
556 | #endif |
538 | #endif |
557 | |
539 | |
… | |
… | |
892 | void |
874 | void |
893 | rxvt_font_x11::clear () |
875 | rxvt_font_x11::clear () |
894 | { |
876 | { |
895 | if (f) |
877 | if (f) |
896 | { |
878 | { |
897 | XFreeFont (term->xdisp, f); |
879 | XFreeFont (term->dpy, f); |
898 | f = 0; |
880 | f = 0; |
899 | } |
881 | } |
900 | } |
882 | } |
901 | |
883 | |
902 | bool |
884 | bool |
… | |
… | |
1074 | void |
1056 | void |
1075 | rxvt_font_xft::clear () |
1057 | rxvt_font_xft::clear () |
1076 | { |
1058 | { |
1077 | if (f) |
1059 | if (f) |
1078 | { |
1060 | { |
1079 | XftFontClose (term->xdisp, f); |
1061 | XftFontClose (term->dpy, f); |
1080 | f = 0; |
1062 | f = 0; |
1081 | } |
1063 | } |
1082 | } |
1064 | } |
1083 | |
1065 | |
1084 | rxvt_fontprop |
1066 | rxvt_fontprop |
… | |
… | |
1251 | bool |
1233 | bool |
1252 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1234 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1253 | { |
1235 | { |
1254 | careful = false; |
1236 | careful = false; |
1255 | |
1237 | |
1256 | if (!XftCharExists (term->xdisp, f, unicode)) |
1238 | if (!XftCharExists (term->dpy, f, unicode)) |
1257 | return false; |
1239 | return false; |
1258 | |
1240 | |
1259 | if (!prop || prop->width == rxvt_fontprop::unset) |
1241 | if (!prop || prop->width == rxvt_fontprop::unset) |
1260 | return true; |
1242 | return true; |
1261 | |
1243 | |
1262 | // check character against base font bounding box |
1244 | // check character against base font bounding box |
1263 | FcChar32 ch = unicode; |
1245 | FcChar32 ch = unicode; |
1264 | XGlyphInfo g; |
1246 | XGlyphInfo g; |
1265 | XftTextExtents32 (term->xdisp, f, &ch, 1, &g); |
1247 | XftTextExtents32 (term->dpy, f, &ch, 1, &g); |
1266 | |
1248 | |
1267 | int w = g.width - g.x; |
1249 | int w = g.width - g.x; |
1268 | int wcw = max (WCWIDTH (unicode), 1); |
1250 | int wcw = max (WCWIDTH (unicode), 1); |
1269 | |
1251 | |
1270 | careful = g.x > 0 || w > prop->width * wcw; |
1252 | careful = g.x > 0 || w > prop->width * wcw; |
… | |
… | |
1282 | void |
1264 | void |
1283 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1265 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1284 | const text_t *text, int len, |
1266 | const text_t *text, int len, |
1285 | int fg, int bg) |
1267 | int fg, int bg) |
1286 | { |
1268 | { |
1287 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
|
|
1288 | |
|
|
1289 | XGlyphInfo extents; |
1269 | XGlyphInfo extents; |
1290 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1270 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1291 | XftGlyphSpec *ep = enc; |
1271 | XftGlyphSpec *ep = enc; |
1292 | |
1272 | |
1293 | dTermDisplay; |
1273 | dTermDisplay; |
1294 | dTermGC; |
1274 | dTermGC; |
1295 | |
1275 | |
|
|
1276 | int w = term->fwidth * len; |
|
|
1277 | int h = term->fheight; |
|
|
1278 | |
|
|
1279 | bool buffered = 0 |
|
|
1280 | #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) |
|
|
1281 | || !term->am_transparent // we aren't transparent |
|
|
1282 | || term->am_pixmap_trans // we have a pixmap |
|
|
1283 | #endif |
|
|
1284 | || bg >= 0; // we don't use a transparent bg |
|
|
1285 | |
1296 | // cut trailing spaces |
1286 | // cut trailing spaces |
1297 | while (len && text [len - 1] == ' ') |
1287 | while (len && text [len - 1] == ' ') |
1298 | len--; |
1288 | len--; |
|
|
1289 | |
|
|
1290 | int x_ = buffered ? 0 : x; |
|
|
1291 | int y_ = buffered ? 0 : y; |
1299 | |
1292 | |
1300 | while (len) |
1293 | while (len) |
1301 | { |
1294 | { |
1302 | int cwidth = term->fwidth; |
1295 | int cwidth = term->fwidth; |
1303 | FcChar32 fc = *text++; len--; |
1296 | FcChar32 fc = *text++; len--; |
… | |
… | |
1308 | if (fc != ' ') // skip spaces |
1301 | if (fc != ' ') // skip spaces |
1309 | { |
1302 | { |
1310 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1303 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1311 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1304 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1312 | |
1305 | |
1313 | |
|
|
1314 | ep->glyph = glyph; |
1306 | ep->glyph = glyph; |
1315 | ep->x = x + (cwidth - extents.xOff >> 1); |
1307 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
1316 | ep->y = y + ascent; |
1308 | ep->y = y_ + ascent; |
1317 | |
1309 | |
1318 | if (extents.xOff == 0) |
1310 | if (extents.xOff == 0) |
1319 | ep->x = x + cwidth; |
1311 | ep->x = x_ + cwidth; |
1320 | |
1312 | |
1321 | ep++; |
1313 | ep++; |
1322 | } |
1314 | } |
1323 | |
1315 | |
1324 | x += cwidth; |
1316 | x_ += cwidth; |
|
|
1317 | } |
|
|
1318 | |
|
|
1319 | if (buffered) |
1325 | } |
1320 | { |
1326 | |
|
|
1327 | if (ep != enc) |
1321 | if (ep != enc) |
|
|
1322 | { |
|
|
1323 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
|
|
1324 | |
|
|
1325 | #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) |
|
|
1326 | if (bg < 0 && term->am_pixmap_trans) |
|
|
1327 | XCopyArea (disp, term->pixmap, d2, gc, x, y, w, h, 0, 0); |
|
|
1328 | else if (bg < 0 && term->bgPixmap.pixmap) |
|
|
1329 | { |
|
|
1330 | XGCValues gcv; |
|
|
1331 | |
|
|
1332 | gcv.fill_style = FillTiled; |
|
|
1333 | gcv.tile = term->pixmap; |
|
|
1334 | gcv.ts_x_origin = -x; |
|
|
1335 | gcv.ts_y_origin = -y; |
|
|
1336 | |
|
|
1337 | GC gc2 = XCreateGC (disp, d2, |
|
|
1338 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
|
|
1339 | &gcv); |
|
|
1340 | |
|
|
1341 | XFillRectangle (disp, d2, gc2, 0, 0, w, h); |
|
|
1342 | |
|
|
1343 | XFreeGC (disp, gc2); |
|
|
1344 | } |
|
|
1345 | else |
|
|
1346 | #endif |
|
|
1347 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
|
|
1348 | |
|
|
1349 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1350 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
|
|
1351 | } |
|
|
1352 | else |
|
|
1353 | clear_rect (d, x, y, w, h, bg); |
|
|
1354 | } |
|
|
1355 | else |
|
|
1356 | { |
|
|
1357 | clear_rect (d, x, y, w, h, bg); |
1328 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1358 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1359 | } |
1329 | } |
1360 | } |
|
|
1361 | |
1330 | #endif |
1362 | #endif |
1331 | |
1363 | |
1332 | ///////////////////////////////////////////////////////////////////////////// |
1364 | ///////////////////////////////////////////////////////////////////////////// |
1333 | |
1365 | |
1334 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1366 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
… | |
… | |
1577 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1609 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1578 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1610 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1579 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1611 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1580 | |
1612 | |
1581 | XftResult result; |
1613 | XftResult result; |
1582 | FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); |
1614 | FcPattern *match = XftFontMatch (term->dpy, term->display->screen, p, &result); |
1583 | |
1615 | |
1584 | FcPatternDestroy (p); |
1616 | FcPatternDestroy (p); |
1585 | |
1617 | |
1586 | if (match) |
1618 | if (match) |
1587 | { |
1619 | { |