Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Jan 19, 2025
1 parent 84fa84b commit e8449a5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cpp/version.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

set(VERSION_MAJOR 7)
set(VERSION_MINOR 0)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
Expand Down
5 changes: 4 additions & 1 deletion py/LunaTranslator/gui/setting_display_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def __init__(self, parent) -> None:


def mayberefreshe():
gobject.baseobject.translation_ui.translate_text.refreshcontent()
if globalconfig["rendertext_using"] == "textbrowser":
gobject.baseobject.translation_ui.translate_text.refreshcontent()
else:
gobject.baseobject.translation_ui.translate_text.textbrowser.setcolors()


def createinternalfontsettings(self, forml: LFormLayout, group, _type):
Expand Down
10 changes: 6 additions & 4 deletions py/LunaTranslator/gui/textbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,23 @@ def loadinternal(self, shoudong=False):
self.textbrowser.dropfilecallback.connect(self.normdropfilepath)
self.textbrowser.resize(size)
self.textbrowser.show()
self.refreshcontent()
self.refreshcontent(lock=False)

def normdropfilepath(self, file):
self.dropfilecallback.emit(os.path.normpath(file))

def refreshcontent(self):
self.textbrowser.refreshcontent_before()
def refreshcontent(self, lock=True):
if lock:
self.textbrowser.refreshcontent_before()
traces = self.trace.copy()
self.clear()
for t, trace in traces:
if t == 0:
self.append(*trace)
elif t == 1:
self.iter_append(*trace)
self.textbrowser.refreshcontent_after()
if lock:
self.textbrowser.refreshcontent_after()

