From b3dec8c153feb3a6e617f7dbf3ac84a9af299ad9 Mon Sep 17 00:00:00 2001 From: Jean Do Date: Wed, 28 Aug 2024 11:38:31 -0400 Subject: [PATCH] adjusted: font constant names, font range conditions --- firmware/font/hextokff.py | 13 ++++++++----- simulator/kruxsim/mocks/lcd.py | 30 ++++++++++++++++++++---------- src/krux/display.py | 2 +- tests/test_display.py | 13 +++++++++---- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/firmware/font/hextokff.py b/firmware/font/hextokff.py index 5cd74a42..fd518e89 100644 --- a/firmware/font/hextokff.py +++ b/firmware/font/hextokff.py @@ -36,10 +36,10 @@ ] TRANSLATIONS_DIR = "../../i18n/translations" -CHINESE_MIN_CODEPOINT = 0x4E00 -CHINESE_MAX_CODEPOINT = 0x9FFF -KOREAN_MIN_CODEPOINT = 0xAC00 -KOREAN_MAX_CODEPOINT = 0xD7A3 +CHINESE_CODEPOINT_MIN = 0x4E00 +CHINESE_CODEPOINT_MAX = 0x9FFF +KOREAN_CODEPOINT_MIN = 0xAC00 +KOREAN_CODEPOINT_MAX = 0xD7A3 def hextokff(filename=None, width=None, height=None, wide_glyphs=None): @@ -72,7 +72,10 @@ def hextokff(filename=None, width=None, height=None, wide_glyphs=None): for translation in translations.values(): for char in translation: # If is Chinese or Korean codepoint - if CHINESE_MIN_CODEPOINT <= ord(char) <= KOREAN_MAX_CODEPOINT: + if ( + CHINESE_CODEPOINT_MIN <= ord(char) <= CHINESE_CODEPOINT_MAX + or KOREAN_CODEPOINT_MIN <= ord(char) <= KOREAN_CODEPOINT_MAX + ): # only include if wide_glyphs is ko-KR if wide_glyphs and current_translation in wide_glyphs: used_codepoints.add(ord(char)) diff --git a/simulator/kruxsim/mocks/lcd.py b/simulator/kruxsim/mocks/lcd.py index b1cd4479..1a640fc3 100644 --- a/simulator/kruxsim/mocks/lcd.py +++ b/simulator/kruxsim/mocks/lcd.py @@ -34,8 +34,8 @@ WIDTH = BOARD_CONFIG["lcd"]["width"] HEIGHT = BOARD_CONFIG["lcd"]["height"] -CHINESE_MIN_CODEPOINT = 0x4E00 -CHINESE_MAX_CODEPOINT = 0x9FFF +CHINESE_CODEPOINT_MIN = 0x4E00 +CHINESE_CODEPOINT_MAX = 0x9FFF KOREAN_CODEPOINT_MIN = 0xAC00 KOREAN_CODEPOINT_MAX = 0xD7A3 @@ -148,12 +148,15 @@ def _is_x_flipped(): def string_width_px(string): standard_width = BOARD_CONFIG["krux"]["display"]["font"][0] - ko_width = BOARD_CONFIG["krux"]["display"]["font_wide"][0] + wide_width = BOARD_CONFIG["krux"]["display"]["font_wide"][0] string_width = 0 for c in string: - if CHINESE_MIN_CODEPOINT < ord(c) < KOREAN_CODEPOINT_MAX: - string_width += ko_width + if ( + CHINESE_CODEPOINT_MIN <= ord(c) <= CHINESE_CODEPOINT_MAX + or KOREAN_CODEPOINT_MIN <= ord(c) <= KOREAN_CODEPOINT_MAX + ): + string_width += wide_width else: string_width += standard_width @@ -161,15 +164,24 @@ def string_width_px(string): def string_has_wide_glyph(string): for c in string: - if CHINESE_MIN_CODEPOINT < ord(c) < KOREAN_CODEPOINT_MAX: + if ( + CHINESE_CODEPOINT_MIN <= ord(c) <= CHINESE_CODEPOINT_MAX + or KOREAN_CODEPOINT_MIN <= ord(c) <= KOREAN_CODEPOINT_MAX + ): return True return False def is_wide(c): - return CHINESE_MIN_CODEPOINT < ord(c) < KOREAN_CODEPOINT_MAX + return ( + CHINESE_CODEPOINT_MIN <= ord(c) <= CHINESE_CODEPOINT_MAX + or KOREAN_CODEPOINT_MIN <= ord(c) <= KOREAN_CODEPOINT_MAX + ) def char_width(c): - if CHINESE_MIN_CODEPOINT < ord(c) < KOREAN_CODEPOINT_MAX: + if ( + CHINESE_CODEPOINT_MIN <= ord(c) <= CHINESE_CODEPOINT_MAX + or KOREAN_CODEPOINT_MIN <= ord(c) <= KOREAN_CODEPOINT_MAX + ): return BOARD_CONFIG["krux"]["display"]["font_wide"][0] else: return BOARD_CONFIG["krux"]["display"]["font"][0] @@ -244,8 +256,6 @@ def run(): ), ) x_position += char_width(c) if BOARD_CONFIG["type"] != "amigo" else -char_width(c) - - color = rgb565torgb888(color) bgcolor = rgb565torgb888(bgcolor) diff --git a/src/krux/display.py b/src/krux/display.py index 08a750be..9d87e2f8 100644 --- a/src/krux/display.py +++ b/src/krux/display.py @@ -29,7 +29,7 @@ DEFAULT_PADDING = 10 MINIMAL_PADDING = 5 FONT_WIDTH, FONT_HEIGHT = board.config["krux"]["display"]["font"] -FONT_WIDTH_WIDE, FONT_HEIGHT_KO = board.config["krux"]["display"]["font_wide"] +FONT_WIDTH_WIDE, FONT_HEIGHT_WIDE = board.config["krux"]["display"]["font_wide"] PORTRAIT, LANDSCAPE = [2, 3] if board.config["type"] == "cube" else [1, 2] QR_DARK_COLOR, QR_LIGHT_COLOR = ( [16904, 61307] if board.config["type"] == "m5stickv" else [0, 6342] diff --git a/tests/test_display.py b/tests/test_display.py index 75138ca6..d8285547 100644 --- a/tests/test_display.py +++ b/tests/test_display.py @@ -2,6 +2,8 @@ b"\x7fn\xfd\x830\x08v9\xd6\xedj\xa0\xdbUU7\xc8\xa0\xe0_U\x7f\x00i\x00\xe3\xd61P\x08\xf5Q\xef^\xfe`\xe8\xc1\x7f\xdex\x936Y\x91\xb8\xeb\xd29c\xd5\xd4\x7f\x00\n#\xfe\xcd\xd7\rJ\x8e\xd9\xe5\xf8\xb9K\xe6x\x17\xb9\xca\xa0\x9a\x9a\x7f\xbb\x1b\x01" ) +CHINESE_CODEPOINT_MIN = 0x4E00 +CHINESE_CODEPOINT_MAX = 0x9FFF KOREAN_CODEPOINT_MIN = 0xAC00 KOREAN_CODEPOINT_MAX = 0xD7A3 @@ -10,14 +12,17 @@ def string_width_px(string): import board standard_width = board.config["krux"]["display"]["font"][0] - ko_width = board.config["krux"]["display"]["font_wide"][0] + wide_width = board.config["krux"]["display"]["font_wide"][0] print("standard_width:", standard_width) - print("ko_width:", ko_width) + print("wide_width:", wide_width) string_width = 0 for c in string: - if KOREAN_CODEPOINT_MIN < ord(c) < KOREAN_CODEPOINT_MAX: - string_width += ko_width + if ( + CHINESE_CODEPOINT_MIN <= ord(c) <= CHINESE_CODEPOINT_MAX + or KOREAN_CODEPOINT_MIN <= ord(c) <= KOREAN_CODEPOINT_MAX + ): + string_width += wide_width else: string_width += standard_width