-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVacuumdefs.sh
executable file
·126 lines (103 loc) · 4.26 KB
/
Vacuumdefs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
#Author: Johannes Deml, Johannes Kalliauer
#Source: http://www.inkscapeforum.com/viewtopic.php?t=16743
#Download: http://ge.tt/7C8JFmF1/v/0?c
#Download date: 2017-10-29
#last Changes: (by Johannes Kalliauer)
#2017-10-29 11h06 defined inkscape alias (Johannes Kalliauer)
echo
#needed if in the bashrc ist defined: export alias inkscape='/cygdrive/c/Program\ Files/Inkscape/inkscape.com'
if [ -z ${inkscape+x} ]; then
echo $inkscape #inkscape not defined
else
echo $inkscape
alias inkscape=$inkscape
fi
#Input parameters:
#alias inkscape='/cygdrive/c/Program\ Files/Inkscape/inkscape.com' #2017-10-29 11h06 (by Johannes Kalliauer)
#alias inkscape.exe='/cygdrive/c/Program\ Files/Inkscape/inkscape.exe'
sourceType="svg"; valid=1
outputType="svg"
count=0
validInput1="svg"
validInput2="pdf"
validInput3="eps"
validOutput1="eps"
validOutput2="pdf"
validOutput3="png"
validOutput4="svg"
validOutput5="plain-svg"
validOutput6="inkscape-svg"
validOutput7="inkscapesvg"
validOutput8="ink-svg"
validOutput9="png96"
#echo "This script allows you to convert all files in this folder from one file type to another."
#valid=0
if [ -z $sourceType ]; then
while [ "$valid" != "1" ]
do
echo "Allowed file types for source: $validInput1, $validInput2, $validInput3"
read -p "What file type do you want to use as a source? " sourceType
if [ "$sourceType" = "$validInput1" ] || [ "$sourceType" = "$validInput2" ] || [ "$sourceType" = "$validInput3" ]; then
valid=1
else
echo "Invalid input! Please use one of the following: $validInput1, $validInput2, $validInput3"
fi
done
fi
if [ -z ${outputType+x} ]; then
valid=0 #ask it output is not defined
fi
while [ "$valid" != "1" ]
do
echo "Allowed file types for output: $validOutput1, $validOutput2, $validOutput3, $validOutput4, $validOutput5, $validOutput6, $validOutput7"
read -p "What file type do you want to convert to? " outputType
if [ "$outputType" = "$validOutput1" ] || [ "$outputType" = "$validOutput2" ] || [ "$outputType" = "$validOutput3" ] || [ "$outputType" = "$validOutput4" ] || [ "$outputType" = "$validOutput5" ] || [ "$outputType" = "$validOutput6" ] || [ "$outputType" = "$validOutput7" ] || [ "$outputType" = "$validOutput8" ] || [ "$outputType" = "$validOutput9" ]; then
valid=1
else
echo "Invalid input! Please use one of the following: $validOutput1, $validOutput2, $validOutput3, $validOutput4"
fi
done
for fileSource in *.$sourceType
do
export i=$fileSource #i will be overritan later
export fileN=$(echo $fileSource | cut -f1 -d" ") #remove spaces if exsiting (and everything after)
export tmp=${fileN%.svg}
#If you want to overwrite the exisiting file, without any backup, delete the following three lines
export i=${tmp}.$sourceType
chmod u+r ./"${fileSource}"
if [ -f "$i" ]; then
echo no renaming
else
echo move
mv ./"${fileSource}" $i
fi
#mv ./"${fileSource}.$sourceType" "./${fileSource}2.xml"
if [ -f "$i" ]; then
count=$((count+1))
file=${i%.svg}
echo $count". "$i" -> "${file}n.$outputType
sed -ri "s/inkscape:version=\"0.4[\. r[:digit:]]+\"//g" $i
if [ "$outputType" = "png" ];then #png
read -p "With what dpi should it be exported (e.g. 300, default: 96)? " dpi
#inkscape $i --vacuum-defs --export-$outputType=$file.$outputType --export-dpi=$dpi
inkscape $i --actions="FileVacuum" --export-type="svg"
elif [ "$outputType" = "svg" ];then # svg
inkscape $i --vacuum-defs --export-plain-$outputType=${file}n.$outputType
elif [ "$outputType" = "$validOutput6" ] || [ "$outputType" = "$validOutput7" ] || [ "$outputType" = "$validOutput8" ]; then #inkscape-svg
cp ./${fileSource} ./${file}Ink.svg
mv ./${fileSource} ./${file}.xml
inkscape ./${file}Ink.svg --vacuum-defs --no-convert-text-baseline-spacing --verb=FileSave --verb=FileClose --verb=FileQuit
elif [ "$outputType" = "$validOutput9" ];then #png96
inkscape $i --vacuum-defs --export-png=$file.png
else #eps, pdf, plain-svg and others
inkscape $i --vacuum-defs --export-$outputType=$file.$outputType
fi
else
echo "no file $i found!"
fi
if [ "$outputType" = "svg" ] || [ "$outputType" = "plain-svg" ] || [ "$outputType" = "ink-svg" ]; then
mv ./${i} ./${file}bak2.xml
fi
done
echo "$count file(s) converted!"