#!/usr/bin/env python # vim: set fileencoding=UTF-8 : # Copyright 2010 Jonas Häggqvist # # BSD license up in this shiznit # # Version 1.0 # Version 1.1 # - fraktur -> boldfraktur # - add fraktur # - add boldscript # - add numbers to doublestruck import sys import codecs import locale ALLRANGES = { 'script': { (65, 90) : 0x1D49C, (97, 122) : 0x1D4B6, }, 'boldscript': { (65, 90) : 0x1D4D0, (97, 122) : 0x1D4EA, }, 'fraktur': { (65, 90) : 0x1D504, (97, 122) : 0x1D51E, }, 'boldfraktur': { (65, 90) : 0x1D56C, (97, 122) : 0x1D586, }, 'doublestruck': { (65, 90) : 0x1D538, (97, 122) : 0x1D552, (48, 57) : 0x1D7D8, }, } def cursifychar(c, ranges): n = ord(c) for (fromrange, torange) in ranges: dest = ranges[(fromrange, torange)] if n >= fromrange and n <= torange: return unichr(n + dest - fromrange) return c def cursify(s, ranges): res = u"" for c in s: res += cursifychar(c, ranges) return res if __name__ == "__main__": sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout); sys.stdin = codecs.getreader(locale.getpreferredencoding())(sys.stdin); line = "x" if len(sys.argv) > 1 and sys.argv[1] in ALLRANGES: ranges = ALLRANGES[sys.argv[1]] else: ranges = ALLRANGES['script'] while line != u"": line = sys.stdin.readline() line = cursify(line, ranges) sys.stdout.write(line)