-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-inputs.sh
More file actions
executable file
·149 lines (117 loc) · 4.78 KB
/
generate-inputs.sh
File metadata and controls
executable file
·149 lines (117 loc) · 4.78 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
#.-------------------------------------------------------------------------.#
#. generate_inputs.sh #
#. #
#. Copyright (C) 2013 LAFKON/Christoph Haag #
#. #
#. This file is part of the r+w id for the Libre Graphics Meeting 2013 #
#. #
#. this is free software: you can redistribute it and/or modify #
#. it under the terms of the GNU General Public License as published by #
#. the Free Software Foundation, either version 3 of the License, or #
#. (at your option) any later version. #
#. #
#. this script is distributed in the hope that it will be useful, #
#. but WITHOUT ANY WARRANTY; without even the implied warranty of #
#. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
#. See the GNU General Public License for more details. #
#. #
#.-------------------------------------------------------------------------.#
TMPDIR=tmp
SVGDIR=i/free/svg/src
PDFDIR=$TMPDIR
ENDDIR=i/free/svg/made
for SVG in `ls $SVGDIR/*.svg | grep -v speak`
do
rm $TMPDIR/*.*
TMPSVG=$TMPDIR/`basename $SVG`
# --------------------------------------------------- #
# COPY SVG TO TMP FILE, #
# MAKE ALL LAYERS VISIBLE, #
# CONVERT EVERY space TO NEWLINE (-> EASIFY GREP) #
# --------------------------------------------------- #
cat $SVG | \
sed 's/display:none/display:inline/g' | \
sed 's/ /\n/g' > $TMPSVG
# --------------------------------------------------- #
# EXPORT ALL ELEMENTS WHICH MATCH THE #
# ID PATTERN (id="ELEMENT-) #
# --------------------------------------------------- #
for ELEMENT in `grep "id=\"ELEMENT-" $TMPSVG | \
cut -d "\"" -f 2`
do
LINENUMBER=`grep -n $ELEMENT $TMPSVG | \
cut -d ":" -f 1 | tail -1`
TMPPDF=$TMPDIR/${LINENUMBER}-${ELEMENT}.pdf
inkscape -z --export-pdf=$TMPPDF \
--export-area-page \
--export-id=$ELEMENT \
--export-area-page \
$TMPSVG
done
# --------------------------------------------------- #
# THIS IS BRUTEFORCE (WO ROHE KRÄFTE SINNLOS WALTEN)
# --------------------------------------------------- #
COUNT=1
while [ $COUNT -le 250 ]
do
for ELEMENTTYPE in `ls $TMPDIR/*.pdf | \
cut -d "-" -f 3 | \
sort -u`
do
LAYERID=`ls $TMPDIR/*.pdf | \
grep $ELEMENTTYPE | \
shuf -n 1 | \
cut -d "-" -f 3,4 | cut -d "." -f 1`
ls $TMPDIR | grep $LAYERID >> $TMPDIR/$COUNT.list
done
cat $TMPDIR/$COUNT.list | sort > $TMPDIR/$COUNT.list.tmp
mv $TMPDIR/$COUNT.list.tmp $TMPDIR/$COUNT.list
if [ `fdupes $TMPDIR | wc -l` -gt 1 ]
then
echo $COUNT.list " = COMBINATIONS EXISTS"
rm $TMPDIR/$COUNT.list
fi
COUNT=`expr $COUNT + 1`
done
# --------------------------------------------------- #
#
# --------------------------------------------------- #
INPUTDIMENSIONS=`basename $SVG | cut -d "." -f 1`
for COMBINATION in `ls $TMPDIR/*.list`
do
LAYERID=`head -1 $COMBINATION | \
cut -d "." -f 1 | \
cut -d "-" -f 3,4`
for LAYER in `sed -n '2,$p' $COMBINATION`
do
LAYERID=$LAYERID-`echo $LAYER | \
cut -d "." -f 1 | cut -d "-" -f 3,4`
done
EXPORTFILENAME=${LAYERID}_${INPUTDIMENSIONS}
if [ `ls $PDFDIR | grep $EXPORTFILENAME | wc -l` -lt 1 ]
then
cp $TMPDIR/`cat $COMBINATION | head -1` \
$TMPDIR/background.pdf
for LAYER in `sed -n '2,$p' $COMBINATION`
do
pdftk $TMPDIR/$LAYER \
background $TMPDIR/background.pdf \
output $TMPDIR/out.pdf
mv $TMPDIR/out.pdf $TMPDIR/background.pdf
done
LAYERID=`echo $LAYERID | sed 's/-//g'`
EXPORTFILENAME=${INPUTDIMENSIONS}_${LAYERID}
mv $TMPDIR/background.pdf $PDFDIR/$EXPORTFILENAME.pdf
pdf2svg $PDFDIR/$EXPORTFILENAME.pdf \
$ENDDIR/$EXPORTFILENAME.svg
sed -i "s/rgb(100%,100%,100%);/#ffffff;/" \
$ENDDIR/$EXPORTFILENAME.svg
sed -i "s/rgb(0%,0%,0%);/#000000;/" \
$ENDDIR/$EXPORTFILENAME.svg
else
echo $EXPORTFILENAME exists
fi
done
done
exit 0;