From 0bed820401b97c79a839ad130b2dfff91b3408ff 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 00:51:53 +0800 Subject: [PATCH] size --- .../gui/setting_display_text.py | 3 +- .../rendertext/textbrowser_imp/miaobian0.py | 8 +- .../rendertext/textbrowser_imp/miaobian1.py | 26 +++++-- .../rendertext/textbrowser_imp/yinying.py | 17 +++- .../LunaTranslator/rendertext/webview.html | 6 +- .../files/defaultconfig/config.json | 78 +++++++++++++++---- LunaTranslator/files/lang/zh.json | 7 +- 7 files changed, 114 insertions(+), 31 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index 15d90cfe..16d78332 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -14,7 +14,6 @@ from gui.usefulwidget import ( D_getIconButton, D_getcolorbutton, getcolorbutton, - getboxlayout, D_getsimpleswitch, selectcolor, FocusFontCombo, @@ -179,7 +178,7 @@ def createinternalfontsettings(self, forml, group, _type): lineW.setValue(dd[key]) lineW.valueChanged.connect(functools.partial(dd.__setitem__, key)) forml.addRow( - name, + _TR(name), lineW, ) diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian0.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian0.py index 2076c374..50fc7c52 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian0.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian0.py @@ -9,22 +9,22 @@ class TextLine(base): def paintText(self, painter: QPainter): self.m_outLineColor, self.m_contentColor = self.colorpair() - self.m_fontOutLineWidth = self.config["width"] + fontOutLineWidth = self.config["width"] text = self.text() font = self.font() font_m = QFontMetrics(font) path = QPainterPath() path.addText( - self.m_fontOutLineWidth, - self.m_fontOutLineWidth + font_m.ascent(), + fontOutLineWidth, + fontOutLineWidth + font_m.ascent(), font, text, ) pen = QPen( self.m_outLineColor, - self.m_fontOutLineWidth, + fontOutLineWidth, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin, diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py index bf4f4a0e..92ccbbbb 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/miaobian1.py @@ -3,28 +3,44 @@ from rendertext.textbrowser_imp.base import base class TextLine(base): + def moveoffset(self): + font = self.font() + fontOutLineWidth = ( + self.config["width"] + font.pointSizeF() * self.config["width_rate"] + ) + return fontOutLineWidth, fontOutLineWidth + + def extraWH(self): + font = self.font() + fontOutLineWidth = ( + self.config["width"] + font.pointSizeF() * self.config["width_rate"] + ) + fontOutLineWidth *= 2 + return fontOutLineWidth, fontOutLineWidth def colorpair(self): return QColor(self.config["fillcolor"]), QColor(self.basecolor) def paintText(self, painter: QPainter): self.m_outLineColor, self.m_contentColor = self.colorpair() - self.m_fontOutLineWidth = self.config["width"] - text = self.text() font = self.font() + fontOutLineWidth = ( + self.config["width"] + font.pointSizeF() * self.config["width_rate"] + ) + font_m = QFontMetrics(font) path = QPainterPath() path.addText( - self.m_fontOutLineWidth, - self.m_fontOutLineWidth + font_m.ascent(), + fontOutLineWidth, + fontOutLineWidth + font_m.ascent(), font, text, ) pen = QPen( self.m_outLineColor, - self.m_fontOutLineWidth, + fontOutLineWidth, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin, diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/yinying.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/yinying.py index 2f1315bc..3415a9a1 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/yinying.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/yinying.py @@ -13,6 +13,21 @@ class QGraphicsDropShadowEffect_multi(QGraphicsDropShadowEffect): class TextLine(TextLabel_0): + def moveoffset(self): + font = self.font() + fontOutLineWidth = ( + font.pointSizeF() * self.config["shadowR"] + self.config["shadowR_ex"] + ) + return fontOutLineWidth, fontOutLineWidth + + def extraWH(self): + font = self.font() + fontOutLineWidth = ( + font.pointSizeF() * self.config["shadowR"] + self.config["shadowR_ex"] + ) + fontOutLineWidth *= 2 + return fontOutLineWidth, fontOutLineWidth + def usingcolor(self): return QColor(self.config["fillcolor"]) @@ -29,6 +44,6 @@ class TextLine(TextLabel_0): font = self.font() self.setShadow_internal( self.basecolor, - font.pointSizeF() * self.config["shadowR"], + font.pointSizeF() * self.config["shadowR"] + self.config["shadowR_ex"], self.config["shadowforce"], ) diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.html b/LunaTranslator/LunaTranslator/rendertext/webview.html index 947961ef..5022d758 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.html +++ b/LunaTranslator/LunaTranslator/rendertext/webview.html @@ -59,7 +59,7 @@ let ntimes = "" for (let i = 0; i < styleargs.shadowforce; i++) { - ntimes += `0px 0px ${args.fontSize * styleargs.shadowR}px ${args.color}` + ntimes += `0px 0px ${args.fontSize * styleargs.shadowR + styleargs.shadowR_ex}px ${args.color}` if (i == styleargs.shadowforce - 1) ntimes += ";" else @@ -93,7 +93,7 @@ let style = document.createElement('style') style.innerHTML = ` #${_id} .stroken{ - -webkit-text-stroke: ${styleargs.width}px ${c1}; + -webkit-text-stroke: ${args.fontSize * styleargs.width_rate + styleargs.width}px ${c1}; position: relative; } #${_id} .stroken::after { @@ -207,7 +207,7 @@ if (isshow_fenci || isfenciclick) { let div = document.createElement('div') - div.style.display='inline-block' + div.style.display = 'inline-block' div.id = _simpleuid() let style = document.createElement('style') if (isshow_fenci) diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index a05085ff..34c2ac51 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -33,7 +33,8 @@ "args": { "fillcolor": "#eeeeee", "shadowforce": 5, - "shadowR": 0.4 + "shadowR": 0.1, + "shadowR_ex": 3 }, "argstype": { "fillcolor": { @@ -48,10 +49,17 @@ "step": 1 }, "shadowR": { - "name": "阴影半径_倍率", + "name": "阴影半径_字体倍率", "type": "spin", - "min": 0.1, + "min": 0, "max": 10, + "step": 0.01 + }, + "shadowR_ex": { + "name": "阴影半径_固定值", + "type": "spin", + "min": 0, + "max": 100, "step": 0.1 } } @@ -70,7 +78,7 @@ "width": { "name": "描边宽度", "type": "spin", - "min": 0.1, + "min": 0, "max": 100, "step": 0.1 } @@ -80,6 +88,7 @@ "name": "描边字体_2", "args": { "fillcolor": "#eeeeee", + "width_rate": 0.1, "width": 3 }, "argstype": { @@ -88,11 +97,18 @@ "type": "colorselect" }, "width": { - "name": "描边宽度", + "name": "描边宽度_固定值", "type": "spin", - "min": 0.1, + "min": 0, "max": 100, "step": 0.1 + }, + "width_rate": { + "name": "描边宽度_字体倍率", + "type": "spin", + "min": 0, + "max": 10, + "step": 0.01 } } }, @@ -100,6 +116,7 @@ "name": "描边字体_3", "args": { "fillcolor": "#eeeeee", + "width_rate": 0.1, "width": 3 }, "argstype": { @@ -108,11 +125,18 @@ "type": "colorselect" }, "width": { - "name": "描边宽度", + "name": "描边宽度_固定值", "type": "spin", - "min": 0.1, + "min": 0, "max": 100, "step": 0.1 + }, + "width_rate": { + "name": "描边宽度_字体倍率", + "type": "spin", + "min": 0, + "max": 10, + "step": 0.01 } } } @@ -145,6 +169,7 @@ "name": "描边字体_2", "args": { "fillcolor": "#eeeeee", + "width_rate": 0.1, "width": 3 }, "argstype": { @@ -153,11 +178,18 @@ "type": "colorselect" }, "width": { - "name": "描边宽度", + "name": "描边宽度_固定值", "type": "spin", - "min": 0.1, + "min": 0, "max": 100, "step": 0.1 + }, + "width_rate": { + "name": "描边宽度_字体倍率", + "type": "spin", + "min": 0, + "max": 10, + "step": 0.01 } } }, @@ -165,6 +197,7 @@ "name": "描边字体_3", "args": { "fillcolor": "#eeeeee", + "width_rate": 0.1, "width": 3 }, "argstype": { @@ -173,11 +206,18 @@ "type": "colorselect" }, "width": { - "name": "描边宽度", + "name": "描边宽度_固定值", "type": "spin", - "min": 0.1, + "min": 0, "max": 100, "step": 0.1 + }, + "width_rate": { + "name": "描边宽度_字体倍率", + "type": "spin", + "min": 0, + "max": 10, + "step": 0.01 } } }, @@ -186,7 +226,8 @@ "args": { "fillcolor": "#eeeeee", "shadowforce": 5, - "shadowR": 1 + "shadowR": 1, + "shadowR_ex": 3 }, "argstype": { "fillcolor": { @@ -201,10 +242,17 @@ "step": 1 }, "shadowR": { - "name": "阴影半径_倍率", + "name": "阴影半径_字体倍率", "type": "spin", - "min": 0.1, + "min": 0, "max": 10, + "step": 0.01 + }, + "shadowR_ex": { + "name": "阴影半径_固定值", + "type": "spin", + "min": 0, + "max": 100, "step": 0.1 } } diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 7d0de99d..9f3b616c 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -803,5 +803,10 @@ "按钮大小": "", "软件显示语言": "", "重启生效": "", - "不支持的游戏?": "" + "不支持的游戏?": "", + "填充颜色": "", + "阴影强度": "", + "阴影半径": "", + "字体倍率": "", + "固定值": "" } \ No newline at end of file