This commit is contained in:
恍兮惚兮 2024-06-19 22:42:38 +08:00
parent 96cabbfea7
commit f2bf3bc0d4
28 changed files with 347 additions and 130 deletions

View File

@ -328,7 +328,7 @@ class multicolorset(QDialog):
self.resize(QSize(300, 10))
formLayout = QFormLayout(self) # 配置layout
_hori = QHBoxLayout()
l = QLabel(_TR("透明度"))
l = QLabel(_TR("透明度"))
_hori.addWidget(l)
_s = FocusSpin()
_s.setValue(globalconfig["showcixing_touming"])

View File

@ -9,5 +9,7 @@ class TextLine(TextLabel_0):
def setShadow(self):
font = self.font()
self.setShadow_internal(
self.basecolor, font.pointSizeF(), self.config["shadowforce"]
self.basecolor,
font.pointSizeF() * self.config["shadowR"],
self.config["shadowforce"],
)

View File

@ -0,0 +1,73 @@
from qtsymbols import *
from myutils.config import globalconfig
from dataclasses import dataclass
import uuid
@dataclass
class datas:
font_family: str
font_size: float
bold: bool
atcenter: bool
color: str
extra_space: float
class base:
@property
def config(self):
return globalconfig["rendertext"]["webview"][self.typename].get("args", {})
def __init__(self, typename, webview, parent) -> None:
self.typename = typename
self.parent = parent
self.webview = webview
def gen_html__(
self, text, font_family, font_size, bold, atcenter, color, extra_space
):
self.data_ = datas(font_family, font_size, bold, atcenter, color, extra_space)
return self.gen_html(text, self.data_)
def gen_html(self, text, data: datas):
raise
def eval(self, js):
self.parent.testeval(js)
def bind(self, name, func):
self.webview.bind(name, func)
def measureH(self, font_family, font_size):
font = QFont(font_family, font_size)
fmetrics = QFontMetrics(font)
return fmetrics.height()
@property
def line_height(self):
if self.data_.extra_space == 0:
return ""
else:
return f"line-height: {self.measureH(self.data_.font_family,self.data_.font_size)+self.data_.extra_space}px;"
@property
def align(self):
align = "text-align: center;" if self.data_.atcenter else ""
return align
@property
def fontinfo(self):
bold = "font-weight: bold;" if self.data_.bold else ""
fms = f"font-family: {self.data_.font_family};font-size: {self.data_.font_size}pt;"
return fms + bold
def getuid(self):
_id = f"luna_{uuid.uuid4()}"
return _id
def makedivstyle(self, _id, inner, style):
return f'<div id="{_id}">{inner}</div><style>{style}</style>'

View File

@ -1,25 +0,0 @@
from qtsymbols import *
import uuid
def gen_html(configs, text, fm, fs, bold, atcenter, color, extra_space):
align = "text-align: center;" if atcenter else ""
bold = "font-weight: bold;" if bold else ""
_id = f"luna_{uuid.uuid4()}"
ntimes = ""
for i in range(configs["shadowforce"]):
ntimes += f"0px 0px {fs*0.4}px {color}"
if i == configs["shadowforce"] - 1:
ntimes += ";"
else:
ntimes += ","
style = f"""<style>#{_id}{{
font-family: {fm};
font-size: {fs}pt;
color:{configs['fillcolor']};
{bold}
text-shadow:{ntimes};
{align};
line-height: calc(1.2em + {extra_space}px);
}}</style>"""
return style + f'<div id="{_id}">{text}</div>'

View File

@ -0,0 +1,18 @@
from qtsymbols import *
from rendertext.internal.webview.base import base, datas
class TextLine(base):
def gen_html(self, text, data: datas):
_id = self.getuid()
style = f"""#{_id}{{
{self.fontinfo}
color:{self.config["fillcolor"]};
{self.align}
{self.line_height}
-webkit-text-stroke: {self.config['width']}px {data.color};
}}
"""
return self.makedivstyle(_id, text, style)

View File

