當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。