This commit is contained in:
JiXieShi
2024-09-21 13:18:06 +08:00
parent 919a9ed1a7
commit 4e53f936d8
5 changed files with 45 additions and 39 deletions

View File

@@ -89,14 +89,14 @@ def generate_chinese_array(input_str, font_str, size):
def format_chinese_array_as_text(chinese_array, size):
text_output = "#pragma once\n\n"
text_output += "#ifndef HW_LIB_OLED_FONT_CHUC_H\n"
text_output += "#define HW_LIB_OLED_FONT_CHUC_H\n\n"
text_output += "#ifndef HW_LIB_FONT_CHUC_H\n"
text_output += "#define HW_LIB_FONT_CHUC_H\n\n"
text_output += f"typedef struct {{\n"
text_output += " uint8_t unicode[2];\n"
text_output += f" uint8_t data[{size[0] * ((size[1] + 7) // 8 * 8) // 8}];\n"
text_output += "} Chinese_t;\n\n"
text_output += f"uint8_t Hzk_size={size[0]};\n\n"
text_output += "Chinese_t Hzk[] = {\n"
text_output += f"static uint8_t Hzk_size={size[0]};\n\n"
text_output += "static Chinese_t Hzk[] = {\n"
line_size = size[0] * size[1] // 8
line_size = line_size // 2
# line_size = 16 if line_size >= 16 else 8
@@ -111,7 +111,7 @@ def format_chinese_array_as_text(chinese_array, size):
text_output += '\n '.join(bytes_lines)
text_output += ",\n }\n },\n"
text_output += "};\n\n"
text_output += "Chinese_t* find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {\n"
text_output += "static Chinese_t* find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {\n"
text_output += " for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {\n"
text_output += " if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {\n"
text_output += " return &Hzk[i];\n"
@@ -119,7 +119,7 @@ def format_chinese_array_as_text(chinese_array, size):
text_output += " }\n"
text_output += " return NULL;\n"
text_output += "}\n"
text_output += "\n#endif //HW_LIB_OLED_FONT_CHUC_H"
text_output += "\n#endif //HW_LIB_FONT_CHUC_H"
return text_output