Skip to content

Commit

Permalink
alpha 1.16.5 update
Browse files Browse the repository at this point in the history
描边文本添加了可以指定宽度的功能
  • Loading branch information
DanDDXuanX committed Nov 5, 2022
1 parent c266e51 commit b0eba08
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 22 deletions.
6 changes: 5 additions & 1 deletion core/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class MediaError(RplGenError):
"({})对于内建动画-骰子,是非法参数。"],
'BadAudio' :["Unsupported audio files '{}'",
"不支持的音频文件 '{}'"],
'InvEgWd' :["Invalid edge width {} for StrokeText!",
"为描边文本指定的描边宽度 {} 是非法的值!"],
}
error_type = ["\x1B[31m[MediaError]:\x1B[0m ",
"\x1B[31m[媒体错误]:\x1B[0m "]
Expand Down Expand Up @@ -437,7 +439,9 @@ class WarningPrint(Print):
'BGMIgnore' :["BGM '{}' is automatically ignored, you should add BGM manually in Premiere Pro later.",
"背景音乐 “{}” 被自动地忽略了!你应该稍后在Premiere Pro软件中手动添加背景音乐。"],
'BadAuFile' :["Audio file '{}' is not exist.",
"音频文件 '{}' 并不存在!"]
"音频文件 '{}' 并不存在!"],
'WideEdge' :["The edge width is set to more than 3, which may cause unintended results.",
"描边宽度被设置超过3,这可能导致意料之外的显示效果。"]
}
# 类型:警告
info_type = ["\x1B[33m[warning]:\x1B[0m ",
Expand Down
27 changes: 21 additions & 6 deletions core/Medias.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,34 @@ def convert(self):
# 描边文本,是Text的子类。注意,使用这个媒体类可能会影响帧率!
class StrokeText(Text):
pygame.font.init()
def __init__(self,fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(0,0,0,255),line_limit=20,edge_color=(255,255,255,255),label_color='Lavender'):
def __init__(self,fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(0,0,0,255),line_limit=20,edge_color=(255,255,255,255),edge_width=1,label_color='Lavender'):
super().__init__(fontfile=fontfile,fontsize=fontsize,color=color,line_limit=line_limit,label_color=label_color) # 继承
self.edge_color=edge_color
self.edge_color = edge_color
try:
self.edge_width = int(edge_width)
except ValueError:
raise MediaError("InvEgWd",edge_width)
if self.edge_width < 0:
raise MediaError("InvEgWd",edge_width)
elif self.edge_width > 3:
print(WarningPrint('WideEdge'))
# bug:受限于pygame的性能,无法正确的表现透明度不同的描边和字体,但在导出PR项目时是正常的
if (self.color[3] < 255) | (self.edge_color[3] < 255):
print(WarningPrint('AlphaText'))
def render(self,tx):
edge = self.text_render.render(tx,True,self.edge_color[0:3])
face = self.text_render.render(tx,True,self.color[0:3])
canvas = pygame.Surface((edge.get_size()[0]+2,edge.get_size()[1]+2),pygame.SRCALPHA)
for pos in [(0,0),(0,1),(0,2),(1,0),(1,2),(2,0),(2,1),(2,2)]:
canvas.blit(edge,pos) # 最大值混合,避免多次blit的叠加
canvas.blit(face,(1,1))
ew = self.edge_width
canvas = pygame.Surface((edge.get_size()[0]+2*ew,edge.get_size()[1]+2*ew),pygame.SRCALPHA)
# 角
for pos in [[0,0],[0,2*ew],[2*ew,0],[2*ew,2*ew]]:
canvas.blit(edge,pos)
# 边
for i in range(1,ew*2):
for pos in [[0,i],[i,0],[2*ew,i],[i,2*ew]]:
canvas.blit(edge,pos)
# 中心
canvas.blit(face,(ew,ew))
# bug:受限于pygame的性能,无法正确的表现透明度不同的描边和字体,但在导出PR项目时是正常的
if (self.color[3] < 255) | (self.edge_color[3] < 255):
# 按照透明度的最小值显示
Expand Down
2 changes: 1 addition & 1 deletion core/Utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# coding: utf-8
# 小工具们
EDITION = 'alpha 1.16.4'
EDITION = 'alpha 1.16.5'

import numpy as np
import time
Expand Down
23 changes: 19 additions & 4 deletions export_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,31 @@ def convert(self):
pass

class StrokeText(Text):
def __init__(self,fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(0,0,0,255),line_limit=20,edge_color=(255,255,255,255),label_color='Lavender'):
def __init__(self,fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(0,0,0,255),line_limit=20,edge_color=(255,255,255,255),edge_width=1,label_color='Lavender'):
super().__init__(fontfile=fontfile,fontsize=fontsize,color=color,line_limit=line_limit,label_color=label_color) # 继承
self.edge_color=edge_color
try:
self.edge_width = int(edge_width)
except ValueError:
raise MediaError("InvEgWd",edge_width)
if self.edge_width < 0:
raise MediaError("InvEgWd",edge_width)
elif self.edge_width > 3:
print(WarningPrint('WideEdge'))
def render(self,tx):
ew = self.edge_width
font_this = ImageFont.truetype(self.fontpath, self.size)
text_this = Image.new(mode='RGBA',size=(self.size*int(len(tx)*1.5),self.size*2),color=(0,0,0,0)) # 画布贪婪为2x高度,1.5*宽度
text_this = Image.new(mode='RGBA',size=(self.size*int(len(tx)*1.5)+2*ew,self.size*2+2*ew),color=(0,0,0,0)) # 画布贪婪为2x高度,1.5*宽度
draw_this = ImageDraw.Draw(text_this)
for pos in [(0,0),(0,1),(0,2),(1,0),(1,2),(2,0),(2,1),(2,2)]:
# 角
for pos in [[0,0],[0,2*ew],[2*ew,0],[2*ew,2*ew]]:
draw_this.text(pos,tx,font = font_this,align ="left",fill = self.edge_color)
draw_this.text((1,1),tx,font = font_this,align ="left",fill = self.color)
# 边
for i in range(1,ew*2):
for pos in [[0,i],[i,0],[2*ew,i],[i,2*ew]]:
draw_this.text(pos,tx,font = font_this,align ="left",fill = self.edge_color)
# 中心
draw_this.text((ew,ew),tx,font = font_this,align ="left",fill = self.color)
return text_this

# 对话框、气泡、文本框
Expand Down
21 changes: 17 additions & 4 deletions gui/subwindows/Media.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,30 @@ def preview(self,image_canvas,prevpos='None'):
else:
image_canvas.paste(draw_text,prevpos,mask=draw_text.split()[-1])
class StrokeText(Text):
def __init__(self,fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(0,0,0,255),line_limit=20,edge_color=(255,255,255,255),label_color='Lavender'):
def __init__(self,fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(0,0,0,255),line_limit=20,edge_color=(255,255,255,255),edge_width=1,label_color='Lavender'):
super().__init__(fontfile=fontfile,fontsize=fontsize,color=color,line_limit=line_limit,label_color=label_color)
self.edge_color=edge_color
try:
self.edge_width = int(edge_width)
except ValueError:
raise Exception("非法的描边宽度!")
if self.edge_width < 0:
raise Exception("非法的描边宽度!")
def draw(self,lenth=-1):
if lenth ==-1:
lenth = self.line_limit
test_canvas = Image.new(mode='RGBA',size=(self.size*int(self.line_limit*1.5),self.size*2),color=(0,0,0,0))#高度贪婪2x,宽度贪婪1.5x
ew = self.edge_width
test_canvas = Image.new(mode='RGBA',size=(self.size*int(self.line_limit*1.5)+2*ew,self.size*2+2*ew),color=(0,0,0,0))#高度贪婪2x,宽度贪婪1.5x
test_draw = ImageDraw.Draw(test_canvas)
for pos in [(0,0),(0,1),(0,2),(1,0),(1,2),(2,0),(2,1),(2,2)]:
# 角
for pos in [[0,0],[0,2*ew],[2*ew,0],[2*ew,2*ew]]:
test_draw.text(pos, ('测试文本'*50)[0:lenth], font = self.text_render,fill = self.edge_color)
test_draw.text((1,1), ('测试文本'*50)[0:lenth], font = self.text_render,fill = self.color)
# 边
for i in range(1,ew*2):
for pos in [[0,i],[i,0],[2*ew,i],[i,2*ew]]:
test_draw.text(pos, ('测试文本'*50)[0:lenth], font = self.text_render,fill = self.edge_color)
# 中心
test_draw.text((ew,ew), ('测试文本'*50)[0:lenth], font = self.text_render,fill = self.color)
p1,p2,p3,p4 = test_canvas.getbbox()
return test_canvas.crop((0,0,p3,p4))
class Bubble(Media):
Expand Down
13 changes: 9 additions & 4 deletions gui/subwindows/MediaDefWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

label_pos_show_text = ImageFont.truetype('./media/SourceHanSerifSC-Heavy.otf', 30)
# RE_mediadef_args = re.compile('(fontfile|fontsize|color|line_limit|filepath|Main_Text|Header_Text|pos|end|x_step|y_step|mt_pos|mt_end|ht_pos|ht_target|fill_mode|align|line_distance|tick|loop|volume|edge_color|label_color)?\ {0,4}=?\ {0,4}(Text\(\)|[^,()]+|\([-\d,\ ]+\))')
RE_mediadef_args = re.compile("(fontfile|fontsize|color|line_limit|filepath|Main_Text|Header_Text|pos|end|x_step|y_step|mt_pos|mt_end|ht_pos|ht_target|fill_mode|align|line_distance|tick|loop|volume|edge_color|sub_key|sub_Bubble|sub_Anime|sub_align|sub_pos|sub_end|am_left|am_right|sub_distance|label_color)?\ {0,4}=?\ {0,4}(Text\(\)|Pos\(\)|\[[\w,'()]+\]|\w+\[[\d\,]+\]|[^,()]+|\([-\d,\ ]+\))")
RE_mediadef_args = re.compile("(fontfile|fontsize|color|line_limit|filepath|Main_Text|Header_Text|pos|end|x_step|y_step|mt_pos|mt_end|ht_pos|ht_target|fill_mode|align|line_distance|tick|loop|volume|edge_color|edge_width|sub_key|sub_Bubble|sub_Anime|sub_align|sub_pos|sub_end|am_left|am_right|sub_distance|label_color)?\ {0,4}=?\ {0,4}(Text\(\)|Pos\(\)|\[[\w,'()]+\]|\w+\[[\d\,]+\]|[^,()]+|\([-\d,\ ]+\))")
# RE_parse_mediadef = re.compile('(\w+)[=\ ]+(Pos|FreePos|PosGrid|Text|StrokeText|Bubble|Animation|Background|BGM|Audio)(\(.+\))')
RE_vaildname = re.compile('^\w+$')
RE_pos_args = re.compile('(\d+),(\d+)|\*\((\d+),(\d+)\)')
Expand Down Expand Up @@ -404,7 +404,7 @@ def comfirm_obj():
'ht_pos':ht_pos.get(),'ht_target':ht_target.get(),
'align':align.get(),'fill_mode':fill_mode.get(),
'line_distance':line_distance.get(),'tick':tick.get(),'loop':loop.get(),
'volume':volume.get(),'edge_color':edge_color.get(),
'volume':volume.get(),'edge_color':edge_color.get(),'edge_width':edge_width.get(),
'sub_key':sub_key.get(),'sub_Bubble':sub_Bubble.get(),'sub_Anime':sub_Anime.get(),
'sub_align':sub_align.get(),'sub_pos':sub_pos.get(),'sub_end':sub_end.get(),
'am_left':am_left.get(),'am_right':am_right.get(),'sub_distance':sub_distance.get(),
Expand Down Expand Up @@ -499,7 +499,7 @@ def call_grouped_args_select(type):
'FreePos':"{pos}",
'PosGrid':"(pos={pos},end={end},x_step={x_step},y_step={y_step})",
'Text':"(fontfile='{fontfile}',fontsize={fontsize},color={color},line_limit={line_limit},label_color='{label_color}')",
'StrokeText':"(fontfile='{fontfile}',fontsize={fontsize},color={color},line_limit={line_limit},edge_color={edge_color},label_color='{label_color}')",
'StrokeText':"(fontfile='{fontfile}',fontsize={fontsize},color={color},line_limit={line_limit},edge_color={edge_color},edge_width={edge_width},label_color='{label_color}')",
'Animation':"(filepath='{filepath}',pos={pos},tick={tick},loop={loop},label_color='{label_color}')",
'Background':"(filepath='{filepath}',pos={pos},label_color='{label_color}')",
'Bubble':"(filepath='{filepath}',Main_Text={Main_Text},Header_Text={Header_Text},pos={pos},mt_pos={mt_pos},ht_pos={ht_pos},ht_target={ht_target},align='{align}',line_distance={line_distance},label_color='{label_color}')",
Expand Down Expand Up @@ -569,6 +569,7 @@ def call_grouped_args_select(type):
loop = tk.BooleanVar(Objdef_windows)
volume = tk.IntVar()
edge_color = tk.StringVar(Objdef_windows)
edge_width = tk.IntVar(Objdef_windows)
sub_key = tk.StringVar(Objdef_windows)
sub_Bubble = tk.StringVar(Objdef_windows)
sub_Anime = tk.StringVar(Objdef_windows)
Expand Down Expand Up @@ -599,6 +600,7 @@ def call_grouped_args_select(type):
loop.set(True)
volume.set(100)
edge_color.set('(255,255,255,255)')
edge_width.set(1)
mt_end.set('(0,0)')
ht_target.set("'Name'") ################BUG in Balloon
fill_mode.set('stretch')
Expand All @@ -620,7 +622,7 @@ def call_grouped_args_select(type):
# 外部输入参数
type_keyword_position = {'Pos':['pos'],'FreePos':['pos'],'PosGrid':['pos','end','x_step','y_step'],
'Text':['fontfile','fontsize','color','line_limit','label_color'],
'StrokeText':['fontfile','fontsize','color','line_limit','edge_color','label_color'],
'StrokeText':['fontfile','fontsize','color','line_limit','edge_color','edge_width','label_color'],
'Bubble':['filepath','Main_Text','Header_Text','pos','mt_pos','ht_pos','ht_target','align','line_distance','label_color'],
'Balloon':['filepath','Main_Text','Header_Text','pos','mt_pos','ht_pos','ht_target','align','line_distance','label_color'],
'DynamicBubble':['filepath','Main_Text','Header_Text','pos','mt_pos','mt_end','ht_pos','ht_target','fill_mode','line_distance','label_color'],
Expand Down Expand Up @@ -704,16 +706,19 @@ def call_grouped_args_select(type):
ttk.Label(StrokeText_frame,text='字体颜色').place(x=10,y=70,width=65,height=25)
ttk.Label(StrokeText_frame,text='单行字数').place(x=10,y=100,width=65,height=25)
ttk.Label(StrokeText_frame,text='描边颜色').place(x=10,y=130,width=65,height=25)
ttk.Label(StrokeText_frame,text='描边宽度').place(x=10,y=160,width=65,height=25)
ttk.Entry(StrokeText_frame,textvariable=fontfile).place(x=75,y=10,width=160,height=25)
ttk.Entry(StrokeText_frame,textvariable=fontsize).place(x=75,y=40,width=160,height=25)
ttk.Entry(StrokeText_frame,textvariable=color).place(x=75,y=70,width=160,height=25)
ttk.Entry(StrokeText_frame,textvariable=line_limit).place(x=75,y=100,width=160,height=25)
ttk.Entry(StrokeText_frame,textvariable=edge_color).place(x=75,y=130,width=160,height=25)
ttk.Entry(StrokeText_frame,textvariable=edge_width).place(x=75,y=160,width=160,height=25)
ttk.Button(StrokeText_frame,text='浏览',command=lambda:call_browse_file(fontfile,'file',filetype='fontfile')).place(x=240,y=10,width=50,height=25)
ttk.Label(StrokeText_frame,text='(整数)',anchor='center').place(x=240,y=40,width=50,height=25)
ttk.Button(StrokeText_frame,text='选择',command=lambda:call_choose_color(color)).place(x=240,y=70,width=50,height=25)
ttk.Label(StrokeText_frame,text='(整数)',anchor='center').place(x=240,y=100,width=50,height=25)
ttk.Button(StrokeText_frame,text='选择',command=lambda:call_choose_color(edge_color)).place(x=240,y=130,width=50,height=25)
ttk.Label(StrokeText_frame,text='(整数)',anchor='center').place(x=240,y=160,width=50,height=25)

# Bubble_frame
# 左
Expand Down
2 changes: 1 addition & 1 deletion gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from tkinter import colorchooser, filedialog, messagebox

EDITION = '1.16.4'
EDITION = '1.16.5'

def browse_file(text_obj, method='file',filetype=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion toy/MediaObject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ KP立绘位置 = FreePos(0,480)
大文本 = Text(fontfile='./media/SourceHanSerifSC-Heavy.otf',fontsize=100,color=(255,255,255,255),line_limit=15,label_color='Lavender')
血条字体 = Text(fontfile='./toy/media/consola.ttf',fontsize=40,color=(255,87,87,255),line_limit=20,label_color='Lavender')
聊天窗主文本 = Text(fontfile='./media/SourceHanSansCN-Regular.otf',fontsize=40,color=(60,60,60,255),line_limit=20,label_color='Lavender')
气泡头文本 = StrokeText(fontfile='./media/SourceHanSerifSC-Heavy.otf',fontsize=40,color=(255,255,255,255),line_limit=10,edge_color=(60,60,60,255),label_color='Lavender')
气泡头文本 = StrokeText(fontfile='./media/SourceHanSerifSC-Heavy.otf',fontsize=40,color=(255,255,255,255),line_limit=10,edge_color=(60,60,60,255),edge_width=3,label_color='Lavender')
张安翔 = Animation(filepath='./toy/media/am1.png',pos=张安翔立绘位置,tick=1,loop=True,label_color='Lavender')
果汁 = Animation(filepath='./toy/media/am3.png',pos=KP立绘位置,tick=1,loop=True,label_color='Lavender')
伊可 = Animation(filepath='./toy/media/正作伊可.png',pos=(1375,481),tick=1,loop=True,label_color='Lavender')
Expand Down

0 comments on commit b0eba08

Please sign in to comment.