@@ -769,10 +769,17 @@ class UnicodeFonts(TruetypeFonts):
769769
770770 def __init__ (self , * args , ** kwargs ):
771771 # This must come first so the backend's owner is set correctly
772- if rcParams ['mathtext.fallback_to_cm' ]:
773- self .cm_fallback = BakomaFonts (* args , ** kwargs )
774- else :
775- self .cm_fallback = None
772+ fallback_rc = rcParams ['mathtext.fallback' ]
773+ if rcParams ['mathtext.fallback_to_cm' ] is not None :
774+ fallback_rc = ('cm' if rcParams ['mathtext.fallback_to_cm' ]
775+ else None )
776+
777+ font_class = {'stix' : StixFonts ,
778+ 'stixsans' : StixSansFonts ,
779+ 'cm' : BakomaFonts
780+ }.get (fallback_rc )
781+ self .cm_fallback = font_class (* args , ** kwargs ) if font_class else None
782+
776783 TruetypeFonts .__init__ (self , * args , ** kwargs )
777784 self .fontmap = {}
778785 for texfont in "cal rm tt it bf sf" .split ():
@@ -783,6 +790,21 @@ def __init__(self, *args, **kwargs):
783790 font = findfont (prop )
784791 self .fontmap ['ex' ] = font
785792
793+ # include STIX sized alternatives for glyphs if fallback is STIX
794+ if isinstance (self .cm_fallback , StixFonts ):
795+ stixsizedaltfonts = {
796+ 0 : 'STIXGeneral' ,
797+ 1 : 'STIXSizeOneSym' ,
798+ 2 : 'STIXSizeTwoSym' ,
799+ 3 : 'STIXSizeThreeSym' ,
800+ 4 : 'STIXSizeFourSym' ,
801+ 5 : 'STIXSizeFiveSym' }
802+
803+ for size , name in stixsizedaltfonts .items ():
804+ fullpath = findfont (name )
805+ self .fontmap [size ] = fullpath
806+ self .fontmap [name ] = fullpath
807+
786808 _slanted_symbols = set (r"\int \oint" .split ())
787809
788810 def _map_virtual_font (self , fontname , font_class , uniindex ):
@@ -830,16 +852,19 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
830852
831853 if not found_symbol :
832854 if self .cm_fallback :
833- if isinstance (self .cm_fallback , BakomaFonts ):
834- _log .warning (
835- "Substituting with a symbol from Computer Modern." )
836- if (fontname in ('it' , 'regular' ) and
837- isinstance (self .cm_fallback , StixFonts )):
838- return self .cm_fallback ._get_glyph (
839- 'rm' , font_class , sym , fontsize )
840- else :
841- return self .cm_fallback ._get_glyph (
842- fontname , font_class , sym , fontsize )
855+ if (fontname in ('it' , 'regular' )
856+ and isinstance (self .cm_fallback , StixFonts )):
857+ fontname = 'rm'
858+
859+ g = self .cm_fallback ._get_glyph (fontname , font_class ,
860+ sym , fontsize )
861+ fname = g [0 ].family_name
862+ if fname in list (BakomaFonts ._fontmap .values ()):
863+ fname = "Computer Modern"
864+ _log .warning ("Substituting symbol {} "
865+ "from {}" .format (sym , fname ))
866+ return g
867+
843868 else :
844869 if (fontname in ('it' , 'regular' )
845870 and isinstance (self , StixFonts )):
0 commit comments