… | |
… | |
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 | |
422 | const char * |
422 | char * |
423 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
423 | rxvt_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 | |
433 | rxvt_fontprop |
433 | rxvt_fontprop |
434 | rxvt_font_x11::properties () |
434 | rxvt_font_x11::properties () |
435 | { |
435 | { |
… | |
… | |
450 | } |
450 | } |
451 | |
451 | |
452 | bool |
452 | bool |
453 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
453 | rxvt_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 | |
469 | bool |
474 | bool |
470 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
475 | rxvt_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; |