diff --git a/ui/textitem.py b/ui/textitem.py index 341ad05c..527a7d31 100644 --- a/ui/textitem.py +++ b/ui/textitem.py @@ -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) @@ -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):