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