diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-04-08 18:48:12 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-04-08 18:48:12 +0000 |
commit | 5469607a00d84a07dc638eda46a87fc90142d64b (patch) | |
tree | cce121bf02e868c5a711d63e58a43288c461c8c3 /third_party/harfbuzz/contrib/tables/mirroring-parse.py | |
parent | a4e5ed854acf0cc707d8768420ce9fb9313ba60a (diff) |
add
git-svn-id: http://skia.googlecode.com/svn/trunk@536 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'third_party/harfbuzz/contrib/tables/mirroring-parse.py')
-rw-r--r-- | third_party/harfbuzz/contrib/tables/mirroring-parse.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/third_party/harfbuzz/contrib/tables/mirroring-parse.py b/third_party/harfbuzz/contrib/tables/mirroring-parse.py new file mode 100644 index 0000000000..5724e19d75 --- /dev/null +++ b/third_party/harfbuzz/contrib/tables/mirroring-parse.py @@ -0,0 +1,50 @@ +import sys + +# http://www.unicode.org/Public/UNIDATA/auxiliary/BidiMirroring.txt + +# This parses a file in the format of the above file and outputs a table +# suitable for bsearch(3). This table maps Unicode code points to their +# 'mirror'. (Mirroring is used when rendering RTL characters, see the Unicode +# standard). By convention, this mapping should be commutative, but this code +# doesn't enforce or check this. + +def main(infile, outfile): + pairs = [] + for line in infile: + line = line[:-1] + if len(line) == 0 or line[0] == '#': + continue + if '#' in line: + (data, _) = line.split('#', 1) + else: + data = line + if ';' not in data: + continue + (a, b) = data.split(';', 1) + a = int(a, 16) + b = int(b, 16) + + pairs.append((a, b)) + + pairs.sort() + + print >>outfile, '// Generated from Unicode Bidi Mirroring tables\n' + print >>outfile, '#ifndef MIRRORING_PROPERTY_H_' + print >>outfile, '#define MIRRORING_PROPERTY_H_\n' + print >>outfile, '#include <stdint.h>' + print >>outfile, 'struct mirroring_property {' + print >>outfile, ' uint32_t a;' + print >>outfile, ' uint32_t b;' + print >>outfile, '};\n' + print >>outfile, 'static const struct mirroring_property mirroring_properties[] = {' + for pair in pairs: + print >>outfile, ' {0x%x, 0x%x},' % pair + print >>outfile, '};\n' + print >>outfile, 'static const unsigned mirroring_properties_count = %d;\n' % len(pairs) + print >>outfile, '#endif // MIRRORING_PROPERTY_H_' + +if __name__ == '__main__': + if len(sys.argv) != 3: + print 'Usage: %s <input .txt> <output .h>' % sys.argv[0] + else: + main(file(sys.argv[1], 'r'), file(sys.argv[2], 'w+')) |