本文整理汇总了Python中matplotlib.ft2font.FT2Font方法的典型用法代码示例。如果您正苦于以下问题:Python ft2font.FT2Font方法的具体用法?Python ft2font.FT2Font怎么用?Python ft2font.FT2Font使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ft2font
的用法示例。
在下文中一共展示了ft2font.FT2Font方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_name
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def get_name(self):
"""
Return the name of the font that best matches the font
properties.
"""
return ft2font.FT2Font(str(findfont(self))).family_name
示例2: _get_font_ttf
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font_ttf(self, prop):
key = hash(prop)
font = self.fontd.get(key)
if font is None:
fname = findfont(prop)
font = self.fontd.get(fname)
if font is None:
font = FT2Font(str(fname))
self.fontd[fname] = font
self.fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, 72.0)
return font
示例3: _get_font
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font(self, prop):
key = hash(prop)
font = self.fontd.get(key)
if font is None:
fname = findfont(prop)
font = self.fontd.get(fname)
if font is None:
font = FT2Font(str(fname))
self.fontd[fname] = font
self.fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, 72.0)
return font
示例4: _write_svgfonts
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _write_svgfonts(self):
if not rcParams['svg.fonttype'] == 'svgfont':
return
writer = self.writer
writer.start(u'defs')
for font_fname, chars in self._fonts.items():
font = FT2Font(font_fname)
font.set_size(72, 72)
sfnt = font.get_sfnt()
writer.start(u'font', id=sfnt[(1, 0, 0, 4)])
writer.element(
u'font-face',
attrib={
u'font-family': font.family_name,
u'font-style': font.style_name.lower(),
u'units-per-em': u'72',
u'bbox': u' '.join(unicode(x / 64.0) for x in font.bbox)})
for char in chars:
glyph = font.load_char(char, flags=LOAD_NO_HINTING)
verts, codes = font.get_path()
path = Path(verts, codes)
path_data = self._convert_path(path)
# name = font.get_glyph_name(char)
writer.element(
u'glyph',
d=path_data,
attrib={
# 'glyph-name': name,
u'unicode': unichr(char),
u'horiz-adv-x': unicode(glyph.linearHoriAdvance / 65536.0)})
writer.end(u'font')
writer.end(u'defs')
示例5: _get_font
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font(self, font):
if font in self.fontmap:
basename = self.fontmap[font]
else:
basename = font
cached_font = self._fonts.get(basename)
if cached_font is None:
font = FT2Font(str(basename))
cached_font = self.CachedFont(font)
self._fonts[basename] = cached_font
self._fonts[font.postscript_name] = cached_font
self._fonts[font.postscript_name.lower()] = cached_font
return cached_font
示例6: _get_font
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font(self, prop):
"""
find a ttf font.
"""
fname = font_manager.findfont(prop)
font = FT2Font(str(fname))
font.set_size(self.FONT_SCALE, self.DPI)
return font
示例7: get_name
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def get_name(self):
"""
Return the name of the font that best matches the font
properties.
"""
return ft2font.FT2Font(findfont(self)).family_name
示例8: _get_font_ttf
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font_ttf(self, prop):
key = hash(prop)
font = self.fontd.get(key)
if font is None:
fname = findfont(prop)
font = self.fontd.get(fname)
if font is None:
font = FT2Font(fname)
self.fontd[fname] = font
self.fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, 72.0)
return font
示例9: _get_font
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font(self, prop):
key = hash(prop)
font = self.fontd.get(key)
if font is None:
fname = findfont(prop)
font = self.fontd.get(fname)
if font is None:
font = FT2Font(fname)
self.fontd[fname] = font
self.fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, 72.0)
return font
示例10: _write_svgfonts
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _write_svgfonts(self):
if not rcParams['svg.fonttype'] == 'svgfont':
return
writer = self.writer
writer.start('defs')
for font_fname, chars in six.iteritems(self._fonts):
font = FT2Font(font_fname)
font.set_size(72, 72)
sfnt = font.get_sfnt()
writer.start('font', id=sfnt[(1, 0, 0, 4)])
writer.element(
'font-face',
attrib={
'font-family': font.family_name,
'font-style': font.style_name.lower(),
'units-per-em': '72',
'bbox': ' '.join(six.text_type(x / 64.0) for x in font.bbox)})
for char in chars:
glyph = font.load_char(char, flags=LOAD_NO_HINTING)
verts, codes = font.get_path()
path = Path(verts, codes)
path_data = self._convert_path(path)
# name = font.get_glyph_name(char)
writer.element(
'glyph',
d=path_data,
attrib={
# 'glyph-name': name,
'unicode': unichr(char),
'horiz-adv-x': six.text_type(glyph.linearHoriAdvance / 65536.0)})
writer.end('font')
writer.end('defs')
示例11: _get_font
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font(self, font):
if font in self.fontmap:
basename = self.fontmap[font]
else:
basename = font
cached_font = self._fonts.get(basename)
if cached_font is None and os.path.exists(basename):
font = FT2Font(basename)
cached_font = self.CachedFont(font)
self._fonts[basename] = cached_font
self._fonts[font.postscript_name] = cached_font
self._fonts[font.postscript_name.lower()] = cached_font
return cached_font
示例12: test_fontinfo
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def test_fontinfo():
import matplotlib.font_manager as font_manager
import matplotlib.ft2font as ft2font
fontpath = font_manager.findfont("Bitstream Vera Sans")
font = ft2font.FT2Font(fontpath)
table = font.get_sfnt_table("head")
assert table['version'] == (1, 0)
示例13: _get_font
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def _get_font(self, prop):
"""
find a ttf font.
"""
fname = font_manager.findfont(prop)
font = FT2Font(fname)
font.set_size(self.FONT_SCALE, self.DPI)
return font
示例14: test_fontinfo
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def test_fontinfo():
import matplotlib.font_manager as font_manager
import matplotlib.ft2font as ft2font
fontpath = font_manager.findfont("DejaVu Sans")
font = ft2font.FT2Font(fontpath)
table = font.get_sfnt_table("head")
assert table['version'] == (1, 0)
示例15: createFontList
# 需要导入模块: from matplotlib import ft2font [as 别名]
# 或者: from matplotlib.ft2font import FT2Font [as 别名]
def createFontList(fontfiles, fontext='ttf'):
"""
A function to create a font lookup list. The default is to create
a list of TrueType fonts. An AFM font list can optionally be
created.
"""
fontlist = []
# Add fonts from list of known font files.
seen = {}
for fpath in fontfiles:
verbose.report('createFontDict: %s' % (fpath), 'debug')
fname = os.path.split(fpath)[1]
if fname in seen: continue
else: seen[fname] = 1
if fontext == 'afm':
try:
fh = open(fpath, 'rb')
except:
verbose.report("Could not open font file %s" % fpath)
continue
try:
try:
font = afm.AFM(fh)
finally:
fh.close()
except RuntimeError:
verbose.report("Could not parse font file %s"%fpath)
continue
try:
prop = afmFontProperty(fpath, font)
except KeyError:
continue
else:
try:
font = ft2font.FT2Font(str(fpath))
except RuntimeError:
verbose.report("Could not open font file %s"%fpath)
continue
except UnicodeError:
verbose.report("Cannot handle unicode filenames")
#print >> sys.stderr, 'Bad file is', fpath
continue
try:
prop = ttfFontProperty(font)
except KeyError:
continue
fontlist.append(prop)
return fontlist