www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

format_json.py (701B)


      1 #!/usr/bin/env python
      2 
      3 import sys
      4 import json
      5 
      6 props = ['depth', 'height', 'italic', 'skew']
      7 
      8 if len(sys.argv) > 1:
      9     if sys.argv[1] == '--width':
     10         props.append('width')
     11 
     12 data = json.load(sys.stdin)
     13 sep = "module.exports = {\n    "
     14 for font in sorted(data):
     15     sys.stdout.write(sep + json.dumps(font))
     16     sep = ": {\n        "
     17     for glyph in sorted(data[font], key=int):
     18         sys.stdout.write(sep + json.dumps(glyph) + ": ")
     19 
     20         values = [value if value != 0.0 else 0 for value in
     21                   [data[font][glyph][key] for key in props]]
     22 
     23         sys.stdout.write(json.dumps(values))
     24         sep = ",\n        "
     25     sep = ",\n    },\n    "
     26 sys.stdout.write(",\n    },\n};\n")