diff options
| author | yum <yum.food.vr@gmail.com> | 2022-11-05 20:58:46 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2022-11-05 20:58:46 -0700 |
| commit | 9b27108a93b2093a348a17e2d354f9cdd240693c (patch) | |
| tree | 44cfcb29ac2d17369203129e5a7f36619867008e /generate_fonts.py | |
| parent | 531969f0074f35059a90e6c3007c30feb19f13d5 (diff) | |
Expand character set from 80 to 64K characters
Each character is now addressed with 2 bytes instead of 1. The number of
bytes per character is configured in (I think) exactly one spot, so
increasing or decreasing this is trivial. English speakers can just set
it to 1.
The animator seems a little unstable; if I leave my character in a
public for a while, the board becomes unresponsive. Oh well.
* Check in fonts. Did this so users don't have to remember to set the
resolution or to disable mipmaps.
Diffstat (limited to 'generate_fonts.py')
| -rw-r--r-- | generate_fonts.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/generate_fonts.py b/generate_fonts.py index ccd9870..c21382d 100644 --- a/generate_fonts.py +++ b/generate_fonts.py @@ -5,8 +5,9 @@ from PIL import Image, ImageFont, ImageDraw import math # Use a power of 2 pixels per character so we can evenly divide the plane. -font_pixels = 64 +font_pixels = 128 font = ImageFont.truetype("unifont-15.0.01.ttf", font_pixels) +font_half_sz = ImageFont.truetype("unifont-15.0.01.ttf", int(font_pixels / 2)) n_rows = 64 n_cols = 128 @@ -60,8 +61,8 @@ total_textures = math.ceil(total_rows / n_rows) print("total textures {}".format(total_textures)) for nth_texture in range(0, total_textures): - # Create a 4K grayscale ("L") image - image = Image.new(mode="L", size=(4096,4096), color=0) + # Create an 8K grayscale ("L") image + image = Image.new(mode="1", size=(8192,8192), color=0) draw = ImageDraw.Draw(image) row_begin = nth_texture * n_rows @@ -71,11 +72,19 @@ for nth_texture in range(0, total_textures): for col in range(0, n_cols): # Generate the unicode character for this spot. n = row * n_cols + col + char = None if n in allowlist: - line += chr(n) + char = chr(n) else: - line += " " - draw.text((0, (row - row_begin) * font_pixels), line, font=font, fill=255) + char = " " + # Hack: Chinese, Japanese, and Korean characters are all double + # width and are all on textures [1,6]. To fit them in the same + # grid, we use a half-size font. + if nth_texture == 0: + draw.text((col * font_pixels / 2, (row - row_begin) * font_pixels), char, font=font, fill=255) + else: + draw.text((col * font_pixels / 2, (row - row_begin) * font_pixels), char, + font=font_half_sz, fill=255) image.save("font-%01d.png" % nth_texture) |
