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.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"
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#define DISPLAY r->display->display
32#define TGC r->TermWin.gc
33 31
34#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 32#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width
35 33
36const struct rxvt_fallback_font { 34const struct rxvt_fallback_font {
37 codeset cs; 35 codeset cs;
130 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, 128 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
131 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 129 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
132 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 130 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
133 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 131 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
134#if XFT 132#if XFT
135 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, 133 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" },
136 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, 134 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" },
137 { CS_UNICODE, "xft:Andale Mono:antialias=false" }, 135 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" },
138 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, 136 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" },
139 137
140 // FreeMono is usually uglier than x fonts, so try last only. 138 // FreeMono is usually uglier than x fonts, so try last only.
141 { CS_UNICODE, "xft:FreeMono:autohint=true" }, 139 { CS_UNICODE, "xft:FreeMono:autohint=true" },
142#endif 140#endif
143 141
144 { CS_UNKNOWN, 0 } 142 { CS_UNKNOWN, 0 }
145}; 143};
146 144
147// these characters are used to guess the font height and width 145// these characters are used to guess the font height and width
148// pango uses a similar algorithm and eosn't trust the font either. 146// pango uses a similar algorithm and doesn't trust the font either.
149static uint16_t extent_test_chars[] = { 147static uint16_t extent_test_chars[] = {
150 '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', 148 '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_',
151 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ 149 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ
152 0x304c, 0x672c, // が本 150 0x304c, 0x672c, // が本
153}; 151};
154 152
155#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 153#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
156 154
155#define dTermDisplay Display *disp = term->display->display
156#define dTermGC GC gc = term->gc
157
157///////////////////////////////////////////////////////////////////////////// 158/////////////////////////////////////////////////////////////////////////////
158 159
159#if XFT 160#if XFT
160rxvt_drawable::~rxvt_drawable () 161rxvt_drawable::~rxvt_drawable ()
161{ 162{
245 if (this->name) free (this->name); // let the compiler optimize 246 if (this->name) free (this->name); // let the compiler optimize
246 this->name = name; 247 this->name = name;
247} 248}
248 249
249void 250void
250rxvt_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
251{ 252{
253 dTermDisplay;
254 dTermGC;
255
252 if (color == Color_bg) 256 if (color == Color_bg)
253 XClearArea (d.display->display, d, x, y, w, h, FALSE); 257 XClearArea (disp, d, x, y, w, h, FALSE);
254 else if (color >= 0) 258 else if (color >= 0)
255 { 259 {
256#if XFT 260#if XFT
257 XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); 261 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
258#else 262#else
259 XSetForeground (d.display->display, TGC, r->pix_colors[color]); 263 XSetForeground (disp, gc, term->pix_colors[color]);
260 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 264 XFillRectangle (disp, d, gc, x, y, w, h);
261#endif 265#endif
262 } 266 }
263} 267}
264 268
265#include "table/linedraw.h" 269#include "table/linedraw.h"
276 rxvt_fontprop properties () 280 rxvt_fontprop properties ()
277 { 281 {
278 rxvt_fontprop p; 282 rxvt_fontprop p;
279 283
280 p.width = p.height = 1; 284 p.width = p.height = 1;
285 p.ascent = rxvt_fontprop::unset;
281 p.weight = rxvt_fontprop::medium; 286 p.weight = rxvt_fontprop::medium;
282 p.slant = rxvt_fontprop::roman; 287 p.slant = rxvt_fontprop::roman;
283 288
284 return p; 289 return p;
285 } 290 }
292 set_name (strdup ("built-in support font")); 297 set_name (strdup ("built-in support font"));
293 298
294 return true; 299 return true;
295 } 300 }
296 301
297 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 302 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
298 { 303 {
299 careful = false; 304 careful = false;
300 305
301 if (unicode <= 0x001f) 306 if (unicode <= 0x001f)
302 return true; 307 return true;
305 return false; 310 return false;
306 311
307 if (unicode <= 0x009f) 312 if (unicode <= 0x009f)
308 return true; 313 return true;
309 314
310 if (unicode >= 0x2500 && unicode <= 0x259f) 315 if (unicode >= 0x2500 && unicode <= 0x259f &&
316 !term->option (Opt_skipBuiltinGlyphs))
311 return true; 317 return true;
312 318
313 if (IS_COMPOSE (unicode)) 319 if (IS_COMPOSE (unicode))
314 return true; 320 return true;
315 321
331void 337void
332rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 338rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
333 const text_t *text, int len, 339 const text_t *text, int len,
334 int fg, int bg) 340 int fg, int bg)
335{ 341{
342 dTermDisplay;
343 dTermGC;
344
336 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);
337 346
338 XSetForeground (d.display->display, TGC, r->pix_colors[fg]); 347 XSetForeground (disp, gc, term->pix_colors[fg]);
339 348
340 while (len) 349 while (len)
341 { 350 {
342#if ENABLE_COMBINING 351#if ENABLE_COMBINING
343 compose_char *cc; 352 compose_char *cc;
347 356
348 while (++text, --len && *text == NOCHAR) 357 while (++text, --len && *text == NOCHAR)
349 ; 358 ;
350 359
351 int width = text - tp; 360 int width = text - tp;
352 int fwidth = r->TermWin.fwidth * width; 361 int fwidth = term->fwidth * width;
353 362
354 if (0x2500 <= t && t <= 0x259f) 363 if (0x2500 <= t && t <= 0x259f)
355 { 364 {
356 uint16_t offs = linedraw_offs[t - 0x2500]; 365 uint16_t offs = linedraw_offs[t - 0x2500];
357 uint32_t *a = linedraw_command + (offs >> 4); 366 uint32_t *a = linedraw_command + (offs >> 4);
358 uint32_t *b = a + (offs & 15); 367 uint32_t *b = a + (offs & 15);
359 368
360 int W = fwidth; 369 int W = fwidth;
361 int H = r->TermWin.fheight; 370 int H = term->fheight;
362 371
363 int x_[16]; 372 int x_[16];
364 int y_[16]; 373 int y_[16];
365 374
366 for (int i = 0; i <= 8; i++) 375 for (int i = 0; i <= 8; i++)
374 383
375 XGCValues gcv; 384 XGCValues gcv;
376 385
377 gcv.cap_style = CapButt; 386 gcv.cap_style = CapButt;
378 gcv.line_width = 0; 387 gcv.line_width = 0;
379 XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); 388 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
380 389
381 while (a < b) 390 while (a < b)
382 { 391 {
383 uint32_t command = *a++; 392 uint32_t command = *a++;
384 393
391 int y2 = y_[(command >> 0) & 15]; 400 int y2 = y_[(command >> 0) & 15];
392 401
393 switch (op) 402 switch (op)
394 { 403 {
395 case 0: // line 404 case 0: // line
396 XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); 405 XDrawLine (disp, d, gc, x1, y1, x2, y2);
397 break; 406 break;
398 407
399 case 1: // rectangle, possibly stippled 408 case 1: // rectangle, possibly stippled
400 if (a) 409 if (a)
401 { 410 {
402 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; 411 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
403 412
404 gcv.fill_style = FillStippled; 413 gcv.fill_style = FillStippled;
405 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); 414 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
406 gcv.ts_x_origin = x; 415 gcv.ts_x_origin = x;
407 gcv.ts_y_origin = y; 416 gcv.ts_y_origin = y;
408 417
409 XChangeGC (d.display->display, TGC, 418 XChangeGC (disp, gc,
410 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 419 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
411 &gcv); 420 &gcv);
412 } 421 }
413 422
414 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);
415 424
416 if (a) 425 if (a)
417 { 426 {
418 XFreePixmap (d.display->display, gcv.stipple); 427 XFreePixmap (disp, gcv.stipple);
419 gcv.stipple = 0; 428 gcv.stipple = 0;
420 gcv.fill_style = FillSolid; 429 gcv.fill_style = FillSolid;
421 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); 430 XChangeGC (disp, gc, GCFillStyle, &gcv);
422 } 431 }
423 break; 432 break;
424 case 2: // arc 433 case 2: // arc
425 XDrawArc (d.display->display, d, TGC, 434 XDrawArc (disp, d, gc,
426 x1 - W/2, y1 - H/2, W-1, H-1, 435 x1 - W/2, y1 - H/2, W-1, H-1,
427 (a - 1) * 90*64, (b - 1) * 90*64); 436 (a - 1) * 90*64, (b - 1) * 90*64);
428 break; 437 break;
429 } 438 }
430 } 439 }
461 case ZERO_WIDTH_CHAR: 470 case ZERO_WIDTH_CHAR:
462 case NOCHAR: 471 case NOCHAR:
463 break; 472 break;
464 473
465 default: 474 default:
466 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, 475 XDrawRectangle (disp, d, gc, x + 2, y + 2,
467 fwidth - 4, r->TermWin.fheight - 4); 476 fwidth - 4, term->fheight - 4);
468 } 477 }
469 478
470 x += fwidth; 479 x += fwidth;
471 } 480 }
472} 481}
480 489
481 rxvt_fontprop properties (); 490 rxvt_fontprop properties ();
482 491
483 bool load (const rxvt_fontprop &prop); 492 bool load (const rxvt_fontprop &prop);
484 493
485 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); 494 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
486 495
487 void draw (rxvt_drawable &d, int x, int y, 496 void draw (rxvt_drawable &d, int x, int y,
488 const text_t *text, int len, 497 const text_t *text, int len,
489 int fg, int bg); 498 int fg, int bg);
490 499
502char * 511char *
503rxvt_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
504{ 513{
505 unsigned long value; 514 unsigned long value;
506 515
507 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 516 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
508 return XGetAtomName (DISPLAY, value); 517 return XGetAtomName (term->display->display, value);
509 else 518 else
510 return rxvt_strdup (repl); 519 return rxvt_strdup (repl);
511} 520}
512 521
513rxvt_fontprop 522rxvt_fontprop
521bool 530bool
522rxvt_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)
523{ 532{
524 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; 533 p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2;
525 p.height = height; 534 p.height = height;
535 p.ascent = rxvt_fontprop::unset;
526 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;
527 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;
528 538
529 return true; 539 return true;
530} 540}
531 541
532bool 542bool
533rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 543rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
534{ 544{
535 unsigned long height; 545 unsigned long height;
546
547#if 0
536 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 548 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
537 return false; 549 return false;
550#else
551 height = f->ascent + f->descent;
552#endif
538 553
539 unsigned long avgwidth; 554 unsigned long avgwidth;
540 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 555 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
541 avgwidth = 0; 556 avgwidth = 0;
542 557
543 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 558 char *weight = get_property (f, "WEIGHT_NAME", "medium");
544 char *slant = get_property (f, "SLANT", "r"); 559 char *slant = get_property (f, "SLANT", "r");
545 560
546 set_properties (p, height, weight, slant, avgwidth); 561 set_properties (p, height, weight, slant, avgwidth);
547 562
548 free (weight); 563 free (weight);
549 free (slant); 564 free (slant);
550 565
566 p.ascent = f->ascent;
567
551 return true; 568 return true;
552} 569}
553 570
554bool 571bool
555rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 572rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
556{ 573{
574 dTermDisplay;
557 int slashes = 0; 575 int slashes = 0;
558 const char *comp[13]; 576 const char *comp[13];
559 577
560 for (const char *c = name; *c; c++) 578 for (const char *c = name; *c; c++)
561 if (*c == '-') 579 if (*c == '-')
569 if (slashes >= 13 587 if (slashes >= 13
570 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 588 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
571 && (*comp[11] >= '0' && *comp[11] <= '9')) 589 && (*comp[11] >= '0' && *comp[11] <= '9'))
572 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]));
573 591
574 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 592 XFontStruct *f = XLoadQueryFont (disp, name);
575 593
576 if (f) 594 if (f)
577 { 595 {
578 // 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
579 // (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).
580 // in that case, just return garbage. 598 // in that case, just return garbage.
581 bool ret = set_properties (p, f); 599 bool ret = set_properties (p, f);
582 XFreeFont (DISPLAY, f); 600 XFreeFont (disp, f);
583 return ret; 601 return ret;
584 } 602 }
585 else 603 else
586 return false; 604 return false;
587} 605}
625} 643}
626 644
627bool 645bool
628rxvt_font_x11::load (const rxvt_fontprop &prop) 646rxvt_font_x11::load (const rxvt_fontprop &prop)
629{ 647{
648 dTermDisplay;
649
630 clear (); 650 clear ();
631 651
632 char field_str[64]; // enough for 128 bits 652 char field_str[64]; // enough for 128 bits
633 653
634 // first morph the font if required 654 // first morph the font if required
637 { 657 {
638 char fname[1024]; 658 char fname[1024];
639 659
640 if (name[0] != '-') 660 if (name[0] != '-')
641 { 661 {
642 f = XLoadQueryFont (DISPLAY, name); 662 f = XLoadQueryFont (disp, name);
643 663
644 if (!f) 664 if (!f)
645 return false; 665 return false;
646 666
647 char *new_name = get_property (f, "FONT", name); 667 char *new_name = get_property (f, "FONT", name);
649 if (new_name) 669 if (new_name)
650 set_name (new_name); 670 set_name (new_name);
651 else 671 else
652 rxvt_warn ("font '%s' has no FONT property, continuing without.", name); 672 rxvt_warn ("font '%s' has no FONT property, continuing without.", name);
653 673
654 XFreeFont (DISPLAY, f); 674 XFreeFont (disp, f);
655 f = 0; 675 f = 0;
656 } 676 }
657 677
658 if (prop.weight != rxvt_fontprop::unset) 678 if (prop.weight != rxvt_fontprop::unset)
659 { 679 {
670 ? "r" : "i"); // TODO: handle "o"blique, too 690 ? "r" : "i"); // TODO: handle "o"blique, too
671 set_name (strdup (fname)); 691 set_name (strdup (fname));
672 } 692 }
673 } 693 }
674 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 };
711
675 char **list; 712 char **list;
676 int count; 713 int count;
677 list = XListFonts (DISPLAY, name, 1024, &count); 714 list = XListFonts (disp, name, 4000, &count);
678 715
679 set_name (0); 716 set_name (0);
680 717
681 if (!list) 718 if (!list)
682 return false; 719 return false;
683 720
684 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 721 font_weight *fonts = new font_weight[count];
685 ? 0 : prop.height);
686 722
687 int bestdiff = 0x7fffffff;
688 for (int i = 0; i < count; i++) 723 for (int i = 0; i < count; i++)
689 { 724 {
690 rxvt_fontprop p; 725 rxvt_fontprop p;
691 char fname[1024]; 726 char fname[1024];
692 727
693 int diff = 0; 728 int diff = 0;
694 729
695 if (replace_field (fname, list[i], 6, '0', field_str)) 730 if (replace_field (fname, list[i], 6, '0', field_str))
696 diff += 10; // slightly penalize scalable fonts 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
697 734
698 if (!set_properties (p, fname)) 735 if (!set_properties (p, fname))
699 continue; 736 continue;
700 737
701 if (prop.height != rxvt_fontprop::unset 738 if (prop.height != rxvt_fontprop::unset
705 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; 742 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); 743 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); 744 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); 745 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width);
709 746
710 if (!name // compare against best found so far 747 fonts[i].name = strdup (fname);
711 || diff < bestdiff) 748 fonts[i].diff = diff;
712 {
713 set_name (strdup (fname));
714 bestdiff = diff;
715 }
716 } 749 }
717 750
718 XFreeFontNames (list); 751 XFreeFontNames (list);
719 752
720 if (!name) 753 // this loop only iterates when the guessed font-size is too small
721 return false; 754 for (;;)
755 {
756 font_weight *best = fonts + count - 1;
722 757
723 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;
724 782
725 if (!f) 783 if (!f)
726 return false; 784 return false;
727 785
728 char *registry = get_property (f, "CHARSET_REGISTRY", 0); 786 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
756 if (cs == CS_UNICODE) 814 if (cs == CS_UNICODE)
757 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
758 816
759 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 817 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
760 enc2b = encm || f->max_char_or_byte2 > 255; 818 enc2b = encm || f->max_char_or_byte2 > 255;
761
762 ascent = f->ascent;
763 descent = f->descent;
764 height = ascent + descent;
765 819
766 slow = false; 820 slow = false;
767 821
768#if 1 // only used for slow detection, TODO optimize 822#if 1 // only used for slow detection, TODO optimize
769 if (f->min_bounds.width == f->max_bounds.width) 823 if (f->min_bounds.width == f->max_bounds.width)
808 862
809 XCharStruct g; 863 XCharStruct g;
810 int dir_ret, asc_ret, des_ret; 864 int dir_ret, asc_ret, des_ret;
811 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); 865 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g);
812 866
813 int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; 867 int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
814 868
815 if (width < g.width) width = g.width; 869 if (width < g.width) width = g.width;
816 } 870 }
817 871
818 if (cs == CS_UNKNOWN) 872 if (cs == CS_UNKNOWN)
837void 891void
838rxvt_font_x11::clear () 892rxvt_font_x11::clear ()
839{ 893{
840 if (f) 894 if (f)
841 { 895 {
842 XFreeFont (DISPLAY, f); 896 XFreeFont (term->display->display, f);
843 f = 0; 897 f = 0;
844 } 898 }
845} 899}
846 900
847bool 901bool
848rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 902rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
849{ 903{
850 uint32_t ch = FROM_UNICODE (cs, unicode); 904 uint32_t ch = FROM_UNICODE (cs, unicode);
851 905
852 if (ch == NOCHAR) 906 if (ch == NOCHAR)
853 return false; 907 return false;
893 return true; 947 return true;
894 948
895 // check character against base font bounding box 949 // check character against base font bounding box
896 int w = xcs->width; 950 int w = xcs->width;
897 int wcw = wcwidth (unicode); 951 int wcw = wcwidth (unicode);
898 if (wcw > 0) w /= wcw; 952 if (wcw > 0) w = (w + wcw - 1) / wcw;
899 953
900 careful = w > prop->width; 954 careful = w > prop->width;
901 if (careful && w > prop->width * MAX_OVERLAP >> 2) 955 if (careful && w > prop->width * MAX_OVERLAP >> 2)
902 return false; 956 return false;
903 957
912 // this looks like a mess /. 966 // this looks like a mess /.
913 // and it is a mess /. 967 // and it is a mess /.
914 // yet we are trying to be perfect /. 968 // yet we are trying to be perfect /.
915 // but the result still isn't perfect /. 969 // but the result still isn't perfect /.
916 970
971 dTermDisplay;
972 dTermGC;
973
917 bool slow = this->slow 974 bool slow = this->slow
918 || width != r->TermWin.fwidth 975 || width != term->fwidth
919 || height != r->TermWin.fheight; 976 || height != term->fheight;
920 977
921 int base = ascent; // sorry, incorrect: r->TermWin.fbase; 978 int base = ascent; // sorry, incorrect: term->fbase;
922 979
923 XGCValues v; 980 XGCValues v;
924 v.foreground = r->pix_colors[fg]; 981 v.foreground = term->pix_colors[fg];
925 v.font = f->fid; 982 v.font = f->fid;
926 983
927 if (enc2b) 984 if (enc2b)
928 { 985 {
929 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 986 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
930 987
931 if (bg == Color_bg && !slow) 988 if (bg == Color_bg && !slow)
932 { 989 {
933 v.background = r->pix_colors[bg]; 990 v.background = term->pix_colors[bg];
934 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 991 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
935 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 992 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
936 } 993 }
937 else 994 else
938 { 995 {
939 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);
940 997
941 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 998 XChangeGC (disp, gc, GCForeground | GCFont, &v);
942 999
943 if (slow) 1000 if (slow)
944 { 1001 {
945 do 1002 do
946 { 1003 {
947 if (xc->byte1 || xc->byte2) 1004 if (xc->byte1 || xc->byte2)
948 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 1005 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
949 1006
950 x += r->TermWin.fwidth; 1007 x += term->fwidth;
951 xc++; len--; 1008 xc++; len--;
952 } 1009 }
953 while (len); 1010 while (len);
954 } 1011 }
955 else 1012 else
956 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 1013 XDrawString16 (disp, d, gc, x, y + base, xc, len);
957 } 1014 }
958 } 1015 }
959 else 1016 else
960 { 1017 {
961 const char *xc = enc_char (text, len, cs, slow); 1018 const char *xc = enc_char (text, len, cs, slow);
962 1019
963 if (bg == Color_bg && !slow) 1020 if (bg == Color_bg && !slow)
964 { 1021 {
965 v.background = r->pix_colors[bg]; 1022 v.background = term->pix_colors[bg];
966 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1023 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
967 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1024 XDrawImageString (disp, d, gc, x, y + base, xc, len);
968 } 1025 }
969 else 1026 else
970 { 1027 {
971 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);
972 1029
973 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1030 XChangeGC (disp, gc, GCForeground | GCFont, &v);
974 1031
975 if (slow) 1032 if (slow)
976 { 1033 {
977 do 1034 do
978 { 1035 {
979 if (*xc) 1036 if (*xc)
980 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1037 XDrawString (disp, d, gc, x, y + base, xc, 1);
981 1038
982 x += r->TermWin.fwidth; 1039 x += term->fwidth;
983 xc++; len--; 1040 xc++; len--;
984 } 1041 }
985 while (len); 1042 while (len);
986 } 1043 }
987 else 1044 else
988 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1045 XDrawString (disp, d, gc, x, y + base, xc, len);
989 } 1046 }
990 } 1047 }
991} 1048}
992 1049
993///////////////////////////////////////////////////////////////////////////// 1050/////////////////////////////////////////////////////////////////////////////
1005 1062
1006 void draw (rxvt_drawable &d, int x, int y, 1063 void draw (rxvt_drawable &d, int x, int y,
1007 const text_t *text, int len, 1064 const text_t *text, int len,
1008 int fg, int bg); 1065 int fg, int bg);
1009 1066
1010 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); 1067 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
1011 1068
1012protected: 1069protected:
1013 XftFont *f; 1070 XftFont *f;
1014}; 1071};
1015 1072
1016void 1073void
1017rxvt_font_xft::clear () 1074rxvt_font_xft::clear ()
1018{ 1075{
1019 if (f) 1076 if (f)
1020 { 1077 {
1021 XftFontClose (DISPLAY, f); 1078 XftFontClose (term->display->display, f);
1022 f = 0; 1079 f = 0;
1023 } 1080 }
1024} 1081}
1025 1082
1026rxvt_fontprop 1083rxvt_fontprop
1030 1087
1031 FT_Face face = XftLockFace (f); 1088 FT_Face face = XftLockFace (f);
1032 1089
1033 p.width = width; 1090 p.width = width;
1034 p.height = height; 1091 p.height = height;
1092 p.ascent = ascent;
1035 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD 1093 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD
1036 ? rxvt_fontprop::bold : rxvt_fontprop::medium; 1094 ? rxvt_fontprop::bold : rxvt_fontprop::medium;
1037 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC 1095 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC
1038 ? rxvt_fontprop::italic : rxvt_fontprop::roman; 1096 ? rxvt_fontprop::italic : rxvt_fontprop::roman;
1039 1097
1043} 1101}
1044 1102
1045bool 1103bool
1046rxvt_font_xft::load (const rxvt_fontprop &prop) 1104rxvt_font_xft::load (const rxvt_fontprop &prop)
1047{ 1105{
1106 dTermDisplay;
1107
1048 clear (); 1108 clear ();
1049 1109
1050 FcPattern *p = FcNameParse ((FcChar8 *) name); 1110 FcPattern *p = FcNameParse ((FcChar8 *) name);
1051 1111
1052 if (!p) 1112 if (!p)
1053 return false; 1113 return false;
1054 1114
1055 FcValue v; 1115 FcValue v;
1056 1116
1057 if (prop.height != rxvt_fontprop::unset 1117 if (prop.height != rxvt_fontprop::unset
1058 || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch 1118 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch
1059 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) 1119 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch))
1060 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); 1120 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
1061 1121
1062 if (prop.weight != rxvt_fontprop::unset 1122 if (prop.weight != rxvt_fontprop::unset
1063 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 1123 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
1078 1138
1079 // store generated name so iso14755 view gives better results 1139 // store generated name so iso14755 view gives better results
1080 set_name ((char *)FcNameUnparse (p)); 1140 set_name ((char *)FcNameUnparse (p));
1081 1141
1082 XftResult result; 1142 XftResult result;
1083 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 1143 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1084 1144
1085 FcPatternDestroy (p); 1145 FcPatternDestroy (p);
1086 1146
1087 if (!match) 1147 if (!match)
1088 return false; 1148 return false;
1090 int ftheight = 0; 1150 int ftheight = 0;
1091 bool success = true; 1151 bool success = true;
1092 1152
1093 for (;;) 1153 for (;;)
1094 { 1154 {
1095 f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); 1155 f = XftFontOpenPattern (disp, FcPatternDuplicate (match));
1096 1156
1097 if (!f) 1157 if (!f)
1098 { 1158 {
1099 success = false; 1159 success = false;
1100 break; 1160 break;
1109 1169
1110 bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; 1170 bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE;
1111 1171
1112 XftUnlockFace (f); 1172 XftUnlockFace (f);
1113 1173
1174 int glheight = height;
1175
1114 for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) 1176 for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; )
1115 { 1177 {
1116 FcChar16 ch = *t; 1178 FcChar16 ch = *t;
1117 1179
1118 if (cs != CS_UNICODE 1180 if (cs != CS_UNICODE
1124 bool careful; 1186 bool careful;
1125 if (!has_char (*t, &prop, careful)) 1187 if (!has_char (*t, &prop, careful))
1126 continue; 1188 continue;
1127 1189
1128 XGlyphInfo g; 1190 XGlyphInfo g;
1129 XftTextExtents16 (DISPLAY, f, &ch, 1, &g); 1191 XftTextExtents16 (disp, f, &ch, 1, &g);
1192
1193 g.width -= g.x;
1130 1194
1131 int wcw = wcwidth (ch); 1195 int wcw = wcwidth (ch);
1132 if (wcw > 0) g.width = g.width / wcw; 1196 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
1133 1197
1134 if (width < g.width) width = g.width; 1198 if (width < g.width ) width = g.width;
1135 if (height < g.height) height = g.height; 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;
1136 } 1212 }
1137 1213
1138 if (prop.height == rxvt_fontprop::unset 1214 if (prop.height == rxvt_fontprop::unset
1139 || height <= prop.height 1215 || (height <= prop.height && glheight <= prop.height)
1140 || height <= 2 1216 || height <= 2
1141 || !scalable) 1217 || !scalable)
1142 break; 1218 break;
1143 1219
1144 if (ftheight) 1220 if (ftheight)
1151 ftheight -= height - prop.height; 1227 ftheight -= height - prop.height;
1152 } 1228 }
1153 else 1229 else
1154 ftheight = prop.height - 1; 1230 ftheight = prop.height - 1;
1155 1231
1156 XftFontClose (DISPLAY, f); 1232 XftFontClose (disp, f);
1157 FcPatternDel (match, FC_PIXEL_SIZE); 1233 FcPatternDel (match, FC_PIXEL_SIZE);
1158 FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); 1234 FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight);
1159 } 1235 }
1160 1236
1161 FcPatternDestroy (match); 1237 FcPatternDestroy (match);
1162 1238
1163#if 0 // do it per-character 1239#if 0 // do it per-character
1170 1246
1171 return success; 1247 return success;
1172} 1248}
1173 1249
1174bool 1250bool
1175rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 1251rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1176{ 1252{
1177 careful = false; 1253 careful = false;
1178 1254
1179 if (!XftCharExists (DISPLAY, f, unicode)) 1255 if (!XftCharExists (term->display->display, f, unicode))
1180 return false; 1256 return false;
1181 1257
1182 if (!prop || prop->width == rxvt_fontprop::unset) 1258 if (!prop || prop->width == rxvt_fontprop::unset)
1183 return true; 1259 return true;
1184 1260
1185 // check character against base font bounding box 1261 // check character against base font bounding box
1186 FcChar32 ch = unicode; 1262 FcChar32 ch = unicode;
1187 XGlyphInfo g; 1263 XGlyphInfo g;
1188 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1264 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1189 1265
1190 int w = g.width; 1266 int w = g.width - g.x;
1191 int wcw = wcwidth (unicode); 1267 int wcw = wcwidth (unicode);
1192 if (wcw > 0) w /= wcw; 1268 if (wcw > 0) w = (w + wcw - 1) / wcw;
1193 1269
1194 careful = w > prop->width; 1270 careful = w > prop->width;
1195 if (careful && w > prop->width * MAX_OVERLAP >> 2) 1271 if (careful && w > prop->width * MAX_OVERLAP >> 2)
1196 return false; 1272 return false;
1197 1273
1201void 1277void
1202rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1278rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1203 const text_t *text, int len, 1279 const text_t *text, int len,
1204 int fg, int bg) 1280 int fg, int bg)
1205{ 1281{
1206 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);
1207
1208 int base = ascent; // should be fbase, but that is incorrect
1209 1283
1210 XGlyphInfo extents; 1284 XGlyphInfo extents;
1211 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); 1285 XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec));
1212 FcChar32 *ep = enc; 1286 XftGlyphSpec *ep = enc;
1213 int ewidth = 0; 1287
1214 int xoff = 0; 1288 dTermDisplay;
1289 dTermGC;
1290
1291 // cut trailing spaces
1292 while (len && text [len - 1] == ' ')
1293 len--;
1215 1294
1216 while (len) 1295 while (len)
1217 { 1296 {
1218 int cwidth = r->TermWin.fwidth; 1297 int cwidth = term->fwidth;
1219 FcChar32 fc = *text++; len--; 1298 FcChar32 fc = *text++; len--;
1220 FT_UInt gl;
1221 1299
1222 while (len && *text == NOCHAR) 1300 while (len && *text == NOCHAR)
1223 text++, len--, cwidth += r->TermWin.fwidth; 1301 text++, len--, cwidth += term->fwidth;
1224 1302
1225 gl = XftCharIndex (d.display->display, f, fc); 1303 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 } 1304 {
1305 FT_UInt glyph = XftCharIndex (disp, f, fc);
1306 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1240 1307
1241 if (fc == ' ' && ep == enc) // skip leading spaces 1308 ep->glyph = glyph;
1309 ep->x = x + (cwidth - extents.xOff >> 1);
1310 ep->y = y + ascent;
1311 ep++;
1242 { 1312 }
1313
1243 x += cwidth; 1314 x += cwidth;
1244 continue;
1245 }
1246
1247 else
1248 {
1249 *ep++ = gl;
1250 ewidth += cwidth;
1251 xoff += extents.xOff;
1252 }
1253 } 1315 }
1254 1316
1255 if (ep != enc) 1317 if (ep != enc)
1256 {
1257 if (xoff > ewidth) xoff = ewidth;
1258 XftDrawGlyphs (d, &r->pix_colors[fg].c, f, 1318 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1259 x + (ewidth - xoff >> 1),
1260 y + base, enc, ep - enc);
1261 }
1262} 1319}
1263#endif 1320#endif
1264 1321
1265///////////////////////////////////////////////////////////////////////////// 1322/////////////////////////////////////////////////////////////////////////////
1266 1323
1267rxvt_fontset::rxvt_fontset (rxvt_t r) 1324rxvt_fontset::rxvt_fontset (rxvt_term *term)
1268: r (r), fontdesc (0) 1325: fontdesc (0), term (term)
1269{ 1326{
1270 clear (); 1327 clear ();
1271} 1328}
1272 1329
1273rxvt_fontset::~rxvt_fontset () 1330rxvt_fontset::~rxvt_fontset ()
1276} 1333}
1277 1334
1278void 1335void
1279rxvt_fontset::clear () 1336rxvt_fontset::clear ()
1280{ 1337{
1281 prop.width = prop.height = prop.weight = prop.slant 1338 prop.width = prop.height = prop.ascent = prop.weight = prop.slant
1282 = rxvt_fontprop::unset; 1339 = rxvt_fontprop::unset;
1283 1340
1284 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1341 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1285 FONT_UNREF (*i); 1342 FONT_UNREF (*i);
1286 1343
1317 f = new rxvt_font_x11; 1374 f = new rxvt_font_x11;
1318 } 1375 }
1319 else 1376 else
1320 f = new rxvt_font_x11; 1377 f = new rxvt_font_x11;
1321 1378
1322 f->set_term (r); 1379 f->set_term (term);
1323 f->set_name (strdup (name)); 1380 f->set_name (strdup (name));
1324 1381
1325 f->cs = cs; 1382 f->cs = cs;
1326 f->loaded = false; 1383 f->loaded = false;
1327 1384
1338 char buf[512]; 1395 char buf[512];
1339 const char *end; 1396 const char *end;
1340 1397
1341 do 1398 do
1342 { 1399 {
1343 while (*desc <= ' ') desc++; 1400 while (*desc && *desc <= ' ')
1401 desc++;
1344 1402
1345 codeset cs = CS_UNICODE; 1403 codeset cs = CS_UNICODE;
1346 1404
1347 if (*desc == '[') 1405 if (*desc == '[')
1348 { 1406 {
1458 if (FROM_UNICODE (f->cs, unicode) == NOCHAR) 1516 if (FROM_UNICODE (f->cs, unicode) == NOCHAR)
1459 goto next_font; 1517 goto next_font;
1460 1518
1461 if (!realize_font (i)) 1519 if (!realize_font (i))
1462 goto next_font; 1520 goto next_font;
1521
1522 if (prop.ascent != rxvt_fontprop::unset)
1523 max_it (f->ascent, prop.ascent);
1463 } 1524 }
1464 1525
1465 if (f->cs == CS_UNKNOWN) 1526 if (f->cs == CS_UNKNOWN)
1466 goto next_font; 1527 goto next_font;
1467 1528
1506 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1567 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1507 FcPatternAddBool (p, FC_MINSPACE, 1); 1568 FcPatternAddBool (p, FC_MINSPACE, 1);
1508 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1569 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1509 1570
1510 XftResult result; 1571 XftResult result;
1511 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 1572 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1512 1573
1513 FcPatternDestroy (p); 1574 FcPatternDestroy (p);
1514 1575
1515 if (match) 1576 if (match)
1516 { 1577 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines