default_theme_builders.py 982 B

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