summaryrefslogtreecommitdiff
path: root/asciifarmclient/charmap.py
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-22 14:07:43 +0200
committertroido <troido@protonmail.com>2020-09-22 14:07:43 +0200
commit5baa21f79f3a2fbee8470a54e81ab2aa99770936 (patch)
tree298884dbf16cd1916bb94fd5ccc09dabe5c9b830 /asciifarmclient/charmap.py
parent2397f225381bafeb87262fef4979ee9eae516717 (diff)
charmap with character_width 2 will automatically convert halfwidth to fullwidth
Diffstat (limited to 'asciifarmclient/charmap.py')
-rw-r--r--asciifarmclient/charmap.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/asciifarmclient/charmap.py b/asciifarmclient/charmap.py
index 43ae006..593364c 100644
--- a/asciifarmclient/charmap.py
+++ b/asciifarmclient/charmap.py
@@ -2,9 +2,26 @@
from .utils import get
from ratuil.textstyle import TextStyle
+from ratuil import strwidth
ALPHABET = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+
+def make_text_wide(char):
+ if len(char) != 1 or strwidth.strwidth(char) != 1:
+ return char
+ o = ord(char)
+ if o >= ord('!') and o <= ord('~'): # printable ascii character
+ return chr(o - ord("!") + ord('!')) # fullwidth ascii block
+ if char == " ":
+ return chr(12288) # ideographic space
+ return char + char
+
+def make_sprite_wide(sprite):
+ (char, fg, bg) = sprite
+ return (make_text_wide(char), fg, bg)
+
+
def parseSprite(sprite):
if isinstance(sprite, str):
return (sprite, None, None)
@@ -47,4 +64,12 @@ class CharMap:
for name, colour in jsonmap.get("msgcolours", {}).items():
self.message_styles[name] = TextStyle(*colour)
self.character_width = jsonmap.get("charwidth", self.character_width)
+
+ def make_wide(self):
+ self.default = make_sprite_wide(self.default)
+ mapping = {}
+ for key, sprite in self.mapping.items():
+ mapping[key] = make_sprite_wide(sprite)
+ self.mapping = mapping
+ self.alphabet = "".join(make_text_wide(char) for char in self.alphabet)