Пример #1
0
  def cmap_dump(self):
    font = TTFont(self.fontfile)
    #TODO(ahmetcelik) cmap in format 12 should be used if it exists
    cmapTable = font['cmap'].getcmap(3, 10)
    if not cmapTable:
      cmapTable = font['cmap'].getcmap(3, 1)
    assert cmapTable,'Unicode cmap table required'
    cmap = cmapTable.cmap  # unicode table


    codepoints = []
    glyphs = []

    for code, name in cmap.iteritems():
      id = font.getGlyphID(name)
      glyphs.append(id)
      codepoints.append(code)
      if self.debug:
        print id,name,code
    font.close()

    cp_dumper = Dumper(self.folder + '/codepoints')
    cp_dumper.dump_array(codepoints, 'I', '>')
    cp_dumper.close()

    gid_dumper = Dumper(self.folder + '/gids')
    gid_dumper.dump_array(glyphs, 'H', '>')
    gid_dumper.close()
Пример #2
0
    def cmap_dump(self):
        font = TTFont(self.fontfile)
        #TODO(ahmetcelik) cmap in format 12 should be used if it exists
        cmapTable = font['cmap'].getcmap(3, 10)
        if not cmapTable:
            cmapTable = font['cmap'].getcmap(3, 1)
        assert cmapTable, 'Unicode cmap table required'
        cmap = cmapTable.cmap  # unicode table

        codepoints = []
        glyphs = []

        for code, name in cmap.iteritems():
            id = font.getGlyphID(name)
            glyphs.append(id)
            codepoints.append(code)
            if self.debug:
                print id, name, code
        font.close()

        cp_dumper = Dumper(self.folder + '/codepoints')
        cp_dumper.dump_array(codepoints, 'I', '>')
        cp_dumper.close()

        gid_dumper = Dumper(self.folder + '/gids')
        gid_dumper.dump_array(glyphs, 'H', '>')
        gid_dumper.close()
Пример #3
0
 def serialize_TOC(self, output_idx, output_data):
   """Dump the TOC data to the file
   """
   if self.tocReady:
     dumper = Dumper(output_idx)
     dumper.dump(self.TOC)
     dumper.close()
     dumper = Dumper(output_data)
     dumper.dumpForEach(self.TOCEntries)
     dumper.close()
Пример #4
0
 def serialize_glyf(self, output_idx, output_data):
   """Dump the Glyf data to the file
   """
   if self.glyfReady:
     dumper = Dumper(output_idx)
     dumper.dump(self.GlyphTable)
     dumper.dump_for_each(self.glyphs_info)
     dumper.close()
     dumper = Dumper(output_data)
     dumper.dump_for_each(self.glyphs_data)
     dumper.close()
Пример #5
0
 def serialize_cff(self, output_idx, output_data):
     """Dump the Glyf data to the file
 """
     if self.cffReady:
         dumper = Dumper(output_idx)
         dumper.dump(self.CffTable)
         dumper.dump_for_each(self.glyphs_info)
         dumper.close()
         dumper = Dumper(output_data)
         dumper.dump_for_each(self.glyphs_data)
         dumper.close()
Пример #6
0
 def serialize_TOC(self, output_idx, output_data):
     """Dump the TOC data to the file
 """
     # TODO(bstell) remove this is not used anywhere
     if self.tocReady:
         dumper = Dumper(output_idx)
         dumper.dump(self.TOC)
         dumper.close()
         dumper = Dumper(output_data)
         dumper.dumpForEach(self.TOCEntries)
         dumper.close()
Пример #7
0
 def serialize_TOC(self, output_idx, output_data):
     """Dump the TOC data to the file
 """
     # TODO(bstell) remove this is not used anywhere
     if self.tocReady:
         dumper = Dumper(output_idx)
         dumper.dump(self.TOC)
         dumper.close()
         dumper = Dumper(output_data)
         dumper.dumpForEach(self.TOCEntries)
         dumper.close()
Пример #8
0
  def metadata(self):
    output = self.folder + '/metadata'
    font = TTFont(self.fontfile)
    metadata = {'numGlyphs': 0, 'has_hmtx': False, 'has_vmtx': False}
    metadata['numGlyphs'] = font['maxp'].numGlyphs
    if 'hmtx' in font:
      metadata['has_hmtx'] = True
      metadata['numberOfHMetrics'] = len(font['hmtx'].metrics)
    if 'vmtx' in font:
      metadata['has_vmtx'] = True
      metadata['numberOfVMetrics'] = len(font['vmtx'].metrics)

    dumper = Dumper(output)
    dumper.dumpObject(metadata)
    dumper.close()
Пример #9
0
    def metadata(self):
        output = self.folder + '/metadata'
        font = TTFont(self.fontfile)
        metadata = {'numGlyphs': 0, 'has_hmtx': False, 'has_vmtx': False}
        metadata['numGlyphs'] = font['maxp'].numGlyphs
        if 'hmtx' in font:
            metadata['has_hmtx'] = True
            metadata['numberOfHMetrics'] = len(font['hmtx'].metrics)
        if 'vmtx' in font:
            metadata['has_vmtx'] = True
            metadata['numberOfVMetrics'] = len(font['vmtx'].metrics)

        dumper = Dumper(output)
        dumper.dumpObject(metadata)
        dumper.close()
Пример #10
0
def dump_closure_map(fontfile, outputfolder):
    """Takes closure of each glyph in the font and dump them into the two seperate files.

  Index file used to locate a glyph in data file.
  Data file contains closure lists
  """

    font = TTFont(fontfile)
    closurer = ClosureTaker(font)

    glyph_metadata = Dumper(outputfolder + "/closure_idx")
    glyph_data = Dumper(outputfolder + "/closure_data")
    bigEndian = ">"
    fmt_offset = ">l"  # offset - length
    fmt_size = ">H"
    fmt_elem = "H"
    elem_size = struct.calcsize(fmt_elem)
    offset = 0
    for g in font.getGlyphOrder():
        closurer.clear()
        closurer.add_glyph_names([g])
        glyphsClosure = closurer.closure()
        id = closurer.glyph_name_to_id[g]
        if len(glyphsClosure) == 1 and id in glyphsClosure:
            # recording not needed
            glyph_metadata.dump_fmt(-1, fmt_offset)
            glyph_metadata.dump_fmt(0, fmt_size)
        else:
            size = elem_size * len(glyphsClosure)
            glyph_data.dump_array(glyphsClosure, fmt_elem, bigEndian)
            glyph_metadata.dump_fmt(offset, fmt_offset)
            glyph_metadata.dump_fmt(size, fmt_size)
            # print id, g, glyphsClosure
            offset += size

    font.close()
    glyph_data.close()
    glyph_metadata.close()
Пример #11
0
def dump_closure_map(fontfile, outputfolder):
    """Takes closure of each glyph in the font and dump them into the two seperate files.

  Index file used to locate a glyph in data file.
  Data file contains closure lists
  """

    font = TTFont(fontfile)
    closurer = ClosureTaker(font)

    glyph_metadata = Dumper(outputfolder + '/closure_idx')
    glyph_data = Dumper(outputfolder + '/closure_data')
    bigEndian = '>'
    fmt_offset = '>l'  # offset - length
    fmt_size = '>H'
    fmt_elem = 'H'
    elem_size = struct.calcsize(fmt_elem)
    offset = 0
    for g in font.getGlyphOrder():
        closurer.clear()
        closurer.add_glyph_names([g])
        glyphsClosure = closurer.closure()
        id = closurer.glyph_name_to_id[g]
        if len(glyphsClosure) == 1 and id in glyphsClosure:
            # recording not needed
            glyph_metadata.dump_fmt(-1, fmt_offset)
            glyph_metadata.dump_fmt(0, fmt_size)
        else:
            size = elem_size * len(glyphsClosure)
            glyph_data.dump_array(glyphsClosure, fmt_elem, bigEndian)
            glyph_metadata.dump_fmt(offset, fmt_offset)
            glyph_metadata.dump_fmt(size, fmt_size)
            #print id, g, glyphsClosure
            offset += size

    font.close()
    glyph_data.close()
    glyph_metadata.close()
Пример #12
0
  def cmap_dump(self):
    font = TTFont(self.fontfile)
    cmap = font['cmap'].getcmap(3, 1).cmap  # unicode table
    assert cmap, 'Unicode cmap table required'

    codepoints = []
    glyphs = []

    for code, name in cmap.iteritems():
      id = font.getGlyphID(name)
      glyphs.append(id)
      codepoints.append(code)
      if self.debug:
        print id,name,code
    font.close()

    cp_dumper = Dumper(self.folder + '/codepoints')
    cp_dumper.dump_array(codepoints, 'H', '>')
    cp_dumper.close()

    gid_dumper = Dumper(self.folder + '/gids')
    gid_dumper.dump_array(glyphs, 'H', '>')
    gid_dumper.close()
Пример #13
0
 def sha1_fingerprint(self):
     dumper = Dumper(self.folder + '/sha1_fingerprint')
     fingerprint = FontInfo.getInformation(self.fontfile, ['SHA1'])['SHA1']
     dumper.dump(fingerprint)
     dumper.close()
Пример #14
0
 def sha1_fingerprint(self):
   dumper = Dumper(self.folder + '/sha1_fingerprint')
   fingerprint = FontInfo.getInformation(self.fontfile, ['SHA1'])['SHA1']
   dumper.dump(fingerprint)
   dumper.close()