default_theme_builders.py 1.1 KB

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