Debian Codegraph @

distro/dev-tools/icons/hime-create-icons.sh

raw
1 #!/bin/sh
2
3 #
4 # Copyright (C) 2011 Lu, Chao-Ming (Tetralet). All rights reserved.
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #
20
21 export LC_ALL=zh_TW.UTF8
22
23 CONVERT=$(whereis -b convert | tr -d '\n' | sed 's/^convert: *//g')
24 if [ -z "$CONVERT" ]; then
25 echo "Command 'convert' is not find. Please install imagemagick package and try again!"
26 exit 0
27 fi
28
29 print_help()
30 {
31 case $1 in
32 -h|--help)
33 echo "Usage: $0 SourceImage.png HalfCharImage.png FullCharImage.png Font_Patch Font_Color Mini_Color"
34 echo "Example: $0 HIME.png HIME_Half.png HIME_Full.png ~/.fonts/DroidSansFallback.ttf \"#1650b8\" \"#c81bca\""
35 exit 0
36 ;;
37 esac
38 }
39
40 if [ "$1" == '' ]; then
41 print_help -h
42 fi
43 if [ ! -f "$1" ]; then
44 echo "ERROR: Source Image file $1 Not find!"
45 echo ""
46 print_help -h
47 fi
48 SOURCE_IMAGE="$1"
49
50 if [ "$2" == '' ]; then
51 print_help -h
52 fi
53 if [ ! -f "$2" ]; then
54 echo "ERROR: HalfChar Image file $2 Not find!"
55 echo ""
56 print_help -h
57 fi
58 HALF_IMAGE="$2"
59
60 if [ "$3" == '' ]; then
61 print_help -h
62 fi
63 if [ ! -f "$3" ]; then
64 echo "ERROR: FullChar Image file $3 Not find!"
65 echo ""
66 print_help -h
67 fi
68 FULL_IMAGE="$3"
69
70 if [ "$4" == '' ]; then
71 print_help -h
72 fi
73 if [ ! -f "$4" ]; then
74 echo "ERROR: Font file $4 Not find!"
75 echo ""
76 print_help -h
77 fi
78 FONT_FILE="$4"
79
80 if [ "$5" == '' ]; then
81 print_help -h
82 fi
83 COLOR="$5"
84
85 if [ "$6" == '' ]; then
86 print_help -h
87 fi
88 MINI_COLOR="$6"
89
90 convert_word()
91 {
92 while [ "$1" != '' ]; do
93 FILE=$1
94 shift
95 if [ "$1" != '' ]; then
96 WORD=$1
97 else
98 echo "ERROR: No target file inputed!"
99 exit 1
100 fi
101 shift
102
103 SIZE=$(echo "$WORD" | wc -m)
104 if [ "$WORD" == "En" ]; then
105 SIZE=2
106 fi
107 WORK_IMAGE="$SOURCE_IMAGE"
108 echo "Trying to draw '$WORD' (Size $SIZE) on $SOURCE_IMAGE to $FILE.png ..."
109 case $SIZE in
110 1)
111 FONT_SIZE=18
112 DRAW_STR="text +0-1 '$WORD'"
113 TEMP_FILE=""
114 ;;
115 2)
116 FONT_SIZE=18
117 DRAW_STR="text +0-1 '$WORD'"
118 TEMP_FILE=""
119 ;;
120 3|4)
121 if [ "$FILE" == "half-simp" ] || [ "$FILE" == "half-trad" ]; then
122 WORK_IMAGE="$HALF_IMAGE"
123 fi
124 if [ "$FILE" == "full-simp" ] || [ "$FILE" == "full-trad" ]; then
125 WORK_IMAGE="$FULL_IMAGE"
126 fi
127 ORIGINAL_WORD="$WORD"
128 WORD=$(echo "$ORIGINAL_WORD" | sed -e 's/\(.\)\(.\)/\1/g')
129 FONT_SIZE=14
130 DRAW_STR="text -4-4 '$WORD'"
131 TEMP_FILE="hime_temp"
132 convert -pointsize "$FONT_SIZE" \
133 -font "$FONT_FILE" \
134 -fill "$COLOR" \
135 -gravity center \
136 -draw "$DRAW_STR" \
137 "$WORK_IMAGE" "$TEMP_FILE.png"
138 WORD=$(echo "$ORIGINAL_WORD" | sed -e 's/\(.\)\(.\)/\2/g')
139 FONT_SIZE=11
140 DRAW_STR="text +5+5 '$WORD'"
141 ;;
142 *)
143 echo "The input word '$WORD' is too long!"
144 exit 1
145 ;;
146 esac
147 if [ "$TEMP_FILE" == '' ] || [ ! -f "$TEMP_FILE.png" ]; then
148 convert -pointsize "$FONT_SIZE" \
149 -font "$FONT_FILE" \
150 -fill "$COLOR" \
151 -gravity center \
152 -draw "$DRAW_STR" \
153 "$WORK_IMAGE" "$FILE.png"
154 else
155 convert -pointsize "$FONT_SIZE" \
156 -font "$FONT_FILE" \
157 -fill "$MINI_COLOR" \
158 -gravity center \
159 -draw "$DRAW_STR" \
160 "$TEMP_FILE.png" "$FILE.png"
161 rm "$TEMP_FILE.png"
162 fi
163 done
164 }
165
166 convert_word 'hime-tray' 'En' \
167 '4corner' '四' \
168 'NewCJ3' '亂' \
169 'amis' '阿' \
170 'ar30' '行' \
171 'chewing' '酷' \
172 'cj' '倉' \
173 'dayi3' '易' \
174 'erbi' '二' \
175 'ez' '輕' \
176 'fcitx-qxm' '冰' \
177 'fcitx-wanfeng' '晚' \
178 'greek' 'αβ' \
179 'esperanto' '★' \
180 'hakka' '客' \
181 'halfwidth-kana' 'ア' \
182 'intcode' '內' \
183 'jtcj_gb' '仓' \
184 'juyin' '注' \
185 'jyutping' '粵' \
186 'kana-nippon' 'あ' \
187 'latin-letters' 'ā' \
188 'newcj' '新' \
189 'noseeing' '嘸' \
190 'paiwan' '排' \
191 'pinyin' '拼' \
192 'sakura' '櫻' \
193 'scj' '快' \
194 'shuangpin' '双' \
195 'simplex' '簡' \
196 'symbols' '%' \
197 'taiwan' '台' \
198 'telecode' '電' \
199 'tsin' '詞' \
200 'tsou' '鄒' \
201 'wm2' '象' \
202 'wubi' '五' \
203 'russian' 'Э' \
204 'hangul' '한' \
205 'cj5' '倉五' \
206 'cj-punc' '倉;' \
207 'en-kana-nippon' 'あE' \
208 'en-chewing' '酷E' \
209 'en-tsin' '詞E' \
210 'half-simp' ' 简' \
211 'half-trad' '  ' \
212 'full-simp' ' 简' \
213 'full-trad' '  ' \
214 'gdayi3' '易三'