-
Notifications
You must be signed in to change notification settings - Fork 3
/
slacheck
381 lines (328 loc) · 14.3 KB
/
slacheck
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash
# set -x
# shell memos :
# ${parameter=default}, ${parameter:=default} # If parameter not set, set it to default.
. shellcolors
# *****************************
# SHELL configs for defaults features
scribuscommand="scribus" # can be changed for some of the files configs so as to avoid scribus crashes
checkimg='check' # check that used images are in images subfolder
checkfonts='check' # check that used fonts are either embeded or subset
comment='comment' # display AAA, BBB, CCC, DDD ; WWW, XXX, YYY, ZZZ or PPP, QQQ, RRR, SSS comments
noimagelist='imagelist' # record images for book_imagelist.md
vecto='' # leave fonts as declared in sla = dont force all fonts vectorization
checkpagenums='check' # do check startpage num
dopdf='create' # dopdf = create : checks pdf exists and is recent and recreate it when not
# dopdf = check : only checks
# dopdf = ignore : neither checks nor (re)creates pdf
# dopdf = force : (re)create all pdf whether existing or recent or not
sla_actionoption='' # default : dont change SLAs
# "-set" edit sla so it checks config specs
verboseoption='' # default : not verbose
# '-v' for verbose
# =====================================================================
vcheck='' # verbose check et +
vconfig=''
setrequested=''
sla_actionoption=''
pagenumval=''
# *****************************
# config for scribus project manager general default features
. slacheck.defaultconfig
# *****************************
# config for project (must be specified... unless project is default project which is unlikely)
# project config can be either in local or parent folder
[ -f "./slacheck.config" ] && . ./slacheck.config $vconfig
[ ! -f "./slacheck.config" ] && [ -f "../slacheck.config" ] && echo -e "${ESC_warning}Parent's folder default slacheck.config is used" && . ../slacheck.config $vconfig
[ ! -f "./slacheck.config" ] && [ -f "../../slacheck.config" ] && echo -e "${ESC_warning}Grand-parent's folder default slacheck.config is used" && . ../../slacheck.config $vconfig
[ ! -f "./slacheck.config" ] && [ ! -f "../slacheck.config" ] && [ ! -f "../../slacheck.config" ] && echo -e "${ESC_warning} No local config for project, using default for $1.sla$ESC_normal"
while [ "$stopoptions" = "" ]
do
stopoptions=true
if [ "$1" = '-?' ]; then
echo "slacheck checks workflow validity of a scribus file"
echo "Options :"
echo "-? : get this help"
echo "-vconfig : verbose config output"
echo "-vcheck : verbose check output"
echo "-pdfignore : dont check whether pdf exists and dont compare PDF and SLA last edit dates"
echo "-pdfcheck : check pdf, but dont re-create it in case required"
echo "-nofontcheck : doesnt check fonts"
echo "-nocomment : dont display comments (user can mark comments with AAA, BBB, CCC, DDD ; WWW, XXX, YYY, ZZZ or PPP, QQQ, RRR, SSS keyword)"
echo "-noimagelist : dont create imagelist"
echo "-forcepdf : (re)create pdf even when it exists allready"
echo "-notimg : dont check for correct included image files"
echo "-set : change the SLA so it conforms to project standards (save in .bak)"
echo "-vecto : all fonts must be vectorized - BETA" # il faut FontEmbedding="1" (logique booléenne inversée)
echo "-pagenum PPP : check that section begins at page number PPP"
echo "-nobleeds : no cropmarks + useDocBleeds"
echo
exit
elif [ "$1" = "-vconfig" ]; then
vconfig=$1
shift
stopoptions=''
elif [ "$1" = "-vcheck" ]; then
shift
vcheck='-v'
stopoptions=''
elif [ "$1" = "-pdfignore" ] || [ "$1" = "-nopdf" ]; then
shift
dopdf='ignore'
stopoptions=''
elif [ "$1" = "-forcepdf" ]; then
shift
dopdf='force'
stopoptions=''
elif [ "$1" = "-pdfcheck" ]; then
shift
dopdf='check'
stopoptions=''
elif [ "$1" = "-notimg" ]; then
shift
checkimg='dontcheck'
stopoptions=''
elif [ "$1" = "-set" ]; then # il faut max 1 set : -set ou -ab
shift
sla_actionoption="-set"
setrequested="-set"
stopoptions=''
elif [ "$1" = '-ab' ]; then
shift
# option "add bookmark" gérée dans makebook
setrequested="-ab"
stopoptions=''
continue
elif [ "$1" = "-nofontcheck" ]; then
shift
checkfonts=''
stopoptions=''
elif [ "$1" = "-nocomment" ]; then
shift
comment=''
stopoptions=''
elif [ "$1" = "-noimagelist" ]; then
shift
imagelist=''
stopoptions=''
elif [ "$1" = "-vecto" ]; then
shift
vecto="-vecto"
stopoptions=''
checkfonts=''
FontEmbedding=1 # logique booléenne inverse
echo -e "${ESC_warning} -vecto option est EN BÉTA EXPÉRIMENTALE $ESC_normal"
elif [ "$1" = '-nobleeds' ]; then # overwrites config option
shift
stopoptions=''
useDocBleeds="1"
cropMarks="0"
elif [ "$1" = "-pagenum" ]; then
shift
checkpagenums='check'
if [ "$1" = '' ]; then
echo -e "${ESC_error} missing page numer after -pagenum$ESC_normal"
exit;
fi
pagenumval="$1"
shift
stopoptions=''
fi
done
# *****************************
# config for chapter file
if [ ! -f "$1.sla" ]
then
echo -e "${ESC_error} missing $1.sla file${ESC_normal}"
exit
fi
if [ -f "./$1.config" ]
then
. "./$1.config" $vconfig
fi
# warning : FontEmbedding = 1 when fonts are vectorized
if [ "$FontEmbedding" = 1 ]
then
checkfonts=''
fi
# *****************************
# Collect comments
#
# grep options :
# -H : affiche le nom de fichier
# -o : n'affiche que la partie matchant le pattern et non toute la ligne
# -i : case insensitif
# -E : c'est une regexp (permettrait d'extraire plus de caractères environnants par ex)
# -v : élimine les lignes vérifiant le pattern
# -P : perl regexp
# \K : dans une perl regexp, permet d'oublier la partie du m à gauche. Ne retourne donc que ce qui suit. Requis ici car les expression lookbehind ne peuvent pas etre de longueur variable.
#
# Il faut '(' dans grep mais '\(' dans sed
grep -oP '<ITEXT [^>]*CH\s*=\s*"\K.*(AAA|BBB|CCC|DDD|PPP|QQQ|RRR|SSS|WWW|XXX|YYY|ZZZ).*(?="\s*\/>)' "$1.sla" | sed 's/^\(.*\(AAA\|BBB\|CCC\|DDD\|PPP\|QQQ\|RRR\|SSS\|WWW\|XXX\|YYY\|ZZZ\).*\)$/ \2 « \1 »/' > .slacheck.comments
sizecomments=$(stat -c%s .slacheck.comments)
if [ -f .slacheck.comments ] && [ $sizecomments -gt 0 ] # pas ">" (car ça crée un fichier "0" !) mais peut etre gt
then
if [ "$comment" != "" ]
then
# -n : no newline at EOL
# -e : manage escape
echo -ne $ESC_notice
cat .slacheck.comments
echo -ne $ESC_normal
fi
echo -ne "## $1.sla\n" >> book_comments.md
cat .slacheck.comments >> book_comments.md
echo -ne "\n\n" >> book_comments.md
fi
# *****************************
# Collect images
#
# grep options :
# -H : affiche le nom de fichier
# -o : n'affiche que la partie matchant le pattern et non toute la ligne
# -i : case insensitif
# -E : c'est une regexp (permettrait d'extraire plus de caractères environnants par ex)
# -v : élimine les lignes vérifiant le pattern
# -P : perl regexp
# \K : dans une perl regexp, permet d'oublier la partie du m à gauche. Ne retourne donc que ce qui suit. Requis ici car les expression lookbehind ne peuvent pas etre de longueur variable.
#
# Il faut '(' dans grep mais '\(' dans sed
grep -oP '<PAGEOBJECT.*PFILE="\K[^"]*' "$1.sla" | sed 's/^\(.*\)$/ \1/' > .slacheck.imagelist
grep -oP '<FRAMEOBJECT.*PFILE="\K[^"]*' "$1.sla" | sed 's/^\(.*\)$/inline \1/' >> .slacheck.imagelist
sizeimagelist=$(stat -c%s .slacheck.imagelist)
if [ sizeimagelist != 0 ] # pas ">" (car ça crée un fichier "0") mais peut etre gt
then
if [ "$imagelist" != "" ]
then
# -n : no newline at EOL
# -e : manage escape
echo -ne $ESC_notice
cat .slacheck.imagelist
echo -ne $ESC_normal
fi
echo -ne "## $1.sla\n" >> book_imagelist.md
cat .slacheck.imagelist >> book_imagelist.md
echo -ne "\n\n" >> book_imagelist.md
fi
alloptions="$vcheck $sla_actionoption"
# As for color profiles, the correct values to be checked are :
# <DOCUMENT ... DPMo="sRGB" DPPr="ISO Coated v2 300% (ECI)" DPIn="sRGB" DPInCMYK="ISO Coated v2 300% (ECI)" DPIn2="sRGB" DPIn3="ISO Coated v2 300% (ECI)" ...>
# <PDF ... SolidP="sRGB" ImageP="sRGB" PrintP="ISO Coated v2 300% (ECI)" ...>
slacheckattr $alloptions "$1" DOCUMENT DPIn "$RGBprof" "RGB color profile"
slacheckattr $alloptions "$1" DOCUMENT DPIn2 "$RGBprof" "RGB color profile"
slacheckattr $alloptions "$1" DOCUMENT HCMS "1" "Color management ?"
slacheckattr $alloptions "$1" DOCUMENT DPuse "1" "Color management ?"
slacheckattr $alloptions "$1" DOCUMENT DPPr "$CMYKprof" "CMYK color profile"
slacheckattr $alloptions "$1" DOCUMENT DPInCMYK "$CMYKprof" "CMYK color profile"
slacheckattr $alloptions "$1" DOCUMENT DPIn3 "$CMYKprof" "CMYK color profile"
slacheckattr $alloptions "$1" DOCUMENT DPSFo "$DPSFo" "Convert colors to printer's CMYK colorspace"
slacheckattr $alloptions "$1" DOCUMENT DPSo "$DPSo" "Fake printer's rendering on screen"
slacheckattr $alloptions "$1" PDF Grayscale "$Grayscale" "PDF output to grayscale"
slacheckattr $alloptions "$1" PDF RGBMode "$RGBMode" "PDF output RGB for screen (rather than CMYK for printer)"
slacheckattr $alloptions "$1" PDF UseProfiles "0" ""
slacheckattr $alloptions "$1" PDF UseProfiles2 "1" ""
slacheckattr $alloptions "$1" DOCUMENT AUTOMATIC "1" "Doc pref / hyphen"
slacheckattr $alloptions "$1" DOCUMENT AUTOCHECK "1" "Suggest and ask to confirm hyphens"
slacheckattr $alloptions "$1" PDF rangeSel "$rangeSel" "PDF selected pages : 1 for a selection of pages / 0 for all pages"
# In case rangeSel is "1", rangeTxt has to be specified in each document's file config :
# slacheckattr $alloptions "$1" PDF rangeTxt "$rangeSel" "PDF for a selection of pages (or for all pages) ?"
slacheckattr $alloptions "$1" PDF SolidP "$RGBprof" "RGBcolor profile"
slacheckattr $alloptions "$1" PDF ImageP "$RGBprof" "RGB color profile"
slacheckattr $alloptions "$1" PDF PrintP "$CMYKprof" "CMYK color profile"
# même sans checkfont, on check DFONT et FontEmbedding !
slacheckattr $alloptions "$1" DOCUMENT DFONT "$DFONT" "DOCUMENT's default font"
slacheckattr $alloptions "$1" PDF FontEmbedding "$FontEmbedding" "0 = Embeds full or subset fonts. 1=outlines = vectorise, sans fontes (logique booléenne inversée)"
if [ "$checkfonts" = 'check' ]
then
echo "Required FontEmbedding = $FontEmbedding (inversed logic)"
fi
# other PDF output checks
slacheckattr $alloptions "$1" PDF Bookmarks "1" "Exporter les bookmarks définis (outlines PDF)"
slacheckattr $alloptions "$1" PDF PicRes "$PicRes" "Max images resolution"
slacheckattr $alloptions "$1" PDF Resolution "$Resolution" "EPS graphics resolution"
slacheckattr $alloptions "$1" PDF Compress "$Compress" "Compression des images"
slacheckattr $alloptions "$1" PDF RecalcPic "$RecalcPic" "Limiter la résolution des images"
slacheckattr $alloptions "$1" PDF CMethod "$CMethod" "Méthode de compression des images"
slacheckattr $alloptions "$1" PDF Quality "$Quality" "Qualité de la compression des images"
slacheckattr $alloptions "$1" PDF EmbedPDF "$EmbedPDF" "Embed PDFs"
slacheckattr $alloptions "$1" PDF Version "$PDFversion" "Version PDF - eg 15 for 1.5"
slacheckattr $alloptions "$1" PDF docInfoMarks "$docInfoMarks" "Nom du fichier et date (+ agrandit les bleeds)"
slacheckattr $alloptions "$1" PDF useDocBleeds "$useDocBleeds" "Utiliser le fond perdu du document"
slacheckattr $alloptions "$1" PDF BTop "$BTop" "Fond perdu en haut"
slacheckattr $alloptions "$1" PDF BLeft "$BLeft" "Fond perdu intérieur (mais indiqué Left ?)"
slacheckattr $alloptions "$1" PDF BRight "$BRight" "Fond perdu extérieur (mais indiqué Right ?)"
slacheckattr $alloptions "$1" PDF BBottom "$BBottom" "Fond perdu en bas"
slacheckattr $alloptions "$1" PDF cropMarks "$cropMarks" "Traits de coupe"
slacheckattr $alloptions "$1" PDF markLength "$markLength" "Longueur des traits de coupe"
slacheckattr $alloptions "$1" PDF markOffset "$markOffset" "Décalage des traits de coupe"
slacheckattr $alloptions "$1" PDF bleedMarks "$bleedMarks" "Traits de fond perdu"
slacheckattr $alloptions "$1" PDF registrationMarks "$registrationMarks" "registrationMarks"
slacheckattr $alloptions "$1" PDF colorMarks "$colorMarks" "colorMarks"
# Check Pages attributes
slacheckattr $alloptions -all "$1" PAGE PAGEWIDTH "$PAGEWIDTH" "Largeur de page A5=420.944881889764"
slacheckattr $alloptions -all "$1" MASTERPAGE PAGEWIDTH "$PAGEWIDTH" "Largeur de page A5=420.944881889764"
slacheckattr $alloptions -all "$1" PAGE PAGEHEIGHT "$PAGEHEIGHT" "Hauteur de page A5=595.275590551181"
slacheckattr $alloptions -all "$1" MASTERPAGE PAGEHEIGHT "$PAGEHEIGHT" "Hauteur de page A5=595.275590551181"
if [ "$checkpagenums" = 'check' ] && [ "$pagenumval" != '' ]
then
slacheckattr $alloptions "$1" Section Start $pagenumval "First page should be #$pagenumval"
fi
if [ "$setrequested" != "" ]
then
exit;
# else
# echo "Attributes have been checked. In case there are mistakes you can fix them using -set option"
fi
if [ "$dopdf" = 'check' ] || [ "$dopdf" = 'create' ] || [ "$dopdf" = 'force' ]
then
# on vérifie qu'il y a un PDF et qu'il a été généré APRÈS l'édition du SLA
# stat -c %y n54.pdf : date de modif de n54.pdf
if [ ! -f "$1.pdf" ]
then
echo Missing "$1.pdf"
elif [ "$1.sla" -nt "$1.pdf" ]
then
datesla=`stat -c %y "$1.sla"`
datepdf=`stat -c %y "$1.pdf"`
echo -e "${ESC_warning}${ESC_normal} $1.sla has been edited and saved later (${datesla%:*}) than last PDF output (${datepdf%:*})"
fi
if [ ! -f "$1.pdf" ] || [ "$1.sla" -nt "$1.pdf" ] || [ "$dopdf" = 'force' ]
then
if [ "$dopdf" = 'create' ] || [ "$dopdf" = 'force' ]
then
if [ -f "$1.pdf" ]
then
mv "$1.pdf" "$1.pdf.bak"
if [ -f "$1.pdf" ]
then
echo -e "${ESC_error}$1.pdf couldnt be moved$ESC_normal"
fi
fi
echo "Export to $1.pdf"
path_to_here=`pwd` # appimages require an absolute path to SLA
if [ "$vcheck" = '' ]
then
# -g : no gui, -ns : no splash screen, but a window still opens...
echo $scribuscommand -g -ns -py `which slatopdf.py` -- "$path_to_here/$1.sla" 2> /dev/null
$scribuscommand -g -ns -py `which slatopdf.py` -- "$path_to_here/$1.sla" 2> /dev/null
else
echo $scribuscommand -g -ns -py `which slatopdf.py` -- "$path_to_here/$1.sla"
$scribuscommand -g -ns -py `which slatopdf.py` -- "$path_to_here/$1.sla"
fi
if [ -f "$1.pdf" ]
then
echo "OK $1.pdf"
else
echo -e "${ESC_error}$1.pdf could not be created$ESC_normal"
fi
fi
fi
fi
if [ "$checkimg" = 'check' ]
then
slacheckimages "$1"
fi
if [ "$checkfonts" = 'check' ]
then
slacheckfonts $vecto "$1"
fi