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


Python Font.newGlyph方法代码示例

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


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

示例1: test_glyph_dispatcher_new

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_glyph_dispatcher_new(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     self.assertEqual(contour.getParent(), glyph)
     self.assertEqual(contour.dispatcher, font.dispatcher)
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(component.getParent(), glyph)
     self.assertEqual(component.dispatcher, font.dispatcher)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(anchor.getParent(), glyph)
     self.assertEqual(anchor.dispatcher, font.dispatcher)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     self.assertEqual(guideline.getParent(), glyph)
     self.assertEqual(guideline.dispatcher, font.dispatcher)
开发者ID:anthrotype,项目名称:defcon,代码行数:28,代码来源:test_layer.py

示例2: compileDecompileCompareDumps

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
def compileDecompileCompareDumps(features, expectedDump):
    # make the font
    font = Font()
    font.info.unitsPerEm = 1000
    font.info.ascender = 750
    font.info.descender = -250
    font.info.xHeight = 500
    font.info.capHeight = 750
    font.info.familyName = "Test"
    font.info.styleName = "Regular"
    glyphNames = [i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
    for glyphName in glyphNames:
        font.newGlyph(glyphName)
        glyph = font[glyphName]
        glyph.unicode = AGL2UV.get(glyphName)
    font.features.text = features
    # compile to OTF
    handle, path = tempfile.mkstemp()
    compiler = OTFCompiler()
    errors = compiler.compile(font, path)["makeotf"]
    # extract the features
    try:
        tables = decompileBinaryToObject(path, compress=True)
    # print compiler errors
    except TTLibError:
        print errors
    # get rid of the temp file
    finally:
        os.remove(path)
    # dump
    writer = DumpWriter()
    tables["GSUB"].write(writer)
    dump = writer.dump()
    # compare
    compareDumps(expectedDump, dump)
开发者ID:anthrotype,项目名称:feaTools2,代码行数:37,代码来源:__init__.py

示例3: test_glyph_dispatcher_inserted

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_glyph_dispatcher_inserted(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     component = Component()
     glyph.appendComponent(component)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     sourceGlyph = glyph
     newFont = Font()
     insertedGlyph = newFont.insertGlyph(sourceGlyph)
     contour = insertedGlyph[0]
     self.assertTrue(contour.getParent(), insertedGlyph)
     self.assertTrue(contour.dispatcher, newFont.dispatcher)
     component = insertedGlyph.components[0]
     self.assertTrue(component.getParent(), insertedGlyph)
     self.assertTrue(component.dispatcher, newFont.dispatcher)
     anchor = insertedGlyph.anchors[0]
     self.assertTrue(anchor.getParent(), insertedGlyph)
     self.assertTrue(anchor.dispatcher, newFont.dispatcher)
     guideline = insertedGlyph.guidelines[0]
     self.assertTrue(guideline.getParent(), insertedGlyph)
     self.assertTrue(guideline.dispatcher, newFont.dispatcher)
开发者ID:anthrotype,项目名称:defcon,代码行数:35,代码来源:test_layer.py

示例4: testDummyFont

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [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

示例5: _makeTestFont

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
def _makeTestFont():
    from fontTools.agl import AGL2UV
    from defcon import Font
    font = Font()
    for name in "ABCD":
        font.newGlyph(name)
        font.newGlyph(name + ".alt1")
        font.newGlyph(name + ".alt2")
    for glyph in font:
        glyph.unicode = AGL2UV.get(glyph.name)
    return font
开发者ID:LettError,项目名称:ufo2svg,代码行数:13,代码来源:kerning.py

示例6: test_keys

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_keys(self):
     font = Font(getTestFontPath())
     self.assertEqual(sorted(font.keys()), ["A", "B", "C"])
     del font["A"]
     self.assertEqual(sorted(font.keys()), ["B", "C"])
     font.newGlyph("A")
     self.assertEqual(sorted(font.keys()), ["A", "B", "C"])
     font = Font()
     self.assertEqual(font.keys(), set())
     font.newGlyph("A")
     self.assertEqual(sorted(font.keys()), ["A"])
开发者ID:anthrotype,项目名称:defcon,代码行数:13,代码来源:test_font.py

示例7: test_markColor

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_markColor(self):
     from defcon.objects.font import Font
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     self.assertIsNone(glyph.markColor)
     glyph.markColor = "1,0,1,0"
     self.assertEqual(glyph.markColor, "1,0,1,0")
     glyph.markColor = "1,0,1,0"
     self.assertEqual(glyph.markColor, "1,0,1,0")
     glyph.markColor = None
     self.assertIsNone(glyph.markColor)
开发者ID:anthrotype,项目名称:defcon,代码行数:14,代码来源:test_glyph.py

示例8: test_newGlyph

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_newGlyph(self):
     font = Font(getTestFontPath())
     glyph = font.newGlyph("NewGlyphTest")
     self.assertEqual(glyph.name, "NewGlyphTest")
     self.assertTrue(glyph.dirty)
     self.assertTrue(font.dirty)
     self.assertEqual(sorted(font.keys()), ["A", "B", "C", "NewGlyphTest"])
开发者ID:anthrotype,项目名称:defcon,代码行数:9,代码来源:test_font.py

示例9: test_delitem

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_delitem(self):
     path = makeTestFontCopy()
     font = Font(path)
     del font["A"]
     self.assertTrue(font.dirty)
     font.newGlyph("NewGlyphTest")
     del font["NewGlyphTest"]
     self.assertEqual(sorted(font.keys()), ["B", "C"])
     self.assertEqual(len(font), 2)
     self.assertFalse("A" in font)
     font.save()
     fileNames = glob.glob(os.path.join(path, 'glyphs', '*.glif'))
     fileNames = [os.path.basename(fileName) for fileName in fileNames]
     self.assertEqual(sorted(fileNames), ["B_.glif", "C_.glif"])
     with self.assertRaises(KeyError):
         del font["NotInFont"]
开发者ID:typesupply,项目名称:defcon,代码行数:18,代码来源:test_font.py

示例10: test_add_classes

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_add_classes(self):
     ufo = Font()
     glyph = ufo.newGlyph('grave')
     glyph.appendAnchor(glyph.anchorClass(
         anchorDict={'name': '_top', 'x': 100, 'y': 200}))
     glyph = ufo.newGlyph('cedilla')
     glyph.appendAnchor(glyph.anchorClass(
         anchorDict={'name': '_bottom', 'x': 100, 'y': 0}))
     lines = []
     writer = MarkFeatureWriter(
         ufo, anchorList=(('bottom', '_bottom'),), mkmkAnchorList=(),
         ligaAnchorList=((('top_1', 'top_2'), '_top'),))
     writer._addClasses(lines, doMark=True, doMkmk=True)
     self.assertEqual(
         '\n'.join(lines).strip(),
         'markClass cedilla <anchor 100 0> @MC_bottom;\n\n'
         'markClass grave <anchor 100 200> @MC_top;')
开发者ID:moyogo,项目名称:ufo2ft,代码行数:19,代码来源:markFeatureWriter_test.py

示例11: test_bottomMargin_get

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_bottomMargin_get(self):
     font = Font(getTestFontPath())
     glyph = font["A"]
     self.assertEqual(glyph.bottomMargin, 0)
     glyph = font["B"]
     self.assertEqual(glyph.bottomMargin, 0)
     # empty glyph
     glyph = font.newGlyph("D")
     self.assertIsNone(glyph.bottomMargin)
开发者ID:anthrotype,项目名称:defcon,代码行数:11,代码来源:test_glyph.py

示例12: test_topMargin_get

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
 def test_topMargin_get(self):
     from defcon.test.testTools import getTestFontPath
     from defcon.objects.font import Font
     font = Font(getTestFontPath())
     glyph = font["A"]
     self.assertEqual(glyph.topMargin, -200)
     # empty glyph
     glyph = font.newGlyph("D")
     self.assertIsNone(glyph.topMargin)
开发者ID:anthrotype,项目名称:defcon,代码行数:11,代码来源:test_glyph.py

示例13: createRandomFont

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
def createRandomFont():
    from defcon import Font
    
    maxGlyphs = 1000
    maxContours = 10
    maxSegments = 10
    maxBox = 700
    drawCallbacks = [drawLineTo, drawCurveTo]
    f = Font()
    for i in range(maxGlyphs):
        name = "%s" %i
        f.newGlyph(name)
        g = f[name]
        g.width = maxBox
        pen = g.getPen()
        for c in range(maxContours):
            drawMoveTo(pen, maxBox)
            for s in range(maxSegments):            
                random.choice(drawCallbacks)(pen, maxBox)
            drawClosePath(pen)
    return f
开发者ID:SayCV,项目名称:tools-FDK,代码行数:23,代码来源:test.py

示例14: test_glyph_unicodes_changed

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
    def test_glyph_unicodes_changed(self):
        font = Font(getTestFontPath())
        glyph = font["A"]
        glyph.unicodes = [123, 456]
        self.assertEqual(font.unicodeData[123], ["A"])
        self.assertEqual(font.unicodeData[456], ["A"])
        self.assertEqual(font.unicodeData[66], ["B"])

        font = Font(getTestFontPath())
        glyph = font.newGlyph("test")
        glyph.unicodes = [65]
        self.assertEqual(font.unicodeData[65], ["test", "A"])
开发者ID:anthrotype,项目名称:defcon,代码行数:14,代码来源:test_font.py

示例15: test_decomposeComponent_nested_components

# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import newGlyph [as 别名]
    def test_decomposeComponent_nested_components(self):
        font = Font()
        font.newGlyph("baseGlyph")
        baseGlyph = font["baseGlyph"]
        pointPen = baseGlyph.getPointPen()
        pointPen.beginPath(identifier="contour1")
        pointPen.addPoint((0, 0), "move", identifier="point1")
        pointPen.addPoint((0, 100), "line")
        pointPen.addPoint((100, 100), "line")
        pointPen.addPoint((100, 0), "line")
        pointPen.addPoint((0, 0), "line")
        pointPen.endPath()

        font.newGlyph("referenceGlyph1")
        referenceGlyph1 = font["referenceGlyph1"]
        pointPen = referenceGlyph1.getPointPen()
        pointPen.addComponent("baseGlyph", (1, 0, 0, 1, 3, 6))
        font.newGlyph("referenceGlyph2")
        referenceGlyph2 = font["referenceGlyph2"]
        pointPen = referenceGlyph2.getPointPen()
        pointPen.addComponent("referenceGlyph1", (1, 0, 0, 1, 10, 20))
        referenceGlyph2.decomposeAllComponents()
        self.assertEqual(len(referenceGlyph2.components), 0)
        self.assertEqual(len(referenceGlyph1.components), 1)
        self.assertEqual(len(referenceGlyph2), 1)
        self.assertEqual(referenceGlyph2.bounds, (13, 26, 113, 126))
开发者ID:anthrotype,项目名称:defcon,代码行数:28,代码来源:test_glyph.py


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