1 | /* |
1 | #ifndef DEFAULTFONT_H_ |
2 | * $Id: defaultfont.h,v 1.4 2003/11/25 11:52:42 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 |
… | |
… | |
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 | #endif |
|
|
42 | rxvt_drawable (rxvt_display *display, Drawable drawable) |
|
|
43 | : display(display), drawable(drawable), xftdrawable(0) { } |
|
|
44 | ~rxvt_drawable (); |
|
|
45 | |
|
|
46 | operator Drawable() { return drawable; } |
|
|
47 | operator XftDraw *(); |
|
|
48 | }; |
25 | |
49 | |
26 | struct rxvt_font { |
50 | struct rxvt_font { |
27 | // managed by the fontset |
51 | // managed by the fontset |
28 | #if EXPLICIT_CONTEXT |
52 | rxvt_t r; |
29 | rxvt_t rxvt_term; |
53 | void set_term (rxvt_t r) { this->r = r; } |
30 | void set_term (pR) { this->rxvt_term = R; } |
54 | |
31 | #else |
|
|
32 | void set_term (pR) { } |
|
|
33 | #endif |
|
|
34 | char *name; |
55 | char *name; |
35 | codeset cs; |
56 | codeset cs; |
36 | bool loaded; |
57 | bool loaded; // wether we tried loading it before (not wether it's loaded) |
37 | |
58 | |
38 | // managed by the font object |
59 | // managed by the font object |
39 | bool prop; // wether this is a proportional font or has other funny characteristics |
60 | bool slow; // wether this is a proportional font or has other funny characteristics |
40 | int ascent, descent, |
61 | int ascent, descent, |
41 | width, height; |
62 | width, height; |
42 | |
63 | |
43 | void set_name (char *name) |
64 | void set_name (char *name) |
44 | { |
65 | { |
45 | if (this->name) free (this->name); // let the compiler optimize |
66 | if (this->name) free (this->name); // let the compiler optimize |
46 | this->name = name; |
67 | this->name = name; |
47 | } |
68 | } |
48 | |
69 | |
49 | rxvt_font () { name = 0; } |
70 | rxvt_font () { name = 0; } |
50 | ~rxvt_font () { free (name); clear (); }; |
71 | ~rxvt_font () { free (name); }; |
51 | |
72 | |
52 | void clear_rect (int x, int y, int w, int h, int color); |
73 | void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color); |
53 | |
74 | |
54 | virtual void clear () { }; |
75 | virtual void clear () { }; |
55 | |
76 | |
56 | virtual bool load (int maxheight) = 0; |
77 | virtual rxvt_fontprop properties () = 0; |
|
|
78 | |
|
|
79 | virtual bool load (const rxvt_fontprop &prop) = 0; |
57 | virtual bool has_codepoint (uint32_t unicode) = 0; |
80 | virtual bool has_codepoint (uint32_t unicode) = 0; |
58 | |
81 | |
59 | virtual void draw (int x, int y, |
82 | virtual void draw (rxvt_drawable &d, |
|
|
83 | int x, int y, |
60 | const text_t *text, int len, |
84 | const text_t *text, int len, |
61 | int fg, int bg) = 0; |
85 | int fg, int bg) = 0; |
62 | }; |
86 | }; |
63 | |
87 | |
64 | //#define FONT_REF(obj) (obj)->refcnt++ |
88 | #define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) |
65 | //#define FONT_UNREF(obj) if (!--(obj)->refcnt) delete (obj) |
|
|
66 | #define FONT_UNREF(f) delete f |
|
|
67 | |
89 | |
68 | struct rxvt_fallback_font; |
90 | struct rxvt_fallback_font; |
69 | |
91 | |
70 | struct rxvt_fontset { |
92 | struct rxvt_fontset { |
71 | rxvt_fontset (pR); |
93 | rxvt_fontset (rxvt_t r); |
72 | ~rxvt_fontset (); |
94 | ~rxvt_fontset (); |
73 | |
95 | |
74 | rxvt_font *new_font (const char *name, codeset cs); |
96 | rxvt_font *new_font (const char *name, codeset cs); |
75 | |
97 | |
76 | void populate (const char *desc); |
98 | bool populate (const char *desc); |
77 | int find_font (uint32_t unicode); |
99 | int find_font (uint32_t unicode); |
78 | |
100 | |
79 | rxvt_font *operator [](int id) const |
101 | rxvt_font *operator [] (int id) const |
80 | { |
102 | { |
81 | return fonts[id]; |
103 | return fonts[id]; |
82 | } |
104 | } |
83 | |
105 | |
84 | rxvt_font *base_font () const |
106 | rxvt_font *base_font () const |
85 | { |
107 | { |
86 | return fonts[base_id]; |
108 | return fonts[base_id]; |
87 | } |
109 | } |
88 | |
110 | |
89 | private: |
111 | private: |
90 | #ifdef EXPLICIT_CONTEXT |
112 | rxvt_t r; |
91 | rxvt_t rxvt_term; |
|
|
92 | #endif |
|
|
93 | simplevec<rxvt_font *> fonts; |
113 | simplevec<rxvt_font *> fonts; |
94 | const rxvt_fallback_font *fallback; |
114 | const rxvt_fallback_font *fallback; |
95 | |
115 | |
96 | int height; |
116 | rxvt_fontprop base_prop; |
97 | int base_id; |
117 | int base_id; |
98 | |
118 | |
99 | bool realize_font (int i); |
119 | bool realize_font (int i); |
100 | void add_fonts (const char *desc); |
120 | void add_fonts (const char *desc); |
101 | void clear (); |
121 | void clear (); |