本文整理汇总了Python中blockdiag.utils.fontmap.FontMap类的典型用法代码示例。如果您正苦于以下问题:Python FontMap类的具体用法?Python FontMap怎么用?Python FontMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FontMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fontmap_empty_config
def test_fontmap_empty_config(self):
config = StringIO(u(""))
fmap = FontMap(config)
font1 = fmap.find()
self.assertTrue(font1)
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(None, font1.path)
self.assertEqual(11, font1.size)
element = FontElement('sansserif', 11)
font2 = fmap.find(element)
self.assertEqual(font1.familyname, font2.familyname)
self.assertEqual(font1.path, font2.path)
self.assertEqual(font1.size, font2.size)
element = FontElement('sansserif-normal', 11)
font3 = fmap.find(element)
self.assertEqual(font1.familyname, font3.familyname)
self.assertEqual(font1.path, font3.path)
self.assertEqual(font1.size, font3.size)
# non-registered familyname
element = FontElement('my-sansserif-normal', 11)
font4 = fmap.find(element)
self.assertEqual(font1.familyname, font4.familyname)
self.assertEqual(font1.path, font4.path)
self.assertEqual(font1.size, font4.size)
示例2: test_fontmap_switch_defaultfamily
def test_fontmap_switch_defaultfamily(self):
_config = u("[fontmap]\nserif-bold: %s\n") % self.fontpath[0]
config = StringIO(_config)
fmap = FontMap(config)
font1 = fmap.find()
self.assertEqual('sansserif-normal', font1.familyname)
self.assertEqual(None, font1.path)
self.assertEqual(11, font1.size)
fmap.set_default_fontfamily('serif-bold')
font2 = fmap.find()
self.assertEqual('serif-bold', font2.familyname)
self.assertEqual(self.fontpath[0], font2.path)
self.assertEqual(11, font2.size)
fmap.set_default_fontfamily('fantasy-italic')
font3 = fmap.find()
self.assertEqual('fantasy-italic', font3.familyname)
self.assertEqual(None, font3.path)
self.assertEqual(11, font3.size)
fmap.fontsize = 20
font4 = fmap.find()
self.assertEqual('fantasy-italic', font4.familyname)
self.assertEqual(None, font4.path)
self.assertEqual(20, font4.size)
示例3: create_fontmap
def create_fontmap(options):
fontmap = FontMap(options.fontmap)
if fontmap.find().path is None or options.font:
fontpath = detectfont(options)
fontmap.set_default_font(fontpath)
return fontmap
示例4: renderToFile
def renderToFile(self, content, imagePath):
"""
content - текст, описывающий диаграмму
imagePath - полный путь до создаваемого файла
"""
from blockdiag.parser import parse_string
from blockdiag.drawer import DiagramDraw
from blockdiag.builder import ScreenNodeBuilder
from blockdiag.utils.fontmap import FontMap
font = os.path.join(os.path.dirname(os.path.abspath(__file__)),
u"fonts",
self._fontDefault)
fontmap = FontMap()
fontmap.set_default_font(font)
text = u"blockdiag {{ {content} }}".format(content=content)
tree = parse_string(text)
diagram = ScreenNodeBuilder.build(tree)
draw = DiagramDraw("png", diagram, imagePath,
fontmap=fontmap, antialias=True)
draw.draw()
draw.save()
示例5: on_builder_inited
def on_builder_inited(self):
# show deprecated message
if self.builder.config.rackdiag_tex_image_format:
self.builder.warn('rackdiag_tex_image_format is deprecated. Use rackdiag_latex_image_format.')
# initialize fontmap
global fontmap
try:
fontmappath = self.builder.config.rackdiag_fontmap
fontmap = FontMap(fontmappath)
except:
fontmap = FontMap(None)
try:
fontpath = self.builder.config.rackdiag_fontpath
if isinstance(fontpath, string_types):
fontpath = [fontpath]
if fontpath:
config = namedtuple('Config', 'font')(fontpath)
fontpath = detectfont(config)
fontmap.set_default_font(fontpath)
except:
pass
示例6: test_fontmap_none_config
def test_fontmap_none_config(self):
fmap = FontMap()
font1 = fmap.find()
self.assertTrue(font1)
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(None, font1.path)
self.assertEqual(11, font1.size)
示例7: test_fontmap_with_nonexistence_fontpath
def test_fontmap_with_nonexistence_fontpath(self):
_config = u("[fontmap]\nserif: unknown_file\n")
config = StringIO(_config)
fmap = FontMap(config)
font1 = fmap.find()
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(None, font1.path)
self.assertEqual(11, font1.size)
示例8: _create_fontmap
def _create_fontmap(fontmap, font):
"""
Inspired from :epkg:`blockdiag` source file (*_bootstrap.py*).
"""
from blockdiag.utils.fontmap import FontMap
fontmap = FontMap(fontmap)
if fontmap.find().path is None or font:
fontpath = _detectfont(font)
fontmap.set_default_font(fontpath)
return fontmap
示例9: test_fontmap_using_fontalias
def test_fontmap_using_fontalias(self):
_config = (u("[fontmap]\nserif-bold: %s\n") +
u("[fontalias]\ntest = serif-bold\n")) % self.fontpath[0]
config = StringIO(_config)
fmap = FontMap(config)
element = FontElement('test', 20)
font1 = fmap.find(element)
self.assertEqual('serif-bold', font1.familyname)
self.assertEqual(self.fontpath[0], font1.path)
self.assertEqual(20, font1.size)
示例10: test_fontmap_with_capital_character
def test_fontmap_with_capital_character(self):
_config = u("[fontmap]\nCapitalCase-sansserif: %s\n") % \
self.fontpath[0]
config = StringIO(_config)
fmap = FontMap(config)
element = FontElement('CapitalCase-sansserif', 11)
font1 = fmap.find(element)
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual('capitalcase-sansserif-normal', font1.familyname)
self.assertEqual(self.fontpath[0], font1.path)
self.assertEqual(11, font1.size)
示例11: test_fontmap_duplicated_fontentry2
def test_fontmap_duplicated_fontentry2(self):
# this testcase is only for python2.6 or later
if sys.version_info > (2, 6):
_config = u("[fontmap]\nsansserif: %s\nsansserif-normal: %s\n") % \
(self.fontpath[0], self.fontpath[1])
config = StringIO(_config)
fmap = FontMap(config)
font1 = fmap.find()
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(self.fontpath[1], font1.path)
self.assertEqual(11, font1.size)
示例12: test_fontmap_duplicated_fontentry1
def test_fontmap_duplicated_fontentry1(self):
_config = u("[fontmap]\nsansserif: %s\nsansserif: %s\n") % \
(self.fontpath[0], self.fontpath[1])
config = StringIO(_config)
if sys.version_info[0] == 2:
fmap = FontMap(config)
font1 = fmap.find()
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(self.fontpath[1], font1.path)
self.assertEqual(11, font1.size)
else:
import configparser
with self.assertRaises(configparser.DuplicateOptionError):
FontMap(config)
示例13: test_fontmap_by_file
def test_fontmap_by_file(self):
tmp = tempfile.mkstemp()
_config = u("[fontmap]\nsansserif: %s\nsansserif-bold: %s\n") % \
(self.fontpath[0], self.fontpath[1])
fp = os.fdopen(tmp[0], 'wt')
fp.write(_config)
fp.close()
fmap = FontMap(tmp[1])
font1 = fmap.find()
self.assertTrue(font1)
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(self.fontpath[0], font1.path)
self.assertEqual(11, font1.size)
os.unlink(tmp[1])
示例14: test_fontmap_including_bom_by_file
def test_fontmap_including_bom_by_file(self):
tmp = tempfile.mkstemp()
_config = (u("[fontmap]\nsansserif: %s\n") +
u("sansserif-bold: %s\n")) % \
(self.fontpath[0], self.fontpath[1])
try:
fp = os.fdopen(tmp[0], 'wb')
fp.write(_config.encode('utf-8-sig'))
fp.close()
fmap = FontMap(tmp[1])
font1 = fmap.find()
self.assertTrue(font1)
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(self.fontpath[0], font1.path)
self.assertEqual(11, font1.size)
finally:
os.unlink(tmp[1])
示例15: test_fontmap_with_nodefault_fontentry
def test_fontmap_with_nodefault_fontentry(self):
_config = u("[fontmap]\nserif: %s\n") % self.fontpath[0]
config = StringIO(_config)
fmap = FontMap(config)
font1 = fmap.find()
self.assertEqual('sans-serif', font1.generic_family)
self.assertEqual(None, font1.path)
self.assertEqual(11, font1.size)
element = FontElement('serif', 11)
font2 = fmap.find(element)
self.assertEqual('serif', font2.generic_family)
self.assertEqual(self.fontpath[0], font2.path)
self.assertEqual(font1.size, font2.size)
element = FontElement('fantasy', 20)
font3 = fmap.find(element)
self.assertEqual('sans-serif', font3.generic_family)
self.assertEqual(None, font3.path)
self.assertEqual(20, font3.size)