本文整理汇总了Python中sstruct.pack函数的典型用法代码示例。如果您正苦于以下问题:Python pack函数的具体用法?Python pack怎么用?Python pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pack函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: compile
def compile(self, ttFont):
dataList = []
dataList.append(sstruct.pack(bigGlyphMetricsFormat, self.metrics))
dataList.append(struct.pack(">H", len(self.componentArray)))
for curComponent in self.componentArray:
curComponent.glyphCode = ttFont.getGlyphID(curComponent.name)
dataList.append(sstruct.pack(ebdtComponentFormat, curComponent))
return string.join(dataList, "")
开发者ID:kipulcha,项目名称:fonttools,代码行数:8,代码来源:E_B_D_T_.py
示例2: compile
def compile(self, ttFont):
if 'glyf' in ttFont:
if ttFont.isLoaded('glyf') and ttFont.recalcBBoxes:
self.recalc(ttFont)
else:
pass # CFF
self.numGlyphs = len(ttFont.getGlyphOrder())
if self.tableVersion != 0x00005000:
self.tableVersion = 0x00010000
data = sstruct.pack(maxpFormat_0_5, self)
if self.tableVersion == 0x00010000:
data = data + sstruct.pack(maxpFormat_1_0_add, self)
return data
开发者ID:Kurios,项目名称:Project32,代码行数:13,代码来源:_m_a_x_p.py
示例3: compile
def compile(self, ttFont):
panose = self.panose
self.panose = sstruct.pack(panoseFormat, self.panose)
if self.version == 0:
data = sstruct.pack(OS2_format_0, self)
elif self.version == 1:
data = sstruct.pack(OS2_format_1, self)
elif self.version in (2, 3, 4):
data = sstruct.pack(OS2_format_2, self)
else:
from fontTools import ttLib
raise ttLib.TTLibError("unknown format for OS/2 table: version %s" % self.version)
self.panose = panose
return data
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:14,代码来源:O_S_2f_2.py
示例4: 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
示例5: _calcMasterChecksum
def _calcMasterChecksum(self, directory):
# calculate checkSumAdjustment
tags = self.tables.keys()
checksums = []
for i in range(len(tags)):
checksums.append(self.tables[tags[i]].checkSum)
# TODO(behdad) I'm fairly sure the checksum for woff is not working correctly.
# Haven't debugged.
if self.DirectoryEntry != SFNTDirectoryEntry:
# Create a SFNT directory for checksum calculation purposes
self.searchRange, self.entrySelector, self.rangeShift = getSearchRange(self.numTables)
directory = sstruct.pack(sfntDirectoryFormat, self)
tables = self.tables.items()
tables.sort()
for tag, entry in tables:
sfntEntry = SFNTDirectoryEntry()
for item in ['tag', 'checkSum', 'offset', 'length']:
setattr(sfntEntry, item, getattr(entry, item))
directory = directory + sfntEntry.toString()
directory_end = sfntDirectorySize + len(self.tables) * sfntDirectoryEntrySize
assert directory_end == len(directory)
checksums.append(calcChecksum(directory))
checksum = sum(checksums) & 0xffffffff
# BiboAfba!
checksumadjustment = (0xB1B0AFBA - checksum) & 0xffffffff
return checksumadjustment
开发者ID:kipulcha,项目名称:fonttools,代码行数:29,代码来源:sfnt.py
示例6: _writeTableDirectory
def _writeTableDirectory(self):
if self.verbose:
debugmsg("writing table directory")
self.file.seek(woffHeaderSize)
for tag, (index, entry, data) in sorted(self.tables.items()):
entry = sstruct.pack(woffDirectoryEntryFormat, entry)
self.file.write(entry)
开发者ID:Eigi,项目名称:woffTools,代码行数:7,代码来源:__init__.py
示例7: compile
def compile(self, ttFont):
self.numGMAPs = len(self.GMAPs)
self.numGlyplets = len(self.glyphlets)
GMAPoffsets = [0]*(self.numGMAPs + 1)
glyphletOffsets = [0]*(self.numGlyplets + 1)
dataList =[ sstruct.pack(GPKGFormat, self)]
pos = len(dataList[0]) + (self.numGMAPs + 1)*4 + (self.numGlyplets + 1)*4
GMAPoffsets[0] = pos
for i in range(1, self.numGMAPs +1):
pos += len(self.GMAPs[i-1])
GMAPoffsets[i] = pos
gmapArray = numpy.array(GMAPoffsets, numpy.uint32)
if sys.byteorder <> "big":
gmapArray = gmapArray.byteswap()
dataList.append(gmapArray.tostring())
glyphletOffsets[0] = pos
for i in range(1, self.numGlyplets +1):
pos += len(self.glyphlets[i-1])
glyphletOffsets[i] = pos
glyphletArray = numpy.array(glyphletOffsets, numpy.uint32)
if sys.byteorder <> "big":
glyphletArray = glyphletArray.byteswap()
dataList.append(glyphletArray.tostring())
dataList += self.GMAPs
dataList += self.glyphlets
data = "".join(dataList)
return data
开发者ID:7o9,项目名称:stdm-plugin,代码行数:30,代码来源:G_P_K_G_.py
示例8: calcHeadCheckSumAdjustment
def calcHeadCheckSumAdjustment(flavor, tables):
numTables = len(tables)
# build the sfnt header
searchRange, entrySelector, rangeShift = getSearchRange(numTables)
sfntDirectoryData = dict(
sfntVersion=flavor,
numTables=numTables,
searchRange=searchRange,
entrySelector=entrySelector,
rangeShift=rangeShift
)
# build the sfnt directory
directory = sstruct.pack(sfntDirectoryFormat, sfntDirectoryData)
for tag, entry in sorted(tables.items()):
entry = tables[tag]
sfntEntry = SFNTDirectoryEntry()
sfntEntry.tag = tag
sfntEntry.checkSum = entry["checkSum"]
sfntEntry.offset = entry["offset"]
sfntEntry.length = entry["length"]
directory += sfntEntry.toString()
# calculate the checkSumAdjustment
checkSums = [entry["checkSum"] for entry in tables.values()]
checkSums.append(calcChecksum(directory))
checkSumAdjustment = sum(checkSums)
checkSumAdjustment = (0xB1B0AFBA - checkSumAdjustment) & 0xffffffff
# done
return checkSumAdjustment
开发者ID:Eigi,项目名称:woffTools,代码行数:28,代码来源:__init__.py
示例9: close
def close(self):
if self.numTables != len(self.tables):
raise WOFFLibError("wrong number of tables; expected %d, found %d" % (self.numTables, len(self.tables)))
# first, handle the checkSumAdjustment
if self.recalculateHeadChecksum and "head" in self.tables:
self._handleHeadChecksum()
# check the table directory conformance
for tag, (index, entry, data) in sorted(self.tables.items()):
self._checkTableConformance(entry, data)
# write the header
header = sstruct.pack(woffHeaderFormat, self)
self.file.seek(0)
self.file.write(header)
# update the directory offsets
offset = woffHeaderSize + (woffDirectoryEntrySize * self.numTables)
order = self._tableOrder()
for tag in order:
index, entry, data = self.tables[tag]
entry.offset = offset
offset += calc4BytePaddedLength(entry.compLength) # ensure byte alignment
# write the directory
self._writeTableDirectory()
# write the table data
self._writeTableData()
# write the metadata
self._writeMetadata()
# write the private data
self._writePrivateData()
# write the header
self._writeHeader()
# go to the beginning of the file
self.file.seek(0)
开发者ID:Eigi,项目名称:woffTools,代码行数:32,代码来源:__init__.py
示例10: compile
def compile(self, ttFont):
packed = sstruct.pack(DSIG_HeaderFormat, self)
headers = [packed]
offset = len(packed) + self.usNumSigs * sstruct.calcsize(DSIG_SignatureFormat)
data = []
for sigrec in self.signatureRecords:
# first pack signature block
sigrec.cbSignature = len(sigrec.pkcs7)
packed = sstruct.pack(DSIG_SignatureBlockFormat, sigrec) + sigrec.pkcs7
data.append(packed)
# update redundant length field
sigrec.ulLength = len(packed)
# update running table offset
sigrec.ulOffset = offset
headers.append(sstruct.pack(DSIG_SignatureFormat, sigrec))
offset += sigrec.ulLength
return "".join(headers + data)
开发者ID:olivierdalang,项目名称:stdm,代码行数:17,代码来源:D_S_I_G_.py
示例11: 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
示例12: compile
def compile(self, parentTable):
data = sstruct.pack(METAStringRecordFormat, self)
if parentTable.metaFlags == 0:
datum = struct.pack(">H", self.offset)
elif parentTable.metaFlags == 1:
datum = struct.pack(">L", self.offset)
data = data + datum
return data
开发者ID:kipulcha,项目名称:fonttools,代码行数:8,代码来源:M_E_T_A_.py
示例13: compile
def compile(self, ttFont):
if self.UV == None:
self.UV = 0
nameLen = len(self.name)
if nameLen < 32:
self.name = self.name + "\0"*(32 - nameLen)
data = sstruct.pack(GMAPRecordFormat1, self)
return data
开发者ID:chiamingyen,项目名称:SciTE,代码行数:8,代码来源:G_M_A_P_.py
示例14: compile
def compile(self, ttFont):
sbixData = ""
self.numSets = len(self.bitmapSets)
sbixHeader = sstruct.pack(sbixHeaderFormat, self)
# calculate offset to start of first bitmap set
setOffset = sbixHeaderFormatSize + sbixBitmapSetOffsetFormatSize * self.numSets
for si in sorted(self.bitmapSets.keys()):
myBitmapSet = self.bitmapSets[si]
myBitmapSet.compile(ttFont)
# append offset to this bitmap set to table header
myBitmapSet.offset = setOffset
sbixHeader += sstruct.pack(sbixBitmapSetOffsetFormat, myBitmapSet)
setOffset += len(myBitmapSet.data)
sbixData += myBitmapSet.data
return sbixHeader + sbixData
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:18,代码来源:_s_b_i_x.py
示例15: compile
def compile(self, ttFont):
glyphIds = map(ttFont.getGlyphID, self.names)
# Make sure all the ids are consecutive. This is required by Format 2.
assert glyphIds == range(self.firstGlyphIndex, self.lastGlyphIndex+1), "Format 2 ids must be consecutive."
self.imageDataOffset = min(zip(*self.locations)[0])
dataList = [EblcIndexSubTable.compile(self, ttFont)]
dataList.append(struct.pack(">L", self.imageSize))
dataList.append(sstruct.pack(bigGlyphMetricsFormat, self.metrics))
return string.join(dataList, "")
开发者ID:kipulcha,项目名称:fonttools,代码行数:10,代码来源:E_B_L_C_.py
示例16: _buildheader
def _buildheader(self):
header = sstruct.pack(headerformat, self)
header = header + apply(struct.pack, (">9h",) + self.ffProperty)
header = header + apply(struct.pack, (">hh",) + self.ffIntl)
header = header + struct.pack(">h", self.ffVersion)
if DEBUG:
print "header is the same?", self._rawheader == header and 'yes.' or 'no.'
if self._rawheader <> header:
print len(self._rawheader), len(header)
self._rawheader = header
开发者ID:ByteForge,项目名称:Researches,代码行数:10,代码来源:fondLib.py
示例17: 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
示例18: compile
def compile(self, ttFont):
self.nameLength = chr(len(self.baseGlyphName))
self.uniqueName = self.compilecompileUniqueName(self.uniqueName, 28)
METAMD5List = eval(self.METAMD5)
self.METAMD5 = ""
for val in METAMD5List:
self.METAMD5 = self.METAMD5 + chr(val)
assert (len(self.METAMD5) == 16), "Failed to pack 16 byte MD5 hash in SING table"
data = sstruct.pack(SINGFormat, self)
data = data + self.baseGlyphName
return data
开发者ID:Kurios,项目名称:Project32,代码行数:11,代码来源:S_I_N_G_.py
示例19: compile
def compile(self):
header = sstruct.pack(nfntHeaderFormat, self)
nEntries = len(self.widthTable)
owTable = [None] * nEntries
locTable = [None] * nEntries
for i in range(nEntries):
owTable[i] = chr(self.offsetTable[i]) + chr(self.widthTable[i])
locTable[i] = struct.pack("h", self.locTable[i])
owTable = string.join(owTable, "")
locTable = string.join(locTable, "")
assert len(locTable) == len(owTable) == 2 * (self.lastChar - self.firstChar + 3)
return header + self.bits + locTable + owTable
开发者ID:Mortimer2013,项目名称:Emoji-Tools,代码行数:12,代码来源:nfntLib.py
示例20: compile
def compile(self, ttFont):
if self.glyphName is None:
from fontTools import ttLib
raise ttLib.TTLibError, "Can't compile bitmap without glyph name"
# TODO: if ttFont has no maxp, cmap etc., ignore glyph names and compile by index?
# (needed if you just want to compile the sbix table on its own)
self.gid = struct.pack(">H", ttFont.getGlyphID(self.glyphName))
if self.imageFormatTag is None:
self.rawdata = ""
else:
self.rawdata = sstruct.pack(sbixBitmapHeaderFormat, self) + self.imageData
开发者ID:BredzPro,项目名称:Emoji-Tools,代码行数:12,代码来源:sbixBitmap.py
注:本文中的sstruct.pack函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论