Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cipher text with web font
# -*- coding: utf-8 -*-
import fontTools.ttLib.tables
import fontTools.ttLib
s1 = u"コピペできない文章です!! 嘘じゃないよ"
s2 = u"ほら。無理でしょ?絶対に不可能なんです!"
tt = fontTools.ttLib.TTFont("mplus-2p-regular.ttf")
chars = set()
glyphMap = dict()
hmtxMap = dict()
for i in range(len(s1)):
c1 = "uni%04X" % ord(s1[i])
c2 = "uni%04X" % ord(s2[i])
print "%s -> %s" % (c1, c2)
glyphMap[c2] = tt['glyf'].glyphs[c1]
hmtxMap[c2] = tt['hmtx'].metrics[c1]
glyphMap['.notdef'] = tt['glyf'].glyphs['.notdef']
for g in dict(tt['glyf'].glyphs):
if g in chars:
tt['glyf'].glyphs[g] = glyphMap[g]
tt['hmtx'].metrics[g] = hmtxMap[g]
tt['glyf'].glyphs[g] = fontTools.ttLib.tables._g_l_y_f.Glyph()
output_path = "output.ttf"
print "wrote %s" % output_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment