Commit a6b46369 authored by dmMaze's avatar dmMaze
Browse files

allow run without update text styles #498

parent 2cc32195
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ preview
# Features
* Fully automated translation  
  - Support automatic text-detection, recognition, removal, and translation. Overall performance is dependent upon these modules.
  - Lettering is based on the formatting estimation of the original text.
  - Typesetting is based on the formatting estimation of the original text.
  - Works decently with manga and comics.
  - Improved manga->English, English->Chinese typesetting (based on the extraction of balloon regions.).
  
@@ -134,7 +134,7 @@ To use Sugoi translator(Japanese-English only), download [offline model](https:/
- Open a folder containing images of a comic (manga/manhua/manhwa) that need translation by clicking the folder icon.
- Click the `Run` button and wait for the process to complete.

The font formats such as font size and color are determined by the program automatically in this process, you can predetermine those formats by change corresponding options from "decide by program" to "use global setting" in the config panel->Lettering. (global settings are those formats shown by the right font format panel when you are not editing any textblock in the scene)
The font formats such as font size and color are determined by the program automatically in this process, you can predetermine those formats by change corresponding options from "decide by program" to "use global setting" in the config panel->Typesetting. (global settings are those formats shown by the right font format panel when you are not editing any textblock in the scene)

## Image Editing

@@ -180,7 +180,7 @@ OCR & Translate Selected Area
* Set parameters of automatic modules in the config panel.  
* ```Ctrl++```/```Ctrl+-``` (Also ```Ctrl+Shift+=```) to resize image.
* ```Ctrl+G```/```Ctrl+F``` to search globally/in current page.
* ```0-9``` to adjust opacity of lettering layer
* ```0-9``` to adjust opacity of text layer
* For text editing: bold - ```Ctrl+B```, underline - ```Ctrl+U```, Italics - ```Ctrl+I``` 
* Set text shadow and transparency in the text style panel -> Effect.  
  
+3 −3
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ Src download implementation based on gallery-dl (#131) thanks to [ROKOLYT](https
### 2023-02-23
[v1.3.30](https://github.com/dmMaze/BallonsTranslator/releases/tag/v1.3.30) released
1. Migrate to PyQt6 for better text rendering preview and [compatibility](https://github.com/Nuitka/Nuitka/issues/251) with nuitka
2. Support set transparency of lettering layer (#88)
2. Support set transparency of text layer (#88)
3. Dump logs to data/logs

### 2023-01-27
@@ -85,10 +85,10 @@ Support Dark Mode since v1.3.13: View->Dark Mode

1. Fix deepl translator, thanks to [@Snowad14](https://github.com/Snowad14)
2. Fix font size & stroke bug which makes text unreadable
3. Support **global font format** (determine the font format settings used by auto-translation mode): in config panel->Lettering, change the corresponding option from "decide by the program" to "use global setting" to enable. Note global settings are those formats shown by the right font format panel when you are not editing any textblock in the scene.
3. Support **global font format** (determine the font format settings used by auto-translation mode): in config panel->Typesetting, change the corresponding option from "decide by the program" to "use global setting" to enable. Note global settings are those formats shown by the right font format panel when you are not editing any textblock in the scene.
4. Add **new inpainting model**: lama-mpe and set it as default.
5. Support multiple textblocks selection & formatting. 
6. Improved manga->English, English->Chinese typesetting (**Auto-layout** in Config panel->Lettering, enabled by default), it can also be applied to selected text blocks use the option in the right-click menu.
6. Improved manga->English, English->Chinese typesetting (**Auto-layout** in Config panel->Typesetting, enabled by default), it can also be applied to selected text blocks use the option in the right-click menu.

<img src="./src/multisel_autolayout.gif" div align=center>
<p align=center>
+3 −4
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ class CustomIntValidator(QIntValidator):
            s = str(d)
        return (QValidator.State.Acceptable, s, pos)


class PercentageLineEdit(QLineEdit):

    finish_edited = Signal(str)
@@ -78,7 +79,6 @@ class PercentageLineEdit(QLineEdit):
        return super().focusOutEvent(e)



class ConfigTextLabel(QLabel):
    def __init__(self, text: str, fontsize: int, font_weight: int = None, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
@@ -90,7 +90,6 @@ class ConfigTextLabel(QLabel):
        self.setFont(font)
        self.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
        self.setOpenExternalLinks(True)
        # self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground, True)

    def setActiveBackground(self):
        self.setStyleSheet("background-color:rgba(30, 147, 229, 51);")
@@ -366,7 +365,7 @@ class ConfigPanel(Widget):
        label_inpaint = self.tr('Inpaint')
        label_translator = self.tr('Translator')
        label_startup = self.tr('Startup')
        label_lettering = self.tr('Lettering')
        label_lettering = self.tr('Typesetting')
        label_save = self.tr('Save')
        label_saladict = self.tr('SalaDict')
    
+56 −35
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ from utils import shared
from utils import create_error_dialog
from modules.translators.trans_chatgpt import GPTTranslator
from .misc import parse_stylesheet, set_html_family
from utils.config import ProgramConfig, pcfg, save_config, text_styles, save_text_styles, load_textstyle_from
from utils.config import ProgramConfig, pcfg, save_config, text_styles, save_text_styles, load_textstyle_from, FontFormat
from utils.fontformat import pt2px
from .config_proj import ProjImgTrans
from .canvas import Canvas
@@ -78,12 +78,14 @@ class MainWindow(mainwindow_cls):
        self.create_infodialog.connect(self.on_create_infodialog)

        self.app = app
        self.backup_blkstyles = []
        self._run_imgtrans_wo_textstyle_update = False

        self.setupThread()
        self.setupUi()
        self.setupConfig()
        self.setupShortcuts()
        self.showMaximized()

        self.setAcceptDrops(True)

        if open_dir != '' and osp.exists(open_dir):
@@ -474,6 +476,7 @@ class MainWindow(mainwindow_cls):
        self.titleBar.replaceMTkeyword_trigger.connect(self.show_MT_keyword_window)
        self.titleBar.replaceOCRkeyword_trigger.connect(self.show_OCR_keyword_window)
        self.titleBar.run_trigger.connect(self.leftBar.runImgtransBtn.click)
        self.titleBar.run_woupdate_textstyle_trigger.connect(self.run_imgtrans_wo_textstyle_update)
        self.titleBar.translate_page_trigger.connect(self.bottomBar.transTranspageBtn.click)
        self.titleBar.expandtstylepanel_trigger.connect(self.expand_tstyle_panel)
        self.titleBar.importtstyle_trigger.connect(self.import_tstyles)
@@ -840,6 +843,8 @@ class MainWindow(mainwindow_cls):
            self.st_manager.updateTranslation()

    def on_imgtrans_pipeline_finished(self):
        self.backup_blkstyles.clear()
        self._run_imgtrans_wo_textstyle_update = False
        self.postprocess_mt_toggle = True
        if pcfg.module.empty_runcache and not shared.HEADLESS:
            self.module_manager.unload_all_models()
@@ -870,6 +875,9 @@ class MainWindow(mainwindow_cls):

    def on_pagtrans_finished(self, page_index: int):
        blk_list = self.imgtrans_proj.get_blklist_byidx(page_index)
        ffmt_list = None
        if len(self.backup_blkstyles) == self.imgtrans_proj.num_pages and len(self.backup_blkstyles[page_index]) == len(blk_list):
            ffmt_list: List[FontFormat] = self.backup_blkstyles[page_index]

        self.postprocess_translations(blk_list)
                
@@ -888,7 +896,10 @@ class MainWindow(mainwindow_cls):
        inpaint_only = inpaint_only and not (pcfg.module.enable_detect or pcfg.module.enable_ocr or pcfg.module.enable_translate)
        
        if not inpaint_only:
            for blk in blk_list:
            for ii, blk in enumerate(blk_list):
                if self._run_imgtrans_wo_textstyle_update and ffmt_list is not None:
                    ffmt_list[ii].update_textblock_format(blk)
                else:
                    if override_fnt_size:
                        blk.font_size = pt2px(gf.size)
                    elif blk._detected_font_size > 0 and not pcfg.module.enable_detect:
@@ -997,7 +1008,12 @@ class MainWindow(mainwindow_cls):
    def run_imgtrans(self):
        self.on_run_imgtrans()

    def run_imgtrans_wo_textstyle_update(self):
        self._run_imgtrans_wo_textstyle_update = True
        self.on_run_imgtrans()

    def on_run_imgtrans(self):
        self.backup_blkstyles.clear()

        if self.bottomBar.textblockChecker.isChecked():
            self.bottomBar.textblockChecker.click()
@@ -1011,7 +1027,12 @@ class MainWindow(mainwindow_cls):
            self.st_manager.updateTextBlkList()
            textblk: TextBlock = None
            for blklist in self.imgtrans_proj.pages.values():
                ffmt_list = []
                self.backup_blkstyles.append(ffmt_list)
                for textblk in blklist:
                    if not pcfg.module.enable_detect:
                        ffmt = FontFormat.from_textblock(textblk)
                        ffmt_list.append(ffmt)
                    if pcfg.module.enable_ocr:
                        textblk.stroke_decide_by_colordiff = True
                        textblk.default_stroke_width = 0.2
+4 −2
Original line number Diff line number Diff line
@@ -415,14 +415,16 @@ class TitleBar(Widget):
            sa.triggered.connect(self.stageEnableStateChanged)

        runAction = QAction(self.tr('Run'), self)
        runWoUpdateTextStyle = QAction(self.tr('Run without update textstyle'), self)
        translatePageAction = QAction(self.tr('Translate page'), self)
        runMenu = QMenu(self.runToolBtn)
        runMenu.addActions(stageActions)
        runMenu.addSeparator()
        runMenu.addActions([runAction, translatePageAction])
        runMenu.addActions([runAction, runWoUpdateTextStyle, translatePageAction])
        self.runToolBtn.setMenu(runMenu)
        self.runToolBtn.setPopupMode(QToolButton.InstantPopup)
        self.run_trigger = runAction.triggered
        self.run_woupdate_textstyle_trigger = runWoUpdateTextStyle.triggered
        self.translate_page_trigger = translatePageAction.triggered

        self.iconLabel = QLabel(self)
@@ -582,7 +584,7 @@ class BottomBar(Widget):
        self.originalSlider.setFixedWidth(150)
        self.originalSlider.setRange(0, 100)

        self.textlayerSlider = PaintQSlider(self.tr("Lettering layer opacity"), Qt.Orientation.Horizontal, self)
        self.textlayerSlider = PaintQSlider(self.tr("Text layer opacity"), Qt.Orientation.Horizontal, self)
        self.textlayerSlider.setFixedWidth(150)
        self.textlayerSlider.setValue(100)
        self.textlayerSlider.setRange(0, 100)
Loading