Loading ballontranslator/ui/textitem.py +25 −10 Original line number Diff line number Diff line Loading @@ -65,15 +65,31 @@ class TextBlkItem(QGraphicsTextItem): def repaint_background(self): self.repainting = True doc = self.document() doc = self.document().clone() doc.setDocumentMargin(self.document().documentMargin()) layout = VerticalTextDocumentLayout(doc) if self.is_vertical else HorizontalTextDocumentLayout(doc) rect = self.rect() doc.setDocumentLayout(layout) layout.setMaxSize(rect.width(), rect.height()) sw = self.stroke_width * pt2px(self.document().defaultFont().pointSizeF()) format = QTextCharFormat() format.setTextOutline (QPen(self.stroke_color, sw, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)) cursor = QTextCursor(doc) cursor.select(QTextCursor.Document) old_fmt = cursor.charFormat() cursor.mergeCharFormat(format) block = doc.firstBlock() stroke_pen = QPen(self.stroke_color, 0, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin) while block.isValid(): it = block.begin() while not it.atEnd(): fragment = it.fragment() cfmt = fragment.charFormat() sw = pt2px(cfmt.fontPointSize()) * self.stroke_width stroke_pen.setWidthF(sw) pos1 = fragment.position() pos2 = pos1 + fragment.length() cursor.setPosition(pos1) cursor.setPosition(pos2, QTextCursor.KeepAnchor) cfmt.setTextOutline(stroke_pen) cursor.mergeCharFormat(cfmt) it += 1 block = block.next() size = self.boundingRect().size() self.background_pixmap = QPixmap(size.toSize()) Loading @@ -85,7 +101,6 @@ class TextBlkItem(QGraphicsTextItem): doc.drawContents(painter) painter.end() cursor.setCharFormat(old_fmt) self.repainting = False def docSizeChanged(self): Loading ballontranslator/ui/textlayout.py +1 −1 Original line number Diff line number Diff line Loading @@ -475,7 +475,7 @@ class VerticalTextDocumentLayout(QAbstractTextDocumentLayout): if char_bottom > available_height: # switch to next line if char_idx == 0 and layout_first_block: self.min_height = line_bottom self.min_height = doc_margin + tbr_h else: x_offset = x_offset - block_width * self.line_spacing line_y_offset = doc_margin Loading Loading
ballontranslator/ui/textitem.py +25 −10 Original line number Diff line number Diff line Loading @@ -65,15 +65,31 @@ class TextBlkItem(QGraphicsTextItem): def repaint_background(self): self.repainting = True doc = self.document() doc = self.document().clone() doc.setDocumentMargin(self.document().documentMargin()) layout = VerticalTextDocumentLayout(doc) if self.is_vertical else HorizontalTextDocumentLayout(doc) rect = self.rect() doc.setDocumentLayout(layout) layout.setMaxSize(rect.width(), rect.height()) sw = self.stroke_width * pt2px(self.document().defaultFont().pointSizeF()) format = QTextCharFormat() format.setTextOutline (QPen(self.stroke_color, sw, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)) cursor = QTextCursor(doc) cursor.select(QTextCursor.Document) old_fmt = cursor.charFormat() cursor.mergeCharFormat(format) block = doc.firstBlock() stroke_pen = QPen(self.stroke_color, 0, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin) while block.isValid(): it = block.begin() while not it.atEnd(): fragment = it.fragment() cfmt = fragment.charFormat() sw = pt2px(cfmt.fontPointSize()) * self.stroke_width stroke_pen.setWidthF(sw) pos1 = fragment.position() pos2 = pos1 + fragment.length() cursor.setPosition(pos1) cursor.setPosition(pos2, QTextCursor.KeepAnchor) cfmt.setTextOutline(stroke_pen) cursor.mergeCharFormat(cfmt) it += 1 block = block.next() size = self.boundingRect().size() self.background_pixmap = QPixmap(size.toSize()) Loading @@ -85,7 +101,6 @@ class TextBlkItem(QGraphicsTextItem): doc.drawContents(painter) painter.end() cursor.setCharFormat(old_fmt) self.repainting = False def docSizeChanged(self): Loading
ballontranslator/ui/textlayout.py +1 −1 Original line number Diff line number Diff line Loading @@ -475,7 +475,7 @@ class VerticalTextDocumentLayout(QAbstractTextDocumentLayout): if char_bottom > available_height: # switch to next line if char_idx == 0 and layout_first_block: self.min_height = line_bottom self.min_height = doc_margin + tbr_h else: x_offset = x_offset - block_width * self.line_spacing line_y_offset = doc_margin Loading