當前位置: 首頁>>代碼示例>>Python>>正文


Python TTGlyphPen.addComponent方法代碼示例

本文整理匯總了Python中fontTools.pens.ttGlyphPen.TTGlyphPen.addComponent方法的典型用法代碼示例。如果您正苦於以下問題:Python TTGlyphPen.addComponent方法的具體用法?Python TTGlyphPen.addComponent怎麽用?Python TTGlyphPen.addComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fontTools.pens.ttGlyphPen.TTGlyphPen的用法示例。


在下文中一共展示了TTGlyphPen.addComponent方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_glyph_decomposes

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
    def test_glyph_decomposes(self):
        componentName = 'a'
        glyphSet = {}
        pen = TTGlyphPen(glyphSet)

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        glyphSet[componentName] = _TestGlyph(pen.glyph())

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        pen.addComponent(componentName, (1, 0, 0, 1, 2, 0))
        compositeGlyph = pen.glyph()

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        pen.moveTo((2, 0))
        pen.lineTo((2, 1))
        pen.lineTo((3, 0))
        pen.closePath()
        plainGlyph = pen.glyph()

        self.assertEqual(plainGlyph, compositeGlyph)
開發者ID:anthrotype,項目名稱:fonttools,代碼行數:31,代碼來源:ttGlyphPen_test.py

示例2: test_out_of_range_transform_decomposed

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
    def test_out_of_range_transform_decomposed(self):
        componentName = 'a'
        glyphSet = {}
        pen = TTGlyphPen(glyphSet)

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        glyphSet[componentName] = _TestGlyph(pen.glyph())

        pen.addComponent(componentName, (3, 0, 0, 2, 0, 0))
        pen.addComponent(componentName, (1, 0, 0, 1, -1, 2))
        pen.addComponent(componentName, (2, 0, 0, -3, 0, 0))
        compositeGlyph = pen.glyph()

        pen.moveTo((0, 0))
        pen.lineTo((0, 2))
        pen.lineTo((3, 0))
        pen.closePath()
        pen.moveTo((-1, 2))
        pen.lineTo((-1, 3))
        pen.lineTo((0, 2))
        pen.closePath()
        pen.moveTo((0, 0))
        pen.lineTo((0, -3))
        pen.lineTo((2, 0))
        pen.closePath()
        expectedGlyph = pen.glyph()

        self.assertEqual(expectedGlyph, compositeGlyph)
開發者ID:MrBrezina,項目名稱:fonttools,代碼行數:33,代碼來源:ttGlyphPen_test.py

示例3: test_trim_remove_hinting_composite_glyph

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
    def test_trim_remove_hinting_composite_glyph(self):
        glyphSet = {"dummy": TTGlyphPen(None).glyph()}

        pen = TTGlyphPen(glyphSet)
        pen.addComponent("dummy", (1, 0, 0, 1, 0, 0))
        composite = pen.glyph()
        p = ttProgram.Program()
        p.fromAssembly(['SVTCA[0]'])
        composite.program = p
        glyphSet["composite"] = composite

        glyfTable = newTable("glyf")
        glyfTable.glyphs = glyphSet
        glyfTable.glyphOrder = sorted(glyphSet)

        composite.compact(glyfTable)

        self.assertTrue(hasattr(composite, "data"))

        # remove hinting from the compacted composite glyph, without expanding it
        composite.trim(remove_hinting=True)

        # check that, after expanding the glyph, we have no instructions
        composite.expand(glyfTable)
        self.assertFalse(hasattr(composite, "program"))

        # now remove hinting from expanded composite glyph
        composite.program = p
        composite.trim(remove_hinting=True)

        # check we have no instructions
        self.assertFalse(hasattr(composite, "program"))

        composite.compact(glyfTable)
開發者ID:behdad,項目名稱:fonttools,代碼行數:36,代碼來源:_g_l_y_f_test.py

示例4: test_recursiveComponent

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
 def test_recursiveComponent(self):
     glyphSet = {}
     pen_dummy = TTGlyphPen(glyphSet)
     glyph_dummy = pen_dummy.glyph()
     glyphSet["A"] = glyph_dummy
     glyphSet["B"] = glyph_dummy
     pen_A = TTGlyphPen(glyphSet)
     pen_A.addComponent("B", (1, 0, 0, 1, 0, 0))
     pen_B = TTGlyphPen(glyphSet)
     pen_B.addComponent("A", (1, 0, 0, 1, 0, 0))
     glyph_A = pen_A.glyph()
     glyph_B = pen_B.glyph()
     glyphSet["A"] = glyph_A
     glyphSet["B"] = glyph_B
     with self.assertRaisesRegex(TTLibError, "glyph '.' contains a recursive component reference"):
         glyph_A.getCoordinates(glyphSet)
開發者ID:behdad,項目名稱:fonttools,代碼行數:18,代碼來源:_g_l_y_f_test.py

