This commit is contained in:
恍兮惚兮 2024-06-19 20:17:57 +08:00
parent 00e7038e95
commit 72a75b1a4f
3 changed files with 21 additions and 15 deletions

View File

@ -2,7 +2,7 @@ from qtsymbols import *
import uuid import uuid
def gen_html(configs, text, fm, fs, bold, atcenter, color): def gen_html(configs, text, fm, fs, bold, atcenter, color, extra_space):
align = "text-align: center;" if atcenter else "" align = "text-align: center;" if atcenter else ""
bold = "font-weight: bold;" if bold else "" bold = "font-weight: bold;" if bold else ""
_id = f"luna_{uuid.uuid4()}" _id = f"luna_{uuid.uuid4()}"
@ -19,7 +19,7 @@ def gen_html(configs, text, fm, fs, bold, atcenter, color):
color:{configs['fillcolor']}; color:{configs['fillcolor']};
{bold} {bold}
text-shadow:{ntimes}; text-shadow:{ntimes};
{align} {align};
line-height: calc(1.5em + {extra_space}px);
}}</style>""" }}</style>"""
return style + f'<div id="{_id}">{text}</div>' return style + f'<div id="{_id}">{text}</div>'

View File

@ -1,7 +1,8 @@
from qtsymbols import * from qtsymbols import *
import uuid import uuid
def gen_html(configs, text, fm, fs, bold, atcenter, color):
def gen_html(configs, text, fm, fs, bold, atcenter, color, extra_space):
align = "text-align: center;" if atcenter else "" align = "text-align: center;" if atcenter else ""
bold = "font-weight: bold;" if bold else "" bold = "font-weight: bold;" if bold else ""
_id = f"luna_{uuid.uuid4()}" _id = f"luna_{uuid.uuid4()}"
@ -12,6 +13,7 @@ def gen_html(configs, text, fm, fs, bold, atcenter, color):
color:{color}; color:{color};
{bold} {bold}
{align} {align}
line-height: calc(1.5em + {extra_space}px);
}}</style>""" }}</style>"""
return style + f'<div id="{_id}">{text}</div>' return style + f'<div id="{_id}">{text}</div>'

View File

@ -130,7 +130,7 @@ class TextBrowser(QWidget, dataget):
def calllunaclickedword(self, packedwordinfo): def calllunaclickedword(self, packedwordinfo):
gobject.baseobject.clickwordcallback(json.loads(unquote(packedwordinfo)), False) gobject.baseobject.clickwordcallback(json.loads(unquote(packedwordinfo)), False)
def gen_html(self, text, fm, fs, bold, atcenter, color): def gen_html(self, *args):
currenttype = globalconfig["rendertext_using_internal"]["webview"] currenttype = globalconfig["rendertext_using_internal"]["webview"]
configs = globalconfig["rendertext"]["webview"][currenttype].get("args", {}) configs = globalconfig["rendertext"]["webview"][currenttype].get("args", {})
try: try:
@ -140,7 +140,7 @@ class TextBrowser(QWidget, dataget):
globalconfig["rendertext"]["webview"].keys() globalconfig["rendertext"]["webview"].keys()
)[0] )[0]
__ = importlib.import_module(f"rendertext.internal.webview.{currenttype}") __ = importlib.import_module(f"rendertext.internal.webview.{currenttype}")
return __.gen_html(configs, text, fm, fs, bold, atcenter, color) return __.gen_html(configs, *args)
def _webview_append(self, _id, origin, atcenter, text, tag, flags, color): def _webview_append(self, _id, origin, atcenter, text, tag, flags, color):
text = text.replace("\n", "<br>").replace("\\", "\\\\") text = text.replace("\n", "<br>").replace("\\", "\\\\")
@ -170,7 +170,15 @@ class TextBrowser(QWidget, dataget):
if (word["orig"] != word["hira"]) and isshowhira: if (word["orig"] != word["hira"]) and isshowhira:
text += ( text += (
f"<rt>" f"<rt>"
+ self.gen_html(word["hira"], fm, fskana, bold, True, kanacolor) + self.gen_html(
word["hira"],
fm,
fskana,
bold,
True,
kanacolor,
globalconfig["extra_space"],
)
+ "</rt>" + "</rt>"
) )
else: else:
@ -178,13 +186,9 @@ class TextBrowser(QWidget, dataget):
text = text + "</ruby>" text = text + "</ruby>"
fm, fs, bold = self._getfontinfo(origin) fm, fs, bold = self._getfontinfo(origin)
text = self.gen_html(text, fm, fs, bold, atcenter, color) text = self.gen_html(
_id_wrap = f"luna_{uuid.uuid4()}" text, fm, fs, bold, atcenter, color, globalconfig["extra_space"]
text = f"""<div id="{_id_wrap}">{text}</div><style> )
#{_id_wrap}{{
margin-bottom:{globalconfig["extra_space"]}px
}}
</style>"""
self.testeval(f"document.getElementById(`{_id}`).innerHTML=`{text}`") self.testeval(f"document.getElementById(`{_id}`).innerHTML=`{text}`")
self.internalheighchange() self.internalheighchange()