Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40356df

Browse files
committed
Merge branch 'mathdefault'
svn path=/trunk/matplotlib/; revision=6702
1 parent 18b5208 commit 40356df

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

lib/matplotlib/config/mplconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class mathtext(TConfig):
168168
bf = T.Trait('serif:bold' , mplT.FontconfigPatternHandler())
169169
sf = T.Trait('sans' , mplT.FontconfigPatternHandler())
170170
fontset = T.Trait('cm', 'cm', 'stix', 'stixsans', 'custom')
171+
default = T.Trait(*("rm cal it tt sf bf default bb frak circled scr regular".split()))
171172
fallback_to_cm = T.true
172173

173174
class axes(TConfig):

lib/matplotlib/config/rcsetup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def validate_font_properties(s):
209209

210210
validate_fontset = ValidateInStrings('fontset', ['cm', 'stix', 'stixsans', 'custom'])
211211

212+
validate_mathtext_default = ValidateInStrings(
213+
'default', "rm cal it tt sf bf default bb frak circled scr regular".split())
214+
212215
validate_verbose = ValidateInStrings('verbose',[
213216
'silent', 'helpful', 'debug', 'debug-annoying',
214217
])
@@ -371,6 +374,7 @@ def __call__(self, s):
371374
'mathtext.bf' : ['serif:bold', validate_font_properties],
372375
'mathtext.sf' : ['sans\-serif', validate_font_properties],
373376
'mathtext.fontset' : ['cm', validate_fontset],
377+
'mathtext.default' : ['it', validate_mathtext_default],
374378
'mathtext.fallback_to_cm' : [True, validate_bool],
375379

376380
'image.aspect' : ['equal', validate_aspect], # equal, auto, a number

lib/matplotlib/mathtext.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def get_kern(self, font1, fontclass1, sym1, fontsize1,
403403
404404
*fontX*: one of the TeX font names::
405405
406-
tt, it, rm, cal, sf, bf or default (non-math)
406+
tt, it, rm, cal, sf, bf or default/regular (non-math)
407407
408408
*fontclassX*: TODO
409409
@@ -419,7 +419,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi):
419419
"""
420420
*font*: one of the TeX font names::
421421
422-
tt, it, rm, cal, sf, bf or default (non-math)
422+
tt, it, rm, cal, sf, bf or default/regular (non-math)
423423
424424
*font_class*: TODO
425425
@@ -543,6 +543,7 @@ def __init__(self, default_font_prop, mathtext_backend):
543543
filename = findfont(default_font_prop)
544544
default_font = self.CachedFont(FT2Font(str(filename)))
545545
self._fonts['default'] = default_font
546+
self._fonts['regular'] = default_font
546547

547548
def destroy(self):
548549
self.glyphd = None
@@ -616,7 +617,7 @@ def get_xheight(self, font, fontsize, dpi):
616617
pclt = cached_font.font.get_sfnt_table('pclt')
617618
if pclt is None:
618619
# Some fonts don't store the xHeight, so we do a poor man's xHeight
619-
metrics = self.get_metrics(font, 'it', 'x', fontsize, dpi)
620+
metrics = self.get_metrics(font, rcParams['mathtext.default'], 'x', fontsize, dpi)
620621
return metrics.iceberg
621622
xHeight = (pclt['xHeight'] / 64.0) * (fontsize / 12.0) * (dpi / 100.0)
622623
return xHeight
@@ -936,7 +937,7 @@ def _map_virtual_font(self, fontname, font_class, uniindex):
936937
elif not doing_sans_conversion:
937938
# This will generate a dummy character
938939
uniindex = 0x1
939-
fontname = 'it'
940+
fontname = rcParams['mathtext.default']
940941

941942
# Handle private use area glyphs
942943
if (fontname in ('it', 'rm', 'bf') and
@@ -1007,6 +1008,7 @@ def __init__(self, default_font_prop):
10071008
default_font.fname = filename
10081009

10091010
self.fonts['default'] = default_font
1011+
self.fonts['regular'] = default_font
10101012
self.pswriter = StringIO()
10111013

10121014
def _get_font(self, font):
@@ -2064,7 +2066,7 @@ class Parser(object):
20642066

20652067
_dropsub_symbols = set(r'''\int \oint'''.split())
20662068

2067-
_fontnames = set("rm cal it tt sf bf default bb frak circled scr".split())
2069+
_fontnames = set("rm cal it tt sf bf default bb frak circled scr regular".split())
20682070

20692071
_function_names = set("""
20702072
arccos csc ker min arcsin deg lg Pr arctan det lim sec arg dim
@@ -2294,7 +2296,7 @@ def copy(self):
22942296
def _get_font(self):
22952297
return self._font
22962298
def _set_font(self, name):
2297-
if name in ('it', 'rm', 'bf'):
2299+
if name in Parser._fontnames:
22982300
self.font_class = name
22992301
self._font = name
23002302
font = property(_get_font, _set_font)
@@ -2336,7 +2338,7 @@ def non_math(self, s, loc, toks):
23362338
hlist = Hlist(symbols)
23372339
# We're going into math now, so set font to 'it'
23382340
self.push_state()
2339-
self.get_state().font = 'it'
2341+
self.get_state().font = rcParams['mathtext.default']
23402342
return [hlist]
23412343

