… | |
… | |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
|
|
26 | #include <cstdlib> |
|
|
27 | |
26 | #define DISPLAY r->Xdisplay |
28 | #define DISPLAY r->Xdisplay |
27 | #define DRAWABLE r->TermWin.vt |
29 | #define DRAWABLE r->TermWin.vt |
28 | #define GC r->TermWin.gc |
30 | #define GC r->TermWin.gc |
29 | |
31 | |
30 | const struct rxvt_fallback_font { |
32 | const struct rxvt_fallback_font { |
… | |
… | |
57 | |
59 | |
58 | // japanese |
60 | // japanese |
59 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | #if ENCODING_JP || ENCODING_JP_EXT |
60 | # if XFT |
62 | # if XFT |
61 | // prefer xft for complex scripts |
63 | // prefer xft for complex scripts |
62 | { CS_UNICODE, "xft:Kochi Gothic" }, |
64 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
63 | # endif |
65 | # endif |
64 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
65 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
66 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
67 | #endif |
69 | #endif |
68 | |
70 | |
69 | #if ENCODING_CN || ENCODING_CN_EXT |
71 | #if ENCODING_CN || ENCODING_CN_EXT |
70 | # if XFT |
72 | # if XFT |
71 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
72 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
73 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
74 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
75 | # endif |
77 | # endif |
76 | { CS_CNS11643_1992_1, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
77 | { CS_CNS11643_1992_2, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
79 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
78 | { CS_CNS11643_1992_3, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
80 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
79 | { CS_CNS11643_1992_4, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
81 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
80 | { CS_CNS11643_1992_5, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
82 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
81 | { CS_CNS11643_1992_6, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
83 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
82 | { CS_CNS11643_1992_7, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
84 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
83 | { CS_CNS11643_1992_F, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
85 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
84 | #endif |
86 | #endif |
85 | |
87 | |
86 | #if XFT |
88 | #if XFT |
87 | { CS_UNICODE, "xft:Andale Mono" }, |
89 | { CS_UNICODE, "xft:Andale Mono" }, |
88 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
90 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
89 | #endif |
91 | #endif |
90 | { CS_UNICODE, "-*-lucidatypewriter-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
92 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
93 | { CS_UNICODE, "xft:FreeMono" }, |
|
|
94 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
|
|
95 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
91 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
96 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
92 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
93 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
94 | |
97 | |
95 | { CS_UNKNOWN, 0 } |
98 | { CS_UNKNOWN, 0 } |
96 | }; |
99 | }; |
97 | |
100 | |
98 | ///////////////////////////////////////////////////////////////////////////// |
101 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
168 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
171 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
169 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
172 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
170 | } |
173 | } |
171 | } |
174 | } |
172 | |
175 | |
|
|
176 | static const char *linedraw_cmds[128] = { |
|
|
177 | "1hH", "2hH", "1vV", "2vV", |
|
|
178 | 0, 0, 0, 0, |
|
|
179 | 0, 0, 0, 0, |
|
|
180 | "1HV", "2H1V", "1H2V", "2HV", |
|
|
181 | |
|
|
182 | // 2510 |
|
|
183 | "1hV", "2h1V", "1h2V", "2hV", |
|
|
184 | "1Hv", "2H1v", "1H2v", "2Hv", |
|
|
185 | "1hv", "2h1v", "1h2v", "2hv", |
|
|
186 | "1HvV", "2H1vV", "1HV2v", "1Hv2V", |
|
|
187 | |
|
|
188 | // 2520 |
|
|
189 | "1H2vV", "2Hv1V", "2HV1v", "2HvV", |
|
|
190 | "1hvV", "2h1vV", "1hV2v", "1hv2V", |
|
|
191 | "1h2vV", "2hv1V", "1v2hV", "2hvV", |
|
|
192 | "1hHV", "2h1HV", "2H1hV", "2hH1V", |
|
|
193 | |
|
|
194 | // 2530 |
|
|
195 | "1hH2V", "2hV1H", "1h2HV", "2hHV", |
|
|
196 | "1hHv", "1vH2h", "1hv2H", "1v2hH", |
|
|
197 | "1hH2v", "1H2hv", "1h2Hv", "2hHv", |
|
|
198 | "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", |
|
|
199 | |
|
|
200 | // 2540 |
|
|
201 | "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", |
|
|
202 | "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", |
|
|
203 | "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", |
|
|
204 | 0, 0, 0, 0, |
|
|
205 | |
|
|
206 | // 2550 |
|
|
207 | 0, 0, 0, 0, |
|
|
208 | 0, 0, 0, 0, |
|
|
209 | 0, 0, 0, 0, |
|
|
210 | 0, 0, 0, 0, |
|
|
211 | |
|
|
212 | // 2560 |
|
|
213 | 0, 0, 0, 0, |
|
|
214 | 0, 0, 0, 0, |
|
|
215 | 0, 0, 0, 0, |
|
|
216 | 0, 0, 0, 0, |
|
|
217 | |
|
|
218 | // 2570 |
|
|
219 | 0, "1a", "1b", "1ab", |
|
|
220 | "1h", "1v", "1H", "1V", |
|
|
221 | "2h", "2v", "2H", "2V", |
|
|
222 | "1h2H", "1v2V", "1H2h", "1V2v" |
|
|
223 | |
|
|
224 | // to be done |
|
|
225 | }; |
|
|
226 | |
173 | struct rxvt_font_default : rxvt_font { |
227 | struct rxvt_font_default : rxvt_font { |
174 | bool load (int maxheight) |
228 | rxvt_fontprop properties () |
|
|
229 | { |
|
|
230 | rxvt_fontprop p; |
|
|
231 | |
|
|
232 | p.height = 1; |
|
|
233 | p.weight = rxvt_fontprop::medium; |
|
|
234 | p.slant = rxvt_fontprop::roman; |
|
|
235 | |
|
|
236 | return p; |
|
|
237 | } |
|
|
238 | |
|
|
239 | bool load (const rxvt_fontprop &prop) |
175 | { |
240 | { |
176 | width = 1; height = 1; |
241 | width = 1; height = 1; |
177 | ascent = 1; descent = 0; |
242 | ascent = 1; descent = 0; |
178 | |
243 | |
179 | return true; |
244 | return true; |
180 | } |
245 | } |
181 | |
246 | |
182 | bool has_codepoint (uint32_t unicode) |
247 | bool has_codepoint (uint32_t unicode) |
183 | { |
248 | { |
184 | if (unicode <= 0x001f |
249 | if (unicode <= 0x001f) |
|
|
250 | return true; |
185 | || (unicode >= 0x80 && unicode <= 0x9f)) |
251 | if (unicode >= 0x0080 && unicode <= 0x009f) |
|
|
252 | return true; |
|
|
253 | |
|
|
254 | if (unicode >= 0x2500 && unicode <= 0x257f |
|
|
255 | && linedraw_cmds[unicode - 0x2500]) |
186 | return true; |
256 | return true; |
187 | |
257 | |
188 | switch (unicode) |
258 | switch (unicode) |
189 | { |
259 | { |
190 | case ZERO_WIDTH_CHAR: |
260 | case ZERO_WIDTH_CHAR: |
… | |
… | |
204 | const text_t *text, int len, |
274 | const text_t *text, int len, |
205 | int fg, int bg) |
275 | int fg, int bg) |
206 | { |
276 | { |
207 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
277 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
208 | |
278 | |
|
|
279 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
|
|
280 | |
209 | while (len--) |
281 | while (len--) |
210 | { |
282 | { |
|
|
283 | text_t t = *text++; |
|
|
284 | |
|
|
285 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
|
|
286 | { |
|
|
287 | const char *p = linedraw_cmds[t - 0x2500]; |
|
|
288 | |
|
|
289 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
|
|
290 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; |
|
|
291 | |
|
|
292 | XGCValues gcv; |
|
|
293 | |
|
|
294 | while (*p) |
|
|
295 | { |
|
|
296 | switch (*p++) |
|
|
297 | { |
|
|
298 | case '1': |
|
|
299 | gcv.line_width = 0; |
|
|
300 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
301 | break; |
|
|
302 | |
|
|
303 | case '2': |
|
|
304 | gcv.line_width = 2; |
|
|
305 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
306 | break; |
|
|
307 | |
|
|
308 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
|
|
309 | case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
|
|
310 | case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
|
|
311 | case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
|
|
312 | case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
|
|
313 | case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
|
|
314 | } |
|
|
315 | } |
|
|
316 | |
|
|
317 | gcv.line_width = 0; |
|
|
318 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
319 | } |
|
|
320 | else |
211 | switch (*text++) |
321 | switch (*text++) |
212 | { |
322 | { |
213 | case NOCHAR: |
323 | case NOCHAR: |
214 | case ZERO_WIDTH_CHAR: |
324 | case ZERO_WIDTH_CHAR: |
215 | break; |
325 | break; |
216 | default: |
326 | default: |
217 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
|
|
218 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
327 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
219 | } |
328 | } |
220 | |
329 | |
221 | x += r->TermWin.fwidth; |
330 | x += r->TermWin.fwidth; |
222 | } |
331 | } |
223 | } |
332 | } |
224 | |
333 | |
… | |
… | |
227 | struct rxvt_font_x11 : rxvt_font { |
336 | struct rxvt_font_x11 : rxvt_font { |
228 | rxvt_font_x11 () { f = 0; } |
337 | rxvt_font_x11 () { f = 0; } |
229 | |
338 | |
230 | void clear (); |
339 | void clear (); |
231 | |
340 | |
232 | bool load (int maxheight); |
341 | rxvt_fontprop properties (); |
|
|
342 | rxvt_fontprop properties (XFontStruct *f); |
|
|
343 | |
|
|
344 | bool load (const rxvt_fontprop &prop); |
233 | |
345 | |
234 | bool has_codepoint (uint32_t unicode); |
346 | bool has_codepoint (uint32_t unicode); |
235 | |
347 | |
236 | void draw (int x, int y, |
348 | void draw (int x, int y, |
237 | const text_t *text, int len, |
349 | const text_t *text, int len, |
… | |
… | |
239 | |
351 | |
240 | XFontStruct *f; |
352 | XFontStruct *f; |
241 | codeset cs; |
353 | codeset cs; |
242 | bool enc2b, encm; |
354 | bool enc2b, encm; |
243 | |
355 | |
244 | const char *get_property (const char *property, const char *repl) const; |
356 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
245 | }; |
357 | }; |
246 | |
358 | |
247 | const char * |
359 | const char * |
248 | rxvt_font_x11::get_property (const char *property, const char *repl) const |
360 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
249 | { |
361 | { |
250 | unsigned long value; |
362 | unsigned long value; |
251 | |
363 | |
252 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
364 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
253 | return XGetAtomName (DISPLAY, value); |
365 | return XGetAtomName (DISPLAY, value); |
254 | else |
366 | else |
255 | return repl; |
367 | return repl; |
256 | } |
368 | } |
257 | |
369 | |
|
|
370 | rxvt_fontprop |
|
|
371 | rxvt_font_x11::properties () |
|
|
372 | { |
|
|
373 | return properties (f); |
|
|
374 | } |
|
|
375 | |
|
|
376 | rxvt_fontprop |
|
|
377 | rxvt_font_x11::properties (XFontStruct *f) |
|
|
378 | { |
|
|
379 | rxvt_fontprop p; |
|
|
380 | |
|
|
381 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
382 | const char *slant = get_property (f, "SLANT", "r"); |
|
|
383 | |
|
|
384 | p.height = height; |
|
|
385 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
386 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
|
|
387 | |
|
|
388 | return p; |
|
|
389 | } |
|
|
390 | |
258 | bool |
391 | bool |
259 | rxvt_font_x11::load (int maxheight) |
392 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
260 | { |
393 | { |
261 | clear (); |
394 | clear (); |
|
|
395 | |
|
|
396 | char **list; |
|
|
397 | int count; |
|
|
398 | XFontStruct *info; |
|
|
399 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
|
|
400 | |
|
|
401 | if (!list) |
|
|
402 | return false; |
|
|
403 | |
|
|
404 | int bestdiff = 0x7fffffff; |
|
|
405 | XFontStruct *best = 0; |
|
|
406 | for (int i = 0; i < count; i++) |
|
|
407 | { |
|
|
408 | XFontStruct *f = info + i; |
|
|
409 | |
|
|
410 | if (f->ascent + f->descent <= prop.height) // weed out too large fonts |
|
|
411 | { |
|
|
412 | rxvt_fontprop p = properties (f); |
|
|
413 | int diff = (prop.height - f->ascent + f->descent) * 32 |
|
|
414 | + abs (prop.weight - p.weight) |
|
|
415 | + abs (prop.slant - p.slant ); |
|
|
416 | |
|
|
417 | if (!best // compare against best found so far |
|
|
418 | || diff < bestdiff) |
|
|
419 | { |
|
|
420 | best = f; |
|
|
421 | bestdiff = diff; |
|
|
422 | } |
|
|
423 | } |
|
|
424 | } |
|
|
425 | |
|
|
426 | if (!best) |
|
|
427 | return false; |
|
|
428 | |
|
|
429 | set_name (strdup (list[best - info])); |
|
|
430 | |
|
|
431 | XFreeFontInfo (list, info, count); |
262 | |
432 | |
263 | f = XLoadQueryFont (DISPLAY, name); |
433 | f = XLoadQueryFont (DISPLAY, name); |
264 | |
434 | |
265 | if (!f) |
435 | if (!f) |
266 | return false; |
436 | return false; |
267 | |
437 | |
268 | unsigned long value; |
438 | unsigned long value; |
269 | |
439 | |
270 | const char *registry = get_property ("CHARSET_REGISTRY", 0); |
440 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
271 | const char *encoding = get_property ("CHARSET_ENCODING", 0); |
441 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
272 | |
442 | |
273 | if (registry && encoding) |
443 | if (registry && encoding) |
274 | { |
444 | { |
275 | char charset[64]; |
445 | char charset[64]; |
276 | snprintf (charset, 64, "%s-%s", registry, encoding); |
446 | snprintf (charset, 64, "%s-%s", registry, encoding); |
277 | |
447 | |
278 | cs = codeset_from_name (charset); |
448 | cs = codeset_from_name (charset); |
279 | } |
449 | } |
280 | else |
450 | else |
281 | { |
451 | { |
282 | const char *charset = get_property ("FONT", 0); |
452 | const char *charset = get_property (f, "FONT", 0); |
283 | |
453 | |
284 | if (!charset) |
454 | if (!charset) |
285 | charset = name; |
455 | charset = name; |
286 | |
456 | |
287 | int count = 13; |
457 | int count = 13; |
… | |
… | |
300 | |
470 | |
301 | ascent = f->ascent; |
471 | ascent = f->ascent; |
302 | descent = f->descent; |
472 | descent = f->descent; |
303 | height = ascent + descent; |
473 | height = ascent + descent; |
304 | |
474 | |
305 | prop = false; |
475 | slow = false; |
306 | |
476 | |
307 | if (f->min_bounds.width == f->max_bounds.width) |
477 | if (f->min_bounds.width == f->max_bounds.width) |
308 | width = f->min_bounds.width; |
478 | width = f->min_bounds.width; |
309 | else if (f->per_char == NULL) |
479 | else if (f->per_char == NULL) |
310 | width = f->max_bounds.width; |
480 | width = f->max_bounds.width; |
311 | else |
481 | else |
312 | { |
482 | { |
313 | prop = true; |
483 | slow = true; |
314 | |
484 | |
315 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
485 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
316 | |
486 | |
317 | if (encm) |
487 | if (encm) |
318 | N += (f->max_byte1 - f->min_byte1) |
488 | N += (f->max_byte1 - f->min_byte1) |
… | |
… | |
403 | // this looks like a mess /. |
573 | // this looks like a mess /. |
404 | // and it is a mess /. |
574 | // and it is a mess /. |
405 | // yet we are trying to be perfect /. |
575 | // yet we are trying to be perfect /. |
406 | // but the result still isn't perfect /. |
576 | // but the result still isn't perfect /. |
407 | |
577 | |
408 | bool slow = prop |
578 | bool slow = this->slow |
409 | || width != r->TermWin.fwidth |
579 | || width != r->TermWin.fwidth |
410 | || height != r->TermWin.fheight; |
580 | || height != r->TermWin.fheight; |
411 | |
581 | |
412 | int base = r->TermWin.fbase; |
582 | int base = r->TermWin.fbase; |
413 | |
583 | |
… | |
… | |
518 | #endif |
688 | #endif |
519 | rxvt_font_xft () { f = 0; d = 0; } |
689 | rxvt_font_xft () { f = 0; d = 0; } |
520 | |
690 | |
521 | void clear (); |
691 | void clear (); |
522 | |
692 | |
523 | bool load (int maxheight); |
693 | rxvt_fontprop properties (); |
|
|
694 | |
|
|
695 | bool load (const rxvt_fontprop &prop); |
524 | |
696 | |
525 | void draw (int x, int y, |
697 | void draw (int x, int y, |
526 | const text_t *text, int len, |
698 | const text_t *text, int len, |
527 | int fg, int bg); |
699 | int fg, int bg); |
528 | |
700 | |
… | |
… | |
560 | for (int i = 0; i < SWATHCOUNT; i++) |
732 | for (int i = 0; i < SWATHCOUNT; i++) |
561 | delete cvr[i]; |
733 | delete cvr[i]; |
562 | #endif |
734 | #endif |
563 | } |
735 | } |
564 | |
736 | |
|
|
737 | rxvt_fontprop |
|
|
738 | rxvt_font_xft::properties () |
|
|
739 | { |
|
|
740 | rxvt_fontprop p; |
|
|
741 | |
|
|
742 | FT_Face face = XftLockFace (f); |
|
|
743 | |
|
|
744 | p.height = height; |
|
|
745 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
746 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
|
|
747 | |
|
|
748 | XftUnlockFace (f); |
|
|
749 | |
|
|
750 | return p; |
|
|
751 | } |
|
|
752 | |
565 | bool |
753 | bool |
566 | rxvt_font_xft::load (int maxheight) |
754 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
567 | { |
755 | { |
568 | #if 0 |
756 | #if 0 |
569 | for (int i = 0; i < SWATHCOUNT; i++) |
757 | for (int i = 0; i < SWATHCOUNT; i++) |
570 | cvr[i] = 0; |
758 | cvr[i] = 0; |
571 | #endif |
759 | #endif |
572 | |
760 | |
573 | clear (); |
761 | clear (); |
574 | |
762 | |
575 | f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); |
763 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
|
|
764 | |
|
|
765 | if (!p) |
|
|
766 | return false; |
|
|
767 | |
|
|
768 | FcValue v; |
|
|
769 | |
|
|
770 | if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
|
|
771 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
|
|
772 | |
|
|
773 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
|
|
774 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
|
|
775 | |
|
|
776 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
777 | |
|
|
778 | XftResult result; |
|
|
779 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
|
|
780 | |
|
|
781 | FcPatternDestroy (p); |
|
|
782 | |
|
|
783 | if (!match) |
|
|
784 | return false; |
|
|
785 | |
|
|
786 | f = XftFontOpenPattern (DISPLAY, match); |
576 | |
787 | |
577 | if (!f) |
788 | if (!f) |
|
|
789 | { |
|
|
790 | FcPatternDestroy (match); |
578 | return false; |
791 | return false; |
|
|
792 | } |
579 | |
793 | |
580 | FT_Face face = XftLockFace (f); |
794 | FT_Face face = XftLockFace (f); |
581 | |
795 | |
582 | prop = !FT_IS_FIXED_WIDTH (face); |
796 | slow = !FT_IS_FIXED_WIDTH (face); |
583 | |
797 | |
584 | int ftheight = 0; |
798 | int ftheight = 0; |
585 | |
799 | |
586 | for (;;) |
800 | for (;;) |
587 | { |
801 | { |
… | |
… | |
589 | FcChar8 c; |
803 | FcChar8 c; |
590 | |
804 | |
591 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
805 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
592 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
806 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
593 | |
807 | |
594 | prop = prop || g1.xOff != g2.xOff; // don't simply trust the font |
808 | if (g1.xOff != g2.xOff) // don't simply trust the font |
|
|
809 | slow = true; |
595 | |
810 | |
596 | width = g2.xOff; |
811 | width = g2.xOff; |
597 | ascent = (face->size->metrics.ascender + 63) >> 6; |
812 | ascent = (face->size->metrics.ascender + 63) >> 6; |
598 | descent = (-face->size->metrics.descender + 63) >> 6; |
813 | descent = (-face->size->metrics.descender + 63) >> 6; |
599 | height = ascent + descent; |
814 | height = ascent + descent; |
600 | |
815 | |
601 | if (height <= maxheight || !maxheight) |
816 | if (height <= prop.height || !prop.height) |
602 | break; |
817 | break; |
603 | |
818 | |
604 | if (ftheight) |
819 | if (ftheight) |
605 | { |
820 | { |
606 | // take smaller steps near the end |
821 | // take smaller steps near the end |
607 | if (height > maxheight + 1) ftheight++; |
822 | if (height > prop.height + 1) ftheight++; |
608 | if (height > maxheight + 2) ftheight++; |
823 | if (height > prop.height + 2) ftheight++; |
609 | if (height > maxheight + 3) ftheight++; |
824 | if (height > prop.height + 3) ftheight++; |
610 | |
825 | |
611 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); |
826 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
612 | } |
827 | } |
613 | else |
828 | else |
614 | FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); |
829 | FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
615 | } |
830 | } |
616 | |
831 | |
617 | XftUnlockFace (f); |
832 | XftUnlockFace (f); |
618 | |
833 | |
619 | return true; |
834 | return true; |
… | |
… | |
651 | if (bg >= 0 && bg != Color_bg) |
866 | if (bg >= 0 && bg != Color_bg) |
652 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
867 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
653 | else |
868 | else |
654 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
869 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
655 | |
870 | |
656 | if (!prop && width == r->TermWin.fwidth) |
871 | if (!slow && width == r->TermWin.fwidth) |
657 | { |
872 | { |
658 | if (sizeof (text_t) == sizeof (FcChar16)) |
873 | if (sizeof (text_t) == sizeof (FcChar16)) |
659 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
874 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
660 | else |
875 | else |
661 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
876 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
… | |
… | |
701 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
916 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
702 | FONT_UNREF (*i); |
917 | FONT_UNREF (*i); |
703 | |
918 | |
704 | fonts.clear (); |
919 | fonts.clear (); |
705 | base_id = 0; |
920 | base_id = 0; |
706 | height = 0x7fffffff; |
921 | base_prop.height = 0x7fffffff; |
|
|
922 | base_prop.weight = rxvt_fontprop::medium; |
|
|
923 | base_prop.slant = rxvt_fontprop::roman; |
707 | |
924 | |
708 | fallback = fallback_fonts; |
925 | fallback = fallback_fonts; |
709 | } |
926 | } |
710 | |
927 | |
711 | rxvt_font * |
928 | rxvt_font * |
… | |
… | |
796 | rxvt_fontset::realize_font (int i) |
1013 | rxvt_fontset::realize_font (int i) |
797 | { |
1014 | { |
798 | if (fonts[i]->loaded) |
1015 | if (fonts[i]->loaded) |
799 | return true; |
1016 | return true; |
800 | |
1017 | |
801 | if (fonts[i]->load (height)) |
|
|
802 | return fonts[i]->loaded = true; |
1018 | fonts[i]->loaded = true; |
803 | |
1019 | |
804 | delete fonts[i]; |
1020 | if (!fonts[i]->load (base_prop)) |
805 | fonts.erase (fonts.begin () + i); |
1021 | { |
806 | |
1022 | fonts[i]->cs = CS_UNKNOWN; |
807 | return false; |
1023 | return false; |
|
|
1024 | } |
|
|
1025 | |
|
|
1026 | return true; |
808 | } |
1027 | } |
809 | |
1028 | |
810 | void |
1029 | void |
811 | rxvt_fontset::populate (const char *desc) |
1030 | rxvt_fontset::populate (const char *desc) |
812 | { |
1031 | { |
… | |
… | |
819 | |
1038 | |
820 | if (!base_id) |
1039 | if (!base_id) |
821 | base_id = 1; |
1040 | base_id = 1; |
822 | |
1041 | |
823 | // we currently need a base-font, no matter what |
1042 | // we currently need a base-font, no matter what |
824 | if (fonts.size () <= base_id) |
1043 | if (fonts.size () <= base_id || !realize_font (base_id)) |
825 | { |
1044 | { |
826 | add_fonts ("fixed"); |
1045 | add_fonts ("fixed"); |
827 | base_id = 1; |
1046 | base_id = fonts.size () - 1; |
828 | } |
1047 | } |
829 | |
1048 | |
830 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1049 | if (fonts.size () <= base_id || !realize_font (base_id)) |
831 | { |
1050 | { |
832 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1051 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
833 | exit (1); |
1052 | exit (1); |
834 | } |
1053 | } |
835 | |
1054 | |
836 | height = fonts[base_id]->height; |
1055 | base_prop = fonts[base_id]->properties (); |
837 | |
|
|
838 | /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/ |
|
|
839 | } |
1056 | } |
840 | |
1057 | |
841 | int |
1058 | int |
842 | rxvt_fontset::find_font (uint32_t unicode) |
1059 | rxvt_fontset::find_font (uint32_t unicode) |
843 | { |
1060 | { |
… | |
… | |
849 | { |
1066 | { |
850 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1067 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
851 | goto next_font; |
1068 | goto next_font; |
852 | |
1069 | |
853 | if (!realize_font (i)) |
1070 | if (!realize_font (i)) |
854 | { |
|
|
855 | --i; |
|
|
856 | goto next_font; |
1071 | goto next_font; |
857 | } |
1072 | } |
858 | |
1073 | |
859 | //printf ("added font %s for %04lx\n", f->name, unicode); |
|
|
860 | } |
|
|
861 | |
|
|
862 | if (f->has_codepoint (unicode)) |
1074 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
863 | return i; |
1075 | return i; |
864 | |
1076 | |
865 | next_font: |
1077 | next_font: |
866 | if (i == fonts.size () - 1 && fallback->name) |
1078 | if (i == fonts.size () - 1 && fallback->name) |
867 | { |
1079 | { |
868 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1080 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
869 | fallback++; |
1081 | fallback++; |
|
|
1082 | i = 0; |
870 | } |
1083 | } |
871 | } |
1084 | } |
872 | |
1085 | |
873 | return 0; /* we must return SOME font */ |
1086 | return 0; /* we must return SOME font */ |
874 | } |
1087 | } |