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


Python defcon.Font方法代码示例

本文整理汇总了Python中defcon.Font方法的典型用法代码示例。如果您正苦于以下问题:Python defcon.Font方法的具体用法?Python defcon.Font怎么用?Python defcon.Font使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在defcon的用法示例。


在下文中一共展示了defcon.Font方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setUp(self):
            libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
            libFolder = os.path.join(libFolder, 'testFonts/')
            self.scalers = []
            self.loadedFonts = []
            self.glyphNames = ['H','I']
            for fontsFolder in ['two-axes','isotropic-anisotropic']:
                fonts = []
                fontsPath = os.path.join(libFolder, fontsFolder)
                os.chdir(fontsPath)
                for singleFontPath in glob.glob('*.ufo'):
                    font = Font(singleFontPath)
                    if 'Italic' not in font.info.styleName:
                        fonts.append(font)
                        self.loadedFonts.append(font)
                scaler = MutatorScaleEngine(fonts)
                self.scalers.append(scaler) 
开发者ID:loicsander,项目名称:Robofont-scripts,代码行数:19,代码来源:scaler.py

示例2: test_adding_master

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def test_adding_master(self):
            libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
            libFolder = os.path.join(libFolder, 'testFonts/')
            newFontPath = os.path.join(libFolder, 'isotropic-anisotropic/bold-mid-contrast.ufo')
            newFont = Font(newFontPath)
            scaler = self.scalers[0]
            scaler.addMaster(newFont)
            self.assertEqual(len(scaler), 5) 
开发者ID:loicsander,项目名称:Robofont-scripts,代码行数:10,代码来源:scaler.py

示例3: setUp

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setUp(self):
            self.glyphNames = ['H', 'Aacute', 'A', 'O', 'B']
            libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
            singleFontPath = u'testFonts/two-axes/regular-low-contrast.ufo'
            fontPath = os.path.join(libFolder, singleFontPath)
            font = Font(fontPath)
            self.smallFont = ScaleFont(font, (0.5, 0.4))
            self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4))
            self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4), stemsWithSlantedSection=True)
            self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4), vstem=100, stemsWithSlantedSection=True)
            self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4), vstem=120, hstem=140, stemsWithSlantedSection=True) 
开发者ID:loicsander,项目名称:Robofont-scripts,代码行数:13,代码来源:fonts.py

示例4: setUp

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setUp(self):
            libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
            singleFontPath = u'testFonts/isotropic-anisotropic/regular-mid-contrast.ufo'
            fontPath = os.path.join(libFolder, singleFontPath)
            self.font = Font(fontPath) 
开发者ID:loicsander,项目名称:Robofont-scripts,代码行数:7,代码来源:fontUtils.py

示例5: testDummyFont

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def testDummyFont():
    from defcon import Font
    font = Font()
    for i, glyphName in enumerate(("a", "grave", "f", "i", "agrave")):
        font.newGlyph(glyphName)
        testDummyGlyph(font[glyphName], i)
        font[glyphName].width = 60 + 10 * i
    return font 
开发者ID:typemytype,项目名称:GlyphConstruction,代码行数:10,代码来源:glyphConstruction.py

示例6: _font_to_quadratic

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def _font_to_quadratic(zipped_paths, **kwargs):
    input_path, output_path = zipped_paths
    ufo = defcon.Font(input_path)
    logger.info('Converting curves for %s', input_path)
    if font_to_quadratic(ufo, **kwargs):
        logger.info("Saving %s", output_path)
        ufo.save(output_path)
    else:
        _copytree(input_path, output_path) 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:11,代码来源:cli.py

示例7: test_single_input_no_output

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def test_single_input_no_output(self, test_paths):
        ufo_path = test_paths[0]

        self.run_main(ufo_path)

        font = defcon.Font(str(ufo_path))
        assert font.lib[CURVE_TYPE_LIB_KEY] == "quadratic" 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:9,代码来源:cli_test.py

示例8: fonts

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def fonts():
    return [Font(ufo) for ufo in TEST_UFOS] 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:4,代码来源:ufo_test.py

示例9: test_incompatible_fonts

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def test_incompatible_fonts(self):
        font1 = Font()
        font1.info.unitsPerEm = 1000
        glyph1 = font1.newGlyph("a")
        pen1 = glyph1.getPen()
        for operator, args in [("moveTo", ((0, 0),)),
                               ("lineTo", ((1, 1),)),
                               ("endPath", ())]:
            getattr(pen1, operator)(*args)

        font2 = Font()
        font2.info.unitsPerEm = 1000
        glyph2 = font2.newGlyph("a")
        pen2 = glyph2.getPen()
        for operator, args in [("moveTo", ((0, 0),)),
                               ("curveTo", ((1, 1), (2, 2), (3, 3))),
                               ("endPath", ())]:
            getattr(pen2, operator)(*args)

        with pytest.raises(IncompatibleFontsError) as excinfo:
            fonts_to_quadratic([font1, font2])
        assert excinfo.match("fonts contains incompatible glyphs: 'a'")

        assert hasattr(excinfo.value, "glyph_errors")
        error = excinfo.value.glyph_errors['a']
        assert isinstance(error, IncompatibleSegmentTypesError)
        assert error.segments == {1: ["line", "curve"]} 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:29,代码来源:ufo_test.py

