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


Python ttLib.newTable方法代码示例

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


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

示例1: setupTable_hmtx

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def setupTable_hmtx(self):
        """
        Make the hmtx table.

        **This should not be called externally.** Subclasses
        may override or supplement this method to handle the
        table creation in a different way if desired.
        """
        if "hmtx" not in self.tables:
            return

        self.otf["hmtx"] = hmtx = newTable("hmtx")
        hmtx.metrics = {}
        for glyphName, glyph in self.allGlyphs.items():
            width = otRound(glyph.width)
            if width < 0:
                raise ValueError("The width should not be negative: '%s'" % (glyphName))
            bounds = self.glyphBoundingBoxes[glyphName]
            left = bounds.xMin if bounds else 0
            hmtx[glyphName] = (width, left) 
开发者ID:googlefonts,项目名称:ufo2ft,代码行数:22,代码来源:outlineCompiler.py

示例2: setupTable_vmtx

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def setupTable_vmtx(self):
        """
        Make the vmtx table.

        **This should not be called externally.** Subclasses
        may override or supplement this method to handle the
        table creation in a different way if desired.
        """
        if "vmtx" not in self.tables:
            return

        self.otf["vmtx"] = vmtx = newTable("vmtx")
        vmtx.metrics = {}
        for glyphName, glyph in self.allGlyphs.items():
            height = otRound(glyph.height)
            if height < 0:
                raise ValueError(
                    "The height should not be negative: '%s'" % (glyphName)
                )
            verticalOrigin = _getVerticalOrigin(self.otf, glyph)
            bounds = self.glyphBoundingBoxes[glyphName]
            top = bounds.yMax if bounds else 0
            vmtx[glyphName] = (height, verticalOrigin - top) 
开发者ID:googlefonts,项目名称:ufo2ft,代码行数:25,代码来源:outlineCompiler.py

示例3: setupTable_VORG

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def setupTable_VORG(self):
        """
        Make the VORG table.

        **This should not be called externally.** Subclasses
        may override or supplement this method to handle the
        table creation in a different way if desired.
        """
        if "VORG" not in self.tables:
            return

        self.otf["VORG"] = vorg = newTable("VORG")
        vorg.majorVersion = 1
        vorg.minorVersion = 0
        vorg.VOriginRecords = {}
        # Find the most frequent verticalOrigin
        vorg_count = Counter(
            _getVerticalOrigin(self.otf, glyph) for glyph in self.allGlyphs.values()
        )
        vorg.defaultVertOriginY = vorg_count.most_common(1)[0][0]
        if len(vorg_count) > 1:
            for glyphName, glyph in self.allGlyphs.items():
                vorg.VOriginRecords[glyphName] = _getVerticalOrigin(self.otf, glyph)
        vorg.numVertOriginYMetrics = len(vorg.VOriginRecords) 
开发者ID:googlefonts,项目名称:ufo2ft,代码行数:26,代码来源:outlineCompiler.py

示例4: setupTable_maxp

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def setupTable_maxp(self):
        """Make the maxp table."""
        if "maxp" not in self.tables:
            return

        self.otf["maxp"] = maxp = newTable("maxp")
        maxp.tableVersion = 0x00010000
        maxp.numGlyphs = len(self.glyphOrder)
        maxp.maxZones = 1
        maxp.maxTwilightPoints = 0
        maxp.maxStorage = 0
        maxp.maxFunctionDefs = 0
        maxp.maxInstructionDefs = 0
        maxp.maxStackElements = 0
        maxp.maxSizeOfInstructions = 0
        maxp.maxComponentElements = max(
            len(g.components) for g in self.allGlyphs.values()
        ) 
开发者ID:googlefonts,项目名称:ufo2ft,代码行数:20,代码来源:outlineCompiler.py

示例5: setupTable_glyf

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def setupTable_glyf(self):
        """Make the glyf table."""
        if not {"glyf", "loca"}.issubset(self.tables):
            return

        self.otf["loca"] = newTable("loca")
        self.otf["glyf"] = glyf = newTable("glyf")
        glyf.glyphs = {}
        glyf.glyphOrder = self.glyphOrder

        hmtx = self.otf.get("hmtx")
        ttGlyphs = self.getCompiledGlyphs()
        for name in self.glyphOrder:
            ttGlyph = ttGlyphs[name]
            if ttGlyph.isComposite() and hmtx is not None and self.autoUseMyMetrics:
                self.autoUseMyMetrics(ttGlyph, name, hmtx)
            glyf[name] = ttGlyph 
开发者ID:googlefonts,项目名称:ufo2ft,代码行数:19,代码来源:outlineCompiler.py

示例6: test_toXML_v1

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def test_toXML_v1(self):
        name = FakeNameTable({258: "Spring theme", 259: "Winter theme"})
        cpal = newTable('CPAL')
        ttFont = {"name": name, "CPAL": cpal}
        cpal.decompile(CPAL_DATA_V1, ttFont)
        self.assertEqual(getXML(cpal.toXML, ttFont),
                         '<version value="1"/>'
                         '<numPaletteEntries value="3"/>'
                         '<palette index="0" label="258" type="1">'
                         '  <!-- Spring theme -->'
                         '  <color index="0" value="#CAFECAFE"/>'
                         '  <color index="1" value="#22110033"/>'
                         '  <color index="2" value="#66554477"/>'
                         '</palette>'
                         '<palette index="1" label="259" type="2">'
                         '  <!-- Winter theme -->'
                         '  <color index="0" value="#59413127"/>'
                         '  <color index="1" value="#42424242"/>'
                         '  <color index="2" value="#13330037"/>'
                         '</palette>'
                         '<paletteEntryLabels>'
                         '  <label index="0" value="513"/>'
                         '  <label index="1" value="514"/>'
                         '  <label index="2" value="515"/>'
                         '</paletteEntryLabels>') 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:27,代码来源:C_P_A_L_test.py

示例7: test_fromXML_v0

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def test_fromXML_v0(self):
        cpal = newTable('CPAL')
        for name, attrs, content in parseXML(
                '<version value="0"/>'
                '<numPaletteEntries value="2"/>'
                '<palette index="0">'
                '  <color index="0" value="#12345678"/>'
                '  <color index="1" value="#FEDCBA98"/>'
                '</palette>'):
            cpal.fromXML(name, attrs, content, ttFont=None)
        self.assertEqual(cpal.version, 0)
        self.assertEqual(cpal.numPaletteEntries, 2)
        self.assertEqual(repr(cpal.palettes), '[[#12345678, #FEDCBA98]]')
        self.assertEqual(cpal.paletteLabels, [0])
        self.assertEqual(cpal.paletteTypes, [0])
        self.assertEqual(cpal.paletteEntryLabels, [0, 0]) 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:18,代码来源:C_P_A_L_test.py

示例8: test_recalcUnicodeRanges

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def test_recalcUnicodeRanges(self):
		font = TTFont()
		font['OS/2'] = os2 = newTable('OS/2')
		font['cmap'] = cmap = newTable('cmap')
		st = getTableModule('cmap').CmapSubtable.newSubtable(4)
		st.platformID, st.platEncID, st.language = 3, 1, 0
		st.cmap = {0x0041:'A', 0x03B1: 'alpha', 0x0410: 'Acyr'}
		cmap.tables = []
		cmap.tables.append(st)
		os2.setUnicodeRanges({0, 1, 9})
		# 'pruneOnly' will clear any bits for which there's no intersection:
		# bit 1 ('Latin 1 Supplement'), in this case. However, it won't set
		# bit 7 ('Greek and Coptic') despite the "alpha" character is present.
		self.assertEqual(os2.recalcUnicodeRanges(font, pruneOnly=True), {0, 9})
		# try again with pruneOnly=False: bit 7 is now set.
		self.assertEqual(os2.recalcUnicodeRanges(font), {0, 7, 9})
		# add a non-BMP char from 'Mahjong Tiles' block (bit 122)
		st.cmap[0x1F000] = 'eastwindtile'
		# the bit 122 and the special bit 57 ('Non Plane 0') are also enabled
		self.assertEqual(os2.recalcUnicodeRanges(font), {0, 7, 9, 57, 122}) 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:22,代码来源:O_S_2f_2_test.py

示例9: build_hhea

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def build_hhea(self):
        if not self.hhea_:
            return
        table = self.font.get("hhea")
        if not table:  # this only happens for unit tests
            table = self.font["hhea"] = newTable("hhea")
            table.decompile(b"\0" * 36, self.font)
            table.tableVersion = 1.0
        if "caretoffset" in self.hhea_:
            table.caretOffset = self.hhea_["caretoffset"]
        if "ascender" in self.hhea_:
            table.ascent = self.hhea_["ascender"]
        if "descender" in self.hhea_:
            table.descent = self.hhea_["descender"]
        if "linegap" in self.hhea_:
            table.lineGap = self.hhea_["linegap"] 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:18,代码来源:builder.py

示例10: build_name

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def build_name(self):
        if not self.names_:
            return
        table = self.font.get("name")
        if not table:  # this only happens for unit tests
            table = self.font["name"] = newTable("name")
            table.names = []
        for name in self.names_:
            nameID, platformID, platEncID, langID, string = name
            if not isinstance(nameID, int):
                # A featureNames name and nameID is actually the tag
                tag = nameID
                if tag not in self.featureNames_ids_:
                    self.featureNames_ids_[tag] = self.get_user_name_id(table)
                    assert self.featureNames_ids_[tag] is not None
                nameID = self.featureNames_ids_[tag]
            table.setName(string, nameID, platformID, platEncID, langID) 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:19,代码来源:builder.py

示例11: buildGDEF

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def buildGDEF(self):
        gdef = otTables.GDEF()
        gdef.GlyphClassDef = self.buildGDEFGlyphClassDef_()
        gdef.AttachList = \
            otl.buildAttachList(self.attachPoints_, self.glyphMap)
        gdef.LigCaretList = \
            otl.buildLigCaretList(self.ligCaretCoords_, self.ligCaretPoints_,
                                  self.glyphMap)
        gdef.MarkAttachClassDef = self.buildGDEFMarkAttachClassDef_()
        gdef.MarkGlyphSetsDef = self.buildGDEFMarkGlyphSetsDef_()
        gdef.Version = 0x00010002 if gdef.MarkGlyphSetsDef else 1.0
        if any((gdef.GlyphClassDef, gdef.AttachList, gdef.LigCaretList,
                gdef.MarkAttachClassDef, gdef.MarkGlyphSetsDef)):
            result = newTable("GDEF")
            result.table = gdef
            return result
        else:
            return None 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:20,代码来源:builder.py

示例12: set_empty_dsig

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def set_empty_dsig(ttFont):
  newDSIG = ttLib.newTable("DSIG")
  newDSIG.ulVersion = 1
  newDSIG.usFlag = 0
  newDSIG.usNumSigs = 0
  newDSIG.signatureRecords = []
  ttFont.tables["DSIG"] = newDSIG 
开发者ID:googlefonts,项目名称:gftools,代码行数:9,代码来源:gftools-fix-dsig.py

示例13: fix

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def fix(self, value=15):
        try:
            table = self.font.get('gasp')
            table.gaspRange[65535] = value
            self.saveit = True
        except:
            print(('ER: {}: no table gasp... '
                  'Creating new table. ').format(self.path))
            table = ttLib.newTable('gasp')
            table.gaspRange = {65535: value}
            self.font['gasp'] = table
            self.saveit = True 
开发者ID:googlefonts,项目名称:gftools,代码行数:14,代码来源:gftools-fix-gasp.py

示例14: addDummyDSIG

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def addDummyDSIG(ttx):
	dsig = newTable("DSIG")
	dsig.data = "\x00\x00\x00\01\x00\x00\x00\x00"
	ttx["DSIG"] = dsig 
开发者ID:twardoch,项目名称:ttfdiet,代码行数:6,代码来源:ttfdiet.py

示例15: decompress

# 需要导入模块: from fontTools import ttLib [as 别名]
# 或者: from fontTools.ttLib import newTable [as 别名]
def decompress(ttFont, **kwargs):
    """ Use the FontTools Subsetter to desubroutinize the font's CFF table.
    Any keyword arguments are passed on as options to the Subsetter.
    Skip if the font contains no subroutines.
    """
    if not has_subrs(ttFont):
        log.debug('No subroutines found; skip decompress')
        return

    from fontTools import subset

    # The FontTools subsetter modifies many tables by default; here
    # we only want to desubroutinize, so we run the subsetter on a
    # temporary copy and extract the resulting CFF table from it
    make_temp = kwargs.pop('make_temp', True)
    if make_temp:
        from io import BytesIO
        from fontTools.ttLib import TTFont, newTable

        stream = BytesIO()
        ttFont.save(stream, reorderTables=None)
        stream.flush()
        stream.seek(0)
        tmpfont = TTFont(stream)
    else:
        tmpfont = ttFont  # run subsetter on the original font

    options = subset.Options(**kwargs)
    options.desubroutinize = True
    options.notdef_outline = True
    subsetter = subset.Subsetter(options=options)
    subsetter.populate(glyphs=tmpfont.getGlyphOrder())
    subsetter.subset(tmpfont)

    if make_temp:
        # copy modified CFF table to original font
        data = tmpfont['CFF '].compile(tmpfont)
        table = newTable('CFF ')
        table.decompile(data, ttFont)
        ttFont['CFF '] = table
        tmpfont.close() 
开发者ID:googlefonts,项目名称:compreffor,代码行数:43,代码来源:__init__.py


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