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

Comparing rxvt-unicode/src/rxvtfont.h (file contents):
Revision 1.24 by ayin, Thu Oct 18 09:11:43 2007 UTC vs.
Revision 1.44 by root, Thu Jun 17 00:49:20 2021 UTC

6# include <X11/Xft/Xft.h> 6# include <X11/Xft/Xft.h>
7#endif 7#endif
8 8
9#include <inttypes.h> 9#include <inttypes.h>
10 10
11#include "feature.h"
12#include "encoding.h" 11#include "encoding.h"
13#include "rxvtutil.h" 12#include "rxvtutil.h"
14#include "rxvttoolkit.h" 13#include "rxvttoolkit.h"
15 14
16struct rxvt_term; 15struct rxvt_term;
17 16
18struct rxvt_fontprop { 17struct rxvt_fontprop
18{
19 enum { 19 enum {
20 unset = -1, 20 unset = -1,
21 medium = 100, bold = 200, 21 medium = 100, bold = 200,
22 roman = 0, italic = 100, 22 roman = 0, italic = 100,
23 }; 23 };
24 int width, height, ascent; 24 int width, height, ascent;
25 int weight, slant; 25 int weight, slant;
26}; 26};
27 27
28struct rxvt_font { 28struct rxvt_font
29{
29 // managed by the fontset 30 // managed by the fontset
30 rxvt_term *term; 31 rxvt_term *term;
31 void set_term (rxvt_term *term) { this->term = term; } 32 void set_term (rxvt_term *term) { this->term = term; }
32 33
33 char *name; 34 char *name;
34 codeset cs; 35 codeset cs;
35 bool loaded; // wether we tried loading it before (not wether it's loaded) 36 bool loaded; // whether we tried loading it before (not whether it's loaded)
37 bool can_compose; // whether the font composes glyphs itself or not, should be a class method, but.. speed....
36 38
37 // managed by the font object 39 // managed by the font object
38 int ascent, descent, 40 int ascent, descent,
39 width, height; 41 width, height;
40 42
41 void set_name (char *name); 43 void set_name (char *name_);
42 44
43 rxvt_font (); 45 rxvt_font ();
44 virtual ~rxvt_font () { free (name); }; 46 virtual ~rxvt_font () { free (name); };
45 47
46 virtual void clear () { }; 48 virtual void clear () { };
54 56
55 virtual void draw (rxvt_drawable &d, 57 virtual void draw (rxvt_drawable &d,
56 int x, int y, 58 int x, int y,
57 const text_t *text, int len, 59 const text_t *text, int len,
58 int fg, int bg) = 0; 60 int fg, int bg) = 0;
61
62 void unref ()
63 {
64 clear ();
65 delete this;
66 }
59}; 67};
60
61#define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0)
62 68
63struct rxvt_fallback_font; 69struct rxvt_fallback_font;
64 70
65struct rxvt_fontset { 71struct rxvt_fontset
72{
66 char *fontdesc; 73 char *fontdesc;
74
75 // must be power-of-two - 1, also has to match RS_fontMask in rxvt.h
76#if USE_256_COLORS
77 enum { fontCount = 7 }; // 2 extra colors bits, 2 fewer fontcount bits
78#else
79 enum { fontCount = 31 };
80#endif
81
82 // index of first font in set
83 enum { firstFont = 2 };
67 84
68 rxvt_fontset (rxvt_term *term); 85 rxvt_fontset (rxvt_term *term);
69 ~rxvt_fontset (); 86 ~rxvt_fontset ();
70 87
71 bool populate (const char *desc); 88 bool populate (const char *desc);
72 void set_prop (const rxvt_fontprop &prop, bool force_prop) { this->prop = prop; this->force_prop = force_prop; } 89 void set_prop (const rxvt_fontprop &prop, bool force_prop) { this->prop = prop; this->force_prop = force_prop; }
73 int find_font (uint32_t unicode); 90 int find_font_idx (uint32_t unicode);
74 int find_font (const char *name) const; 91 int find_font (const char *name) const;
75 bool realize_font (int i); 92 bool realize_font (int i);
76 93
77 // font-id's MUST fit into a signed 16 bit integer, and within 0..255
78 rxvt_font *operator [] (int id) const 94 rxvt_font *operator [] (int id) const
79 { 95 {
80 return fonts[id & 0x7f]; 96 return fonts[id >> 1];
97 }
98
99 int
100 find_font (unicode_t unicode)
101 {
102 return min<int> ((fontCount << 1) | 1, find_font_idx (unicode));
81 } 103 }
82 104
83private: 105private:
84 rxvt_term *term; 106 rxvt_term *term;
85 rxvt_fontprop prop; 107 rxvt_fontprop prop;
86 bool force_prop; 108 bool force_prop;
87 simplevec<rxvt_font *> fonts; 109 simplevec<rxvt_font *> fonts;
88 const rxvt_fallback_font *fallback; 110 const rxvt_fallback_font *fallback;
89 111
90 typedef unsigned char pagemap[256]; 112 // this once was a "typedef xxx pagemap[256]
113 // but c++ arrays are not normal types, and cannot be
114 // put into containers, new doesn't work for them etc. etc.
115 // so we wrap out array into an object that acts like one. doh.
116 // example: C++ has no separate new and new [] forms,
117 // and if pagemap is char[256], new incorrectly assumes we want to
118 // allocate an array of chars instead of a single pagemap.
119 struct pagemap
120 {
121 unsigned char cppsucks[256];
122 unsigned char &operator [](int i) { return cppsucks [i]; };
123 };
91 vector<pagemap *> fmap; 124 vector<pagemap *> fmap;
92 125
93 void clear (); 126 void clear ();
94 rxvt_font *new_font (const char *name, codeset cs); 127 rxvt_font *new_font (const char *name, codeset cs);
128 void prepare_font (rxvt_font *font, codeset cs);
95 void add_fonts (const char *desc); 129 void add_fonts (const char *desc);
130 void push_font (rxvt_font *font);
96}; 131};
97 132
98#endif /* _DEFAULTFONT_H_ */ 133#endif /* _DEFAULTFONT_H_ */
99 134

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines