Example #1
0
 def base_font(self):
     output = self.folder + '/base'
     baseFonter = BaseFonter(self.fontfile)
     header_dict = FontInfo.getInformation(self.fontfile,
                                           FontInfo.TAGS.keys())
     bin_header = BaseHeaderPrepare.prepare(BaseFonter.BASE_VERSION,
                                            header_dict)
     baseFonter.base(output, bin_header)
Example #2
0
def dump_tables(fontfile, output):
    font = TTFont(fontfile, lazy=True)
    dump_folder = output + '_tables'
    print('dump results in {0}'.format(dump_folder))
    try:
        os.makedirs(dump_folder)
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise

    header_dict = FontInfo.getInformation(fontfile, FontInfo.TAGS.keys())
    bin_header = BaseHeaderPrepare.prepare(BaseFonter.BASE_VERSION,
                                           header_dict)
    print('Base header total size=', len(bin_header))

    base_fonter = BaseFonter(fontfile)
    base_dump = dump_folder + '/base_dump'
    base_fonter.dump_base(base_dump)
    # OpenType tables.
    dump_file = open(base_dump, 'r+b')
    tables = font.reader.tables
    for name in font.reader.tables:
        table = tables[name]
        offset = table.offset
        length = table.length
        #print('{0}: offset={1}, length={2}'.format(name, offset, length))
        table_file_name = dump_folder + '/' + name.replace('/', '_')
        table_file = open(table_file_name, 'w+b')
        dump_file.seek(offset)
        table_file.write(dump_file.read(length))
        table_file.close()
        rle_table = RleFont(table_file_name)
        rle_table.encode()
        rle_table.write(table_file_name)
        compressor = Compressor(Compressor.GZIP_INPLACE_CMD)
        compressor.compress(table_file_name)
        print('{0}: offset={1:9d}\tlen={2:9d}\tcmp_len={3:9d}'.format(
            name, offset, length, os.path.getsize(table_file_name + '.gz')))

    print('TODO(bstell) save and compress the CFF parts.')
    if 'CFF ' in font:
        dumpCFFTable(font)

    font.close()
Example #3
0
def dump_tables(fontfile, output):
  font = TTFont(fontfile,lazy=True)
  dump_folder = output + '_tables'
  print('dump results in {0}'.format(dump_folder))
  try:
    os.makedirs(dump_folder)
  except OSError as exception:
    if exception.errno != errno.EEXIST:
      raise

  header_dict = FontInfo.getInformation(fontfile, FontInfo.TAGS.keys())
  bin_header = BaseHeaderPrepare.prepare(BaseFonter.BASE_VERSION, header_dict)
  print('Base header total size=',len(bin_header))

  base_fonter = BaseFonter(fontfile)
  base_dump =  dump_folder + '/base_dump'
  base_fonter.dump_base(base_dump)
  # OpenType tables.
  dump_file = open(base_dump,'r+b')
  tables = font.reader.tables
  for name in font.reader.tables:
    table = tables[name]
    offset = table.offset
    length = table.length
    #print('{0}: offset={1}, length={2}'.format(name, offset, length))
    table_file_name = dump_folder + '/' + name.replace('/', '_')
    table_file = open(table_file_name,'w+b')
    dump_file.seek(offset);
    table_file.write(dump_file.read(length))
    table_file.close()
    rle_table = RleFont(table_file_name)
    rle_table.encode()
    rle_table.write(table_file_name)
    compressor = Compressor(Compressor.GZIP_INPLACE_CMD)
    compressor.compress(table_file_name)
    print('{0}: offset={1:9d}\tlen={2:9d}\tcmp_len={3:9d}'.format(name, offset, length,os.path.getsize(table_file_name+'.gz')))

  print('TODO(bstell) save and compress the CFF parts.')
  if 'CFF ' in font:
    dumpCFFTable(font)

  font.close()
Example #4
0
 def base_font(self):
   output = self.folder + '/base'
   baseFonter = BaseFonter(self.fontfile)
   header_dict = FontInfo.getInformation(self.fontfile, FontInfo.TAGS.keys())
   bin_header = BaseHeaderPrepare.prepare(BaseFonter.BASE_VERSION, header_dict)
   baseFonter.base(output, bin_header)