From 8fcbebd11de1c50fb8aa889f7bab3cfef8358f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 22 Jun 2024 18:23:59 +0800 Subject: [PATCH] trace --- .../rendertext/textbrowser_imp/miaobian1.py | 6 +-- .../LunaTranslator/rendertext/webview.html | 49 +++++++++++-------- .../files/defaultconfig/config.json | 14 ++++-- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py index 951a369c..da5b780d 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py @@ -35,10 +35,10 @@ class TextLine(base): font_m = QFontMetrics(font) path = QPainterPath() - for i in range(self.config["trace"]): + for i in range(1 + int(10 * self.config["trace"])): path.addText( - fontOutLineWidth + i, - fontOutLineWidth + i + font_m.ascent(), + fontOutLineWidth + i / 10, + fontOutLineWidth + i / 10 + font_m.ascent(), font, text, ) diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.html b/LunaTranslator/LunaTranslator/rendertext/webview.html index 141d7767..d8d274d2 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.html +++ b/LunaTranslator/LunaTranslator/rendertext/webview.html @@ -102,32 +102,39 @@ commoninit_font_align_height(ele, args) let style = document.createElement('style') style.innerHTML = ` - #${_id} .stroken{ + #${_id}{ + display: grid; + } + #${_id} div{ + margin: 0; + grid-column: 1; + grid-row: 1; + } + #${_id} .nostroken { + color: ${c2}; + }` + for (let i = 0; i < 1 + styleargs.trace * 10; i++) { + style.innerHTML += `#${_id} .stroken${i}{ -webkit-text-stroke: ${args.fontSize * styleargs.width_rate + styleargs.width}px ${c1}; position: relative; - } - #${_id} .stroken::after { - content: attr(content1); - color: ${c2}; - position: absolute; - left: 0; - right: 0; - top: 0; - -webkit-text-stroke-width: 0; + z-index: -1; + left: ${(i + i) / 10}px; + top: ${(i + i) / 10}px; + user-select: none; }` - - ele.appendChild(style) - let sps = text.split('\n') - for (let i = 0; i < sps.length; i++) { - let div = document.createElement('div') - - div.innerText = sps[i] - - div.setAttribute('content1', sps[i]) - div.classList.add('stroken') - ele.appendChild(div) } + ele.appendChild(style) + let p = document.createElement('div') + p.innerText = text; + p.classList.add('nostroken') + ele.appendChild(p) + for (let i = 0; i < styleargs.trace * 10; i++) { + let p = document.createElement('div') + p.innerText = text; + p.classList.add(`stroken${i}`) + ele.appendChild(p) + } return ele } diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index ab07a247..907a051c 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -90,6 +90,7 @@ "fillcolor": "#eeeeee", "width_rate": 0.1, "width": 3, + "trace": 0, "reverse": true }, "argstype": { @@ -114,6 +115,13 @@ "min": 0, "max": 10, "step": 0.01 + }, + "trace": { + "name": "投影距离", + "type": "spin", + "min": 0, + "max": 100, + "step": 0.1 } } } @@ -148,7 +156,7 @@ "fillcolor": "#eeeeee", "width_rate": 0.1, "width": 3, - "trace": 5, + "trace": 0, "reverse": true }, "argstype": { @@ -176,10 +184,10 @@ }, "trace": { "name": "投影距离", - "type": "intspin", + "type": "spin", "min": 0, "max": 100, - "step": 1 + "step": 0.1 } } },