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.4 by pcg, Sat Nov 29 18:42:07 2003 UTC vs.
Revision 1.10 by pcg, Wed Dec 24 09:07:01 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 rxvt_fontprop properties (XFontStruct *f);
343
344 bool load (const rxvt_fontprop &prop);
328 345
329 bool has_codepoint (uint32_t unicode); 346 bool has_codepoint (uint32_t unicode);
330 347
331 void draw (int x, int y, 348 void draw (int x, int y,
332 const text_t *text, int len, 349 const text_t *text, int len,
334 351
335 XFontStruct *f; 352 XFontStruct *f;
336 codeset cs; 353 codeset cs;
337 bool enc2b, encm; 354 bool enc2b, encm;
338 355
339 const char *get_property (const char *property, const char *repl) const; 356 const char *get_property (XFontStruct *f, const char *property, const char *repl) const;
340}; 357};
341 358
342const char * 359const char *
343rxvt_font_x11::get_property (const char *property, const char *repl) const 360rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
344{ 361{
345 unsigned long value; 362 unsigned long value;
346 363
347 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 364 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
348 return XGetAtomName (DISPLAY, value); 365 return XGetAtomName (DISPLAY, value);
349 else 366 else
350 return repl; 367 return repl;
351} 368}
352 369
370rxvt_fontprop
371rxvt_font_x11::properties ()
372{
373 return properties (f);
374}
375
376rxvt_fontprop
377rxvt_font_x11::properties (XFontStruct *f)
378{
379 rxvt_fontprop p;
380
381 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
382 const char *slant = get_property (f, "SLANT", "r");
383
384 unsigned long avgwidth;
385 p.width = XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)
386 ? avgwidth / 10
387 : (height + 1) / 2;
388 p.height = height;
389 p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium;
390 p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic;
391
392 return p;
393}
394
353bool 395bool
354rxvt_font_x11::load (int maxheight) 396rxvt_font_x11::load (const rxvt_fontprop &prop)
355{ 397{
356 clear (); 398 clear ();
399
400 char **list;
401 int count;
402 XFontStruct *info;
403 list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info);
404
405 if (!list)
406 return false;
407
408 int bestdiff = 0x7fffffff;
409 XFontStruct *best = 0;
410 for (int i = 0; i < count; i++)
411 {
412 XFontStruct *f = info + i;
413
414 if (f->ascent + f->descent <= prop.height) // weed out too large fonts
415 {
416 rxvt_fontprop p = properties (f);
417 int diff = (prop.height - f->ascent + f->descent) * 32
418 + abs (prop.weight - p.weight)
419 + abs (prop.slant - p.slant );
420
421 if (!best // compare against best found so far
422 || diff < bestdiff)
423 {
424 best = f;
425 bestdiff = diff;
426 }
427 }
428 }
429
430 if (!best)
431 return false;
432
433 set_name (strdup (list[best - info]));
434
435 XFreeFontInfo (list, info, count);
357 436
358 f = XLoadQueryFont (DISPLAY, name); 437 f = XLoadQueryFont (DISPLAY, name);
359 438
360 if (!f) 439 if (!f)
361 return false; 440 return false;
362 441
363 unsigned long value; 442 unsigned long value;
364 443
365 const char *registry = get_property ("CHARSET_REGISTRY", 0); 444 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
366 const char *encoding = get_property ("CHARSET_ENCODING", 0); 445 const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
367 446
368 if (registry && encoding) 447 if (registry && encoding)
369 { 448 {
370 char charset[64]; 449 char charset[64];
371 snprintf (charset, 64, "%s-%s", registry, encoding); 450 snprintf (charset, 64, "%s-%s", registry, encoding);
372 451
373 cs = codeset_from_name (charset); 452 cs = codeset_from_name (charset);
374 } 453 }
375 else 454 else
376 { 455 {
377 const char *charset = get_property ("FONT", 0); 456 const char *charset = get_property (f, "FONT", 0);
378 457
379 if (!charset) 458 if (!charset)
380 charset = name; 459 charset = name;
381 460
382 int count = 13; 461 int count = 13;
395 474
396 ascent = f->ascent; 475 ascent = f->ascent;
397 descent = f->descent; 476 descent = f->descent;
398 height = ascent + descent; 477 height = ascent + descent;
399 478
400 prop = false; 479 slow = false;
401 480
402 if (f->min_bounds.width == f->max_bounds.width) 481 if (f->min_bounds.width == f->max_bounds.width)
403 width = f->min_bounds.width; 482 width = f->min_bounds.width;
404 else if (f->per_char == NULL) 483 else if (f->per_char == NULL)
405 width = f->max_bounds.width; 484 width = f->max_bounds.width;
406 else 485 else
407 { 486 {
408 prop = true; 487 slow = true;
409 488
410 int N = f->max_char_or_byte2 - f->min_char_or_byte2; 489 int N = f->max_char_or_byte2 - f->min_char_or_byte2;
411 490
412 if (encm) 491 if (encm)
413 N += (f->max_byte1 - f->min_byte1) 492 N += (f->max_byte1 - f->min_byte1)
498 // this looks like a mess /. 577 // this looks like a mess /.
499 // and it is a mess /. 578 // and it is a mess /.
500 // yet we are trying to be perfect /. 579 // yet we are trying to be perfect /.
501 // but the result still isn't perfect /. 580 // but the result still isn't perfect /.
502 581
503 bool slow = prop 582 bool slow = this->slow
504 || width != r->TermWin.fwidth 583 || width != r->TermWin.fwidth
505 || height != r->TermWin.fheight; 584 || height != r->TermWin.fheight;
506 585
507 int base = r->TermWin.fbase; 586 int base = r->TermWin.fbase;
508 587
583//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables 662//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
584#define SWATHBITS 8 663#define SWATHBITS 8
585#endif 664#endif
586 665
587struct rxvt_font_xft : rxvt_font { 666struct rxvt_font_xft : rxvt_font {
588#if 0
589 enum {
590 SWATHCOUNT = 1 << (21 - UNIBITS),
591 SWATHSIZE = 1 << (SWATHBITS - 5)
592 };
593 typedef uint32_t swath[SWATHSIZE];
594
595 swath *cvr[SWATHCOUNT];
596#endif
597
598#if 0
599 void gen_coverage_swath (unsigned int page);
600
601 bool has_char (uint32_t ch)
602 {
603 unsigned int page = ch >> SWATHBITS;
604 unsigned int idx = ch & ((1 << SWATHBITS) - 1);
605
606 if (page >= SWATHCOUNT)
607 return false;
608
609 if (!cvr[page]) gen_coverage_swath (page);
610
611 return cvr[page][idx >> 5] & (1 << (idx & 31));
612 }
613#endif
614 rxvt_font_xft () { f = 0; d = 0; } 667 rxvt_font_xft () { f = 0; d = 0; }
615 668
616 void clear (); 669 void clear ();
617 670
618 bool load (int maxheight); 671 rxvt_fontprop properties ();
672
673 bool load (const rxvt_fontprop &prop);
619 674
620 void draw (int x, int y, 675 void draw (int x, int y,
621 const text_t *text, int len, 676 const text_t *text, int len,
622 int fg, int bg); 677 int fg, int bg);
623 678
624 bool has_codepoint (uint32_t unicode); 679 bool has_codepoint (uint32_t unicode);
625 680
626protected: 681protected:
627 XftFont *f; 682 XftFont *f;
628 XftDraw *d; 683 XftDraw *d;
629
630#if 0
631 virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0;
632 void set_swath (uint32_t ch)
633 {
634 cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1));
635 }
636#endif
637}; 684};
638 685
639void 686void
640rxvt_font_xft::clear () 687rxvt_font_xft::clear ()
641{ 688{
648 if (d) 695 if (d)
649 { 696 {
650 XftDrawDestroy (d); 697 XftDrawDestroy (d);
651 d = 0; 698 d = 0;
652 } 699 }
700}
653 701
654#if 0 702rxvt_fontprop
655 for (int i = 0; i < SWATHCOUNT; i++) 703rxvt_font_xft::properties ()
656 delete cvr[i]; 704{
657#endif 705 rxvt_fontprop p;
706
707 FT_Face face = XftLockFace (f);
708
709 p.width = width; p.height = height;
710 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium;
711 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman;
712
713 XftUnlockFace (f);
714
715 return p;
658} 716}
659 717
660bool 718bool
661rxvt_font_xft::load (int maxheight) 719rxvt_font_xft::load (const rxvt_fontprop &prop)
662{ 720{
663#if 0 721#if 0
664 for (int i = 0; i < SWATHCOUNT; i++) 722 for (int i = 0; i < SWATHCOUNT; i++)
665 cvr[i] = 0; 723 cvr[i] = 0;
666#endif 724#endif
667 725
668 clear (); 726 clear ();
669 727
670 f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); 728 FcPattern *p = FcNameParse ((FcChar8 *) name);
729
730 if (!p)
731 return false;
732
733 FcValue v;
734
735 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
736 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
737
738 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)
739 FcPatternAddInteger (p, FC_SLANT, prop.slant);
740
741 // clip width, we can't do better, or can we?
742 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
743 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
744
745 //FcPatternAddBool (p, FC_MINSPACE, 1);
746
747 XftResult result;
748 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result);
749
750 FcPatternDestroy (p);
751
752 if (!match)
753 return false;
754
755 f = XftFontOpenPattern (DISPLAY, match);
671 756
672 if (!f) 757 if (!f)
758 {
759 FcPatternDestroy (match);
673 return false; 760 return false;
761 }
674 762
675 FT_Face face = XftLockFace (f); 763 FT_Face face = XftLockFace (f);
676 764
677 prop = !FT_IS_FIXED_WIDTH (face); 765 slow = !FT_IS_FIXED_WIDTH (face);
678 766
679 int ftheight = 0; 767 int ftheight = 0;
680 768
681 for (;;) 769 for (;;)
682 { 770 {
684 FcChar8 c; 772 FcChar8 c;
685 773
686 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); 774 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1);
687 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); 775 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2);
688 776
689 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font 777 if (g1.xOff != g2.xOff) // don't simply trust the font
778 slow = true;
690 779
691 width = g2.xOff; 780 width = g2.xOff;
692 ascent = (face->size->metrics.ascender + 63) >> 6; 781 ascent = (face->size->metrics.ascender + 63) >> 6;
693 descent = (-face->size->metrics.descender + 63) >> 6; 782 descent = (-face->size->metrics.descender + 63) >> 6;
694 height = ascent + descent; 783 height = ascent + descent;
695 784
696 if (height <= maxheight || !maxheight) 785 if (height <= prop.height || !prop.height)
697 break; 786 break;
698 787
699 if (ftheight) 788 if (ftheight)
700 { 789 {
701 // take smaller steps near the end 790 // take smaller steps near the end
702 if (height > maxheight + 1) ftheight++; 791 if (height > prop.height + 1) ftheight++;
703 if (height > maxheight + 2) ftheight++; 792 if (height > prop.height + 2) ftheight++;
704 if (height > maxheight + 3) ftheight++; 793 if (height > prop.height + 3) ftheight++;
705 794
706 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); 795 FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height);
707 } 796 }
708 else 797 else
709 FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); 798 FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height);
710 } 799 }
711 800
712 XftUnlockFace (f); 801 XftUnlockFace (f);
713 802
714 return true; 803 return true;
715} 804}
716
717#if 0
718void rxvt_font::gen_coverage_swath (unsigned int page)
719{
720 cvr[page] = new swath;
721
722 for (int i = 0; i < SWATHSIZE; i++)
723 cvr[page][i] = 0;
724
725 populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1);
726}
727#endif
728 805
729bool 806bool
730rxvt_font_xft::has_codepoint (uint32_t unicode) 807rxvt_font_xft::has_codepoint (uint32_t unicode)
731{ 808{
732 return XftCharExists (DISPLAY, f, unicode); 809 return XftCharExists (DISPLAY, f, unicode);
746 if (bg >= 0 && bg != Color_bg) 823 if (bg >= 0 && bg != Color_bg)
747 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); 824 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
748 else 825 else
749 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 826 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
750 827
751 if (!prop && width == r->TermWin.fwidth) 828 if (!slow && width == r->TermWin.fwidth)
752 { 829 {
753 if (sizeof (text_t) == sizeof (FcChar16)) 830 if (sizeof (text_t) == sizeof (FcChar16))
754 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); 831 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
755 else 832 else
756 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); 833 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len);
796 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) 873 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++)
797 FONT_UNREF (*i); 874 FONT_UNREF (*i);
798 875
799 fonts.clear (); 876 fonts.clear ();
800 base_id = 0; 877 base_id = 0;
801 height = 0x7fffffff; 878 base_prop.height = 0x7fffffff;
879 base_prop.weight = rxvt_fontprop::medium;
880 base_prop.slant = rxvt_fontprop::roman;
802 881
803 fallback = fallback_fonts; 882 fallback = fallback_fonts;
804} 883}
805 884
806rxvt_font * 885rxvt_font *
891rxvt_fontset::realize_font (int i) 970rxvt_fontset::realize_font (int i)
892{ 971{
893 if (fonts[i]->loaded) 972 if (fonts[i]->loaded)
894 return true; 973 return true;
895 974
896 if (fonts[i]->load (height))
897 return fonts[i]->loaded = true; 975 fonts[i]->loaded = true;
898 976
899 delete fonts[i]; 977 if (!fonts[i]->load (base_prop))
900 fonts.erase (fonts.begin () + i); 978 {
901 979 fonts[i]->cs = CS_UNKNOWN;
902 return false; 980 return false;
981 }
982
983 return true;
903} 984}
904 985
905void 986void
906rxvt_fontset::populate (const char *desc) 987rxvt_fontset::populate (const char *desc)
907{ 988{
914 995
915 if (!base_id) 996 if (!base_id)
916 base_id = 1; 997 base_id = 1;
917 998
918 // we currently need a base-font, no matter what 999 // we currently need a base-font, no matter what
919 if (fonts.size () <= base_id) 1000 if (fonts.size () <= base_id || !realize_font (base_id))
920 { 1001 {
921 add_fonts ("fixed"); 1002 add_fonts ("fixed");
922 base_id = 1; 1003 base_id = fonts.size () - 1;
923 } 1004 }
924 1005
925 if (fonts.size () <= base_id || !realize_font (base_id)) 1006 if (fonts.size () <= base_id || !realize_font (base_id))
926 { 1007 {
927 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); 1008 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n");
928 exit (1); 1009 exit (1);
929 } 1010 }
930 1011
931 height = fonts[base_id]->height; 1012 base_prop = fonts[base_id]->properties ();
932
933 /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/
934} 1013}
935 1014
936int 1015int
937rxvt_fontset::find_font (uint32_t unicode) 1016rxvt_fontset::find_font (uint32_t unicode)
938{ 1017{
944 { 1023 {
945 if (FROM_UNICODE (f->cs, unicode) == NOCHAR) 1024 if (FROM_UNICODE (f->cs, unicode) == NOCHAR)
946 goto next_font; 1025 goto next_font;
947 1026
948 if (!realize_font (i)) 1027 if (!realize_font (i))
949 {
950 --i;
951 goto next_font; 1028 goto next_font;
952 } 1029 }
953 1030
954 //printf ("added font %s for %04lx\n", f->name, unicode);
955 }
956
957 if (f->has_codepoint (unicode)) 1031 if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode))
958 return i; 1032 return i;
959 1033
960 next_font: 1034 next_font:
961 if (i == fonts.size () - 1 && fallback->name) 1035 if (i == fonts.size () - 1 && fallback->name)
962 { 1036 {
963 fonts.push_back (new_font (fallback->name, fallback->cs)); 1037 fonts.push_back (new_font (fallback->name, fallback->cs));
964 fallback++; 1038 fallback++;
1039 i = 0;
965 } 1040 }
966 } 1041 }
967 1042
968 return 0; /* we must return SOME font */ 1043 return 0; /* we must return SOME font */
969} 1044}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines