ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtfont.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.6 by root, Tue Aug 17 01:58:17 2004 UTC vs.
Revision 1.84 by root, Tue Jan 17 05:47:42 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines