Commit 739ec095 authored by dmMaze's avatar dmMaze
Browse files

fix adaptive font size not applied (#268) and add option to disable it

parent 8037693e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
# To install pytorch cuda (gpu) version, please look https://pytorch.org/

PyQt6-Qt6==6.4.2    # ffor qt>6.4.2 , framelesswindow is broken on windows, and text rendering is wrong on macOS
PyQt6-Qt6==6.4.2    # for qt>6.4.2 , framelesswindow is broken on windows, and text rendering is wrong on macOS
PyQt6==6.4.2   #PyQt5>=5.15.9
numpy
urllib3==1.25.11 # https://github.com/psf/requests/issues/5740
+21 −11
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ class ConfigBlock(Widget):
        self.addSublock(sublock)
        return sublock

    def addCheckBox(self, name: str, discription: str = None) -> QCheckBox:
    def addCheckBox(self, name: str, discription: str = None, sublock: ConfigSubBlock = None) -> QCheckBox:
        checkbox = QCheckBox()
        if discription is not None:
            font = checkbox.font()
@@ -208,11 +208,14 @@ class ConfigBlock(Widget):
            vertical_layout = True
        else:
            vertical_layout = False
        if sublock is None:
            sublock = ConfigSubBlock(checkbox, name, vertical_layout=vertical_layout)
            if vertical_layout is False:
                sublock.layout().addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding))
            self.addSublock(sublock)
        return checkbox
        else:
            sublock.layout().addWidget(checkbox)
        return checkbox, sublock

    def getSubBlockbyIdx(self, idx: int) -> ConfigSubBlock:
        return self.subblock_list[idx]
@@ -392,7 +395,7 @@ class ConfigPanel(Widget):
        self.trans_sub_block = dlConfigPanel.addBlockWidget(self.trans_config_panel)

        generalConfigPanel.addTextLabel(label_startup)
        self.open_on_startup_checker = generalConfigPanel.addCheckBox(self.tr('Reopen last project on startup'))
        self.open_on_startup_checker, _ = generalConfigPanel.addCheckBox(self.tr('Reopen last project on startup'))
        self.open_on_startup_checker.stateChanged.connect(self.on_open_onstartup_changed)

        generalConfigPanel.addTextLabel(label_lettering)
@@ -430,10 +433,13 @@ class ConfigPanel(Widget):
        global_fntfmt_layout.addWidget(sublock, 2, 1)
        global_fntfmt_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding), 0, 2)

        self.let_autolayout_checker = generalConfigPanel.addCheckBox(self.tr('Auto layout'), 
                discription=self.tr('Split translation into multi-lines according to the extracted balloon region. The font size will be adaptively resized if it is set to \"decide by program.\"'))
        self.let_autolayout_checker, sublock = generalConfigPanel.addCheckBox(self.tr('Auto layout'), 
                discription=self.tr('Split translation into multi-lines according to the extracted balloon region.'))
        self.let_autolayout_adaptive_fntsize_checker, _ = generalConfigPanel.addCheckBox(None, self.tr('Adjust font size adaptively if it is set to \"decide by program.\"'), sublock=sublock)
        self.let_autolayout_adaptive_fntsize_checker.stateChanged.connect(self.on_adaptive_fntsize_changed)

        self.let_autolayout_checker.stateChanged.connect(self.on_autolayout_changed)
        self.let_uppercase_checker = generalConfigPanel.addCheckBox(self.tr('To uppercase'))
        self.let_uppercase_checker, _ = generalConfigPanel.addCheckBox(self.tr('To uppercase'))
        self.let_uppercase_checker.stateChanged.connect(self.on_uppercase_changed)

        generalConfigPanel.addTextLabel(label_save)
@@ -453,7 +459,7 @@ class ConfigPanel(Widget):
        sublock.layout().insertStretch(-1)
        generalConfigPanel.addSublock(sublock)

        self.selectext_minimenu_checker = generalConfigPanel.addCheckBox(self.tr('Show mini menu when selecting text.'))
        self.selectext_minimenu_checker, _ = generalConfigPanel.addCheckBox(self.tr('Show mini menu when selecting text.'))
        self.selectext_minimenu_checker.stateChanged.connect(self.on_selectext_minimenu_changed)
        self.saladict_shortcut = QKeySequenceEdit("ALT+W", self)
        self.saladict_shortcut.keySequenceChanged.connect(self.on_saladict_shortcut_changed)
