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

Skip to content

Commit 16cc4f1

Browse files
committed
First pass at getting STIX fonts to work.
Support .otf fonts in font_manager.py svn path=/trunk/matplotlib/; revision=4107
1 parent feaf6d6 commit 16cc4f1

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

lib/matplotlib/_mathtext_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@
18851885
'measeq': 8798,
18861886
'upharpoonleft': 8639,
18871887
'lq': 8216,
1888-
'Upsilon': 978,
1888+
'Upsilon': 933,
18891889
'subsetneq': 8842,
18901890
'greater': 62,
18911891
'supsetneq': 8843,
@@ -2238,7 +2238,7 @@
22382238
'combiningbreve' : 774,
22392239
'combiningoverline' : 772,
22402240
'combininggraveaccent' : 768,
2241-
'combiningacuteaccent' : 714,
2241+
'combiningacuteaccent' : 769,
22422242
'combiningdiaeresis' : 776,
22432243
'combiningtilde' : 771,
22442244
'combiningrightarrowabove' : 8407,

lib/matplotlib/font_manager.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import os, sys, glob, shutil
3737
from sets import Set
3838
import matplotlib
39-
from matplotlib import afm
39+
from matplotlib import afm
4040
from matplotlib import ft2font
4141
from matplotlib import rcParams, get_home, get_configdir
4242
from matplotlib.cbook import is_string_like
@@ -95,6 +95,10 @@
9595
path = os.path.join(home, '.fonts')
9696
X11FontDirectories.append(path)
9797

98+
def get_fontext_synonyms(fontext):
99+
return {'ttf': ('ttf', 'otf'),
100+
'afm': ('afm',)}[fontext]
101+
98102
def win32FontDirectory():
99103
"""Return the user-specified font directory for Win32."""
100104

@@ -121,6 +125,8 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
121125
if directory is None:
122126
directory = win32FontDirectory()
123127

128+
fontext = get_fontext_synonyms(fontext)
129+
124130
key, items = None, {}
125131
for fontdir in MSFontDirectories:
126132
try:
@@ -129,15 +135,18 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
129135
continue
130136

131137
if not local:
132-
return glob.glob(os.path.join(directory, '*.'+fontext))
138+
files = []
139+
for ext in fontext:
140+
files.extend(glob.glob(os.path.join(directory, '*.'+ext)))
141+
return files
133142
try:
134143
for j in range(_winreg.QueryInfoKey(local)[1]):
135144
try:
136145
key, direc, any = _winreg.EnumValue( local, j)
137146
if not os.path.dirname(direc):
138147
direc = os.path.join(directory, direc)
139148
direc = os.path.abspath(direc).lower()
140-
if direc[-4:] == '.'+fontext:
149+
if os.path.splitext(direc)[1][1:] in fontext:
141150
items[direc] = 1
142151
except EnvironmentError:
143152
continue
@@ -168,13 +177,16 @@ def OSXInstalledFonts(directory=None, fontext=None):
168177
if directory is None:
169178
directory = OSXFontDirectory()
170179

180+
fontext = get_fontext_synonyms(fontext)
181+
171182
files = []
172183
for path in directory:
173184
if fontext is None:
174185
files.extend(glob.glob(os.path.join(path,'*')))
175186
else:
176-
files.extend(glob.glob(os.path.join(path, '*.'+fontext)))
177-
files.extend(glob.glob(os.path.join(path, '*.'+fontext.upper())))
187+
for ext in fontext:
188+
files.extend(glob.glob(os.path.join(path, '*.'+ext)))
189+
files.extend(glob.glob(os.path.join(path, '*.'+ext.upper())))
178190
return files
179191

180192

@@ -201,12 +213,14 @@ def get_fontconfig_fonts(fontext='ttf'):
201213
except ImportError:
202214
return {}
203215

216+
fontext = get_fontext_synonyms(fontext)
217+
204218
fontfiles = {}
205219
status, output = commands.getstatusoutput("fc-list file")
206220
if status == 0:
207221
for line in output.split('\n'):
208222
fname = line.split(':')[0]
209-
if (os.path.splitext(fname)[1] == "." + fontext and
223+
if (os.path.splitext(fname)[1][1:] in fontext and
210224
os.path.exists(fname)):
211225
fontfiles[fname] = 1
212226

@@ -221,7 +235,8 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
221235
AFM fonts as an option.
222236
"""
223237
fontfiles = {}
224-
238+
fontexts = get_fontext_synonyms(fontext)
239+
225240
if fontpaths is None:
226241
if sys.platform == 'win32':
227242
fontdir = win32FontDirectory()
@@ -230,7 +245,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
230245
# now get all installed fonts directly...
231246
for f in win32InstalledFonts(fontdir):
232247
base, ext = os.path.splitext(f)
233-
if len(ext)>1 and ext[1:].lower()==fontext:
248+
if len(ext)>1 and ext[1:].lower() in fontexts:
234249
fontfiles[f] = 1
235250
else:
236251
fontpaths = x11FontDirectory()
@@ -246,8 +261,10 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
246261
fontpaths = [fontpaths]
247262

248263
for path in fontpaths:
249-
files = glob.glob(os.path.join(path, '*.'+fontext))
250-
files.extend(glob.glob(os.path.join(path, '*.'+fontext.upper())))
264+
files = []
265+
for ext in fontexts:
266+
files.extend(glob.glob(os.path.join(path, '*.'+ext)))
267+
files.extend(glob.glob(os.path.join(path, '*.'+ext.upper())))
251268
for fname in files:
252269
fontfiles[os.path.abspath(fname)] = 1
253270

@@ -1047,16 +1064,17 @@ def lookup_name(name):
10471064

10481065
def fc_match(pattern, fontext):
10491066
import commands
1067+
fontexts = get_fontext_synonyms(fontext)
10501068
ext = "." + fontext
10511069
status, output = commands.getstatusoutput('fc-match -sv "%s"' % pattern)
10521070
if status == 0:
10531071
for match in _fc_match_regex.finditer(output):
10541072
file = match.group(1)
1055-
if os.path.splitext(file)[1] == ext:
1073+
if os.path.splitext(file)[1][1:] in fontexts:
10561074
return file
10571075
return None
10581076

1059-
_fc_match_regex = re.compile(r'\sfile:\s+"(.*)"')
1077+
_fc_match_regex = re.compile(r'\sfile:\s+"([^"]*)"')
10601078
_fc_match_cache = {}
10611079

10621080
def findfont(prop, fontext='ttf'):

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ def _get_glyph(self, fontname, sym, fontsize):
814814
MathTextWarning)
815815
return self.cm_fallback._get_glyph(fontname, sym, fontsize)
816816
else:
817+
warn("Substituting with a dummy symbol.", MathTextWarning)
817818
new_fontname = fontname
818819
cached_font = self._get_font(fontname)
819820
uniindex = 0xA4 # currency character, for lack of anything better

0 commit comments

Comments
 (0)