1 | /* |
1 | #ifndef DEFAULTFONT_H_ |
2 | * $Id: defaultfont.h,v 1.8 2003/12/24 09:07:01 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" |
25 | |
26 | |
26 | struct rxvt_fontprop { |
27 | struct rxvt_fontprop { |
27 | enum { |
28 | enum { |
28 | medium = 100, bold = 200, |
29 | medium = 100, bold = 200, |
29 | roman = 0, italic = 100, |
30 | roman = 0, italic = 100, |
30 | }; |
31 | }; |
31 | int width, height; |
32 | int width, height; |
32 | int weight, slant; |
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 *(); |
33 | }; |
48 | }; |
34 | |
49 | |
35 | struct rxvt_font { |
50 | struct rxvt_font { |
36 | // managed by the fontset |
51 | // managed by the fontset |
37 | rxvt_t r; |
52 | rxvt_t r; |
… | |
… | |
51 | if (this->name) free (this->name); // let the compiler optimize |
66 | if (this->name) free (this->name); // let the compiler optimize |
52 | this->name = name; |
67 | this->name = name; |
53 | } |
68 | } |
54 | |
69 | |
55 | rxvt_font () { name = 0; } |
70 | rxvt_font () { name = 0; } |
56 | ~rxvt_font () { free (name); clear (); }; |
71 | ~rxvt_font () { free (name); }; |
57 | |
72 | |
58 | 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); |
59 | |
74 | |
60 | virtual void clear () { }; |
75 | virtual void clear () { }; |
61 | |
76 | |
62 | virtual rxvt_fontprop properties () = 0; |
77 | virtual rxvt_fontprop properties () = 0; |
63 | |
78 | |
64 | virtual bool load (const rxvt_fontprop &prop) = 0; |
79 | virtual bool load (const rxvt_fontprop &prop) = 0; |
65 | virtual bool has_codepoint (uint32_t unicode) = 0; |
80 | virtual bool has_codepoint (uint32_t unicode) = 0; |
66 | |
81 | |
67 | virtual void draw (int x, int y, |
82 | virtual void draw (rxvt_drawable &d, |
|
|
83 | int x, int y, |
68 | const text_t *text, int len, |
84 | const text_t *text, int len, |
69 | int fg, int bg) = 0; |
85 | int fg, int bg) = 0; |
70 | }; |
86 | }; |
71 | |
87 | |
72 | //#define FONT_REF(obj) (obj)->refcnt++ |
88 | #define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) |
73 | //#define FONT_UNREF(obj) if (!--(obj)->refcnt) delete (obj) |
|
|
74 | #define FONT_UNREF(f) delete f |
|
|
75 | |
89 | |
76 | struct rxvt_fallback_font; |
90 | struct rxvt_fallback_font; |
77 | |
91 | |
78 | struct rxvt_fontset { |
92 | struct rxvt_fontset { |
79 | rxvt_fontset (rxvt_t r); |
93 | rxvt_fontset (rxvt_t r); |
80 | ~rxvt_fontset (); |
94 | ~rxvt_fontset (); |
81 | |
95 | |
82 | rxvt_font *new_font (const char *name, codeset cs); |
96 | rxvt_font *new_font (const char *name, codeset cs); |
83 | |
97 | |
84 | void populate (const char *desc); |
98 | bool populate (const char *desc); |
85 | int find_font (uint32_t unicode); |
99 | int find_font (uint32_t unicode); |
86 | |
100 | |
87 | rxvt_font *operator [](int id) const |
101 | rxvt_font *operator [] (int id) const |
88 | { |
102 | { |
89 | return fonts[id]; |
103 | return fonts[id]; |
90 | } |
104 | } |
91 | |
105 | |
92 | rxvt_font *base_font () const |
106 | rxvt_font *base_font () const |