@ -0,0 +1,37 @@
from qtsymbols import *
from rendertext.internal.webview.base import base, datas
class TextLine(base):
def colorpair(self, color):
return self.config["fillcolor"], color
def gen_html(self, text, data: datas):
c1, c2 = self.colorpair(data.color)
_id = self.getuid()
_text = text.replace('"', '\\"')
style = f"""#{_id} .text{{
{self.fontinfo}
{self.align}
{self.line_height}
}}
#{_id} .stroke {{
-webkit-text-stroke: {self.config['width']}px {c1};
position: relative;
}}
#{_id} .stroke::after {{
content: "{_text}";
color: {c2};
position: absolute;
left: 0;
right: 0;
top: 0;
-webkit-text-stroke-width: 0;
}}
"""
text = f"""<div class="stroke text">
{text}
</div>"""
return self.makedivstyle(_id, text, style)

View File

@ -0,0 +1,8 @@
from qtsymbols import *
from rendertext.internal.webview.miaobian1 import TextLine as TL1
class TextLine(TL1):
def colorpair(self, color):
return color, self.config["fillcolor"]

View File

@ -1,19 +1,17 @@
from qtsymbols import *
import uuid
from rendertext.internal.webview.base import base, datas
def gen_html(configs, text, fm, fs, bold, atcenter, color, extra_space):
align = "text-align: center;" if atcenter else ""
bold = "font-weight: bold;" if bold else ""
_id = f"luna_{uuid.uuid4()}"
style = f"""<style>#{_id}{{
font-family: {fm};
font-size: {fs}pt;
color:white;
color:{color};
{bold}
{align}
line-height: calc(1.2em + {extra_space}px);
}}</style>"""
class TextLine(base):
return style + f'<div id="{_id}">{text}</div>'
def gen_html(self, text, data: datas):
_id = self.getuid()
style = f"""#{_id}{{
{self.fontinfo}
color:{data.color};
{self.align}
{self.line_height}
}}
"""
return self.makedivstyle(_id, text, style)

View File

@ -0,0 +1,24 @@
from qtsymbols import *
from rendertext.internal.webview.base import base, datas
class TextLine(base):
def gen_html(self, text, data: datas):
_id = self.getuid()
ntimes = ""
for i in range(self.config["shadowforce"]):
ntimes += f"0px 0px {data.font_size*self.config['shadowR']}px {data.color}"
if i == self.config["shadowforce"] - 1:
ntimes += ";"
else:
ntimes += ","
style = f"""#{_id}{{
{self.fontinfo}
color:{self.config['fillcolor']};
text-shadow:{ntimes};
{self.align}
{self.line_height}
}}
"""
return self.makedivstyle(_id, text, style)

View File

@ -17,13 +17,11 @@ class dataget:
pass
return (c.red(), c.green(), c.blue(), globalconfig["showcixing_touming"] / 100)
def _randomcolor(self, word, ignorealpha=False):
def _randomcolor(self, word):
color = self._randomcolor_1(word)
if not color:
return None
r, g, b, a = color
if ignorealpha:
a = 1
return f"rgba({r}, {g}, {b}, {a})"
def _getfontinfo(self, origin):

View File

