Commit d5815d30 authored by dmMaze's avatar dmMaze
Browse files

support vertical letter spacing

parent c92f31f2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -153,6 +153,8 @@ class Canvas(QGraphicsScene):
        self.selectionChanged.connect(self.on_selection_changed)     
        self.stroke_path_item: StrokeItem = None

        self.editor_index = 0 # 0: drawing 1: text editor

    def scaleUp(self):
        self.scaleImage(1 + CANVAS_SCALE_SPEED)

@@ -322,7 +324,7 @@ class Canvas(QGraphicsScene):

    @property
    def creating_normal_rect(self):
        return self.image_edit_mode == ImageEditMode.RectTool
        return self.image_edit_mode == ImageEditMode.RectTool and self.editor_index == 0

    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None:
        if self.creating_textblock:
+5 −1
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ class MainWindow(QMainWindow):
        self.rightComicTransStackPanel = QStackedWidget(self)
        self.rightComicTransStackPanel.addWidget(self.drawingPanel)
        self.rightComicTransStackPanel.addWidget(self.textPanel)
        self.rightComicTransStackPanel.currentChanged.connect(self.on_transpanel_changed)

        self.comicTransSplitter = QSplitter(Qt.Orientation.Horizontal)
        self.comicTransSplitter.addWidget(self.pageList)
@@ -578,3 +579,6 @@ class MainWindow(QMainWindow):
        if self.bottomBar.textblockChecker.isChecked():
            self.bottomBar.textblockChecker.click()
        self.dl_manager.runImgtransPipeline()

    def on_transpanel_changed(self):
        self.canvas.editor_index = self.rightComicTransStackPanel.currentIndex()
 No newline at end of file
+12 −4
Original line number Diff line number Diff line
@@ -488,13 +488,12 @@ class VerticalTextDocumentLayout(SceneTextLayout):
            num_rspaces = text_len - len(text.rstrip())
            num_lspaces = text_len - len(text.lstrip())

            
            tbr_h = space_w = 0
            char_idx += num_lspaces
            if char_idx < blk_text_len:
                cfmt = self.get_char_fontfmt(block_no, char_idx)
                space_w = cfmt.space_width
                tbr_h = cfmt.tbr.height()
                tbr_h = cfmt.tbr.height() * ls
                char = blk_text[char_idx]
                if char in PUNSET_VERNEEDROTATE:
                    tbr, br = cfmt.punc_rect(char)
@@ -504,12 +503,17 @@ class VerticalTextDocumentLayout(SceneTextLayout):
                        tbr_h = br.width() - (br.width() * 2 - cw2)
                    if char in {'', ''}:
                        tbr_h = line.naturalTextWidth() - num_lspaces * space_w
                        next_char_idx = char_idx + 1
                        if next_char_idx < blk_text_len and blk_text[next_char_idx] == char:
                            tbr_h -= cfmt.tbr.height() * (ls - 1)
                    tbr_h += cfmt.tbr.height() * (ls - 1)
                elif char in PUNSET_PAUSEORSTOP:
                    if char in {'', '', '', ''}:
                        tbr_h = cfmt.punc_actual_rect(line, char, cache=True)[3]
                    else:
                        tbr, br = cfmt.punc_rect(char)
                        tbr_h = tbr.height() + cfmt.font_metrics.descent()
                    tbr_h += cfmt.tbr.height() * (ls - 1)
            elif char_idx - num_lspaces < blk_text_len:
                cfmt = self.get_char_fontfmt(block_no, char_idx - num_lspaces)
                tbr_h = cfmt.tbr.height() + cfmt.font_metrics.descent()
@@ -522,6 +526,7 @@ class VerticalTextDocumentLayout(SceneTextLayout):
                if is_final_block:
                    self.draw_shifted = max(self.draw_shifted, shifted)

            
            char_yoffset_lst = [line_y_offset]
            for _ in range(num_lspaces):
                char_yoffset_lst.append(min(available_height - tbr_h, char_yoffset_lst[-1] + space_w))
@@ -549,7 +554,7 @@ class VerticalTextDocumentLayout(SceneTextLayout):

            line.setPosition(QPointF(x_offset, line_y_offset))
            blk_char_yoffset.append([line_y_offset, line_bottom])
            line_y_offset = line_bottom
            line_y_offset = max(line_bottom, doc_margin)
            char_idx += text_len - num_lspaces
        tl.endLayout()
            
@@ -562,7 +567,10 @@ class VerticalTextDocumentLayout(SceneTextLayout):
        return QRectF(0, 0, max(self.document().pageSize().width(), self.max_width), 2147483647)

    def setLetterSpacing(self, letter_spacing: float):
        if self.letter_spacing != letter_spacing:
            self.letter_spacing = letter_spacing
            self.reLayout()
        


class HorizontalTextDocumentLayout(SceneTextLayout):