default_theme_builders.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Functions used to generate source files during build time
  2. All such functions are invoked in a subprocess on Windows to prevent build flakiness.
  3. """
  4. import os
  5. import os.path
  6. from platform_methods import subprocess_main
  7. def make_fonts_header(target, source, env):
  8. dst = target[0]
  9. g = open(dst, "w", encoding="utf-8")
  10. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  11. g.write("#ifndef _DEFAULT_FONTS_H\n")
  12. g.write("#define _DEFAULT_FONTS_H\n")
  13. # Saving uncompressed, since FreeType will reference from memory pointer.
  14. for i in range(len(source)):
  15. with open(source[i], "rb") as f:
  16. buf = f.read()
  17. name = os.path.splitext(os.path.basename(source[i]))[0]
  18. g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
  19. g.write("static const unsigned char _font_" + name + "[] = {\n")
  20. for j in range(len(buf)):
  21. g.write("\t" + str(buf[j]) + ",\n")
  22. g.write("};\n")
  23. g.write("#endif")
  24. g.close()
  25. if __name__ == "__main__":
  26. subprocess_main(globals())