Skip to content

Commit 60597ee

Browse files
authored
Merge pull request #4043 from grandixximo/docs-inkscape-rsvg-shim
docs: shim inkscape -> rsvg-convert in docs build (fixes #4040)
2 parents ded5c73 + c1b2cc7 commit 60597ee

2 files changed

Lines changed: 97 additions & 1 deletion

File tree

debian/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ elif [ -f /etc/lsb-release ]; then
110110
fi
111111

112112
if [ -n "$ENABLE_BUILD_DOCUMENTATION" ]; then
113-
DOC_DEPENDS="dblatex (>= 0.2.12),\n dvipng,\n fonts-dejavu,\n graphviz,\n groff,\n inkscape,\n python3-lxml,\n source-highlight,\n texlive-extra-utils,\n texlive-font-utils,\n texlive-fonts-recommended,\n texlive-lang-cyrillic,\n texlive-lang-european,\n texlive-lang-french,\n texlive-lang-german,\n texlive-lang-polish,\n texlive-lang-spanish,\n texlive-latex-recommended,\n w3c-linkchecker,\n xsltproc"
113+
DOC_DEPENDS="dblatex (>= 0.2.12),\n dvipng,\n fonts-dejavu,\n graphviz,\n groff,\n inkscape,\n librsvg2-bin,\n python3-lxml,\n source-highlight,\n texlive-extra-utils,\n texlive-font-utils,\n texlive-fonts-recommended,\n texlive-lang-cyrillic,\n texlive-lang-european,\n texlive-lang-french,\n texlive-lang-german,\n texlive-lang-polish,\n texlive-lang-spanish,\n texlive-latex-recommended,\n w3c-linkchecker,\n xsltproc"
114114

115115

116116
case $DISTRIB_NAME in

scripts/inkscape

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
# Shim that intercepts the inkscape calls made by dblatex during the
3+
# LinuxCNC docs build and forwards them to rsvg-convert. Avoids the noisy
4+
# Pango/GtkRecentManager warnings that headless Inkscape prints on every
5+
# SVG conversion (see issue #4040). Handles both dblatex syntaxes:
6+
# new (Inkscape 1.x): inkscape -D --export-filename=OUT IN
7+
# old (Inkscape 0.x): inkscape -z -D --export-png=OUT IN
8+
# (also --export-pdf=, --export-eps=)
9+
# Falls back to the real inkscape whenever the args do not match the
10+
# expected pattern, when rsvg-convert is missing, or when
11+
# LINUXCNC_DOCS_NO_RSVG is set.
12+
13+
set -u
14+
15+
real_inkscape() {
16+
# Find the next `inkscape` on PATH after stripping the directory holding
17+
# this shim, so we do not recurse into ourselves.
18+
local self_dir
19+
self_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
20+
local stripped_path
21+
stripped_path=$(printf '%s' "$PATH" | tr ':' '\n' \
22+
| grep -vxF "$self_dir" | paste -sd:)
23+
PATH="$stripped_path" exec inkscape "$@"
24+
}
25+
26+
# Escape hatch.
27+
if [ -n "${LINUXCNC_DOCS_NO_RSVG:-}" ]; then
28+
real_inkscape "$@"
29+
fi
30+
31+
# rsvg-convert must be available.
32+
if ! command -v rsvg-convert >/dev/null 2>&1; then
33+
real_inkscape "$@"
34+
fi
35+
36+
# Parse the dblatex call pattern. Accepted flags:
37+
# -D, -d, -z, --without-gui (ignored: pose/area/legacy GUI suppression)
38+
# --export-filename=OUT (Inkscape 1.x)
39+
# --export-png=OUT (Inkscape 0.x)
40+
# --export-pdf=OUT (Inkscape 0.x)
41+
# --export-eps=OUT (Inkscape 0.x)
42+
# One positional input. Anything else falls through to real inkscape.
43+
out=""
44+
in=""
45+
fmt=""
46+
saw_unknown=0
47+
for arg in "$@"; do
48+
case "$arg" in
49+
-D|-d|-z|--without-gui)
50+
;;
51+
--export-filename=*)
52+
out="${arg#--export-filename=}"
53+
;;
54+
--export-png=*)
55+
out="${arg#--export-png=}"
56+
fmt=png
57+
;;
58+
--export-pdf=*)
59+
out="${arg#--export-pdf=}"
60+
fmt=pdf
61+
;;
62+
--export-eps=*)
63+
out="${arg#--export-eps=}"
64+
fmt=eps
65+
;;
66+
-*)
67+
saw_unknown=1
68+
;;
69+
*)
70+
if [ -n "$in" ]; then
71+
saw_unknown=1
72+
else
73+
in="$arg"
74+
fi
75+
;;
76+
esac
77+
done
78+
79+
if [ "$saw_unknown" = 1 ] || [ -z "$in" ] || [ -z "$out" ]; then
80+
real_inkscape "$@"
81+
fi
82+
83+
# If format not yet set (new-syntax --export-filename), infer from extension.
84+
if [ -z "$fmt" ]; then
85+
case "$out" in
86+
*.pdf) fmt=pdf ;;
87+
*.png) fmt=png ;;
88+
*.eps) fmt=eps ;;
89+
*.svg) fmt=svg ;;
90+
*) real_inkscape "$@" ;;
91+
esac
92+
fi
93+
94+
if ! rsvg-convert -f "$fmt" -o "$out" "$in"; then
95+
real_inkscape "$@"
96+
fi

0 commit comments

Comments
 (0)