@ -96,7 +96,7 @@ class TextBrowser(QWidget, dataget):
)
def internalheighchange(self):
self.testeval(
self.webivewwidget.webview.eval(
f'calllunaheightchange(document.getElementById("{self.rootdivid}").offsetHeight)'
)
@ -132,64 +132,87 @@ class TextBrowser(QWidget, dataget):
def gen_html(self, *args):
currenttype = globalconfig["rendertext_using_internal"]["webview"]
configs = globalconfig["rendertext"]["webview"][currenttype].get("args", {})
try:
__ = importlib.import_module(f"rendertext.internal.webview.{currenttype}")
except:
from traceback import print_exc
print_exc()
globalconfig["rendertext_using_internal"]["webview"] = currenttype = list(
globalconfig["rendertext"]["webview"].keys()
)[0]
__ = importlib.import_module(f"rendertext.internal.webview.{currenttype}")
return __.gen_html(configs, *args)
return __.TextLine(currenttype, self.webivewwidget.webview, self).gen_html__(
*args
)
def _webview_append(self, _id, origin, atcenter, text, tag, flags, color):
text = text.replace("\n", "<br>").replace("\\", "\\\\")
fmori, fsori, boldori = self._getfontinfo(origin)
fmkana, fskana, boldkana = self._getfontinfo_kana()
kanacolor = self._getkanacolor()
if len(tag):
rb, rb2 = "<ruby>", "</ruby>"
isshowhira, isshow_fenci, isfenciclick = flags
fm, fskana, bold = self._getfontinfo_kana()
kanacolor = self._getkanacolor()
if isshowhira:
rb, rb2, rt, rt2 = "<ruby>", "</ruby>", "<rt>", "</rt>"
rt, rt2 = "<rt>", "</rt>"
else:
rb, rb2, rt, rt2 = "<ruby>", "</ruby>", "", ""
rt, rt2 = "", ""
text = rb
for word in tag:
color1 = self._randomcolor(word, ignorealpha=True)
if isshow_fenci and color1:
style = f' style="color: {color1};" '
else:
style = ""
if word["orig"] == "\n":
text = text + rb2 + "<br>" + rb
continue
if isfenciclick:
click = f'''onclick="calllunaclickedword('{quote(json.dumps(word))}')"'''
else:
click = ""
if word["orig"] == "\n":
text = text + rb2 + "<br>" + rb
continue
text += (
f"""<div {style} {click}>"""
+ word["orig"].replace("\\", "\\\\")
+ "</div>"
_maskid = f"luna_{uuid.uuid4()}"
textori = word["orig"].replace("\\", "\\\\")
textori = self.gen_html(
textori,
fmori,
fsori,
boldori,
atcenter,
color,
globalconfig["extra_space"],
)
text += f"""<div {click} id="{_maskid}">""" + textori + "</div>"
if isshow_fenci:
color1 = self._randomcolor(word)
_style = f"""
<style>#{_maskid}{{
background-color: {color1};
}}</style>"""
text += _style
if (word["orig"] != word["hira"]) and isshowhira:
inner = self.gen_html(
word["hira"],
fm,
word["hira"].replace("\\", "\\\\"),
fmkana,
fskana,
bold,
boldkana,
True,
kanacolor,
globalconfig["extra_space"],
0,
)
else:
inner = ""
text += rt + inner + rt2
text = text + rb2
fm, fs, bold = self._getfontinfo(origin)
text = self.gen_html(
text, fm, fs, bold, atcenter, color, globalconfig["extra_space"]
)
if atcenter:
text = f'<div style="text-align: center;">{text}</div>'
else:
text = self.gen_html(
text,
fmori,
fsori,
boldori,
atcenter,
color,
globalconfig["extra_space"],
)
self.testeval(f"document.getElementById(`{_id}`).innerHTML=`{text}`")
self.internalheighchange()

View File

@ -20,19 +20,20 @@
"primitivtemetaorigin": "vid",
"rendertext_using": "textbrowser",
"rendertext_using_internal": {
"webview": "faguang",
"textbrowser": "faguang"
"webview": "yinying",
"textbrowser": "yinying"
},
"rendertext": {
"webview": {
"normal": {
"name": "普通字体"
},
"faguang": {
"name": "发光字体",
"yinying": {
"name": "阴影字体",
"args": {
"fillcolor": "#eeeeee",
"shadowforce": 5
"shadowforce": 5,
"shadowR": 0.4
},
"argstype": {
"fillcolor": {
@ -40,11 +41,78 @@
"type": "colorselect"
},
"shadowforce": {
"name": "发光亮度",
"name": "阴影强度",
"type": "intspin",
"min": 1,
"max": 100,
"step": 1
},
"shadowR": {
"name": "阴影半径_倍率",
"type": "spin",
"min": 0.1,
"max": 10,
"step": 0.1
}
}
},
"miaobian0": {
"name": "描边字体_1",
"args": {
"fillcolor": "#eeeeee",
"width": 3
},
"argstype": {
"fillcolor": {
"name": "填充颜色",
"type": "colorselect"
},
"width": {
"name": "描边宽度",
"type": "spin",
"min": 0.1,
"max": 100,
"step": 0.1
}
}
},
"miaobian1": {
"name": "描边字体_2",
"args": {
"fillcolor": "#eeeeee",
"width": 3
},
"argstype": {
"fillcolor": {
"name": "填充颜色",
"type": "colorselect"
},
"width": {
"name": "描边宽度",
"type": "spin",
"min": 0.1,
"max": 100,
"step": 0.1
}
}
},
"miaobian2": {
"name": "描边字体_3",
"args": {
"fillcolor": "#eeeeee",
"width": 3
},
"argstype": {
"fillcolor": {
"name": "填充颜色",
"type": "colorselect"
},
"width": {
"name": "描边宽度",
"type": "spin",
"min": 0.1,
"max": 100,
"step": 0.1
}
}
}
@ -113,11 +181,12 @@
}
}
},
"faguang": {
"name": "发光字体",
"yinying": {
"name": "阴影字体",
"args": {
"fillcolor": "#eeeeee",
"shadowforce": 5
"shadowforce": 5,
"shadowR":1
},
"argstype": {
"fillcolor": {
@ -125,11 +194,18 @@
"type": "colorselect"
},
"shadowforce": {
"name": "发光亮度",
"name": "阴影强度",
"type": "intspin",
"min": 1,
"max": 100,
"step": 1
},
"shadowR": {
"name": "阴影半径_倍率",
"type": "spin",
"min": 0.1,
"max": 10,
"step": 0.1
}
}
}

View File

@ -705,8 +705,6 @@
"百度OCR": "بايدو التعرف الضوئي على الحروف",
"飞书OCR": "كتاب الطيران التعرف الضوئي على الحروف",
"讯飞OCR": "التعرف الضوئي على الحروف",
"发光字体": "خط الانارة",
"发光亮度": "سطوع مضيئة",
"最大缓冲区长度": "أقصى طول المخزن المؤقت",
"最大缓存文本长度": "أقصى طول النص مخبأ",
"半径": "نصف قطر",
@ -793,5 +791,6 @@
"兼容接口": "واجهة متوافقة",
"调试浏览器": "تصحيح المتصفح",
"手动翻译": "دليل الترجمة",
"显示引擎": "عرض المحرك"
"显示引擎": "عرض المحرك",
"阴影字体": "خطوط الظل"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "百度OCR",
"飞书OCR": "飛書OCR",
"讯飞OCR": "訊飛OCR",
"发光字体": "發光字體",
"发光亮度": "發光亮度",
"最大缓冲区长度": "最大緩衝區長度",
"最大缓存文本长度": "最大緩存文字長度",
"半径": "半徑",
@ -793,5 +791,6 @@
"兼容接口": "相容介面",
"调试浏览器": "調試瀏覽器",
"手动翻译": "手動翻譯",
"显示引擎": "顯示引擎"
"显示引擎": "顯示引擎",
"阴影字体": "陰影字體"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Baidu OCR",
"飞书OCR": "Feishu OCR",
"讯飞OCR": "IFlytek OCR",
"发光字体": "Luminous font",
"发光亮度": "luminance",
"最大缓冲区长度": "Maximum buffer length",
"最大缓存文本长度": "Maximum cached text length",
"半径": "radius",
@ -793,5 +791,6 @@
"兼容接口": "Compatible interface",
"调试浏览器": "Debugging browser",
"手动翻译": "Manual translation",
"显示引擎": "Display Engine"
"显示引擎": "Display Engine",
"阴影字体": "Shadow font"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Baidu OCR",
"飞书OCR": "Flying Book OCR",
"讯飞OCR": "IFLYTEK OCR",
"发光字体": "Fuente luminosa",
"发光亮度": "Brillo luminoso",
"最大缓冲区长度": "Longitud máxima de la zona de amortiguación",
"最大缓存文本长度": "Longitud máxima del texto en caché",
"半径": "Radio",
@ -793,5 +791,6 @@
"兼容接口": "Interfaz compatible",
"调试浏览器": "Depurar el navegador",
"手动翻译": "Traducción manual",
"显示引擎": "Motor de visualización"
"显示引擎": "Motor de visualización",
"阴影字体": "Fuente de sombra"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Baidu ocr",
"飞书OCR": "Livre volant ocr",
"讯飞OCR": "OCR volant",
"发光字体": "Polices lumineuses",
"发光亮度": "Luminosité lumineuse",
"最大缓冲区长度": "Longueur maximale du tampon",
"最大缓存文本长度": "Longueur maximale du texte mis en cache",
"半径": "Rayon",
@ -793,5 +791,6 @@
"兼容接口": "Interface compatible",
"调试浏览器": "Déboguer le Navigateur",
"手动翻译": "Traduction manuelle",
"显示引擎": "Moteur d'affichage"
"显示引擎": "Moteur d'affichage",
"阴影字体": "Shadow font"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "OCR Baidu",
"飞书OCR": "OCR Feishu",
"讯飞OCR": "OCR IFlytek",
"发光字体": "Carattere luminoso",
"发光亮度": "luminanza",
"最大缓冲区长度": "Lunghezza massima del buffer",
"最大缓存文本长度": "Lunghezza massima del testo memorizzato nella cache",
"半径": "raggio",
@ -793,5 +791,6 @@
"兼容接口": "Interfaccia compatibile",
"调试浏览器": "Browser di debug",
"手动翻译": "Traduzione manuale",
"显示引擎": "Motore di visualizzazione"
"显示引擎": "Motore di visualizzazione",
"阴影字体": "Carattere ombra"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "百度OCR",
"飞书OCR": "フライブックOCR",
"讯飞OCR": "アイフライテックOCR",
"发光字体": "発光フォント",
"发光亮度": "発光輝度",
"最大缓冲区长度": "最大バッファ長",
"最大缓存文本长度": "最大キャッシュテキスト長",
"半径": "半径はんけい",
@ -793,5 +791,6 @@
"兼容接口": "互換インタフェース",
"调试浏览器": "デバッグブラウザ",
"手动翻译": "手動翻訳",
"显示引擎": "ディスプレイエンジン"
"显示引擎": "ディスプレイエンジン",
"阴影字体": "シャドウフォント"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "바이두 OCR",
"飞书OCR": "페이서 OCR",
"讯飞OCR": "아이플라이테크 OCR",
"发光字体": "발광 글꼴",
"发光亮度": "광도",
"最大缓冲区长度": "최대 버퍼 길이",
"最大缓存文本长度": "최대 캐시 텍스트 길이",
"半径": "반지름",
@ -793,5 +791,6 @@
"兼容接口": "호환 인터페이스",
"调试浏览器": "디버그 브라우저",
"手动翻译": "수동 번역",
"显示引擎": "디스플레이 엔진"
"显示引擎": "디스플레이 엔진",
"阴影字体": "그림자 글꼴"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "OCR Baidu",
"飞书OCR": "OCR Feishu",
"讯飞OCR": "OCR IFlytek",
"发光字体": "Jasna czcionka",
"发光亮度": "luminancja",
"最大缓冲区长度": "Maksymalna długość bufora",
"最大缓存文本长度": "Maksymalna długość buforowanego tekstu",
"半径": "promień",
@ -793,5 +791,6 @@
"兼容接口": "Kompatybilny interfejs",
"调试浏览器": "Debugowanie przeglądarki",
"手动翻译": "Tłumaczenie ręczne",
"显示引擎": "Silnik wyświetlania"
"显示引擎": "Silnik wyświetlania",
"阴影字体": "Czcionka cienia"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Сотня OCR",
"飞书OCR": "Летающая книга OCR",
"讯飞OCR": "Сигнал OCR",
"发光字体": "Светящийся шрифт",
"发光亮度": "Светимость",
"最大缓冲区长度": "Максимальная длина буфера",
"最大缓存文本长度": "Максимальная длина текста кэша",
"半径": "Радиус",
@ -793,5 +791,6 @@
"兼容接口": "Совместимый интерфейс",
"调试浏览器": "Отладка браузера",
"手动翻译": "Ручной перевод",
"显示引擎": "Показать движок"
"显示引擎": "Показать движок",
"阴影字体": "Шрифт теней"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "ไป่ตู้ OCR",
"飞书OCR": "หนังสือบิน OCR",
"讯飞OCR": "โปรแกรม iFlytek OCR",
"发光字体": "Luminous ตัวอักษร",
"发光亮度": "ความสว่างส่องสว่าง",
"最大缓冲区长度": "ความยาวบัฟเฟอร์สูงสุด",
"最大缓存文本长度": "ความยาวสูงสุดของข้อความแคช",
"半径": "รัศมี",
@ -793,5 +791,6 @@
"兼容接口": "อินเตอร์เฟซที่เข้ากันได้",
"调试浏览器": "ดีบักเบราว์เซอร์",
"手动翻译": "การแปลด้วยตนเอง",
"显示引擎": "แสดงเครื่องยนต์"
"显示引擎": "แสดงเครื่องยนต์",
"阴影字体": "Shadow ตัวอักษร"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Baidu OCR",
"飞书OCR": "Feishu OCR",
"讯飞OCR": "IFlytek OCR",
"发光字体": "Açık yazıtipi",
"发光亮度": "ışık",
"最大缓冲区长度": "Azamik buffer uzunluğu",
"最大缓存文本长度": "Maximum cached text length",
"半径": "radius",
@ -793,5 +791,6 @@
"兼容接口": "Kompatibil arayüz",
"调试浏览器": "Hata ayıklama tarayıcısı",
"手动翻译": "Elle çevirim",
"显示引擎": "Gösterim Motoru"
"显示引擎": "Gösterim Motoru",
"阴影字体": "Gölge yazıtipi"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Baidu OCR",
"飞书OCR": "Feishu OCR",
"讯飞OCR": "IFlytek OCR",
"发光字体": "Світливий шрифт",
"发光亮度": "світло",
"最大缓冲区长度": "Максимальна довжина буфера",
"最大缓存文本长度": "Максимальна довжина кешування тексту",
"半径": "радіус",
@ -793,5 +791,6 @@
"兼容接口": "Сумісний інтерфейс",
"调试浏览器": "Відладка навігатора",
"手动翻译": "Ручний переклад",
"显示引擎": "Рушій показу"
"显示引擎": "Рушій показу",
"阴影字体": "Шрифт тіні"
}

View File

@ -705,8 +705,6 @@
"百度OCR": "Số lượng OCR",
"飞书OCR": "Sách bay OCR",
"讯飞OCR": "Máy bay OCR",
"发光字体": "Phông phát sáng",
"发光亮度": "Độ sáng phát sáng",
"最大缓冲区长度": "Chiều dài bộ đệm tối đa",
"最大缓存文本长度": "Độ dài văn bản bộ nhớ cache tối đa",
"半径": "Bán kính",
@ -793,5 +791,6 @@
"兼容接口": "Giao diện tương thích",
"调试浏览器": "Gỡ lỗi trình duyệt",
"手动翻译": "Dịch thủ công",
"显示引擎": "Công cụ hiển thị"
"显示引擎": "Công cụ hiển thị",
"阴影字体": "Phông bóng"
}

View File

@ -709,8 +709,6 @@
"百度OCR": "",
"飞书OCR": "",
"讯飞OCR": "",
"发光字体": "",
"发光亮度": "",
"最大缓冲区长度": "",
"最大缓存文本长度": "",
"半径": "",
@ -793,5 +791,6 @@
"最大行数": "",
"超过时截断而非过滤": "",
"调试浏览器": "",
"显示引擎": ""
"显示引擎": "",
"阴影字体": ""
}

View File

@ -28,8 +28,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
include(generate_product_version)
set(VERSION_MAJOR 5)
set(VERSION_MINOR 0)
set(VERSION_PATCH 2)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h)