Skip to content

Instantly share code, notes, and snippets.

@nitoyon
Created April 19, 2012 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitoyon/2422505 to your computer and use it in GitHub Desktop.
Save nitoyon/2422505 to your computer and use it in GitHub Desktop.
Cipher text with web font
#!/usr/bin/python
# -*- 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])
chars.add(c2);
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]
else:
tt['glyf'].glyphs[g] = fontTools.ttLib.tables._g_l_y_f.Glyph()
output_path = "output.ttf"
tt.save(output_path)
print "wrote %s" % output_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment