示例#1
0
 def __zero_charset_fmt(self,output):
   font = TTFont(output)
   cffTableOffset = font.reader.tables['CFF '].offset
   cffTable = font['CFF '].cff
   assert len(cffTable.fontNames) == 1 #only one font should be present
   charsetOffset = cffTable[cffTable.fontNames[0]].rawDict['charset']
   numGlyphs = font['maxp'].numGlyphs
   inner_file = font.reader.file
   inner_file.seek(cffTableOffset+charsetOffset)
   format = readCard8(inner_file);
   if format != 2 and format != 1:
     return None
   record_len = 4 if format == 2 else 3
   seenGlyphCount = 0
   size = 0
   while seenGlyphCount < numGlyphs:
     inner_file.seek(2,io.SEEK_CUR)
     if format == 2:
       nLeft = readCard16(inner_file)
     else: #format 1
       nLeft = readCard8(inner_file)
     seenGlyphCount += nLeft + 1
     size += 1
   font.close()
   filler = Filler(output)
   filler.fill(cffTableOffset+charsetOffset+1, record_len*size, '\x00')
   filler.close()
示例#2
0
    def type6_7(font):
        cffTableOffset = font.reader.tables['CFF '].offset
        cffTable = font['CFF '].cff
        assert len(cffTable.fontNames) == 1  #only one font should be present
        charsetOffset = cffTable[cffTable.fontNames[0]].rawDict['charset']
        numGlyphs = font['maxp'].numGlyphs
        inner_file = font.reader.file
        inner_file.seek(cffTableOffset + charsetOffset)
        format = readCard8(inner_file)
        if format != 2 and format != 1:
            return None
        seenGlyphCount = 0
        firstArr = []
        nLeftArr = []
        while seenGlyphCount < numGlyphs:
            first = readCard16(inner_file)
            if format == 2:
                nLeft = readCard16(inner_file)
            elif format == 1:
                nLeft = readCard8(inner_file)
            firstArr.append(first)
            nLeftArr.append(nLeft)
            seenGlyphCount += nLeft + 1
        rangeCount = len(firstArr)
        #print 'charset size',rangeCount*4+1,'bytes'
        gos_data = Bits()
        escaped_data = Bits()
        gos_data.frombytes(struct.pack('>L', cffTableOffset + charsetOffset))
        if format == 2:
            gos_data.frombytes(struct.pack('>B', 6))  #format 2
        elif format == 1:
            gos_data.frombytes(struct.pack('>B', 7))  #format 1
        gos_data.frombytes(struct.pack('>H', rangeCount))
        deltaFirst = generateDeltaArray(firstArr)
        deltaNLeft = generateDeltaArray(nLeftArr)
        for idx in xrange(rangeCount):
            first_enc = NumberEncoders.BitEncodeAllOnesEscape(
                deltaFirst[idx], 5)
            extend_bits_or_escape(gos_data, escaped_data, first_enc)
            nLeft_enc = NumberEncoders.BitEncodeAllOnesEscape(
                deltaNLeft[idx], 3)
            extend_bits_or_escape(gos_data, escaped_data, nLeft_enc)

        whole_data = gos_data.tobytes() + escaped_data.tobytes()
        #print 'type6 size',len(whole_data)
        return whole_data
示例#3
0
  def type6_7(font):
    cffTableOffset = font.reader.tables['CFF '].offset
    cffTable = font['CFF '].cff
    assert len(cffTable.fontNames) == 1 #only one font should be present
    charsetOffset = cffTable[cffTable.fontNames[0]].rawDict['charset']
    numGlyphs = font['maxp'].numGlyphs
    inner_file = font.reader.file
    inner_file.seek(cffTableOffset+charsetOffset)
    format = readCard8(inner_file);
    if format != 2 and format != 1:
      return None
    seenGlyphCount = 0
    firstArr = []
    nLeftArr = []
    while seenGlyphCount < numGlyphs:
      first = readCard16(inner_file)
      if format == 2:
        nLeft = readCard16(inner_file)
      elif format == 1:
        nLeft = readCard8(inner_file)
      firstArr.append(first)
      nLeftArr.append(nLeft)
      seenGlyphCount += nLeft + 1
    rangeCount = len(firstArr)
    #print 'charset size',rangeCount*4+1,'bytes'
    gos_data = Bits()
    escaped_data = Bits()
    gos_data.frombytes(struct.pack('>L',cffTableOffset+charsetOffset))
    if format == 2:
      gos_data.frombytes(struct.pack('>B',6)) #format 2
    elif format == 1:
      gos_data.frombytes(struct.pack('>B',7)) #format 1
    gos_data.frombytes(struct.pack('>H',rangeCount))
    deltaFirst = generateDeltaArray(firstArr)
    deltaNLeft = generateDeltaArray(nLeftArr)
    for idx in xrange(rangeCount):
      first_enc = NumberEncoders.BitEncodeAllOnesEscape(deltaFirst[idx],5)
      extend_bits_or_escape(gos_data, escaped_data, first_enc)
      nLeft_enc = NumberEncoders.BitEncodeAllOnesEscape(deltaNLeft[idx],3)
      extend_bits_or_escape(gos_data, escaped_data, nLeft_enc)

    whole_data = gos_data.tobytes() + escaped_data.tobytes()
    #print 'type6 size',len(whole_data)
    return whole_data