Skip to content

Commit

Permalink
font support for pr_464 (ja-JP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Do committed Oct 18, 2024
1 parent 1e1c94f commit 8c87d45
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
50 changes: 25 additions & 25 deletions firmware/font/bdftokff.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
FONT14 = "ter-u14n"
FONT16 = "ter-u16n"
FONT24 = "ter-u24b"
ASIA14 = "FusionPixel-14"
ASIA16 = "unifont-16"
ASIA24 = "NotoSansCJK-24"
WIDE14 = "FusionPixel-14"
WIDE16 = "unifont-16"
WIDE24 = "NotoSansCJK-24"


def open_bdf_save_kff(filename, width, height, replace):
Expand All @@ -44,12 +44,12 @@ def open_bdf_save_kff(filename, width, height, replace):
filename_kff = "bit_dock_yahboom"
elif filename == FONT24:
filename_kff = "amigo"
elif filename == ASIA14:
filename_kff = "m5stickv_asia"
elif filename == ASIA16:
filename_kff = "bit_dock_yahboom_asia"
elif filename == ASIA24:
filename_kff = "amigo_asia"
elif filename == WIDE14:
filename_kff = "m5stickv_wide"
elif filename == WIDE16:
filename_kff = "bit_dock_yahboom_wide"
elif filename == WIDE24:
filename_kff = "amigo_wide"

# Create hexfile based on bdf
font_hex = "\n".join(bdftohex.bdftohex(filename + ".bdf")) + "\n"
Expand All @@ -73,7 +73,7 @@ def open_bdf_save_kff(filename, width, height, replace):
# in order to replace the contents of the unicode[] variable
# in the font.c
wide_glyphs = None
if filename in (ASIA14, ASIA16, ASIA24):
if filename in (WIDE14, WIDE16, WIDE24):
wide_glyphs = ["ko-KR", "zh-CN", "ja-JP"]
font_kff = hextokff.hextokff(filename + ".hex", width, height, wide_glyphs)
with open(filename_kff + ".kff", "w", encoding="utf-8", newline="\n") as save_file:
Expand All @@ -95,14 +95,14 @@ def save_new_fontc(font_name, overwrite=False):
device_name = "dock"
elif font_name == FONT24:
device_name = filename_kff = "amigo"
elif font_name == ASIA14:
filename_kff = "m5stickv_asia"
elif font_name == ASIA16:
filename_kff = "bit_dock_yahboom_asia"
elif font_name == WIDE14:
filename_kff = "m5stickv_wide"
elif font_name == WIDE16:
filename_kff = "bit_dock_yahboom_wide"
device_name = "dock"
elif font_name == ASIA24:
elif font_name == WIDE24:
device_name = "amigo"
filename_kff = "amigo_asia"
filename_kff = "amigo_wide"

maixpy_path_start = "../MaixPy/projects/maixpy_"
maixpy_path_end = (
Expand All @@ -112,7 +112,7 @@ def save_new_fontc(font_name, overwrite=False):
with open(filename_kff + ".kff", "r", encoding="utf-8") as read_file:
content_kff = read_file.read()

if font_name in (ASIA14, ASIA16, ASIA24):
if font_name in (WIDE14, WIDE16, WIDE24):
re_escape_str = "static uint8_t unicode_wide[] = {\n"
content_kff = re_escape_str + content_kff + "\n};"
else:
Expand All @@ -134,7 +134,7 @@ def save_new_fontc(font_name, overwrite=False):
save_file.write(unicode_str)

# Also replace for bit and yahboom
if font_name in (FONT16, ASIA16):
if font_name in (FONT16, WIDE16):
filename = maixpy_path_start + "bit" + maixpy_path_end
with open(filename, "w", encoding="utf-8", newline="\n") as save_file:
save_file.write(unicode_str)
Expand All @@ -144,7 +144,7 @@ def save_new_fontc(font_name, overwrite=False):
save_file.write(unicode_str)

# Also replace for Cube
if font_name in (FONT14, ASIA14):
if font_name in (FONT14, WIDE14):
filename = maixpy_path_start + "cube" + maixpy_path_end
with open(filename, "w", encoding="utf-8", newline="\n") as save_file:
save_file.write(unicode_str)
Expand All @@ -167,14 +167,14 @@ def save_new_fontc(font_name, overwrite=False):
open_bdf_save_kff(FONT14, 8, 14, replace)
open_bdf_save_kff(FONT16, 8, 16, replace)
open_bdf_save_kff(FONT24, 12, 24, replace)
open_bdf_save_kff(ASIA14, 14, 14, replace)
open_bdf_save_kff(ASIA16, 16, 16, replace)
open_bdf_save_kff(ASIA24, 24, 24, replace)
open_bdf_save_kff(WIDE14, 14, 14, replace)
open_bdf_save_kff(WIDE16, 16, 16, replace)
open_bdf_save_kff(WIDE24, 24, 24, replace)

# generate new font.c files (delete kff files)
save_new_fontc(FONT14, replace)
save_new_fontc(FONT16, replace)
save_new_fontc(FONT24, replace)
save_new_fontc(ASIA14, replace)
save_new_fontc(ASIA16, replace)
save_new_fontc(ASIA24, replace)
save_new_fontc(WIDE14, replace)
save_new_fontc(WIDE16, replace)
save_new_fontc(WIDE24, replace)
10 changes: 5 additions & 5 deletions firmware/font/hextokff.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
]
TRANSLATIONS_DIR = "../../i18n/translations"

JAPANESE_CODEPOINT_MIN = 0x3000
JAPANESE_CODEPOINT_MIN = 0x3000 # defined as WIDEFONT_CODEPOINT_MIN in MaixPy
JAPANESE_CODEPOINT_MAX = 0x30FF
CHINESE_CODEPOINT_MIN = 0x4E00
CHINESE_CODEPOINT_MAX = 0x9FFF
KOREAN_CODEPOINT_MIN = 0xAC00
KOREAN_CODEPOINT_MAX = 0xD7A3
FWRANDHWK_CODEPOINT_MIN = 0xFF00 # full width roman and half width katakana
FWRANDHWK_CODEPOINT_MAX = 0xFFEF
FULLHALFWIDTH_CODEPOINT_MIN = 0xFF00
FULLHALFWIDTH_CODEPOINT_MAX = 0xFFEF # defined as WIDEFONT_CODEPOINT_MAX in MaixPy


def hextokff(filename=None, width=None, height=None, wide_glyphs=None):
Expand Down Expand Up @@ -80,9 +80,9 @@ def hextokff(filename=None, width=None, height=None, wide_glyphs=None):
JAPANESE_CODEPOINT_MIN <= ord(char) <= JAPANESE_CODEPOINT_MAX
or CHINESE_CODEPOINT_MIN <= ord(char) <= CHINESE_CODEPOINT_MAX
or KOREAN_CODEPOINT_MIN <= ord(char) <= KOREAN_CODEPOINT_MAX
or FWRANDHWK_CODEPOINT_MIN
or FULLHALFWIDTH_CODEPOINT_MIN
<= ord(char)
<= FWRANDHWK_CODEPOINT_MAX
<= FULLHALFWIDTH_CODEPOINT_MAX
):
# only include if wide_glyphs required by this locale
if wide_glyphs and current_translation in wide_glyphs:
Expand Down

0 comments on commit 8c87d45

Please sign in to comment.