#!/usr/xpg4/bin/sh # pstomvd 0.1.0 Thu 19 Dec 1996 # by Adam M. Costello # pstomvd [ -r dpi ] [ -w width ] [ -h height ] base # # Converts the file base.ps into a multivalent document comprised of # base.html, base.mvd, base????.xdc, base????.gif. The resolution is # in dots per inch, and defaults to 100. The width and height of the # page are in inches, and default to 8.5 and 11.0. # # This script does not pretend to be flexible--it's a demonstration. # global variables dpi=100 filegamma=0.6 format=%04d height=11.0 numcolors=256 scale=3 width=8.5 usage() { echo "$0 [ -r resolution ] base" >&2 exit 1 } while [ $# -gt 1 ]; do if [ "$1" = -r ]; then res=$2 shift 2 continue fi if [ "$1" = -w ]; then width=$2 shift 2 fi if [ "$1" = -h ]; then height=$2 shift 2 fi usage done [ $# -eq 1 ] || usage tmpdir=/tmp/pstomvd$$ mkdir $tmpdir base=$1 # pst2xdc initialpage src dest pst2xdc() { page=$1 src=$2 dest=$3 psttoxdoc -w "$width" -h "$height" -p "$page" < "$src" > "$dest" #rm "$src" echo "$dest is ready" >&2 } # ppm2gif src dest ppm2gif() { src=$1 dest=$2 pnmscale `echo "6k 1 $scale / p" | dc` < "$src" | pnmgamma $filegamma | ppmquant $numcolors 2>&- | ppmtogif 2>&- > "$dest" rm "$src" echo "$dest is ready" >&2 } gsdpi=`expr $scale \* $dpi` ################ # main execution gs -q -r$gsdpi -dWRITESYSTEMDICT -dDELAYBIND -dNOPAUSE -sDEVICE=ppmraw \ -sOutputFile="$tmpdir/$format.ppm" -dVERBOSE -sCHARSET=Latin-1 \ pstext.ps - < "$base.ps" | nawk ' BEGIN { getline Idirective; newpage = 1; } { filename = sprintf(base format ".pst", page); if (newpage) { print Idirective > filename; newpage = 0; } print > filename; if (index($0, "P") == 1) { close filename; print sprintf(format, page++); newpage = 1; } } ' base="$tmpdir/" format=$format page=1 | while read page; do ppm2gif "$tmpdir/$page.ppm" "$base$page.gif" & pst2xdc $page "$tmpdir/$page.pst" "$base$page.xdc" & numpages=$page done echo "total number of pages: $numpages" >&2 xdocscale=`echo "6k 300 $dpi / p" | dc` cat > "$base.mvd" << !EOF! !EOF! cat > "$base.html" << !EOF! untitled !EOF! wait { echo "You are now ready to run:" echo "appletviewer $base.html" } >&2 rmdir $tmpdir