Commit 39e9ce3f authored by dmMaze's avatar dmMaze
Browse files

apply texteffect to transpipline

parent 97e64a1a
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ class ConfigBlock(Widget):
        sublock.pressed.connect(lambda idx0, idx1: self.sublock_pressed.emit(idx0, idx1))
        self.subblock_list.append(sublock)

    def addCombobox(self, sel: List[str], name: str, discription: str = None, vertical_layout: bool = False, target_block: QWidget = None) -> ConfigComboBox:
    def addCombobox(self, sel: List[str], name: str, discription: str = None, vertical_layout: bool = False, target_block: QWidget = None) -> Tuple[ConfigComboBox, QWidget]:
        combox = ConfigComboBox()
        combox.addItems(sel)
        if target_block is None:
@@ -360,6 +360,8 @@ class ConfigPanel(Widget):
        self.let_fntcolor_combox.currentIndexChanged.connect(self.on_fontcolor_flag_changed)
        self.let_alignment_combox, _ = generalConfigPanel.addCombobox([dec_program_str, use_global_str], self.tr('alignment'), target_block=letblk_1)
        self.let_alignment_combox.currentIndexChanged.connect(self.on_alignment_flag_changed)
        self.let_effect_combox, letblk_2 = generalConfigPanel.addCombobox([dec_program_str, use_global_str], self.tr('effect'))
        self.let_effect_combox.currentIndexChanged.connect(self.on_effect_flag_changed)

        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.\"'))
@@ -416,6 +418,9 @@ class ConfigPanel(Widget):
    def on_alignment_flag_changed(self):
        self.config.let_alignment_flag = self.let_alignment_combox.currentIndex()

    def on_effect_flag_changed(self):
        self.config.let_fnteffect_flag = self.let_effect_combox.currentIndex()

    def on_source_flag_changed(self):
        self.config.src_choice_flag = self.src_choice_combox.currentIndex()

+9 −1
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ class MainWindow(QMainWindow):
        self.configPanel.blockSignals(True)
        if self.config.open_recent_on_startup:
            self.configPanel.open_on_startup_checker.setChecked(True)
        self.configPanel.let_effect_combox.setCurrentIndex(self.config.let_fnteffect_flag)
        self.configPanel.let_fntsize_combox.setCurrentIndex(self.config.let_fntsize_flag)
        self.configPanel.let_fntstroke_combox.setCurrentIndex(self.config.let_fntstroke_flag)
        self.configPanel.let_fntcolor_combox.setCurrentIndex(self.config.let_fntcolor_flag)
@@ -552,6 +553,7 @@ class MainWindow(QMainWindow):
        override_fnt_stroke = self.config.let_fntstroke_flag == 1
        override_fnt_color = self.config.let_fntcolor_flag == 1
        override_alignment = self.config.let_alignment_flag == 1
        override_effect = self.config.let_fnteffect_flag == 1
        gf = self.textPanel.formatpanel.global_format
        
        for blk in blk_list:
@@ -559,11 +561,17 @@ class MainWindow(QMainWindow):
                blk.font_size = pt2px(gf.size)
            if override_fnt_stroke:
                blk.default_stroke_width = gf.stroke_width
                
            if override_fnt_color:
                blk.set_font_colors(gf.frgb, gf.srgb, accumulate=False)
            if override_alignment:
                blk._alignment = gf.alignment
            if override_effect:
                blk.opacity = gf.opacity
                blk.shadow_color = gf.shadow_color
                blk.shadow_radius = gf.shadow_radius
                blk.shadow_strength = gf.shadow_strength
                blk.shadow_offset = gf.shadow_offset
            
            blk.line_spacing = gf.line_spacing
            blk.letter_spacing = gf.letter_spacing
            sw = blk.stroke_width
+5 −2
Original line number Diff line number Diff line
@@ -479,9 +479,11 @@ class ProgramConfig:
        let_fntsize_flag: int = 0,
        let_fntstroke_flag: int = 0,
        let_fntcolor_flag: int = 0,
        let_fnteffect_flag: int = 1,
        let_alignment_flag: int = 0,
        let_autolayout_flag: bool = True,
        let_uppercase_flag: bool = True) -> None:
        let_uppercase_flag: bool = True,
        **kwargs) -> None:

        if isinstance(dl, dict):
            self.dl = DLModuleConfig(**dl)
@@ -511,12 +513,13 @@ class ProgramConfig:
        self.let_fntsize_flag = let_fntsize_flag
        self.let_fntstroke_flag = let_fntstroke_flag
        self.let_fntcolor_flag = let_fntcolor_flag
        self.let_fnteffect_flag = let_fnteffect_flag
        self.let_alignment_flag = let_alignment_flag
        self.let_autolayout_flag = let_autolayout_flag
        self.let_uppercase_flag = let_uppercase_flag


class LruIgnoreArgs:
class LruIgnoreArg:

    def __init__(self, **kwargs) -> None:
        for key in kwargs:
+3 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import numpy as np
from typing import List
from functools import lru_cache, cached_property

from .misc import pixmap2ndarray, pt2px, LruIgnoreArgs
from .misc import pixmap2ndarray, pt2px, LruIgnoreArg
from . import constants as C

def print_transform(tr: QTransform):
@@ -59,7 +59,7 @@ def punc_actual_rect(line: QTextLine, family: str, size: float, weight: int, ita
    return ar

@lru_cache(maxsize=2048)
def punc_actual_rect_cached(line: LruIgnoreArgs, char: str, family: str, size: float, weight: int, italic: bool, stroke_width: float) -> List[int]:
def punc_actual_rect_cached(line: LruIgnoreArg, char: str, family: str, size: float, weight: int, italic: bool, stroke_width: float) -> List[int]:
    # QtextLine line is invisibale to lru
    return punc_actual_rect(line.line, family, size, weight, italic, stroke_width)

@@ -121,7 +121,7 @@ class CharFontFormat:

    def punc_actual_rect(self, line: QTextLine, char: str, cache=False) -> List[int]:
        if cache:
            line = LruIgnoreArgs(line=line)
            line = LruIgnoreArg(line=line)
            ar = punc_actual_rect_cached(line, char, self.family, self.size, self.weight, self.font.italic(), self.stroke_width)
        else:
            ar =  punc_actual_rect(line, self.family, self.size, self.weight, self.font.italic(), self.stroke_width)