2024-03-12 02:05:37 +08:00
|
|
|
"""Functions used to generate source files during build time"""
|
2024-01-15 20:14:55 +08:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
def make_fonts_header(target, source, env):
|
2024-03-12 02:05:37 +08:00
|
|
|
dst = str(target[0])
|
2024-01-15 20:14:55 +08:00
|
|
|
|
2024-03-11 01:09:48 +08:00
|
|
|
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")
|
2024-01-15 20:14:55 +08:00
|
|
|
|
2024-03-11 01:09:48 +08:00
|
|
|
# Saving uncompressed, since FreeType will reference from memory pointer.
|
|
|
|
for i in range(len(source)):
|
2024-03-12 02:05:37 +08:00
|
|
|
file = str(source[i])
|
|
|
|
with open(file, "rb") as f:
|
2024-03-11 01:09:48 +08:00
|
|
|
buf = f.read()
|
2024-01-15 20:14:55 +08:00
|
|
|
|
2024-03-12 02:05:37 +08:00
|
|
|
name = os.path.splitext(os.path.basename(file))[0]
|
2024-01-15 20:14:55 +08:00
|
|
|
|
2024-03-11 01:09:48 +08:00
|
|
|
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")
|
2024-01-15 20:14:55 +08:00
|
|
|
|
2024-03-11 01:09:48 +08:00
|
|
|
g.write("};\n")
|
2024-01-15 20:14:55 +08:00
|
|
|
|
2024-03-11 01:09:48 +08:00
|
|
|
g.write("#endif")
|