(font_filepaths, *, _kerning_factor, thread_id,
enable_last_resort)
| 1732 | |
| 1733 | @lru_cache(64) |
| 1734 | def _get_font(font_filepaths, *, _kerning_factor, thread_id, |
| 1735 | enable_last_resort): |
| 1736 | (first_fontpath, first_fontindex), *rest = font_filepaths |
| 1737 | fallback_list = [ |
| 1738 | ft2font.FT2Font(fpath, face_index=index, |
| 1739 | _kerning_factor=_kerning_factor) |
| 1740 | for fpath, index in rest |
| 1741 | ] |
| 1742 | last_resort_path = _cached_realpath( |
| 1743 | cbook._get_data_path('fonts', 'ttf', 'LastResortHE-Regular.ttf')) |
| 1744 | try: |
| 1745 | last_resort_index = font_filepaths.index((last_resort_path, 0)) |
| 1746 | except ValueError: |
| 1747 | last_resort_index = -1 |
| 1748 | # Add Last Resort font so we always have glyphs regardless of font, unless we're |
| 1749 | # already in the list. |
| 1750 | if enable_last_resort: |
| 1751 | fallback_list.append( |
| 1752 | ft2font.FT2Font(last_resort_path, |
| 1753 | _kerning_factor=_kerning_factor, |
| 1754 | _warn_if_used=True)) |
| 1755 | last_resort_index = len(fallback_list) |
| 1756 | font = ft2font.FT2Font( |
| 1757 | first_fontpath, face_index=first_fontindex, |
| 1758 | _fallback_list=fallback_list, |
| 1759 | _kerning_factor=_kerning_factor |
| 1760 | ) |
| 1761 | # Ensure we are using the right charmap for the Last Resort font; FreeType picks the |
| 1762 | # Unicode one by default, but this exists only for Windows, and is empty. |
| 1763 | if last_resort_index == 0: |
| 1764 | font.set_charmap(0) |
| 1765 | elif last_resort_index > 0: |
| 1766 | fallback_list[last_resort_index - 1].set_charmap(0) |
| 1767 | return font |
| 1768 | |
| 1769 | |
| 1770 | # FT2Font objects cannot be used across fork()s because they reference the same |
no test coverage detected
searching dependent graphs…