本文整理汇总了Python中blockdiag.utils.fontmap.FontMap.find方法的典型用法代码示例。如果您正苦于以下问题:Python FontMap.find方法的具体用法?Python FontMap.find怎么用?Python FontMap.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blockdiag.utils.fontmap.FontMap
的用法示例。
在下文中一共展示了FontMap.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fontmap_switch_defaultfamily
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例2: test_fontmap_empty_config
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例3: create_fontmap
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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: test_fontmap_none_config
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例5: test_fontmap_with_nonexistence_fontpath
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例6: _create_fontmap
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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
示例7: test_fontmap_using_fontalias
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例8: test_fontmap_with_nodefault_fontentry
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例9: test_fontmap_with_capital_character
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例10: test_fontmap_duplicated_fontentry2
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例11: test_fontmap_duplicated_fontentry1
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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)
示例12: test_fontmap_by_file
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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])
示例13: test_fontmap_including_bom_by_file
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
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])
示例14: test_fontmap_normal_config
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
def test_fontmap_normal_config(self):
_config = u("[fontmap]\nsansserif: %s\nsansserif-bold: %s\n") % \
(self.fontpath[0], self.fontpath[1])
config = StringIO(_config)
fmap = FontMap(config)
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)
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)
element = FontElement('sansserif-bold', 11)
font4 = fmap.find(element)
self.assertEqual('sansserif-bold', font4.familyname)
self.assertEqual(self.fontpath[1], font4.path)
self.assertEqual(font1.size, font4.size)
element = FontElement(None, None)
font5 = fmap.find(element)
self.assertEqual(font1.familyname, font5.familyname)
self.assertEqual(font1.path, font5.path)
self.assertEqual(font1.size, font5.size)
element = object()
font6 = fmap.find(element)
self.assertEqual(font1.familyname, font6.familyname)
self.assertEqual(font1.path, font6.path)
self.assertEqual(font1.size, font6.size)
示例15: DiagramMetrics
# 需要导入模块: from blockdiag.utils.fontmap import FontMap [as 别名]
# 或者: from blockdiag.utils.fontmap.FontMap import find [as 别名]
class DiagramMetrics(object):
cellsize = cellsize
edge_layout = 'normal'
node_padding = 4
line_spacing = 2
shadow_offset = XY(3, 6)
page_margin = XY(0, 0)
page_padding = [0, 0, 0, 0]
node_width = cellsize * 16
node_height = cellsize * 5
span_width = cellsize * 8
span_height = cellsize * 5
def __init__(self, diagram, drawer=None, fontmap=None):
self.drawer = drawer
if diagram.node_width is not None:
self.node_width = diagram.node_width
if diagram.node_height is not None:
self.node_height = diagram.node_height
if diagram.span_width is not None:
self.span_width = diagram.span_width
if diagram.span_height is not None:
self.span_height = diagram.span_height
if fontmap is not None:
self.fontmap = fontmap
else:
self.fontmap = FontMap()
if diagram.page_padding is not None:
self.page_padding = diagram.page_padding
if diagram.edge_layout is not None:
self.edge_layout = diagram.edge_layout
# setup spreadsheet
sheet = self.spreadsheet = SpreadSheetMetrics(self)
nodes = [n for n in diagram.traverse_nodes() if n.drawable]
node_width = self.node_width
for x in range(diagram.colwidth):
widths = [n.width for n in nodes if n.xy.x == x]
if widths:
width = max(n or node_width for n in widths)
sheet.set_node_width(x, width)
node_height = self.node_height
for y in range(diagram.colheight):
heights = [n.height for n in nodes if n.xy.y == y]
if heights:
height = max(n or node_height for n in heights)
sheet.set_node_height(y, height)
@property
def original_metrics(self):
return self
def shift(self, x, y):
metrics = copy.copy(self)
metrics.spreadsheet = copy.copy(self.spreadsheet)
metrics.spreadsheet.metrics = metrics
metrics.page_margin = XY(x, y)
return metrics
def textsize(self, string, font=None, width=65535):
return self.drawer.textsize(string, font, maxwidth=width)
def node(self, node):
renderer = noderenderer.get(node.shape)
if hasattr(renderer, 'render'):
return renderer(node, self)
else:
return self.cell(node)
def cell(self, node, use_padding=True):
return self.spreadsheet.node(node, use_padding)
def group(self, group):
return self.spreadsheet.node(group, use_padding=False)
def edge(self, edge):
if self.edge_layout == 'flowchart':
if edge.node1.group.orientation == 'landscape':
return FlowchartLandscapeEdgeMetrics(edge, self)
else:
return FlowchartPortraitEdgeMetrics(edge, self)
else:
if edge.node1.group.orientation == 'landscape':
return LandscapeEdgeMetrics(edge, self)
else:
return PortraitEdgeMetrics(edge, self)
def font_for(self, element):
return self.fontmap.find(element)
#.........这里部分代码省略.........