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

Skip to content

Commit 414ffc8

Browse files
committed
Shorten RendererWx.get_wx_font.
1 parent 4b27b46 commit 414ffc8

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def write(self, msg):
6767
print("Stderr: %s\n\r" % msg)
6868

6969

70-
# the True dots per inch on the screen; should be display dependent
71-
# see
70+
# the True dots per inch on the screen; should be display dependent; see
7271
# http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5
7372
# for some info about screen dpi
7473
PIXELS_PER_INCH = 75
@@ -342,38 +341,19 @@ def get_gc(self):
342341
return self.gc
343342

344343
def get_wx_font(self, s, prop):
345-
"""
346-
Return a wx font. Cache instances in a font dictionary for
347-
efficiency
348-
"""
344+
"""Return a wx font. Cache font instances for efficiency."""
349345
DEBUG_MSG("get_wx_font()", 1, self)
350-
351346
key = hash(prop)
352-
fontprop = prop
353-
fontname = fontprop.get_name()
354-
355347
font = self.fontd.get(key)
356348
if font is not None:
357349
return font
358-
359-
# Allow use of platform independent and dependent font names
360-
wxFontname = self.fontnames.get(fontname, wx.ROMAN)
361-
wxFacename = '' # Empty => wxPython chooses based on wx_fontname
362-
363350
# Font colour is determined by the active wx.Pen
364351
# TODO: It may be wise to cache font information
365-
size = self.points_to_pixels(fontprop.get_size_in_points())
366-
367-
font = wx.Font(int(size + 0.5), # Size
368-
wxFontname, # 'Generic' name
369-
self.fontangles[fontprop.get_style()], # Angle
370-
self.fontweights[fontprop.get_weight()], # Weight
371-
False, # Underline
372-
wxFacename) # Platform font name
373-
374-
# cache the font and gc and return it
375-
self.fontd[key] = font
376-
352+
self.fontd[key] = font = wx.Font( # Cache the font and gc.
353+
pointSize=self.points_to_pixels(prop.get_size_in_points()),
354+
family=self.fontnames.get(prop.get_name(), wx.ROMAN),
355+
style=self.fontangles[prop.get_style()],
356+
weight=self.fontweights[prop.get_weight()])
377357
return font
378358

379359
def points_to_pixels(self, points):

0 commit comments

Comments
 (0)