ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtfont.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.74 by root, Tue Dec 6 15:41:26 2005 UTC vs.
Revision 1.77 by root, Wed Jan 4 20:43:38 2006 UTC

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>
29#include <inttypes.h> 30#include <inttypes.h>
30 31
31#define DISPLAY r->display->display 32#define DISPLAY r->display->display
32#define TGC r->TermWin.gc 33#define TGC r->gc
33 34
34#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 35#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width
35 36
36const struct rxvt_fallback_font { 37const struct rxvt_fallback_font {
37 codeset cs; 38 codeset cs;
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 ! OPTION_R (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
333 const text_t *text, int len, 336 const text_t *text, int len,
334 int fg, int bg) 337 int fg, int bg)
335{ 338{
336 Display *disp = d.display->display; 339 Display *disp = d.display->display;
337 340
338 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 341 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
339 342
340 XSetForeground (disp, TGC, r->pix_colors[fg]); 343 XSetForeground (disp, TGC, r->pix_colors[fg]);
341 344
342 while (len) 345 while (len)
343 { 346 {
349 352
350 while (++text, --len && *text == NOCHAR) 353 while (++text, --len && *text == NOCHAR)
351 ; 354 ;
352 355
353 int width = text - tp; 356 int width = text - tp;
354 int fwidth = r->TermWin.fwidth * width; 357 int fwidth = r->fwidth * width;
355 358
356 if (0x2500 <= t && t <= 0x259f) 359 if (0x2500 <= t && t <= 0x259f &&
360 ! OPTION_R (Opt_skipBuiltinGlyphs))
357 { 361 {
358 uint16_t offs = linedraw_offs[t - 0x2500]; 362 uint16_t offs = linedraw_offs[t - 0x2500];
359 uint32_t *a = linedraw_command + (offs >> 4); 363 uint32_t *a = linedraw_command + (offs >> 4);
360 uint32_t *b = a + (offs & 15); 364 uint32_t *b = a + (offs & 15);
361 365
362 int W = fwidth; 366 int W = fwidth;
363 int H = r->TermWin.fheight; 367 int H = r->fheight;
364 368
365 int x_[16]; 369 int x_[16];
366 int y_[16]; 370 int y_[16];
367 371
368 for (int i = 0; i <= 8; i++) 372 for (int i = 0; i <= 8; i++)
464 case NOCHAR: 468 case NOCHAR:
465 break; 469 break;
466 470
467 default: 471 default:
468 XDrawRectangle (disp, d, TGC, x + 2, y + 2, 472 XDrawRectangle (disp, d, TGC, x + 2, y + 2,
469 fwidth - 4, r->TermWin.fheight - 4); 473 fwidth - 4, r->fheight - 4);
470 } 474 }
471 475
472 x += fwidth; 476 x += fwidth;
473 } 477 }
474} 478}
523bool 527bool
524rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) 528rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth)
525{ 529{
526 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; 530 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2;
527 p.height = height; 531 p.height = height;
532 p.ascent = rxvt_fontprop::unset;
528 p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; 533 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; 534 p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic;
530 535
531 return true; 536 return true;
532} 537}
552 557
553 set_properties (p, height, weight, slant, avgwidth); 558 set_properties (p, height, weight, slant, avgwidth);
554 559
555 free (weight); 560 free (weight);
556 free (slant); 561 free (slant);
562
563 p.ascent = f->ascent;
557 564
558 return true; 565 return true;
559} 566}
560 567
561bool 568bool
956 // and it is a mess /. 963 // and it is a mess /.
957 // yet we are trying to be perfect /. 964 // yet we are trying to be perfect /.
958 // but the result still isn't perfect /. 965 // but the result still isn't perfect /.
959 966
960 bool slow = this->slow 967 bool slow = this->slow
961 || width != r->TermWin.fwidth 968 || width != r->fwidth
962 || height != r->TermWin.fheight; 969 || height != r->fheight;
963 970
964 int base = ascent; // sorry, incorrect: r->TermWin.fbase; 971 int base = ascent; // sorry, incorrect: r->fbase;
965 972
966 XGCValues v; 973 XGCValues v;
967 v.foreground = r->pix_colors[fg]; 974 v.foreground = r->pix_colors[fg];
968 v.font = f->fid; 975 v.font = f->fid;
969 976
977 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 984 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
978 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 985 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
979 } 986 }
980 else 987 else
981 { 988 {
982 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 989 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
983 990
984 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 991 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
985 992
986 if (slow) 993 if (slow)
987 { 994 {
988 do 995 do
989 { 996 {
990 if (xc->byte1 || xc->byte2) 997 if (xc->byte1 || xc->byte2)
991 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 998 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1);
992 999
993 x += r->TermWin.fwidth; 1000 x += r->fwidth;
994 xc++; len--; 1001 xc++; len--;
995 } 1002 }
996 while (len); 1003 while (len);
997 } 1004 }
998 else 1005 else
1009 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1016 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
1010 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1017 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
1011 } 1018 }
1012 else 1019 else
1013 { 1020 {
1014 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 1021 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
1015 1022
1016 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1023 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v);
1017 1024
1018 if (slow) 1025 if (slow)
1019 { 1026 {
1020 do 1027 do
1021 { 1028 {
1022 if (*xc) 1029 if (*xc)
1023 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1030 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1);
1024 1031
1025 x += r->TermWin.fwidth; 1032 x += r->fwidth;
1026 xc++; len--; 1033 xc++; len--;
1027 } 1034 }
1028 while (len); 1035 while (len);
1029 } 1036 }
1030 else 1037 else
1073 1080
1074 FT_Face face = XftLockFace (f); 1081 FT_Face face = XftLockFace (f);
1075 1082
1076 p.width = width; 1083 p.width = width;
1077 p.height = height; 1084 p.height = height;
1085 p.ascent = ascent;
1078 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD 1086 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD
1079 ? rxvt_fontprop::bold : rxvt_fontprop::medium; 1087 ? rxvt_fontprop::bold : rxvt_fontprop::medium;
1080 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC 1088 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC
1081 ? rxvt_fontprop::italic : rxvt_fontprop::roman; 1089 ? rxvt_fontprop::italic : rxvt_fontprop::roman;
1082 1090
1262void 1270void
1263rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1271rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1264 const text_t *text, int len, 1272 const text_t *text, int len,
1265 int fg, int bg) 1273 int fg, int bg)
1266{ 1274{
1267 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 1275 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg);
1268 1276
1269 int base = ascent; // should be fbase, but that is incorrect 1277 int base = ascent; // should be fbase, but that is incorrect
1270 1278
1271 XGlyphInfo extents; 1279 XGlyphInfo extents;
1272 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); 1280 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32));
1273 FcChar32 *ep = enc; 1281 FcChar32 *ep = enc;
1274 int ewidth = 0; 1282 int ewidth = 0;
1275 1283
1276 while (len) 1284 while (len)
1277 { 1285 {
1278 int cwidth = r->TermWin.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->TermWin.fwidth; 1290 text++, len--, cwidth += r->fwidth;
1283 1291
1284 if (fc == ' ' && ep == enc) // skip leading spaces 1292 if (fc == ' ' && ep == enc) // skip leading spaces
1285 x += cwidth; 1293 x += cwidth;
1286 else 1294 else
1287 { 1295 {
1336} 1344}
1337 1345
1338void 1346void
1339rxvt_fontset::clear () 1347rxvt_fontset::clear ()
1340{ 1348{
1341 prop.width = prop.height = prop.weight = prop.slant 1349 prop.width = prop.height = prop.ascent = prop.weight = prop.slant
1342 = rxvt_fontprop::unset; 1350 = rxvt_fontprop::unset;
1343 1351
1344 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1352 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1345 FONT_UNREF (*i); 1353 FONT_UNREF (*i);
1346 1354
1519 if (FROM_UNICODE (f->cs, unicode) == NOCHAR) 1527 if (FROM_UNICODE (f->cs, unicode) == NOCHAR)
1520 goto next_font; 1528 goto next_font;
1521 1529
1522 if (!realize_font (i)) 1530 if (!realize_font (i))
1523 goto next_font; 1531 goto next_font;
1532
1533 if (prop.ascent != rxvt_fontprop::unset)
1534 max_it (f->ascent, prop.ascent);
1524 } 1535 }
1525 1536
1526 if (f->cs == CS_UNKNOWN) 1537 if (f->cs == CS_UNKNOWN)
1527 goto next_font; 1538 goto next_font;
1528 1539

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines