Loading ballontranslator/ui/fontformatpanel.py +1 −1 Original line number Diff line number Diff line Loading @@ -438,7 +438,7 @@ class FontFormatPanel(Widget): self.lineSpacingBox = SizeComboBox([0, 10], self) self.lineSpacingBox.addItems(["1.0", "1.1", "1.2"]) self.lineSpacingBox.setToolTip("Change line spacing") self.lineSpacingBox.setToolTip(self.tr("Change line spacing")) self.lineSpacingBox.apply_change.connect(self.update_line_spacing) self.lineSpacingBox.editTextChanged.connect(self.onLineSpacingEditorChanged) Loading ballontranslator/ui/mainwindow.py +3 −3 Original line number Diff line number Diff line Loading @@ -438,8 +438,6 @@ class MainWindow(QMainWindow): else: mask_path = inpainted_path = None img = QImage(self.canvas.imgLayer.pixmap().size(), QImage.Format.Format_ARGB32) restore_textblock_mode = False if self.config.imgtrans_textblock: restore_textblock_mode = True Loading @@ -466,6 +464,7 @@ class MainWindow(QMainWindow): self.imsave_thread.saveImg(inpainted_path, inpainted_array) # save result: rendered text + inpainted img = QImage(self.canvas.imgLayer.pixmap().size(), QImage.Format.Format_ARGB32) painter = QPainter(img) painter.setRenderHint(QPainter.RenderHint.Antialiasing) self.canvas.render(painter) Loading Loading @@ -516,7 +515,8 @@ class MainWindow(QMainWindow): self.st_manager.updateTranslation() def on_imgtrans_pipeline_finished(self): self.pageListCurrentItemChanged() # self.pageListCurrentItemChanged() pass def postprocess_translations(self, blk_list: List[TextBlock]) -> None: src_is_cjk = is_cjk(self.config.dl.translate_source) Loading ballontranslator/ui/scene_textlayout.py +7 −8 Original line number Diff line number Diff line Loading @@ -467,7 +467,6 @@ class VerticalTextDocumentLayout(SceneTextLayout): tl.beginLayout() option = doc.defaultTextOption() option.setWrapMode(QTextOption.WrapAnywhere) # option.setFlags(QTextOption.Flag.IncludeTrailingSpaces) tl.setTextOption(option) while True: Loading @@ -488,12 +487,13 @@ class VerticalTextDocumentLayout(SceneTextLayout): num_rspaces = text_len - len(text.rstrip()) num_lspaces = text_len - len(text.lstrip()) tbr_h = space_w = 0 tbr_h = space_w = let_sp_offset = 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() * ls let_sp_offset = cfmt.tbr.height() * (ls - 1) tbr_h = cfmt.tbr.height() + let_sp_offset char = blk_text[char_idx] if char in PUNSET_VERNEEDROTATE: tbr, br = cfmt.punc_rect(char) Loading @@ -505,15 +505,15 @@ class VerticalTextDocumentLayout(SceneTextLayout): 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) tbr_h -= let_sp_offset tbr_h += let_sp_offset 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) tbr_h += let_sp_offset 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() Loading @@ -526,14 +526,13 @@ 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)) blk_line_spaces.append([num_rspaces, num_lspaces, char_yoffset_lst, char_idx - num_lspaces]) char_bottom = char_yoffset_lst[-1] + tbr_h if char_bottom > available_height: if char_bottom - max(let_sp_offset, 0) > available_height: # switch to next line if char_idx == 0 and layout_first_block: self.min_height = doc_margin + tbr_h Loading ballontranslator/ui/textitem.py +7 −5 Original line number Diff line number Diff line Loading @@ -498,6 +498,7 @@ class TextBlkItem(QGraphicsTextItem): format.setFontWeight(ffmat.weight) format.setFontItalic(ffmat.italic) format.setFontUnderline(ffmat.underline) if not ffmat.vertical: format.setFontLetterSpacingType(QFont.SpacingType.PercentageSpacing) format.setFontLetterSpacing(ffmat.letter_spacing * 100) cursor.setCharFormat(format) Loading @@ -517,9 +518,10 @@ class TextBlkItem(QGraphicsTextItem): op = doc.defaultTextOption() op.setAlignment(alignment) doc.setDefaultTextOption(op) if ffmat.vertical: self.setLetterSpacing(ffmat.letter_spacing) self.setLineSpacing(ffmat.line_spacing) self.letter_spacing = ffmat.letter_spacing # self.setLetterSpacing(ffmat.letter_spacing) def updateBlkFormat(self): fmt = self.get_fontformat() Loading @@ -533,7 +535,7 @@ class TextBlkItem(QGraphicsTextItem): # self.blk._alignment = self.blk.alignment() self.blk.set_font_colors(fmt.frgb, fmt.srgb, accumulate=False) def setLineSpacing(self, line_spacing: float, cursor=None): def setLineSpacing(self, line_spacing: float): self.line_spacing = line_spacing self.layout.setLineSpacing(self.line_spacing) self.repaint_background() Loading Loading
ballontranslator/ui/fontformatpanel.py +1 −1 Original line number Diff line number Diff line Loading @@ -438,7 +438,7 @@ class FontFormatPanel(Widget): self.lineSpacingBox = SizeComboBox([0, 10], self) self.lineSpacingBox.addItems(["1.0", "1.1", "1.2"]) self.lineSpacingBox.setToolTip("Change line spacing") self.lineSpacingBox.setToolTip(self.tr("Change line spacing")) self.lineSpacingBox.apply_change.connect(self.update_line_spacing) self.lineSpacingBox.editTextChanged.connect(self.onLineSpacingEditorChanged) Loading
ballontranslator/ui/mainwindow.py +3 −3 Original line number Diff line number Diff line Loading @@ -438,8 +438,6 @@ class MainWindow(QMainWindow): else: mask_path = inpainted_path = None img = QImage(self.canvas.imgLayer.pixmap().size(), QImage.Format.Format_ARGB32) restore_textblock_mode = False if self.config.imgtrans_textblock: restore_textblock_mode = True Loading @@ -466,6 +464,7 @@ class MainWindow(QMainWindow): self.imsave_thread.saveImg(inpainted_path, inpainted_array) # save result: rendered text + inpainted img = QImage(self.canvas.imgLayer.pixmap().size(), QImage.Format.Format_ARGB32) painter = QPainter(img) painter.setRenderHint(QPainter.RenderHint.Antialiasing) self.canvas.render(painter) Loading Loading @@ -516,7 +515,8 @@ class MainWindow(QMainWindow): self.st_manager.updateTranslation() def on_imgtrans_pipeline_finished(self): self.pageListCurrentItemChanged() # self.pageListCurrentItemChanged() pass def postprocess_translations(self, blk_list: List[TextBlock]) -> None: src_is_cjk = is_cjk(self.config.dl.translate_source) Loading
ballontranslator/ui/scene_textlayout.py +7 −8 Original line number Diff line number Diff line Loading @@ -467,7 +467,6 @@ class VerticalTextDocumentLayout(SceneTextLayout): tl.beginLayout() option = doc.defaultTextOption() option.setWrapMode(QTextOption.WrapAnywhere) # option.setFlags(QTextOption.Flag.IncludeTrailingSpaces) tl.setTextOption(option) while True: Loading @@ -488,12 +487,13 @@ class VerticalTextDocumentLayout(SceneTextLayout): num_rspaces = text_len - len(text.rstrip()) num_lspaces = text_len - len(text.lstrip()) tbr_h = space_w = 0 tbr_h = space_w = let_sp_offset = 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() * ls let_sp_offset = cfmt.tbr.height() * (ls - 1) tbr_h = cfmt.tbr.height() + let_sp_offset char = blk_text[char_idx] if char in PUNSET_VERNEEDROTATE: tbr, br = cfmt.punc_rect(char) Loading @@ -505,15 +505,15 @@ class VerticalTextDocumentLayout(SceneTextLayout): 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) tbr_h -= let_sp_offset tbr_h += let_sp_offset 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) tbr_h += let_sp_offset 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() Loading @@ -526,14 +526,13 @@ 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)) blk_line_spaces.append([num_rspaces, num_lspaces, char_yoffset_lst, char_idx - num_lspaces]) char_bottom = char_yoffset_lst[-1] + tbr_h if char_bottom > available_height: if char_bottom - max(let_sp_offset, 0) > available_height: # switch to next line if char_idx == 0 and layout_first_block: self.min_height = doc_margin + tbr_h Loading
ballontranslator/ui/textitem.py +7 −5 Original line number Diff line number Diff line Loading @@ -498,6 +498,7 @@ class TextBlkItem(QGraphicsTextItem): format.setFontWeight(ffmat.weight) format.setFontItalic(ffmat.italic) format.setFontUnderline(ffmat.underline) if not ffmat.vertical: format.setFontLetterSpacingType(QFont.SpacingType.PercentageSpacing) format.setFontLetterSpacing(ffmat.letter_spacing * 100) cursor.setCharFormat(format) Loading @@ -517,9 +518,10 @@ class TextBlkItem(QGraphicsTextItem): op = doc.defaultTextOption() op.setAlignment(alignment) doc.setDefaultTextOption(op) if ffmat.vertical: self.setLetterSpacing(ffmat.letter_spacing) self.setLineSpacing(ffmat.line_spacing) self.letter_spacing = ffmat.letter_spacing # self.setLetterSpacing(ffmat.letter_spacing) def updateBlkFormat(self): fmt = self.get_fontformat() Loading @@ -533,7 +535,7 @@ class TextBlkItem(QGraphicsTextItem): # self.blk._alignment = self.blk.alignment() self.blk.set_font_colors(fmt.frgb, fmt.srgb, accumulate=False) def setLineSpacing(self, line_spacing: float, cursor=None): def setLineSpacing(self, line_spacing: float): self.line_spacing = line_spacing self.layout.setLineSpacing(self.line_spacing) self.repaint_background() Loading