Skip to content

API: convert string fontsize to points immediately #7007

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

Merged
merged 9 commits into from
Dec 12, 2016
Merged
Prev Previous commit
Next Next commit
STY: some whitespace cleanups
  • Loading branch information
tacaswell committed Dec 12, 2016
commit 98e9fb20623645ae414e875bc8ce4c88ce16eb57
24 changes: 16 additions & 8 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@
MSFolders = \
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'

MSFontDirectories = [

MSFontDirectories = [
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts',
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts']

X11FontDirectories = [

X11FontDirectories = [
# an old standard installation point
"/usr/X11R6/lib/X11/fonts/TTF/",
"/usr/X11/lib/X11/fonts",
Expand Down Expand Up @@ -156,6 +158,7 @@
path = os.path.join(home, '.fonts')
X11FontDirectories.append(path)


def get_fontext_synonyms(fontext):
"""
Return a list of file extensions extensions that are synonyms for
Expand All @@ -165,6 +168,7 @@ def get_fontext_synonyms(fontext):
'otf': ('ttf', 'otf'),
'afm': ('afm',)}[fontext]


def list_fonts(directory, extensions):
"""
Return a list of all fonts matching any of the extensions,
Expand All @@ -174,6 +178,7 @@ def list_fonts(directory, extensions):
for ext in extensions])
return cbook.listFiles(directory, pattern)


def win32FontDirectory():
"""
Return the user-specified font directory for Win32. This is
Expand All @@ -186,21 +191,22 @@ def win32FontDirectory():
try:
from six.moves import winreg
except ImportError:
pass # Fall through to default
pass # Fall through to default
else:
try:
user = winreg.OpenKey(winreg.HKEY_CURRENT_USER, MSFolders)
try:
try:
return winreg.QueryValueEx(user, 'Fonts')[0]
except OSError:
pass # Fall through to default
pass # Fall through to default
finally:
winreg.CloseKey(user)
except OSError:
pass # Fall through to default
pass # Fall through to default
return os.path.join(os.environ['WINDIR'], 'Fonts')


def win32InstalledFonts(directory=None, fontext='ttf'):
"""
Search for fonts in the specified font directory, or use the
Expand Down Expand Up @@ -246,6 +252,7 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
winreg.CloseKey(local)
return None


def OSXInstalledFonts(directories=None, fontext='ttf'):
"""
Get list of font files on OS X - ignores font suffix by default.
Expand Down Expand Up @@ -297,6 +304,7 @@ def get_fontconfig_fonts(fontext='ttf'):
if os.path.splitext(fname)[1][1:] in fontext]



def findSystemFonts(fontpaths=None, fontext='ttf'):
"""
Search for fonts in the specified font paths. If no paths are
Expand Down Expand Up @@ -338,6 +346,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):

return [fname for fname in fontfiles if os.path.exists(fname)]


def weight_as_number(weight):
"""
Return the weight property as a numeric value. String values
Expand Down Expand Up @@ -419,7 +428,6 @@ def ttfFontProperty(font):
else:
style = 'normal'


# Variants are: small-caps and normal (default)

# !!!! Untested
Expand Down Expand Up @@ -451,8 +459,8 @@ def ttfFontProperty(font):
# Relative stretches are: wider, narrower
# Child value is: inherit

if sfnt4.find('narrow') >= 0 or sfnt4.find('condensed') >= 0 or \
sfnt4.find('cond') >= 0:
if (sfnt4.find('narrow') >= 0 or sfnt4.find('condensed') >= 0 or
sfnt4.find('cond') >= 0):
stretch = 'condensed'
elif sfnt4.find('demi cond') >= 0:
stretch = 'semi-condensed'
Expand Down