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.47 by pcg, Tue Mar 16 06:04:28 2004 UTC vs.
Revision 1.52 by pcg, Thu Apr 8 20:31:45 2004 UTC

1/*--------------------------------*-C-*---------------------------------*; 1/*--------------------------------*-C-*---------------------------------*
2 * File: defaultfont.C 2 * File: defaultfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
230 bool has_codepoint (unicode_t unicode) 230 bool has_codepoint (unicode_t unicode)
231 { 231 {
232 if (unicode <= 0x001f) 232 if (unicode <= 0x001f)
233 return true; 233 return true;
234 234
235 if (unicode >= 0x0080 && unicode <= 0x009f) 235 if (unicode <= 0x007f)
236 return false;
237
238 if (unicode <= 0x009f)
236 return true; 239 return true;
237 240
238 if (unicode >= 0x2500 && unicode <= 0x259f) 241 if (unicode >= 0x2500 && unicode <= 0x259f)
239 return true; 242 return true;
240 243
408 411
409 XFontStruct *f; 412 XFontStruct *f;
410 codeset cs; 413 codeset cs;
411 bool enc2b, encm; 414 bool enc2b, encm;
412 415
413 const char *get_property (XFontStruct *f, const char *property, const char *repl) const; 416 char *get_property (XFontStruct *f, const char *property, const char *repl) const;
414 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); 417 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
415 bool set_properties (rxvt_fontprop &p, XFontStruct *f); 418 bool set_properties (rxvt_fontprop &p, XFontStruct *f);
416 bool set_properties (rxvt_fontprop &p, const char *name); 419 bool set_properties (rxvt_fontprop &p, const char *name);
417}; 420};
418 421
419const char * 422char *
420rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 423rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
421{ 424{
422 unsigned long value; 425 unsigned long value;
423 426
424 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 427 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
425 return XGetAtomName (DISPLAY, value); 428 return XGetAtomName (DISPLAY, value);
426 else 429 else
427 return repl; 430 return rxvt_strdup (repl);
428} 431}
429 432
430rxvt_fontprop 433rxvt_fontprop
431rxvt_font_x11::properties () 434rxvt_font_x11::properties ()
432{ 435{
447} 450}
448 451
449bool 452bool
450rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 453rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
451{ 454{
452 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
453 const char *slant = get_property (f, "SLANT", "r");
454
455 unsigned long height; 455 unsigned long height;
456 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 456 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
457 return false; 457 return false;
458 458
459 unsigned long avgwidth; 459 unsigned long avgwidth;
460 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 460 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
461 avgwidth = 0; 461 avgwidth = 0;
462 462
463 char *weight = get_property (f, "WEIGHT_NAME", "medium");
464 char *slant = get_property (f, "SLANT", "r");
465
463 return set_properties (p, height, weight, slant, avgwidth); 466 set_properties (p, height, weight, slant, avgwidth);
467
468 free (weight);
469 free (slant);
470
471 return true;
464} 472}
465 473
466bool 474bool
467rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 475rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
468{ 476{
572 f = XLoadQueryFont (DISPLAY, name); 580 f = XLoadQueryFont (DISPLAY, name);
573 581
574 if (!f) 582 if (!f)
575 return false; 583 return false;
576 584
577 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 585 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
578 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 586 char *encoding = get_property (f, "CHARSET_ENCODING", 0);
579 587
580 if (registry && encoding) 588 if (registry && encoding)
581 { 589 {
582 char charset[64]; 590 char charset[64];
583 snprintf (charset, 64, "%s-%s", registry, encoding); 591 snprintf (charset, 64, "%s-%s", registry, encoding);
596 if (*charset++ == '-' && !--count) 604 if (*charset++ == '-' && !--count)
597 break; 605 break;
598 606
599 cs = codeset_from_name (charset); 607 cs = codeset_from_name (charset);
600 } 608 }
609
610 free (registry);
611 free (encoding);
601 612
602 if (cs == CS_UNICODE) 613 if (cs == CS_UNICODE)
603 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 614 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
604 615
605 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 616 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
718 729
719 int base = r->TermWin.fbase; 730 int base = r->TermWin.fbase;
720 731
721 XGCValues v; 732 XGCValues v;
722 v.foreground = r->PixColors[fg]; 733 v.foreground = r->PixColors[fg];
723 v.background = r->PixColors[bg];
724 v.font = f->fid; 734 v.font = f->fid;
725 735
726 if (enc2b) 736 if (enc2b)
727 { 737 {
728 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 738 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
729 739
730 if (bg == Color_bg && !slow) 740 if (bg == Color_bg && !slow)
731 { 741 {
742 v.background = r->PixColors[bg];
732 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 743 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
733 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 744 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
734 } 745 }
735 else 746 else
736 { 747 {
758 { 769 {
759 const char *xc = enc_char (text, len, cs, slow); 770 const char *xc = enc_char (text, len, cs, slow);
760 771
761 if (bg == Color_bg && !slow) 772 if (bg == Color_bg && !slow)
762 { 773 {
774 v.background = r->PixColors[bg];
763 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 775 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
764 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 776 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
765 } 777 }
766 else 778 else
767 { 779 {
986#endif 998#endif
987 999
988///////////////////////////////////////////////////////////////////////////// 1000/////////////////////////////////////////////////////////////////////////////
989 1001
990rxvt_fontset::rxvt_fontset (rxvt_t r) 1002rxvt_fontset::rxvt_fontset (rxvt_t r)
991: r (r) 1003: r (r), fontdesc (0)
992{ 1004{
993 clear (); 1005 clear ();
994} 1006}
995 1007
996rxvt_fontset::~rxvt_fontset () 1008rxvt_fontset::~rxvt_fontset ()
1001void 1013void
1002rxvt_fontset::clear () 1014rxvt_fontset::clear ()
1003{ 1015{
1004 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1016 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1005 FONT_UNREF (*i); 1017 FONT_UNREF (*i);
1018
1019 free (fontdesc); fontdesc = 0;
1006 1020
1007 fonts.clear (); 1021 fonts.clear ();
1008 base_id = 0; 1022 base_id = 0;
1009 base_prop.height = 0x7fffffff; 1023 base_prop.height = 0x7fffffff;
1010 base_prop.weight = rxvt_fontprop::medium; 1024 base_prop.weight = rxvt_fontprop::medium;
1118bool 1132bool
1119rxvt_fontset::populate (const char *desc) 1133rxvt_fontset::populate (const char *desc)
1120{ 1134{
1121 clear (); 1135 clear ();
1122 1136
1137 fontdesc = strdup (desc);
1138
1123 fonts.push_back (new_font (0, CS_UNICODE)); 1139 fonts.push_back (new_font (0, CS_UNICODE));
1124 realize_font (0); 1140 realize_font (0);
1125 1141
1126 add_fonts (desc); 1142 add_fonts (desc);
1127 1143
1145} 1161}
1146 1162
1147int 1163int
1148rxvt_fontset::find_font (unicode_t unicode) 1164rxvt_fontset::find_font (unicode_t unicode)
1149{ 1165{
1150 for (unsigned int i = 0; i < fonts.size (); i++) 1166 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii
1167 i < fonts.size ();
1168 i++)
1151 { 1169 {
1152 rxvt_font *f = fonts[i]; 1170 rxvt_font *f = fonts[i];
1153 1171
1154 if (!f->loaded) 1172 if (!f->loaded)
1155 { 1173 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines