Skip to content

Commit

Permalink
try to fix stroke shifting #650
Browse files Browse the repository at this point in the history
  • Loading branch information
dmMaze committed Nov 15, 2024
1 parent 8c408b1 commit 30acebe
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions ui/textitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,10 @@ def on_content_changed(self):
self.update()

def paint_stroke(self, painter: QPainter):
doc = self.document().clone()
doc.setDocumentMargin(self.padding())
layout = VerticalTextDocumentLayout(doc, self.fontformat) if self.fontformat.vertical \
else HorizontalTextDocumentLayout(doc, self.fontformat)
layout._draw_offset = self.layout._draw_offset
layout.line_spacing = self.fontformat.line_spacing
layout.letter_spacing = self.fontformat.letter_spacing
layout._is_painting_stroke = True
rect = self.rect()
layout.setMaxSize(rect.width(), rect.height(), False)
doc.setDocumentLayout(layout)

layout.relayout_on_changed = False
doc = QTextDocument()
doc.setDocumentMargin(self.document().documentMargin())
doc.setDefaultFont(self.document().defaultFont())
doc.setHtml(self.document().toHtml())
cursor = QTextCursor(doc)
block = doc.firstBlock()
stroke_pen = QPen(self.stroke_qcolor, 0, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)
Expand All @@ -170,6 +161,17 @@ def paint_stroke(self, painter: QPainter):
cursor.mergeCharFormat(cfmt)
it += 1
block = block.next()

layout = VerticalTextDocumentLayout(doc, self.fontformat) if self.fontformat.vertical \
else HorizontalTextDocumentLayout(doc, self.fontformat)
layout._draw_offset = self.layout._draw_offset
layout.line_spacing = self.fontformat.line_spacing
layout.letter_spacing = self.fontformat.letter_spacing
layout._is_painting_stroke = True
layout.setMaxSize(self.layout.max_width, self.layout.max_height, False)
doc.setDocumentLayout(layout)

layout.relayout_on_changed = False
doc.drawContents(painter)

def repaint_background(self):
Expand Down

0 comments on commit 30acebe

Please sign in to comment.