]> git.ipfire.org Git - thirdparty/cups.git/blob - tools/makebuttons
Load cups into easysw/current.
[thirdparty/cups.git] / tools / makebuttons
1 #!/bin/sh
2 #
3 # "$Id$"
4 #
5 # Button generation script for the Common UNIX Printing System (CUPS).
6 #
7 # Originally created and donated by Philippe Combes (see STR #2231).
8 #
9 # Copyright 2007 by Easy Software Products, all rights reserved.
10 #
11 # These coded instructions, statements, and computer programs are the
12 # property of Easy Software Products and are protected by Federal
13 # copyright law. Distribution and use rights are outlined in the file
14 # "LICENSE.txt" which should have been included with this file. If this
15 # file is missing or damaged please contact Easy Software Products
16 # at:
17 #
18 # Attn: CUPS Licensing Information
19 # Easy Software Products
20 # 44141 Airport View Drive, Suite 204
21 # Hollywood, Maryland 20636-3142 USA
22 #
23 # Voice: (301) 373-9600
24 # EMail: cups-info@cups.org
25 # WWW: http://www.cups.org
26 #
27
28 #
29 # This little script uses convert from ImageMagick to generate CUPS buttons.
30 # It requires ImageMagick version 6.2.4 or higher.
31 #
32 # It can generate 20-pixel high one-line buttons and 40-pixel high two-line
33 # buttons.
34 #
35 # Usage:
36 #
37 # tools/makebuttons locale buttons.txt
38 #
39 # "Locale" is the locale name, either "ll" or "ll_CC" where "ll" is the
40 # 2-letter language abbreviation and "CC" is the 2-letter ISO country
41 # code. The new "ll-region" syntax is *not* supported at this time
42 # and should not be used!
43 #
44 # "Buttons.txt" is a file containing the buttons to be created and must
45 # be formatted as follows:
46 #
47 # filename.gif color text for button
48 #
49 # "filename.gif" is the name of the image file to create.
50 #
51 # "color" is the color of the button, one of "std" (the normal olive
52 # background), "black", "green", or "red".
53 #
54 # The remainder of the line following the color is used as the text
55 # for the button. Use "@UP" and "@DOWN" to include up and down arrows,
56 # and "\\n" to break the text into 2 lines (not generally recommended).
57 #
58 # Lines starting with '#' are treated as comments. See the file
59 # "tools/buttons.txt" for inspiration...
60 #
61
62 if test $# -lt 2; then
63 echo Usage: tools/makebuttons locale buttons.txt
64 exit 1
65 elif test ! -d tools; then
66 echo ERROR: You MUST run the makebuttons script from the main CUPS source directory!
67 exit 1
68 elif test "x`convert --help | grep extent`" = x; then
69 echo ERROR: This script requires ImageMagick 6.2.4 or higher.
70 exit 1
71 else
72 locale=$1
73 list=$2
74 fi
75
76 if test ! -f $list; then
77 echo "ERROR: $list: file not found."
78 exit 1
79 elif test ! -r $list; then
80 echo "ERROR: $list: cannot read file."
81 exit 1
82 fi
83
84
85 # Bitstream Vera font...
86 font="fonts/Vera.ttf"
87
88 # Base image
89 base="tools/buttons.gif"
90
91 # Colors
92 background="#d4d4a4"
93 black="#000000"
94 green="#009900"
95 red="#cc0000"
96 standard="#666633"
97
98
99 # 'generate_button()' - Create a button image.
100 #
101 # Arg 1: button filename (WITH .gif extension!)
102 # Arg 2: button color: black, green, red or std (only the initial letter matters)
103 # Arg 3+: the text !
104
105 function generate_button()
106 {
107 # Collect arguments...
108 filename=$1
109 shift
110
111 color=$1
112 shift
113
114 txt="$*"
115
116 # Show progress...
117 echo Creating $filename...
118
119 # Figure out the foreground and background colors...
120 bgclr=$background
121
122 case x$color in
123 xb*)
124 fgclr=$black
125 fuzz="10%"
126 ;;
127
128 xg*)
129 fgclr=$green
130 fuzz="10%"
131 ;;
132
133 xr*)
134 fgclr=$red
135 fuzz="1%"
136 ;;
137
138 xs*)
139 fgclr=$standard
140 fuzz="10%"
141 ;;
142
143 *)
144 echo "ERROR: Unknown color $color for $filename!"
145 exit 1
146 ;;
147 esac
148
149 # See if we need to add the up or down arrows...
150 add_arrows=0 # 1: up arrows, 2: down arrows
151
152 if echo $txt | grep '@UP' > /dev/null 2>&1; then
153 add_arrows=1
154 txt="`echo $txt | sed 's|@UP||g'`"
155 elif echo $txt | grep '@DOWN' > /dev/null 2>&1; then
156 add_arrows=2
157 txt="`echo $txt | sed 's|@DOWN||g'`"
158 fi
159
160 tmp_btn=/tmp/cups-btn-$$.bmp
161
162 # First step: generate an image trimmed to the text.
163 # -> annotate a 40x400 rectangle with the provided text
164 # -> trim to the text
165 convert $base -extent 400x40 -fill "$fgclr" \
166 -draw "rectangle 0,0 399,39" \
167 -fill "#ffffff" -encoding Unicode -pointsize 13 -font "$font" \
168 -gravity Center -annotate 0x0+0+0 "$txt" -trim $tmp_btn
169
170 # From the 1st step, we get text width and height
171 txt_h=`identify -format "%h" $tmp_btn`
172 txt_w=`identify -format "%w" $tmp_btn`
173
174 if test $txt_h -gt 32; then
175 echo "ERROR: 2 lines maximum for the button text"
176 exit 1
177 fi
178
179 # With the default font, one line is less than 16 pixels high, and a
180 # two lines of text is at least 20 pixels high. So, from the text
181 # height we guess if we need a one- or two-line button.
182 if test $txt_h -ge 18; then
183 btn_h=40
184 else
185 btn_h=20
186 fi
187
188 if test $add_arrows -gt 0; then
189 if test $btn_h -eq 20; then
190 txt_w=`expr $txt_w + 36`
191 elif test $btn_h -eq 40; then
192 txt_w=`expr $txt_w + 58`
193 fi
194 fi
195
196 # Second step: generate the button.
197 #
198 # Procedure:
199 #
200 # - Draw a rectangle with the background color (for correct
201 # button borders)
202 # - Draw a roundRectangle (args are coordinates, not lengths!)
203 # - Make the background transparent (with correct fuzz feature)
204 # - Annotate centered text (in height, it is necessary to have
205 # -1 in y parameter so that the text is not too low)
206 rad=`expr $btn_h / 2`
207 btn_w=`expr $txt_w + $rad + $rad`
208 btn_top=`expr $btn_h - 1`
209
210 convert $base \
211 -extent $btn_w'x'$btn_h -fill "$bgclr" \
212 -draw "rectangle 0,0 $btn_w,$btn_h" -fill "$fgclr" \
213 -draw "roundRectangle 0,0 `expr $btn_w - 1`,$btn_top `expr $rad - 1`,$rad" \
214 -fuzz $fuzz -transparent "$bgclr" -write $filename \
215 -fill "#ffffff" -encoding Unicode -pointsize 13 \
216 -font "$font" -gravity Center -annotate 0x0+0-1 "$txt" \
217 $filename
218
219 if test $add_arrows -gt 0; then
220 if test $add_arrows -eq 1; then
221 # UP arrows
222 if test $btn_h -eq 20; then
223 # 1-line buttons
224 pts1="9,15 21,15 15,4"
225 pts2="`expr $btn_w - 10`,15 `expr $btn_w - 22`,15 `expr $btn_w - 16`,4"
226 else
227 # 2-line buttons
228 pts1="16,30 34,30 25,10"
229 pts2="`expr $btn_w - 17`,30 `expr $btn_w - 35`,30 `expr $btn_w - 26`,10"
230 fi
231 else
232 # DOWN arrows
233 if [ $btn_h -eq 20 ]; then
234 # 1-line buttons
235 pts1="9,4 21,4 15,15"
236 pts2="`expr $btn_w - 10`,4 `expr $btn_w - 22`,4 `expr $btn_w - 16`,15"
237 else
238 # 2-line buttons
239 pts1="16,10 34,10 25,30"
240 pts2="`expr $btn_w - 17`,10 `expr $btn_w - 35`,10 `expr $btn_w - 26`,30"
241 fi
242 fi
243
244 convert $filename -fill "#ffffff" -draw "polygon $pts1" \
245 -draw "polygon $pts2" $filename
246 fi
247
248 rm -f $tmp_btn
249 }
250
251 # Make sure the locale-specific destination directory exists...
252 if test ! -d doc/$locale/images; then
253 echo Creating doc/$locale/images...
254 mkdir -p doc/$locale/images
255 fi
256
257 # Process each line in the file...
258 cat $list | while read line; do
259 if test "x`echo $line | cut -c1`" = "x#"; then
260 continue
261 fi
262
263 generate_button doc/$locale/images/$line
264 done
265
266 #
267 # End of "$Id$".
268 #