1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: defaultfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
9 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
|
|
24 | #include "rxvtlib.h" |
|
|
25 | #include "rxvtutil.h" |
24 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
25 | |
27 | |
26 | #include <cstdlib> |
28 | #include <cstdlib> |
27 | |
29 | |
28 | #define DISPLAY r->display->display |
30 | #include <inttypes.h> |
29 | #define TGC r->TermWin.gc |
31 | |
|
|
32 | #define MAX_OVERLAP_ROMAN (8 + 2) // max. character width in 8ths of the base width |
|
|
33 | #define MAX_OVERLAP_ITALIC (8 + 3) // max. overlap for italic fonts |
|
|
34 | |
|
|
35 | #define OVERLAP_OK(w,wcw,prop) ((w) <= ( \ |
|
|
36 | (prop)->slant >= rxvt_fontprop::italic \ |
|
|
37 | ? ((prop)->width * (wcw) * MAX_OVERLAP_ITALIC + 7) >> 3 \ |
|
|
38 | : ((prop)->width * (wcw) * MAX_OVERLAP_ROMAN + 7) >> 3 \ |
|
|
39 | )) |
30 | |
40 | |
31 | const struct rxvt_fallback_font { |
41 | const struct rxvt_fallback_font { |
32 | codeset cs; |
42 | codeset cs; |
33 | const char *name; |
43 | const char *name; |
34 | } fallback_fonts[] = { |
44 | } fallback_fonts[] = { |
… | |
… | |
52 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
62 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
53 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
63 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
54 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
64 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
55 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
65 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
56 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
66 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
|
|
67 | |
|
|
68 | # if XFT |
|
|
69 | { CS_KOI8_U, "xft::lang=ru" }, |
|
|
70 | |
|
|
71 | { CS_ISO8859_5, "xft::lang=ru" }, |
|
|
72 | { CS_ISO8859_6, "xft::lang=ar" }, |
|
|
73 | { CS_ISO8859_7, "xft::lang=el" }, |
|
|
74 | { CS_ISO8859_8, "xft::lang=he" }, |
|
|
75 | { CS_ISO8859_9, "xft::lang=tr" }, |
|
|
76 | { CS_ISO8859_10, "xft::lang=se" }, |
|
|
77 | { CS_ISO8859_11, "xft::lang=th" }, |
|
|
78 | # endif |
57 | #endif |
79 | #endif |
58 | |
80 | |
59 | // japanese |
81 | // japanese |
60 | #if ENCODING_JP || ENCODING_JP_EXT |
82 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | # if XFT |
83 | # if XFT |
62 | // prefer xft for complex scripts |
84 | // prefer xft for complex scripts |
63 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
85 | { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, |
|
|
86 | { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" }, |
|
|
87 | { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, |
|
|
88 | { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, |
64 | # endif |
89 | # endif |
65 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
90 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
91 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
92 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
93 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
69 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
94 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
70 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
95 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
71 | #endif |
96 | #endif |
72 | |
97 | |
73 | #if ENCODING_CN || ENCODING_CN_EXT |
98 | #if ENCODING_ZH || ENCODING_ZH_EXT |
74 | # if XFT |
99 | # if XFT |
|
|
100 | { CS_GBK_0, "xft:AR PL KaitiM GB" }, |
|
|
101 | { CS_GBK_0, "xft:AR PL SungtiL GB" }, |
|
|
102 | { CS_GBK_0, "xft::lang=zh" }, |
75 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
103 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
76 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
104 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
77 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
105 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
78 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
106 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
|
|
107 | { CS_GB2312_1980_0, "xft::lang=zh" }, |
79 | # endif |
108 | # endif |
|
|
109 | { CS_GBK_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gbk*-0" }, |
80 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
110 | { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, |
81 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
111 | { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, |
82 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
112 | { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, |
|
|
113 | { CS_GB2312_1980_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
83 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
114 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
84 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
115 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
85 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
116 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
86 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
117 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
87 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
118 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
… | |
… | |
89 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
120 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
90 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
121 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
91 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
122 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
92 | #endif |
123 | #endif |
93 | |
124 | |
|
|
125 | #if ENCODING_KR |
|
|
126 | { CS_KSC5601_1987_0, "-baekmuk-gulim-*-*-*-*-*-*-*-*-c-*-ksc5601*" }, |
|
|
127 | { CS_KSC5601_1987_0, "-*-*-*-*-*-*-*-*-*-*-c-*-ksc5601*" }, |
|
|
128 | # if XFT |
|
|
129 | { CS_KSC5601_1987_0, "xft:Baekmuk Gulim:antialias=false" }, |
|
|
130 | { CS_KSC5601_1987_0, "xft::lang=ko:antialias=false" }, |
|
|
131 | # endif |
|
|
132 | #endif |
|
|
133 | |
|
|
134 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
135 | //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs. |
94 | #if XFT |
136 | #if XFT |
|
|
137 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
|
|
138 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
|
|
139 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
|
|
140 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
|
|
141 | |
|
|
142 | // FreeMono is usually uglier than x fonts, so try after the others |
95 | { CS_UNICODE, "xft:Andale Mono" }, |
143 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
96 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
|
|
97 | #endif |
144 | #endif |
98 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
145 | |
99 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
146 | // generic font fallback, put this last, as many iso10646 fonts have extents |
|
|
147 | // specified for all glyphs in the range they cover, but most are simply empty |
100 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
148 | //{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
101 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
149 | //{ CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
102 | #if XFT |
|
|
103 | // FreeMono is usually uglier than x fonts, so try last only. |
|
|
104 | //{ CS_UNICODE, "xft:FreeMono" }, |
|
|
105 | #endif |
|
|
106 | |
|
|
107 | { CS_UNKNOWN, 0 } |
150 | { CS_UNKNOWN, 0 } |
108 | }; |
151 | }; |
109 | |
152 | |
|
|
153 | // these characters are used to guess the font height and width |
|
|
154 | // pango uses a similar algorithm and doesn't trust the font either. |
|
|
155 | static uint16_t extent_test_chars[] = { |
|
|
156 | '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', |
|
|
157 | 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ |
|
|
158 | 0x304c, 0x672c, // が本 |
|
|
159 | }; |
|
|
160 | |
|
|
161 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
|
|
162 | |
|
|
163 | #define dTermDisplay Display *disp = term->dpy |
|
|
164 | #define dTermGC GC gc = term->gc |
|
|
165 | |
110 | ///////////////////////////////////////////////////////////////////////////// |
166 | ///////////////////////////////////////////////////////////////////////////// |
111 | |
|
|
112 | #if XFT |
|
|
113 | rxvt_drawable::~rxvt_drawable () |
|
|
114 | { |
|
|
115 | if (xftdrawable) |
|
|
116 | XftDrawDestroy (xftdrawable); |
|
|
117 | } |
|
|
118 | |
|
|
119 | rxvt_drawable::operator XftDraw *() |
|
|
120 | { |
|
|
121 | if (!xftdrawable) |
|
|
122 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
|
|
123 | |
|
|
124 | return xftdrawable; |
|
|
125 | } |
|
|
126 | #endif |
|
|
127 | |
|
|
128 | ///////////////////////////////////////////////////////////////////////////// |
|
|
129 | |
|
|
130 | static void *enc_buf; |
|
|
131 | static uint32_t enc_len; |
|
|
132 | |
|
|
133 | static inline void * |
|
|
134 | get_enc_buf (uint32_t len) |
|
|
135 | { |
|
|
136 | if (len > enc_len) |
|
|
137 | { |
|
|
138 | free (enc_buf); |
|
|
139 | enc_buf = malloc (len); |
|
|
140 | enc_len = len; |
|
|
141 | } |
|
|
142 | |
|
|
143 | return enc_buf; |
|
|
144 | } |
|
|
145 | |
167 | |
146 | static const char * |
168 | static const char * |
147 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
169 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
148 | { |
170 | { |
149 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
171 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
172 | uint8_t *res = buf; |
150 | |
173 | |
151 | while (len--) |
174 | while (len--) |
152 | { |
175 | { |
153 | uint32_t c = FROM_UNICODE (cs, *text++); |
176 | uint32_t c = FROM_UNICODE (cs, *text++); |
154 | |
177 | |
… | |
… | |
159 | } |
182 | } |
160 | |
183 | |
161 | *buf++ = c; |
184 | *buf++ = c; |
162 | } |
185 | } |
163 | |
186 | |
164 | return (const char *)enc_buf; |
187 | return (const char *)res; |
165 | } |
188 | } |
166 | |
189 | |
167 | static const XChar2b * |
190 | static const XChar2b * |
168 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
191 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
169 | { |
192 | { |
170 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
193 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
194 | XChar2b *res = buf; |
171 | |
195 | |
172 | while (len--) |
196 | while (len--) |
173 | { |
197 | { |
174 | uint32_t c = FROM_UNICODE (cs, *text++); |
198 | uint32_t c = FROM_UNICODE (cs, *text++); |
175 | |
199 | |
… | |
… | |
182 | buf->byte1 = c >> 8; |
206 | buf->byte1 = c >> 8; |
183 | buf->byte2 = c; |
207 | buf->byte2 = c; |
184 | buf++; |
208 | buf++; |
185 | } |
209 | } |
186 | |
210 | |
187 | return (XChar2b *)enc_buf; |
211 | return res; |
188 | } |
212 | } |
189 | |
213 | |
190 | ///////////////////////////////////////////////////////////////////////////// |
214 | ///////////////////////////////////////////////////////////////////////////// |
191 | |
215 | |
|
|
216 | rxvt_font::rxvt_font () |
|
|
217 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
|
|
218 | { |
|
|
219 | } |
|
|
220 | |
192 | void |
221 | void |
|
|
222 | rxvt_font::set_name (char *name) |
|
|
223 | { |
|
|
224 | if (this->name == name) |
|
|
225 | return; |
|
|
226 | |
|
|
227 | if (this->name) free (this->name); // let the compiler optimize |
|
|
228 | this->name = name; |
|
|
229 | } |
|
|
230 | |
|
|
231 | void |
193 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
232 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
194 | { |
233 | { |
195 | if (color == Color_bg) |
234 | dTermDisplay; |
196 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
235 | dTermGC; |
|
|
236 | |
|
|
237 | if (color == Color_bg || color == Color_transparent) |
|
|
238 | XClearArea (disp, d, x, y, w, h, false); |
197 | else if (color >= 0) |
239 | else if (color >= 0) |
198 | { |
240 | { |
199 | #if XFT |
241 | #if XFT |
200 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
242 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
201 | #else |
243 | #else |
202 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
244 | XSetForeground (disp, gc, term->pix_colors[color]); |
203 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
245 | XFillRectangle (disp, d, gc, x, y, w, h); |
204 | #endif |
246 | #endif |
205 | } |
247 | } |
206 | } |
248 | } |
|
|
249 | |
|
|
250 | ///////////////////////////////////////////////////////////////////////////// |
207 | |
251 | |
208 | #include "table/linedraw.h" |
252 | #include "table/linedraw.h" |
209 | |
253 | |
210 | struct rxvt_font_default : rxvt_font { |
254 | struct rxvt_font_default : rxvt_font { |
|
|
255 | struct rxvt_fontset *fs; |
|
|
256 | |
|
|
257 | rxvt_font_default (rxvt_fontset *fs) |
|
|
258 | : rxvt_font () |
|
|
259 | { |
|
|
260 | this->fs = fs; |
|
|
261 | } |
211 | |
262 | |
212 | rxvt_fontprop properties () |
263 | rxvt_fontprop properties () |
213 | { |
264 | { |
214 | rxvt_fontprop p; |
265 | rxvt_fontprop p; |
215 | |
266 | |
216 | p.width = p.height = 1; |
267 | p.width = p.height = 1; |
|
|
268 | p.ascent = rxvt_fontprop::unset; |
217 | p.weight = rxvt_fontprop::medium; |
269 | p.weight = rxvt_fontprop::medium; |
218 | p.slant = rxvt_fontprop::roman; |
270 | p.slant = rxvt_fontprop::roman; |
219 | |
271 | |
220 | return p; |
272 | return p; |
221 | } |
273 | } |
222 | |
274 | |
223 | bool load (const rxvt_fontprop &prop) |
275 | bool load (const rxvt_fontprop &prop, bool force_prop) |
224 | { |
276 | { |
225 | width = 1; height = 1; |
277 | width = 1; height = 1; |
226 | ascent = 1; descent = 0; |
278 | ascent = 1; descent = 0; |
227 | |
279 | |
228 | set_name (strdup ("built-in pseudofont")); |
280 | set_name (strdup ("built-in support font")); |
229 | |
281 | |
230 | return true; |
282 | return true; |
231 | } |
283 | } |
232 | |
284 | |
233 | bool has_codepoint (unicode_t unicode) |
285 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
234 | { |
286 | { |
|
|
287 | careful = false; |
|
|
288 | |
235 | if (unicode <= 0x001f) |
289 | if (unicode <= 0x001f) |
236 | return true; |
290 | return true; |
237 | |
291 | |
238 | if (unicode <= 0x007f) |
292 | if (unicode <= 0x007f) |
239 | return false; |
293 | return false; |
240 | |
294 | |
241 | if (unicode <= 0x009f) |
295 | if (unicode <= 0x009f) |
242 | return true; |
296 | return true; |
243 | |
297 | |
244 | if (unicode >= 0x2500 && unicode <= 0x259f) |
298 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
299 | !term->option (Opt_skipBuiltinGlyphs)) |
245 | return true; |
300 | return true; |
246 | |
301 | |
247 | if (IS_COMPOSE (unicode)) |
302 | if (IS_COMPOSE (unicode)) |
248 | return true; |
303 | return true; |
249 | |
304 | |
250 | switch (unicode) |
305 | switch (unicode) |
251 | { |
306 | { |
252 | case ZERO_WIDTH_CHAR: |
307 | case ZERO_WIDTH_CHAR: |
|
|
308 | case NOCHAR: |
253 | return true; |
309 | return true; |
254 | } |
310 | } |
255 | |
311 | |
256 | return false; |
312 | return false; |
257 | } |
313 | } |
… | |
… | |
264 | void |
320 | void |
265 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
321 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
266 | const text_t *text, int len, |
322 | const text_t *text, int len, |
267 | int fg, int bg) |
323 | int fg, int bg) |
268 | { |
324 | { |
|
|
325 | dTermDisplay; |
|
|
326 | dTermGC; |
|
|
327 | |
269 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
328 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
270 | |
329 | |
271 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
330 | XSetForeground (disp, gc, term->pix_colors[fg]); |
272 | |
331 | |
273 | while (len--) |
332 | while (len) |
274 | { |
333 | { |
275 | #if ENABLE_COMBINING |
334 | #if ENABLE_COMBINING |
276 | compose_char *cc; |
335 | compose_char *cc; |
277 | #endif |
336 | #endif |
|
|
337 | const text_t *tp = text; |
278 | text_t t = *text++; |
338 | text_t t = *tp; |
|
|
339 | |
|
|
340 | while (++text, --len && *text == NOCHAR) |
|
|
341 | ; |
|
|
342 | |
|
|
343 | int width = text - tp; |
|
|
344 | int fwidth = term->fwidth * width; |
279 | |
345 | |
280 | if (0x2500 <= t && t <= 0x259f) |
346 | if (0x2500 <= t && t <= 0x259f) |
281 | { |
347 | { |
282 | uint16_t offs = linedraw_offs[t - 0x2500]; |
348 | uint16_t offs = linedraw_offs[t - 0x2500]; |
283 | uint32_t *a = linedraw_command + (offs >> 4); |
349 | uint32_t *a = linedraw_command + (offs >> 4); |
284 | uint32_t *b = a + (offs & 15); |
350 | uint32_t *b = a + (offs & 15); |
285 | |
351 | |
286 | int W = r->TermWin.fwidth; |
352 | int W = fwidth; |
287 | int H = r->TermWin.fheight; |
353 | int H = term->fheight; |
288 | |
354 | |
289 | int x_[16]; |
355 | int x_[16]; |
290 | int y_[16]; |
356 | int y_[16]; |
291 | |
357 | |
292 | for (int i = 0; i <= 8; i++) |
358 | for (int i = 0; i <= 8; i++) |
… | |
… | |
300 | |
366 | |
301 | XGCValues gcv; |
367 | XGCValues gcv; |
302 | |
368 | |
303 | gcv.cap_style = CapButt; |
369 | gcv.cap_style = CapButt; |
304 | gcv.line_width = 0; |
370 | gcv.line_width = 0; |
305 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
371 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
306 | |
372 | |
307 | while (a < b) |
373 | while (a < b) |
308 | { |
374 | { |
309 | uint32_t command = *a++; |
375 | uint32_t command = *a++; |
310 | |
376 | |
… | |
… | |
317 | int y2 = y_[(command >> 0) & 15]; |
383 | int y2 = y_[(command >> 0) & 15]; |
318 | |
384 | |
319 | switch (op) |
385 | switch (op) |
320 | { |
386 | { |
321 | case 0: // line |
387 | case 0: // line |
322 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
388 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
323 | break; |
389 | break; |
324 | |
390 | |
325 | case 1: // rectangle, possibly stippled |
391 | case 1: // rectangle, possibly stippled |
326 | if (a) |
392 | if (a) |
327 | { |
393 | { |
328 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
394 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
329 | |
395 | |
330 | gcv.fill_style = FillStippled; |
396 | gcv.fill_style = FillStippled; |
331 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
397 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
332 | gcv.ts_x_origin = x; |
398 | gcv.ts_x_origin = x; |
333 | gcv.ts_y_origin = y; |
399 | gcv.ts_y_origin = y; |
334 | |
400 | |
335 | XChangeGC (d.display->display, TGC, |
401 | XChangeGC (disp, gc, |
336 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
402 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
337 | &gcv); |
403 | &gcv); |
338 | } |
404 | } |
339 | |
405 | |
340 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
406 | XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
341 | |
407 | |
342 | if (a) |
408 | if (a) |
343 | { |
409 | { |
344 | XFreePixmap (d.display->display, gcv.stipple); |
410 | XFreePixmap (disp, gcv.stipple); |
345 | gcv.stipple = 0; |
411 | gcv.stipple = 0; |
346 | gcv.fill_style = FillSolid; |
412 | gcv.fill_style = FillSolid; |
347 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
413 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
348 | } |
414 | } |
349 | break; |
415 | break; |
350 | case 2: // arc |
416 | case 2: // arc |
351 | XDrawArc (d.display->display, d, TGC, |
417 | XDrawArc (disp, d, gc, |
352 | x1 - W/2, y1 - H/2, W-1, H-1, |
418 | x1 - W/2, y1 - H/2, W-1, H-1, |
353 | (a - 1) * 90*64, (b - 1) * 90*64); |
419 | (a - 1) * 90*64, (b - 1) * 90*64); |
354 | break; |
420 | break; |
355 | } |
421 | } |
356 | } |
422 | } |
357 | } |
423 | } |
358 | #if ENABLE_COMBINING |
424 | #if ENABLE_COMBINING |
359 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
425 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
360 | { |
426 | { |
|
|
427 | min_it (width, 2); // we only support wcwidth up to 2 |
|
|
428 | |
|
|
429 | text_t chrs[2]; |
|
|
430 | chrs [1] = NOCHAR; |
|
|
431 | |
|
|
432 | *chrs = cc->c1; |
361 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
433 | rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; |
362 | f1->draw (d, x, y, &(t = cc->c1), 1, fg, bg); |
434 | f1->draw (d, x, y, chrs, width, fg, bg); |
|
|
435 | |
363 | if (cc->c2 != NOCHAR) |
436 | if (cc->c2 != NOCHAR) |
364 | { |
437 | { |
|
|
438 | bool careful; |
|
|
439 | |
365 | // prefer font of first character, for no good reasons |
440 | // prefer font of first character, for no good reasons |
366 | rxvt_font *f2 = f1->has_codepoint (cc->c2) |
441 | *chrs = cc->c2; |
|
|
442 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
367 | ? f1 |
443 | ? f1 |
368 | : (*fs)[fs->find_font (cc->c2)]; |
444 | : (*fs)[fs->find_font (cc->c2)]; |
369 | |
445 | |
370 | f2->draw (d, x, y, &(t = cc->c2), 1, fg, -1); |
446 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
371 | } |
447 | } |
372 | } |
448 | } |
373 | #endif |
449 | #endif |
374 | else |
450 | else |
375 | switch (t) |
451 | switch (t) |
376 | { |
452 | { |
|
|
453 | case '\t': |
377 | case ZERO_WIDTH_CHAR: |
454 | case ZERO_WIDTH_CHAR: |
|
|
455 | case NOCHAR: |
378 | break; |
456 | break; |
379 | |
457 | |
380 | default: |
458 | default: |
381 | int w = 0; |
|
|
382 | while (len > 0 && *text == NOCHAR) |
|
|
383 | { |
|
|
384 | ++text; |
|
|
385 | --len; |
|
|
386 | w += r->TermWin.fwidth; |
|
|
387 | } |
|
|
388 | |
|
|
389 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
459 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
390 | w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); |
460 | fwidth - 4, term->fheight - 4); |
391 | x += w; |
|
|
392 | } |
461 | } |
393 | |
462 | |
394 | x += r->TermWin.fwidth; |
463 | x += fwidth; |
395 | } |
464 | } |
396 | } |
465 | } |
397 | |
466 | |
398 | ///////////////////////////////////////////////////////////////////////////// |
467 | ///////////////////////////////////////////////////////////////////////////// |
399 | |
468 | |
… | |
… | |
402 | |
471 | |
403 | void clear (); |
472 | void clear (); |
404 | |
473 | |
405 | rxvt_fontprop properties (); |
474 | rxvt_fontprop properties (); |
406 | |
475 | |
407 | bool load (const rxvt_fontprop &prop); |
476 | bool load (const rxvt_fontprop &prop, bool force_prop); |
408 | |
477 | |
409 | bool has_codepoint (unicode_t unicode); |
478 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
410 | |
479 | |
411 | void draw (rxvt_drawable &d, int x, int y, |
480 | void draw (rxvt_drawable &d, int x, int y, |
412 | const text_t *text, int len, |
481 | const text_t *text, int len, |
413 | int fg, int bg); |
482 | int fg, int bg); |
414 | |
483 | |
|
|
484 | bool slow; // wether this is a proportional font or has other funny characteristics |
415 | XFontStruct *f; |
485 | XFontStruct *f; |
416 | codeset cs; |
|
|
417 | bool enc2b, encm; |
486 | bool enc2b, encm; |
418 | |
487 | |
419 | char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
488 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
420 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
489 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
421 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
490 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
422 | bool set_properties (rxvt_fontprop &p, const char *name); |
491 | bool set_properties (rxvt_fontprop &p, const char *name); |
423 | }; |
492 | }; |
424 | |
493 | |
425 | char * |
494 | char * |
426 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
495 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
427 | { |
496 | { |
428 | unsigned long value; |
497 | unsigned long value; |
429 | |
498 | |
430 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
499 | if (XGetFontProperty (f, property, &value)) |
431 | return XGetAtomName (DISPLAY, value); |
500 | return XGetAtomName (term->dpy, value); |
432 | else |
501 | else |
433 | return rxvt_strdup (repl); |
502 | return rxvt_strdup (repl); |
434 | } |
503 | } |
435 | |
504 | |
436 | rxvt_fontprop |
505 | rxvt_fontprop |
… | |
… | |
442 | } |
511 | } |
443 | |
512 | |
444 | bool |
513 | bool |
445 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
514 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
446 | { |
515 | { |
447 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
516 | p.width = width != rxvt_fontprop::unset ? width |
|
|
517 | : avgwidth ? (avgwidth + 1) / 10 |
|
|
518 | : (height + 1) / 2; |
448 | p.height = height; |
519 | p.height = height; |
|
|
520 | p.ascent = rxvt_fontprop::unset; |
449 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
521 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
450 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
522 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
451 | |
523 | |
452 | return true; |
524 | return true; |
453 | } |
525 | } |
454 | |
526 | |
455 | bool |
527 | bool |
456 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
528 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
457 | { |
529 | { |
458 | unsigned long height; |
530 | unsigned long height; |
|
|
531 | |
|
|
532 | #if 0 |
459 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
533 | if (!XGetFontProperty (f, XInternAtom (term->dpy, "PIXEL_SIZE", 0), &height)) |
460 | return false; |
534 | return false; |
|
|
535 | #else |
|
|
536 | height = f->ascent + f->descent; |
|
|
537 | #endif |
461 | |
538 | |
462 | unsigned long avgwidth; |
539 | unsigned long avgwidth; |
463 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
540 | if (!XGetFontProperty (f, term->xa [XA_AVERAGE_WIDTH], &avgwidth)) |
464 | avgwidth = 0; |
541 | avgwidth = 0; |
465 | |
542 | |
466 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
543 | char *weight = get_property (f, term->xa [XA_WEIGHT_NAME], "medium"); |
467 | char *slant = get_property (f, "SLANT", "r"); |
544 | char *slant = get_property (f, term->xa [XA_SLANT], "r"); |
468 | |
545 | |
469 | set_properties (p, height, weight, slant, avgwidth); |
546 | set_properties (p, height, weight, slant, avgwidth); |
470 | |
547 | |
471 | free (weight); |
548 | free (weight); |
472 | free (slant); |
549 | free (slant); |
473 | |
550 | |
|
|
551 | p.ascent = f->ascent; |
|
|
552 | |
474 | return true; |
553 | return true; |
475 | } |
554 | } |
476 | |
555 | |
477 | bool |
556 | bool |
478 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
557 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
479 | { |
558 | { |
|
|
559 | dTermDisplay; |
480 | int slashes = 0; |
560 | int slashes = 0; |
481 | const char *comp[13]; |
561 | const char *comp[13]; |
482 | |
562 | |
483 | for (const char *c = name; *c; c++) |
563 | for (const char *c = name; *c; c++) |
484 | if (*c == '-') |
564 | if (*c == '-') |
… | |
… | |
492 | if (slashes >= 13 |
572 | if (slashes >= 13 |
493 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
573 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
494 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
574 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
495 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
575 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
496 | |
576 | |
497 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
577 | XFontStruct *f = XLoadQueryFont (disp, name); |
498 | |
578 | |
499 | if (f) |
579 | if (f) |
500 | { |
580 | { |
501 | // the font should really exist now. if not, we have a problem |
581 | // the font should really exist now. if not, we have a problem |
502 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
582 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
503 | // in that case, just return garbage. |
583 | // in that case, just return garbage. |
504 | bool ret = set_properties (p, f); |
584 | bool ret = set_properties (p, f); |
505 | XFreeFont (DISPLAY, f); |
585 | XFreeFont (disp, f); |
506 | return ret; |
586 | return ret; |
507 | } |
587 | } |
508 | else |
588 | else |
509 | return false; |
589 | return false; |
510 | } |
590 | } |
511 | |
591 | |
512 | // fix the size of scalable fonts |
592 | // fix the size of scalable fonts |
513 | static void |
593 | static bool |
514 | fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop) |
594 | replace_field (char *buf, const char *name, int index, const char old, const char *replace) |
515 | { |
595 | { |
516 | int slashes = 0; |
596 | int slashes = 0; |
517 | const char *size; |
597 | const char *field, *end; |
518 | |
598 | |
519 | for (const char *c = name; *c; c++) |
599 | for (const char *c = name; *c; c++) |
520 | if (*c == '-') |
600 | if (*c == '-') |
521 | { |
601 | { |
522 | if (slashes == 6) |
602 | if (slashes == index) |
523 | size = c + 1; |
603 | field = c + 1; |
|
|
604 | |
|
|
605 | if (slashes == index + 1) |
|
|
606 | end = c; |
524 | |
607 | |
525 | if (++slashes >= 13) |
608 | if (++slashes >= 13) |
526 | break; |
609 | break; |
527 | } |
610 | } |
528 | |
611 | |
529 | if (slashes >= 13 && size[0] == '0') |
612 | if (slashes >= 13 && (!old || *field == old)) |
530 | { |
613 | { |
|
|
614 | // TODO: check for overflow in font-name |
531 | strncpy (buf, name, size - name); |
615 | strncpy (buf, name, field - name); |
532 | buf += size - name; |
616 | buf += field - name; |
533 | buf += sprintf (buf, "%d", prop.height); |
|
|
534 | strcpy (buf, size + 1); |
617 | strcpy (buf, replace); |
|
|
618 | strcat (buf, end); |
|
|
619 | |
|
|
620 | return true; |
535 | } |
621 | } |
536 | else |
622 | else |
|
|
623 | { |
537 | strcpy (buf, name); |
624 | strcpy (buf, name); |
|
|
625 | |
|
|
626 | return false; |
|
|
627 | } |
538 | } |
628 | } |
539 | |
629 | |
540 | bool |
630 | bool |
541 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
631 | rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop) |
542 | { |
632 | { |
|
|
633 | dTermDisplay; |
|
|
634 | |
543 | clear (); |
635 | clear (); |
|
|
636 | |
|
|
637 | char field_str[64]; // enough for 128 bits |
|
|
638 | |
|
|
639 | // first morph the font if required |
|
|
640 | if (force_prop) |
|
|
641 | { |
|
|
642 | char fname[1024]; |
|
|
643 | |
|
|
644 | if (name[0] != '-') |
|
|
645 | { |
|
|
646 | f = XLoadQueryFont (disp, name); |
|
|
647 | |
|
|
648 | if (!f) |
|
|
649 | return false; |
|
|
650 | |
|
|
651 | char *new_name = get_property (f, XA_FONT, name); |
|
|
652 | |
|
|
653 | if (new_name) |
|
|
654 | set_name (new_name); |
|
|
655 | else |
|
|
656 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
|
|
657 | |
|
|
658 | XFreeFont (disp, f); |
|
|
659 | f = 0; |
|
|
660 | } |
|
|
661 | |
|
|
662 | if (prop.weight != rxvt_fontprop::unset) |
|
|
663 | { |
|
|
664 | replace_field (fname, name, 2, 0, |
|
|
665 | prop.weight < rxvt_fontprop::bold |
|
|
666 | ? "medium" : "bold"); |
|
|
667 | set_name (strdup (fname)); |
|
|
668 | } |
|
|
669 | |
|
|
670 | if (prop.slant != rxvt_fontprop::unset) |
|
|
671 | { |
|
|
672 | replace_field (fname, name, 3, 0, |
|
|
673 | prop.slant < rxvt_fontprop::italic |
|
|
674 | ? "r" : "i"); // TODO: handle "o"blique, too |
|
|
675 | set_name (strdup (fname)); |
|
|
676 | } |
|
|
677 | } |
|
|
678 | |
|
|
679 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
|
|
680 | ? 0 : prop.height); |
|
|
681 | |
|
|
682 | struct font_weight { |
|
|
683 | char *name; |
|
|
684 | int diff; |
|
|
685 | |
|
|
686 | void clear () |
|
|
687 | { |
|
|
688 | name = 0; |
|
|
689 | diff = 0x7fffffff; |
|
|
690 | } |
|
|
691 | |
|
|
692 | font_weight () { clear (); } |
|
|
693 | ~font_weight () { free (name); } |
|
|
694 | }; |
544 | |
695 | |
545 | char **list; |
696 | char **list; |
546 | int count; |
697 | int count; |
547 | list = XListFonts (DISPLAY, name, 1024, &count); |
698 | list = XListFonts (disp, name, 4000, &count); |
|
|
699 | |
548 | set_name (0); |
700 | set_name (0); |
549 | |
701 | |
550 | if (!list) |
702 | if (!list) |
551 | return false; |
703 | return false; |
552 | |
704 | |
553 | int bestdiff = 0x7fffffff; |
705 | font_weight *fonts = new font_weight[count]; |
|
|
706 | |
554 | for (int i = 0; i < count; i++) |
707 | for (int i = 0; i < count; i++) |
555 | { |
708 | { |
556 | rxvt_fontprop p; |
709 | rxvt_fontprop p; |
557 | char fname[1024]; |
710 | char fname[1024]; |
558 | fix_scalable (fname, list[i], prop); |
711 | |
|
|
712 | int diff = 0; |
|
|
713 | |
|
|
714 | if (replace_field (fname, list[i], 6, '0', field_str)) |
|
|
715 | diff += 10; // slightly penalize scalable fonts |
|
|
716 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
717 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
559 | |
718 | |
560 | if (!set_properties (p, fname)) |
719 | if (!set_properties (p, fname)) |
561 | continue; |
720 | continue; |
562 | |
721 | |
|
|
722 | if (prop.height != rxvt_fontprop::unset |
563 | if (p.height > prop.height) // weed out too large fonts |
723 | && p.height > prop.height) // weed out too large fonts |
564 | continue; |
724 | continue; |
565 | |
725 | |
566 | int diff = (prop.height - p.height) * 32 |
726 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
567 | + abs (prop.weight - p.weight) |
727 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
568 | + abs (prop.slant - p.slant ); |
728 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
|
|
729 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
569 | |
730 | |
570 | if (!name // compare against best found so far |
731 | fonts[i].name = strdup (fname); |
571 | || diff < bestdiff) |
732 | fonts[i].diff = diff; |
572 | { |
|
|
573 | set_name (strdup (fname)); |
|
|
574 | bestdiff = diff; |
|
|
575 | } |
|
|
576 | } |
733 | } |
577 | |
734 | |
578 | XFreeFontNames (list); |
735 | XFreeFontNames (list); |
579 | |
736 | |
580 | if (!name) |
737 | // this loop only iterates when the guessed font-size is too small |
581 | return false; |
738 | for (;;) |
|
|
739 | { |
|
|
740 | font_weight *best = fonts + count - 1; |
582 | |
741 | |
583 | f = XLoadQueryFont (DISPLAY, name); |
742 | for (font_weight *w = best; w-- > fonts; ) |
|
|
743 | if (w->diff <= best->diff) |
|
|
744 | best = w; |
|
|
745 | |
|
|
746 | if (!best->name |
|
|
747 | || !(f = XLoadQueryFont (disp, best->name))) |
|
|
748 | break; |
|
|
749 | |
|
|
750 | set_name (best->name); |
|
|
751 | best->clear (); |
|
|
752 | |
|
|
753 | ascent = f->ascent; |
|
|
754 | descent = f->descent; |
|
|
755 | height = ascent + descent; |
|
|
756 | |
|
|
757 | if (prop.height == rxvt_fontprop::unset |
|
|
758 | || height <= prop.height) |
|
|
759 | break; // font is ready for use |
|
|
760 | |
|
|
761 | // PIXEL_SIZE small enough, but real height too large |
|
|
762 | clear (); |
|
|
763 | } |
|
|
764 | |
|
|
765 | delete [] fonts; |
584 | |
766 | |
585 | if (!f) |
767 | if (!f) |
586 | return false; |
768 | return false; |
587 | |
769 | |
588 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
770 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
589 | char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
771 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
590 | |
772 | |
591 | if (registry && encoding) |
773 | if (registry && encoding) |
592 | { |
774 | { |
593 | char charset[64]; |
775 | char charset[64]; |
594 | snprintf (charset, 64, "%s-%s", registry, encoding); |
776 | snprintf (charset, 64, "%s-%s", registry, encoding); |
595 | |
777 | |
596 | cs = codeset_from_name (charset); |
778 | cs = codeset_from_name (charset); |
597 | } |
779 | } |
598 | else |
780 | else |
599 | { |
781 | { |
600 | const char *charset = get_property (f, "FONT", 0); |
782 | const char *charset = get_property (f, XA_FONT, 0); |
601 | |
783 | |
602 | if (!charset) |
784 | if (!charset) |
603 | charset = name; |
785 | charset = name; |
604 | |
786 | |
605 | int count = 13; |
787 | int count = 13; |
… | |
… | |
617 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
799 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
618 | |
800 | |
619 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
801 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
620 | enc2b = encm || f->max_char_or_byte2 > 255; |
802 | enc2b = encm || f->max_char_or_byte2 > 255; |
621 | |
803 | |
622 | ascent = f->ascent; |
|
|
623 | descent = f->descent; |
|
|
624 | height = ascent + descent; |
|
|
625 | |
|
|
626 | slow = false; |
804 | slow = false; |
627 | |
805 | |
|
|
806 | #if 1 // only used for slow detection, TODO optimize |
628 | if (f->min_bounds.width == f->max_bounds.width) |
807 | if (f->min_bounds.width == f->max_bounds.width || !f->per_char) |
629 | width = f->min_bounds.width; |
|
|
630 | else if (f->per_char == NULL) |
|
|
631 | width = f->max_bounds.width; |
808 | width = f->max_bounds.width; |
632 | else |
809 | else |
633 | { |
810 | { |
634 | slow = true; |
811 | slow = true; |
635 | |
812 | |
… | |
… | |
645 | width = f->per_char[N].width; |
822 | width = f->per_char[N].width; |
646 | |
823 | |
647 | --N; |
824 | --N; |
648 | } |
825 | } |
649 | } |
826 | } |
|
|
827 | #endif |
|
|
828 | |
|
|
829 | width = 1; |
|
|
830 | |
|
|
831 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
|
|
832 | { |
|
|
833 | if (FROM_UNICODE (cs, *t) == NOCHAR) |
|
|
834 | continue; |
|
|
835 | |
|
|
836 | // ignore characters we wouldn't use anyways |
|
|
837 | bool careful; |
|
|
838 | if (!has_char (*t, &prop, careful)) |
|
|
839 | continue; |
|
|
840 | |
|
|
841 | XChar2b ch = { *t >> 8, *t }; |
|
|
842 | |
|
|
843 | XCharStruct g; |
|
|
844 | int dir_ret, asc_ret, des_ret; |
|
|
845 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
|
|
846 | |
|
|
847 | int wcw = WCWIDTH (*t); |
|
|
848 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
|
|
849 | |
|
|
850 | if (width < g.width) width = g.width; |
|
|
851 | } |
650 | |
852 | |
651 | if (cs == CS_UNKNOWN) |
853 | if (cs == CS_UNKNOWN) |
652 | { |
854 | { |
653 | fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
855 | fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
654 | |
856 | |
655 | clear (); |
857 | clear (); |
656 | |
|
|
657 | return false; |
858 | return false; |
658 | } |
859 | } |
|
|
860 | |
|
|
861 | #if 0 // do it per-character |
|
|
862 | if (prop && width > prop->width) |
|
|
863 | { |
|
|
864 | clear (); |
|
|
865 | return false; |
|
|
866 | } |
|
|
867 | #endif |
659 | |
868 | |
660 | return true; |
869 | return true; |
661 | } |
870 | } |
662 | |
871 | |
663 | void |
872 | void |
664 | rxvt_font_x11::clear () |
873 | rxvt_font_x11::clear () |
665 | { |
874 | { |
666 | if (f) |
875 | if (f) |
667 | { |
876 | { |
668 | XFreeFont (DISPLAY, f); |
877 | XFreeFont (term->dpy, f); |
669 | f = 0; |
878 | f = 0; |
670 | } |
879 | } |
671 | } |
880 | } |
672 | |
881 | |
673 | bool |
882 | bool |
674 | rxvt_font_x11::has_codepoint (unicode_t unicode) |
883 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
675 | { |
884 | { |
676 | uint32_t ch = FROM_UNICODE (cs, unicode); |
885 | uint32_t ch = FROM_UNICODE (cs, unicode); |
677 | |
886 | |
678 | if (ch == NOCHAR) |
887 | if (ch == NOCHAR) |
679 | return false; |
888 | return false; |
… | |
… | |
688 | |
897 | |
689 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
898 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
690 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
899 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
691 | return false; |
900 | return false; |
692 | |
901 | |
693 | if (!f->per_char) |
902 | if (f->per_char) |
694 | return true; |
903 | { |
695 | |
|
|
696 | int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1; |
904 | int D = f->max_char_or_byte2 - f->min_char_or_byte2 + 1; |
697 | int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2; |
905 | int N = (byte1 - f->min_byte1) * D + byte2 - f->min_char_or_byte2; |
698 | |
906 | |
699 | xcs = f->per_char + N; |
907 | xcs = f->per_char + N; |
|
|
908 | } |
|
|
909 | else |
|
|
910 | xcs = &f->max_bounds; |
700 | } |
911 | } |
701 | else |
912 | else |
702 | { |
913 | { |
703 | if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2) |
914 | if (ch < f->min_char_or_byte2 || ch > f->max_char_or_byte2) |
704 | return false; |
915 | return false; |
705 | |
916 | |
706 | if (!f->per_char) |
917 | if (f->per_char) |
707 | return true; |
|
|
708 | |
|
|
709 | xcs = f->per_char + (ch - f->min_char_or_byte2); |
918 | xcs = f->per_char + (ch - f->min_char_or_byte2); |
|
|
919 | else |
|
|
920 | xcs = &f->max_bounds; |
710 | } |
921 | } |
711 | |
922 | |
712 | if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0 |
923 | if (xcs->lbearing == 0 && xcs->rbearing == 0 && xcs->width == 0 |
713 | && xcs->ascent == 0 && xcs->descent == 0) |
924 | && xcs->ascent == 0 && xcs->descent == 0) |
|
|
925 | return false; |
|
|
926 | |
|
|
927 | if (!prop || prop->width == rxvt_fontprop::unset) |
|
|
928 | return true; |
|
|
929 | |
|
|
930 | // check wether character overlaps previous/next character |
|
|
931 | int w = xcs->rbearing - xcs->lbearing; |
|
|
932 | int wcw = max (WCWIDTH (unicode), 1); |
|
|
933 | |
|
|
934 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
|
|
935 | |
|
|
936 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
714 | return false; |
937 | return false; |
715 | |
938 | |
716 | return true; |
939 | return true; |
717 | } |
940 | } |
718 | |
941 | |
… | |
… | |
724 | // this looks like a mess /. |
947 | // this looks like a mess /. |
725 | // and it is a mess /. |
948 | // and it is a mess /. |
726 | // yet we are trying to be perfect /. |
949 | // yet we are trying to be perfect /. |
727 | // but the result still isn't perfect /. |
950 | // but the result still isn't perfect /. |
728 | |
951 | |
|
|
952 | dTermDisplay; |
|
|
953 | dTermGC; |
|
|
954 | |
729 | bool slow = this->slow |
955 | bool slow = this->slow |
730 | || width != r->TermWin.fwidth |
956 | || width != term->fwidth |
731 | || height != r->TermWin.fheight; |
957 | || height != term->fheight; |
732 | |
958 | |
733 | int base = r->TermWin.fbase; |
959 | int base = ascent; // sorry, incorrect: term->fbase; |
734 | |
960 | |
735 | XGCValues v; |
961 | XGCValues v; |
736 | v.foreground = r->pix_colors[fg]; |
962 | v.foreground = term->pix_colors[fg]; |
737 | v.font = f->fid; |
963 | v.font = f->fid; |
738 | |
964 | |
739 | if (enc2b) |
965 | if (enc2b) |
740 | { |
966 | { |
741 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
967 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
742 | |
968 | |
743 | if (bg == Color_bg && !slow) |
969 | if (bg == Color_bg && !slow) |
744 | { |
970 | { |
745 | v.background = r->pix_colors[bg]; |
971 | v.background = term->pix_colors[bg]; |
746 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
972 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
747 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
973 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
748 | } |
974 | } |
749 | else |
975 | else |
750 | { |
976 | { |
751 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
977 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
752 | |
978 | |
753 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
979 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
754 | |
980 | |
755 | if (slow) |
981 | if (slow) |
756 | { |
982 | { |
757 | do |
983 | do |
758 | { |
984 | { |
759 | if (xc->byte1 || xc->byte2) |
985 | if (xc->byte1 || xc->byte2) |
760 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
986 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
761 | |
987 | |
762 | x += r->TermWin.fwidth; |
988 | x += term->fwidth; |
763 | xc++; len--; |
989 | xc++; len--; |
764 | } |
990 | } |
765 | while (len); |
991 | while (len); |
766 | } |
992 | } |
767 | else |
993 | else |
768 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
994 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
769 | } |
995 | } |
770 | } |
996 | } |
771 | else |
997 | else |
772 | { |
998 | { |
773 | const char *xc = enc_char (text, len, cs, slow); |
999 | const char *xc = enc_char (text, len, cs, slow); |
774 | |
1000 | |
775 | if (bg == Color_bg && !slow) |
1001 | if (bg == Color_bg && !slow) |
776 | { |
1002 | { |
777 | v.background = r->pix_colors[bg]; |
1003 | v.background = term->pix_colors[bg]; |
778 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1004 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
779 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1005 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
780 | } |
1006 | } |
781 | else |
1007 | else |
782 | { |
1008 | { |
783 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1009 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
784 | |
1010 | |
785 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1011 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
786 | |
1012 | |
787 | if (slow) |
1013 | if (slow) |
788 | { |
1014 | { |
789 | do |
1015 | do |
790 | { |
1016 | { |
791 | if (*xc) |
1017 | if (*xc) |
792 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1018 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
793 | |
1019 | |
794 | x += r->TermWin.fwidth; |
1020 | x += term->fwidth; |
795 | xc++; len--; |
1021 | xc++; len--; |
796 | } |
1022 | } |
797 | while (len); |
1023 | while (len); |
798 | } |
1024 | } |
799 | else |
1025 | else |
800 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1026 | XDrawString (disp, d, gc, x, y + base, xc, len); |
801 | } |
1027 | } |
802 | } |
1028 | } |
803 | } |
1029 | } |
804 | |
1030 | |
805 | ///////////////////////////////////////////////////////////////////////////// |
1031 | ///////////////////////////////////////////////////////////////////////////// |
806 | |
1032 | |
807 | #if XFT |
1033 | #if XFT |
808 | #if 0 |
|
|
809 | #define UNIBITS 21 |
|
|
810 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
|
|
811 | #define SWATHBITS 8 |
|
|
812 | #endif |
|
|
813 | |
1034 | |
814 | struct rxvt_font_xft : rxvt_font { |
1035 | struct rxvt_font_xft : rxvt_font { |
815 | rxvt_font_xft () { f = 0; } |
1036 | rxvt_font_xft () { f = 0; } |
816 | |
1037 | |
817 | void clear (); |
1038 | void clear (); |
818 | |
1039 | |
819 | rxvt_fontprop properties (); |
1040 | rxvt_fontprop properties (); |
820 | |
1041 | |
821 | bool load (const rxvt_fontprop &prop); |
1042 | bool load (const rxvt_fontprop &prop, bool force_prop); |
822 | |
1043 | |
823 | void draw (rxvt_drawable &d, int x, int y, |
1044 | void draw (rxvt_drawable &d, int x, int y, |
824 | const text_t *text, int len, |
1045 | const text_t *text, int len, |
825 | int fg, int bg); |
1046 | int fg, int bg); |
826 | |
1047 | |
827 | bool has_codepoint (unicode_t unicode); |
1048 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; |
828 | |
1049 | |
829 | protected: |
1050 | protected: |
830 | XftFont *f; |
1051 | XftFont *f; |
831 | }; |
1052 | }; |
832 | |
1053 | |
833 | void |
1054 | void |
834 | rxvt_font_xft::clear () |
1055 | rxvt_font_xft::clear () |
835 | { |
1056 | { |
836 | if (f) |
1057 | if (f) |
837 | { |
1058 | { |
838 | XftFontClose (DISPLAY, f); |
1059 | XftFontClose (term->dpy, f); |
839 | f = 0; |
1060 | f = 0; |
840 | } |
1061 | } |
841 | } |
1062 | } |
842 | |
1063 | |
843 | rxvt_fontprop |
1064 | rxvt_fontprop |
… | |
… | |
847 | |
1068 | |
848 | FT_Face face = XftLockFace (f); |
1069 | FT_Face face = XftLockFace (f); |
849 | |
1070 | |
850 | p.width = width; |
1071 | p.width = width; |
851 | p.height = height; |
1072 | p.height = height; |
|
|
1073 | p.ascent = ascent; |
852 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1074 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
853 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1075 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
854 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1076 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
855 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1077 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
856 | |
1078 | |
… | |
… | |
858 | |
1080 | |
859 | return p; |
1081 | return p; |
860 | } |
1082 | } |
861 | |
1083 | |
862 | bool |
1084 | bool |
863 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1085 | rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop) |
864 | { |
1086 | { |
865 | #if 0 |
1087 | dTermDisplay; |
866 | for (int i = 0; i < SWATHCOUNT; i++) |
|
|
867 | cvr[i] = 0; |
|
|
868 | #endif |
|
|
869 | |
1088 | |
870 | clear (); |
1089 | clear (); |
871 | |
1090 | |
872 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1091 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
873 | |
1092 | |
874 | if (!p) |
1093 | if (!p) |
875 | return false; |
1094 | return false; |
876 | |
1095 | |
877 | FcValue v; |
1096 | FcValue v; |
878 | |
1097 | |
|
|
1098 | if (prop.height != rxvt_fontprop::unset |
879 | if (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch) |
1099 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
|
|
1100 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
880 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1101 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
881 | |
1102 | |
|
|
1103 | if (prop.weight != rxvt_fontprop::unset |
882 | if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1104 | && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)) |
883 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1105 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
884 | |
1106 | |
|
|
1107 | if (prop.slant != rxvt_fontprop::unset |
885 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
1108 | && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)) |
886 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1109 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
887 | |
|
|
888 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
|
|
889 | FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
890 | |
1110 | |
891 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1111 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
892 | // clip width, we can't do better, or can we? |
1112 | // clip width, we can't do better, or can we? |
893 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1113 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
894 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
1114 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); |
895 | #endif |
1115 | #endif |
|
|
1116 | |
|
|
1117 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
|
|
1118 | FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
1119 | |
|
|
1120 | // store generated name so iso14755 view gives better results |
|
|
1121 | set_name ((char *)FcNameUnparse (p)); |
896 | |
1122 | |
897 | XftResult result; |
1123 | XftResult result; |
898 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1124 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
899 | |
1125 | |
900 | FcPatternDestroy (p); |
1126 | FcPatternDestroy (p); |
901 | |
1127 | |
902 | if (!match) |
1128 | if (!match) |
903 | return false; |
1129 | return false; |
904 | |
1130 | |
905 | f = XftFontOpenPattern (DISPLAY, match); |
|
|
906 | |
|
|
907 | if (!f) |
|
|
908 | { |
|
|
909 | FcPatternDestroy (match); |
|
|
910 | return false; |
|
|
911 | } |
|
|
912 | |
|
|
913 | FT_Face face = XftLockFace (f); |
|
|
914 | |
|
|
915 | slow = !FT_IS_FIXED_WIDTH (face); |
|
|
916 | |
|
|
917 | int ftheight = 0; |
1131 | int ftheight = 0; |
|
|
1132 | bool success = true; |
918 | |
1133 | |
919 | for (;;) |
1134 | for (;;) |
920 | { |
1135 | { |
921 | XGlyphInfo g1, g2; |
1136 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
922 | FcChar8 c; |
|
|
923 | |
1137 | |
924 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
1138 | if (!f) |
925 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
1139 | { |
|
|
1140 | success = false; |
|
|
1141 | break; |
|
|
1142 | } |
926 | |
1143 | |
927 | if (g1.xOff != g2.xOff) // don't simply trust the font |
1144 | FT_Face face = XftLockFace (f); |
928 | slow = true; |
|
|
929 | |
1145 | |
930 | width = g2.xOff; |
|
|
931 | ascent = (face->size->metrics.ascender + 63) >> 6; |
1146 | ascent = (face->size->metrics.ascender + 63) >> 6; |
932 | descent = (-face->size->metrics.descender + 63) >> 6; |
1147 | descent = (-face->size->metrics.descender + 63) >> 6; |
933 | height = ascent + descent; |
1148 | height = max (ascent + descent, (face->size->metrics.height + 63) >> 6); |
|
|
1149 | width = 0; |
934 | |
1150 | |
|
|
1151 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
|
|
1152 | |
|
|
1153 | XftUnlockFace (f); |
|
|
1154 | |
|
|
1155 | int glheight = height; |
|
|
1156 | |
|
|
1157 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
|
|
1158 | { |
|
|
1159 | FcChar16 ch = *t; |
|
|
1160 | |
|
|
1161 | if (cs != CS_UNICODE |
|
|
1162 | && ch > 0x100 |
|
|
1163 | && FROM_UNICODE (cs, ch) == NOCHAR) |
|
|
1164 | continue; |
|
|
1165 | |
|
|
1166 | // ignore characters we wouldn't use anyways |
|
|
1167 | bool careful; |
|
|
1168 | if (!has_char (*t, &prop, careful)) |
|
|
1169 | continue; |
|
|
1170 | |
|
|
1171 | XGlyphInfo g; |
|
|
1172 | XftTextExtents16 (disp, f, &ch, 1, &g); |
|
|
1173 | |
|
|
1174 | g.width -= g.x; |
|
|
1175 | |
|
|
1176 | int wcw = WCWIDTH (ch); |
|
|
1177 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
|
|
1178 | |
|
|
1179 | if (width < g.width ) width = g.width; |
|
|
1180 | if (height < g.height ) height = g.height; |
|
|
1181 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1182 | } |
|
|
1183 | |
|
|
1184 | if (!width) |
|
|
1185 | { |
|
|
1186 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1187 | |
|
|
1188 | XftFontClose (disp, f); |
|
|
1189 | f = 0; |
|
|
1190 | |
|
|
1191 | success = false; |
|
|
1192 | break; |
|
|
1193 | } |
|
|
1194 | |
|
|
1195 | if (prop.height == rxvt_fontprop::unset |
935 | if (height <= prop.height || !prop.height) |
1196 | || (height <= prop.height && glheight <= prop.height) |
|
|
1197 | || height <= 2 |
|
|
1198 | || !scalable) |
936 | break; |
1199 | break; |
937 | |
1200 | |
938 | if (ftheight) |
1201 | if (ftheight) |
939 | { |
1202 | { |
940 | // take smaller steps near the end |
1203 | // take smaller steps near the end |
941 | if (height > prop.height + 1) ftheight++; |
1204 | if (height > prop.height + 1) ftheight++; |
942 | if (height > prop.height + 2) ftheight++; |
1205 | if (height > prop.height + 2) ftheight++; |
943 | if (height > prop.height + 3) ftheight++; |
1206 | if (height > prop.height + 3) ftheight++; |
944 | |
1207 | |
945 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
1208 | ftheight -= height - prop.height; |
946 | } |
1209 | } |
947 | else |
1210 | else |
948 | FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
1211 | ftheight = prop.height - 1; |
|
|
1212 | |
|
|
1213 | XftFontClose (disp, f); |
|
|
1214 | FcPatternDel (match, FC_PIXEL_SIZE); |
|
|
1215 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
|
|
1216 | } |
|
|
1217 | |
|
|
1218 | FcPatternDestroy (match); |
|
|
1219 | |
|
|
1220 | #if 0 // do it per-character |
|
|
1221 | if (prop.width != rxvt_fontprop::unset && width > prop.width) |
949 | } |
1222 | { |
|
|
1223 | clear (); |
|
|
1224 | success = false; |
|
|
1225 | } |
|
|
1226 | #endif |
950 | |
1227 | |
951 | XftUnlockFace (f); |
1228 | return success; |
|
|
1229 | } |
|
|
1230 | |
|
|
1231 | bool |
|
|
1232 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
|
|
1233 | { |
|
|
1234 | careful = false; |
|
|
1235 | |
|
|
1236 | if (!XftCharExists (term->dpy, f, unicode)) |
|
|
1237 | return false; |
|
|
1238 | |
|
|
1239 | if (!prop || prop->width == rxvt_fontprop::unset) |
|
|
1240 | return true; |
|
|
1241 | |
|
|
1242 | // check character against base font bounding box |
|
|
1243 | FcChar32 ch = unicode; |
|
|
1244 | XGlyphInfo g; |
|
|
1245 | XftTextExtents32 (term->dpy, f, &ch, 1, &g); |
|
|
1246 | |
|
|
1247 | int w = g.width - g.x; |
|
|
1248 | int wcw = max (WCWIDTH (unicode), 1); |
|
|
1249 | |
|
|
1250 | careful = g.x > 0 || w > prop->width * wcw; |
|
|
1251 | |
|
|
1252 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
|
|
1253 | return false; |
|
|
1254 | |
|
|
1255 | // this weeds out _totally_ broken fonts, or glyphs |
|
|
1256 | if (!OVERLAP_OK (g.xOff, wcw, prop)) |
|
|
1257 | return false; |
952 | |
1258 | |
953 | return true; |
1259 | return true; |
954 | } |
|
|
955 | |
|
|
956 | bool |
|
|
957 | rxvt_font_xft::has_codepoint (unicode_t unicode) |
|
|
958 | { |
|
|
959 | return XftCharExists (DISPLAY, f, unicode); |
|
|
960 | } |
1260 | } |
961 | |
1261 | |
962 | void |
1262 | void |
963 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1263 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
964 | const text_t *text, int len, |
1264 | const text_t *text, int len, |
965 | int fg, int bg) |
1265 | int fg, int bg) |
966 | { |
1266 | { |
967 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1267 | XGlyphInfo extents; |
|
|
1268 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
|
|
1269 | XftGlyphSpec *ep = enc; |
968 | |
1270 | |
969 | if (0 && !slow && width == r->TermWin.fwidth) |
1271 | dTermDisplay; |
|
|
1272 | dTermGC; |
|
|
1273 | |
|
|
1274 | int w = term->fwidth * len; |
|
|
1275 | int h = term->fheight; |
|
|
1276 | |
|
|
1277 | bool buffered = bg >= 0 // we don't use a transparent bg |
|
|
1278 | #ifndef FORCE_UNBUFFERED_XFT |
|
|
1279 | # ifdef ENABLE_TRANSPARENCY |
|
|
1280 | || !term->am_transparent // we aren't transparent |
|
|
1281 | # endif |
|
|
1282 | #endif |
|
|
1283 | ; |
|
|
1284 | |
|
|
1285 | // cut trailing spaces |
|
|
1286 | while (len && text [len - 1] == ' ') |
|
|
1287 | len--; |
|
|
1288 | |
|
|
1289 | int x_ = buffered ? 0 : x; |
|
|
1290 | int y_ = buffered ? 0 : y; |
|
|
1291 | |
|
|
1292 | while (len) |
|
|
1293 | { |
|
|
1294 | int cwidth = term->fwidth; |
|
|
1295 | FcChar32 fc = *text++; len--; |
|
|
1296 | |
|
|
1297 | while (len && *text == NOCHAR) |
|
|
1298 | text++, len--, cwidth += term->fwidth; |
|
|
1299 | |
|
|
1300 | if (fc != ' ') // skip spaces |
|
|
1301 | { |
|
|
1302 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1303 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
|
|
1304 | |
|
|
1305 | ep->glyph = glyph; |
|
|
1306 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
|
|
1307 | ep->y = y_ + ascent; |
|
|
1308 | |
|
|
1309 | if (extents.xOff == 0) |
|
|
1310 | ep->x = x_ + cwidth; |
|
|
1311 | |
|
|
1312 | ep++; |
|
|
1313 | } |
|
|
1314 | |
|
|
1315 | x_ += cwidth; |
970 | { |
1316 | } |
971 | if (sizeof (text_t) == sizeof (FcChar16)) |
1317 | |
972 | XftDrawString16 (d, &r->pix_colors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
1318 | if (buffered) |
|
|
1319 | { |
|
|
1320 | if (ep != enc) |
|
|
1321 | { |
|
|
1322 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
|
|
1323 | |
|
|
1324 | if (0) |
|
|
1325 | ; |
|
|
1326 | #ifdef ENABLE_TRANSPARENCY |
|
|
1327 | else if (bg < 0 && term->am_pixmap_trans) |
|
|
1328 | XCopyArea (disp, term->pixmap, d2, gc, |
|
|
1329 | x + term->window_vt_x, y + term->window_vt_y, |
|
|
1330 | w, h, 0, 0); |
|
|
1331 | #endif |
|
|
1332 | #ifdef XPM_BACKGROUND |
|
|
1333 | else if (bg < 0 && term->bgPixmap.pixmap) |
|
|
1334 | { |
|
|
1335 | XGCValues gcv; |
|
|
1336 | |
|
|
1337 | gcv.fill_style = FillTiled; |
|
|
1338 | gcv.tile = term->pixmap; |
|
|
1339 | gcv.ts_x_origin = -x; |
|
|
1340 | gcv.ts_y_origin = -y; |
|
|
1341 | |
|
|
1342 | GC gc2 = XCreateGC (disp, d2, |
|
|
1343 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
|
|
1344 | &gcv); |
|
|
1345 | |
|
|
1346 | XFillRectangle (disp, d2, gc2, 0, 0, w, h); |
|
|
1347 | |
|
|
1348 | XFreeGC (disp, gc2); |
|
|
1349 | } |
|
|
1350 | #endif |
|
|
1351 | else |
|
|
1352 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
|
|
1353 | |
|
|
1354 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1355 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
|
|
1356 | } |
973 | else |
1357 | else |
974 | XftDrawString32 (d, &r->pix_colors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
1358 | clear_rect (d, x, y, w, h, bg); |
975 | } |
1359 | } |
976 | else |
1360 | else |
977 | { |
1361 | { |
978 | while (len) |
1362 | clear_rect (d, x, y, w, h, bg); |
979 | { |
1363 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
980 | if (*text != NOCHAR && *text != ' ') |
|
|
981 | { |
|
|
982 | int fwidth = r->TermWin.fwidth; |
|
|
983 | if (len >= 2 && text[1] == NOCHAR) |
|
|
984 | fwidth *= 2; |
|
|
985 | |
|
|
986 | XGlyphInfo extents; |
|
|
987 | if (sizeof (text_t) == sizeof (FcChar16)) |
|
|
988 | { |
|
|
989 | XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents); |
|
|
990 | XftDrawString16 (d, &r->pix_colors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
991 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
|
|
992 | } |
|
|
993 | else |
|
|
994 | { |
|
|
995 | XGlyphInfo extents; |
|
|
996 | XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents); |
|
|
997 | XftDrawString32 (d, &r->pix_colors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
998 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
|
|
999 | } |
|
|
1000 | } |
|
|
1001 | |
|
|
1002 | x += r->TermWin.fwidth; |
|
|
1003 | text++; |
|
|
1004 | len--; |
|
|
1005 | } |
|
|
1006 | } |
1364 | } |
1007 | } |
1365 | } |
|
|
1366 | |
1008 | #endif |
1367 | #endif |
1009 | |
1368 | |
1010 | ///////////////////////////////////////////////////////////////////////////// |
1369 | ///////////////////////////////////////////////////////////////////////////// |
1011 | |
1370 | |
1012 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1371 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1013 | : r (r), fontdesc (0) |
1372 | : fontdesc (0), term (term) |
1014 | { |
1373 | { |
1015 | clear (); |
1374 | clear (); |
1016 | } |
1375 | } |
1017 | |
1376 | |
1018 | rxvt_fontset::~rxvt_fontset () |
1377 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1021 | } |
1380 | } |
1022 | |
1381 | |
1023 | void |
1382 | void |
1024 | rxvt_fontset::clear () |
1383 | rxvt_fontset::clear () |
1025 | { |
1384 | { |
|
|
1385 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
|
|
1386 | = rxvt_fontprop::unset; |
|
|
1387 | force_prop = false; |
|
|
1388 | |
1026 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1389 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1027 | FONT_UNREF (*i); |
1390 | FONT_UNREF (*i); |
1028 | |
1391 | |
|
|
1392 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
|
|
1393 | delete *p; |
|
|
1394 | |
1029 | free (fontdesc); fontdesc = 0; |
1395 | free (fontdesc); fontdesc = 0; |
1030 | |
1396 | |
1031 | fonts.clear (); |
1397 | fonts.clear (); |
1032 | base_id = 0; |
|
|
1033 | base_prop.height = 0x7fffffff; |
|
|
1034 | base_prop.weight = rxvt_fontprop::medium; |
|
|
1035 | base_prop.slant = rxvt_fontprop::roman; |
|
|
1036 | |
1398 | |
1037 | fallback = fallback_fonts; |
1399 | fallback = fallback_fonts; |
1038 | } |
1400 | } |
1039 | |
1401 | |
1040 | rxvt_font * |
1402 | rxvt_font * |
… | |
… | |
1043 | rxvt_font *f; |
1405 | rxvt_font *f; |
1044 | |
1406 | |
1045 | if (!name || !*name) |
1407 | if (!name || !*name) |
1046 | { |
1408 | { |
1047 | name = ""; |
1409 | name = ""; |
1048 | f = new rxvt_font_default; |
1410 | f = new rxvt_font_default (this); |
1049 | } |
1411 | } |
1050 | #if XFT |
1412 | #if XFT |
1051 | else if (!strncmp (name, "xft:", 4)) |
1413 | else if (!strncmp (name, "xft:", 4)) |
1052 | { |
1414 | { |
1053 | name += 4; |
1415 | name += 4; |
1054 | f = new rxvt_font_xft; |
1416 | f = new rxvt_font_xft (); |
1055 | } |
1417 | } |
1056 | #endif |
1418 | #endif |
1057 | else if (!strncmp (name, "x:", 2)) |
1419 | else if (!strncmp (name, "x:", 2)) |
1058 | { |
1420 | { |
1059 | name += 2; |
1421 | name += 2; |
1060 | f = new rxvt_font_x11; |
1422 | f = new rxvt_font_x11; |
1061 | } |
1423 | } |
1062 | else |
1424 | else |
1063 | f = new rxvt_font_x11; |
1425 | f = new rxvt_font_x11; |
1064 | |
1426 | |
1065 | f->fs = this; |
|
|
1066 | f->set_term (r); |
1427 | f->set_term (term); |
1067 | f->set_name (strdup (name)); |
1428 | f->set_name (strdup (name)); |
1068 | |
1429 | |
1069 | f->cs = cs; |
1430 | f->cs = cs; |
1070 | f->loaded = false; |
1431 | f->loaded = false; |
1071 | |
1432 | |
… | |
… | |
1082 | char buf[512]; |
1443 | char buf[512]; |
1083 | const char *end; |
1444 | const char *end; |
1084 | |
1445 | |
1085 | do |
1446 | do |
1086 | { |
1447 | { |
1087 | while (*desc <= ' ') desc++; |
1448 | while (*desc && *desc <= ' ') |
|
|
1449 | desc++; |
|
|
1450 | |
|
|
1451 | codeset cs = CS_UNICODE; |
1088 | |
1452 | |
1089 | if (*desc == '[') |
1453 | if (*desc == '[') |
1090 | { |
1454 | { |
1091 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1455 | char spec[256]; |
1092 | |
|
|
1093 | //const char *extra = desc++; // not yet used |
1456 | const char *extra = ++desc; // not yet used |
1094 | |
1457 | |
1095 | desc = strchr (desc, ']'); |
1458 | desc = strchr (desc, ']'); |
1096 | |
1459 | |
1097 | if (!desc) |
1460 | if (!desc) |
1098 | { |
1461 | { |
1099 | fprintf (stderr, "ERROR: opening '[' without closing ']' in font specification.\n"); |
1462 | rxvt_warn ("ERROR: opening '[' without closing ']' in font specification, trying to continue.\n"); |
1100 | break; |
1463 | break; |
1101 | } |
1464 | } |
|
|
1465 | |
|
|
1466 | memcpy (spec, extra, min (desc - extra, 255)); |
|
|
1467 | spec[min (desc - extra, 255)] = 0; |
|
|
1468 | |
|
|
1469 | if (!strncmp (extra, "codeset=", sizeof ("codeset=") - 1)) |
|
|
1470 | cs = codeset_from_name (spec + sizeof ("codeset=") - 1); |
|
|
1471 | else |
|
|
1472 | rxvt_warn ("unknown parameter '%s' in font specification, skipping.\n", spec); |
1102 | |
1473 | |
1103 | desc++; |
1474 | desc++; |
1104 | while (*desc <= ' ') desc++; |
1475 | while (*desc <= ' ') desc++; |
1105 | } |
1476 | } |
1106 | |
1477 | |
… | |
… | |
1111 | if (end - desc < 511) |
1482 | if (end - desc < 511) |
1112 | { |
1483 | { |
1113 | strncpy (buf, desc, end - desc); |
1484 | strncpy (buf, desc, end - desc); |
1114 | buf[end - desc] = 0; |
1485 | buf[end - desc] = 0; |
1115 | |
1486 | |
1116 | fonts.push_back (new_font (buf, CS_UNICODE)); |
1487 | fonts.push_back (new_font (buf, cs)); |
1117 | } |
1488 | } |
|
|
1489 | else |
|
|
1490 | rxvt_warn ("fontset element too long (>511 bytes), ignored."); |
1118 | |
1491 | |
1119 | desc = end + 1; |
1492 | desc = end + 1; |
1120 | } |
1493 | } |
1121 | while (*end); |
1494 | while (*end); |
1122 | } |
1495 | } |
1123 | } |
1496 | } |
1124 | |
1497 | |
1125 | bool |
1498 | bool |
1126 | rxvt_fontset::realize_font (int i) |
1499 | rxvt_fontset::realize_font (int i) |
1127 | { |
1500 | { |
|
|
1501 | if (i < 0 || i >= fonts.size ()) |
|
|
1502 | return false; |
|
|
1503 | |
1128 | if (fonts[i]->loaded) |
1504 | if (fonts[i]->loaded) |
1129 | return true; |
1505 | return true; |
1130 | |
1506 | |
1131 | fonts[i]->loaded = true; |
1507 | fonts[i]->loaded = true; |
1132 | |
1508 | |
1133 | if (!fonts[i]->load (base_prop)) |
1509 | if (!fonts[i]->load (prop, force_prop)) |
1134 | { |
1510 | { |
1135 | fonts[i]->cs = CS_UNKNOWN; |
1511 | fonts[i]->cs = CS_UNKNOWN; |
1136 | return false; |
1512 | return false; |
1137 | } |
1513 | } |
1138 | |
1514 | |
… | |
… | |
1148 | |
1524 | |
1149 | fonts.push_back (new_font (0, CS_UNICODE)); |
1525 | fonts.push_back (new_font (0, CS_UNICODE)); |
1150 | realize_font (0); |
1526 | realize_font (0); |
1151 | |
1527 | |
1152 | add_fonts (desc); |
1528 | add_fonts (desc); |
1153 | |
|
|
1154 | if (!base_id) |
|
|
1155 | base_id = 1; |
|
|
1156 | |
|
|
1157 | // we currently need a base-font, no matter what |
|
|
1158 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
|
|
1159 | { |
|
|
1160 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
|
|
1161 | add_fonts ("fixed"); |
|
|
1162 | base_id = fonts.size () - 1; |
|
|
1163 | } |
|
|
1164 | |
|
|
1165 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
|
|
1166 | return false; |
|
|
1167 | |
|
|
1168 | base_prop = fonts[base_id]->properties (); |
|
|
1169 | |
1529 | |
1170 | return true; |
1530 | return true; |
1171 | } |
1531 | } |
1172 | |
1532 | |
1173 | int |
1533 | int |
… | |
… | |
1179 | |
1539 | |
1180 | return -1; |
1540 | return -1; |
1181 | } |
1541 | } |
1182 | |
1542 | |
1183 | int |
1543 | int |
1184 | rxvt_fontset::find_font (unicode_t unicode, bool bold) |
1544 | rxvt_fontset::find_font (unicode_t unicode) |
1185 | { |
1545 | { |
|
|
1546 | if (unicode >= 1<<20) |
|
|
1547 | return 0; |
1186 | |
1548 | |
1187 | for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii |
1549 | unicode_t hi = unicode >> 8; |
1188 | i < fonts.size (); |
1550 | |
1189 | i++) |
1551 | if (hi < fmap.size () |
|
|
1552 | && fmap[hi] |
|
|
1553 | && (*fmap[hi])[unicode & 0xff] != 0xff) |
|
|
1554 | return (*fmap[hi])[unicode & 0xff]; |
|
|
1555 | |
|
|
1556 | unsigned int i; |
|
|
1557 | |
|
|
1558 | for (i = 0; i < fonts.size (); i++) |
1190 | { |
1559 | { |
1191 | rxvt_font *f = fonts[i]; |
1560 | rxvt_font *f = fonts[i]; |
1192 | |
1561 | |
1193 | if (!f->loaded) |
1562 | if (!f->loaded) |
1194 | { |
1563 | { |
1195 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1564 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1196 | goto next_font; |
1565 | goto next_font; |
1197 | |
1566 | |
1198 | if (!realize_font (i)) |
1567 | if (!realize_font (i)) |
1199 | goto next_font; |
1568 | goto next_font; |
|
|
1569 | |
|
|
1570 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1571 | max_it (f->ascent, prop.ascent); |
1200 | } |
1572 | } |
1201 | |
1573 | |
1202 | if (f->cs == CS_UNKNOWN) |
1574 | if (f->cs == CS_UNKNOWN) |
1203 | goto next_font; |
1575 | goto next_font; |
1204 | |
1576 | |
1205 | if (bold && f->properties ().weight < rxvt_fontprop::bold) |
1577 | bool careful; |
|
|
1578 | if (f->has_char (unicode, &prop, careful)) |
|
|
1579 | { |
|
|
1580 | if (careful) |
|
|
1581 | i |= 128; |
|
|
1582 | |
1206 | goto next_font; |
1583 | goto found; |
1207 | |
1584 | } |
1208 | if (f->has_codepoint (unicode)) |
|
|
1209 | return i; |
|
|
1210 | |
1585 | |
1211 | next_font: |
1586 | next_font: |
1212 | if (i == fonts.size () - 1) |
1587 | if (i == fonts.size () - 1) |
1213 | { |
1588 | { |
1214 | if (fallback->name) |
1589 | if (fallback->name) |
1215 | { |
1590 | { |
1216 | // search through the fallback list |
1591 | // search through the fallback list |
1217 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1592 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1218 | fallback++; |
1593 | fallback++; |
1219 | } |
1594 | } |
1220 | else if (!bold) |
1595 | else |
1221 | { |
1596 | { |
1222 | // try to find a new font. |
1597 | // try to find a new font. |
1223 | // only xft currently supported, as there is no |
1598 | // only xft currently supported, as there is no |
1224 | // way to configure this and xft is easier to hack in, |
1599 | // way to configure this and xft is easier to hack in, |
1225 | // while x11 has more framework in place already. |
1600 | // while x11 has more framework in place already. |
1226 | #if XFT |
1601 | // TODO: this is a real resource hog, xft takes ages(?) |
|
|
1602 | #if XFT && USE_SLOW_LOOKUP |
1227 | // grab the first xft font that seems suitable |
1603 | // grab the first xft font that seems suitable |
1228 | FcPattern *p = FcPatternCreate (); |
1604 | FcPattern *p = FcPatternCreate (); |
1229 | |
1605 | |
1230 | FcCharSet *s = FcCharSetCreate (); |
1606 | FcCharSet *s = FcCharSetCreate (); |
1231 | FcCharSetAddChar (s, unicode); |
1607 | FcCharSetAddChar (s, unicode); |
1232 | FcPatternAddCharSet (p, FC_CHARSET, s); |
1608 | FcPatternAddCharSet (p, FC_CHARSET, s); |
1233 | // charsets don't help that much, as xft might return |
1609 | // charsets don't help that much, as xft might return |
1234 | // a non-matching font even if a better font is available :/ |
1610 | // a non-matching font even if a better font is available :/ |
1235 | |
1611 | |
|
|
1612 | x x x x TODO prop might have unset contents |
1236 | FcPatternAddInteger (p, FC_PIXEL_SIZE, base_prop.height); |
1613 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1237 | FcPatternAddInteger (p, FC_WEIGHT, base_prop.weight); |
1614 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1238 | FcPatternAddInteger (p, FC_SLANT, base_prop.slant); |
1615 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1239 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1616 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1240 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1617 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1241 | |
1618 | |
1242 | XftResult result; |
1619 | XftResult result; |
1243 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1620 | FcPattern *match = XftFontMatch (term->dpy, term->display->screen, p, &result); |
1244 | |
1621 | |
1245 | FcPatternDestroy (p); |
1622 | FcPatternDestroy (p); |
1246 | |
1623 | |
1247 | if (match) |
1624 | if (match) |
1248 | { |
1625 | { |
… | |
… | |
1263 | #endif |
1640 | #endif |
1264 | } |
1641 | } |
1265 | } |
1642 | } |
1266 | } |
1643 | } |
1267 | |
1644 | |
1268 | // if no bold font found, use a regular one |
1645 | /* we must return SOME font */ |
1269 | if (bold) |
1646 | i = 0; |
1270 | return find_font (unicode); |
|
|
1271 | |
1647 | |
1272 | return 0; /* we must return SOME font */ |
1648 | found: |
1273 | } |
1649 | // found a font, cache it |
|
|
1650 | if (i < 255) |
|
|
1651 | { |
|
|
1652 | while (hi >= fmap.size ()) |
|
|
1653 | fmap.push_back (0); |
1274 | |
1654 | |
|
|
1655 | if (!fmap[hi]) |
|
|
1656 | { |
|
|
1657 | fmap[hi] = (pagemap *)new pagemap; |
|
|
1658 | memset (fmap[hi], 0xff, sizeof (pagemap)); |
|
|
1659 | } |
1275 | |
1660 | |
|
|
1661 | (*fmap[hi])[unicode & 0xff] = i; |
|
|
1662 | } |
1276 | |
1663 | |
|
|
1664 | return i; |
|
|
1665 | } |
|
|
1666 | |
|
|
1667 | |
|
|
1668 | |