示例10: setup_fonts_to_quadratic_defcon

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setup_fonts_to_quadratic_defcon():
    from defcon import Font
    return [[Font(os.path.join(DATADIR, 'RobotoSubset-Regular.ufo'))],
            MAX_ERR_EM] 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:6,代码来源:ufo_benchmark.py

示例11: buildStatic

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def buildStatic(self,
    ufo,             # input UFO as filename string or defcon.Font object
    outputFilename,  # output filename string
    cff=True,        # true = makes CFF outlines. false = makes TTF outlines.
    **kwargs,        # passed along to ufo2ft.compile*()
  ):
    if isinstance(ufo, str):
      ufo = Font(ufo)

    # update version to actual, real version. Must come after any call to setFontInfo.
    updateFontVersion(ufo, dummy=False, isVF=False)

    compilerOptions = dict(
      useProductionNames=True,
      inplace=True,  # avoid extra copy
      removeOverlaps=True,
      overlapsBackend='pathops', # use Skia's pathops
    )

    log.info("compiling %s -> %s (%s)", _LazyFontName(ufo), outputFilename,
             "OTF/CFF-2" if cff else "TTF")

    if cff:
      font = ufo2ft.compileOTF(ufo, **compilerOptions)
    else: # ttf
      font = ufo2ft.compileTTF(ufo, **compilerOptions)

    log.debug("writing %s", outputFilename)
    font.save(outputFilename) 
开发者ID:rsms,项目名称:inter,代码行数:31,代码来源:builder.py

示例12: _loadDesignspace

# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def _loadDesignspace(designspace):
    log.info("loading designspace sources")
    if isinstance(designspace, str):
      designspace = DesignSpaceDocument.fromfile(designspace)
    else:
      # copy that we can mess with
      designspace = DesignSpaceDocument.fromfile(designspace.path)

    masters = designspace.loadSourceFonts(opener=Font)
    # masters = [s.font for s in designspace.sources]  # list of UFO font objects

    # Update the default source's full name to not include style name
    defaultFont = designspace.default.font
    defaultFont.info.openTypeNameCompatibleFullName = defaultFont.info.familyName

    for ufo in masters:
      # update font version
      updateFontVersion(ufo, dummy=False, isVF=True)

    log.info("Preprocessing glyphs")
    # find glyphs subject to decomposition and/or overlap removal
    # TODO: Find out why this loop is SO DAMN SLOW. It might just be so that defcon is
    #       really slow when reading glyphs. Perhaps we can sidestep defcon and just
    #       read & parse the .glif files ourselves.
    glyphNamesToDecompose  = set()  # glyph names
    glyphsToRemoveOverlaps = set()  # glyph objects
    for ufo in masters:
      for g in ufo:
        if g.components and not composedGlyphIsTrivial(g):
          glyphNamesToDecompose.add(g.name)
        if 'removeoverlap' in findGlyphDirectives(g.note):
          if g.components and len(g.components) > 0:
            glyphNamesToDecompose.add(g.name)
          glyphsToRemoveOverlaps.add(g)

    # decompose
    if glyphNamesToDecompose:
      if log.isEnabledFor(logging.DEBUG):
        log.debug('Decomposing glyphs:\n  %s', "\n  ".join(glyphNamesToDecompose))
      elif log.isEnabledFor(logging.INFO):
        log.info('Decomposing %d glyphs', len(glyphNamesToDecompose))
      decomposeGlyphs(masters, glyphNamesToDecompose)

    # remove overlaps
    if glyphsToRemoveOverlaps:
      rmoverlapFilter = RemoveOverlapsFilter(backend='pathops')
      rmoverlapFilter.start()
      if log.isEnabledFor(logging.DEBUG):
        log.debug(
          'Removing overlaps in glyphs:\n  %s',
          "\n  ".join(set([g.name for g in glyphsToRemoveOverlaps])),
        )
      elif log.isEnabledFor(logging.INFO):
        log.info('Removing overlaps in %d glyphs', len(glyphsToRemoveOverlaps))
      for g in glyphsToRemoveOverlaps:
        rmoverlapFilter.filter(g)

    # handle control back to fontmake
    return designspace 
开发者ID:rsms,项目名称:inter,代码行数:61,代码来源:builder.py


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