|
7 | 7 | system font path that matches the specified `FontProperties`
|
8 | 8 | instance. The `FontManager` also handles Adobe Font Metrics
|
9 | 9 | (AFM) font files for use by the PostScript backend.
|
| 10 | +The `FontManager.addfont` function adds a custom font from a file without |
| 11 | +installing it into your operating system. |
10 | 12 |
|
11 | 13 | The design is based on the `W3C Cascading Style Sheet, Level 1 (CSS1)
|
12 | 14 | font specification <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_.
|
@@ -980,6 +982,27 @@ class FontManager:
|
980 | 982 | method does a nearest neighbor search to find the font that most closely
|
981 | 983 | matches the specification. If no good enough match is found, the default
|
982 | 984 | font is returned.
|
| 985 | +
|
| 986 | + Fonts added with the `FontManager.addfont` method will not persist in the |
| 987 | + cache; therefore, `addfont` will need to be called every time Matplotlib is |
| 988 | + imported. This method should only be used if and when a font cannot be |
| 989 | + installed on your operating system by other means. |
| 990 | +
|
| 991 | + Notes |
| 992 | + ----- |
| 993 | + The `FontManager.addfont` method must be called on the global `FontManager` |
| 994 | + instance. |
| 995 | +
|
| 996 | + Example usage:: |
| 997 | +
|
| 998 | + import matplotlib.pyplot as plt |
| 999 | + from matplotlib import font_manager |
| 1000 | +
|
| 1001 | + font_dirs = ["/resources/fonts"] # The path to the custom font file. |
| 1002 | + font_files = font_manager.findSystemFonts(fontpaths=font_dirs) |
| 1003 | +
|
| 1004 | + for font_file in font_files: |
| 1005 | + font_manager.fontManager.addfont(font_file) |
983 | 1006 | """
|
984 | 1007 | # Increment this version number whenever the font cache data
|
985 | 1008 | # format or behavior has changed and requires an existing font
|
@@ -1030,6 +1053,12 @@ def addfont(self, path):
|
1030 | 1053 | Parameters
|
1031 | 1054 | ----------
|
1032 | 1055 | path : str or path-like
|
| 1056 | +
|
| 1057 | + Notes |
| 1058 | + ----- |
| 1059 | + This method is useful for adding a custom font without installing it in |
| 1060 | + your operating system. See the `FontManager` singleton instance for |
| 1061 | + usage and caveats about this function. |
1033 | 1062 | """
|
1034 | 1063 | # Convert to string in case of a path as
|
1035 | 1064 | # afmFontProperty and FT2Font expect this
|
|
0 commit comments