3030from base64 import b64encode
3131import dataclasses
3232from functools import cache , lru_cache
33- import functools
3433from io import BytesIO
3534import json
3635import logging
@@ -695,57 +694,6 @@ def afmFontProperty(fontpath, font):
695694 return FontEntry (fontpath , 0 , name , style , variant , weight , stretch , size )
696695
697696
698- def _cleanup_fontproperties_init (init_method ):
699- """
700- A decorator to limit the call signature to a single positional argument
701- or alternatively only keyword arguments.
702-
703- We still accept but deprecate all other call signatures.
704-
705- When the deprecation expires we can switch the signature to::
706-
707- __init__(self, pattern=None, /, *, family=None, style=None, ...)
708-
709- plus a runtime check that pattern is not used alongside with the
710- keyword arguments. This results eventually in the two possible
711- call signatures::
712-
713- FontProperties(pattern)
714- FontProperties(family=..., size=..., ...)
715-
716- """
717- @functools .wraps (init_method )
718- def wrapper (self , * args , ** kwargs ):
719- # multiple args with at least some positional ones
720- if len (args ) > 1 or len (args ) == 1 and kwargs :
721- # Note: Both cases were previously handled as individual properties.
722- # Therefore, we do not mention the case of font properties here.
723- _api .warn_deprecated (
724- "3.10" ,
725- message = "Passing individual properties to FontProperties() "
726- "positionally was deprecated in Matplotlib %(since)s and "
727- "will be removed in %(removal)s. Please pass all properties "
728- "via keyword arguments."
729- )
730- # single non-string arg -> clearly a family not a pattern
731- if len (args ) == 1 and not kwargs and not cbook .is_scalar_or_string (args [0 ]):
732- # Case font-family list passed as single argument
733- _api .warn_deprecated (
734- "3.10" ,
735- message = "Passing family as positional argument to FontProperties() "
736- "was deprecated in Matplotlib %(since)s and will be removed "
737- "in %(removal)s. Please pass family names as keyword"
738- "argument."
739- )
740- # Note on single string arg:
741- # This has been interpreted as pattern so far. We are already raising if a
742- # non-pattern compatible family string was given. Therefore, we do not need
743- # to warn for this case.
744- return init_method (self , * args , ** kwargs )
745-
746- return wrapper
747-
748-
749697class FontProperties :
750698 """
751699 A class for storing and manipulating font properties.
@@ -814,11 +762,17 @@ class FontProperties:
814762 fontconfig.
815763 """
816764
817- @ _cleanup_fontproperties_init
818- def __init__ ( self , family = None , style = None , variant = None , weight = None ,
765+ def __init__ ( self , pattern = None , / , * ,
766+ family = None , style = None , variant = None , weight = None ,
819767 stretch = None , size = None ,
820768 fname = None , # if set, it's a hardcoded filename to use
821769 math_fontfamily = None ):
770+ if pattern is not None :
771+ if not (family is None and style is None and variant is None and
772+ weight is None and stretch is None and size is None and
773+ fname is None ):
774+ raise TypeError ("Passing both a fontconfig pattern and individual "
775+ "properties to FontProperties() is invalid" )
822776 self .set_family (family )
823777 self .set_style (style )
824778 self .set_variant (variant )
@@ -827,13 +781,10 @@ def __init__(self, family=None, style=None, variant=None, weight=None,
827781 self .set_file (fname )
828782 self .set_size (size )
829783 self .set_math_fontfamily (math_fontfamily )
830- # Treat family as a fontconfig pattern if it is the only parameter
831- # provided. Even in that case, call the other setters first to set
832- # attributes not specified by the pattern to the rcParams defaults.
833- if (isinstance (family , str )
834- and style is None and variant is None and weight is None
835- and stretch is None and size is None and fname is None ):
836- self .set_fontconfig_pattern (family )
784+ # Even in the case a fontconfig pattern is provided, call the other setters
785+ # first to set attributes not specified by the pattern to the rcParams defaults.
786+ if pattern is not None :
787+ self .set_fontconfig_pattern (pattern )
837788
838789 @classmethod
839790 def _from_any (cls , arg ):
0 commit comments