def __zero_cmaps(self,output): font = TTFont(output) old_cmap_method = change_method(_c_m_a_p.table__c_m_a_p, _decompile_in_table_cmap,'decompile') old_12_method = change_method(_c_m_a_p.cmap_format_12_or_13,_decompile_in_cmap_format_12_13, 'decompile') old_4_method = change_method(_c_m_a_p.cmap_format_4,_decompile_in_cmap_format_4, 'decompile') cmap_offset = font.reader.tables['cmap'].offset cmapTables = font['cmap'] cmap12 = cmapTables.getcmap(3, 10) #format 12 cmap4 = cmapTables.getcmap(3, 1) #format 4 ranges_to_zero = [] if cmap12: ranges_to_zero.append((cmap_offset+cmap12.offset+16,cmap12.length-16)) #if cmap4: # ranges_to_zero.append((cmap_offset+cmap4.offset+14,cmap4.length-14)) change_method(_c_m_a_p.cmap_format_12_or_13,old_12_method,'decompile') change_method(_c_m_a_p.cmap_format_4,old_4_method,'decompile') change_method(_c_m_a_p.table__c_m_a_p,old_cmap_method,'decompile') font.close() #if len(ranges_to_zero)<2: #return if both doesn't exist # return for block in ranges_to_zero: filler = Filler(output) filler.fill(block[0], block[1], '\x00') filler.close()
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()
def __zero_loca(self, output): # more advanced filling needed self.font = TTFont(output) loca_off = self.font.reader.tables['loca'].offset loca_len = self.font.reader.tables['loca'].length self.font.close() filler = Filler(output) filler.fill(loca_off, loca_len, '\0') filler.close()
def __zero_glyf(self, output): self.font = TTFont(output) glyf_off = self.font.reader.tables['glyf'].offset glyf_len = self.font.reader.tables['glyf'].length self.font.close() filler = Filler(output) filler.fill(glyf_off, glyf_len, '\0') filler.close()
def __zero_glyf(self, output): self.font = TTFont(output) # Do not clear the .notdef outlines offset_table = self.font['loca'].locations notdef_len = offset_table[1] - offset_table[0] glyf_off = self.font.reader.tables['glyf'].offset + notdef_len glyf_len = self.font.reader.tables['glyf'].length - notdef_len self.font.close() filler = Filler(output) filler.fill(glyf_off, glyf_len, '\x00') filler.close()
def __end_char_strings(self, output): self.font = TTFont(output) assert 'CFF ' in self.font cffTableOffset = self.font.reader.tables['CFF '].offset cffTable = self.font['CFF '].cff assert len(cffTable.fontNames) == 1 charStringOffset = cffTable[cffTable.fontNames[0]].rawDict['CharStrings'] inner_file = self.font.reader.file inner_file.seek(cffTableOffset + charStringOffset) rawIndexFile = Index(inner_file) baseOffset = rawIndexFile.offsetBase size = rawIndexFile.offsets[-1] - 1 offset = baseOffset + rawIndexFile.offsets[0] self.font.close() filler = Filler(output) filler.fill(offset, size, '\x00') filler.close()
def __zero_char_strings(self, output): self.font = TTFont(output) assert 'CFF ' in self.font cffTableOffset = self.font.reader.tables['CFF '].offset cffTable = self.font['CFF '].cff assert len(cffTable.fontNames) == 1 charStringOffset = cffTable[cffTable.fontNames[0]].rawDict['CharStrings'] inner_file = self.font.reader.file inner_file.seek(cffTableOffset + charStringOffset) rawIndexFile = Index(inner_file) baseOffset = rawIndexFile.offsetBase notdef_glyph_size = rawIndexFile.offsets[1] - rawIndexFile.offsets[0] size = rawIndexFile.offsets[-1] - 1 - notdef_glyph_size offset = baseOffset + rawIndexFile.offsets[0] + notdef_glyph_size self.font.close() filler = Filler(output) filler.fill(offset, size, '\x00') filler.close()