3 # This file is part of NIT ( http://www.nitlanguage.org ).
5 # Copyright 2012-2013 Alexis Laferrière <alexis.laf@xymus.net>
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # This script extracts pngs from a single svg for all objects with ids
20 # beginning by 0. Requires Inkscape.
22 # there are some trick used do to inconsistency in inkscape input and output values
23 # the document must be resized to fit all objects
26 log=$dir/`basename $0 .sh`.log
28 echo $0 executed at `date` > $log
32 echo "Usage: $0 source.svg destination/folder/"
37 destinationFolder="$2"
38 if [ ! -f $sourceFile ]
40 echo "Source file \"$sourceFile\" not found."
44 if [ ! -d $destinationFolder ]
46 echo "Destination folder \"$destinationFolder\" not found, creating it."
47 mkdir -p $destinationFolder
51 query=`inkscape --query-all $sourceFile`
54 for line in $query; do
62 if echo $y | grep e &> /dev/null; then
65 if echo $x | grep e &> /dev/null; then
69 echo "$x < $min_x" | bc &> /dev/null
75 echo "$y < $min_y" | bc &> /dev/null
81 full_h=`inkscape "-f$sourceFile" -C -H 2>> $log`
83 for line in $query; do #`inkscape --query-all $sourceFile | grep ^0`; do
84 if echo $line | grep ^0 &> /dev/null; then
86 id=${ld[0]} #${line:0: $[`expr index "$line" ,` - 1] }
87 name=${line:1: $[`expr index "$line" ,` - 2] }
95 if echo $y | grep e &> /dev/null; then
98 if echo $x | grep e &> /dev/null; then
102 # corrected dim for pow(2)
105 while (i<$w || i<$h){
110 echo "found $i for $w $h" &>> $log
113 dw=`echo \($cw-$w\)/2|bc`
114 dh=`echo \($ch-$h\)/2|bc`
115 cx=`echo $x + \($cw-$w\)/2|bc`
116 cy=`echo $y + \($ch-$h\)/2|bc`
118 # corrects value of y.
119 y=`echo $full_h - $y | bc`
121 echo "x=$x y=$y w=$w h=$h" &>> $log
122 echo "cx=$cx cy=$cy cw=$cw ch=$ch" &>> $log
123 i=`echo "$i * 2" | bc`
124 inkscape -z -C "-f$sourceFile" "-i$id" -j "-a`echo $x-$dw|bc`:`echo $y-$h-$dh|bc`:`echo $x+$w+$dw|bc`:`echo $y+$dh|bc`" "-e$destinationFolder/$name.png" -b#000000 -y0.0 -d180 -w$i -h$i &>> $log