1 | /* |
1 | #ifndef DEFAULTFONT_H_ |
2 | * $Id: defaultfont.h,v 1.5 2003/11/25 15:25:17 pcg Exp $ |
2 | #define DEFAULTFONT_H_ |
3 | */ |
|
|
4 | |
3 | |
5 | #ifndef _DEFAULTFONT_H_ |
4 | #include <X11/Xlib.h> |
6 | #define _DEFAULTFONT_H_ |
5 | #if XFT |
|
|
6 | # include <X11/Xft/Xft.h> |
|
|
7 | #endif |
7 | |
8 | |
8 | #ifdef HAVE_XSETLOCALE |
9 | #ifdef HAVE_XSETLOCALE |
9 | # define X_LOCALE |
10 | # define X_LOCALE |
10 | # include <X11/Xlocale.h> |
11 | # include <X11/Xlocale.h> |
11 | #else |
12 | #else |
12 | # ifdef HAVE_SETLOCALE |
13 | # ifdef HAVE_SETLOCALE |
13 | # include <locale.h> |
14 | # include <clocale> |
14 | # endif |
15 | # endif |
15 | #endif /* HAVE_XLOCALE */ |
16 | #endif /* HAVE_XLOCALE */ |
16 | |
17 | |
17 | #ifdef HAVE_NL_LANGINFO |
18 | #ifdef HAVE_NL_LANGINFO |
18 | # include <langinfo.h> |
19 | # include <langinfo.h> |
19 | #endif |
20 | #endif |
20 | |
21 | |
21 | #include "rxvtlib.h" |
22 | #include "rxvtlib.h" |
22 | #include "feature.h" |
23 | #include "feature.h" |
23 | #include "encoding.h" |
24 | #include "encoding.h" |
24 | #include "rxvtvec.h" |
25 | #include "rxvtstl.h" |
|
|
26 | |
|
|
27 | struct rxvt_fontprop { |
|
|
28 | enum { |
|
|
29 | medium = 100, bold = 200, |
|
|
30 | roman = 0, italic = 100, |
|
|
31 | }; |
|
|
32 | int width, height; |
|
|
33 | int weight, slant; |
|
|
34 | }; |
|
|
35 | |
|
|
36 | struct rxvt_drawable { |
|
|
37 | rxvt_display *display; |
|
|
38 | Drawable drawable; |
|
|
39 | #if XFT |
|
|
40 | XftDraw *xftdrawable; |
|
|
41 | operator XftDraw *(); |
|
|
42 | #endif |
|
|
43 | |
|
|
44 | rxvt_drawable (rxvt_display *display, Drawable drawable) |
|
|
45 | : display(display), |
|
|
46 | #if XFT |
|
|
47 | xftdrawable(0), |
|
|
48 | #endif |
|
|
49 | drawable(drawable) |
|
|
50 | { } |
|
|
51 | |
|
|
52 | #if XFT |
|
|
53 | ~rxvt_drawable (); |
|
|
54 | #endif |
|
|
55 | |
|
|
56 | operator Drawable() { return drawable; } |
|
|
57 | }; |
25 | |
58 | |
26 | struct rxvt_font { |
59 | struct rxvt_font { |
|
|
60 | struct rxvt_fontset *fs; |
27 | // managed by the fontset |
61 | // managed by the fontset |
28 | rxvt_t r; |
62 | rxvt_t r; |
29 | void set_term (rxvt_t r) { this->r = r; } |
63 | void set_term (rxvt_t r) { this->r = r; } |
30 | |
64 | |
31 | char *name; |
65 | char *name; |
32 | codeset cs; |
66 | codeset cs; |
33 | bool loaded; |
67 | bool loaded; // wether we tried loading it before (not wether it's loaded) |
34 | |
68 | |
35 | // managed by the font object |
69 | // managed by the font object |
36 | bool prop; // wether this is a proportional font or has other funny characteristics |
70 | bool slow; // wether this is a proportional font or has other funny characteristics |
37 | int ascent, descent, |
71 | int ascent, descent, |
38 | width, height; |
72 | width, height; |
39 | |
73 | |
40 | void set_name (char *name) |
74 | void set_name (char *name) |
41 | { |
75 | { |
42 | if (this->name) free (this->name); // let the compiler optimize |
76 | if (this->name) free (this->name); // let the compiler optimize |
43 | this->name = name; |
77 | this->name = name; |
44 | } |
78 | } |
45 | |
79 | |
46 | rxvt_font () { name = 0; } |
80 | rxvt_font () { name = 0; } |
47 | ~rxvt_font () { free (name); clear (); }; |
81 | ~rxvt_font () { free (name); }; |
48 | |
82 | |
49 | void clear_rect (int x, int y, int w, int h, int color); |
83 | void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color); |
50 | |
84 | |
51 | virtual void clear () { }; |
85 | virtual void clear () { }; |
52 | |
86 | |
53 | virtual bool load (int maxheight) = 0; |
87 | virtual rxvt_fontprop properties () = 0; |
|
|
88 | |
|
|
89 | virtual bool load (const rxvt_fontprop &prop) = 0; |
54 | virtual bool has_codepoint (uint32_t unicode) = 0; |
90 | virtual bool has_codepoint (uint32_t unicode) = 0; |
55 | |
91 | |
56 | virtual void draw (int x, int y, |
92 | virtual void draw (rxvt_drawable &d, |
|
|
93 | int x, int y, |
57 | const text_t *text, int len, |
94 | const text_t *text, int len, |
58 | int fg, int bg) = 0; |
95 | int fg, int bg) = 0; |
59 | }; |
96 | }; |
60 | |
97 | |
61 | //#define FONT_REF(obj) (obj)->refcnt++ |
98 | #define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) |
62 | //#define FONT_UNREF(obj) if (!--(obj)->refcnt) delete (obj) |
|
|
63 | #define FONT_UNREF(f) delete f |
|
|
64 | |
99 | |
65 | struct rxvt_fallback_font; |
100 | struct rxvt_fallback_font; |
66 | |
101 | |
67 | struct rxvt_fontset { |
102 | struct rxvt_fontset { |
68 | rxvt_fontset (rxvt_t r); |
103 | rxvt_fontset (rxvt_t r); |
69 | ~rxvt_fontset (); |
104 | ~rxvt_fontset (); |
70 | |
105 | |
71 | rxvt_font *new_font (const char *name, codeset cs); |
106 | rxvt_font *new_font (const char *name, codeset cs); |
72 | |
107 | |
73 | void populate (const char *desc); |
108 | bool populate (const char *desc); |
74 | int find_font (uint32_t unicode); |
109 | int find_font (uint32_t unicode); |
75 | |
110 | |
76 | rxvt_font *operator [](int id) const |
111 | rxvt_font *operator [] (int id) const |
77 | { |
112 | { |
78 | return fonts[id]; |
113 | return fonts[id]; |
79 | } |
114 | } |
80 | |
115 | |
81 | rxvt_font *base_font () const |
116 | rxvt_font *base_font () const |
… | |
… | |
86 | private: |
121 | private: |
87 | rxvt_t r; |
122 | rxvt_t r; |
88 | simplevec<rxvt_font *> fonts; |
123 | simplevec<rxvt_font *> fonts; |
89 | const rxvt_fallback_font *fallback; |
124 | const rxvt_fallback_font *fallback; |
90 | |
125 | |
91 | int height; |
126 | rxvt_fontprop base_prop; |
92 | int base_id; |
127 | int base_id; |
93 | |
128 | |
94 | bool realize_font (int i); |
129 | bool realize_font (int i); |
95 | void add_fonts (const char *desc); |
130 | void add_fonts (const char *desc); |
96 | void clear (); |
131 | void clear (); |