Get an `.ft2font.FT2Font` object given a list of file paths. Parameters ---------- font_filepaths : Iterable[str, bytes, os.PathLike, FontPath], \ str, bytes, os.PathLike, FontPath Relative or absolute paths to the font files to be used. If a single string, bytes,
(font_filepaths, hinting_factor=None)
| 1785 | |
| 1786 | @_api.delete_parameter('3.11', 'hinting_factor') |
| 1787 | def get_font(font_filepaths, hinting_factor=None): |
| 1788 | """ |
| 1789 | Get an `.ft2font.FT2Font` object given a list of file paths. |
| 1790 | |
| 1791 | Parameters |
| 1792 | ---------- |
| 1793 | font_filepaths : Iterable[str, bytes, os.PathLike, FontPath], \ |
| 1794 | str, bytes, os.PathLike, FontPath |
| 1795 | Relative or absolute paths to the font files to be used. |
| 1796 | |
| 1797 | If a single string, bytes, or `os.PathLike`, then it will be treated |
| 1798 | as a list with that entry only. |
| 1799 | |
| 1800 | If more than one filepath is passed, then the returned FT2Font object |
| 1801 | will fall back through the fonts, in the order given, to find a needed |
| 1802 | glyph. |
| 1803 | |
| 1804 | Returns |
| 1805 | ------- |
| 1806 | `.ft2font.FT2Font` |
| 1807 | |
| 1808 | """ |
| 1809 | match font_filepaths: |
| 1810 | case FontPath(path, index): |
| 1811 | paths = ((_cached_realpath(path), index), ) |
| 1812 | case str() | bytes() | os.PathLike() as path: |
| 1813 | paths = ((_cached_realpath(path), 0), ) |
| 1814 | case _: |
| 1815 | paths = tuple( |
| 1816 | (_cached_realpath(fname.path), fname.face_index) |
| 1817 | if isinstance(fname, FontPath) else (_cached_realpath(fname), 0) |
| 1818 | for fname in font_filepaths) |
| 1819 | |
| 1820 | font = _get_font( |
| 1821 | # must be a tuple to be cached |
| 1822 | paths, |
| 1823 | _kerning_factor=mpl.rcParams['text.kerning_factor'], |
| 1824 | # also key on the thread ID to prevent segfaults with multi-threading |
| 1825 | thread_id=threading.get_ident(), |
| 1826 | enable_last_resort=mpl.rcParams['font.enable_last_resort'], |
| 1827 | ) |
| 1828 | # Ensure the transform is always consistent. |
| 1829 | font._set_transform([[0x10000, 0], [0, 0x10000]], [0, 0]) |
| 1830 | return font |
| 1831 | |
| 1832 | |
| 1833 | def _load_fontmanager(*, try_read_cache=True): |
searching dependent graphs…