[test/shaping] Add hb-unicode-prettyname
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 20 Jan 2012 01:28:31 +0000 (20:28 -0500)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 20 Jan 2012 18:27:40 +0000 (13:27 -0500)
test/shaping/hb-unicode-prettyname [new file with mode: 0755]

diff --git a/test/shaping/hb-unicode-prettyname b/test/shaping/hb-unicode-prettyname
new file mode 100755 (executable)
index 0000000..5e6bc7f
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import sys
+import re
+import unicodedata
+
+shorthands = {
+       "ZERO WIDTH NON-JOINER": "ZWNJ",
+       "ZERO WIDTH JOINER": "ZWJ",
+       "NARROW NO-BREAK SPACE": "NNBSP",
+       "COMBINING GRAPHEME JOINER": "CGJ",
+}
+def pretty_name (x):
+       try:
+               s = unicodedata.name (x)
+       except ValueError:
+               return "XXX"
+       s = re.sub (".* LETTER ", "", s)
+       s = re.sub (".* VOWEL SIGN (.*)", r"\1-MATRA", s)
+       s = re.sub (".* SIGN ", "", s)
+       s = re.sub (".* COMBINING ", "", s)
+       if re.match (".* VIRAMA", s):
+               s = "HALANT"
+       if s in shorthands:
+               s = shorthands[s]
+       return s
+
+
+def pretty_names (s):
+       s = re.sub ("[<+>\\]", "", s)
+       s = re.sub ("[uU]", " ", s)
+       print s
+       s = [unichr (int (x, 16)) for x in re.split ('[, ]', s) if len (x)]
+       return ' + '.join (pretty_name (x) for x in s)
+
+if __name__ == '__main__':
+       print pretty_names (','.join (sys.argv[1:]))
+