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.81 by root, Mon Jan 9 07:19:18 2006 UTC vs.
Revision 1.85 by root, Wed Jan 25 00:42:21 2006 UTC

26#include "rxvtfont.h" 26#include "rxvtfont.h"
27 27
28#include <cstdlib> 28#include <cstdlib>
29#include <wchar.h> 29#include <wchar.h>
30#include <inttypes.h> 30#include <inttypes.h>
31
32#define DISPLAY r->display->display
33#define TGC r->gc
34 31
35#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 32#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width
36 33
37const struct rxvt_fallback_font { 34const struct rxvt_fallback_font {
38 codeset cs; 35 codeset cs;
153 0x304c, 0x672c, // が本 150 0x304c, 0x672c, // が本
154}; 151};
155 152
156#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 153#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
157 154
155#define dTermDisplay Display *disp = term->display->display
156#define dTermGC GC gc = term->gc
157
158///////////////////////////////////////////////////////////////////////////// 158/////////////////////////////////////////////////////////////////////////////
159 159
160#if XFT 160#if XFT
161rxvt_drawable::~rxvt_drawable () 161rxvt_drawable::~rxvt_drawable ()
162{ 162{
173} 173}
174#endif 174#endif
175 175
176///////////////////////////////////////////////////////////////////////////// 176/////////////////////////////////////////////////////////////////////////////
177 177
178static void *enc_buf;
179static uint32_t enc_len;
180
181static inline void *
182get_enc_buf (uint32_t len)
183{
184 if (len > enc_len)
185 {
186 free (enc_buf);
187 enc_buf = malloc (len);
188 enc_len = len;
189 }
190
191 return enc_buf;
192}
193
194static const char * 178static const char *
195enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 179enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
196{ 180{
197 uint8_t *buf = (uint8_t *)get_enc_buf (len); 181 uint8_t *buf = rxvt_temp_buf<uint8_t> (len);
182 uint8_t *res = buf;
198 183
199 while (len--) 184 while (len--)
200 { 185 {
201 uint32_t c = FROM_UNICODE (cs, *text++); 186 uint32_t c = FROM_UNICODE (cs, *text++);
202 187
207 } 192 }
208 193
209 *buf++ = c; 194 *buf++ = c;
210 } 195 }
211 196
212 return (const char *)enc_buf; 197 return (const char *)res;
213} 198}
214 199
215static const XChar2b * 200static const XChar2b *
216enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) 201enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
217{ 202{
218 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 203 XChar2b *buf = rxvt_temp_buf<XChar2b> (len);
204 XChar2b *res = buf;
219 205
220 while (len--) 206 while (len--)
221 { 207 {
222 uint32_t c = FROM_UNICODE (cs, *text++); 208 uint32_t c = FROM_UNICODE (cs, *text++);
223 209
230 buf->byte1 = c >> 8; 216 buf->byte1 = c >> 8;
231 buf->byte2 = c; 217 buf->byte2 = c;
232 buf++; 218 buf++;
233 } 219 }
234 220
235 return (XChar2b *)enc_buf; 221 return res;
236} 222}
237 223
238///////////////////////////////////////////////////////////////////////////// 224/////////////////////////////////////////////////////////////////////////////
239 225
240void 226void
246 if (this->name) free (this->name); // let the compiler optimize 232 if (this->name) free (this->name); // let the compiler optimize
247 this->name = name; 233 this->name = name;
248} 234}
249 235
250void 236void
251rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) 237rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
252{ 238{
239 dTermDisplay;
240 dTermGC;
241
253 if (color == Color_bg) 242 if (color == Color_bg)
254 XClearArea (d.display->display, d, x, y, w, h, FALSE); 243 XClearArea (disp, d, x, y, w, h, FALSE);
255 else if (color >= 0) 244 else if (color >= 0)
256 { 245 {
257#if XFT 246#if XFT
258 XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); 247 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
259#else 248#else
260 XSetForeground (d.display->display, TGC, r->pix_colors[color]); 249 XSetForeground (disp, gc, term->pix_colors[color]);
261 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 250 XFillRectangle (disp, d, gc, x, y, w, h);
262#endif 251#endif
263 } 252 }
264} 253}
265 254
266#include "table/linedraw.h" 255#include "table/linedraw.h"
294 set_name (strdup ("built-in support font")); 283 set_name (strdup ("built-in support font"));
295 284
296 return true; 285 return true;
297 } 286 }
298 287
299 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 288 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
300 { 289 {
301 careful = false; 290 careful = false;
302 291
303 if (unicode <= 0x001f) 292 if (unicode <= 0x001f)
304 return true; 293 return true;
308 297
309 if (unicode <= 0x009f) 298 if (unicode <= 0x009f)
310 return true; 299 return true;
311 300
312 if (unicode >= 0x2500 && unicode <= 0x259f && 301 if (unicode >= 0x2500 && unicode <= 0x259f &&
313 !r->option (Opt_skipBuiltinGlyphs)) 302 !term->option (Opt_skipBuiltinGlyphs))
314 return true; 303 return true;
315 304
316 if (IS_COMPOSE (unicode)) 305 if (IS_COMPOSE (unicode))
317 return true; 306 return true;
318 307
334void 323void
335rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 324rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
336 const text_t *text, int len, 325 const text_t *text, int len,
337 int fg, int bg) 326 int fg, int bg)
338{ 327{
339 Display *disp = d.display->display; 328 dTermDisplay;
329 dTermGC;
340 330
341 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 331 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
342 332
343 XSetForeground (disp, TGC, r->pix_colors[fg]); 333 XSetForeground (disp, gc, term->pix_colors[fg]);
344 334
345 while (len) 335 while (len)
346 { 336 {
347#if ENABLE_COMBINING 337#if ENABLE_COMBINING
348 compose_char *cc; 338 compose_char *cc;
352 342
353 while (++text, --len && *text == NOCHAR) 343 while (++text, --len && *text == NOCHAR)
354 ; 344 ;
355 345
356 int width = text - tp; 346 int width = text - tp;
357 int fwidth = r->fwidth * width; 347 int fwidth = term->fwidth * width;
358 348
359 if (0x2500 <= t && t <= 0x259f) 349 if (0x2500 <= t && t <= 0x259f)
360 { 350 {
361 uint16_t offs = linedraw_offs[t - 0x2500]; 351 uint16_t offs = linedraw_offs[t - 0x2500];
362 uint32_t *a = linedraw_command + (offs >> 4); 352 uint32_t *a = linedraw_command + (offs >> 4);
363 uint32_t *b = a + (offs & 15); 353 uint32_t *b = a + (offs & 15);
364 354
365 int W = fwidth; 355 int W = fwidth;
366 int H = r->fheight; 356 int H = term->fheight;
367 357
368 int x_[16]; 358 int x_[16];
369 int y_[16]; 359 int y_[16];
370 360
371 for (int i = 0; i <= 8; i++) 361 for (int i = 0; i <= 8; i++)
379 369
380 XGCValues gcv; 370 XGCValues gcv;
381 371
382 gcv.cap_style = CapButt; 372 gcv.cap_style = CapButt;
383 gcv.line_width = 0; 373 gcv.line_width = 0;
384 XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); 374 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
385 375
386 while (a < b) 376 while (a < b)
387 { 377 {
388 uint32_t command = *a++; 378 uint32_t command = *a++;
389 379
396 int y2 = y_[(command >> 0) & 15]; 386 int y2 = y_[(command >> 0) & 15];
397 387
398 switch (op) 388 switch (op)
399 { 389 {
400 case 0: // line 390 case 0: // line
401 XDrawLine (disp, d, TGC, x1, y1, x2, y2); 391 XDrawLine (disp, d, gc, x1, y1, x2, y2);
402 break; 392 break;
403 393
404 case 1: // rectangle, possibly stippled 394 case 1: // rectangle, possibly stippled
405 if (a) 395 if (a)
406 { 396 {
409 gcv.fill_style = FillStippled; 399 gcv.fill_style = FillStippled;
410 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 400 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
411 gcv.ts_x_origin = x; 401 gcv.ts_x_origin = x;
412 gcv.ts_y_origin = y; 402 gcv.ts_y_origin = y;
413 403
414 XChangeGC (disp, TGC, 404 XChangeGC (disp, gc,
415 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 405 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
416 &gcv); 406 &gcv);
417 } 407 }
418 408
419 XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 409 XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
420 410
421 if (a) 411 if (a)
422 { 412 {
423 XFreePixmap (disp, gcv.stipple); 413 XFreePixmap (disp, gcv.stipple);
424 gcv.stipple = 0; 414 gcv.stipple = 0;
425 gcv.fill_style = FillSolid; 415 gcv.fill_style = FillSolid;
426 XChangeGC (disp, TGC, GCFillStyle, &gcv); 416 XChangeGC (disp, gc, GCFillStyle, &gcv);
427 } 417 }
428 break; 418 break;
429 case 2: // arc 419 case 2: // arc
430 XDrawArc (disp, d, TGC, 420 XDrawArc (disp, d, gc,
431 x1 - W/2, y1 - H/2, W-1, H-1, 421 x1 - W/2, y1 - H/2, W-1, H-1,
432 (a - 1) * 90*64, (b - 1) * 90*64); 422 (a - 1) * 90*64, (b - 1) * 90*64);
433 break; 423 break;
434 } 424 }
435 } 425 }
466 case ZERO_WIDTH_CHAR: 456 case ZERO_WIDTH_CHAR:
467 case NOCHAR: 457 case NOCHAR:
468 break; 458 break;
469 459
470 default: 460 default:
471 XDrawRectangle (disp, d, TGC, x + 2, y + 2, 461 XDrawRectangle (disp, d, gc, x + 2, y + 2,
472 fwidth - 4, r->fheight - 4); 462 fwidth - 4, term->fheight - 4);
473 } 463 }
474 464
475 x += fwidth; 465 x += fwidth;
476 } 466 }
477} 467}
485 475
486 rxvt_fontprop properties (); 476 rxvt_fontprop properties ();
487 477
488 bool load (const rxvt_fontprop &prop); 478 bool load (const rxvt_fontprop &prop);
489 479
490 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); 480 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
491 481
492 void draw (rxvt_drawable &d, int x, int y, 482 void draw (rxvt_drawable &d, int x, int y,
493 const text_t *text, int len, 483 const text_t *text, int len,
494 int fg, int bg); 484 int fg, int bg);
495 485
507char * 497char *
508rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 498rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
509{ 499{
510 unsigned long value; 500 unsigned long value;
511 501
512 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 502 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
513 return XGetAtomName (DISPLAY, value); 503 return XGetAtomName (term->display->display, value);
514 else 504 else
515 return rxvt_strdup (repl); 505 return rxvt_strdup (repl);
516} 506}
517 507
518rxvt_fontprop 508rxvt_fontprop
539rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 529rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
540{ 530{
541 unsigned long height; 531 unsigned long height;
542 532
543#if 0 533#if 0
544 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 534 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
545 return false; 535 return false;
546#else 536#else
547 height = f->ascent + f->descent; 537 height = f->ascent + f->descent;
548#endif 538#endif
549 539
550 unsigned long avgwidth; 540 unsigned long avgwidth;
551 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 541 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
552 avgwidth = 0; 542 avgwidth = 0;
553 543
554 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 544 char *weight = get_property (f, "WEIGHT_NAME", "medium");
555 char *slant = get_property (f, "SLANT", "r"); 545 char *slant = get_property (f, "SLANT", "r");
556 546
565} 555}
566 556
567bool 557bool
568rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 558rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
569{ 559{
560 dTermDisplay;
570 int slashes = 0; 561 int slashes = 0;
571 const char *comp[13]; 562 const char *comp[13];
572 563
573 for (const char *c = name; *c; c++) 564 for (const char *c = name; *c; c++)
574 if (*c == '-') 565 if (*c == '-')
582 if (slashes >= 13 573 if (slashes >= 13
583 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 574 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
584 && (*comp[11] >= '0' && *comp[11] <= '9')) 575 && (*comp[11] >= '0' && *comp[11] <= '9'))
585 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); 576 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
586 577
587 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 578 XFontStruct *f = XLoadQueryFont (disp, name);
588 579
589 if (f) 580 if (f)
590 { 581 {
591 // the font should really exist now. if not, we have a problem 582 // the font should really exist now. if not, we have a problem
592 // (e.g. if the user did xset fp rehash just when we were searching fonts). 583 // (e.g. if the user did xset fp rehash just when we were searching fonts).
593 // in that case, just return garbage. 584 // in that case, just return garbage.
594 bool ret = set_properties (p, f); 585 bool ret = set_properties (p, f);
595 XFreeFont (DISPLAY, f); 586 XFreeFont (disp, f);
596 return ret; 587 return ret;
597 } 588 }
598 else 589 else
599 return false; 590 return false;
600} 591}
638} 629}
639 630
640bool 631bool
641rxvt_font_x11::load (const rxvt_fontprop &prop) 632rxvt_font_x11::load (const rxvt_fontprop &prop)
642{ 633{
643 Display *disp = DISPLAY; 634 dTermDisplay;
644 635
645 clear (); 636 clear ();
646 637
647 char field_str[64]; // enough for 128 bits 638 char field_str[64]; // enough for 128 bits
648 639
723 int diff = 0; 714 int diff = 0;
724 715
725 if (replace_field (fname, list[i], 6, '0', field_str)) 716 if (replace_field (fname, list[i], 6, '0', field_str))
726 diff += 10; // slightly penalize scalable fonts 717 diff += 10; // slightly penalize scalable fonts
727 else if (replace_field (fname, list[i], 11, '0', "0")) 718 else if (replace_field (fname, list[i], 11, '0', "0"))
728 diff += 300; // more heavily penalize what looks like scaled bitmap fotns 719 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
729 720
730 if (!set_properties (p, fname)) 721 if (!set_properties (p, fname))
731 continue; 722 continue;
732 723
733 if (prop.height != rxvt_fontprop::unset 724 if (prop.height != rxvt_fontprop::unset
886void 877void
887rxvt_font_x11::clear () 878rxvt_font_x11::clear ()
888{ 879{
889 if (f) 880 if (f)
890 { 881 {
891 XFreeFont (DISPLAY, f); 882 XFreeFont (term->display->display, f);
892 f = 0; 883 f = 0;
893 } 884 }
894} 885}
895 886
896bool 887bool
897rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 888rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
898{ 889{
899 uint32_t ch = FROM_UNICODE (cs, unicode); 890 uint32_t ch = FROM_UNICODE (cs, unicode);
900 891
901 if (ch == NOCHAR) 892 if (ch == NOCHAR)
902 return false; 893 return false;
961 // this looks like a mess /. 952 // this looks like a mess /.
962 // and it is a mess /. 953 // and it is a mess /.
963 // yet we are trying to be perfect /. 954 // yet we are trying to be perfect /.
964 // but the result still isn't perfect /. 955 // but the result still isn't perfect /.
965 956
957 dTermDisplay;
958 dTermGC;
959
966 bool slow = this->slow 960 bool slow = this->slow
967 || width != r->fwidth 961 || width != term->fwidth
968 || height != r->fheight; 962 || height != term->fheight;
969 963
970 int base = ascent; // sorry, incorrect: r->fbase; 964 int base = ascent; // sorry, incorrect: term->fbase;
971 965
972 XGCValues v; 966 XGCValues v;
973 v.foreground = r->pix_colors[fg]; 967 v.foreground = term->pix_colors[fg];
974 v.font = f->fid; 968 v.font = f->fid;
975 969
976 if (enc2b) 970 if (enc2b)
977 { 971 {
978 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 972 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
979 973
980 if (bg == Color_bg && !slow) 974 if (bg == Color_bg && !slow)
981 { 975 {
982 v.background = r->pix_colors[bg]; 976 v.background = term->pix_colors[bg];
983 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 977 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
984 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 978 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
985 } 979 }
986 else 980 else
987 { 981 {
988 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 982 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
989 983
990 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 984 XChangeGC (disp, gc, GCForeground | GCFont, &v);
991 985
992 if (slow) 986 if (slow)
993 { 987 {
994 do 988 do
995 { 989 {
996 if (xc->byte1 || xc->byte2) 990 if (xc->byte1 || xc->byte2)
997 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 991 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
998 992
999 x += r->fwidth; 993 x += term->fwidth;
1000 xc++; len--; 994 xc++; len--;
1001 } 995 }
1002 while (len); 996 while (len);
1003 } 997 }
1004 else 998 else
1005 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 999 XDrawString16 (disp, d, gc, x, y + base, xc, len);
1006 } 1000 }
1007 } 1001 }
1008 else 1002 else
1009 { 1003 {
1010 const char *xc = enc_char (text, len, cs, slow); 1004 const char *xc = enc_char (text, len, cs, slow);
1011 1005
1012 if (bg == Color_bg && !slow) 1006 if (bg == Color_bg && !slow)
1013 { 1007 {
1014 v.background = r->pix_colors[bg]; 1008 v.background = term->pix_colors[bg];
1015 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1009 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
1016 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1010 XDrawImageString (disp, d, gc, x, y + base, xc, len);
1017 } 1011 }
1018 else 1012 else
1019 { 1013 {
1020 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1014 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1021 1015
1022 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1016 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1023 1017
1024 if (slow) 1018 if (slow)
1025 { 1019 {
1026 do 1020 do
1027 { 1021 {
1028 if (*xc) 1022 if (*xc)
1029 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1023 XDrawString (disp, d, gc, x, y + base, xc, 1);
1030 1024
1031 x += r->fwidth; 1025 x += term->fwidth;
1032 xc++; len--; 1026 xc++; len--;
1033 } 1027 }
1034 while (len); 1028 while (len);
1035 } 1029 }
1036 else 1030 else
1037 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1031 XDrawString (disp, d, gc, x, y + base, xc, len);
1038 } 1032 }
1039 } 1033 }
1040} 1034}
1041 1035
1042///////////////////////////////////////////////////////////////////////////// 1036/////////////////////////////////////////////////////////////////////////////
1054 1048
1055 void draw (rxvt_drawable &d, int x, int y, 1049 void draw (rxvt_drawable &d, int x, int y,
1056 const text_t *text, int len, 1050 const text_t *text, int len,
1057 int fg, int bg); 1051 int fg, int bg);
1058 1052
1059 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); 1053 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
1060 1054
1061protected: 1055protected:
1062 XftFont *f; 1056 XftFont *f;
1063}; 1057};
1064 1058
1065void 1059void
1066rxvt_font_xft::clear () 1060rxvt_font_xft::clear ()
1067{ 1061{
1068 if (f) 1062 if (f)
1069 { 1063 {
1070 XftFontClose (DISPLAY, f); 1064 XftFontClose (term->display->display, f);
1071 f = 0; 1065 f = 0;
1072 } 1066 }
1073} 1067}
1074 1068
1075rxvt_fontprop 1069rxvt_fontprop
1093} 1087}
1094 1088
1095bool 1089bool
1096rxvt_font_xft::load (const rxvt_fontprop &prop) 1090rxvt_font_xft::load (const rxvt_fontprop &prop)
1097{ 1091{
1098 Display *disp = DISPLAY; 1092 dTermDisplay;
1099 1093
1100 clear (); 1094 clear ();
1101 1095
1102 FcPattern *p = FcNameParse ((FcChar8 *) name); 1096 FcPattern *p = FcNameParse ((FcChar8 *) name);
1103 1097
1130 1124
1131 // store generated name so iso14755 view gives better results 1125 // store generated name so iso14755 view gives better results
1132 set_name ((char *)FcNameUnparse (p)); 1126 set_name ((char *)FcNameUnparse (p));
1133 1127
1134 XftResult result; 1128 XftResult result;
1135 FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); 1129 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1136 1130
1137 FcPatternDestroy (p); 1131 FcPatternDestroy (p);
1138 1132
1139 if (!match) 1133 if (!match)
1140 return false; 1134 return false;
1238 1232
1239 return success; 1233 return success;
1240} 1234}
1241 1235
1242bool 1236bool
1243rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 1237rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1244{ 1238{
1245 careful = false; 1239 careful = false;
1246 1240
1247 if (!XftCharExists (DISPLAY, f, unicode)) 1241 if (!XftCharExists (term->display->display, f, unicode))
1248 return false; 1242 return false;
1249 1243
1250 if (!prop || prop->width == rxvt_fontprop::unset) 1244 if (!prop || prop->width == rxvt_fontprop::unset)
1251 return true; 1245 return true;
1252 1246
1253 // check character against base font bounding box 1247 // check character against base font bounding box
1254 FcChar32 ch = unicode; 1248 FcChar32 ch = unicode;
1255 XGlyphInfo g; 1249 XGlyphInfo g;
1256 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1250 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1257 1251
1258 int w = g.width - g.x; 1252 int w = g.width - g.x;
1259 int wcw = wcwidth (unicode); 1253 int wcw = wcwidth (unicode);
1260 if (wcw > 0) w = (w + wcw - 1) / wcw; 1254 if (wcw > 0) w = (w + wcw - 1) / wcw;
1261 1255
1269void 1263void
1270rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1264rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1271 const text_t *text, int len, 1265 const text_t *text, int len,
1272 int fg, int bg) 1266 int fg, int bg)
1273{ 1267{
1274 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1268 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1275 1269
1276 XGlyphInfo extents; 1270 XGlyphInfo extents;
1277 XftGlyphSpec *enc = (XftGlyphSpec *) get_enc_buf (len * sizeof (XftGlyphSpec)); 1271 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1278 XftGlyphSpec *ep = enc; 1272 XftGlyphSpec *ep = enc;
1273
1274 dTermDisplay;
1275 dTermGC;
1279 1276
1280 // cut trailing spaces 1277 // cut trailing spaces
1281 while (len && text [len - 1] == ' ') 1278 while (len && text [len - 1] == ' ')
1282 len--; 1279 len--;
1283 1280
1284 while (len) 1281 while (len)
1285 { 1282 {
1286 int cwidth = r->fwidth; 1283 int cwidth = term->fwidth;
1287 FcChar32 fc = *text++; len--; 1284 FcChar32 fc = *text++; len--;
1288 1285
1289 while (len && *text == NOCHAR) 1286 while (len && *text == NOCHAR)
1290 text++, len--, cwidth += r->fwidth; 1287 text++, len--, cwidth += term->fwidth;
1291 1288
1292 if (fc != ' ') // skip spaces 1289 if (fc != ' ') // skip spaces
1293 { 1290 {
1294 FT_UInt gl = XftCharIndex (d.display->display, f, fc); 1291 FT_UInt glyph = XftCharIndex (disp, f, fc);
1295 XftGlyphExtents (d.display->display, f, &gl, 1, &extents); 1292 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1296 1293
1297 ep->glyph = gl; 1294 ep->glyph = glyph;
1298 ep->x = x + (cwidth - extents.xOff >> 1); 1295 ep->x = x + (cwidth - extents.xOff >> 1);
1299 ep->y = y + ascent; 1296 ep->y = y + ascent;
1300 ep++; 1297 ep++;
1301 } 1298 }
1302 1299
1303 x += cwidth; 1300 x += cwidth;
1304 } 1301 }
1305 1302
1306 if (ep != enc) 1303 if (ep != enc)
1307 XftDrawGlyphSpec (d, &r->pix_colors[fg].c, f, enc, ep - enc); 1304 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1308} 1305}
1309#endif 1306#endif
1310 1307
1311///////////////////////////////////////////////////////////////////////////// 1308/////////////////////////////////////////////////////////////////////////////
1312 1309
1313rxvt_fontset::rxvt_fontset (rxvt_t r) 1310rxvt_fontset::rxvt_fontset (rxvt_term *term)
1314: fontdesc (0), r (r) 1311: fontdesc (0), term (term)
1315{ 1312{
1316 clear (); 1313 clear ();
1317} 1314}
1318 1315
1319rxvt_fontset::~rxvt_fontset () 1316rxvt_fontset::~rxvt_fontset ()
1363 f = new rxvt_font_x11; 1360 f = new rxvt_font_x11;
1364 } 1361 }
1365 else 1362 else
1366 f = new rxvt_font_x11; 1363 f = new rxvt_font_x11;
1367 1364
1368 f->set_term (r); 1365 f->set_term (term);
1369 f->set_name (strdup (name)); 1366 f->set_name (strdup (name));
1370 1367
1371 f->cs = cs; 1368 f->cs = cs;
1372 f->loaded = false; 1369 f->loaded = false;
1373 1370
1556 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1553 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1557 FcPatternAddBool (p, FC_MINSPACE, 1); 1554 FcPatternAddBool (p, FC_MINSPACE, 1);
1558 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1555 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1559 1556
1560 XftResult result; 1557 XftResult result;
1561 FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); 1558 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1562 1559
1563 FcPatternDestroy (p); 1560 FcPatternDestroy (p);
1564 1561
1565 if (match) 1562 if (match)
1566 { 1563 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines