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

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.48 by pcg, Tue Mar 16 11:07:44 2004 UTC vs.
Revision 1.49 by pcg, Mon Mar 22 15:15:04 2004 UTC

411 411
412 XFontStruct *f; 412 XFontStruct *f;
413 codeset cs; 413 codeset cs;
414 bool enc2b, encm; 414 bool enc2b, encm;
415 415
416 const char *get_property (XFontStruct *f, const char *property, const char *repl) const; 416 char *get_property (XFontStruct *f, const char *property, const char *repl) const;
417 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); 417 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
418 bool set_properties (rxvt_fontprop &p, XFontStruct *f); 418 bool set_properties (rxvt_fontprop &p, XFontStruct *f);
419 bool set_properties (rxvt_fontprop &p, const char *name); 419 bool set_properties (rxvt_fontprop &p, const char *name);
420}; 420};
421 421
422const char * 422char *
423rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 423rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
424{ 424{
425 unsigned long value; 425 unsigned long value;
426 426
427 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 427 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
428 return XGetAtomName (DISPLAY, value); 428 return XGetAtomName (DISPLAY, value);
429 else 429 else
430 return repl; 430 return rxvt_strdup (repl);
431} 431}
432 432
433rxvt_fontprop 433rxvt_fontprop
434rxvt_font_x11::properties () 434rxvt_font_x11::properties ()
435{ 435{
450} 450}
451 451
452bool 452bool
453rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 453rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
454{ 454{
455 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
456 const char *slant = get_property (f, "SLANT", "r");
457
458 unsigned long height; 455 unsigned long height;
459 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 456 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
460 return false; 457 return false;
461 458
462 unsigned long avgwidth; 459 unsigned long avgwidth;
463 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 460 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
464 avgwidth = 0; 461 avgwidth = 0;
465 462
463 char *weight = get_property (f, "WEIGHT_NAME", "medium");
464 char *slant = get_property (f, "SLANT", "r");
465
466 return set_properties (p, height, weight, slant, avgwidth); 466 set_properties (p, height, weight, slant, avgwidth);
467
468 free (weight);
469 free (slant);
470
471 return true;
467} 472}
468 473
469bool 474bool
470rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 475rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
471{ 476{
575 f = XLoadQueryFont (DISPLAY, name); 580 f = XLoadQueryFont (DISPLAY, name);
576 581
577 if (!f) 582 if (!f)
578 return false; 583 return false;
579 584
580 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 585 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
581 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 586 char *encoding = get_property (f, "CHARSET_ENCODING", 0);
582 587
583 if (registry && encoding) 588 if (registry && encoding)
584 { 589 {
585 char charset[64]; 590 char charset[64];
586 snprintf (charset, 64, "%s-%s", registry, encoding); 591 snprintf (charset, 64, "%s-%s", registry, encoding);
599 if (*charset++ == '-' && !--count) 604 if (*charset++ == '-' && !--count)
600 break; 605 break;
601 606
602 cs = codeset_from_name (charset); 607 cs = codeset_from_name (charset);
603 } 608 }
609
610 free (registry);
611 free (encoding);
604 612
605 if (cs == CS_UNICODE) 613 if (cs == CS_UNICODE)
606 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 614 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
607 615
608 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 616 encm = f->min_byte1 != 0 || f->max_byte1 != 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines