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


Python sstruct.unpack函数代码示例

本文整理汇总了Python中sstruct.unpack函数的典型用法代码示例。如果您正苦于以下问题:Python unpack函数的具体用法?Python unpack怎么用?Python unpack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: decompile

    def decompile(self, ttFont):
        self.glyphName = ttFont.getGlyphName(self.gid)
        if self.rawdata is None:
            from fontTools import ttLib

            raise (ttLib.TTLibError, "No table data to decompile.")
        if len(self.rawdata) > 0:
            if len(self.rawdata) < sbixBitmapHeaderFormatSize:
                from fontTools import ttLib

                # print "Bitmap %i header too short: Expected %x, got %x." % (self.gid, sbixBitmapHeaderFormatSize, len(self.rawdata))
                raise (ttLib.TTLibError, "Bitmap header too short.")

            sstruct.unpack(sbixBitmapHeaderFormat, self.rawdata[:sbixBitmapHeaderFormatSize], self)

            if self.imageFormatTag == "dupe":
                # bitmap is a reference to another glyph's bitmap
                gid, = struct.unpack(">H", self.rawdata[sbixBitmapHeaderFormatSize:])
                self.referenceGlyphName = ttFont.getGlyphName(gid)
            else:
                self.imageData = self.rawdata[sbixBitmapHeaderFormatSize:]
                self.referenceGlyphName = None
                # clean up
        del self.rawdata
        del self.gid
开发者ID:BredzPro,项目名称:Emoji-Tools,代码行数:25,代码来源:sbixBitmap.py

示例2: decompile

    def decompile(self, data):
        # header; FontRec
        sstruct.unpack(nfntHeaderFormat, data[:headerSize], self)

        # assert self.fRectHeight == (self.ascent + self.descent)

        # rest
        tableSize = 2 * (self.lastChar - self.firstChar + 3)
        bitmapSize = 2 * self.rowWords * self.fRectHeight

        self.bits = data[headerSize:headerSize + bitmapSize]

        # XXX deal with self.nDescent being a positive number
        assert (headerSize + bitmapSize + tableSize - 16) / 2 == self.owTLoc  # ugh...

        locTable = data[headerSize + bitmapSize:headerSize + bitmapSize + tableSize]
        if len(locTable) <> tableSize:
            raise ValueError, 'invalid NFNT format'

        owTable = data[headerSize + bitmapSize + tableSize:headerSize + bitmapSize + 2 * tableSize]
        if len(owTable) <> tableSize:
            raise ValueError, 'invalid NFNT format'

        # fill tables
        self.offsetTable = []
        self.widthTable = []
        self.locTable = []
        for i in range(0, tableSize, 2):
            self.offsetTable.append(ord(owTable[i]))
            self.widthTable.append(ord(owTable[i + 1]))
            loc, = struct.unpack("h", locTable[i:i + 2])
            self.locTable.append(loc)
开发者ID:Mortimer2013,项目名称:Emoji-Tools,代码行数:32,代码来源:nfntLib.py

示例3: decompile

    def decompile(self, ttFont):
        if self.data is None:
            from fontTools import ttLib

            raise (ttLib.TTLibError, "No table data to decompile.")
        if len(self.data) < sbixBitmapSetHeaderFormatSize:
            from fontTools import ttLib

            raise (ttLib.TTLibError, "BitmapSet header too short: Expected %x, got %x.") \
                  % (sbixBitmapSetHeaderFormatSize, len(self.data))

        # read BitmapSet header from raw data
        sstruct.unpack(sbixBitmapSetHeaderFormat, self.data[:sbixBitmapSetHeaderFormatSize], self)

        # calculate number of bitmaps
        firstBitmapOffset, = struct.unpack(">L", \
                                           self.data[
                                           sbixBitmapSetHeaderFormatSize: sbixBitmapSetHeaderFormatSize + sbixBitmapOffsetEntryFormatSize])
        self.numBitmaps = (firstBitmapOffset - sbixBitmapSetHeaderFormatSize) / sbixBitmapOffsetEntryFormatSize - 1
        # ^ -1 because there's one more offset than bitmaps

        # build offset list for single bitmap offsets
        self.bitmapOffsets = []
        for i in range(self.numBitmaps + 1):  # + 1 because there's one more offset than bitmaps
            start = i * sbixBitmapOffsetEntryFormatSize + sbixBitmapSetHeaderFormatSize
            myOffset, = struct.unpack(">L", self.data[start: start + sbixBitmapOffsetEntryFormatSize])
            self.bitmapOffsets.append(myOffset)

        # iterate through offset list and slice raw data into bitmaps
        for i in range(self.numBitmaps):
            myBitmap = Bitmap(rawdata=self.data[self.bitmapOffsets[i]: self.bitmapOffsets[i + 1]], gid=i)
            myBitmap.decompile(ttFont)
            self.bitmaps[myBitmap.glyphName] = myBitmap
        del self.bitmapOffsets
        del self.data
开发者ID:Mortimer2013,项目名称:Emoji-Tools,代码行数:35,代码来源:sbixBitmapSet.py

示例4: decompile

	def decompile(self, data, ttFont):
		# read table header
		sstruct.unpack(sbixHeaderFormat, data[ : sbixHeaderFormatSize], self)
		# collect offsets to individual bitmap sets in self.bitmapSetOffsets
		for i in range(self.numSets):
			myOffset = sbixHeaderFormatSize + i * sbixBitmapSetOffsetFormatSize
			offsetEntry = sbixBitmapSetOffset()
			sstruct.unpack(sbixBitmapSetOffsetFormat, \
				data[myOffset : myOffset+sbixBitmapSetOffsetFormatSize], \
				offsetEntry)
			self.bitmapSetOffsets.append(offsetEntry.offset)
		
		# decompile BitmapSets
		for i in range(self.numSets-1, -1, -1):
			myBitmapSet = BitmapSet(rawdata=data[self.bitmapSetOffsets[i]:])
			data = data[:self.bitmapSetOffsets[i]]
			myBitmapSet.decompile(ttFont)
			#print "  BitmapSet length: %xh" % len(bitmapSetData)
			#print "Number of Bitmaps:", myBitmapSet.numBitmaps
			if myBitmapSet.size in self.bitmapSets:
				from fontTools import ttLib
				raise(ttLib.TTLibError, "Pixel 'size' must be unique for each BitmapSet")
			self.bitmapSets[myBitmapSet.size] = myBitmapSet
		
		# after the bitmaps have been extracted, we don't need the offsets anymore
		del self.bitmapSetOffsets
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:26,代码来源:_s_b_i_x.py

示例5: __init__

	def __init__(self, refNum):
		self.__fileName = array.array("c", "\0" * 64)
		sstruct.unpack(_FCBPBFormat, 
				"\0" * sstruct.calcsize(_FCBPBFormat), self)
		self.ioNamePtr = self.__fileName.buffer_info()[0]
		self.ioRefNum = refNum
		self.ioVRefNum = GetVRefNum(refNum)
		self.__haveInfo = 0
开发者ID:Kurios,项目名称:Project32,代码行数:8,代码来源:homeResFile.py

示例6: _getheader

	def _getheader(self):
		data = self.FOND.data
		sstruct.unpack(headerformat, data[:28], self)
		self.ffProperty = struct.unpack(">9h", data[28:46])
		self.ffIntl = struct.unpack(">hh", data[46:50])
		self.ffVersion, = struct.unpack(">h", data[50:FONDheadersize])
		
		if DEBUG:
			self._rawheader = data[:FONDheadersize]
			self.parsedthings.append((0, FONDheadersize, 'header'))
开发者ID:ByteForge,项目名称:Researches,代码行数:10,代码来源:fondLib.py

示例7: getInfo

	def getInfo(self):
		if self.__haveInfo:
			return
		data = sstruct.pack(_FCBPBFormat, self)
		buf = array.array("c", data)
		ptr = buf.buffer_info()[0]
		err = _getInfo(ptr)
		if err:
			raise Res.Error("can't get file info", err)
		sstruct.unpack(_FCBPBFormat, buf.tostring(), self)
		self.__haveInfo = 1
开发者ID:Kurios,项目名称:Project32,代码行数:11,代码来源:homeResFile.py

示例8: decompile

	def decompile(self, data, ttFont):
		sstruct.unpack(postFormat, data[:postFormatSize], self)
		data = data[postFormatSize:]
		if self.formatType == 1.0:
			self.decode_format_1_0(data, ttFont)
		elif self.formatType == 2.0:
			self.decode_format_2_0(data, ttFont)
		elif self.formatType == 3.0:
			self.decode_format_3_0(data, ttFont)
		else:
			# supported format
			raise ttLib.TTLibError("'post' table format %f not supported" % self.formatType)
