当前位置: 首页>>代码示例>>Python>>正文


Python fontmap.FontMap类代码示例

本文整理汇总了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)
开发者ID:bithium,项目名称:blockdiag,代码行数:28,代码来源:test_utils_fontmap.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:27,代码来源:test_utils_fontmap.py

示例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
开发者ID:aboyett,项目名称:blockdiag,代码行数:7,代码来源:bootstrap.py

示例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()
开发者ID:unreal666,项目名称:outwiker,代码行数:26,代码来源:diagramrender.py

示例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
开发者ID:blockdiag,项目名称:sphinxcontrib-nwdiag,代码行数:25,代码来源:rackdiag.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:8,代码来源:test_utils_fontmap.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:9,代码来源:test_utils_fontmap.py

示例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
开发者ID:sdpython,项目名称:pyensae,代码行数:10,代码来源:blockdiag_helper.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:11,代码来源:test_utils_fontmap.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:12,代码来源:test_utils_fontmap.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:12,代码来源:test_utils_fontmap.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:15,代码来源:test_utils_fontmap.py

示例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])
开发者ID:bithium,项目名称:blockdiag,代码行数:18,代码来源:test_utils_fontmap.py

示例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])
开发者ID:bithium,项目名称:blockdiag,代码行数:20,代码来源:test_utils_fontmap.py

示例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)
开发者ID:bithium,项目名称:blockdiag,代码行数:21,代码来源:test_utils_fontmap.py


注:本文中的blockdiag.utils.fontmap.FontMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。