diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput.py b/LunaTranslator/LunaTranslator/gui/setting_textinput.py index b9136faf..9f016bdd 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput.py @@ -344,18 +344,8 @@ def gethookembedgrid(self): ], [ "限制每行字数", - D_getsimpleswitch( - globalconfig["embedded"], - "limittextlength_use", - callback=lambda _: gobject.baseobject.textsource.flashembedsettings(), - ), - D_getspinbox( - 0, - 1000, - globalconfig["embedded"], - "limittextlength_length", - callback=lambda x: gobject.baseobject.textsource.flashembedsettings(), - ), + D_getsimpleswitch(globalconfig["embedded"], "limittextlength_use"), + D_getspinbox(0, 1000, globalconfig["embedded"], "limittextlength_length"), ], [ "修改游戏字体", diff --git a/LunaTranslator/LunaTranslator/myutils/post.py b/LunaTranslator/LunaTranslator/myutils/post.py index 11a93025..71afa412 100644 --- a/LunaTranslator/LunaTranslator/myutils/post.py +++ b/LunaTranslator/LunaTranslator/myutils/post.py @@ -7,6 +7,7 @@ from myutils.utils import ( checkmd5reloadmodule, LRUCache, getlangsrc, + getlanguagespace, parsemayberegexreplace, ) from myutils.config import ( @@ -202,10 +203,7 @@ def _4_f(line): def _6_fEX(line): srclang = getlangsrc() - if srclang in ["zh", "ja", "cht"]: - white = "" - else: - white = " " + white = getlanguagespace(srclang) line = ( line.replace("\r ", " ") .replace("\n ", " ") diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index fcdba035..458a3f0d 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -81,6 +81,10 @@ def getlangtgt(): return __internal__getlang("private_tgtlang_2", "tgtlang4") +def getlanguagespace(lang): + return "" if (lang in ("zh", "ja", "cht")) else " " + + def findenclose(text, tag): i = 0 tags = f"<{tag}" diff --git a/LunaTranslator/LunaTranslator/ocrengines/baseocrclass.py b/LunaTranslator/LunaTranslator/ocrengines/baseocrclass.py index 3cde110b..f66e34d8 100644 --- a/LunaTranslator/LunaTranslator/ocrengines/baseocrclass.py +++ b/LunaTranslator/LunaTranslator/ocrengines/baseocrclass.py @@ -1,4 +1,5 @@ from myutils.config import globalconfig, ocrsetting, ocrerrorfix +from myutils.utils import getlanguagespace from myutils.commonbase import commonbase @@ -18,10 +19,8 @@ class baseocr(commonbase): def space(self): if globalconfig["ocrmergelines"] == False: space = "\n" - elif self.srclang_1 in ["zh", "ja", "cht"]: - space = "" else: - space = " " + space = getlanguagespace(self.srclang_1) return space ############################################################ diff --git a/LunaTranslator/LunaTranslator/ocrengines/windowsocr.py b/LunaTranslator/LunaTranslator/ocrengines/windowsocr.py index 330c51f0..b6a0c049 100644 --- a/LunaTranslator/LunaTranslator/ocrengines/windowsocr.py +++ b/LunaTranslator/LunaTranslator/ocrengines/windowsocr.py @@ -66,12 +66,8 @@ class OCR(baseocr): + ", ".join([_TR(getlang_inner2show(f)) for f in _allsupport]) ) - if self.srclang in ["zh", "ja", "cht"]: - space = "" - else: - space = " " - ret = winrtutils.OCR_f(imagebinary, self.supportmap[self.srclang], space) + ret = winrtutils.OCR_f(imagebinary, self.supportmap[self.srclang], self.space) boxs = [_[1:] for _ in ret] texts = [_[0] for _ in ret] diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index d00445dd..15031ef3 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -11,7 +11,7 @@ from myutils.config import ( findgameuidofpath, ) from textsource.textsourcebase import basetext -from myutils.utils import checkchaos, getfilemd5 +from myutils.utils import checkchaos, getfilemd5, getlangtgt, getlanguagespace from myutils.hwnd import injectdll, test_injectable, ListProcess, getpidexe from myutils.wrapper import threader from traceback import print_exc @@ -158,7 +158,6 @@ class texthook(basetext): c_uint32, c_uint32, c_bool, - c_uint32, ) self.Luna_checkisusingembed = LunaHost.Luna_checkisusingembed self.Luna_checkisusingembed.argtypes = DWORD, c_uint64, c_uint64, c_uint64 @@ -358,19 +357,30 @@ class texthook(basetext): @threader def getembedtext(self, text, tp): if self.safeembedcheck(text) == False: - self.embedcallback(text, text) + self.embedcallback(text, "") return if not self.isautorunning: - self.embedcallback(text, text) + self.embedcallback(text, "") return if self.checkisusingembed(tp.addr, tp.ctx, tp.ctx2): trans = self.waitfortranslation(text) if not trans: - trans = text + trans = "" self.embedcallback(text, trans) - def embedcallback(self, text, trans): - + def embedcallback(self, text: str, trans: str): + if len(trans) and globalconfig["embedded"]["limittextlength_use"]: + length = globalconfig["embedded"]["limittextlength_length"] + lines = trans.split("\n") + newlines = [] + space = getlanguagespace(getlangtgt()) + for line in lines: + line = line.split(space) if space else line + while len(line): + newlines.append(space.join(line[:length])) + line = line[length:] + trans = "\n".join(newlines) + print(trans) for pid in self.pids.copy(): self.Luna_embedcallback(pid, text, trans) @@ -393,11 +403,6 @@ class texthook(basetext): globalconfig["embedded"]["insertspace_policy"], globalconfig["embedded"]["keeprawtext"], True, - ( - globalconfig["embedded"]["limittextlength_length"] - if globalconfig["embedded"]["limittextlength_use"] - else 0 - ), ) def onremovehook(self, hc, hn, tp): diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 193de273..add6cc2b 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 28) -set(VERSION_PATCH 5) +set(VERSION_PATCH 6) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)