Debian Codegraph @

src/figures/make-figures

raw
1 #!/bin/sh -eu
2 #
3 # Dia Scripts
4 # Copyright (C) 2007-2026 by Thomas Dreibholz
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Contact: [email protected]
20
21 FIGURES="
22 EN-RSerPool-ProtocolStack
23 EN-RSerPool-Handlespace-Information
24 EN-RSerPool-PE-PRH-PR
25 EN-RSerPool-Scenario
26 EN-RSerPool-Scenario-without-PPE-and-PPU
27 EN-RSerPool-Scenario-with-PPE
28 "
29 DENSITY="300x300"
30
31 for figure in $FIGURES ; do
32 # ====== Export Dia to PDF ===============================================
33 dia -n -t cairo-pdf -e tmp1.pdf "$figure.dia"
34
35 # ====== Make PDF with transparent background ============================
36 # OLD:
37 # epstopdf --outfile=tmp1.eps tmp1.pdf
38 # pdfcrop --hires tmp1.eps tmp2.pdf
39
40 pdfcrop --quiet --hires tmp1.pdf tmp2.pdf
41
42 # The background is specified as something like:
43 # 1 1 1 rg /a0 gs
44 # 0 0 596 843 re f
45 # => Remove the first occurrence only
46 qpdf -qdf tmp2.pdf tmp1.qdf
47 sed -e '0,/^.* re\( f\|\)$/s/^\(.* re\)\( f\|\)$/%% \1/' \
48 -e '0,/^1 1 1 rg\( .*\|\)$/s/^\(1 1 1 rg\)\( .*\|\)$/%% \1/' \
49 <tmp1.qdf >tmp2.qdf
50 fix-qdf tmp2.qdf >"$figure.pdf"
51
52 # ls -l tmp1.qdf tmp2.qdf
53 # colordiff tmp1.qdf tmp2.qdf || true
54
55 # ====== Make SVG, with transparent background ===========================
56 pdf2svg "$figure.pdf" "$figure.svg"
57
58 # Should be unnecessary, since the background has already been removed:
59 # pdf2svg "$figure.pdf" tmp1.svg
60 # sed \
61 # -e 's#\(<rect [^>]*fill-opacity="\)\([0-9\.]*\)\("/>\)#\10\3#g' \
62 # <tmp1.svg >"$figure.svg"
63
64 # ====== Make PNG and WebP, with transparent background ==================
65 # NOTE: GraphicsMagick PDF to PNG with transparency is broken!
66 gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r$DENSITY -q -sOutputFile="$figure.png" "$figure.pdf"
67 gm convert "$figure.png" "$figure.webp"
68
69 rm -f tmp1.pdf tmp2.pdf tmp1.eps tmp1.qdf tmp2.qdf tmp1.svg
70 done