开发者ID:Kurios,项目名称:Project32,代码行数:12,代码来源:_p_o_s_t.py

示例9: test_incorrect_compressed_size

	def test_incorrect_compressed_size(self):
		data = self.file.read(woff2DirectorySize)
		header = sstruct.unpack(woff2DirectoryFormat, data)
		header['totalCompressedSize'] = 0
		data = sstruct.pack(woff2DirectoryFormat, header)
		with self.assertRaises(brotli.error):
			WOFF2Reader(BytesIO(data + self.file.read()))
开发者ID:CodeOps,项目名称:fonttools,代码行数:7,代码来源:woff2_test.py

示例10: test_incorrect_file_size

	def test_incorrect_file_size(self):
		data = self.file.read(woff2DirectorySize)
		header = sstruct.unpack(woff2DirectoryFormat, data)
		header['length'] -= 1
		data = sstruct.pack(woff2DirectoryFormat, header)
		with self.assertRaisesRegex(
				ttLib.TTLibError, "doesn't match the actual file size"):
			WOFF2Reader(BytesIO(data + self.file.read()))
开发者ID:CodeOps,项目名称:fonttools,代码行数:8,代码来源:woff2_test.py

示例11: __init__

 def __init__(self, file, checkChecksums=1):
     self.file = file
     self.checkChecksums = checkChecksums
     # unpack the header
     self.file.seek(0)
     bytes = self.file.read(woffHeaderSize)
     if len(bytes) != woffHeaderSize:
         raise WOFFLibError("Not a properly formatted WOFF file.")
     sstruct.unpack(woffHeaderFormat, bytes, self)
     if self.signature != "wOFF":
         raise WOFFLibError("Not a properly formatted WOFF file.")
     # unpack the directory
     self.tables = {}
     for i in range(self.numTables):
         entry = WOFFDirectoryEntry()
         entry.fromFile(self.file)
         self.tables[entry.tag] = entry
开发者ID:Eigi,项目名称:woffTools,代码行数:17,代码来源:__init__.py

示例12: decompile

	def decompile(self, data, ttFont):
		dummy, data = sstruct.unpack2(OS2_format_0, data, self)
		if self.version == 1 and not data:
			# workaround for buggy Apple fonts
			self.version = 0
		if self.version == 1:
			sstruct.unpack2(OS2_format_1_addition, data, self)
		elif self.version in (2, 3, 4):
			sstruct.unpack2(OS2_format_2_addition, data, self)
		elif self.version != 0:
			from fontTools import ttLib
			raise ttLib.TTLibError("unknown format for OS/2 table: version %s" % self.version)
		self.panose = sstruct.unpack(panoseFormat, self.panose, Panose())
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:13,代码来源:O_S_2f_2.py

示例13: __init__

	def __init__(self, file, checkChecksums=1, fontNumber=-1):
		self.file = file
		self.checkChecksums = checkChecksums

		self.flavor = None
		self.flavorData = None
		self.DirectoryEntry = SFNTDirectoryEntry
		self.sfntVersion = self.file.read(4)
		self.file.seek(0)
		if self.sfntVersion == "ttcf":
			sstruct.unpack(ttcHeaderFormat, self.file.read(ttcHeaderSize), self)
			assert self.Version == 0x00010000 or self.Version == 0x00020000, "unrecognized TTC version 0x%08x" % self.Version
			if not 0 <= fontNumber < self.numFonts:
				from fontTools import ttLib
				raise ttLib.TTLibError, "specify a font number between 0 and %d (inclusive)" % (self.numFonts - 1)
			offsetTable = struct.unpack(">%dL" % self.numFonts, self.file.read(self.numFonts * 4))
			if self.Version == 0x00020000:
				pass # ignoring version 2.0 signatures
			self.file.seek(offsetTable[fontNumber])
			sstruct.unpack(sfntDirectoryFormat, self.file.read(sfntDirectorySize), self)
		elif self.sfntVersion == "wOFF":
			self.flavor = "woff"
			self.DirectoryEntry = WOFFDirectoryEntry
			sstruct.unpack(woffDirectoryFormat, self.file.read(woffDirectorySize), self)
		else:
			sstruct.unpack(sfntDirectoryFormat, self.file.read(sfntDirectorySize), self)

		if self.sfntVersion not in ("\000\001\000\000", "OTTO", "true"):
			from fontTools import ttLib
			raise ttLib.TTLibError, "Not a TrueType or OpenType font (bad sfntVersion)"
		self.tables = {}
		for i in range(self.numTables):
			entry = self.DirectoryEntry()
			entry.fromFile(self.file)
			if entry.length > 0:
				self.tables[entry.tag] = entry
			else:
				# Ignore zero-length tables. This doesn't seem to be documented,
				# yet it's apparently how the Windows TT rasterizer behaves.
				# Besides, at least one font has been sighted which actually
				# *has* a zero-length table.
				pass

		# Load flavor data if any
		if self.flavor == "woff":
			self.flavorData = WOFFFlavorData(self)
