def write_font_record(data, obfuscate=True, compress=True):
 flags = 0
 key_len = 20
 usize = len(data)
 xor_key = ''
 if compress:
  flags |= 1
  data = zlib.compress(data, 9)
 if (obfuscate and (len(data) >= 1040)):
  flags |= 2
  xor_key = os.urandom(key_len)
  key = bytearray(xor_key)
  data = bytearray(data)
  for i in xrange(1040):
   data[i] ^= key[(i % key_len)]
  data = bytes(data)
 key_start = (struct.calcsize('>5L') + 4)
 data_start = (key_start + len(xor_key))
 header = ('FONT' + struct.pack('>5L', usize, flags, data_start, len(xor_key), key_start))
 return ((header + xor_key) + data)

def write_font_record ( data , obfuscate = True , compress = True ) : flags = 0 key_len = 20 usize = len ( data ) xor_key = '' if compress : flags |= 1 data = zlib . compress ( data , 9 ) if ( obfuscate and ( len ( data ) >= 1040 ) ) : flags |= 2 xor_key = os . urandom ( key_len ) key = bytearray ( xor_key ) data = bytearray ( data ) for i in xrange ( 1040 ) : data [ i ] ^= key [ ( i % key_len ) ] data = bytes ( data ) key_start = ( struct . calcsize ( '>5L' ) + 4 ) data_start = ( key_start + len ( xor_key ) ) header = ( 'FONT' + struct . pack ( '>5L' , usize , flags , data_start , len ( xor_key ) , key_start ) ) return ( ( header + xor_key ) + data )
write the ttf/otf font represented by data into a font record .