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 | * |
… | |
… | |
163 | #define dTermDisplay Display *disp = term->dpy |
163 | #define dTermDisplay Display *disp = term->dpy |
164 | #define dTermGC GC gc = term->gc |
164 | #define dTermGC GC gc = term->gc |
165 | |
165 | |
166 | ///////////////////////////////////////////////////////////////////////////// |
166 | ///////////////////////////////////////////////////////////////////////////// |
167 | |
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->dpy, drawable, screen->visual, screen->cmap); |
|
|
179 | |
|
|
180 | return xftdrawable; |
|
|
181 | } |
|
|
182 | #endif |
|
|
183 | |
|
|
184 | ///////////////////////////////////////////////////////////////////////////// |
|
|
185 | |
|
|
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) |
188 | { |
170 | { |
189 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
171 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
190 | uint8_t *res = buf; |
172 | uint8_t *res = buf; |
… | |
… | |
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 == Color_bg || color == Color_transparent) |
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 if (color >= 0) |
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); |
… | |
… | |
288 | p.slant = rxvt_fontprop::roman; |
270 | p.slant = rxvt_fontprop::roman; |
289 | |
271 | |
290 | return p; |
272 | return p; |
291 | } |
273 | } |
292 | |
274 | |
293 | bool load (const rxvt_fontprop &prop) |
275 | bool load (const rxvt_fontprop &prop, bool force_prop) |
294 | { |
276 | { |
295 | width = 1; height = 1; |
277 | width = 1; height = 1; |
296 | ascent = 1; descent = 0; |
278 | ascent = 1; descent = 0; |
297 | |
279 | |
298 | set_name (strdup ("built-in support font")); |
280 | set_name (strdup ("built-in support font")); |
… | |
… | |
459 | *chrs = cc->c2; |
441 | *chrs = cc->c2; |
460 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
442 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
461 | ? f1 |
443 | ? f1 |
462 | : (*fs)[fs->find_font (cc->c2)]; |
444 | : (*fs)[fs->find_font (cc->c2)]; |
463 | |
445 | |
464 | f2->draw (d, x, y, chrs, width, fg, -1); |
446 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
465 | } |
447 | } |
466 | } |
448 | } |
467 | #endif |
449 | #endif |
468 | else |
450 | else |
469 | switch (t) |
451 | switch (t) |
… | |
… | |
489 | |
471 | |
490 | void clear (); |
472 | void clear (); |
491 | |
473 | |
492 | rxvt_fontprop properties (); |
474 | rxvt_fontprop properties (); |
493 | |
475 | |
494 | bool load (const rxvt_fontprop &prop); |
476 | bool load (const rxvt_fontprop &prop, bool force_prop); |
495 | |
477 | |
496 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
478 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
497 | |
479 | |
498 | void draw (rxvt_drawable &d, int x, int y, |
480 | void draw (rxvt_drawable &d, int x, int y, |
499 | const text_t *text, int len, |
481 | const text_t *text, int len, |
500 | int fg, int bg); |
482 | int fg, int bg); |
501 | |
483 | |
502 | bool slow; // wether this is a proportional font or has other funny characteristics |
484 | bool slow; // wether this is a proportional font or has other funny characteristics |
503 | XFontStruct *f; |
485 | XFontStruct *f; |
504 | codeset cs; |
|
|
505 | bool enc2b, encm; |
486 | bool enc2b, encm; |
506 | |
487 | |
507 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
488 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
508 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
489 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
509 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
490 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
… | |
… | |
645 | return false; |
626 | return false; |
646 | } |
627 | } |
647 | } |
628 | } |
648 | |
629 | |
649 | bool |
630 | bool |
650 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
631 | rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop) |
651 | { |
632 | { |
652 | dTermDisplay; |
633 | dTermDisplay; |
653 | |
634 | |
654 | clear (); |
635 | clear (); |
655 | |
636 | |
656 | char field_str[64]; // enough for 128 bits |
637 | char field_str[64]; // enough for 128 bits |
657 | |
638 | |
658 | // first morph the font if required |
639 | // first morph the font if required |
659 | if (prop.weight != rxvt_fontprop::unset |
640 | if (force_prop) |
660 | || prop.slant != rxvt_fontprop::unset) |
|
|
661 | { |
641 | { |
662 | char fname[1024]; |
642 | char fname[1024]; |
663 | |
643 | |
664 | if (name[0] != '-') |
644 | if (name[0] != '-') |
665 | { |
645 | { |
… | |
… | |
1057 | |
1037 | |
1058 | void clear (); |
1038 | void clear (); |
1059 | |
1039 | |
1060 | rxvt_fontprop properties (); |
1040 | rxvt_fontprop properties (); |
1061 | |
1041 | |
1062 | bool load (const rxvt_fontprop &prop); |
1042 | bool load (const rxvt_fontprop &prop, bool force_prop); |
1063 | |
1043 | |
1064 | void draw (rxvt_drawable &d, int x, int y, |
1044 | void draw (rxvt_drawable &d, int x, int y, |
1065 | const text_t *text, int len, |
1045 | const text_t *text, int len, |
1066 | int fg, int bg); |
1046 | int fg, int bg); |
1067 | |
1047 | |
… | |
… | |
1100 | |
1080 | |
1101 | return p; |
1081 | return p; |
1102 | } |
1082 | } |
1103 | |
1083 | |
1104 | bool |
1084 | bool |
1105 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1085 | rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop) |
1106 | { |
1086 | { |
1107 | dTermDisplay; |
1087 | dTermDisplay; |
1108 | |
1088 | |
1109 | clear (); |
1089 | clear (); |
1110 | |
1090 | |
… | |
… | |
1119 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1099 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1120 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1100 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1121 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1101 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1122 | |
1102 | |
1123 | if (prop.weight != rxvt_fontprop::unset |
1103 | if (prop.weight != rxvt_fontprop::unset |
1124 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1104 | && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)) |
1125 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1105 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1126 | |
1106 | |
1127 | if (prop.slant != rxvt_fontprop::unset |
1107 | if (prop.slant != rxvt_fontprop::unset |
1128 | && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
1108 | && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)) |
1129 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1109 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1130 | |
1110 | |
1131 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1111 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1132 | // clip width, we can't do better, or can we? |
1112 | // clip width, we can't do better, or can we? |
1133 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1113 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
… | |
… | |
1282 | void |
1262 | void |
1283 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1263 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1284 | const text_t *text, int len, |
1264 | const text_t *text, int len, |
1285 | int fg, int bg) |
1265 | int fg, int bg) |
1286 | { |
1266 | { |
1287 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
|
|
1288 | |
|
|
1289 | XGlyphInfo extents; |
1267 | XGlyphInfo extents; |
1290 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1268 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1291 | XftGlyphSpec *ep = enc; |
1269 | XftGlyphSpec *ep = enc; |
1292 | |
1270 | |
1293 | dTermDisplay; |
1271 | dTermDisplay; |
1294 | dTermGC; |
1272 | dTermGC; |
1295 | |
1273 | |
|
|
1274 | int w = term->fwidth * len; |
|
|
1275 | int h = term->fheight; |
|
|
1276 | |
|
|
1277 | bool buffered = bg >= 0 // we don't use a transparent bg |
|
|
1278 | #ifndef FORCE_UNBUFFERED_XFT |
|
|
1279 | # ifdef ENABLE_TRANSPARENCY |
|
|
1280 | || !term->am_transparent // we aren't transparent |
|
|
1281 | # endif |
|
|
1282 | #endif |
|
|
1283 | ; |
|
|
1284 | |
1296 | // cut trailing spaces |
1285 | // cut trailing spaces |
1297 | while (len && text [len - 1] == ' ') |
1286 | while (len && text [len - 1] == ' ') |
1298 | len--; |
1287 | len--; |
|
|
1288 | |
|
|
1289 | int x_ = buffered ? 0 : x; |
|
|
1290 | int y_ = buffered ? 0 : y; |
1299 | |
1291 | |
1300 | while (len) |
1292 | while (len) |
1301 | { |
1293 | { |
1302 | int cwidth = term->fwidth; |
1294 | int cwidth = term->fwidth; |
1303 | FcChar32 fc = *text++; len--; |
1295 | FcChar32 fc = *text++; len--; |
… | |
… | |
1309 | { |
1301 | { |
1310 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1302 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1311 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1303 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1312 | |
1304 | |
1313 | ep->glyph = glyph; |
1305 | ep->glyph = glyph; |
1314 | ep->x = x + (cwidth - extents.xOff >> 1); |
1306 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
1315 | ep->y = y + ascent; |
1307 | ep->y = y_ + ascent; |
1316 | |
1308 | |
1317 | if (extents.xOff == 0) |
1309 | if (extents.xOff == 0) |
1318 | ep->x = x + cwidth; |
1310 | ep->x = x_ + cwidth; |
1319 | |
1311 | |
1320 | ep++; |
1312 | ep++; |
1321 | } |
1313 | } |
1322 | |
1314 | |
1323 | x += cwidth; |
1315 | x_ += cwidth; |
|
|
1316 | } |
|
|
1317 | |
|
|
1318 | if (buffered) |
1324 | } |
1319 | { |
1325 | |
|
|
1326 | if (ep != enc) |
1320 | if (ep != enc) |
|
|
1321 | { |
|
|
1322 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
|
|
1323 | |
|
|
1324 | if (0) |
|
|
1325 | ; |
|
|
1326 | #ifdef ENABLE_TRANSPARENCY |
|
|
1327 | else if (bg < 0 && term->am_pixmap_trans) |
|
|
1328 | XCopyArea (disp, term->pixmap, d2, gc, |
|
|
1329 | x + term->window_vt_x, y + term->window_vt_y, |
|
|
1330 | w, h, 0, 0); |
|
|
1331 | #endif |
|
|
1332 | #ifdef XPM_BACKGROUND |
|
|
1333 | else if (bg < 0 && term->bgPixmap.pixmap) |
|
|
1334 | { |
|
|
1335 | XGCValues gcv; |
|
|
1336 | |
|
|
1337 | gcv.fill_style = FillTiled; |
|
|
1338 | gcv.tile = term->pixmap; |
|
|
1339 | gcv.ts_x_origin = -x; |
|
|
1340 | gcv.ts_y_origin = -y; |
|
|
1341 | |
|
|
1342 | GC gc2 = XCreateGC (disp, d2, |
|
|
1343 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
|
|
1344 | &gcv); |
|
|
1345 | |
|
|
1346 | XFillRectangle (disp, d2, gc2, 0, 0, w, h); |
|
|
1347 | |
|
|
1348 | XFreeGC (disp, gc2); |
|
|
1349 | } |
|
|
1350 | #endif |
|
|
1351 | else |
|
|
1352 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
|
|
1353 | |
|
|
1354 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1355 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
|
|
1356 | } |
|
|
1357 | else |
|
|
1358 | clear_rect (d, x, y, w, h, bg); |
|
|
1359 | } |
|
|
1360 | else |
|
|
1361 | { |
|
|
1362 | clear_rect (d, x, y, w, h, bg); |
1327 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1363 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1364 | } |
1328 | } |
1365 | } |
|
|
1366 | |
1329 | #endif |
1367 | #endif |
1330 | |
1368 | |
1331 | ///////////////////////////////////////////////////////////////////////////// |
1369 | ///////////////////////////////////////////////////////////////////////////// |
1332 | |
1370 | |
1333 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1371 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
… | |
… | |
1344 | void |
1382 | void |
1345 | rxvt_fontset::clear () |
1383 | rxvt_fontset::clear () |
1346 | { |
1384 | { |
1347 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1385 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1348 | = rxvt_fontprop::unset; |
1386 | = rxvt_fontprop::unset; |
|
|
1387 | force_prop = false; |
1349 | |
1388 | |
1350 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1389 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1351 | FONT_UNREF (*i); |
1390 | FONT_UNREF (*i); |
1352 | |
1391 | |
1353 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1392 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
… | |
… | |
1465 | if (fonts[i]->loaded) |
1504 | if (fonts[i]->loaded) |
1466 | return true; |
1505 | return true; |
1467 | |
1506 | |
1468 | fonts[i]->loaded = true; |
1507 | fonts[i]->loaded = true; |
1469 | |
1508 | |
1470 | if (!fonts[i]->load (prop)) |
1509 | if (!fonts[i]->load (prop, force_prop)) |
1471 | { |
1510 | { |
1472 | fonts[i]->cs = CS_UNKNOWN; |
1511 | fonts[i]->cs = CS_UNKNOWN; |
1473 | return false; |
1512 | return false; |
1474 | } |
1513 | } |
1475 | |
1514 | |