fix: lower Chinese full stop to bitmap cell baseline
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import unittest
|
||||
from PIL import Image
|
||||
from build_cjk import lower_full_stop, image_to_tga, tga_to_image
|
||||
from fix_full_stop import patch_atlas
|
||||
|
||||
|
||||
class FullStopTests(unittest.TestCase):
|
||||
def test_ink_moves_to_bottom_without_shape_loss(self):
|
||||
tile = Image.new('RGBA', (12, 12))
|
||||
for x, y in [(3, 5), (4, 5), (2, 6), (5, 6), (2, 7), (5, 7), (3, 8), (4, 8)]:
|
||||
tile.putpixel((x, y), (255, 255, 255, 255))
|
||||
fixed = lower_full_stop(tile)
|
||||
self.assertEqual(fixed.getbbox(), (2, 8, 6, 12))
|
||||
self.assertEqual(tile.crop((2, 5, 6, 9)).tobytes(), fixed.crop((2, 8, 6, 12)).tobytes())
|
||||
self.assertEqual(lower_full_stop(fixed).tobytes(), fixed.tobytes())
|
||||
|
||||
def test_patch_preserves_neighbors_header_footer_and_orientation(self):
|
||||
for desc in (8, 40):
|
||||
image = Image.new('RGBA', (24, 24), (7, 8, 9, 255))
|
||||
image.paste((0, 0, 0, 0), (12, 12, 24, 24))
|
||||
image.putpixel((14, 17), (255, 255, 255, 255))
|
||||
raw = image_to_tga(image, desc, b'unchanged-footer')
|
||||
meta = {'cell': 12, 'atlas': [24, 24], 'cells': {'41379': {'uni': '。', 'x': 12, 'y': 12}}}
|
||||
fixed = patch_atlas(raw, meta)
|
||||
after, _ = tga_to_image(fixed)
|
||||
self.assertEqual(fixed[:18], raw[:18])
|
||||
self.assertTrue(fixed.endswith(b'unchanged-footer'))
|
||||
self.assertEqual(after.crop((0, 0, 24, 12)).tobytes(), image.crop((0, 0, 24, 12)).tobytes())
|
||||
self.assertEqual(after.crop((0, 12, 12, 24)).tobytes(), image.crop((0, 12, 12, 24)).tobytes())
|
||||
self.assertEqual(after.getpixel((14, 23)), (255, 255, 255, 255))
|
||||
self.assertEqual(patch_atlas(fixed, meta), fixed)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user