1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: rxvtfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
9 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
|
|
24 | #include "rxvtlib.h" |
24 | #include "rxvtutil.h" |
25 | #include "rxvtutil.h" |
25 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
26 | |
27 | |
27 | #include <cstdlib> |
28 | #include <cstdlib> |
28 | #include <wchar.h> |
29 | #include <wchar.h> |
… | |
… | |
276 | rxvt_fontprop properties () |
277 | rxvt_fontprop properties () |
277 | { |
278 | { |
278 | rxvt_fontprop p; |
279 | rxvt_fontprop p; |
279 | |
280 | |
280 | p.width = p.height = 1; |
281 | p.width = p.height = 1; |
|
|
282 | p.ascent = rxvt_fontprop::unset; |
281 | p.weight = rxvt_fontprop::medium; |
283 | p.weight = rxvt_fontprop::medium; |
282 | p.slant = rxvt_fontprop::roman; |
284 | p.slant = rxvt_fontprop::roman; |
283 | |
285 | |
284 | return p; |
286 | return p; |
285 | } |
287 | } |
… | |
… | |
305 | return false; |
307 | return false; |
306 | |
308 | |
307 | if (unicode <= 0x009f) |
309 | if (unicode <= 0x009f) |
308 | return true; |
310 | return true; |
309 | |
311 | |
310 | if (unicode >= 0x2500 && unicode <= 0x259f) |
312 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
313 | !r->option (Opt_skipBuiltinGlyphs)) |
311 | return true; |
314 | return true; |
312 | |
315 | |
313 | if (IS_COMPOSE (unicode)) |
316 | if (IS_COMPOSE (unicode)) |
314 | return true; |
317 | return true; |
315 | |
318 | |
… | |
… | |
523 | bool |
526 | bool |
524 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
527 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
525 | { |
528 | { |
526 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
529 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
527 | p.height = height; |
530 | p.height = height; |
|
|
531 | p.ascent = rxvt_fontprop::unset; |
528 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
532 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
529 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
533 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
530 | |
534 | |
531 | return true; |
535 | return true; |
532 | } |
536 | } |
… | |
… | |
552 | |
556 | |
553 | set_properties (p, height, weight, slant, avgwidth); |
557 | set_properties (p, height, weight, slant, avgwidth); |
554 | |
558 | |
555 | free (weight); |
559 | free (weight); |
556 | free (slant); |
560 | free (slant); |
|
|
561 | |
|
|
562 | p.ascent = f->ascent; |
557 | |
563 | |
558 | return true; |
564 | return true; |
559 | } |
565 | } |
560 | |
566 | |
561 | bool |
567 | bool |
… | |
… | |
1073 | |
1079 | |
1074 | FT_Face face = XftLockFace (f); |
1080 | FT_Face face = XftLockFace (f); |
1075 | |
1081 | |
1076 | p.width = width; |
1082 | p.width = width; |
1077 | p.height = height; |
1083 | p.height = height; |
|
|
1084 | p.ascent = ascent; |
1078 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1085 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1079 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1086 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1080 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1087 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1081 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1088 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1082 | |
1089 | |
… | |
… | |
1262 | void |
1269 | void |
1263 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1270 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1264 | const text_t *text, int len, |
1271 | const text_t *text, int len, |
1265 | int fg, int bg) |
1272 | int fg, int bg) |
1266 | { |
1273 | { |
|
|
1274 | XGlyphInfo extents; |
|
|
1275 | XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); |
|
|
1276 | XftGlyphSpec *ep = enc; |
|
|
1277 | |
1267 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1278 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1268 | |
1279 | |
1269 | int base = ascent; // should be fbase, but that is incorrect |
1280 | // cut trailing spaces |
1270 | |
1281 | while (len && text [len - 1] == ' ') |
1271 | XGlyphInfo extents; |
1282 | len--; |
1272 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
|
|
1273 | FcChar32 *ep = enc; |
|
|
1274 | int ewidth = 0; |
|
|
1275 | |
1283 | |
1276 | while (len) |
1284 | while (len) |
1277 | { |
1285 | { |
1278 | int cwidth = r->fwidth; |
1286 | int cwidth = r->fwidth; |
1279 | FcChar32 fc = *text++; len--; |
1287 | FcChar32 fc = *text++; len--; |
1280 | |
1288 | |
1281 | while (len && *text == NOCHAR) |
1289 | while (len && *text == NOCHAR) |
1282 | text++, len--, cwidth += r->fwidth; |
1290 | text++, len--, cwidth += r->fwidth; |
1283 | |
1291 | |
1284 | if (fc == ' ' && ep == enc) // skip leading spaces |
1292 | if (fc != ' ') // skip spaces |
1285 | x += cwidth; |
|
|
1286 | else |
|
|
1287 | { |
1293 | { |
1288 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
1294 | FT_UInt glyph = XftCharIndex (d.display->display, f, fc); |
1289 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
1295 | XftGlyphExtents (d.display->display, f, &glyph, 1, &extents); |
1290 | |
1296 | |
1291 | if (extents.xOff != cwidth) |
1297 | ep->glyph = glyph; |
1292 | { |
1298 | ep->x = x + (cwidth - extents.xOff >> 1); |
1293 | if (ewidth) |
1299 | ep->y = y + ascent; |
1294 | { |
1300 | ep++; |
1295 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1296 | x, y + base, enc, ep - enc); |
|
|
1297 | x += ewidth; |
|
|
1298 | |
|
|
1299 | ep = enc; |
|
|
1300 | ewidth = 0; |
|
|
1301 | } |
|
|
1302 | |
|
|
1303 | if (extents.xOff > cwidth) |
|
|
1304 | extents.xOff = cwidth; |
|
|
1305 | |
|
|
1306 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1307 | x + (cwidth - extents.xOff >> 1), |
|
|
1308 | y + base, &gl, 1); |
|
|
1309 | x += cwidth; |
|
|
1310 | } |
1301 | } |
1311 | else |
1302 | |
1312 | { |
1303 | x += cwidth; |
1313 | *ep++ = gl; |
|
|
1314 | ewidth += cwidth; |
|
|
1315 | } |
|
|
1316 | } |
|
|
1317 | } |
1304 | } |
1318 | |
1305 | |
1319 | if (ep != enc) |
1306 | if (ep != enc) |
1320 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1307 | XftDrawGlyphSpec (d, &r->pix_colors[fg].c, f, enc, ep - enc); |
1321 | x, y + base, enc, ep - enc); |
|
|
1322 | } |
1308 | } |
1323 | #endif |
1309 | #endif |
1324 | |
1310 | |
1325 | ///////////////////////////////////////////////////////////////////////////// |
1311 | ///////////////////////////////////////////////////////////////////////////// |
1326 | |
1312 | |
… | |
… | |
1336 | } |
1322 | } |
1337 | |
1323 | |
1338 | void |
1324 | void |
1339 | rxvt_fontset::clear () |
1325 | rxvt_fontset::clear () |
1340 | { |
1326 | { |
1341 | prop.width = prop.height = prop.weight = prop.slant |
1327 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1342 | = rxvt_fontprop::unset; |
1328 | = rxvt_fontprop::unset; |
1343 | |
1329 | |
1344 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1330 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1345 | FONT_UNREF (*i); |
1331 | FONT_UNREF (*i); |
1346 | |
1332 | |
… | |
… | |
1519 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1505 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1520 | goto next_font; |
1506 | goto next_font; |
1521 | |
1507 | |
1522 | if (!realize_font (i)) |
1508 | if (!realize_font (i)) |
1523 | goto next_font; |
1509 | goto next_font; |
|
|
1510 | |
|
|
1511 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1512 | max_it (f->ascent, prop.ascent); |
1524 | } |
1513 | } |
1525 | |
1514 | |
1526 | if (f->cs == CS_UNKNOWN) |
1515 | if (f->cs == CS_UNKNOWN) |
1527 | goto next_font; |
1516 | goto next_font; |
1528 | |
1517 | |