mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-21 20:42:15 -07:00
Add asset packs font support
This commit is contained in:
@@ -85,6 +85,20 @@ def pack_icon_static(src: pathlib.Path, dst: pathlib.Path):
|
||||
dst.with_suffix(".bmx").write_bytes(convert_bmx(src))
|
||||
|
||||
|
||||
def pack_font(src: pathlib.Path, dst: pathlib.Path):
|
||||
code = src.read_bytes().split(b' U8G2_FONT_SECTION("')[1].split(b'") =')[1].strip()
|
||||
font = b""
|
||||
for line in code.splitlines():
|
||||
if line.count(b'"') == 2:
|
||||
font += (
|
||||
line[line.find(b'"') + 1 : line.rfind(b'"')]
|
||||
.decode("unicode_escape")
|
||||
.encode("latin_1")
|
||||
)
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
dst.with_suffix(".u8f").write_bytes(font)
|
||||
|
||||
|
||||
def pack(
|
||||
input: "str | pathlib.Path", output: "str | pathlib.Path", logger: typing.Callable
|
||||
):
|
||||
@@ -145,6 +159,13 @@ def pack(
|
||||
icon, packed / "Icons" / icons.name / icon.name
|
||||
)
|
||||
|
||||
if (source / "Fonts").is_dir():
|
||||
for font in (source / "Fonts").iterdir():
|
||||
if not font.is_file():
|
||||
continue
|
||||
logger(f"Compile: font for pack '{source.name}': {font.name}")
|
||||
pack_font(font, packed / "Fonts" / font.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
input(
|
||||
|
||||
@@ -85,6 +85,10 @@ def _packs_emitter(target, source, env):
|
||||
target_dir.File(source_dir.rel_path(node).removesuffix(".png") + ".bmx")
|
||||
for node in env.GlobRecursive("*/Icons/**/*.png", source_dir.srcnode())
|
||||
)
|
||||
target.extend(
|
||||
target_dir.File(source_dir.rel_path(node).removesuffix(".c") + ".u8f")
|
||||
for node in env.GlobRecursive("*/Fonts/*.c", source_dir.srcnode())
|
||||
)
|
||||
|
||||
return target, source
|
||||
|
||||
|
||||
Reference in New Issue
Block a user