开发者ID:kipulcha,项目名称:fonttools,代码行数:46,代码来源:sfnt.py

示例14: decompile

	def decompile(self, data, ttFont):
		dummy, data = sstruct.unpack2(OS2_format_0, data, self)
		# workarounds for buggy fonts (Apple, mona)
		if not data:
			self.version = 0
		elif len(data) == sstruct.calcsize(OS2_format_1_addition):
			self.version = 1
		elif len(data) == sstruct.calcsize(OS2_format_2_addition):
			if self.version not in (2, 3, 4):
				self.version = 1
		else:
			from fontTools import ttLib
			raise ttLib.TTLibError, "unknown format for OS/2 table (incorrect length): version %s" % (self.version, len(data))
		if self.version == 1:
			sstruct.unpack2(OS2_format_1_addition, data, self)
		elif self.version in (2, 3, 4):
			sstruct.unpack2(OS2_format_2_addition, data, self)
		elif self.version <> 0:
			from fontTools import ttLib
			raise ttLib.TTLibError, "unknown format for OS/2 table: version %s" % self.version
		self.panose = sstruct.unpack(panoseFormat, self.panose, Panose())
开发者ID:7o9,项目名称:stdm-plugin,代码行数:21,代码来源:O_S_2f_2.py

示例15: __init__

	def __init__(self, file, checkChecksums=1, fontNumber=-1):
		self.file = file
		self.checkChecksums = checkChecksums
		data = self.file.read(sfntDirectorySize)
		if len(data) != sfntDirectorySize:
			from fontTools import ttLib
			raise ttLib.TTLibError("Not a TrueType or OpenType font (not enough data)")
		sstruct.unpack(sfntDirectoryFormat, data, self)
		if self.sfntVersion == b"ttcf":
			assert ttcHeaderSize == sfntDirectorySize
			sstruct.unpack(ttcHeaderFormat, data, self)
			assert self.Version == b'\0\1\0\0' or self.Version == b'\0\2\0\0', "unrecognized TTC version 0x%08x" % self.Version
			if not 0 <= fontNumber < self.numFonts:
				from fontTools import ttLib
				raise ttLib.TTLibError("specify a font number between 0 and %d (inclusive)" % (self.numFonts - 1))
			offsetTable = struct.unpack(">%dL" % self.numFonts, self.file.read(self.numFonts * 4))
			if self.Version == b'\0\2\0\0':
				pass # ignoring version 2.0 signatures
			self.file.seek(offsetTable[fontNumber])
			data = self.file.read(sfntDirectorySize)
			sstruct.unpack(sfntDirectoryFormat, data, self)
		if self.sfntVersion not in (b'\0\1\0\0', b"OTTO", b"true"):
			from fontTools import ttLib
			raise ttLib.TTLibError("Not a TrueType or OpenType font (bad sfntVersion)")
		self.tables = {}
		for i in range(self.numTables):
			entry = SFNTDirectoryEntry()
			entry.fromFile(self.file)
			if entry.length > 0:
                                self.tables[entry.tag] = entry
			else:
				# Ignore zero-length tables. This doesn't seem to be documented,
				# yet it's apparently how the Windows TT rasterizer behaves.
				# Besides, at least one font has been sighted which actually
				# *has* a zero-length table.
				pass
开发者ID:Kurios,项目名称:Project32,代码行数:36,代码来源:sfnt.py


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