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.56 by root, Fri Dec 10 19:55:55 2004 UTC vs.
Revision 1.86 by root, Wed Jan 25 13:24:45 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"
24#include "rxvtutil.h" 25#include "rxvtutil.h"
25#include "rxvtfont.h" 26#include "rxvtfont.h"
26 27
27#include <cstdlib> 28#include <cstdlib>
28#include <wchar.h> 29#include <wchar.h>
29#include <inttypes.h> 30#include <inttypes.h>
30 31
31#define DISPLAY r->display->display
32#define TGC r->TermWin.gc
33
34#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 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,prop) (w) > ( \
36 prop->slant >= rxvt_fontprop::italic \
37 ? (prop->width * MAX_OVERLAP_ITALIC + 7) >> 3 \
38 : (prop->width * MAX_OVERLAP_ROMAN + 7) >> 3 \
39 )
35 40
36const struct rxvt_fallback_font { 41const struct rxvt_fallback_font {
37 codeset cs; 42 codeset cs;
38 const char *name; 43 const char *name;
39} fallback_fonts[] = { 44} fallback_fonts[] = {
130 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, 135 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
131 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 136 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
132 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 137 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
133 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 138 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
134#if XFT 139#if XFT
135 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, 140 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" },
136 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, 141 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" },
137 { CS_UNICODE, "xft:Andale Mono:antialias=false" }, 142 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" },
138 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, 143 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" },
139 144
140 // FreeMono is usually uglier than x fonts, so try last only. 145 // FreeMono is usually uglier than x fonts, so try last only.
141 { CS_UNICODE, "xft:FreeMono:autohint=true" }, 146 { CS_UNICODE, "xft:FreeMono:autohint=true" },
142#endif 147#endif
143 148
144 { CS_UNKNOWN, 0 } 149 { CS_UNKNOWN, 0 }
145}; 150};
146 151
147// these characters are used to guess the font height and width 152// these characters are used to guess the font height and width
148// pango uses a similar algorithm and eosn't trust the font either. 153// pango uses a similar algorithm and doesn't trust the font either.
149static uint16_t extent_test_chars[] = { 154static uint16_t extent_test_chars[] = {
150 '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', 155 '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_',
151 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ 156 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ
152 0x304c, 0x672c, // が本 157 0x304c, 0x672c, // が本
153}; 158};
154 159
155#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 160#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
156 161
162#define dTermDisplay Display *disp = term->display->display
163#define dTermGC GC gc = term->gc
164
157///////////////////////////////////////////////////////////////////////////// 165/////////////////////////////////////////////////////////////////////////////
158 166
159#if XFT 167#if XFT
160rxvt_drawable::~rxvt_drawable () 168rxvt_drawable::~rxvt_drawable ()
161{ 169{
172} 180}
173#endif 181#endif
174 182
175///////////////////////////////////////////////////////////////////////////// 183/////////////////////////////////////////////////////////////////////////////
176 184
177static void *enc_buf;
178static uint32_t enc_len;
179
180static inline void *
181get_enc_buf (uint32_t len)
182{
183 if (len > enc_len)
184 {
185 free (enc_buf);
186 enc_buf = malloc (len);
187 enc_len = len;
188 }
189
190 return enc_buf;
191}
192
193static const char * 185static const char *
194enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 186enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
195{ 187{
196 uint8_t *buf = (uint8_t *)get_enc_buf (len); 188 uint8_t *buf = rxvt_temp_buf<uint8_t> (len);
189 uint8_t *res = buf;
197 190
198 while (len--) 191 while (len--)
199 { 192 {
200 uint32_t c = FROM_UNICODE (cs, *text++); 193 uint32_t c = FROM_UNICODE (cs, *text++);
201 194
206 } 199 }
207 200
208 *buf++ = c; 201 *buf++ = c;
209 } 202 }
210 203
211 return (const char *)enc_buf; 204 return (const char *)res;
212} 205}
213 206
214static const XChar2b * 207static const XChar2b *
215enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) 208enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
216{ 209{
217 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 210 XChar2b *buf = rxvt_temp_buf<XChar2b> (len);
211 XChar2b *res = buf;
218 212
219 while (len--) 213 while (len--)
220 { 214 {
221 uint32_t c = FROM_UNICODE (cs, *text++); 215 uint32_t c = FROM_UNICODE (cs, *text++);
222 216
229 buf->byte1 = c >> 8; 223 buf->byte1 = c >> 8;
230 buf->byte2 = c; 224 buf->byte2 = c;
231 buf++; 225 buf++;
232 } 226 }
233 227
234 return (XChar2b *)enc_buf; 228 return res;
235} 229}
236 230
237///////////////////////////////////////////////////////////////////////////// 231/////////////////////////////////////////////////////////////////////////////
238 232
239void 233void
245 if (this->name) free (this->name); // let the compiler optimize 239 if (this->name) free (this->name); // let the compiler optimize
246 this->name = name; 240 this->name = name;
247} 241}
248 242
249void 243void
250rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) 244rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
251{ 245{
246 dTermDisplay;
247 dTermGC;
248
252 if (color == Color_bg) 249 if (color == Color_bg)
253 XClearArea (d.display->display, d, x, y, w, h, FALSE); 250 XClearArea (disp, d, x, y, w, h, FALSE);
254 else if (color >= 0) 251 else if (color >= 0)
255 { 252 {
256#if XFT 253#if XFT
257 XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); 254 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
258#else 255#else
259 XSetForeground (d.display->display, TGC, r->pix_colors[color]); 256 XSetForeground (disp, gc, term->pix_colors[color]);
260 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 257 XFillRectangle (disp, d, gc, x, y, w, h);
261#endif 258#endif
262 } 259 }
263} 260}
264 261
265#include "table/linedraw.h" 262#include "table/linedraw.h"
276 rxvt_fontprop properties () 273 rxvt_fontprop properties ()
277 { 274 {
278 rxvt_fontprop p; 275 rxvt_fontprop p;
279 276
280 p.width = p.height = 1; 277 p.width = p.height = 1;
278 p.ascent = rxvt_fontprop::unset;
281 p.weight = rxvt_fontprop::medium; 279 p.weight = rxvt_fontprop::medium;
282 p.slant = rxvt_fontprop::roman; 280 p.slant = rxvt_fontprop::roman;
283 281
284 return p; 282 return p;
285 } 283 }
292 set_name (strdup ("built-in support font")); 290 set_name (strdup ("built-in support font"));
293 291
294 return true; 292 return true;
295 } 293 }
296 294
297 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 295 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
298 { 296 {
299 careful = false; 297 careful = false;
300 298
301 if (unicode <= 0x001f) 299 if (unicode <= 0x001f)
302 return true; 300 return true;
305 return false; 303 return false;
306 304
307 if (unicode <= 0x009f) 305 if (unicode <= 0x009f)
308 return true; 306 return true;
309 307
310 if (unicode >= 0x2500 && unicode <= 0x259f) 308 if (unicode >= 0x2500 && unicode <= 0x259f &&
309 !term->option (Opt_skipBuiltinGlyphs))
311 return true; 310 return true;
312 311
313 if (IS_COMPOSE (unicode)) 312 if (IS_COMPOSE (unicode))
314 return true; 313 return true;
315 314
331void 330void
332rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 331rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
333 const text_t *text, int len, 332 const text_t *text, int len,
334 int fg, int bg) 333 int fg, int bg)
335{ 334{
335 dTermDisplay;
336 dTermGC;
337
336 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 338 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
337 339
338 XSetForeground (d.display->display, TGC, r->pix_colors[fg]); 340 XSetForeground (disp, gc, term->pix_colors[fg]);
339 341
340 while (len) 342 while (len)
341 { 343 {
342#if ENABLE_COMBINING 344#if ENABLE_COMBINING
343 compose_char *cc; 345 compose_char *cc;
347 349
348 while (++text, --len && *text == NOCHAR) 350 while (++text, --len && *text == NOCHAR)
349 ; 351 ;
350 352
351 int width = text - tp; 353 int width = text - tp;
352 int fwidth = r->TermWin.fwidth * width; 354 int fwidth = term->fwidth * width;
353 355
354 if (0x2500 <= t && t <= 0x259f) 356 if (0x2500 <= t && t <= 0x259f)
355 { 357 {
356 uint16_t offs = linedraw_offs[t - 0x2500]; 358 uint16_t offs = linedraw_offs[t - 0x2500];
357 uint32_t *a = linedraw_command + (offs >> 4); 359 uint32_t *a = linedraw_command + (offs >> 4);
358 uint32_t *b = a + (offs & 15); 360 uint32_t *b = a + (offs & 15);
359 361
360 int W = fwidth; 362 int W = fwidth;
361 int H = r->TermWin.fheight; 363 int H = term->fheight;
362 364
363 int x_[16]; 365 int x_[16];
364 int y_[16]; 366 int y_[16];
365 367
366 for (int i = 0; i <= 8; i++) 368 for (int i = 0; i <= 8; i++)
374 376
375 XGCValues gcv; 377 XGCValues gcv;
376 378
377 gcv.cap_style = CapButt; 379 gcv.cap_style = CapButt;
378 gcv.line_width = 0; 380 gcv.line_width = 0;
379 XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); 381 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
380 382
381 while (a < b) 383 while (a < b)
382 { 384 {
383 uint32_t command = *a++; 385 uint32_t command = *a++;
384 386
391 int y2 = y_[(command >> 0) & 15]; 393 int y2 = y_[(command >> 0) & 15];
392 394
393 switch (op) 395 switch (op)
394 { 396 {
395 case 0: // line 397 case 0: // line
396 XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); 398 XDrawLine (disp, d, gc, x1, y1, x2, y2);
397 break; 399 break;
398 400
399 case 1: // rectangle, possibly stippled 401 case 1: // rectangle, possibly stippled
400 if (a) 402 if (a)
401 { 403 {
402 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; 404 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
403 405
404 gcv.fill_style = FillStippled; 406 gcv.fill_style = FillStippled;
405 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); 407 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
406 gcv.ts_x_origin = x; 408 gcv.ts_x_origin = x;
407 gcv.ts_y_origin = y; 409 gcv.ts_y_origin = y;
408 410
409 XChangeGC (d.display->display, TGC, 411 XChangeGC (disp, gc,
410 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 412 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
411 &gcv); 413 &gcv);
412 } 414 }
413 415
414 XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 416 XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
415 417
416 if (a) 418 if (a)
417 { 419 {
418 XFreePixmap (d.display->display, gcv.stipple); 420 XFreePixmap (disp, gcv.stipple);
419 gcv.stipple = 0; 421 gcv.stipple = 0;
420 gcv.fill_style = FillSolid; 422 gcv.fill_style = FillSolid;
421 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); 423 XChangeGC (disp, gc, GCFillStyle, &gcv);
422 } 424 }
423 break; 425 break;
424 case 2: // arc 426 case 2: // arc
425 XDrawArc (d.display->display, d, TGC, 427 XDrawArc (disp, d, gc,
426 x1 - W/2, y1 - H/2, W-1, H-1, 428 x1 - W/2, y1 - H/2, W-1, H-1,
427 (a - 1) * 90*64, (b - 1) * 90*64); 429 (a - 1) * 90*64, (b - 1) * 90*64);
428 break; 430 break;
429 } 431 }
430 } 432 }
461 case ZERO_WIDTH_CHAR: 463 case ZERO_WIDTH_CHAR:
462 case NOCHAR: 464 case NOCHAR:
463 break; 465 break;
464 466
465 default: 467 default:
466 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, 468 XDrawRectangle (disp, d, gc, x + 2, y + 2,
467 fwidth - 4, r->TermWin.fheight - 4); 469 fwidth - 4, term->fheight - 4);
468 } 470 }
469 471
470 x += fwidth; 472 x += fwidth;
471 } 473 }
472} 474}
480 482
481 rxvt_fontprop properties (); 483 rxvt_fontprop properties ();
482 484
483 bool load (const rxvt_fontprop &prop); 485 bool load (const rxvt_fontprop &prop);
484 486
485 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); 487 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
486 488
487 void draw (rxvt_drawable &d, int x, int y, 489 void draw (rxvt_drawable &d, int x, int y,
488 const text_t *text, int len, 490 const text_t *text, int len,
489 int fg, int bg); 491 int fg, int bg);
490 492
502char * 504char *
503rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 505rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
504{ 506{
505 unsigned long value; 507 unsigned long value;
506 508
507 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 509 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
508 return XGetAtomName (DISPLAY, value); 510 return XGetAtomName (term->display->display, value);
509 else 511 else
510 return rxvt_strdup (repl); 512 return rxvt_strdup (repl);
511} 513}
512 514
513rxvt_fontprop 515rxvt_fontprop
521bool 523bool
522rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) 524rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth)
523{ 525{
524 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; 526 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2;
525 p.height = height; 527 p.height = height;
528 p.ascent = rxvt_fontprop::unset;
526 p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; 529 p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium;
527 p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; 530 p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic;
528 531
529 return true; 532 return true;
530} 533}
531 534
532bool 535bool
533rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 536rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
534{ 537{
535 unsigned long height; 538 unsigned long height;
539
540#if 0
536 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 541 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
537 return false; 542 return false;
543#else
544 height = f->ascent + f->descent;
545#endif
538 546
539 unsigned long avgwidth; 547 unsigned long avgwidth;
540 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 548 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
541 avgwidth = 0; 549 avgwidth = 0;
542 550
543 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 551 char *weight = get_property (f, "WEIGHT_NAME", "medium");
544 char *slant = get_property (f, "SLANT", "r"); 552 char *slant = get_property (f, "SLANT", "r");
545 553
546 set_properties (p, height, weight, slant, avgwidth); 554 set_properties (p, height, weight, slant, avgwidth);
547 555
548 free (weight); 556 free (weight);
549 free (slant); 557 free (slant);
550 558
559 p.ascent = f->ascent;
560
551 return true; 561 return true;
552} 562}
553 563
554bool 564bool
555rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 565rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
556{ 566{
567 dTermDisplay;
557 int slashes = 0; 568 int slashes = 0;
558 const char *comp[13]; 569 const char *comp[13];
559 570
560 for (const char *c = name; *c; c++) 571 for (const char *c = name; *c; c++)
561 if (*c == '-') 572 if (*c == '-')
569 if (slashes >= 13 580 if (slashes >= 13
570 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 581 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
571 && (*comp[11] >= '0' && *comp[11] <= '9')) 582 && (*comp[11] >= '0' && *comp[11] <= '9'))
572 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); 583 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
573 584
574 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 585 XFontStruct *f = XLoadQueryFont (disp, name);
575 586
576 if (f) 587 if (f)
577 { 588 {
578 // the font should really exist now. if not, we have a problem 589 // the font should really exist now. if not, we have a problem
579 // (e.g. if the user did xset fp rehash just when we were searching fonts). 590 // (e.g. if the user did xset fp rehash just when we were searching fonts).
580 // in that case, just return garbage. 591 // in that case, just return garbage.
581 bool ret = set_properties (p, f); 592 bool ret = set_properties (p, f);
582 XFreeFont (DISPLAY, f); 593 XFreeFont (disp, f);
583 return ret; 594 return ret;
584 } 595 }
585 else 596 else
586 return false; 597 return false;
587} 598}
625} 636}
626 637
627bool 638bool
628rxvt_font_x11::load (const rxvt_fontprop &prop) 639rxvt_font_x11::load (const rxvt_fontprop &prop)
629{ 640{
641 dTermDisplay;
642
630 clear (); 643 clear ();
631 644
632 char field_str[64]; // enough for 128 bits 645 char field_str[64]; // enough for 128 bits
633 646
634 // first morph the font if required 647 // first morph the font if required
637 { 650 {
638 char fname[1024]; 651 char fname[1024];
639 652
640 if (name[0] != '-') 653 if (name[0] != '-')
641 { 654 {
642 f = XLoadQueryFont (DISPLAY, name); 655 f = XLoadQueryFont (disp, name);
643 656
644 if (!f) 657 if (!f)
645 return false; 658 return false;
646 659
647 char *new_name = get_property (f, "FONT", name); 660 char *new_name = get_property (f, "FONT", name);
649 if (new_name) 662 if (new_name)
650 set_name (new_name); 663 set_name (new_name);
651 else 664 else
652 rxvt_warn ("font '%s' has no FONT property, continuing without.", name); 665 rxvt_warn ("font '%s' has no FONT property, continuing without.", name);
653 666
654 XFreeFont (DISPLAY, f); 667 XFreeFont (disp, f);
655 f = 0; 668 f = 0;
656 } 669 }
657 670
658 if (prop.weight != rxvt_fontprop::unset) 671 if (prop.weight != rxvt_fontprop::unset)
659 { 672 {
670 ? "r" : "i"); // TODO: handle "o"blique, too 683 ? "r" : "i"); // TODO: handle "o"blique, too
671 set_name (strdup (fname)); 684 set_name (strdup (fname));
672 } 685 }
673 } 686 }
674 687
688 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset
689 ? 0 : prop.height);
690
691 struct font_weight {
692 char *name;
693 int diff;
694
695 void clear ()
696 {
697 name = 0;
698 diff = 0x7fffffff;
699 }
700
701 font_weight () { clear (); }
702 ~font_weight () { free (name); }
703 };
704
675 char **list; 705 char **list;
676 int count; 706 int count;
677 list = XListFonts (DISPLAY, name, 1024, &count); 707 list = XListFonts (disp, name, 4000, &count);
678 708
679 set_name (0); 709 set_name (0);
680 710
681 if (!list) 711 if (!list)
682 return false; 712 return false;
683 713
684 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 714 font_weight *fonts = new font_weight[count];
685 ? 0 : prop.height);
686 715
687 int bestdiff = 0x7fffffff;
688 for (int i = 0; i < count; i++) 716 for (int i = 0; i < count; i++)
689 { 717 {
690 rxvt_fontprop p; 718 rxvt_fontprop p;
691 char fname[1024]; 719 char fname[1024];
692 720
693 int diff = 0; 721 int diff = 0;
694 722
695 if (replace_field (fname, list[i], 6, '0', field_str)) 723 if (replace_field (fname, list[i], 6, '0', field_str))
696 diff += 10; // slightly penalize scalable fonts 724 diff += 10; // slightly penalize scalable fonts
725 else if (replace_field (fname, list[i], 11, '0', "0"))
726 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
697 727
698 if (!set_properties (p, fname)) 728 if (!set_properties (p, fname))
699 continue; 729 continue;
700 730
701 if (prop.height != rxvt_fontprop::unset 731 if (prop.height != rxvt_fontprop::unset
705 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; 735 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128;
706 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); 736 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight);
707 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); 737 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant);
708 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); 738 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width);
709 739
710 if (!name // compare against best found so far 740 fonts[i].name = strdup (fname);
711 || diff < bestdiff) 741 fonts[i].diff = diff;
712 {
713 set_name (strdup (fname));
714 bestdiff = diff;
715 }
716 } 742 }
717 743
718 XFreeFontNames (list); 744 XFreeFontNames (list);
719 745
720 if (!name) 746 // this loop only iterates when the guessed font-size is too small
721 return false; 747 for (;;)
748 {
749 font_weight *best = fonts + count - 1;
722 750
723 f = XLoadQueryFont (DISPLAY, name); 751 for (font_weight *w = best; w-- > fonts; )
752 if (w->diff <= best->diff)
753 best = w;
754
755 if (!best->name
756 || !(f = XLoadQueryFont (disp, best->name)))
757 break;
758
759 set_name (best->name);
760 best->clear ();
761
762 ascent = f->ascent;
763 descent = f->descent;
764 height = ascent + descent;
765
766 if (prop.height == rxvt_fontprop::unset
767 || height <= prop.height)
768 break; // font is ready for use
769
770 // PIXEL_SIZE small enough, but real height too large
771 clear ();
772 }
773
774 delete [] fonts;
724 775
725 if (!f) 776 if (!f)
726 return false; 777 return false;
727 778
728 char *registry = get_property (f, "CHARSET_REGISTRY", 0); 779 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
756 if (cs == CS_UNICODE) 807 if (cs == CS_UNICODE)
757 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 808 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
758 809
759 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 810 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
760 enc2b = encm || f->max_char_or_byte2 > 255; 811 enc2b = encm || f->max_char_or_byte2 > 255;
761
762 ascent = f->ascent;
763 descent = f->descent;
764 height = ascent + descent;
765 812
766 slow = false; 813 slow = false;
767 814
768#if 1 // only used for slow detection, TODO optimize 815#if 1 // only used for slow detection, TODO optimize
769 if (f->min_bounds.width == f->max_bounds.width) 816 if (f->min_bounds.width == f->max_bounds.width)
808 855
809 XCharStruct g; 856 XCharStruct g;
810 int dir_ret, asc_ret, des_ret; 857 int dir_ret, asc_ret, des_ret;
811 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); 858 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g);
812 859
813 int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; 860 int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
814 861
815 if (width < g.width) width = g.width; 862 if (width < g.width) width = g.width;
816 } 863 }
817 864
818 if (cs == CS_UNKNOWN) 865 if (cs == CS_UNKNOWN)
837void 884void
838rxvt_font_x11::clear () 885rxvt_font_x11::clear ()
839{ 886{
840 if (f) 887 if (f)
841 { 888 {
842 XFreeFont (DISPLAY, f); 889 XFreeFont (term->display->display, f);
843 f = 0; 890 f = 0;
844 } 891 }
845} 892}
846 893
847bool 894bool
848rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 895rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
849{ 896{
850 uint32_t ch = FROM_UNICODE (cs, unicode); 897 uint32_t ch = FROM_UNICODE (cs, unicode);
851 898
852 if (ch == NOCHAR) 899 if (ch == NOCHAR)
853 return false; 900 return false;
891 938
892 if (!prop || prop->width == rxvt_fontprop::unset) 939 if (!prop || prop->width == rxvt_fontprop::unset)
893 return true; 940 return true;
894 941
895 // check character against base font bounding box 942 // check character against base font bounding box
896 int w = xcs->width; 943 int w = xcs->rbearing - xcs->lbearing;
897 int wcw = wcwidth (unicode); 944 int wcw = WCWIDTH (unicode);
898 if (wcw > 0) w /= wcw; 945 if (wcw > 0) w = (w + wcw - 1) / wcw;
899 946
900 careful = w > prop->width; 947 careful = w > prop->width;
901 if (careful && w > prop->width * MAX_OVERLAP >> 2) 948 if (careful && OVERLAP_OK (w, prop))
902 return false; 949 return false;
903 950
904 return true; 951 return true;
905} 952}
906 953
912 // this looks like a mess /. 959 // this looks like a mess /.
913 // and it is a mess /. 960 // and it is a mess /.
914 // yet we are trying to be perfect /. 961 // yet we are trying to be perfect /.
915 // but the result still isn't perfect /. 962 // but the result still isn't perfect /.
916 963
964 dTermDisplay;
965 dTermGC;
966
917 bool slow = this->slow 967 bool slow = this->slow
918 || width != r->TermWin.fwidth 968 || width != term->fwidth
919 || height != r->TermWin.fheight; 969 || height != term->fheight;
920 970
921 int base = ascent; // sorry, incorrect: r->TermWin.fbase; 971 int base = ascent; // sorry, incorrect: term->fbase;
922 972
923 XGCValues v; 973 XGCValues v;
924 v.foreground = r->pix_colors[fg]; 974 v.foreground = term->pix_colors[fg];
925 v.font = f->fid; 975 v.font = f->fid;
926 976
927 if (enc2b) 977 if (enc2b)
928 { 978 {
929 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 979 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
930 980
931 if (bg == Color_bg && !slow) 981 if (bg == Color_bg && !slow)
932 { 982 {
933 v.background = r->pix_colors[bg]; 983 v.background = term->pix_colors[bg];
934 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 984 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
935 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 985 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
936 } 986 }
937 else 987 else
938 { 988 {
939 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 989 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
940 990
941 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 991 XChangeGC (disp, gc, GCForeground | GCFont, &v);
942 992
943 if (slow) 993 if (slow)
944 { 994 {
945 do 995 do
946 { 996 {
947 if (xc->byte1 || xc->byte2) 997 if (xc->byte1 || xc->byte2)
948 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 998 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
949 999
950 x += r->TermWin.fwidth; 1000 x += term->fwidth;
951 xc++; len--; 1001 xc++; len--;
952 } 1002 }
953 while (len); 1003 while (len);
954 } 1004 }
955 else 1005 else
956 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 1006 XDrawString16 (disp, d, gc, x, y + base, xc, len);
957 } 1007 }
958 } 1008 }
959 else 1009 else
960 { 1010 {
961 const char *xc = enc_char (text, len, cs, slow); 1011 const char *xc = enc_char (text, len, cs, slow);
962 1012
963 if (bg == Color_bg && !slow) 1013 if (bg == Color_bg && !slow)
964 { 1014 {
965 v.background = r->pix_colors[bg]; 1015 v.background = term->pix_colors[bg];
966 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1016 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
967 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1017 XDrawImageString (disp, d, gc, x, y + base, xc, len);
968 } 1018 }
969 else 1019 else
970 { 1020 {
971 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 1021 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
972 1022
973 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1023 XChangeGC (disp, gc, GCForeground | GCFont, &v);
974 1024
975 if (slow) 1025 if (slow)
976 { 1026 {
977 do 1027 do
978 { 1028 {
979 if (*xc) 1029 if (*xc)
980 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1030 XDrawString (disp, d, gc, x, y + base, xc, 1);
981 1031
982 x += r->TermWin.fwidth; 1032 x += term->fwidth;
983 xc++; len--; 1033 xc++; len--;
984 } 1034 }
985 while (len); 1035 while (len);
986 } 1036 }
987 else 1037 else
988 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1038 XDrawString (disp, d, gc, x, y + base, xc, len);
989 } 1039 }
990 } 1040 }
991} 1041}
992 1042
993///////////////////////////////////////////////////////////////////////////// 1043/////////////////////////////////////////////////////////////////////////////
1005 1055
1006 void draw (rxvt_drawable &d, int x, int y, 1056 void draw (rxvt_drawable &d, int x, int y,
1007 const text_t *text, int len, 1057 const text_t *text, int len,
1008 int fg, int bg); 1058 int fg, int bg);
1009 1059
1010 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); 1060 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
1011 1061
1012protected: 1062protected:
1013 XftFont *f; 1063 XftFont *f;
1014}; 1064};
1015 1065
1016void 1066void
1017rxvt_font_xft::clear () 1067rxvt_font_xft::clear ()
1018{ 1068{
1019 if (f) 1069 if (f)
1020 { 1070 {
1021 XftFontClose (DISPLAY, f); 1071 XftFontClose (term->display->display, f);
1022 f = 0; 1072 f = 0;
1023 } 1073 }
1024} 1074}
1025 1075
1026rxvt_fontprop 1076rxvt_fontprop
1030 1080
1031 FT_Face face = XftLockFace (f); 1081 FT_Face face = XftLockFace (f);
1032 1082
1033 p.width = width; 1083 p.width = width;
1034 p.height = height; 1084 p.height = height;
1085 p.ascent = ascent;
1035 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD 1086 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD
1036 ? rxvt_fontprop::bold : rxvt_fontprop::medium; 1087 ? rxvt_fontprop::bold : rxvt_fontprop::medium;
1037 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC 1088 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC
1038 ? rxvt_fontprop::italic : rxvt_fontprop::roman; 1089 ? rxvt_fontprop::italic : rxvt_fontprop::roman;
1039 1090
1043} 1094}
1044 1095
1045bool 1096bool
1046rxvt_font_xft::load (const rxvt_fontprop &prop) 1097rxvt_font_xft::load (const rxvt_fontprop &prop)
1047{ 1098{
1099 dTermDisplay;
1100
1048 clear (); 1101 clear ();
1049 1102
1050 FcPattern *p = FcNameParse ((FcChar8 *) name); 1103 FcPattern *p = FcNameParse ((FcChar8 *) name);
1051 1104
1052 if (!p) 1105 if (!p)
1053 return false; 1106 return false;
1054 1107
1055 FcValue v; 1108 FcValue v;
1056 1109
1057 if (prop.height != rxvt_fontprop::unset 1110 if (prop.height != rxvt_fontprop::unset
1058 || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch 1111 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch
1059 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) 1112 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch))
1060 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); 1113 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
1061 1114
1062 if (prop.weight != rxvt_fontprop::unset 1115 if (prop.weight != rxvt_fontprop::unset
1063 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 1116 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
1078 1131
1079 // store generated name so iso14755 view gives better results 1132 // store generated name so iso14755 view gives better results
1080 set_name ((char *)FcNameUnparse (p)); 1133 set_name ((char *)FcNameUnparse (p));
1081 1134
1082 XftResult result; 1135 XftResult result;
1083 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 1136 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1084 1137
1085 FcPatternDestroy (p); 1138 FcPatternDestroy (p);
1086 1139
1087 if (!match) 1140 if (!match)
1088 return false; 1141 return false;
1090 int ftheight = 0; 1143 int ftheight = 0;
1091 bool success = true; 1144 bool success = true;
1092 1145
1093 for (;;) 1146 for (;;)
1094 { 1147 {
1095 f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); 1148 f = XftFontOpenPattern (disp, FcPatternDuplicate (match));
1096 1149
1097 if (!f) 1150 if (!f)
1098 { 1151 {
1099 success = false; 1152 success = false;
1100 break; 1153 break;
1109 1162
1110 bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; 1163 bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE;
1111 1164
1112 XftUnlockFace (f); 1165 XftUnlockFace (f);
1113 1166
1167 int glheight = height;
1168
1114 for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) 1169 for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; )
1115 { 1170 {
1116 FcChar16 ch = *t; 1171 FcChar16 ch = *t;
1117 1172
1118 if (cs != CS_UNICODE 1173 if (cs != CS_UNICODE
1124 bool careful; 1179 bool careful;
1125 if (!has_char (*t, &prop, careful)) 1180 if (!has_char (*t, &prop, careful))
1126 continue; 1181 continue;
1127 1182
1128 XGlyphInfo g; 1183 XGlyphInfo g;
1129 XftTextExtents16 (DISPLAY, f, &ch, 1, &g); 1184 XftTextExtents16 (disp, f, &ch, 1, &g);
1130 1185
1186 g.width -= g.x;
1187
1131 int wcw = wcwidth (ch); 1188 int wcw = WCWIDTH (ch);
1132 if (wcw > 0) g.width = g.width / wcw; 1189 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
1133 1190
1134 if (width < g.width) width = g.width; 1191 if (width < g.width ) width = g.width;
1135 if (height < g.height) height = g.height; 1192 if (height < g.height ) height = g.height;
1193 if (glheight < g.height - g.y) glheight = g.height - g.y;
1194 }
1195
1196 if (!width)
1197 {
1198 rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name);
1199
1200 XftFontClose (disp, f);
1201 f = 0;
1202
1203 success = false;
1204 break;
1136 } 1205 }
1137 1206
1138 if (prop.height == rxvt_fontprop::unset 1207 if (prop.height == rxvt_fontprop::unset
1139 || height <= prop.height 1208 || (height <= prop.height && glheight <= prop.height)
1140 || height <= 2 1209 || height <= 2
1141 || !scalable) 1210 || !scalable)
1142 break; 1211 break;
1143 1212
1144 if (ftheight) 1213 if (ftheight)
1151 ftheight -= height - prop.height; 1220 ftheight -= height - prop.height;
1152 } 1221 }
1153 else 1222 else
1154 ftheight = prop.height - 1; 1223 ftheight = prop.height - 1;
1155 1224
1156 XftFontClose (DISPLAY, f); 1225 XftFontClose (disp, f);
1157 FcPatternDel (match, FC_PIXEL_SIZE); 1226 FcPatternDel (match, FC_PIXEL_SIZE);
1158 FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); 1227 FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight);
1159 } 1228 }
1160 1229
1161 FcPatternDestroy (match); 1230 FcPatternDestroy (match);
1162 1231
1163#if 0 // do it per-character 1232#if 0 // do it per-character
1170 1239
1171 return success; 1240 return success;
1172} 1241}
1173 1242
1174bool 1243bool
1175rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 1244rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1176{ 1245{
1177 careful = false; 1246 careful = false;
1178 1247
1179 if (!XftCharExists (DISPLAY, f, unicode)) 1248 if (!XftCharExists (term->display->display, f, unicode))
1180 return false; 1249 return false;
1181 1250
1182 if (!prop || prop->width == rxvt_fontprop::unset) 1251 if (!prop || prop->width == rxvt_fontprop::unset)
1183 return true; 1252 return true;
1184 1253
1185 // check character against base font bounding box 1254 // check character against base font bounding box
1186 FcChar32 ch = unicode; 1255 FcChar32 ch = unicode;
1187 XGlyphInfo g; 1256 XGlyphInfo g;
1188 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1257 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1189 1258
1190 int w = g.width; 1259 int w = g.width - g.x;
1191 int wcw = wcwidth (unicode); 1260 int wcw = WCWIDTH (unicode);
1192 if (wcw > 0) w /= wcw; 1261 if (wcw > 0) w = (w + wcw - 1) / wcw;
1193 1262
1194 careful = w > prop->width; 1263 careful = w > prop->width;
1195 if (careful && w > prop->width * MAX_OVERLAP >> 2) 1264 if (careful && OVERLAP_OK (w, prop))
1196 return false; 1265 return false;
1197 1266
1198 return true; 1267 return true;
1199} 1268}
1200 1269
1201void 1270void
1202rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1271rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1203 const text_t *text, int len, 1272 const text_t *text, int len,
1204 int fg, int bg) 1273 int fg, int bg)
1205{ 1274{
1206 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 1275 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1207
1208 int base = ascent; // should be fbase, but that is incorrect
1209 1276
1210 XGlyphInfo extents; 1277 XGlyphInfo extents;
1211 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); 1278 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1212 FcChar32 *ep = enc; 1279 XftGlyphSpec *ep = enc;
1213 int ewidth = 0; 1280
1214 int xoff = 0; 1281 dTermDisplay;
1282 dTermGC;
1283
1284 // cut trailing spaces
1285 while (len && text [len - 1] == ' ')
1286 len--;
1215 1287
1216 while (len) 1288 while (len)
1217 { 1289 {
1218 int cwidth = r->TermWin.fwidth; 1290 int cwidth = term->fwidth;
1219 FcChar32 fc = *text++; len--; 1291 FcChar32 fc = *text++; len--;
1220 FT_UInt gl;
1221 1292
1222 while (len && *text == NOCHAR) 1293 while (len && *text == NOCHAR)
1223 text++, len--, cwidth += r->TermWin.fwidth; 1294 text++, len--, cwidth += term->fwidth;
1224 1295
1225 gl = XftCharIndex (d.display->display, f, fc); 1296 if (fc != ' ') // skip spaces
1226 XftGlyphExtents (d.display->display, f, &gl, 1, &extents);
1227
1228 if (extents.xOff != cwidth && ep != enc)
1229 {
1230 if (xoff > ewidth) xoff = ewidth;
1231 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1232 x + (ewidth - xoff >> 1),
1233 y + base, enc, ep - enc);
1234 x += ewidth;
1235
1236 ep = enc;
1237 ewidth = 0;
1238 xoff = 0;
1239 } 1297 {
1298 FT_UInt glyph = XftCharIndex (disp, f, fc);
1299 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1240 1300
1241 if (fc == ' ' && ep == enc) // skip leading spaces 1301 ep->glyph = glyph;
1302 ep->x = x + (cwidth - extents.xOff >> 1);
1303 ep->y = y + ascent;
1304 ep++;
1242 { 1305 }
1306
1243 x += cwidth; 1307 x += cwidth;
1244 continue;
1245 }
1246
1247 else
1248 {
1249 *ep++ = gl;
1250 ewidth += cwidth;
1251 xoff += extents.xOff;
1252 }
1253 } 1308 }
1254 1309
1255 if (ep != enc) 1310 if (ep != enc)
1256 {
1257 if (xoff > ewidth) xoff = ewidth;
1258 XftDrawGlyphs (d, &r->pix_colors[fg].c, f, 1311 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1259 x + (ewidth - xoff >> 1),
1260 y + base, enc, ep - enc);
1261 }
1262} 1312}
1263#endif 1313#endif
1264 1314
1265///////////////////////////////////////////////////////////////////////////// 1315/////////////////////////////////////////////////////////////////////////////
1266 1316
1267rxvt_fontset::rxvt_fontset (rxvt_t r) 1317rxvt_fontset::rxvt_fontset (rxvt_term *term)
1268: r (r), fontdesc (0) 1318: fontdesc (0), term (term)
1269{ 1319{
1270 clear (); 1320 clear ();
1271} 1321}
1272 1322
1273rxvt_fontset::~rxvt_fontset () 1323rxvt_fontset::~rxvt_fontset ()
1276} 1326}
1277 1327
1278void 1328void
1279rxvt_fontset::clear () 1329rxvt_fontset::clear ()
1280{ 1330{
1281 prop.width = prop.height = prop.weight = prop.slant 1331 prop.width = prop.height = prop.ascent = prop.weight = prop.slant
1282 = rxvt_fontprop::unset; 1332 = rxvt_fontprop::unset;
1283 1333
1284 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1334 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1285 FONT_UNREF (*i); 1335 FONT_UNREF (*i);
1286 1336
1317 f = new rxvt_font_x11; 1367 f = new rxvt_font_x11;
1318 } 1368 }
1319 else 1369 else
1320 f = new rxvt_font_x11; 1370 f = new rxvt_font_x11;
1321 1371
1322 f->set_term (r); 1372 f->set_term (term);
1323 f->set_name (strdup (name)); 1373 f->set_name (strdup (name));
1324 1374
1325 f->cs = cs; 1375 f->cs = cs;
1326 f->loaded = false; 1376 f->loaded = false;
1327 1377
1338 char buf[512]; 1388 char buf[512];
1339 const char *end; 1389 const char *end;
1340 1390
1341 do 1391 do
1342 { 1392 {
1343 while (*desc <= ' ') desc++; 1393 while (*desc && *desc <= ' ')
1394 desc++;
1344 1395
1345 codeset cs = CS_UNICODE; 1396 codeset cs = CS_UNICODE;
1346 1397
1347 if (*desc == '[') 1398 if (*desc == '[')
1348 { 1399 {
1458 if (FROM_UNICODE (f->cs, unicode) == NOCHAR) 1509 if (FROM_UNICODE (f->cs, unicode) == NOCHAR)
1459 goto next_font; 1510 goto next_font;
1460 1511
1461 if (!realize_font (i)) 1512 if (!realize_font (i))
1462 goto next_font; 1513 goto next_font;
1514
1515 if (prop.ascent != rxvt_fontprop::unset)
1516 max_it (f->ascent, prop.ascent);
1463 } 1517 }
1464 1518
1465 if (f->cs == CS_UNKNOWN) 1519 if (f->cs == CS_UNKNOWN)
1466 goto next_font; 1520 goto next_font;
1467 1521
1506 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1560 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1507 FcPatternAddBool (p, FC_MINSPACE, 1); 1561 FcPatternAddBool (p, FC_MINSPACE, 1);
1508 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1562 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1509 1563
1510 XftResult result; 1564 XftResult result;
1511 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 1565 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1512 1566
1513 FcPatternDestroy (p); 1567 FcPatternDestroy (p);
1514 1568
1515 if (match) 1569 if (match)
1516 { 1570 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines