[144] | 1 | #! /bin/sh |
---|
| 2 | # |
---|
| 3 | # module : |
---|
| 4 | # add frame and callouts image to an existing one |
---|
| 5 | # |
---|
[183] | 6 | # !! exists only because graphics callouts are not yet available |
---|
[144] | 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 |
---|
[149] | 27 | 0101|0201|mouse) |
---|
[144] | 28 | # screen capture to be commented by frames and callouts images |
---|
[147] | 29 | capture="figpng/xxx_${1}_org.png" |
---|
[144] | 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 |
---|
[147] | 49 | figpng/xxx_0101_org.png) |
---|
| 50 | capture_xsize=520 #++ should be obtain by parsing identify result |
---|
| 51 | capture_ysize=309 #++ should be obtain by parsing identify result |
---|
| 52 | # |
---|
[183] | 53 | # description of frames (title, xmin, ymin, xmax,ymax) |
---|
[147] | 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=3 |
---|
| 59 | zone_t[1]="Data file" |
---|
| 60 | zone_l[1]="datafile" |
---|
| 61 | zone_rect[1]="26,53, 485,95" |
---|
| 62 | zone_t[2]="Init method" |
---|
| 63 | zone_l[2]="initmethod" |
---|
| 64 | zone_rect[2]="78,101, 433,152" |
---|
| 65 | zone_t[3]="Init program" |
---|
| 66 | zone_l[3]="initprogram" |
---|
| 67 | zone_rect[3]="3,159, 518,278" |
---|
| 68 | #zone_t[1]="Data file" |
---|
| 69 | #zone_l[1]="datafile" |
---|
| 70 | #zone_rect[1]="5,55 515,90" |
---|
| 71 | #zone_t[2]="Init file" |
---|
| 72 | #zone_l[2]="initfile" |
---|
| 73 | #zone_rect[2]="5,150 515,200" |
---|
| 74 | ;; |
---|
| 75 | figpng/xxx_0201_org.png) |
---|
[149] | 76 | capture_xsize=429 #++ should be obtain by parsing identify result |
---|
[144] | 77 | capture_ysize=630 #++ should be obtain by parsing identify result |
---|
| 78 | # |
---|
[183] | 79 | # description of frames (title, xmin, ymin, xmax,ymax) |
---|
[144] | 80 | # nb : title and label are not yet used but they may be added in a kind of |
---|
| 81 | # comments |
---|
| 82 | # later in xml as id or label |
---|
| 83 | # now they are only here to remind us what we do |
---|
[149] | 84 | zone_nb=10 |
---|
[144] | 85 | # |
---|
[149] | 86 | zone_t[1]="Plot type" |
---|
| 87 | zone_l[1]="plottype" |
---|
| 88 | zone_rect[1]="3,24, 97,51" |
---|
| 89 | zone_t[2]="Menu" |
---|
| 90 | zone_l[2]="menu" |
---|
| 91 | zone_rect[2]="108,24, 325,53" |
---|
| 92 | zone_t[3]="OK" |
---|
| 93 | zone_l[3]="ok" |
---|
| 94 | zone_rect[3]="5,59, 44,86" |
---|
| 95 | zone_t[4]="Page layout" |
---|
| 96 | zone_l[4]="pagelayout" |
---|
| 97 | zone_rect[4]="70,59, 193,86" |
---|
| 98 | zone_t[5]="Variables list" |
---|
| 99 | zone_l[5]="variableslist" |
---|
| 100 | zone_rect[5]="209,60, 323,85" |
---|
| 101 | zone_t[6]="Files list" |
---|
| 102 | zone_l[6]="fileslist" |
---|
| 103 | zone_rect[6]="2,95, 344,117" |
---|
| 104 | zone_t[7]="Command text" |
---|
| 105 | zone_l[7]="commandtext" |
---|
| 106 | zone_rect[7]="2,126, 346,160" |
---|
| 107 | zone_t[8]="Calendar" |
---|
| 108 | zone_l[8]="calendar" |
---|
| 109 | zone_rect[8]="2,169, 212,216" |
---|
| 110 | zone_t[9]="Domdef" |
---|
| 111 | zone_l[9]="domdef" |
---|
| 112 | zone_rect[9]="16,227, 308,447" |
---|
| 113 | zone_t[10]="Specifications" |
---|
| 114 | zone_l[10]="specifications" |
---|
| 115 | zone_rect[10]="1,458, 345,580" |
---|
[144] | 116 | # the next three lines are here to check calcultation of CALSPAIR units |
---|
| 117 | # see http://www.docbook.org/tdg/en/html/area.html |
---|
| 118 | # if you want to use it, please add one to zone_nb |
---|
[149] | 119 | zone_t[11]="just to check full size rectangle" |
---|
| 120 | zone_l[11]="check" |
---|
| 121 | zone_rect[11]="0,0 ${capture_xsize},${capture_ysize}" |
---|
[144] | 122 | ;; |
---|
[149] | 123 | figpng/xxx_mouse_org.png) |
---|
| 124 | capture_xsize=57 #++ should be obtain by parsing identify result |
---|
| 125 | capture_ysize=82 #++ should be obtain by parsing identify result |
---|
| 126 | # |
---|
[183] | 127 | # description of frames (title, xmin, ymin, xmax,ymax) |
---|
[149] | 128 | # nb : title and label are not yet used but they may be added in a kind of |
---|
| 129 | # comments |
---|
| 130 | # later in xml as id or label |
---|
| 131 | # now they are only here to remind us what we do |
---|
| 132 | zone_nb=3 |
---|
| 133 | zone_t[1]="Left" |
---|
| 134 | zone_l[1]="left" |
---|
| 135 | zone_rect[1]="3,14, 11,21" |
---|
| 136 | zone_t[2]="Middle" |
---|
| 137 | zone_l[2]="middle" |
---|
| 138 | zone_rect[2]="21,14, 28,19" |
---|
| 139 | zone_t[3]="Right" |
---|
| 140 | zone_l[3]="right" |
---|
| 141 | zone_rect[3]="39,14, 46,20" |
---|
| 142 | ;; |
---|
[144] | 143 | *) |
---|
| 144 | echo " eee : ${capture} not implemented" |
---|
| 145 | exit 3 |
---|
| 146 | ;; |
---|
| 147 | esac |
---|
| 148 | |
---|
[149] | 149 | |
---|
| 150 | |
---|
| 151 | |
---|
[144] | 152 | # |
---|
| 153 | # calculation of % of the rectangle of each zone for Calspair |
---|
| 154 | iz=1 |
---|
| 155 | while [ ${iz} -le ${zone_nb} ] |
---|
| 156 | do |
---|
| 157 | xymin=$(echo ${zone_rect[${iz}]} | awk '{print $1}') |
---|
| 158 | xymax=$(echo ${zone_rect[${iz}]} | awk '{print $2}') |
---|
| 159 | xmin=$(echo ${xymin} | awk -F "," '{print $1}') |
---|
| 160 | xmax=$(echo ${xymax} | awk -F "," '{print $1}') |
---|
| 161 | ymin=$(echo ${xymin} | awk -F "," '{print $2}') |
---|
| 162 | ymax=$(echo ${xymax} | awk -F "," '{print $2}') |
---|
| 163 | xmin_pc=$(echo "(${xmin} / ${capture_xsize}) * 10000" | bc -l) |
---|
| 164 | xmin_pc=$(echo ${xmin_pc} } | awk -F "." '{print $1}') |
---|
| 165 | ymin_pc=$(echo "(${ymin} / ${capture_ysize}) * 10000" | bc -l) |
---|
| 166 | ymin_pc=$(echo ${ymin_pc} } | awk -F "." '{print $1}') |
---|
| 167 | xmax_pc=$(echo "(${xmax} / ${capture_xsize}) * 10000" | bc -l) |
---|
| 168 | xmax_pc=$(echo ${xmax_pc} } | awk -F "." '{print $1}') |
---|
| 169 | ymax_pc=$(echo "(${ymax} / ${capture_ysize}) * 10000" | bc -l) |
---|
| 170 | ymax_pc=$(echo ${ymax_pc} } | awk -F "." '{print $1}') |
---|
| 171 | #echo "xmin_pc zone ${iz} = ${xmin_pc}" |
---|
| 172 | #echo "ymin_pc zone ${iz} = ${ymin_pc}" |
---|
| 173 | #echo "xmax_pc zone ${iz} = ${xmax_pc}" |
---|
| 174 | #echo "ymax_pc zone ${iz} = ${ymax_pc}" |
---|
| 175 | #read a |
---|
| 176 | zone_rect_pc[${iz}]="${xmin_pc},${ymin_pc} ${xmax_pc},${ymax_pc}" |
---|
| 177 | iz=$(( ${iz} + 1 )) |
---|
| 178 | done |
---|
| 179 | # build the new image ie build the convert command to be run |
---|
| 180 | # first part : use the capture image and prepare black border and white |
---|
| 181 | # rectangles insertion |
---|
| 182 | cmd="convert -size ${capture_xsize}x${capture_ysize} \ |
---|
| 183 | ${capture} \ |
---|
| 184 | -linewidth 2 \ |
---|
| 185 | -stroke black \ |
---|
| 186 | -fill transparent" |
---|
| 187 | # |
---|
| 188 | # then loop on the frames to be drawed |
---|
| 189 | iz=1 |
---|
| 190 | while [ ${iz} -le ${zone_nb} ] |
---|
| 191 | do |
---|
| 192 | leftcorner=$(echo ${zone_rect[${iz}]} | awk '{print $1}') |
---|
| 193 | cmd="${cmd} -draw \"rectangle ${zone_rect[${iz}]}\" \ |
---|
| 194 | -draw \"image over ${leftcorner} ${callout_xsize},${callout_ysize} 'images/callouts/${iz}.png'\"" |
---|
| 195 | iz=$(( ${iz} + 1 )) |
---|
| 196 | done |
---|
| 197 | # |
---|
[149] | 198 | # |
---|
| 199 | # +++ verrue mal codee... |
---|
[183] | 200 | # dans le cas mouse, je ne veux pas les cadres |
---|
[149] | 201 | # a voir si on integre proprement ou si on vire... |
---|
[258] | 202 | if [ ${1} = mouse ] |
---|
[149] | 203 | then |
---|
| 204 | cmd="convert -size ${capture_xsize}x${capture_ysize} ${capture}" |
---|
| 205 | iz=1 |
---|
| 206 | while [ ${iz} -le ${zone_nb} ] |
---|
| 207 | do |
---|
| 208 | leftcorner=$(echo ${zone_rect[${iz}]} | awk '{print $1}') |
---|
| 209 | cmd="${cmd} -draw \"image over ${leftcorner} ${callout_xsize},${callout_ysize} 'images/callouts/${iz}.png'\"" |
---|
| 210 | iz=$(( ${iz} + 1 )) |
---|
| 211 | done |
---|
| 212 | |
---|
| 213 | fi |
---|
| 214 | # +++ verrue mal codee... |
---|
| 215 | # |
---|
| 216 | # |
---|
[144] | 217 | # last component of the convert command : the name of the output image |
---|
[147] | 218 | framecallouts=$(dirname ${capture})/$(basename ${capture} _org.png).png |
---|
[144] | 219 | cmd="${cmd} ${framecallouts}" |
---|
| 220 | # |
---|
| 221 | #echo "cmd = ${cmd}" |
---|
| 222 | #read a |
---|
| 223 | # |
---|
| 224 | # run the convert command |
---|
| 225 | eval ${cmd} |
---|
| 226 | convert_status=${?} |
---|
| 227 | if [ ${convert_status} -ne 0 ] |
---|
| 228 | then |
---|
| 229 | echo " eee : convert doesn't work properly" >> ${log} |
---|
| 230 | echo " eee : return status = ${return_convert}" >> ${log} |
---|
| 231 | exit 2 |
---|
| 232 | fi |
---|
| 233 | echo " iii : image ${framecallouts} is ready" |
---|
| 234 | echo " iii : you can add the following lines in XML/Docbook" |
---|
| 235 | cat << EOF |
---|
| 236 | <imageobjectco> |
---|
| 237 | <areaspec units="calspair"> |
---|
| 238 | EOF |
---|
| 239 | iz=1 |
---|
| 240 | while [ ${iz} -le ${zone_nb} ] |
---|
| 241 | do |
---|
| 242 | echo "<area id=\"${zone_l[${iz}]}\" coords=\"${zone_rect_pc[${iz}]}\"/>" |
---|
| 243 | iz=$(( ${iz} + 1 )) |
---|
| 244 | done |
---|
| 245 | cat << EOF |
---|
| 246 | </areaspec> |
---|
| 247 | <imageobject> |
---|
| 248 | <imagedata fileref="${framecallouts}"/> <!-- ++ instead of ${capture} --> |
---|
| 249 | </imageobject> |
---|
| 250 | <calloutlist> |
---|
| 251 | EOF |
---|
| 252 | iz=1 |
---|
| 253 | while [ ${iz} -le ${zone_nb} ] |
---|
| 254 | do |
---|
| 255 | cat << EOF |
---|
| 256 | <callout arearefs="${zone_l[${iz}]}"> |
---|
| 257 | <para>${zone_t[${iz}]}</para> |
---|
| 258 | </callout> |
---|
| 259 | EOF |
---|
| 260 | iz=$(( ${iz} + 1 )) |
---|
| 261 | done |
---|
| 262 | cat << EOF |
---|
| 263 | </calloutlist> |
---|
| 264 | </imageobjectco> |
---|
| 265 | EOF |
---|
| 266 | # |
---|
| 267 | exit 0 |
---|