Skip to content

Commit

Permalink
set some punctuations to align center in vertical mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dmMaze committed Mar 28, 2024
1 parent 00b8699 commit 00e4c9f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ui/scene_textlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def print_transform(tr: QTransform):

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

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

@cached_property
def space_width(self) -> int:
Expand Down Expand Up @@ -431,6 +431,11 @@ def updateDrawOffsets(self):
xoff -= natral_shifted
yoff += natral_shifted

if char in PUNSET_ALIGNCENTER:
tbr, br = cfmt.punc_rect(char)
yoff += (tbr.height() + cfmt.font_metrics.descent() - act_rect[3]) / 2
# yoff = 0

else:
empty_spacing = num_lspaces * cfmt.space_width
if TEXTLAYOUT_QTVERSION:
Expand Down Expand Up @@ -684,7 +689,7 @@ def layoutBlock(self, block: QTextBlock):
tbr_h -= let_sp_offset
tbr_h += let_sp_offset
elif vertical_force_aligncentel(char):
if char not in PUNSET_ALIGNTOP:
if char not in PUNSET_ALIGNCENTER:
tbr_h = cfmt.punc_actual_rect(line, char, cache=True)[3]
else:
tbr, br = cfmt.punc_rect(char)
Expand Down

0 comments on commit 00e4c9f

Please sign in to comment.