@@ -507,6 +513,9 @@ class ConfigPanel(Widget):
    def on_autolayout_changed(self):
        pcfg.let_autolayout_flag = self.let_autolayout_checker.isChecked()

    def on_adaptive_fntsize_changed(self):
        pcfg.let_autolayout_adaptive_fntsz = self.let_autolayout_adaptive_fntsize_checker.isChecked()

    def on_uppercase_changed(self):
        pcfg.let_uppercase_flag = self.let_uppercase_checker.isChecked()

@@ -567,6 +576,7 @@ class ConfigPanel(Widget):
        self.let_fnt_scolor_combox.setCurrentIndex(pcfg.let_fnt_scolor_flag)
        self.let_alignment_combox.setCurrentIndex(pcfg.let_alignment_flag)
        self.let_autolayout_checker.setChecked(pcfg.let_autolayout_flag)
        self.let_autolayout_adaptive_fntsize_checker.setChecked(pcfg.let_autolayout_adaptive_fntsz)
        self.selectext_minimenu_checker.setChecked(pcfg.textselect_mini_menu)
        self.let_uppercase_checker.setChecked(pcfg.let_uppercase_flag)
        self.saladict_shortcut.setKeySequence(pcfg.saladict_shortcut)
+10 −4
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ except:
from .textitem import TextBlkItem, TextBlock, xywh2xyxypoly
from .canvas import Canvas
from .textedit_area import TransTextEdit, SourceTextEdit, TransPairWidget, SelectTextMiniMenu, TextEditListScrollArea, QVBoxLayout, Widget
from utils.fontformat import FontFormat, pt2px
from utils.fontformat import FontFormat, pt2px, px2pt
from .textedit_commands import propagate_user_edit, TextEditCommand, ReshapeItemCommand, MoveBlkItemsCommand, AutoLayoutCommand, ApplyFontformatCommand, ApplyEffectCommand, RotateItemCommand, TextItemEditCommand, TextEditCommand, PageReplaceOneCommand, PageReplaceAllCommand, MultiPasteCommand, ResetAngleCommand
from .fontformatpanel import FontFormatPanel
from utils.config import pcfg
@@ -687,7 +687,7 @@ class SceneTextManager(QObject):
        delimiter_len = text_size_func(delimiter)[0]
 
        adaptive_fntsize = False
        if self.auto_textlayout_flag and pcfg.let_fntsize_flag == 0 and pcfg.module.enable_detect:
        if self.auto_textlayout_flag and pcfg.let_fntsize_flag == 0 and pcfg.let_autolayout_flag and pcfg.let_autolayout_adaptive_fntsz:
            if not tgt_is_cjk:
                adaptive_fntsize = True
            
@@ -698,7 +698,13 @@ class SceneTextManager(QObject):
            downscale_constraint = 0.6
            # downscale the font size if textarea exceeds the balloon_area / ballon_area_thresh
            # or the longest word exceeds the region_width
            resize_ratio = np.clip(min(area_ratio / ballon_area_thresh, max(wl_list) / region_rect[2], blkitem.blk.font_size / line_height), downscale_constraint, 1.0) 
            # dont remember why i divide line_hight here
            # resize_ratio = np.clip(min(area_ratio / ballon_area_thresh, region_rect [2] / max(wl_list), blkitem.blk.font_size / line_height), downscale_constraint, 1.0) 
            resize_ratio = np.clip(min(area_ratio / ballon_area_thresh, region_rect [2] / max(wl_list)), downscale_constraint, 1.0)

        if text.startswith('SAKUY'):
            cv2.imwrite('sakuy.png', mask)
            pass

        max_central_width = np.inf
        if tgt_is_cjk:
@@ -731,7 +737,7 @@ class SceneTextManager(QObject):
        if max_central_width != np.inf:
            max_central_width = max(int(max_central_width * text_w), 0.75 * region_rect[2])

        padding = pt2px(blk_font.pointSizeF()) + 20   # dummpy padding variable
        padding = pt2px(blk_font.pointSizeF()) + 10   # dummpy padding variable
        if fmt.alignment == 1:
            if len(blkitem.blk) > 0:
                centroid = blkitem.blk.center().astype(np.int64).tolist()
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ class ProgramConfig(Config):
    let_fnteffect_flag: int = 1
    let_alignment_flag: int = 0
    let_autolayout_flag: bool = True
    let_autolayout_adaptive_fntsz: bool = True
    let_uppercase_flag: bool = True
    font_presets: dict = field(default_factory=lambda: dict())
    fsearch_case: bool = False
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class TextBlock:
    shadow_color: Tuple = (0, 0, 0)
    shadow_offset: List = field(default_factory = lambda : [0., 0.])
    src_is_vertical: bool = None
    _detected_font_size: int = -1
    _detected_font_size: float = -1

    region_mask: np.ndarray = None
    region_inpaint_dict: Dict = None