-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path修改字重.sh
executable file
·66 lines (54 loc) · 1.49 KB
/
修改字重.sh
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
#!/bin/bash
counter=1
declare -A file_times
files=()
# Get files with modification times
for file in *.ttf; do
mtime=$(stat -c %Y "$file")
file_times["$file"]=$mtime
done
# Sort files by modification time (newest first)
readarray -t sorted_files < <(
for file in "${!file_times[@]}"; do
echo "${file_times[$file]}|$file"
done | sort -rn | cut -d'|' -f2
)
# Display sorted files with dates
for file in "${sorted_files[@]}"; do
mtime=$(date -r "$file" "+%Y-%m-%d %H:%M:%S")
echo "${counter}. ${file} (${mtime})"
files+=("$file")
counter=$((counter + 1))
done
if [ ${#files[@]} -eq 0 ]; then
echo "当前目录下没有找到 TTF 文件。"
exit 1
fi
echo "请输入要修改字重的字体编号:"
read choice
if [[ $choice -le 0 || $choice -gt ${#files[@]} ]]; then
echo "无效的选择,请重新运行脚本。"
exit 1
fi
selected_file="${files[$choice-1]}"
# Prompt for weight scale
echo "请输入字重缩放比例 (例如: 1.2 或 120%):"
read scale_input
# Convert percentage to decimal if needed
if [[ $scale_input == *"%" ]]; then
scale=$(echo "scale=2; ${scale_input%\%}/100" | bc)
else
scale=$scale_input
fi
# Validate scale input
if (( $(echo "$scale <= 0" | bc -l) )); then
echo "缩放比例必须大于0"
exit 1
fi
# Call Python script with scale parameter
python3 weight_font.py "$selected_file" "$scale"
if [ $? -eq 0 ]; then
echo "字体字重修改完成!"
else
echo "修改失败,请检查错误信息。"
fi