Skip to content

Commit

Permalink
align chars for vertical text layout #662, add extra padding to avoid…
Browse files Browse the repository at this point in the history
… stroke trunctation
  • Loading branch information
dmMaze committed Dec 1, 2024
1 parent 34a467f commit a7cc082
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions ui/scene_textlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def updateDrawOffsets(self):
yoff = -non_bracket_br[1] - non_bracket_br[3]
yoff = yoff - (line_width - non_bracket_br[3]) / 2

elif vertical_force_aligncentel(char):
else:
space_shift = 0
if num_lspaces > 0:
space_shift = num_lspaces * cfmt.space_width
Expand All @@ -472,15 +472,15 @@ def updateDrawOffsets(self):
tbr, br = cfmt.punc_rect(char)
yoff += (tbr.height() + cfmt.font_metrics.descent() - act_rect[3]) / 2

else:
empty_spacing = num_lspaces * cfmt.space_width
if TEXTLAYOUT_QTVERSION:
xshift = max(line.naturalTextWidth() - cfmt.br.width(), 0)
else:
xshift = empty_spacing
# else:
# empty_spacing = num_lspaces * cfmt.space_width
# if TEXTLAYOUT_QTVERSION:
# xshift = max(line.naturalTextWidth() - cfmt.br.width(), 0)
# else:
# xshift = empty_spacing

xoff = -xshift
yoff = min(cfmt.br.top() - cfmt.tbr.top(), -cfmt.tbr.top() - line.ascent()) + empty_spacing
# xoff = -xshift
# yoff = min(cfmt.br.top() - cfmt.tbr.top(), -cfmt.tbr.top() - line.ascent()) + empty_spacing

xy_offsets[0], xy_offsets[1] = xoff, yoff
block = block.next()
Expand Down
5 changes: 3 additions & 2 deletions ui/textitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def setStrokeWidth(self, stroke_width: float, padding=True, repaint_background=T

self.fontformat.stroke_width = stroke_width
if stroke_width > 0 and padding:
p = self.layout.max_font_size(to_px=True) * stroke_width / 2
p = self.layout.max_font_size(to_px=True) * (stroke_width + 0.05) / 2
self.setPadding(p)

self._after_set_ffmt(cursor, repaint_background, restore_cursor, **after_kwargs)
Expand All @@ -829,7 +829,8 @@ def setFontSize(self, value: float, repaint_background: bool = False, set_select
if repaint_background:
fs = pt2px(max(self.layout.max_font_size(), value))
self.layout.relayout_on_changed = False
self.setPadding(fs * self.fontformat.stroke_width / 2)
if self.fontformat.stroke_width > 0:
self.setPadding(fs * (self.fontformat.stroke_width + 0.05) / 2)
self.layout.relayout_on_changed = True
cfmt = QTextCharFormat()
cfmt.setFontPointSize(value)
Expand Down

0 comments on commit a7cc082

Please sign in to comment.