示例5: test_no_handle_overflowing_transform

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
    def test_no_handle_overflowing_transform(self):
        componentName = 'a'
        glyphSet = {}
        pen = TTGlyphPen(glyphSet, handleOverflowingTransforms=False)

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        baseGlyph = pen.glyph()
        glyphSet[componentName] = _TestGlyph(baseGlyph)

        pen.addComponent(componentName, (3, 0, 0, 1, 0, 0))
        compositeGlyph = pen.glyph()

        self.assertEqual(compositeGlyph.components[0].transform,
                         ((3, 0), (0, 1)))

        with self.assertRaises(struct.error):
            compositeGlyph.compile({'a': baseGlyph})
開發者ID:MrBrezina,項目名稱:fonttools,代碼行數:22,代碼來源:ttGlyphPen_test.py

示例6: makeGlyfBBox1

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
def makeGlyfBBox1(calcBBoxes=True, composite=False):
    font = getTTFont(sfntTTFSourcePath, recalcBBoxes=calcBBoxes)
    glyf = font["glyf"]
    hmtx = font["hmtx"]
    for name in ("bbox1", "bbox2"):
        pen = TTGlyphPen(None)
        if name == "bbox1":
            pen.moveTo((0, 0))
            pen.lineTo((0, 1000))
            pen.lineTo((1000, 1000))
            pen.lineTo((1000, 0))
            pen.closePath()
        else:
            pen.moveTo((0, 0))
            pen.qCurveTo((500, 750), (600, 500), (500, 250), (0, 0))
            pen.closePath()
        glyph = pen.glyph()
        if not calcBBoxes:
            glyph.recalcBounds(glyf)
            glyph.xMax -= 100
        glyf.glyphs[name] = glyph
        hmtx.metrics[name] = (0, 0)
        glyf.glyphOrder.append(name)

    if composite:
        name = "bbox3"
        pen = TTGlyphPen(glyf.glyphOrder)
        pen.addComponent("bbox1", [1, 0, 0, 1, 0, 0])
        pen.addComponent("bbox2", [1, 0, 0, 1, 1000, 0])
        glyph = pen.glyph()
        glyph.recalcBounds(glyf)
        glyf.glyphs[name] = glyph
        hmtx.metrics[name] = (0, 0)
        glyf.glyphOrder.append(name)

    tableData = getSFNTData(font)[0]
    font.close()
    del font
    header, directory, tableData = defaultSFNTTestData(tableData=tableData, flavor="TTF")
    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data
開發者ID:w3c,項目名稱:woff2-tests,代碼行數:43,代碼來源:AuthoringToolTestCaseGenerator.py

示例7: test_within_range_component_transform

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
    def test_within_range_component_transform(self):
        componentName = 'a'
        glyphSet = {}
        pen = TTGlyphPen(glyphSet)

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        glyphSet[componentName] = _TestGlyph(pen.glyph())

        pen.addComponent(componentName, (1.5, 0, 0, 1, 0, 0))
        pen.addComponent(componentName, (1, 0, 0, -1.5, 0, 0))
        compositeGlyph = pen.glyph()

        pen.addComponent(componentName, (1.5, 0, 0, 1, 0, 0))
        pen.addComponent(componentName, (1, 0, 0, -1.5, 0, 0))
        expectedGlyph = pen.glyph()

        self.assertEqual(expectedGlyph, compositeGlyph)
開發者ID:MrBrezina,項目名稱:fonttools,代碼行數:22,代碼來源:ttGlyphPen_test.py

示例8: test_clamp_to_almost_2_component_transform

# 需要導入模塊: from fontTools.pens.ttGlyphPen import TTGlyphPen [as 別名]
# 或者: from fontTools.pens.ttGlyphPen.TTGlyphPen import addComponent [as 別名]
    def test_clamp_to_almost_2_component_transform(self):
        componentName = 'a'
        glyphSet = {}
        pen = TTGlyphPen(glyphSet)

        pen.moveTo((0, 0))
        pen.lineTo((0, 1))
        pen.lineTo((1, 0))
        pen.closePath()
        glyphSet[componentName] = _TestGlyph(pen.glyph())

        pen.addComponent(componentName, (1.99999, 0, 0, 1, 0, 0))
        pen.addComponent(componentName, (1, 2, 0, 1, 0, 0))
        pen.addComponent(componentName, (1, 0, 2, 1, 0, 0))
        pen.addComponent(componentName, (1, 0, 0, 2, 0, 0))
        pen.addComponent(componentName, (-2, 0, 0, -2, 0, 0))
        compositeGlyph = pen.glyph()

        almost2 = MAX_F2DOT14  # 0b1.11111111111111
        pen.addComponent(componentName, (almost2, 0, 0, 1, 0, 0))
        pen.addComponent(componentName, (1, almost2, 0, 1, 0, 0))
        pen.addComponent(componentName, (1, 0, almost2, 1, 0, 0))
        pen.addComponent(componentName, (1, 0, 0, almost2, 0, 0))
        pen.addComponent(componentName, (-2, 0, 0, -2, 0, 0))
        expectedGlyph = pen.glyph()

        self.assertEqual(expectedGlyph, compositeGlyph)
開發者ID:MrBrezina,項目名稱:fonttools,代碼行數:29,代碼來源:ttGlyphPen_test.py


注:本文中的fontTools.pens.ttGlyphPen.TTGlyphPen.addComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。