-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Add feature to fallback to stix font in mathtext #11644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
37020f8
3ae26b7
0791122
b95bf17
7a26f16
09f4e6d
0b5ee3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,7 +758,10 @@ class UnicodeFonts(TruetypeFonts): | |
|
||
def __init__(self, *args, **kwargs): | ||
# This must come first so the backend's owner is set correctly | ||
if rcParams['mathtext.fallback_to_cm']: | ||
if rcParams['mathtext.fallback'] == 'stix': | ||
self.cm_fallback = StixFonts(*args, **kwargs) | ||
elif (rcParams['mathtext.fallback'] == 'cm' or | ||
rcParams['mathtext.fallback_to_cm']): | ||
self.cm_fallback = BakomaFonts(*args, **kwargs) | ||
else: | ||
self.cm_fallback = None | ||
|
@@ -772,6 +775,21 @@ def __init__(self, *args, **kwargs): | |
font = findfont(prop) | ||
self.fontmap['ex'] = font | ||
|
||
# include STIZ sized alternatives for glyphs if fallback is STIX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. STIX? (typo) |
||
if isinstance(self.cm_fallback, StixFonts): | ||
stixsizedaltfonts = { | ||
0: 'STIXGeneral', | ||
1: 'STIXSizeOneSym', | ||
2: 'STIXSizeTwoSym', | ||
3: 'STIXSizeThreeSym', | ||
4: 'STIXSizeFourSym', | ||
5: 'STIXSizeFiveSym'} | ||
|
||
for size, name in stixsizedaltfonts.items(): | ||
fullpath = findfont(name) | ||
self.fontmap[size] = fullpath | ||
self.fontmap[name] = fullpath | ||
|
||
_slanted_symbols = set(r"\int \oint".split()) | ||
|
||
def _map_virtual_font(self, fontname, font_class, uniindex): | ||
|
@@ -825,13 +843,17 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True): | |
warnings.warn( | ||
"Substituting with a symbol from Computer Modern.", | ||
MathTextWarning) | ||
elif isinstance(self.cm_fallback, StixFonts): | ||
warnings.warn("Substituting with a symbol from STIX.", | ||
MathTextWarning) | ||
|
||
if (fontname in ('it', 'regular') and | ||
isinstance(self.cm_fallback, StixFonts)): | ||
return self.cm_fallback._get_glyph( | ||
'rm', font_class, sym, fontsize) | ||
else: | ||
return self.cm_fallback._get_glyph( | ||
fontname, font_class, sym, fontsize) | ||
fontname = 'rm' | ||
|
||
return self.cm_fallback._get_glyph( | ||
fontname, font_class, sym, fontsize) | ||
|
||
else: | ||
if (fontname in ('it', 'regular') | ||
and isinstance(self, StixFonts)): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,6 +446,20 @@ def validate_font_properties(s): | |
return s | ||
|
||
|
||
def validate_mathtext_fallback(s): | ||
fallback_fonts = ['cm', 'stix'] | ||
if s is None or s == 'None': | ||
return None | ||
|
||
if not isinstance(s, str): | ||
raise ValueError("Must be a string or None.") | ||
|
||
if s.lower() in fallback_fonts: | ||
return s | ||
|
||
raise ValueError("%s is not a valid fallback font name. Valid fallback " | ||
"font names are %s." % (s, ", ".join(fallback_fonts))) | ||
|
||
validate_fontset = ValidateInStrings( | ||
'fontset', | ||
['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom']) | ||
|
@@ -1117,6 +1131,7 @@ def _validate_linestyle(ls): | |
'mathtext.fontset': ['dejavusans', validate_fontset], | ||
'mathtext.default': ['it', validate_mathtext_default], | ||
'mathtext.fallback_to_cm': [True, validate_bool], | ||
'mathtext.fallback': [None, validate_mathtext_fallback], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs some documentation. In particular it seems Preferably, we would deprecate This needs to be in |
||
|
||
'image.aspect': ['equal', validate_aspect], # equal, auto, a number | ||
'image.interpolation': ['nearest', validate_string], | ||
|