1
1
"""
2
2
A module for finding, managing, and using fonts across platforms.
3
3
4
- This module provides a single `FontManager` instance that can
4
+ This module provides a single `FontManager` instance, ``fontManager``, that can
5
5
be shared across backends and platforms. The `findfont`
6
6
function returns the best TrueType (TTF) font file in the local or
7
7
system font path that matches the specified `FontProperties`
@@ -627,32 +627,33 @@ class FontProperties:
627
627
628
628
- family: A list of font names in decreasing order of priority.
629
629
The items may include a generic font family name, either
630
- 'sans-serif' (default) , 'serif', 'cursive', 'fantasy', or 'monospace'.
630
+ 'sans-serif', 'serif', 'cursive', 'fantasy', or 'monospace'.
631
631
In that case, the actual font to be used will be looked up
632
- from the associated rcParam.
632
+ from the associated rcParam. Default: :rc:`font.family`
633
633
634
- - style: Either 'normal' (default), 'italic' or 'oblique'.
634
+ - style: Either 'normal', 'italic' or 'oblique'.
635
+ Default: :rc:`font.style`
635
636
636
- - variant: Either 'normal' (default) or 'small-caps'.
637
+ - variant: Either 'normal' or 'small-caps'.
638
+ Default: :rc:`font.variant`
637
639
638
640
- stretch: A numeric value in the range 0-1000 or one of
639
641
'ultra-condensed', 'extra-condensed', 'condensed',
640
- 'semi-condensed', 'normal' (default) , 'semi-expanded', 'expanded',
641
- 'extra-expanded' or 'ultra-expanded'.
642
+ 'semi-condensed', 'normal', 'semi-expanded', 'expanded',
643
+ 'extra-expanded' or 'ultra-expanded'. Default: :rc:`font.stretch`
642
644
643
645
- weight: A numeric value in the range 0-1000 or one of
644
- 'ultralight', 'light', 'normal' (default) , 'regular', 'book', 'medium',
646
+ 'ultralight', 'light', 'normal', 'regular', 'book', 'medium',
645
647
'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy',
646
- 'extra bold', 'black'.
648
+ 'extra bold', 'black'. Default: :rc:`font.weight`
647
649
648
650
- size: Either an relative value of 'xx-small', 'x-small',
649
651
'small', 'medium', 'large', 'x-large', 'xx-large' or an
650
- absolute font size, e.g., 10 (default).
652
+ absolute font size, e.g., 10. Default: :rc:`font.size`
651
653
652
- - math_fontfamily: The family of fonts used to render math text; overrides
653
- :rc:`mathtext.fontset`. Supported values are the same as the ones
654
- supported by :rc:`mathtext.fontset`: 'dejavusans', 'dejavuserif', 'cm',
655
- 'stix', 'stixsans' and 'custom'.
654
+ - math_fontfamily: The family of fonts used to render math text.
655
+ Supported values are: 'dejavusans', 'dejavuserif', 'cm',
656
+ 'stix', 'stixsans' and 'custom'. Default: :rc:`mathtext.fontset`
656
657
657
658
Alternatively, a font may be specified using the absolute path to a font
658
659
file, by using the *fname* kwarg. However, in this case, it is typically
@@ -807,7 +808,7 @@ def set_family(self, family):
807
808
is CSS parlance), such as: 'serif', 'sans-serif', 'cursive',
808
809
'fantasy', or 'monospace', a real font name or a list of real
809
810
font names. Real font names are not supported when
810
- :rc:`text.usetex` is `True`.
811
+ :rc:`text.usetex` is `True`. Default: :rc:`font.family`
811
812
"""
812
813
if family is None :
813
814
family = rcParams ['font.family' ]
@@ -817,7 +818,11 @@ def set_family(self, family):
817
818
818
819
def set_style (self , style ):
819
820
"""
820
- Set the font style. Values are: 'normal', 'italic' or 'oblique'.
821
+ Set the font style.
822
+
823
+ Parameters
824
+ ----------
825
+ style : {'normal', 'italic', 'oblique'}, default: :rc:`font.style`
821
826
"""
822
827
if style is None :
823
828
style = rcParams ['font.style' ]
@@ -826,7 +831,11 @@ def set_style(self, style):
826
831
827
832
def set_variant (self , variant ):
828
833
"""
829
- Set the font variant. Values are: 'normal' or 'small-caps'.
834
+ Set the font variant.
835
+
836
+ Parameters
837
+ ----------
838
+ variant : {'normal', 'small-caps'}, default: :rc:`font.variant`
830
839
"""
831
840
if variant is None :
832
841
variant = rcParams ['font.variant' ]
@@ -835,10 +844,14 @@ def set_variant(self, variant):
835
844
836
845
def set_weight (self , weight ):
837
846
"""
838
- Set the font weight. May be either a numeric value in the
839
- range 0-1000 or one of 'ultralight', 'light', 'normal',
840
- 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold',
841
- 'demi', 'bold', 'heavy', 'extra bold', 'black'
847
+ Set the font weight.
848
+
849
+ Parameters
850
+ ----------
851
+ weight : int or {'ultralight', 'light', 'normal', 'regular', 'book', \
852
+ 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', \
853
+ 'extra bold', 'black'}, default: :rc:`font.weight`
854
+ If int, must be in the range 0-1000.
842
855
"""
843
856
if weight is None :
844
857
weight = rcParams ['font.weight' ]
@@ -853,10 +866,14 @@ def set_weight(self, weight):
853
866
854
867
def set_stretch (self , stretch ):
855
868
"""
856
- Set the font stretch or width. Options are: 'ultra-condensed',
857
- 'extra-condensed', 'condensed', 'semi-condensed', 'normal',
858
- 'semi-expanded', 'expanded', 'extra-expanded' or
859
- 'ultra-expanded', or a numeric value in the range 0-1000.
869
+ Set the font stretch or width.
870
+
871
+ Parameters
872
+ ----------
873
+ stretch : int or {'ultra-condensed', 'extra-condensed', 'condensed', \
874
+ 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', \
875
+ 'ultra-expanded'}, default: :rc:`font.stretch`
876
+ If int, must be in the range 0-1000.
860
877
"""
861
878
if stretch is None :
862
879
stretch = rcParams ['font.stretch' ]
@@ -871,9 +888,14 @@ def set_stretch(self, stretch):
871
888
872
889
def set_size (self , size ):
873
890
"""
874
- Set the font size. Either an relative value of 'xx-small',
875
- 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'
876
- or an absolute font size, e.g., 12.
891
+ Set the font size.
892
+
893
+ Parameters
894
+ ----------
895
+ size : float or {'xx-small', 'x-small', 'small', 'medium', \
896
+ 'large', 'x-large', 'xx-large'}, default: :rc:`font.size`
897
+ If float, the font size in points. The string values denote sizes
898
+ relative to the default font size.
877
899
"""
878
900
if size is None :
879
901
size = rcParams ['font.size' ]
@@ -1091,6 +1113,9 @@ def addfont(self, path):
1091
1113
----------
1092
1114
path : str or path-like
1093
1115
"""
1116
+ # Convert to string in case of a path as
1117
+ # afmFontProperty and FT2Font expect this
1118
+ path = os .fsdecode (path )
1094
1119
if Path (path ).suffix .lower () == ".afm" :
1095
1120
with open (path , "rb" ) as fh :
1096
1121
font = _afm .AFM (fh )
0 commit comments