我想用我的python程序导出一个truetype文件。根据规范,truetype文件由可能包含以下任何数据类型的表组成:
Data type Description
BYTE 8-bit unsigned integer.
CHAR 8-bit signed integer.
USHORT 16-bit unsigned integer.
SHORT 16-bit signed integer.
ULONG 32-bit unsigned integer.
LONG 32-bit signed integer.
FIXED 32-bit signed fixed-point number (16.16)
FUNIT Smallest measurable distance in the em space.
FWORD 16-bit signed integer (SHORT) that describes a quantity in FUnits.
UFWORD Unsigned 16-bit integer (USHORT) that describes a quantity in FUnits.
F2DOT14 16-bit signed fixed number with the low 14 bits of fraction (2.14).我该如何将这类数据写入文件呢?
编辑:到目前为止,我得到的是:
s.data = ''
s.data += '{0:016}'.format(10)将数字10写为16位无符号整数。但是,我不能
s.file = open('test.ttf', 'wb')
s.file.write(s.data)因为这引发了一个
TypeError: 'str' does not support the buffer interface 发布于 2014-04-21 19:40:23
我这样做了:
s.data = []
s.data.append('{0:016b}'.format(someint))
f = open('test.ttf', 'wb')
bytearray = array.array('B')
for b in s.data:
b1 = int(b[:16], 2)
bytearray.append(b1)
if len(b)>16:
b2 = int(b[16:], 2)
bytearray.append(b2)
bytearray.tofile(f)
f.close()而且看起来很管用。
https://stackoverflow.com/questions/23181784
复制相似问题