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