1 | #ifndef DEFAULTFONT_H_ |
1 | #ifndef DEFAULTFONT_H_ |
2 | #define DEFAULTFONT_H_ |
2 | #define DEFAULTFONT_H_ |
|
|
3 | |
|
|
4 | #include <X11/Xlib.h> |
|
|
5 | #if XFT |
|
|
6 | # include <X11/Xft/Xft.h> |
|
|
7 | #endif |
3 | |
8 | |
4 | #ifdef HAVE_XSETLOCALE |
9 | #ifdef HAVE_XSETLOCALE |
5 | # define X_LOCALE |
10 | # define X_LOCALE |
6 | # include <X11/Xlocale.h> |
11 | # include <X11/Xlocale.h> |
7 | #else |
12 | #else |
8 | # ifdef HAVE_SETLOCALE |
13 | # ifdef HAVE_SETLOCALE |
9 | # include <locale.h> |
14 | # include <clocale> |
10 | # endif |
15 | # endif |
11 | #endif /* HAVE_XLOCALE */ |
16 | #endif /* HAVE_XLOCALE */ |
12 | |
17 | |
13 | #ifdef HAVE_NL_LANGINFO |
18 | #ifdef HAVE_NL_LANGINFO |
14 | # include <langinfo.h> |
19 | # include <langinfo.h> |
15 | #endif |
20 | #endif |
|
|
21 | |
|
|
22 | #include <inttypes.h> |
16 | |
23 | |
17 | #include "rxvtlib.h" |
24 | #include "rxvtlib.h" |
18 | #include "feature.h" |
25 | #include "feature.h" |
19 | #include "encoding.h" |
26 | #include "encoding.h" |
20 | #include "rxvtstl.h" |
27 | #include "rxvtstl.h" |
… | |
… | |
26 | }; |
33 | }; |
27 | int width, height; |
34 | int width, height; |
28 | int weight, slant; |
35 | int weight, slant; |
29 | }; |
36 | }; |
30 | |
37 | |
|
|
38 | struct rxvt_drawable { |
|
|
39 | rxvt_display *display; |
|
|
40 | Drawable drawable; |
|
|
41 | #if XFT |
|
|
42 | XftDraw *xftdrawable; |
|
|
43 | operator XftDraw *(); |
|
|
44 | #endif |
|
|
45 | |
|
|
46 | rxvt_drawable (rxvt_display *display, Drawable drawable) |
|
|
47 | : display(display), |
|
|
48 | #if XFT |
|
|
49 | xftdrawable(0), |
|
|
50 | #endif |
|
|
51 | drawable(drawable) |
|
|
52 | { } |
|
|
53 | |
|
|
54 | #if XFT |
|
|
55 | ~rxvt_drawable (); |
|
|
56 | #endif |
|
|
57 | |
|
|
58 | operator Drawable() { return drawable; } |
|
|
59 | }; |
|
|
60 | |
31 | struct rxvt_font { |
61 | struct rxvt_font { |
|
|
62 | struct rxvt_fontset *fs; |
32 | // managed by the fontset |
63 | // managed by the fontset |
33 | rxvt_t r; |
64 | rxvt_t r; |
34 | void set_term (rxvt_t r) { this->r = r; } |
65 | void set_term (rxvt_t r) { this->r = r; } |
35 | |
66 | |
36 | char *name; |
67 | char *name; |
… | |
… | |
47 | if (this->name) free (this->name); // let the compiler optimize |
78 | if (this->name) free (this->name); // let the compiler optimize |
48 | this->name = name; |
79 | this->name = name; |
49 | } |
80 | } |
50 | |
81 | |
51 | rxvt_font () { name = 0; } |
82 | rxvt_font () { name = 0; } |
52 | ~rxvt_font () { clear (); free (name); }; |
83 | ~rxvt_font () { free (name); }; |
53 | |
84 | |
54 | void clear_rect (int x, int y, int w, int h, int color); |
85 | void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color); |
55 | |
86 | |
56 | virtual void clear () { }; |
87 | virtual void clear () { }; |
57 | |
88 | |
58 | virtual rxvt_fontprop properties () = 0; |
89 | virtual rxvt_fontprop properties () = 0; |
59 | |
90 | |
60 | virtual bool load (const rxvt_fontprop &prop) = 0; |
91 | virtual bool load (const rxvt_fontprop &prop) = 0; |
61 | virtual bool has_codepoint (uint32_t unicode) = 0; |
92 | virtual bool has_codepoint (uint32_t unicode) = 0; |
62 | |
93 | |
63 | virtual void draw (int x, int y, |
94 | virtual void draw (rxvt_drawable &d, |
|
|
95 | int x, int y, |
64 | const text_t *text, int len, |
96 | const text_t *text, int len, |
65 | int fg, int bg) = 0; |
97 | int fg, int bg) = 0; |
66 | }; |
98 | }; |
67 | |
99 | |
68 | //#define FONT_REF(obj) (obj)->refcnt++ |
100 | #define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) |
69 | //#define FONT_UNREF(obj) if (!--(obj)->refcnt) delete (obj) |
|
|
70 | #define FONT_UNREF(f) delete f |
|
|
71 | |
101 | |
72 | struct rxvt_fallback_font; |
102 | struct rxvt_fallback_font; |
73 | |
103 | |
74 | struct rxvt_fontset { |
104 | struct rxvt_fontset { |
|
|
105 | char *fontdesc; |
|
|
106 | |
75 | rxvt_fontset (rxvt_t r); |
107 | rxvt_fontset (rxvt_t r); |
76 | ~rxvt_fontset (); |
108 | ~rxvt_fontset (); |
77 | |
109 | |
78 | rxvt_font *new_font (const char *name, codeset cs); |
110 | rxvt_font *new_font (const char *name, codeset cs); |
79 | |
111 | |
80 | void populate (const char *desc); |
112 | bool populate (const char *desc); |
81 | int find_font (uint32_t unicode); |
113 | int find_font (uint32_t unicode, bool bold = false); |
|
|
114 | int find_font (const char *name) const; |
82 | |
115 | |
|
|
116 | // font-id's MUST fit into a signed 16 bit integer. |
83 | rxvt_font *operator [] (int id) const |
117 | rxvt_font *operator [] (int id) const |
84 | { |
118 | { |
85 | return fonts[id]; |
119 | return fonts[id]; |
86 | } |
120 | } |
87 | |
121 | |