fix: lower Chinese full stop to bitmap cell baseline

This commit is contained in:
DragonHD
2026-09-20 11:55:26 +08:00
parent 8a061bc3a0
commit 997ae29355
4 changed files with 100 additions and 0 deletions
+12
View File
@@ -157,6 +157,16 @@ def pick_font(size):
raise SystemExit("no CJK ttf found")
def lower_full_stop(tile):
"""Anchor the Chinese full stop at the bottom of its full-width cell."""
bbox = tile.getchannel('A').getbbox()
if bbox is None:
return tile.copy()
result = Image.new('RGBA', tile.size, (0, 0, 0, 0))
result.paste(tile.crop(bbox), (bbox[0], tile.height - (bbox[3] - bbox[1])))
return result
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--game", default=DEFAULT_GAME)
@@ -211,6 +221,8 @@ def main():
x = col * cell
y = args.cjk_y0 + row * cell
d.text((x, y + args.draw_dy), uni, font=font, fill=(255, 255, 255, 255))
if uni == '\u3002':
atlas.paste(lower_full_stop(atlas.crop((x, y, x + cell, y + cell))), (x, y))
cells[code] = {"x": x, "y": y, "uni": uni}
# sanity: ink must fit the cell
bb = atlas.crop((x, y, x + cell, y + cell)).getbbox()