mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-27 01:58:09 -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(
|
||||
|
||||
Reference in New Issue
Block a user