Пример #1
0
 def font_desecret(self, font_url, string_list):
     bin_data = base64.decodebytes(font_url.encode())
     font = TTFont(BytesIO(bin_data))
     font.saveXML("text.xml")
     font = TTFont(BytesIO(bin_data))
     c = font['cmap'].tables[0].ttFont.tables['cmap'].tables[0].cmap
     res_ls = []
     for string in string_list:
         res_str = ''
         for char in string:
             try:
                 decode_num = ord(char)
                 num = c[decode_num]
                 num = int(num[-2:]) - 1
             except:
                 num = "."
             res_str += str(num)
         res_ls.append(res_str)
     return res_ls
Пример #2
0
import fontTools
from fontTools.ttLib.ttFont import TTFont
#
font = TTFont('maoyan7.woff')

font.saveXML('local_fonts7.xml')

# # 每一个数字虽然对应多个16进制,但是对应一个唯一坐标
# f = font.getGlyphOrder()[2]
# print(f)
# print(font['glyf'][f].coordinates)
# print(font['glyf'][f].coordinates.array)
# print(font['glyf'][f].coordinates.array.tobytes())
# print(font['glyf'][f].coordinates.array.tobytes().hex())
# '7e01f5ff1d01e2ff2401230206010402d900e601a400c7017200bb0170000f02b0003102f90064020f01760221018c023001af025201cc027e01d1027e01e6ff'
# '7f01f1ff1e01e6ff2401230203011102c900e6019d00b8016900b70174001a02ac003102f40064020b017702210196022f01ae024401bd028201d1027801e6ff'
# '7f01e6ff2401e6ff24011e020301fe01ce00db019000b9016700ba0170000b02b600310201015e0206017d02260196023801b8024a01c6027001c2027e01e5ff'
#
# # print(font.keys())  # ['GlyphOrder', 'head', 'hhea', 'maxp', 'OS/2', 'hmtx', 'cmap', 'loca', 'glyf', 'name', 'post', 'GSUB']
# #
# # # 获取getGlyphOrder节点的name值,返回为列表
# # print(font.getGlyphOrder())  # ['glyph00000', 'x', 'uniF013', 'uniF4D4', 'uniEE40', 'uniF7E1', 'uniF34B', 'uniE1A0', 'uniF1BE', 'uniE91E', 'uniF16F', 'uniF724']
# # print(font.getGlyphNames())
# # print(font.getBestCmap())
# #
# s =""""""
# print(s)
# print(ord(s))
# ''
#
# #