def __init__(self, parent):
super().__init__(parent)
Expand Down
119 changes: 97 additions & 22 deletions py/LunaTranslator/rendertext/webview.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,40 @@
ele.style.color = `var(--${args.color})`
return ele
}
function yinying_create_internal(styleargs, text, args) {
let ele = document.createElement('div')
maybesethtml(ele, args, text)
ele.style.color = styleargs.fillcolor
function createyinyingstyle(styleargs, _id, color) {
let ntimes = ""
for (let i = 0; i < styleargs.shadowforce; i++) {
ntimes += `0px 0px calc(${styleargs.shadowR}em + ${styleargs.shadowR_ex}px) var(--${args.color})`
ntimes += `0px 0px calc(${styleargs.shadowR}em + ${styleargs.shadowR_ex}px) var(--${color})`
if (i == styleargs.shadowforce - 1)
ntimes += ";"
else
ntimes += ","
}
return `#${_id}{text-shadow:${ntimes}}`
}
function yinying_create_internal(styleargs, text, args) {
let ele = document.createElement('div')
maybesethtml(ele, args, text)
ele.style.color = `var(--YINYING_FILLCOLOR)`
let _id = _simpleuid()
ele.id = _id
let style = document.createElement('style')
style.innerText = `#${_id}{text-shadow:${ntimes}}`
style.innerHTML = createyinyingstyle(styleargs, _id, args.color)
style.classList.add('yinyingstyleklass')
style.setAttribute('__color', args.color)
style.setAttribute('__id', _id)
ele.appendChild(style)
return ele
}
function miaobian12_common(styleargs, text, args) {
let c2 = `var(--${args.color})`
let c1 = styleargs.fillcolor
function createmiaobianstyle(styleargs, _id, color) {

let c2 = `var(--${color})`
let c1 = `var(--miaobianfillcolor)`
if (styleargs.reverse) {
c2 = styleargs.fillcolor
c1 = `var(--${args.color})`
c2 = `var(--miaobianfillcolor)`
c1 = `var(--${color})`
}
let ele = document.createElement('div')
let _id = _simpleuid()
ele.id = _id
let style = document.createElement('style')
style.innerHTML = `
let innerHTML = `
#${_id}{
display: grid;
}
Expand All @@ -142,8 +145,8 @@
color: ${c2};
z-index: 2;
}`
for (let i = 0; i < 1 + styleargs.trace * 10; i++) {
style.innerHTML += `#${_id} .stroken${i}{
for (let i = 0; i < Math.round(1 + styleargs.trace * 10); i++) {
innerHTML += `#${_id} .stroken${i}{
color: ${c1};
-webkit-text-stroke: calc(${styleargs.width_rate}em + ${styleargs.width}px) ${c1};
position: relative;
Expand All @@ -153,13 +156,28 @@
user-select: none;
}`
}
return innerHTML
}
function miaobian12_common(styleargs, text, args) {
let ele = document.createElement('div')
let _id = _simpleuid()
ele.id = _id
let style = document.createElement('style')
style.innerHTML = createmiaobianstyle(styleargs, _id, args.color)
style.setAttribute('__color', args.color)
style.setAttribute('__id', _id)
style.classList.add('miaobiaostyleklass')
ele.appendChild(style)
let p = document.createElement('div')
maybesethtml(p, args, text)
p.classList.add('nostroken')
ele.appendChild(p)
ele.classList.add('miaobiaostyleele')
ele.setAttribute('__save_usehtml', args.userawhtml)
ele.setAttribute('__save_text', text)
ele.setAttribute('__save_n', Math.round(1 + styleargs.trace * 10))

for (let i = 0; i < 1 + styleargs.trace * 10; i++) {
for (let i = 0; i < Math.round(1 + styleargs.trace * 10); i++) {
let p = document.createElement('div')
maybesethtml(p, args, text)
p.classList.add(`stroken${i}`)
Expand Down Expand Up @@ -445,10 +463,66 @@
document.getElementById('styleforfont').innerHTML = style
safe_calllunaheightchange()
}
function yinying_dynamic(styleargs) {
document.querySelectorAll('.yinyingstyleklass').forEach(
(ele) => {
let __color = ele.getAttribute('__color')
let __id = ele.getAttribute('__id')
ele.innerHTML = createyinyingstyle(styleargs, __id, __color)
}
)
return `--YINYING_FILLCOLOR:${styleargs.fillcolor};`
}
function miaobian12_dynamic(styleargs) {
document.querySelectorAll('.miaobiaostyleklass').forEach(
(ele) => {
let __color = ele.getAttribute('__color')
let __id = ele.getAttribute('__id')
ele.innerHTML = createmiaobianstyle(styleargs, __id, __color)
}
)
document.querySelectorAll('.miaobiaostyleele').forEach(
(ele) => {
let targetlen = Math.round(1 + styleargs.trace * 10)
let __save_n = parseInt(ele.getAttribute('__save_n'))
ele.setAttribute('__save_n', targetlen)
console.log(targetlen, __save_n)
if (__save_n > targetlen) {
for (let i = targetlen; i < __save_n; i++) {
ele.querySelectorAll(`.stroken${i}`).forEach(
(e) => {
ele.removeChild(e)
}
)
}
}
else {
let __save_usehtml = ele.getAttribute('__save_usehtml')
let __save_text = ele.getAttribute('__save_text')

for (let i = __save_n; i < targetlen; i++) {
let p = document.createElement('div')
if (__save_usehtml)
p.innerHTML = __save_text
else
p.innerText = __save_text
p.classList.add(`stroken${i}`)
ele.appendChild(p)
}
}
}
)
return `--miaobianfillcolor:${styleargs.fillcolor};`
}
regist_style_dynamic = {
normal: (_) => "",
yinying: yinying_dynamic,
miaobian1: miaobian12_dynamic,
}
function setcolors(colorsjs) {
let colors = JSON.parse(decodeURIComponent(colorsjs))
console.log(colors)
let style = ''
let info = JSON.parse(decodeURIComponent(colorsjs))
let colors = info.color
let style = regist_style_dynamic[info.style](info.styleargs)
for (let klass in colors) {
style += `
--${klass}:${colors[klass]};
Expand All @@ -457,6 +531,7 @@
document.getElementById('colorcontroller').innerHTML = `:root {
${style}
}`
safe_calllunaheightchange()
}
</script>
<script>
Expand Down
7 changes: 5 additions & 2 deletions py/LunaTranslator/rendertext/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ def setcolors(self):
mp = {}
for color in self.colorset:
mp[color.asklass()] = color.get()
self.debugeval("setcolors('{}')".format(quote(json.dumps(mp))))
style = self._getstylevalid()
styleargs = globalconfig["rendertext"]["webview"][style].get("args", {})
infos = dict(color=mp, style=style, styleargs=styleargs)
self.debugeval("setcolors('{}')".format(quote(json.dumps(infos))))

def _setcolors(self, color: ColorControl = None):
if color in self.colorset:
Expand All @@ -322,8 +325,8 @@ def _setcolors(self, color: ColorControl = None):
self.setcolors()

def _webview_append(self, _id, text: str, tag, flags, color: ColorControl):
style = self._getstylevalid()
self._setcolors(color)
style = self._getstylevalid()
styleargs = globalconfig["rendertext"]["webview"][style].get("args", {})
if len(tag):
isshowhira, isshow_fenci, isfenciclick = flags
Expand Down
24 changes: 8 additions & 16 deletions py/files/defaultconfig/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,28 @@
"argstype": {
"fillcolor": {
"name": "填充颜色",
"type": "colorselect",
"dynamic": true
"type": "colorselect"
},
"shadowforce": {
"name": "阴影强度",
"type": "intspin",
"min": 1,
"max": 100,
"step": 1,
"dynamic": true
"step": 1
},
"shadowR": {
"name": "阴影半径",
"type": "spin",
"min": 0,
"max": 10,
"step": 0.01,
"dynamic": true
"step": 0.01
},
"shadowR_ex": {
"name": "阴影半径",
"type": "spin",
"min": 0,
"max": 100,
"step": 0.1,
"dynamic": true
"step": 0.1
}
}
},
Expand All @@ -82,29 +78,25 @@
"argstype": {
"reverse": {
"name": "反转颜色",
"type": "switch",
"dynamic": true
"type": "switch"
},
"fillcolor": {
"name": "填充颜色",
"type": "colorselect",
"dynamic": true
"type": "colorselect"
},
"width": {
"name": "描边宽度",
"type": "spin",
"min": 0,
"max": 100,
"step": 0.1,
"dynamic": true
"step": 0.1
},
"width_rate": {
"name": "描边宽度",
"type": "spin",
"min": 0,
"max": 10,
"step": 0.01,
"dynamic": true
"step": 0.01
},
"trace": {
"name": "投影距离",
Expand Down

0 comments on commit e8449a5

Please sign in to comment.