fix: center tutorial introduction paragraphs
This commit is contained in:
@@ -7,7 +7,7 @@ from test_cjk_layout import layout
|
||||
|
||||
|
||||
class IntroTests(unittest.TestCase):
|
||||
def test_intro_paragraphs_are_left_aligned_without_orphan_punctuation(self):
|
||||
def test_intro_paragraphs_are_centered_without_orphan_punctuation(self):
|
||||
mapping = json.loads(Path(__file__).with_name('tutorial_cn.json').read_text(encoding='utf-8'))
|
||||
intros = [v for k, v in mapping.items() if k.startswith('\fNow')]
|
||||
self.assertEqual(len(intros), 2)
|
||||
@@ -15,7 +15,9 @@ class IntroTests(unittest.TestCase):
|
||||
for width in (360, 400, 480):
|
||||
lines, _ = layout(intro, width=width, alignment=0)
|
||||
for raw, x, y in lines:
|
||||
self.assertEqual(x, 0)
|
||||
text = raw.decode("gb2312")
|
||||
pixels = sum(5 if c == " " else 8 if ord(c) < 128 else 12 for c in text)
|
||||
self.assertEqual(x, (width - pixels) // 2)
|
||||
self.assertNotIn(raw.decode('gb2312')[0], ',。!?、;:”)')
|
||||
self.assertEqual(len(lines), 4)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user