diff --git a/LunaTranslator/LunaTranslator/hiraparse/basehira.py b/LunaTranslator/LunaTranslator/hiraparse/basehira.py index 7b8f4bb7..7a3467b0 100644 --- a/LunaTranslator/LunaTranslator/hiraparse/basehira.py +++ b/LunaTranslator/LunaTranslator/hiraparse/basehira.py @@ -30,6 +30,17 @@ class basehira: def proxy(self): return getproxy(("cishu", self.typename)) + def splitspace(self, word: str): + start = "" + end = "" + while word.startswith(" "): + start += " " + word = word[1:] + while word.endswith(" "): + end += " " + word = word[:-1] + return start, word, end + def parseparse(self, text): hira = [] try: @@ -41,6 +52,22 @@ class basehira: except Exception as e: self.needinit = True raise e + __parsekonge = [] + for word in hira: + ori = word["orig"] + start, w, end = self.splitspace(ori) + if len(start) == 0 and len(end) == 0: + __parsekonge.append(word) + continue + word["orig"] = w + word["hira"] = self.splitspace(word["hira"])[1] + + if len(start): + __parsekonge.append({"orig": start, "hira": start}) + __parsekonge.append(word) + if len(end): + __parsekonge.append({"orig": end, "hira": end}) + hira = __parsekonge for _1 in range(len(hira)): _ = len(hira) - 1 - _1 if globalconfig["hira_vis_type"] == 0: diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser.py index c380df96..947530d6 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser.py @@ -413,7 +413,7 @@ class TextBrowser(QWidget, dataget): tl3 = self.textbrowser.cursorRect(self.textcursor).topLeft() color = self._randomcolor(word) if color: - if word["orig"] not in ["\n", " ", ""]: + if len(word["orig"].strip()): if labeli >= len(self.searchmasklabels) - 1: ql = QLabel(self.atback2) ql.setMouseTracking(True) diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.html b/LunaTranslator/LunaTranslator/rendertext/webview.html index 6518c6c7..c34592be 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.html +++ b/LunaTranslator/LunaTranslator/rendertext/webview.html @@ -113,13 +113,14 @@ } #${_id} .nostroken { color: ${c2}; + z-index: 2; }` for (let i = 0; i < 1 + styleargs.trace * 10; i++) { style.innerHTML += `#${_id} .stroken${i}{ color: ${c1}; -webkit-text-stroke: ${args.fontSize * styleargs.width_rate + styleargs.width}px ${c1}; position: relative; - z-index: -1; + z-index: 1; left: ${(i + 1) / 10}px; top: ${(i + 1) / 10}px; user-select: none; @@ -179,6 +180,7 @@ commoninit_font_align_height(__1, args) wrap.appendChild(__1) } + return wrap } @@ -245,7 +247,15 @@ let mayberuby = [] tag.forEach(word => { let eleori = dispatch_text_style(style, styleargs, word.orig, { atcenter: true, fontFamily: fmori, fontSize: fsori, bold: boldori, color: color, lineHeight: line_height }) - + if (word.orig.trim().length == 0) { + if (isshowhira) { + let rt = document.createElement('rt') + rt.appendChild(eleori) + eleori = rt + } + mayberuby.push(eleori) + return + } if (isshow_fenci || isfenciclick) { let div = document.createElement('div') div.style.display = 'inline-block' @@ -255,6 +265,7 @@ style.innerHTML += `#${div.id} { background-color: ${word.color}; }` + console.log(`${word.color}`) if (isfenciclick) { div.setAttribute('word', JSON.stringify(word)) div.addEventListener('click', function (e) { @@ -271,7 +282,7 @@ mayberuby.push(div) } else - mayberuby.push(div) + mayberuby.push(eleori) if (isshowhira) { let rt = document.createElement('rt') @@ -289,13 +300,13 @@ ruby.appendChild(e) }); ele.appendChild(ruby) + ele.appendChild(document.createElement('br')) } else { mayberuby.forEach(e => { ele.appendChild(e) }); } - ele.appendChild(document.createElement('br')) }) safe_calllunaheightchange(document.getElementById(rootdivid).offsetHeight)