C_O_L_R_.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:otRebuilder 作者: Pal3love 项目源码 文件源码
def decompile(self, data, ttFont):
        self.getGlyphName = ttFont.getGlyphName # for use in get/set item functions, for access by GID
        self.version, numBaseGlyphRecords, offsetBaseGlyphRecord, offsetLayerRecord, numLayerRecords = struct.unpack(">HHLLH", data[:14])
        assert (self.version == 0), "Version of COLR table is higher than I know how to handle"
        glyphOrder = ttFont.getGlyphOrder()
        gids = []
        layerLists = []
        glyphPos = offsetBaseGlyphRecord
        for i in range(numBaseGlyphRecords):
            gid, firstLayerIndex, numLayers = struct.unpack(">HHH", data[glyphPos:glyphPos+6])
            glyphPos += 6
            gids.append(gid)
            assert (firstLayerIndex + numLayers <= numLayerRecords)
            layerPos = offsetLayerRecord + firstLayerIndex * 4
            layers = []
            for j in range(numLayers):
                layerGid, colorID = struct.unpack(">HH", data[layerPos:layerPos+4])
                try:
                    layerName = glyphOrder[layerGid]
                except IndexError:
                    layerName = self.getGlyphName(layerGid)
                layerPos += 4
                layers.append(LayerRecord(layerName, colorID))
            layerLists.append(layers)

        self.ColorLayers = colorLayerLists = {}
        try:
            names = list(map(operator.getitem, [glyphOrder]*numBaseGlyphRecords, gids))
        except IndexError:
            getGlyphName = self.getGlyphName
            names = list(map(getGlyphName, gids ))

        list(map(operator.setitem, [colorLayerLists]*numBaseGlyphRecords, names, layerLists))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号