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

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.6 by pcg, Wed Dec 17 22:29:03 2003 UTC vs.
Revision 1.12 by pcg, Fri Dec 26 07:42:23 2003 UTC

21 21
22#include "../config.h" 22#include "../config.h"
23#include "rxvt.h" 23#include "rxvt.h"
24#include "defaultfont.h" 24#include "defaultfont.h"
25 25
26#include <cstdlib>
27
26#define DISPLAY r->Xdisplay 28#define DISPLAY r->Xdisplay
27#define DRAWABLE r->TermWin.vt 29#define DRAWABLE r->TermWin.vt
28#define GC r->TermWin.gc 30#define GC r->TermWin.gc
29 31
30const struct rxvt_fallback_font { 32const struct rxvt_fallback_font {
57 59
58 // japanese 60 // japanese
59#if ENCODING_JP || ENCODING_JP_EXT 61#if ENCODING_JP || ENCODING_JP_EXT
60# if XFT 62# if XFT
61 // prefer xft for complex scripts 63 // prefer xft for complex scripts
62 { CS_UNICODE, "xft:Kochi Gothic" }, 64 { CS_UNICODE, "xft:Kochi Gothic:antialias=false" },
63# endif 65# endif
64 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, 66 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
65 { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, 67 { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
66 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, 68 { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" },
67#endif 69#endif
68 70
69#if ENCODING_CN || ENCODING_CN_EXT 71#if ENCODING_CN || ENCODING_CN_EXT
70# if XFT 72# if XFT
71 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 73 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
72 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, 74 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" },
73 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, 75 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" },
74 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, 76 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" },
75# endif 77# endif
76 { CS_CNS11643_1992_1, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-1" }, 78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-1" },
77 { CS_CNS11643_1992_2, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-2" }, 79 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-2" },
78 { CS_CNS11643_1992_3, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-3" }, 80 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-3" },
79 { CS_CNS11643_1992_4, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-4" }, 81 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-4" },
80 { CS_CNS11643_1992_5, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-5" }, 82 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-5" },
81 { CS_CNS11643_1992_6, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-6" }, 83 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-6" },
82 { CS_CNS11643_1992_7, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-7" }, 84 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-7" },
83 { CS_CNS11643_1992_F, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-f" }, 85 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-f" },
84#endif 86#endif
85 87
86#if XFT 88#if XFT
87 { CS_UNICODE, "xft:Andale Mono" }, 89 { CS_UNICODE, "xft:Andale Mono" },
88 { CS_UNICODE, "xft:Arial Unicode MS" }, 90 { CS_UNICODE, "xft:Arial Unicode MS" },
89#endif 91#endif
90 { CS_UNICODE, "-*-lucidatypewriter-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 92 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
93 { CS_UNICODE, "xft:FreeMono" },
94 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
95 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
91 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 96 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
92 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
93 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
94 97
95 { CS_UNKNOWN, 0 } 98 { CS_UNKNOWN, 0 }
96}; 99};
97 100
98///////////////////////////////////////////////////////////////////////////// 101/////////////////////////////////////////////////////////////////////////////
220 223
221 // to be done 224 // to be done
222}; 225};
223 226
224struct rxvt_font_default : rxvt_font { 227struct rxvt_font_default : rxvt_font {
225 bool load (int maxheight) 228 rxvt_fontprop properties ()
229 {
230 rxvt_fontprop p;
231
232 p.width = p.height = 1;
233 p.weight = rxvt_fontprop::medium;
234 p.slant = rxvt_fontprop::roman;
235
236 return p;
237 }
238
239 bool load (const rxvt_fontprop &prop)
226 { 240 {
227 width = 1; height = 1; 241 width = 1; height = 1;
228 ascent = 1; descent = 0; 242 ascent = 1; descent = 0;
229 243
230 return true; 244 return true;
322struct rxvt_font_x11 : rxvt_font { 336struct rxvt_font_x11 : rxvt_font {
323 rxvt_font_x11 () { f = 0; } 337 rxvt_font_x11 () { f = 0; }
324 338
325 void clear (); 339 void clear ();
326 340
327 bool load (int maxheight); 341 rxvt_fontprop properties ();
342
343 bool load (const rxvt_fontprop &prop);
328 344
329 bool has_codepoint (uint32_t unicode); 345 bool has_codepoint (uint32_t unicode);
330 346
331 void draw (int x, int y, 347 void draw (int x, int y,
332 const text_t *text, int len, 348 const text_t *text, int len,
334 350
335 XFontStruct *f; 351 XFontStruct *f;
336 codeset cs; 352 codeset cs;
337 bool enc2b, encm; 353 bool enc2b, encm;
338 354
339 const char *get_property (const char *property, const char *repl) const; 355 const char *get_property (XFontStruct *f, const char *property, const char *repl) const;
356 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
357 bool set_properties (rxvt_fontprop &p, XFontStruct *f);
358 bool set_properties (rxvt_fontprop &p, const char *name);
340}; 359};
341 360
342const char * 361const char *
343rxvt_font_x11::get_property (const char *property, const char *repl) const 362rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
344{ 363{
345 unsigned long value; 364 unsigned long value;
346 365
347 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 366 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
348 return XGetAtomName (DISPLAY, value); 367 return XGetAtomName (DISPLAY, value);
349 else 368 else
350 return repl; 369 return repl;
351} 370}
352 371
372rxvt_fontprop
373rxvt_font_x11::properties ()
374{
375 rxvt_fontprop p;
376 set_properties (p, f);
377 return p;
378}
379
353bool 380bool
354rxvt_font_x11::load (int maxheight) 381rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth)
382{
383 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2;
384 p.height = height;
385 p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium;
386 p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic;
387
388 return true;
389}
390
391bool
392rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
393{
394 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
395 const char *slant = get_property (f, "SLANT", "r");
396
397 unsigned long height;
398 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
399 return false;
400
401 unsigned long avgwidth;
402 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
403 avgwidth = 0;
404
405 return set_properties (p, height, weight, slant, avgwidth);
406}
407
408bool
409rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
410{
411 int slashes = 0;
412 const char *comp[12];
413
414 for (const char *c = name; *c; c++)
415 if (*c == '-')
416 {
417 comp[slashes++] = c + 1;
418 if (slashes >= 13)
419 break;
420 }
421
422 /* can we short-circuit the costly XLoadQueryFont? */
423 if (slashes >= 13
424 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
425 && (*comp[11] >= '0' && *comp[11] <= '9'))
426 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
427
428 XFontStruct *f = XLoadQueryFont (DISPLAY, name);
429
430 if (f)
431 {
432 // the font should really exists now. if not, we have a problem
433 // (e.g. if the user did xset fp rehash just when we were searching fonts).
434 // in that case, just return garbage.
435 bool ret = set_properties (p, f);
436 XFreeFont (DISPLAY, f);
437 return ret;
438 }
439 else
440 return false;
441}
442
443// fix the size of scalable fonts
444static void
445fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop)
446{
447 int slashes = 0;
448 const char *size;
449
450 for (const char *c = name; *c; c++)
451 if (*c == '-')
452 {
453 if (slashes == 6)
454 size = c + 1;
455
456 if (++slashes >= 13)
457 break;
458 }
459
460 if (slashes >= 13 && size[0] == '0')
461 {
462 strncpy (buf, name, size - name);
463 buf += size - name;
464 buf += sprintf (buf, "%d", prop.height);
465 strcpy (buf, size + 1);
466 }
467 else
468 strcpy (buf, name);
469}
470
471bool
472rxvt_font_x11::load (const rxvt_fontprop &prop)
355{ 473{
356 clear (); 474 clear ();
357 475
358 char **list; 476 char **list;
359 int count; 477 int count;
360 XFontStruct *info;
361 list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); 478 list = XListFonts (DISPLAY, name, 512, &count);
479 set_name (0);
362 480
363 if (!list) 481 if (!list)
364 return false; 482 return false;
365 483
366 XFontStruct *best = 0; 484 int bestdiff = 0x7fffffff;
367 for (int i = 0; i < count; i++) 485 for (int i = 0; i < count; i++)
368 { 486 {
369 XFontStruct *f = info + i; 487 rxvt_fontprop p;
370 if (f->ascent + f->descent <= maxheight) // weed out too large fonts 488 char fname[1024];
489 fix_scalable (fname, list[i], prop);
490
491 if (!set_properties (p, fname))
492 continue;
493
494 if (p.height > prop.height) // weed out too large fonts
495 continue;
496
497 int diff = (prop.height - p.height) * 32
498 + abs (prop.weight - p.weight)
499 + abs (prop.slant - p.slant );
500
371 if (!best // compare against best found so far 501 if (!name // compare against best found so far
372 || best->ascent + best->descent < f->ascent + f->descent) 502 || diff < bestdiff)
503 {
504 set_name (strdup (fname));
373 best = f; 505 bestdiff = diff;
506 }
374 } 507 }
375 508
376 set_name (strdup (list[best - info])); 509 XFreeFontNames (list);
377 510
378 XFreeFontInfo (list, info, count); 511 if (!name)
512 return false;
379 513
380 f = XLoadQueryFont (DISPLAY, name); 514 f = XLoadQueryFont (DISPLAY, name);
381 515
382 if (!f) 516 if (!f)
383 return false; 517 return false;
384 518
385 unsigned long value; 519 unsigned long value;
386 520
387 const char *registry = get_property ("CHARSET_REGISTRY", 0); 521 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
388 const char *encoding = get_property ("CHARSET_ENCODING", 0); 522 const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
389 523
390 if (registry && encoding) 524 if (registry && encoding)
391 { 525 {
392 char charset[64]; 526 char charset[64];
393 snprintf (charset, 64, "%s-%s", registry, encoding); 527 snprintf (charset, 64, "%s-%s", registry, encoding);
394 528
395 cs = codeset_from_name (charset); 529 cs = codeset_from_name (charset);
396 } 530 }
397 else 531 else
398 { 532 {
399 const char *charset = get_property ("FONT", 0); 533 const char *charset = get_property (f, "FONT", 0);
400 534
401 if (!charset) 535 if (!charset)
402 charset = name; 536 charset = name;
403 537
404 int count = 13; 538 int count = 13;
417 551
418 ascent = f->ascent; 552 ascent = f->ascent;
419 descent = f->descent; 553 descent = f->descent;
420 height = ascent + descent; 554 height = ascent + descent;
421 555
422 prop = false; 556 slow = false;
423 557
424 if (f->min_bounds.width == f->max_bounds.width) 558 if (f->min_bounds.width == f->max_bounds.width)
425 width = f->min_bounds.width; 559 width = f->min_bounds.width;
426 else if (f->per_char == NULL) 560 else if (f->per_char == NULL)
427 width = f->max_bounds.width; 561 width = f->max_bounds.width;
428 else 562 else
429 { 563 {
430 prop = true; 564 slow = true;
431 565
432 int N = f->max_char_or_byte2 - f->min_char_or_byte2; 566 int N = f->max_char_or_byte2 - f->min_char_or_byte2;
433 567
434 if (encm) 568 if (encm)
435 N += (f->max_byte1 - f->min_byte1) 569 N += (f->max_byte1 - f->min_byte1)
520 // this looks like a mess /. 654 // this looks like a mess /.
521 // and it is a mess /. 655 // and it is a mess /.
522 // yet we are trying to be perfect /. 656 // yet we are trying to be perfect /.
523 // but the result still isn't perfect /. 657 // but the result still isn't perfect /.
524 658
525 bool slow = prop 659 bool slow = this->slow
526 || width != r->TermWin.fwidth 660 || width != r->TermWin.fwidth
527 || height != r->TermWin.fheight; 661 || height != r->TermWin.fheight;
528 662
529 int base = r->TermWin.fbase; 663 int base = r->TermWin.fbase;
530 664
605//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables 739//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
606#define SWATHBITS 8 740#define SWATHBITS 8
607#endif 741#endif
608 742
609struct rxvt_font_xft : rxvt_font { 743struct rxvt_font_xft : rxvt_font {
610#if 0
611 enum {
612 SWATHCOUNT = 1 << (21 - UNIBITS),
613 SWATHSIZE = 1 << (SWATHBITS - 5)
614 };
615 typedef uint32_t swath[SWATHSIZE];
616
617 swath *cvr[SWATHCOUNT];
618#endif
619
620#if 0
621 void gen_coverage_swath (unsigned int page);
622
623 bool has_char (uint32_t ch)
624 {
625 unsigned int page = ch >> SWATHBITS;
626 unsigned int idx = ch & ((1 << SWATHBITS) - 1);
627
628 if (page >= SWATHCOUNT)
629 return false;
630
631 if (!cvr[page]) gen_coverage_swath (page);
632
633 return cvr[page][idx >> 5] & (1 << (idx & 31));
634 }
635#endif
636 rxvt_font_xft () { f = 0; d = 0; } 744 rxvt_font_xft () { f = 0; d = 0; }
637 745
638 void clear (); 746 void clear ();
639 747
640 bool load (int maxheight); 748 rxvt_fontprop properties ();
749
750 bool load (const rxvt_fontprop &prop);
641 751
642 void draw (int x, int y, 752 void draw (int x, int y,
643 const text_t *text, int len, 753 const text_t *text, int len,
644 int fg, int bg); 754 int fg, int bg);
645 755
646 bool has_codepoint (uint32_t unicode); 756 bool has_codepoint (uint32_t unicode);
647 757
648protected: 758protected:
649 XftFont *f; 759 XftFont *f;
650 XftDraw *d; 760 XftDraw *d;
651
652#if 0
653 virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0;
654 void set_swath (uint32_t ch)
655 {
656 cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1));
657 }
658#endif
659}; 761};
660 762
661void 763void
662rxvt_font_xft::clear () 764rxvt_font_xft::clear ()
663{ 765{
670 if (d) 772 if (d)
671 { 773 {
672 XftDrawDestroy (d); 774 XftDrawDestroy (d);
673 d = 0; 775 d = 0;
674 } 776 }
777}
675 778
676#if 0 779rxvt_fontprop
677 for (int i = 0; i < SWATHCOUNT; i++) 780rxvt_font_xft::properties ()
678 delete cvr[i]; 781{
679#endif 782 rxvt_fontprop p;
783
784 FT_Face face = XftLockFace (f);
785
786 p.width = width; p.height = height;
787 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium;
788 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman;
789
790 XftUnlockFace (f);
791
792 return p;
680} 793}
681 794
682bool 795bool
683rxvt_font_xft::load (int maxheight) 796rxvt_font_xft::load (const rxvt_fontprop &prop)
684{ 797{
685#if 0 798#if 0
686 for (int i = 0; i < SWATHCOUNT; i++) 799 for (int i = 0; i < SWATHCOUNT; i++)
687 cvr[i] = 0; 800 cvr[i] = 0;
688#endif 801#endif
689 802
690 clear (); 803 clear ();
691 804
692 f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); 805 FcPattern *p = FcNameParse ((FcChar8 *) name);
806
807 if (!p)
808 return false;
809
810 FcValue v;
811
812 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
813 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
814
815 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)
816 FcPatternAddInteger (p, FC_SLANT, prop.slant);
817
818#if 0 // clipping unfortunately destroys our precious double-width-characters
819 // clip width, we can't do better, or can we?
820 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
821 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
822#endif
823
824 //FcPatternAddBool (p, FC_MINSPACE, 1);
825
826 XftResult result;
827 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result);
828
829 FcPatternDestroy (p);
830
831 if (!match)
832 return false;
833
834 f = XftFontOpenPattern (DISPLAY, match);
693 835
694 if (!f) 836 if (!f)
837 {
838 FcPatternDestroy (match);
695 return false; 839 return false;
840 }
696 841
697 FT_Face face = XftLockFace (f); 842 FT_Face face = XftLockFace (f);
698 843
699 prop = !FT_IS_FIXED_WIDTH (face); 844 slow = !FT_IS_FIXED_WIDTH (face);
700 845
701 int ftheight = 0; 846 int ftheight = 0;
702 847
703 for (;;) 848 for (;;)
704 { 849 {
706 FcChar8 c; 851 FcChar8 c;
707 852
708 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); 853 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1);
709 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); 854 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2);
710 855
711 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font 856 if (g1.xOff != g2.xOff) // don't simply trust the font
857 slow = true;
712 858
713 width = g2.xOff; 859 width = g2.xOff;
714 ascent = (face->size->metrics.ascender + 63) >> 6; 860 ascent = (face->size->metrics.ascender + 63) >> 6;
715 descent = (-face->size->metrics.descender + 63) >> 6; 861 descent = (-face->size->metrics.descender + 63) >> 6;
716 height = ascent + descent; 862 height = ascent + descent;
717 863
718 if (height <= maxheight || !maxheight) 864 if (height <= prop.height || !prop.height)
719 break; 865 break;
720 866
721 if (ftheight) 867 if (ftheight)
722 { 868 {
723 // take smaller steps near the end 869 // take smaller steps near the end
724 if (height > maxheight + 1) ftheight++; 870 if (height > prop.height + 1) ftheight++;
725 if (height > maxheight + 2) ftheight++; 871 if (height > prop.height + 2) ftheight++;
726 if (height > maxheight + 3) ftheight++; 872 if (height > prop.height + 3) ftheight++;
727 873
728 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); 874 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height);
729 } 875 }
730 else 876 else
731 FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); 877 FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height);
732 } 878 }
733 879
734 XftUnlockFace (f); 880 XftUnlockFace (f);
735 881
736 return true; 882 return true;
737} 883}
738
739#if 0
740void rxvt_font::gen_coverage_swath (unsigned int page)
741{
742 cvr[page] = new swath;
743
744 for (int i = 0; i < SWATHSIZE; i++)
745 cvr[page][i] = 0;
746
747 populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1);
748}
749#endif
750 884
751bool 885bool
752rxvt_font_xft::has_codepoint (uint32_t unicode) 886rxvt_font_xft::has_codepoint (uint32_t unicode)
753{ 887{
754 return XftCharExists (DISPLAY, f, unicode); 888 return XftCharExists (DISPLAY, f, unicode);
768 if (bg >= 0 && bg != Color_bg) 902 if (bg >= 0 && bg != Color_bg)
769 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); 903 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
770 else 904 else
771 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 905 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
772 906
773 if (!prop && width == r->TermWin.fwidth) 907 if (!slow && width == r->TermWin.fwidth && 0)
774 { 908 {
775 if (sizeof (text_t) == sizeof (FcChar16)) 909 if (sizeof (text_t) == sizeof (FcChar16))
776 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); 910 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
777 else 911 else
778 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); 912 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len);
781 { 915 {
782 while (len) 916 while (len)
783 { 917 {
784 if (*text != NOCHAR && *text != ' ') 918 if (*text != NOCHAR && *text != ' ')
785 { 919 {
920 XGlyphInfo extents;
786 if (sizeof (text_t) == sizeof (FcChar16)) 921 if (sizeof (text_t) == sizeof (FcChar16))
787 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); 922 {
923 XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents);
924 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (r->TermWin.fwidth - extents.width) / 2,
925 y + r->TermWin.fbase, (const FcChar16 *)text, 1);
926 }
788 else 927 else
789 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); 928 {
929 XGlyphInfo extents;
930 XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents);
931 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (r->TermWin.fwidth - extents.width) / 2,
932 y + r->TermWin.fbase, (const FcChar32 *)text, 1);
933 }
790 } 934 }
791 935
792 x += r->TermWin.fwidth; 936 x += r->TermWin.fwidth;
793 text++; 937 text++;
794 len--; 938 len--;
818 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) 962 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++)
819 FONT_UNREF (*i); 963 FONT_UNREF (*i);
820 964
821 fonts.clear (); 965 fonts.clear ();
822 base_id = 0; 966 base_id = 0;
823 height = 0x7fffffff; 967 base_prop.height = 0x7fffffff;
968 base_prop.weight = rxvt_fontprop::medium;
969 base_prop.slant = rxvt_fontprop::roman;
824 970
825 fallback = fallback_fonts; 971 fallback = fallback_fonts;
826} 972}
827 973
828rxvt_font * 974rxvt_font *
915 if (fonts[i]->loaded) 1061 if (fonts[i]->loaded)
916 return true; 1062 return true;
917 1063
918 fonts[i]->loaded = true; 1064 fonts[i]->loaded = true;
919 1065
920 if (!fonts[i]->load (height)) 1066 if (!fonts[i]->load (base_prop))
921 { 1067 {
922 fonts[i]->cs = CS_UNKNOWN; 1068 fonts[i]->cs = CS_UNKNOWN;
923 return false; 1069 return false;
924 } 1070 }
925 1071
938 1084
939 if (!base_id) 1085 if (!base_id)
940 base_id = 1; 1086 base_id = 1;
941 1087
942 // we currently need a base-font, no matter what 1088 // we currently need a base-font, no matter what
943 if (fonts.size () <= base_id) 1089 if (fonts.size () <= base_id || !realize_font (base_id))
944 { 1090 {
945 add_fonts ("fixed"); 1091 add_fonts ("fixed");
946 base_id = 1; 1092 base_id = fonts.size () - 1;
947 } 1093 }
948 1094
949 if (fonts.size () <= base_id || !realize_font (base_id)) 1095 if (fonts.size () <= base_id || !realize_font (base_id))
950 { 1096 {
951 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); 1097 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n");
952 exit (1); 1098 exit (1);
953 } 1099 }
954 1100
955 height = fonts[base_id]->height; 1101 base_prop = fonts[base_id]->properties ();
956
957 /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/
958} 1102}
959 1103
960int 1104int
961rxvt_fontset::find_font (uint32_t unicode) 1105rxvt_fontset::find_font (uint32_t unicode)
962{ 1106{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines