mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-12-23 09:12:04 +02:00
Split gitsch2ppm into its constituents.
- scripts/gitsch2ps: generate PS files for KiCad schematics in git - scripts/normalizeschps: normalize eeschema Postscript - scripts/schps2ppm: generate PPM files from normalized Eeschema Postscript - scripts/gitsch2ppm: wrapper and cache manager for the above scripts
This commit is contained in:
parent
a61e9da4d9
commit
b3f2014863
@ -12,36 +12,6 @@
|
||||
#
|
||||
|
||||
|
||||
RES=1280x850
|
||||
LINEWIDTH=120
|
||||
|
||||
|
||||
ps2ppm()
|
||||
{
|
||||
X=`echo $RES | sed 's/x.*//'`
|
||||
Y=`echo $RES | sed 's/.*x//'`
|
||||
IRES=${Y}x$X
|
||||
res=`expr 72 \* $X / 800`
|
||||
|
||||
( cat <<EOF
|
||||
%!PS-Adobe-3.0
|
||||
/setlinewidth { $LINEWIDTH 2 copy lt { exch } if pop setlinewidth } bind def
|
||||
/rectfill { rectstroke } bind def
|
||||
EOF
|
||||
sed <"$1" '1d
|
||||
/%%DocumentMedia: A4.*/a-20 -10 translate
|
||||
/%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
|
||||
}
|
||||
/%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
|
||||
}
|
||||
/%%Orientation: Landscape/d'; ) |
|
||||
gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
|
||||
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
|
||||
pnmflip -r270 |
|
||||
cat >"${1%.ps}.ppm"
|
||||
}
|
||||
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF 1>&2
|
||||
@ -59,7 +29,9 @@ EOF
|
||||
|
||||
cache=false
|
||||
keep=false
|
||||
sanitize=true
|
||||
res=
|
||||
sanitize=
|
||||
width=
|
||||
while true; do
|
||||
case "$1" in
|
||||
-c) cache=true
|
||||
@ -67,13 +39,12 @@ while true; do
|
||||
-k) keep=true
|
||||
shift;;
|
||||
-r) [ -z "$2" ] && usage
|
||||
RES="$2"
|
||||
res="-r $2"
|
||||
shift 2;;
|
||||
-S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
|
||||
[ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
|
||||
-S) sanitize=-S
|
||||
shift;;
|
||||
-w) [ -z "$2" ] && usage
|
||||
LINEWIDTH="$2"
|
||||
width="-r $2"
|
||||
shift 2;;
|
||||
-*)
|
||||
usage;;
|
||||
@ -82,53 +53,30 @@ while true; do
|
||||
esac
|
||||
done
|
||||
|
||||
[ ! -z "$3" -a -z "$5" ] || usage
|
||||
dir="$1"
|
||||
schem="$2"
|
||||
sdir=`dirname "$schem"`
|
||||
if [ -z "$4" ]; then
|
||||
commit=HEAD
|
||||
outdir="$3"
|
||||
else
|
||||
commit="$3"
|
||||
outdir="$4"
|
||||
fi
|
||||
tmp=`pwd`/_gitsch2ppm
|
||||
eval outdir=\${$#}
|
||||
|
||||
[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
|
||||
|
||||
[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
|
||||
[ -d "$dir/.git" ] || usage
|
||||
|
||||
tmp="$dir/../_gitsch2ppm"
|
||||
sch="$tmp/$sdir"
|
||||
# with thanks to http://www.faqs.org/faqs/unix-faq/faq/part2/section-12.html
|
||||
argv=
|
||||
while [ $# -gt 1 ]; do
|
||||
argv="$argv \"$1\""
|
||||
shift
|
||||
done
|
||||
eval set x "$argv"
|
||||
shift
|
||||
|
||||
if ! $cache; then
|
||||
rm -rf "$tmp"
|
||||
rm -rf "$outdir"
|
||||
|
||||
git clone -s -n "$dir/.git" "$tmp" || exit
|
||||
( cd "$tmp" && git checkout -q "$commit"; ) || exit
|
||||
|
||||
if [ ! -f "$tmp/$schem" ]; then
|
||||
echo "$schem not found (checked out into $tmp)" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$sch" || exit
|
||||
rm -f *.ps *.ppm
|
||||
$sanitize "$tmp/${schem%.sch}.pro" ||
|
||||
exit
|
||||
eeschema --plot "$tmp/$schem"
|
||||
) || exit
|
||||
gitsch2ps $sanitize "$@" "$tmp"
|
||||
for n in "$tmp"/*.ps; do
|
||||
normalizeschps $width "$n"
|
||||
done
|
||||
fi
|
||||
|
||||
for n in "$sch"/*.ps; do
|
||||
ps2ppm "$n"
|
||||
mkdir -p "$outdir"
|
||||
for n in "$tmp"/*.ps; do
|
||||
schps2ppm $res "$n" "$outdir/`basename \"${n%.ps}.ppm\"`"
|
||||
done
|
||||
|
||||
mkdir -p "$outdir"
|
||||
|
||||
mv "$sch"/*.ppm "$outdir"
|
||||
|
||||
$keep || rm -rf "$tmp"
|
||||
|
81
scripts/gitsch2ps
Executable file
81
scripts/gitsch2ps
Executable file
@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# gitsch2ps - Generate PS files for KiCad schematics in git
|
||||
#
|
||||
# Written 2010 by Werner Almesberger
|
||||
# Copyright 2010 Werner Almesberger
|
||||
#
|
||||
# This program 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF 1>&2
|
||||
usage: $0 [options] top-dir top-schem [commit] outdir
|
||||
|
||||
-S sanitize the KiCad profile
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
sanitize=true
|
||||
while true; do
|
||||
case "$1" in
|
||||
-S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
|
||||
[ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
|
||||
shift;;
|
||||
-*)
|
||||
usage;;
|
||||
*)
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ ! -z "$3" -a -z "$5" ] || usage
|
||||
dir="$1"
|
||||
schem="$2"
|
||||
sdir=`dirname "$schem"`
|
||||
if [ -z "$4" ]; then
|
||||
commit=HEAD
|
||||
outdir="$3"
|
||||
else
|
||||
commit="$3"
|
||||
outdir="$4"
|
||||
fi
|
||||
|
||||
[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
|
||||
|
||||
[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
|
||||
[ -d "$dir/.git" ] || usage
|
||||
|
||||
tmp="$dir/../_gitsch2ps"
|
||||
sch="$tmp/$sdir"
|
||||
|
||||
rm -rf "$tmp"
|
||||
rm -rf "$outdir"
|
||||
|
||||
git clone -s -n "$dir/.git" "$tmp" || exit
|
||||
( cd "$tmp" && git checkout -q "$commit"; ) || exit
|
||||
|
||||
if [ ! -f "$tmp/$schem" ]; then
|
||||
echo "$schem not found (checked out into $tmp)" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$sch" || exit
|
||||
rm -f *.ps
|
||||
$sanitize "$tmp/${schem%.sch}.pro" ||
|
||||
exit
|
||||
eeschema --plot "$tmp/$schem"
|
||||
) || exit
|
||||
|
||||
mkdir -p "$outdir"
|
||||
mv "$sch"/*.ps "$outdir"
|
||||
|
||||
rm -rf "$tmp"
|
59
scripts/normalizeschps
Executable file
59
scripts/normalizeschps
Executable file
@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# normalizeschps - Normalize eeschema Postscript
|
||||
#
|
||||
# Written 2010 by Werner Almesberger
|
||||
# Copyright 2010 Werner Almesberger
|
||||
#
|
||||
# This program 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
|
||||
|
||||
LINEWIDTH=120
|
||||
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF 1>&2
|
||||
usage: $0 [options] file ...
|
||||
|
||||
-w points Postscript line width (default: $LINEWIDTH)
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-w) [ -z "$2" ] && usage
|
||||
LINEWIDTH="$2"
|
||||
shift 2;;
|
||||
-*)
|
||||
usage;;
|
||||
*)
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
for n in "$@"; do
|
||||
sed -i '
|
||||
1c%!PS-Adobe-3.0\
|
||||
currentdict /DidNormalize known not { \
|
||||
/setlinewidth { '$LINEWIDTH' 2 copy lt { exch } if pop \
|
||||
setlinewidth } bind def \
|
||||
/rectfill { rectstroke } bind def \
|
||||
/DidNormalize true def \
|
||||
} if \
|
||||
gsave
|
||||
/%%DocumentMedia: A4.*/a-20 -10 translate
|
||||
/%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
|
||||
}
|
||||
/%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
|
||||
}
|
||||
$agrestore' "$n"
|
||||
done
|
||||
|
||||
# /%%Orientation: Landscape/d' "$n"
|
53
scripts/schps2ppm
Executable file
53
scripts/schps2ppm
Executable file
@ -0,0 +1,53 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# schps2ppm - Generate PPM files from normalized Eeschema Postscript
|
||||
#
|
||||
# Written 2010 by Werner Almesberger
|
||||
# Copyright 2010 Werner Almesberger
|
||||
#
|
||||
# This program 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
|
||||
|
||||
RES=1280x850
|
||||
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF 1>&2
|
||||
usage: $0 [options] [file.ps [file.ppm]]
|
||||
|
||||
-r XxY image resolution (default: $RES)
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-r) [ -z "$2" ] && usage
|
||||
RES="$2"
|
||||
shift 2;;
|
||||
-*)
|
||||
usage;;
|
||||
*)
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ ! -z "$3" ] && usage
|
||||
in=${1:--}
|
||||
out=${2:-/dev/stdout}
|
||||
|
||||
X=`echo $RES | sed 's/x.*//'`
|
||||
Y=`echo $RES | sed 's/.*x//'`
|
||||
IRES=${Y}x$X
|
||||
res=`expr 72 \* $X / 800`
|
||||
|
||||
cat "$in" |
|
||||
gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
|
||||
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
|
||||
pnmflip -r270 >"$out"
|
Loading…
Reference in New Issue
Block a user