virtualx-engine/editor/themes/editor_theme_builders.py
2024-03-10 12:57:57 -05:00

38 lines
1.1 KiB
Python

"""
Functions used to generate source files during build time
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
"""
import os
from platform_methods import subprocess_main
def make_fonts_header(target, source, env):
dst = target[0]
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _EDITOR_FONTS_H\n")
g.write("#define _EDITOR_FONTS_H\n")
# Saving uncompressed, since FreeType will reference from memory pointer.
for i in range(len(source)):
with open(source[i], "rb") as f:
buf = f.read()
name = os.path.splitext(os.path.basename(source[i]))[0]
g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
g.write("static const unsigned char _font_" + name + "[] = {\n")
for j in range(len(buf)):
g.write("\t" + str(buf[j]) + ",\n")
g.write("};\n")
g.write("#endif")
if __name__ == "__main__":
subprocess_main(globals())