Skip to content

Commit 00e4c9f

Browse files
committed
set some punctuations to align center in vertical mode
1 parent 00b8699 commit 00e4c9f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ui/scene_textlayout.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def print_transform(tr: QTransform):
2323

2424
# https://www.w3.org/TR/2022/DNOTE-clreq-20220801/#tables_of_chinese_punctuation_marks
2525
# https://www.w3.org/TR/2022/DNOTE-clreq-20220801/#glyphs_sizes_and_positions_in_character_faces_of_punctuation_marks
26-
PUNSET_PAUSEORSTOP = {'。', '.', ',', '、', ':', ';', '!', '?'} # dont need to rotate,
27-
PUNSET_ALIGNTOP = {'。', '.', ',', '、'}
26+
PUNSET_PAUSEORSTOP = {'。', '.', ',', '、', '·', ':', ';', '!', '?'} # dont need to rotate,
27+
PUNSET_ALIGNCENTER = {'。', '.', ',', '、', '}
2828
PUNSET_BRACKETL = {'「', '『', '“', '‘', '(', '《', '〈', '【', '〖', '〔', '[', '{', '('}
2929
PUNSET_BRACKETR = {'」', '』', '”', '’', ')', '》', '〉', '】', '〗', '〕', ']', '}'}
3030
PUNSET_BRACKET = PUNSET_BRACKETL.union(PUNSET_BRACKETR)
@@ -124,14 +124,14 @@ def br(self) -> QRectF:
124124
# return get_punc_rect('啊', self.family, self.size, self.weight, self.font.italic())[1]
125125
_, br1 = get_punc_rect('啊', self.family, self.size, self.weight, self.font.italic())
126126
_, br2 = get_punc_rect('木', self.family, self.size, self.weight, self.font.italic())
127-
return QRectF(br2.left(), br2.top(), br1.right() - br2.left(), br2.height())
127+
return QRectF(br2.left(), br2.top(), max(br1.right(), br2.right()) - min(br1.left(), br2.left()), br2.height())
128128

129129
@cached_property
130130
def tbr(self) -> QRectF:
131131
# return get_punc_rect('啊', self.family, self.size, self.weight, self.font.italic())[0]
132132
br1, _ = get_punc_rect('啊', self.family, self.size, self.weight, self.font.italic())
133133
br2, _ = get_punc_rect('木', self.family, self.size, self.weight, self.font.italic())
134-
return QRectF(br2.left(), br2.top(), br1.right() - br2.left(), br2.height())
134+
return QRectF(br2.left(), br2.top(), max(br1.right(), br2.right()) - min(br1.left(), br2.left()), br2.height())
135135

136136
@cached_property
137137
def space_width(self) -> int:
@@ -431,6 +431,11 @@ def updateDrawOffsets(self):
431431
xoff -= natral_shifted
432432
yoff += natral_shifted
433433

434+
if char in PUNSET_ALIGNCENTER:
435+
tbr, br = cfmt.punc_rect(char)
436+
yoff += (tbr.height() + cfmt.font_metrics.descent() - act_rect[3]) / 2
437+
# yoff = 0
438+
434439
else:
435440
empty_spacing = num_lspaces * cfmt.space_width
436441
if TEXTLAYOUT_QTVERSION:
@@ -684,7 +689,7 @@ def layoutBlock(self, block: QTextBlock):
684689
tbr_h -= let_sp_offset
685690
tbr_h += let_sp_offset
686691
elif vertical_force_aligncentel(char):
687-
if char not in PUNSET_ALIGNTOP:
692+
if char not in PUNSET_ALIGNCENTER:
688693
tbr_h = cfmt.punc_actual_rect(line, char, cache=True)[3]
689694
else:
690695
tbr, br = cfmt.punc_rect(char)

0 commit comments

Comments
 (0)