parameters: (fontdata)
return_statement: return ''.join((fixed, nameheaders, rootstring))
docstring: given ttf font data produce an EOT header
docstring_summary: given ttf font data produce an EOT header
docstring_tokens: given ttf font data produce an EOT header
function: def make_eot_header(fontdata):
      """given ttf font data produce an EOT header"""
      fontDataSize = len(fontdata)
      font = get_table_directory(fontdata)
  
      # toss out .otf fonts, t2embed library doesn't support these
      tableDir = font['tableDir']
  
      # check for required tables
      required = (OpenType.TABLE_HEAD, OpenType.TABLE_NAME, OpenType.TABLE_OS2)
      for table in required:
          if not (table in tableDir):
              raise FontError('missing required table ' + multicharval(table))
  
      # read name strings
  
      # pull out data from individual tables to construct fixed header portion
      # need to calculate eotSize before packing
      version = EOT.EOT_VERSION
      flags = 0
      charset = EOT.EOT_DEFAULT_CHARSET
      magicNumber = EOT.EOT_MAGIC_NUMBER
  
      # read values from OS/2 table
      os2Dir = tableDir[OpenType.TABLE_OS2]
      os2offset = os2Dir['offset']
      os2size = struct.calcsize(OpenType.OS2_UNPACK)
  
      if os2size > os2Dir['length']:
          raise FontError('OS/2 table invalid length')
  
      os2fields = struct.unpack(OpenType.OS2_UNPACK, fontdata[os2offset : os2offset + os2size])
  
      panose = []
      urange = []
      codepage = []
  
      weight, fsType = os2fields[:2]
      panose[:10] = os2fields[2:12]
      urange[:4] = os2fields[12:16]
      fsSelection = os2fields[16]
      codepage[:2] = os2fields[17:19]
  
      italic = fsSelection & OpenType.OS2_FSSELECTION_ITALIC
  
      # read in values from head table
      headDir = tableDir[OpenType.TABLE_HEAD]
      headoffset = headDir['offset']
      headsize = struct.calcsize(OpenType.HEAD_UNPACK)
  
      if headsize > headDir['length']:
          raise FontError('head table invalid length')
  
      headfields = struct.unpack(OpenType.HEAD_UNPACK, fontdata[headoffset : headoffset + headsize])
      checkSumAdjustment = headfields[0]
  
      # make name headers
      nameheaders = make_eot_name_headers(fontdata, tableDir[OpenType.TABLE_NAME])
      rootstring = make_root_string()
  
      # calculate the total eot size
      eotSize = struct.calcsize(EOT.EOT_HEADER_PACK) + len(nameheaders) + len(rootstring) + fontDataSize
      fixed = struct.pack(EOT.EOT_HEADER_PACK,
                          *([eotSize, fontDataSize, version, flags] + panose + [charset, italic] +
                            [weight, fsType, magicNumber] + urange + codepage + [checkSumAdjustment]))
  
      return ''.join((fixed, nameheaders, rootstring))
function_tokens: def make_eot_header ( fontdata ) : fontDataSize = len ( fontdata ) font = get_table_directory ( fontdata ) # toss out .otf fonts, t2embed library doesn't support these tableDir = font [ 'tableDir' ] # check for required tables required = ( OpenType . TABLE_HEAD , OpenType . TABLE_NAME , OpenType . TABLE_OS2 ) for table in required : if not ( table in tableDir ) : raise FontError ( 'missing required table ' + multicharval ( table ) ) # read name strings # pull out data from individual tables to construct fixed header portion # need to calculate eotSize before packing version = EOT . EOT_VERSION flags = 0 charset = EOT . EOT_DEFAULT_CHARSET magicNumber = EOT . EOT_MAGIC_NUMBER # read values from OS/2 table os2Dir = tableDir [ OpenType . TABLE_OS2 ] os2offset = os2Dir [ 'offset' ] os2size = struct . calcsize ( OpenType . OS2_UNPACK ) if os2size > os2Dir [ 'length' ] : raise FontError ( 'OS/2 table invalid length' ) os2fields = struct . unpack ( OpenType . OS2_UNPACK , fontdata [ os2offset : os2offset + os2size ] ) panose = [ ] urange = [ ] codepage = [ ] weight , fsType = os2fields [ : 2 ] panose [ : 10 ] = os2fields [ 2 : 12 ] urange [ : 4 ] = os2fields [ 12 : 16 ] fsSelection = os2fields [ 16 ] codepage [ : 2 ] = os2fields [ 17 : 19 ] italic = fsSelection & OpenType . OS2_FSSELECTION_ITALIC # read in values from head table headDir = tableDir [ OpenType . TABLE_HEAD ] headoffset = headDir [ 'offset' ] headsize = struct . calcsize ( OpenType . HEAD_UNPACK ) if headsize > headDir [ 'length' ] : raise FontError ( 'head table invalid length' ) headfields = struct . unpack ( OpenType . HEAD_UNPACK , fontdata [ headoffset : headoffset + headsize ] ) checkSumAdjustment = headfields [ 0 ] # make name headers nameheaders = make_eot_name_headers ( fontdata , tableDir [ OpenType . TABLE_NAME ] ) rootstring = make_root_string ( ) # calculate the total eot size eotSize = struct . calcsize ( EOT . EOT_HEADER_PACK ) + len ( nameheaders ) + len ( rootstring ) + fontDataSize fixed = struct . pack ( EOT . EOT_HEADER_PACK , * ( [ eotSize , fontDataSize , version , flags ] + panose + [ charset , italic ] + [ weight , fsType , magicNumber ] + urange + codepage + [ checkSumAdjustment ] ) ) return '' . join ( ( fixed , nameheaders , rootstring ) )