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.13 by pcg, Fri Dec 26 08:18:45 2003 UTC vs.
Revision 1.23 by pcg, Sun Feb 22 08:28:36 2004 UTC

1/*--------------------------------*-C-*---------------------------------*; 1/*--------------------------------*-C-*---------------------------------*;
2 * File: defaultfont.C 2 * File: defaultfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003 Marc Lehmann rxvt@plan9.de> 4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
23#include "rxvt.h" 23#include "rxvt.h"
24#include "defaultfont.h" 24#include "defaultfont.h"
25 25
26#include <cstdlib> 26#include <cstdlib>
27 27
28#define DISPLAY r->Xdisplay 28#define DISPLAY r->display->display
29#define DRAWABLE r->TermWin.vt 29#define DRAWABLE r->TermWin.vt
30#define GC r->TermWin.gc 30#define GC r->TermWin.gc
31 31
32const struct rxvt_fallback_font { 32const struct rxvt_fallback_font {
33 codeset cs; 33 codeset cs;
73 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 73 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
74 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, 74 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" },
75 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, 75 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" },
76 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, 76 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" },
77# endif 77# endif
78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-1" }, 79 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" },
79 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-2" }, 80 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" },
80 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-3" }, 81 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" },
81 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-4" }, 82 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" },
82 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-5" }, 83 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" },
83 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-6" }, 84 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" },
84 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-7" }, 85 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" },
85 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-f" }, 86 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" },
86#endif 87#endif
87 88
88#if XFT 89#if XFT
89 { CS_UNICODE, "xft:Andale Mono" }, 90 { CS_UNICODE, "xft:Andale Mono" },
90 { CS_UNICODE, "xft:Arial Unicode MS" }, 91 { CS_UNICODE, "xft:Arial Unicode MS" },
102 103
103static void *enc_buf; 104static void *enc_buf;
104static uint32_t enc_len; 105static uint32_t enc_len;
105 106
106static inline void * 107static inline void *
107get_enc_buf (int len) 108get_enc_buf (uint32_t len)
108{ 109{
109 if (len > enc_len) 110 if (len > enc_len)
110 { 111 {
111 free (enc_buf); 112 free (enc_buf);
112 enc_buf = malloc (len); 113 enc_buf = malloc (len);
114 115
115 return enc_buf; 116 return enc_buf;
116} 117}
117 118
118static const char * 119static const char *
119enc_char (const text_t *text, int len, codeset cs, bool &zero) 120enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
120{ 121{
121 uint8_t *buf = (uint8_t *)get_enc_buf (len); 122 uint8_t *buf = (uint8_t *)get_enc_buf (len);
122 123
123 while (len--) 124 while (len--)
124 { 125 {
135 136
136 return (const char *)enc_buf; 137 return (const char *)enc_buf;
137} 138}
138 139
139static const XChar2b * 140static const XChar2b *
140enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) 141enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
141{ 142{
142 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 143 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b));
143 144
144 while (len--) 145 while (len--)
145 { 146 {
427 428
428 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 429 XFontStruct *f = XLoadQueryFont (DISPLAY, name);
429 430
430 if (f) 431 if (f)
431 { 432 {
432 // the font should really exists now. if not, we have a problem 433 // the font should really exist now. if not, we have a problem
433 // (e.g. if the user did xset fp rehash just when we were searching fonts). 434 // (e.g. if the user did xset fp rehash just when we were searching fonts).
434 // in that case, just return garbage. 435 // in that case, just return garbage.
435 bool ret = set_properties (p, f); 436 bool ret = set_properties (p, f);
436 XFreeFont (DISPLAY, f); 437 XFreeFont (DISPLAY, f);
437 return ret; 438 return ret;
514 f = XLoadQueryFont (DISPLAY, name); 515 f = XLoadQueryFont (DISPLAY, name);
515 516
516 if (!f) 517 if (!f)
517 return false; 518 return false;
518 519
519 unsigned long value;
520
521 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 520 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
522 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 521 const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
523 522
524 if (registry && encoding) 523 if (registry && encoding)
525 { 524 {
611 /* check wether the character exists in _this_ font. horrible. */ 610 /* check wether the character exists in _this_ font. horrible. */
612 XCharStruct *xcs; 611 XCharStruct *xcs;
613 612
614 if (encm) 613 if (encm)
615 { 614 {
616 int byte1 = ch >> 8; 615 unsigned char byte1 = ch >> 8;
617 int byte2 = ch & 255; 616 unsigned char byte2 = ch & 255;
618 617
619 if (byte1 < f->min_byte1 || byte1 > f->max_byte1 618 if (byte1 < f->min_byte1 || byte1 > f->max_byte1
620 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) 619 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2)
621 return false; 620 return false;
622 621
761}; 760};
762 761
763void 762void
764rxvt_font_xft::clear () 763rxvt_font_xft::clear ()
765{ 764{
765 if (d)
766 {
767 XftDrawDestroy (d);
768 d = 0;
769 }
770
766 if (f) 771 if (f)
767 { 772 {
768 XftFontClose (DISPLAY, f); 773 XftFontClose (DISPLAY, f);
769 f = 0; 774 f = 0;
770 }
771
772 if (d)
773 {
774 XftDrawDestroy (d);
775 d = 0;
776 } 775 }
777} 776}
778 777
779rxvt_fontprop 778rxvt_fontprop
780rxvt_font_xft::properties () 779rxvt_font_xft::properties ()
891void 890void
892rxvt_font_xft::draw (int x, int y, 891rxvt_font_xft::draw (int x, int y,
893 const text_t *text, int len, 892 const text_t *text, int len,
894 int fg, int bg) 893 int fg, int bg)
895{ 894{
896 if (!d) 895 d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap);
897 {
898 dR;
899 d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP);
900 }
901 896
902 if (bg >= 0 && bg != Color_bg) 897 if (bg >= 0 && bg != Color_bg)
903 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); 898 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
904 else 899 else
905 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 900 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
946#endif 941#endif
947 942
948///////////////////////////////////////////////////////////////////////////// 943/////////////////////////////////////////////////////////////////////////////
949 944
950rxvt_fontset::rxvt_fontset (rxvt_t r) 945rxvt_fontset::rxvt_fontset (rxvt_t r)
951#ifdef EXPLICIT_CONTEXT
952: r(r) 946: r (r)
953#endif
954{ 947{
955 clear (); 948 clear ();
956} 949}
957 950
958rxvt_fontset::~rxvt_fontset () 951rxvt_fontset::~rxvt_fontset ()
961} 954}
962 955
963void 956void
964rxvt_fontset::clear () 957rxvt_fontset::clear ()
965{ 958{
966 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) 959 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
967 FONT_UNREF (*i); 960 FONT_UNREF (*i);
968 961
969 fonts.clear (); 962 fonts.clear ();
970 base_id = 0; 963 base_id = 0;
971 base_prop.height = 0x7fffffff; 964 base_prop.height = 0x7fffffff;
1025 1018
1026 if (*desc == '[') 1019 if (*desc == '[')
1027 { 1020 {
1028 fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); 1021 fprintf (stderr, "extra font parameters not yet supported, skipping.\n");
1029 1022
1030 const char *extra = desc++; 1023 //const char *extra = desc++; // not yet used
1031 1024
1032 desc = strchr (desc, ']'); 1025 desc = strchr (desc, ']');
1033 1026
1034 if (!desc) 1027 if (!desc)
1035 { 1028 {
1074 } 1067 }
1075 1068
1076 return true; 1069 return true;
1077} 1070}
1078 1071
1079void 1072bool
1080rxvt_fontset::populate (const char *desc) 1073rxvt_fontset::populate (const char *desc)
1081{ 1074{
1082 clear (); 1075 clear ();
1083 1076
1084 fonts.push_back (new_font (0, CS_UNICODE)); 1077 fonts.push_back (new_font (0, CS_UNICODE));
1088 1081
1089 if (!base_id) 1082 if (!base_id)
1090 base_id = 1; 1083 base_id = 1;
1091 1084
1092 // we currently need a base-font, no matter what 1085 // we currently need a base-font, no matter what
1093 if (fonts.size () <= base_id || !realize_font (base_id)) 1086 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1094 { 1087 {
1095 puts ("unable to load specified font(s), falling back to 'fixed'\n"); 1088 puts ("unable to load specified font (s), falling back to 'fixed'\n");
1096 add_fonts ("fixed"); 1089 add_fonts ("fixed");
1097 base_id = fonts.size () - 1; 1090 base_id = fonts.size () - 1;
1098 } 1091 }
1099 1092
1100 if (fonts.size () <= base_id || !realize_font (base_id)) 1093 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1101 { 1094 return false;
1102 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n");
1103 exit (1);
1104 }
1105 1095
1106 base_prop = fonts[base_id]->properties (); 1096 base_prop = fonts[base_id]->properties ();
1097
1098 return true;
1107} 1099}
1108 1100
1109int 1101int
1110rxvt_fontset::find_font (uint32_t unicode) 1102rxvt_fontset::find_font (uint32_t unicode)
1111{ 1103{
1112 for (int i = 0; i < fonts.size (); i++) 1104 for (unsigned int i = 0; i < fonts.size (); i++)
1113 { 1105 {
1114 rxvt_font *f = fonts[i]; 1106 rxvt_font *f = fonts[i];
1115 1107
1116 if (!f->loaded) 1108 if (!f->loaded)
1117 { 1109 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines