summaryrefslogtreecommitdiff
path: root/embed_font.py
diff options
context:
space:
mode:
authorIndrajith K L2025-11-03 19:43:05 +0530
committerIndrajith K L2025-11-03 19:43:05 +0530
commit9bb3957d5fd3f176e8bd888c53a65c54f62cfab6 (patch)
tree96aac66d2ef569a3352ee2b634d4e26ef64a25ba /embed_font.py
parent02d6be119fa130121a04799e81aff203472b6233 (diff)
downloadreilua-enhanced-9bb3957d5fd3f176e8bd888c53a65c54f62cfab6.tar.gz
reilua-enhanced-9bb3957d5fd3f176e8bd888c53a65c54f62cfab6.tar.bz2
reilua-enhanced-9bb3957d5fd3f176e8bd888c53a65c54f62cfab6.zip
cleaned up root folder, organized files into docs/scripts/tools dirs
Diffstat (limited to 'embed_font.py')
-rw-r--r--embed_font.py57
1 files changed, 0 insertions, 57 deletions
diff --git a/embed_font.py b/embed_font.py
deleted file mode 100644
index 8144718..0000000
--- a/embed_font.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/env python3
-"""
-Embed font file into C header.
-Usage: python embed_font.py <output.h> <font.ttf>
-"""
-
-import sys
-import os
-
-def embed_file(file_path, var_name):
- """Convert a file to a C byte array"""
- with open(file_path, 'rb') as f:
- data = f.read()
-
- output = f"/* {os.path.basename(file_path)} */\n"
- output += f"static const unsigned char {var_name}[] = {{\n"
-
- # Write bytes in rows of 16
- for i in range(0, len(data), 16):
- chunk = data[i:i+16]
- hex_values = ', '.join(f'0x{b:02x}' for b in chunk)
- output += f" {hex_values},\n"
-
- output += "};\n"
- output += f"static const unsigned int {var_name}_size = {len(data)};\n\n"
-
- return output
-
-def main():
- if len(sys.argv) != 3:
- print("Usage: python embed_font.py <output.h> <font.ttf>")
- sys.exit(1)
-
- output_file = sys.argv[1]
- font_file = sys.argv[2]
-
- # Check if file exists
- if not os.path.exists(font_file):
- print(f"Error: {font_file} not found!")
- sys.exit(1)
-
- # Generate header content
- header_content = "/* Auto-generated embedded font file */\n"
- header_content += "#pragma once\n\n"
-
- # Embed font file
- header_content += embed_file(font_file, "embedded_font_data")
-
- # Write to output file
- with open(output_file, 'w') as f:
- f.write(header_content)
-
- print(f"Generated {output_file}")
- print(f" - Embedded {font_file} ({os.path.getsize(font_file)} bytes)")
-
-if __name__ == "__main__":
- main()