23422344
def _make_space(self, percentage):
@@ -2346,7 +2348,7 @@ def _make_space(self, percentage):
23462348
width = self._em_width_cache.get(key)
23472349
if width is None:
23482350
metrics = state.font_output.get_metrics(
2349-
state.font, 'it', 'm', state.fontsize, state.dpi)
2351+
state.font, rcParams['mathtext.default'], 'm', state.fontsize, state.dpi)
23502352
width = metrics.advance
23512353
self._em_width_cache[key] = width
23522354
return Kern(width * percentage)
@@ -2665,7 +2667,7 @@ def frac(self, s, loc, toks):
26652667
# Shift so the fraction line sits in the middle of the
26662668
# equals sign
26672669
metrics = state.font_output.get_metrics(
2668-
state.font, 'it', '=', state.fontsize, state.dpi)
2670+
state.font, rcParams['mathtext.default'], '=', state.fontsize, state.dpi)
26692671
shift = (cden.height -
26702672
((metrics.ymax + metrics.ymin) / 2 -
26712673
thickness * 3.0))

lib/matplotlib/rcsetup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def validate_font_properties(s):
233233

234234
validate_fontset = ValidateInStrings('fontset', ['cm', 'stix', 'stixsans', 'custom'])
235235

236+
validate_mathtext_default = ValidateInStrings(
237+
'default', "rm cal it tt sf bf default bb frak circled scr regular".split())
238+
236239
validate_verbose = ValidateInStrings('verbose',[
237240
'silent', 'helpful', 'debug', 'debug-annoying',
238241
])
@@ -397,6 +400,7 @@ def __call__(self, s):
397400
'mathtext.bf' : ['serif:bold', validate_font_properties],
398401
'mathtext.sf' : ['sans\-serif', validate_font_properties],
399402
'mathtext.fontset' : ['cm', validate_fontset],
403+
'mathtext.default' : ['it', validate_mathtext_default],
400404
'mathtext.fallback_to_cm' : [True, validate_bool],
401405

402406
'image.aspect' : ['equal', validate_aspect], # equal, auto, a number

matplotlibrc.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ numerix : %(numerix)s # numpy, Numeric or numarray
185185
# fonts when a symbol can not be found in one of
186186
# the custom math fonts.
187187

188+
#mathtext.default : it # The default font to use for math.
189+
# Can be any of the LaTeX font names, including
190+
# the special name "regular" for the same font
191+
# used in regular text.
192+
188193
### AXES
189194
# default face and edge color, default tick sizes,
190195
# default fontsizes for ticklabels, and so on. See

0 commit comments

Comments
 (0)