A font handling class for the STIX fonts. In addition to what UnicodeFonts provides, this class: - supports "virtual fonts" which are complete alpha numeric character sets with different font styles at special Unicode code points, such as "Blackboard". - handles sized
| 783 | |
| 784 | |
| 785 | class StixFonts(UnicodeFonts): |
| 786 | """ |
| 787 | A font handling class for the STIX fonts. |
| 788 | |
| 789 | In addition to what UnicodeFonts provides, this class: |
| 790 | |
| 791 | - supports "virtual fonts" which are complete alpha numeric |
| 792 | character sets with different font styles at special Unicode |
| 793 | code points, such as "Blackboard". |
| 794 | |
| 795 | - handles sized alternative characters for the STIXSizeX fonts. |
| 796 | """ |
| 797 | _fontmap = { |
| 798 | 'rm': 'STIXGeneral', |
| 799 | 'it': 'STIXGeneral:italic', |
| 800 | 'bf': 'STIXGeneral:weight=bold', |
| 801 | 'bfit': 'STIXGeneral:italic:bold', |
| 802 | 'nonunirm': 'STIXNonUnicode', |
| 803 | 'nonuniit': 'STIXNonUnicode:italic', |
| 804 | 'nonunibf': 'STIXNonUnicode:weight=bold', |
| 805 | '0': 'STIXGeneral', |
| 806 | '1': 'STIXSizeOneSym', |
| 807 | '2': 'STIXSizeTwoSym', |
| 808 | '3': 'STIXSizeThreeSym', |
| 809 | '4': 'STIXSizeFourSym', |
| 810 | '5': 'STIXSizeFiveSym', |
| 811 | } |
| 812 | _fallback_font = None |
| 813 | _sans = False |
| 814 | |
| 815 | def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlags): |
| 816 | TruetypeFonts.__init__(self, default_font_prop, load_glyph_flags) |
| 817 | for key, name in self._fontmap.items(): |
| 818 | fullpath = findfont(name) |
| 819 | self.fontmap[key] = fullpath |
| 820 | self.fontmap[name] = fullpath |
| 821 | |
| 822 | def _map_virtual_font(self, fontname: str, font_class: str, |
| 823 | uniindex: CharacterCodeType) -> tuple[str, CharacterCodeType]: |
| 824 | # Handle these "fonts" that are actually embedded in |
| 825 | # other fonts. |
| 826 | font_mapping = stix_virtual_fonts.get(fontname) |
| 827 | if (self._sans and font_mapping is None |
| 828 | and fontname not in ('regular', 'default')): |
| 829 | font_mapping = stix_virtual_fonts['sf'] |
| 830 | doing_sans_conversion = True |
| 831 | else: |
| 832 | doing_sans_conversion = False |
| 833 | |
| 834 | if isinstance(font_mapping, dict): |
| 835 | try: |
| 836 | mapping = font_mapping[font_class] |
| 837 | except KeyError: |
| 838 | mapping = font_mapping['rm'] |
| 839 | elif isinstance(font_mapping, list): |
| 840 | mapping = font_mapping |
| 841 | else: |
| 842 | mapping = None |