1 | #! /bin/sh |
---|
2 | # |
---|
3 | # module : |
---|
4 | # add frame and callouts image to an existing one |
---|
5 | # |
---|
6 | # !! exists only because graphics callouts are not yet avalaible |
---|
7 | # with xsl processing on XML/Docbook files (xsl stylesheet 1.70 and |
---|
8 | # DocBook DTD 4.2) |
---|
9 | # |
---|
10 | # thanks to the authors of the following web pages |
---|
11 | # http://www.win.tue.nl/~aeb/linux/misc/convert/convert-draw-text.html |
---|
12 | # http://www.cit.gu.edu.au/~anthony/graphics/imagick6/draw/ |
---|
13 | # http://www.cit.gu.edu.au/~anthony/graphics/imagick6/annotating/ |
---|
14 | # |
---|
15 | # update : |
---|
16 | # $Id$ |
---|
17 | # fplod 2006-07-20T16:05:19Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
18 | # add a parameter = the number of figpng/xxx_n.png |
---|
19 | # fplod 2006-07-19T12:40:02Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
20 | # first release |
---|
21 | # |
---|
22 | # |
---|
23 | set -u |
---|
24 | set -o posix |
---|
25 | # |
---|
26 | case "${1}" in |
---|
27 | 1|2) |
---|
28 | # screen capture to be commented by frames and callouts images |
---|
29 | capture="figpng/xxx_${1}.png" |
---|
30 | ;; |
---|
31 | *) |
---|
32 | echo "eee : unknown parameter ${1}" |
---|
33 | exit 1 |
---|
34 | ;; |
---|
35 | esac |
---|
36 | # |
---|
37 | if [ ! -f ${capture} ] |
---|
38 | then |
---|
39 | echo " eee : ${capture} not found" |
---|
40 | exit 1 |
---|
41 | fi |
---|
42 | # |
---|
43 | # |
---|
44 | callout_path=images/callouts/ |
---|
45 | callout_xsize=12 # ++ should be obtain by parsing identify result |
---|
46 | callout_ysize=12 # ++ should be obtain by parsing identify result |
---|
47 | # |
---|
48 | case ${capture} in |
---|
49 | figpng/xxx_2.png) |
---|
50 | capture_xsize=1211 #++ should be obtain by parsing identify result |
---|
51 | capture_ysize=630 #++ should be obtain by parsing identify result |
---|
52 | # |
---|
53 | # description of frames (title, xmin,ymin, xmax,ymax) |
---|
54 | # nb : title and label are not yet used but they may be added in a kind of |
---|
55 | # comments |
---|
56 | # later in xml as id or label |
---|
57 | # now they are only here to remind us what we do |
---|
58 | zone_nb=4 |
---|
59 | zone_t[1]="Page layout" |
---|
60 | zone_l[1]="pagelayout" |
---|
61 | zone_rect[1]="70,55 200,80" |
---|
62 | zone_t[2]="Calendar" |
---|
63 | zone_l[2]="calendar" |
---|
64 | zone_rect[2]="10,140 230,180" |
---|
65 | zone_t[3]="Domain" |
---|
66 | zone_l[3]="domain" |
---|
67 | zone_rect[3]="10,200 300,400" |
---|
68 | zone_t[4]="Specify" |
---|
69 | zone_l[4]="specify" |
---|
70 | zone_rect[4]="10,450 350,500" |
---|
71 | # |
---|
72 | # the next three lines are here to check calcultation of CALSPAIR units |
---|
73 | # see http://www.docbook.org/tdg/en/html/area.html |
---|
74 | # if you want to use it, please add one to zone_nb |
---|
75 | zone_t[5]="just to check full size rectangle" |
---|
76 | zone_l[5]="check" |
---|
77 | zone_rect[5]="0,0 ${capture_xsize},${capture_ysize}" |
---|
78 | ;; |
---|
79 | figpng/xxx_1.png) |
---|
80 | capture_xsize=520 #++ should be obtain by parsing identify result |
---|
81 | capture_ysize=309 #++ should be obtain by parsing identify result |
---|
82 | # |
---|
83 | # description of frames (title, xmin,ymin, xmax,ymax) |
---|
84 | # nb : title and label are not yet used but they may be added in a kind of |
---|
85 | # comments |
---|
86 | # later in xml as id or label |
---|
87 | # now they are only here to remind us what we do |
---|
88 | zone_nb=2 |
---|
89 | zone_t[1]="Data file" |
---|
90 | zone_l[1]="datafile" |
---|
91 | zone_rect[1]="5,55 515,90" |
---|
92 | zone_t[2]="Init file" |
---|
93 | zone_l[2]="initfile" |
---|
94 | zone_rect[2]="5,150 515,200" |
---|
95 | ;; |
---|
96 | *) |
---|
97 | echo " eee : ${capture} not implemented" |
---|
98 | exit 3 |
---|
99 | ;; |
---|
100 | esac |
---|
101 | |
---|
102 | # |
---|
103 | # calculation of % of the rectangle of each zone for Calspair |
---|
104 | iz=1 |
---|
105 | while [ ${iz} -le ${zone_nb} ] |
---|
106 | do |
---|
107 | xymin=$(echo ${zone_rect[${iz}]} | awk '{print $1}') |
---|
108 | xymax=$(echo ${zone_rect[${iz}]} | awk '{print $2}') |
---|
109 | xmin=$(echo ${xymin} | awk -F "," '{print $1}') |
---|
110 | xmax=$(echo ${xymax} | awk -F "," '{print $1}') |
---|
111 | ymin=$(echo ${xymin} | awk -F "," '{print $2}') |
---|
112 | ymax=$(echo ${xymax} | awk -F "," '{print $2}') |
---|
113 | xmin_pc=$(echo "(${xmin} / ${capture_xsize}) * 10000" | bc -l) |
---|
114 | xmin_pc=$(echo ${xmin_pc} } | awk -F "." '{print $1}') |
---|
115 | ymin_pc=$(echo "(${ymin} / ${capture_ysize}) * 10000" | bc -l) |
---|
116 | ymin_pc=$(echo ${ymin_pc} } | awk -F "." '{print $1}') |
---|
117 | xmax_pc=$(echo "(${xmax} / ${capture_xsize}) * 10000" | bc -l) |
---|
118 | xmax_pc=$(echo ${xmax_pc} } | awk -F "." '{print $1}') |
---|
119 | ymax_pc=$(echo "(${ymax} / ${capture_ysize}) * 10000" | bc -l) |
---|
120 | ymax_pc=$(echo ${ymax_pc} } | awk -F "." '{print $1}') |
---|
121 | #echo "xmin_pc zone ${iz} = ${xmin_pc}" |
---|
122 | #echo "ymin_pc zone ${iz} = ${ymin_pc}" |
---|
123 | #echo "xmax_pc zone ${iz} = ${xmax_pc}" |
---|
124 | #echo "ymax_pc zone ${iz} = ${ymax_pc}" |
---|
125 | #read a |
---|
126 | zone_rect_pc[${iz}]="${xmin_pc},${ymin_pc} ${xmax_pc},${ymax_pc}" |
---|
127 | iz=$(( ${iz} + 1 )) |
---|
128 | done |
---|
129 | # build the new image ie build the convert command to be run |
---|
130 | # first part : use the capture image and prepare black border and white |
---|
131 | # rectangles insertion |
---|
132 | cmd="convert -size ${capture_xsize}x${capture_ysize} \ |
---|
133 | ${capture} \ |
---|
134 | -linewidth 2 \ |
---|
135 | -stroke black \ |
---|
136 | -fill transparent" |
---|
137 | # |
---|
138 | # then loop on the frames to be drawed |
---|
139 | iz=1 |
---|
140 | while [ ${iz} -le ${zone_nb} ] |
---|
141 | do |
---|
142 | leftcorner=$(echo ${zone_rect[${iz}]} | awk '{print $1}') |
---|
143 | cmd="${cmd} -draw \"rectangle ${zone_rect[${iz}]}\" \ |
---|
144 | -draw \"image over ${leftcorner} ${callout_xsize},${callout_ysize} 'images/callouts/${iz}.png'\"" |
---|
145 | iz=$(( ${iz} + 1 )) |
---|
146 | done |
---|
147 | # |
---|
148 | # last component of the convert command : the name of the output image |
---|
149 | framecallouts=$(dirname ${capture})/$(basename ${capture} .png)_complete.png |
---|
150 | cmd="${cmd} ${framecallouts}" |
---|
151 | # |
---|
152 | #echo "cmd = ${cmd}" |
---|
153 | #read a |
---|
154 | # |
---|
155 | # run the convert command |
---|
156 | eval ${cmd} |
---|
157 | convert_status=${?} |
---|
158 | if [ ${convert_status} -ne 0 ] |
---|
159 | then |
---|
160 | echo " eee : convert doesn't work properly" >> ${log} |
---|
161 | echo " eee : return status = ${return_convert}" >> ${log} |
---|
162 | exit 2 |
---|
163 | fi |
---|
164 | echo " iii : image ${framecallouts} is ready" |
---|
165 | echo " iii : you can add the following lines in XML/Docbook" |
---|
166 | cat << EOF |
---|
167 | <imageobjectco> |
---|
168 | <areaspec units="calspair"> |
---|
169 | EOF |
---|
170 | iz=1 |
---|
171 | while [ ${iz} -le ${zone_nb} ] |
---|
172 | do |
---|
173 | echo "<area id=\"${zone_l[${iz}]}\" coords=\"${zone_rect_pc[${iz}]}\"/>" |
---|
174 | iz=$(( ${iz} + 1 )) |
---|
175 | done |
---|
176 | cat << EOF |
---|
177 | </areaspec> |
---|
178 | <imageobject> |
---|
179 | <imagedata fileref="${framecallouts}"/> <!-- ++ instead of ${capture} --> |
---|
180 | </imageobject> |
---|
181 | <calloutlist> |
---|
182 | EOF |
---|
183 | iz=1 |
---|
184 | while [ ${iz} -le ${zone_nb} ] |
---|
185 | do |
---|
186 | cat << EOF |
---|
187 | <callout arearefs="${zone_l[${iz}]}"> |
---|
188 | <para>${zone_t[${iz}]}</para> |
---|
189 | </callout> |
---|
190 | EOF |
---|
191 | iz=$(( ${iz} + 1 )) |
---|
192 | done |
---|
193 | cat << EOF |
---|
194 | </calloutlist> |
---|
195 | </imageobjectco> |
---|
196 | EOF |
---|
197 | # |
---|
198 | exit 0 |
---|