… | |
… | |
306 | return false; |
306 | return false; |
307 | |
307 | |
308 | if (unicode <= 0x009f) |
308 | if (unicode <= 0x009f) |
309 | return true; |
309 | return true; |
310 | |
310 | |
|
|
311 | #ifdef BUILTIN_GLYPHS |
311 | if (unicode >= 0x2500 && unicode <= 0x259f && |
312 | if (unicode >= 0x2500 && unicode <= 0x259f && |
312 | !term->option (Opt_skipBuiltinGlyphs)) |
313 | !term->option (Opt_skipBuiltinGlyphs)) |
313 | return true; |
314 | return true; |
|
|
315 | #endif |
314 | |
316 | |
315 | if (IS_COMPOSE (unicode)) |
317 | if (IS_COMPOSE (unicode)) |
316 | return true; |
318 | return true; |
317 | |
319 | |
318 | switch (unicode) |
320 | switch (unicode) |
… | |
… | |
608 | return false; |
610 | return false; |
609 | } |
611 | } |
610 | |
612 | |
611 | // fix the size of scalable fonts |
613 | // fix the size of scalable fonts |
612 | static bool |
614 | static bool |
613 | replace_field (char *buf, const char *name, int index, const char old, const char *replace) |
615 | replace_field (char **ptr, const char *name, int index, const char old, const char *replace) |
614 | { |
616 | { |
615 | int slashes = 0; |
617 | int slashes = 0; |
616 | const char *field, *end; |
618 | const char *field, *end; |
617 | |
619 | |
618 | for (const char *c = name; *c; c++) |
620 | for (const char *c = name; *c; c++) |
… | |
… | |
628 | break; |
630 | break; |
629 | } |
631 | } |
630 | |
632 | |
631 | if (slashes >= 13 && (!old || *field == old)) |
633 | if (slashes >= 13 && (!old || *field == old)) |
632 | { |
634 | { |
633 | // TODO: check for overflow in font-name |
635 | size_t len = field - name; |
|
|
636 | *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1); |
634 | strncpy (buf, name, field - name); |
637 | strncpy (*ptr, name, len); |
635 | buf += field - name; |
|
|
636 | strcpy (buf, replace); |
638 | strcpy (*ptr + len, replace); |
637 | strcat (buf, end); |
639 | strcat (*ptr, end); |
638 | |
640 | |
639 | return true; |
641 | return true; |
640 | } |
642 | } |
641 | else |
643 | else |
642 | { |
644 | { |
643 | strcpy (buf, name); |
645 | *ptr = strdup (name); |
644 | |
646 | |
645 | return false; |
647 | return false; |
646 | } |
648 | } |
647 | } |
649 | } |
648 | |
650 | |
… | |
… | |
656 | char field_str[64]; // enough for 128 bits |
658 | char field_str[64]; // enough for 128 bits |
657 | |
659 | |
658 | // first morph the font if required |
660 | // first morph the font if required |
659 | if (force_prop) |
661 | if (force_prop) |
660 | { |
662 | { |
661 | char fname[1024]; |
663 | char *fname; |
662 | |
664 | |
663 | if (name[0] != '-') |
665 | if (name[0] != '-') |
664 | { |
666 | { |
665 | f = XLoadQueryFont (disp, name); |
667 | f = XLoadQueryFont (disp, name); |
666 | |
668 | |
… | |
… | |
678 | f = 0; |
680 | f = 0; |
679 | } |
681 | } |
680 | |
682 | |
681 | if (prop.weight != rxvt_fontprop::unset) |
683 | if (prop.weight != rxvt_fontprop::unset) |
682 | { |
684 | { |
683 | replace_field (fname, name, 2, 0, |
685 | replace_field (&fname, name, 2, 0, |
684 | prop.weight < rxvt_fontprop::bold |
686 | prop.weight < rxvt_fontprop::bold |
685 | ? "medium" : "bold"); |
687 | ? "medium" : "bold"); |
686 | set_name (strdup (fname)); |
688 | set_name (fname); |
687 | } |
689 | } |
688 | |
690 | |
689 | if (prop.slant != rxvt_fontprop::unset) |
691 | if (prop.slant != rxvt_fontprop::unset) |
690 | { |
692 | { |
691 | replace_field (fname, name, 3, 0, |
693 | replace_field (&fname, name, 3, 0, |
692 | prop.slant < rxvt_fontprop::italic |
694 | prop.slant < rxvt_fontprop::italic |
693 | ? "r" : "i"); // TODO: handle "o"blique, too |
695 | ? "r" : "i"); // TODO: handle "o"blique, too |
694 | set_name (strdup (fname)); |
696 | set_name (fname); |
695 | } |
697 | } |
696 | } |
698 | } |
697 | |
699 | |
698 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
700 | sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset |
699 | ? 0 : prop.height); |
701 | ? 0 : prop.height); |
… | |
… | |
724 | font_weight *fonts = new font_weight[count]; |
726 | font_weight *fonts = new font_weight[count]; |
725 | |
727 | |
726 | for (int i = 0; i < count; i++) |
728 | for (int i = 0; i < count; i++) |
727 | { |
729 | { |
728 | rxvt_fontprop p; |
730 | rxvt_fontprop p; |
729 | char fname[1024]; |
731 | char *fname; |
730 | |
732 | |
731 | int diff = 0; |
733 | int diff = 0; |
732 | |
734 | |
733 | if (replace_field (fname, list[i], 6, '0', field_str)) |
735 | if (replace_field (&fname, list[i], 6, '0', field_str)) |
734 | diff += 10; // slightly penalize scalable fonts |
736 | diff += 10; // slightly penalize scalable fonts |
|
|
737 | else |
|
|
738 | { |
|
|
739 | free (fname); |
735 | else if (replace_field (fname, list[i], 11, '0', "0")) |
740 | if (replace_field (&fname, list[i], 11, '0', "0")) |
736 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
741 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
|
|
742 | } |
737 | |
743 | |
738 | if (!set_properties (p, fname)) |
744 | if (!set_properties (p, fname)) |
739 | continue; |
745 | continue; |
740 | |
746 | |
741 | if (prop.height != rxvt_fontprop::unset |
747 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
745 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
751 | if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; |
746 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
752 | if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); |
747 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
753 | if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); |
748 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
754 | //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); |
749 | |
755 | |
750 | fonts[i].name = strdup (fname); |
756 | fonts[i].name = fname; |
751 | fonts[i].diff = diff; |
757 | fonts[i].diff = diff; |
752 | } |
758 | } |
753 | |
759 | |
754 | XFreeFontNames (list); |
760 | XFreeFontNames (list); |
755 | |
761 | |