From: Ian Jackson Date: Mon, 26 Feb 2018 23:34:24 +0000 (+0000) Subject: svg-prep-dxf: copy from private repo f0cc4e6f4db54b4c59660d46330ecb3e735ce009 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=commitdiff_plain;h=a115b87c3f7176ad7ce8ce2c4633cd4799e98f9b;hp=00f6e6b886700261cade1e42b9c3e195be99f4d2 svg-prep-dxf: copy from private repo f0cc4e6f4db54b4c59660d46330ecb3e735ce009 Signed-off-by: Ian Jackson --- diff --git a/svg-prep-dxf b/svg-prep-dxf new file mode 100755 index 0000000..9f101f3 --- /dev/null +++ b/svg-prep-dxf @@ -0,0 +1,175 @@ +#!/bin/bash +us=svg-prep-dxf +usage () { cat <&2 "svg-dxf-prep: $*"; exit 1; } +badusage () { usage >&2; exit 1; } + +flatness=0.01 +# ^ this number seems to work reasonably well +# although maybe it should be adjusted? + +while true; do + case "$1" in + --flatness=*) + flatness="${1#*=}" + ;; + -*) + badusage + ;; + *) + break + ;; + esac + shift +done + +case "$#" in +2) ;; +*) badusage ;; +esac + +source=$1 +dest=$2 + +case "$source" in +*.svg) ;; +*) badusage ;; +esac + +case "$dest" in +*.dxf) ;; +*) badusage ;; +esac + +tmpdir="$(dirname "$dest")/.$(basename "$dest").tmpdir" +rm -rf -- "$tmpdir" +mkdir -- "$tmpdir" + +case "$tmpdir" in +/*) abstmpdir="$tmpdir" ;; +*) abstmpdir="$PWD/$tmpdir" ;; +esac + +cp -- "$source" "$tmpdir/t.svg" + +# startx seems to send "client" stdout/stderr somewhere hopeless +exec 4>&2 + +baseextdir=$(inkscape -x) +ourid=uk.org.greenend.chiark.ijackson.swirly.flatten + +# inkscape doesn't provide a way to specify a per-invocation +# extension directory, but it does look in $HOME. +# Anyway, we're going to want a fresh HOME for startx. +ourxd="$tmpdir"/.config/inkscape/extensions +mkdir -p "$ourxd" +mkdir -p "$tmpdir/.local/share" # inkscape complains otherwise, wtf + +# Putting the absolute path in the XML doesn't seem to work: +# inkscape complains that this "dependency" (implicit, apparently) +# is not satisfied. +# I'm not sure why this is, but this does work: +ln -s -- "$baseextdir/flatten.py" "$ourxd" + +xmlstarlet \ +ed \ + -N ie=http://www.inkscape.org/namespace/inkscape/extension \ + -u "/ie:inkscape-extension/ie:_name" -v "Our Flatten Beziers" \ + -u "/ie:inkscape-extension/ie:id" -v $ourid \ + -d '/ie:inkscape-extension/ie:dependency' \ + -u '/ie:inkscape-extension/ie:param[@name="flatness"]' -v $flatness \ + "$baseextdir"/flatten.inx \ + >"$ourxd"/our-flatten.inx +# known bugs with this approach: +# - we rely on the .inx filename +# - we rely on flatten.py being in the extensions/ directory +# and called exactly that +# - we drop the dependencies rather than editing them + +cat <<'END' >"$tmpdir/run-inkscape" +#!/bin/sh +exec >&4 2>&4 +echo +printf "running inkscape to transform and clean up..." +cd "$HOME" +inkscape \ + --with-gui \ + t.svg \ + --verb=EditSelectAll \ + --verb=StrokeToPath \ + --verb=ToolNode \ + --verb=EditSelectAll \ + --verb=SelectionUnion \ + --verb=EditSelectAll \ + --verb=uk.org.greenend.chiark.ijackson.swirly.flatten.noprefs \ + --verb=FileSave \ + --verb=FileQuit \ + +echo done. +echo +END +chmod +x "$tmpdir"/run-inkscape + +cat <