#!/bin/sh # # Output an Encapsulated PostScript File with a 14:10 aspect grid on top # defs_file=@defs@ export PATH=@path@ export LD_LIBRARY_PATH=@ld_lib_path@ x_off=0 y_off=0 scaling=1 g_intvl=1.5 g_thick=0.05 g_color=0:0:0 p_size=a4 if [ -f $defs_file ]; then defs=$(cat $defs_file) oifs="$IFS" IFS=" " for line in $defs; do if [ "$IFS" != "$oifs" ]; then IFS="$oifs"; fi key="${line%%[ ]*}"; val="${line##*[ ]}" case "$key" in x_offset) x_off=$val;; y_offset) y_off=$val;; scaling) scaling=$val;; grid_interval) g_interval=$val;; grid_thickness) g_thick=$val;; grid_color) g_color=$val;; paper_size) p_size=$val;; esac done fi usage_defs="-x$x_off -y$y_off -s$scaling -i$g_intvl -t$g_thick -c$g_color -p$p_size" usage () { echo "usage: grid [-x xoffset] [-y yoffset] [-s scaling] [-i gridinterval] [-t gridthickness] [-c gridcolor] [-r] [-p papersize] [-l] file Default values: $usage_defs" >&2 exit 1 } while getopts ":x:y:s:i:t:c:rp:l" c do case "$c" in x) x_off=$OPTARG;; y) y_off=$OPTARG;; s) scaling=$OPTARG;; i) g_intvl=$OPTARG;; t) g_thick=$OPTARG;; c) g_color=$OPTARG;; r) r_flag=1;; p) p_size=$OPTARG;; l) l_flag=1;; :|'?') usage;; esac done if [ $OPTIND -gt 1 ]; then shift $(($OPTIND - 1)); fi if [ $# -lt 1 ]; then usage; fi if [ ! -f "$1" ]; then echo "grid: Can't open file \`$1'" >&2 exit 1 fi ts="$(file "$1")" t="${ts#*: }" case "$t" in PostScript\ document\ text*) eps=$1;; JPEG\ image\ data*) pnmcmd=$(which djpeg) || \ { echo "grid: Can't find \`djpeg'" >&2; exit 1; };; TIFF\ image\ data*) pnmcmd=$(which tifftopnm) || \ { echo "grid: Can't find \`tifftopnm'" >&2; exit 1; };; GIF\ image\ data*) pnmcmd=$(which giftopnm) || pnmcmd=$(which giftoppm) || \ { echo "grid: Can't find \`giftopnm' or \`giftoppm'" >&2; exit 1; };; *) echo "grid: Unknown file type" >&2 exit 1;; esac case "$p_size" in a4) pw=210; ph=297;; letter) pw=215.9; ph=279.4;; *) pw=${p_size%[X|x]*}; ph=${p_size#*[X|x]};; esac if [ -n "$pnmcmd" ]; then tmpfile=$(mktemp /usr/tmp/grid.XXXXXX) || exit 1 eps=$tmpfile ps_in="$(echo "$pw $ph" | awk '{print ($1 / 25.4) " " ($2 / 25.4)}')" pw_in="${ps_in% *}"; ph_in="${ps_in#* }" $pnmcmd "$1" 2>/dev/null | pnmtops -width $pw_in -height $ph_in \ -noturn >$eps 2>/dev/null || { rm -f $tmpfile; exit 1; } fi tmp=$(cat "$eps" | awk '/^%%BoundingBox:/ { print (- $2) " " (- $3) }') llx_adj=${tmp% *}; lly_adj=${tmp#* } g_hdiv=1.4; g_vdiv=1 if [ -n "$r_flag" ]; then g_hdiv=1; g_vdiv=1.4 fi if [ -n "$l_flag" ]; then tmp=$pw; pw=$ph; ph=$tmp fi cat <