Created
April 19, 2012 17:37
-
-
Save nitoyon/2422505 to your computer and use it in GitHub Desktop.
Cipher text with web font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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