-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlite.main.aardio
More file actions
271 lines (244 loc) · 13.4 KB
/
Copy pathlite.main.aardio
File metadata and controls
271 lines (244 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
Copyright (c) [2023] [MIKACHU2333]
[kaf-cli-gui-lite] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
import win.ui
import fsys
import fsys.dlg
/*DSG{{*/
mainForm = win.form(cls="kaf-cli-gui_FORM";text="kaf-cli-gui";right=521;bottom=311;acceptfiles=1;border="dialog frame";max=false)
mainForm.add(
align={cls="combobox";left=118;top=98;right=184;bottom=120;edge=1;font=LOGFONT(name='微软雅黑');items={"center";"left";"right"};mode="dropdown";z=25};
author={cls="edit";left=340;top=159;right=496;bottom=181;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;z=6};
bookname={cls="edit";left=50;top=159;right=282;bottom=181;edge=1;font=LOGFONT(name='微软雅黑');z=4};
button={cls="button";text="开始转换";left=295;top=273;right=504;bottom=295;border=1;default=1;font=LOGFONT(name='微软雅黑');z=22};
button3={cls="button";text="手动选择";left=426;top=16;right=502;bottom=60;font=LOGFONT(name='微软雅黑');z=28};
button4={cls="button";text="选择字体";left=50;top=128;right=259;bottom=150;font=LOGFONT(name='微软雅黑');z=30};
combobox={cls="combobox";left=154;top=199;right=198;bottom=221;edge=1;font=LOGFONT(name='微软雅黑');items={"em";"pm"};mode="dropdown";z=10};
combobox2={cls="combobox";left=270;top=199;right=336;bottom=221;edge=1;font=LOGFONT(name='微软雅黑');items={"epub";"all";"mobi";"azw3"};mode="dropdown";z=13};
combobox3={cls="combobox";left=458;top=239;right=502;bottom=261;edge=1;font=LOGFONT(name='微软雅黑');items={"zh";"en";"de";"fr";"it";"es";"ja";"pt";"ru";"nl"};mode="dropdown";z=15};
file_path={cls="edit";left=124;top=16;right=416;bottom=60;ah=1;autovscroll=false;aw=1;edge=1;font=LOGFONT(h=-14;name='微软雅黑');hscroll=1;multiline=1;z=27};
indent={cls="edit";text="2";left=408;top=198;right=432;bottom=220;align="center";edge=1;font=LOGFONT(name='微软雅黑');multiline=1;num=1;z=12};
match={cls="edit";left=106;top=239;right=282;bottom=261;edge=1;font=LOGFONT(name='微软雅黑');z=17};
maxtitle={cls="edit";text="35";left=380;top=239;right=404;bottom=261;align="center";edge=1;font=LOGFONT(name='微软雅黑');num=1;z=19};
outname={cls="edit";left=106;top=273;right=282;bottom=295;edge=1;font=LOGFONT(name='微软雅黑');z=21};
plus={cls="plus";text="点此添加封面图片";left=319;top=70;right=499;bottom=120;disabled=1;font=LOGFONT(h=-14;name='微软雅黑');hscroll=1;notify=1;z=26};
row_heigh={cls="edit";text="1.5";left=478;top=198;right=502;bottom=220;align="center";edge=1;font=LOGFONT(name='微软雅黑');multiline=1;num=1;z=32};
space={cls="edit";text="1";left=122;top=199;right=152;bottom=221;align="center";edge=1;font=LOGFONT(name='微软雅黑');multiline=1;num=1;z=8};
static={cls="static";text="TXT文件路径";left=18;top=24;right=112;bottom=54;align="center";center=1;font=LOGFONT(h=-14;name='微软雅黑');transparent=1;z=1};
static10={cls="static";text="标题最大字数";left=294;top=239;right=376;bottom=261;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=18};
static11={cls="static";text="显示帮助";left=203;top=69;right=297;bottom=119;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');frame=1;notify=1;transparent=1;z=23};
static12={cls="static";text="输出文件名";left=14;top=273;right=102;bottom=295;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=20};
static13={cls="static";text="字体";left=10;top=128;right=48;bottom=150;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=29};
static14={cls="static";text="行高";left=444;top=198;right=477;bottom=220;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=31};
static2={cls="static";text="标题居中方式";left=20;top=98;right=106;bottom=120;align="center";center=1;font=LOGFONT(name='微软雅黑');group=1;transparent=1;z=2};
static3={cls="static";text="段落间距(em/pm)";left=10;top=199;right=121;bottom=221;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=7};
static4={cls="static";text="书名";left=8;top=159;right=48;bottom=181;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=3};
static5={cls="static";text="作者";left=300;top=159;right=336;bottom=181;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=5};
static6={cls="static";text="输出格式";left=209;top=199;right=268;bottom=221;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=9};
static7={cls="static";text="段首缩进";left=349;top=198;right=407;bottom=220;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=11};
static8={cls="static";text="语言";left=420;top=239;right=454;bottom=261;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=14};
static9={cls="static";text="标题正则识别";left=14;top=239;right=102;bottom=261;align="center";center=1;font=LOGFONT(name='微软雅黑');transparent=1;z=16};
tips={cls="checkbox";text="是否添加kaf-cli教程";left=36;top=68;right=170;bottom=90;font=LOGFONT(name='微软雅黑');z=24}
)
/*}}*/
mainForm.plus.disabledText = "请先置入小说再添加封面"
mainForm.show()
font_path = ""
pic_path = io._exedir + "cover.png"
var temp = win.loadForm("/dlg/additional.aardio",,mainForm.hwnd)
temp.plus.text = /*首次使用需加载kaf-cli程序。
直接将文本文档拖入主程序即可自动识别。
若不指定封面,本程序将自动生成并使用文字封面。
请先置入文本文档再在目录添加 cover.png !(或手动选择)
本程序仅为GUI界面,不含实际功能。
原项目见“显示帮助”按钮。*/
input_file = function(mainForm){
if(io.exist(io._exedir + "cover.png")){
fsys.delete(io._exedir + "cover.png")
}
mainForm.plus.text = "点此添加封面图片"
mainForm.plus.disabled = false
mainForm.bookname.text = io.splitpath(mainForm.file_path.text).name
mainForm.outname.text = mainForm.bookname.text
mainForm.redraw()
if(string.cmp(io.splitpath(mainForm.file_path.text).ext, ".txt")){
win.msgboxErr("请放入文本文档",,mainForm.hwnd)
mainForm.file_path.text = ""
}
}
mainForm.onDropFiles = function(files){
mainForm.file_path.text = files[1]
input_file(mainForm)
}
get_pic = function(){
var temp = fsys.dlg.open("封面图片|*.png;*.jpg|","请选择封面图片",,mainForm.hwnd,,)
if(temp == null){
if(win.msgbox('未获取到路径\n选是:创建封面;选否:使用orly风格封面(需联网)',"Error",4,mainForm.hwnd) == 6){
create_pic(mainForm.bookname.text)
return (io._exedir + "cover.png")
}else{
return "orly"
}
}else{
mainForm.plus.editable = true
mainForm.plus.text = temp
return temp
}
}
mainForm.plus.oncommand = function(id,event){
win.msgbox('如果自动生成封面请先修改书名\n如果希望设置orly风格封面请联网\n并在首次选择封面时直接关闭该窗口',"Tip",,mainForm.hwnd)
pic_path = get_pic()
}
mainForm.static11.oncommand = function(id,event){
var temp = win.loadForm("/dlg/additional.aardio",,mainForm.hwnd)
temp.plus.text = /*本项目地址:https://github.com/Mikachu2333/kaf-cli-gui
原项目地址:https://github.com/ystyle/kaf-cli
详述(源自原项目):
Usage of kaf-cli:
-align string
标题对齐方式: left、center、righ。环境变量KAF_CLI_ALIGN可修改默认值 (default "center")
-author string
作者 (default "YSTYLE")
-bookname string
书名: 默认为txt文件名
-bottom string
段落间距(单位可以为em、px) (default "1em")
-cover string
封面图片可为: 本地图片, 和orly。 设置为orly时生成orly风格的封面, 需要连接网络。 (default "cover.png")
-cover-orly-color string
orly封面的主题色, 可以为1-16和hex格式的颜色代码, 不填时随机
-cover-orly-idx int
orly封面的动物, 可以为0-41, 不填时随机, 具体图案可以查看: https://orly.nanmu.me (default -1)
-filename string
txt 文件名
-font string
嵌入字体, 之后epub的正文都将使用该字体
-format string
书籍格式: all、epub、mobi、azw3。环境变量KAF_CLI_FORMAT可修改默认值 (default "all")
-indent uint
段落缩进字数 (default 2)
-lang string
设置语言: en,de,fr,it,es,zh,ja,pt,ru,nl。环境变量KAF_CLI_LANG可修改默认值 (default "en")
-line-height string
行高(用于设置行间距, 默认为1.5rem)
-match string
匹配标题的正则表达式, 不写可以自动识别, 如果没生成章节就参考教程。例: -match 第.{1,8}章 表示第和章字之间可以有1-8个任意文字
-max uint
标题最大字数 (default 35)
-out string
输出文件名,不需要包含格式后缀
-tips
添加本软件教程 (default true)
-unknow-title string
未知章节默认名称 (default "章节正文")
-volume-match string
卷匹配规则 (default "^第[0-9一二三四五六七八九十零〇百千两 ]+[卷部]")
原软件许可证:
Copyright (c) [2019] [YSTYLE]
[kaf-cli] is licensed under the Mulan PSL v1.
You can use this software according to the terms and conditions of the Mulan PSL v1.
You may obtain a copy of Mulan PSL v1 at:
http://license.coscl.org.cn/MulanPSL
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
PURPOSE.
See the Mulan PSL v1 for more details.
本软件许可证:
Copyright (c) [2023] [MIKACHU2333]
[kaf-cli-gui-full] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
}
create_pic = function(title){
import gdip.bitmap
import gdip.family
import gdip.font
import gdip.graphics
import gdip.solidBrush
import gdip.stringformat
var temp_pic = gdip.bitmap(350,600)
var graphics = gdip.graphics(temp_pic)
var gdi_brush = gdip.solidBrush(0xFF000000)
var gdi_font = gdip.family("微软雅黑")
var gdi_fontfmt = gdi_font.createFont(45,0/*_FontStyleRegular*/,2/*_GdipUnitPixel*/)
var gdi_fmt = gdip.stringformat()
gdi_fmt.align = 1
var gdi_rc = gdip.RECTF()
gdi_rc.x = 0
gdi_rc.y = 60
gdi_rc.height = 600
gdi_rc.width = 350
graphics.drawString(title,gdi_fontfmt,gdi_rc,gdi_fmt,gdi_brush)
temp_pic.save(io._exedir + "cover.png")
}
mainForm.button.oncommand = function(id,event){
mainForm.button.disabledText = {"✶";"✸";"✹";"✺";"✹";"✷"}
if((pic_path == (io._exedir + "cover.png")) and !io.exist(io._exedir + "cover.png")){
create_pic(mainForm.bookname.text)
}
path = tostring(io.joinpath(io._exedir,"kaf-cli.exe"))
args = {
"1" = "-align=" + mainForm.align.selText;
"2" = "-author=""" + (((mainForm.author.text != "") ? (mainForm.author.text + """") : "YSTYLE"""));
"3" = "-bookname=""" + ((mainForm.bookname.text != "") ? mainForm.bookname.text : io.splitpath(mainForm.file_path).name) + """";
"4" = "-bottom=" + (tostring(mainForm.space.text) + mainForm.combobox.selText);
"5" = "-cover=""" + pic_path + """";
"6" = "-filename=""" + mainForm.file_path.text + """";
"7" = "-format=" + mainForm.combobox2.selText;
"8" = "-indent=" + mainForm.indent.text;
"9" = "-lang=" + mainForm.combobox3.selText;
"10" = "-match=" + mainForm.match.text;
"11" = "-max=" + mainForm.maxtitle.text;
"12" = "-out=""" + io.joinpath(io.splitpath(mainForm.file_path.text).dir,mainForm.bookname.text) + """";
"13" = "-tips=" + tostring(mainForm.tips.checked);
"14" = "-font=""" + font_path + """";
"15" = "-line-height=" + tostring(mainForm.row_heigh.text);
}
if(args["10"] == "-match="){
args["10"] = null
}
if(args["14"] == "-font=""选择字体"""){
args["14"] = null
}
text_args = ""
for(i,j in args){
text_args = text_args + j + " "
}
win.msgbox(text_args)
thread.invoke(
function(path,text_args,mainForm){
import win.ui
raw.execute(path,text_args)
mainForm.plus.editable = false
mainForm.plus.disabledText = "请先置入小说再添加封面"
mainForm.button.text = "开始转换"
mainForm.file_path.text = ""
pic_path = (io._exedir + "cover.png")
},path,text_args,mainForm
)
mainForm.button.disabledText = null
win.msgbox("成功",,,mainForm.hwnd)
}
mainForm.button3.oncommand = function(id,event){
mainForm.file_path.text = fsys.dlg.open("文本文档|*.txt|","选择小说",,mainForm.hwnd,,)
input_file(mainForm)
}
mainForm.button4.oncommand = function(id,event){
font_path = fsys.dlg.open("字体|*.otf;*.ttf","选择字体",,mainForm.hwnd)
mainForm.button4.text = io.splitpath(font_path).name
}
return win.loopMessage()