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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines