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 | * |
… | |
… | |
232 | 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 |
233 | { |
233 | { |
234 | dTermDisplay; |
234 | dTermDisplay; |
235 | dTermGC; |
235 | dTermGC; |
236 | |
236 | |
237 | if (color < 0 || color == Color_bg) |
237 | if (color == Color_bg || color == Color_transparent) |
238 | XClearArea (disp, d, x, y, w, h, false); |
238 | XClearArea (disp, d, x, y, w, h, false); |
239 | else |
239 | else if (color >= 0) |
240 | { |
240 | { |
241 | #if XFT |
241 | #if XFT |
242 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
242 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
243 | #else |
243 | #else |
244 | XSetForeground (disp, gc, term->pix_colors[color]); |
244 | XSetForeground (disp, gc, term->pix_colors[color]); |
… | |
… | |
270 | p.slant = rxvt_fontprop::roman; |
270 | p.slant = rxvt_fontprop::roman; |
271 | |
271 | |
272 | return p; |
272 | return p; |
273 | } |
273 | } |
274 | |
274 | |
275 | bool load (const rxvt_fontprop &prop) |
275 | bool load (const rxvt_fontprop &prop, bool force_prop) |
276 | { |
276 | { |
277 | width = 1; height = 1; |
277 | width = 1; height = 1; |
278 | ascent = 1; descent = 0; |
278 | ascent = 1; descent = 0; |
279 | |
279 | |
280 | set_name (strdup ("built-in support font")); |
280 | set_name (strdup ("built-in support font")); |
… | |
… | |
441 | *chrs = cc->c2; |
441 | *chrs = cc->c2; |
442 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
442 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
443 | ? f1 |
443 | ? f1 |
444 | : (*fs)[fs->find_font (cc->c2)]; |
444 | : (*fs)[fs->find_font (cc->c2)]; |
445 | |
445 | |
446 | f2->draw (d, x, y, chrs, width, fg, -1); |
446 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
447 | } |
447 | } |
448 | } |
448 | } |
449 | #endif |
449 | #endif |
450 | else |
450 | else |
451 | switch (t) |
451 | switch (t) |
… | |
… | |
471 | |
471 | |
472 | void clear (); |
472 | void clear (); |
473 | |
473 | |
474 | rxvt_fontprop properties (); |
474 | rxvt_fontprop properties (); |
475 | |
475 | |
476 | bool load (const rxvt_fontprop &prop); |
476 | bool load (const rxvt_fontprop &prop, bool force_prop); |
477 | |
477 | |
478 | 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; |
479 | |
479 | |
480 | void draw (rxvt_drawable &d, int x, int y, |
480 | void draw (rxvt_drawable &d, int x, int y, |
481 | const text_t *text, int len, |
481 | const text_t *text, int len, |
482 | int fg, int bg); |
482 | int fg, int bg); |
483 | |
483 | |
484 | 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 |
485 | XFontStruct *f; |
485 | XFontStruct *f; |
486 | codeset cs; |
|
|
487 | bool enc2b, encm; |
486 | bool enc2b, encm; |
488 | |
487 | |
489 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
488 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
490 | 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); |
491 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
490 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
… | |
… | |
627 | return false; |
626 | return false; |
628 | } |
627 | } |
629 | } |
628 | } |
630 | |
629 | |
631 | bool |
630 | bool |
632 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
631 | rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop) |
633 | { |
632 | { |
634 | dTermDisplay; |
633 | dTermDisplay; |
635 | |
634 | |
636 | clear (); |
635 | clear (); |
637 | |
636 | |
638 | char field_str[64]; // enough for 128 bits |
637 | char field_str[64]; // enough for 128 bits |
639 | |
638 | |
640 | // first morph the font if required |
639 | // first morph the font if required |
641 | if (prop.weight != rxvt_fontprop::unset |
640 | if (force_prop) |
642 | || prop.slant != rxvt_fontprop::unset) |
|
|
643 | { |
641 | { |
644 | char fname[1024]; |
642 | char fname[1024]; |
645 | |
643 | |
646 | if (name[0] != '-') |
644 | if (name[0] != '-') |
647 | { |
645 | { |
… | |
… | |
1039 | |
1037 | |
1040 | void clear (); |
1038 | void clear (); |
1041 | |
1039 | |
1042 | rxvt_fontprop properties (); |
1040 | rxvt_fontprop properties (); |
1043 | |
1041 | |
1044 | bool load (const rxvt_fontprop &prop); |
1042 | bool load (const rxvt_fontprop &prop, bool force_prop); |
1045 | |
1043 | |
1046 | void draw (rxvt_drawable &d, int x, int y, |
1044 | void draw (rxvt_drawable &d, int x, int y, |
1047 | const text_t *text, int len, |
1045 | const text_t *text, int len, |
1048 | int fg, int bg); |
1046 | int fg, int bg); |
1049 | |
1047 | |
… | |
… | |
1082 | |
1080 | |
1083 | return p; |
1081 | return p; |
1084 | } |
1082 | } |
1085 | |
1083 | |
1086 | bool |
1084 | bool |
1087 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1085 | rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop) |
1088 | { |
1086 | { |
1089 | dTermDisplay; |
1087 | dTermDisplay; |
1090 | |
1088 | |
1091 | clear (); |
1089 | clear (); |
1092 | |
1090 | |
… | |
… | |
1101 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1099 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1102 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1100 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1103 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1101 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1104 | |
1102 | |
1105 | if (prop.weight != rxvt_fontprop::unset |
1103 | if (prop.weight != rxvt_fontprop::unset |
1106 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1104 | && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)) |
1107 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1105 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1108 | |
1106 | |
1109 | if (prop.slant != rxvt_fontprop::unset |
1107 | if (prop.slant != rxvt_fontprop::unset |
1110 | && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
1108 | && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)) |
1111 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1109 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1112 | |
1110 | |
1113 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1111 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1114 | // clip width, we can't do better, or can we? |
1112 | // clip width, we can't do better, or can we? |
1115 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1113 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
… | |
… | |
1274 | dTermGC; |
1272 | dTermGC; |
1275 | |
1273 | |
1276 | int w = term->fwidth * len; |
1274 | int w = term->fwidth * len; |
1277 | int h = term->fheight; |
1275 | int h = term->fheight; |
1278 | |
1276 | |
|
|
1277 | /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. |
|
|
1278 | * Maybe make buffering into a resource flag? Compile time option doesn't seems like a |
|
|
1279 | * good idea from the perspective of packaging for wide variety of user configs. |
|
|
1280 | */ |
1279 | bool buffered = 0 |
1281 | bool buffered = true |
1280 | #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) |
1282 | #ifdef FORCE_UNBUFFERED_XFT |
1281 | || !term->am_transparent // we aren't transparent |
1283 | && bg >= 0 |
1282 | || term->am_pixmap_trans // we have a pixmap |
|
|
1283 | #endif |
1284 | #endif |
1284 | || bg >= 0; // we don't use a transparent bg |
1285 | ; |
1285 | |
|
|
1286 | // cut trailing spaces |
1286 | // cut trailing spaces |
1287 | while (len && text [len - 1] == ' ') |
1287 | while (len && text [len - 1] == ' ') |
1288 | len--; |
1288 | len--; |
1289 | |
1289 | |
1290 | int x_ = buffered ? 0 : x; |
1290 | int x_ = buffered ? 0 : x; |
… | |
… | |
1319 | if (buffered) |
1319 | if (buffered) |
1320 | { |
1320 | { |
1321 | if (ep != enc) |
1321 | if (ep != enc) |
1322 | { |
1322 | { |
1323 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1323 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
|
|
1324 | bool back_rendered = false; |
1324 | |
1325 | |
1325 | #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) |
1326 | #ifdef HAVE_BG_PIXMAP |
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) |
1327 | if (term->bgPixmap.pixmap) |
1329 | { |
1328 | { |
|
|
1329 | Picture dst = 0; |
|
|
1330 | if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) |
|
|
1331 | dst = XftDrawPicture(d2); |
|
|
1332 | |
|
|
1333 | if (bg < 0 || dst != 0) |
|
|
1334 | { |
|
|
1335 | if (term->bgPixmap.pmap_width >= x + term->window_vt_x+w |
|
|
1336 | && term->bgPixmap.pmap_height >= y + term->window_vt_y+h) |
|
|
1337 | { |
|
|
1338 | XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, |
|
|
1339 | x + term->window_vt_x, y + term->window_vt_y, |
|
|
1340 | w, h, 0, 0); |
|
|
1341 | } |
|
|
1342 | else |
|
|
1343 | { |
1330 | XGCValues gcv; |
1344 | XGCValues gcv; |
1331 | |
1345 | |
1332 | gcv.fill_style = FillTiled; |
1346 | gcv.fill_style = FillTiled; |
1333 | gcv.tile = term->pixmap; |
1347 | gcv.tile = term->bgPixmap.pixmap; |
1334 | gcv.ts_x_origin = -x; |
1348 | gcv.ts_x_origin = -x; |
1335 | gcv.ts_y_origin = -y; |
1349 | gcv.ts_y_origin = -y; |
1336 | |
1350 | |
1337 | GC gc2 = XCreateGC (disp, d2, |
1351 | XChangeGC (disp, gc, |
1338 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
1352 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
1339 | &gcv); |
1353 | &gcv); |
1340 | |
1354 | |
1341 | XFillRectangle (disp, d2, gc2, 0, 0, w, h); |
1355 | XFillRectangle (disp, d2, gc/*gc2*/, 0, 0, w, h); |
1342 | |
1356 | |
1343 | XFreeGC (disp, gc2); |
1357 | gcv.fill_style = FillSolid; |
|
|
1358 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
|
|
1359 | } |
|
|
1360 | |
|
|
1361 | if (bg >= 0) |
|
|
1362 | { |
|
|
1363 | Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); |
|
|
1364 | XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
1365 | } |
|
|
1366 | |
|
|
1367 | back_rendered = true; |
|
|
1368 | } |
1344 | } |
1369 | } |
1345 | else |
|
|
1346 | #endif |
1370 | #endif |
|
|
1371 | |
|
|
1372 | if(bg >= 0 && !back_rendered) |
1347 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
1373 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
1348 | |
1374 | |
1349 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1375 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1350 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1376 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1351 | } |
1377 | } |
… | |
… | |
1377 | void |
1403 | void |
1378 | rxvt_fontset::clear () |
1404 | rxvt_fontset::clear () |
1379 | { |
1405 | { |
1380 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1406 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1381 | = rxvt_fontprop::unset; |
1407 | = rxvt_fontprop::unset; |
|
|
1408 | force_prop = false; |
1382 | |
1409 | |
1383 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1410 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1384 | FONT_UNREF (*i); |
1411 | FONT_UNREF (*i); |
1385 | |
1412 | |
1386 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1413 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
… | |
… | |
1498 | if (fonts[i]->loaded) |
1525 | if (fonts[i]->loaded) |
1499 | return true; |
1526 | return true; |
1500 | |
1527 | |
1501 | fonts[i]->loaded = true; |
1528 | fonts[i]->loaded = true; |
1502 | |
1529 | |
1503 | if (!fonts[i]->load (prop)) |
1530 | if (!fonts[i]->load (prop, force_prop)) |
1504 | { |
1531 | { |
1505 | fonts[i]->cs = CS_UNKNOWN; |
1532 | fonts[i]->cs = CS_UNKNOWN; |
1506 | return false; |
1533 | return false; |
1507 | } |
1534 | } |
1508 | |
1535 | |