#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile README escher.triang.ps illusion.ps maketgif.l
#   pstotgif pstotgif.pro
# Wrapped by william@makaha on Sat Sep 11 19:09:20 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(428 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XSHAROBJECTS=README Makefile maketgif.l pstotgif pstotgif.pro illusion.ps escher.triang.ps
Xmaketgif: maketgif.l
X	lex  maketgif.l 
X	cc -o maketgif lex.yy.c -ll
X	rm lex.yy.c
Xtest: maketgif
X	pstotgif illusion.ps 
X	tgif illusion.ps.obj
X	pstotgif -m 2 illusion.ps 
X	tgif illusion.ps.obj
X	pstotgif -t illusion.ps 
X	tgif illusion.ps.obj
X	pstotgif  escher.triang.ps 
X	tgif escher.triang.ps.obj
Xshar:
X	shar $(SHAROBJECTS) > pstotgif.shar
END_OF_FILE
if test 428 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2234 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XPSTOTGIF
XCopyright (C) 1993, Wolfgang Glunz, Siemens AG, glunz@ztivax.zfe.siemens.de
X
Xpstotgif allows to convert Postscript files to a simple vector graphic
Xformat, that can be edited with tgif. Ask archie on where to find tgif.
Xpstotgif works by redefining the two basic painting operators of
XPostscript, stroke and show. Others like fill or image are not supported.
XAfter redefining these operators, the Postscript file that needs to
Xbe converted is processed by GhostScript (gs). So you need to have
XGhostscript in order to use this program.
Xpstotgif uses a postprocessor to actually build the input file for tgif.
XThis is a small lex-program (maketgif). To build it, just type make.
XEdit the pstotgif script and change LIB according to your local 
Xenvironment.
X
XThe output of gs that is piped to maketgif is similar to PostScript (moveto
Xlineto, show, ...). This is because I once needed to generate a simple
X(using only basic operators) PostScript file from a complex one. 
X
XA cleaner approach to all this would be to implement a new device 
Xdriver in GhostScript. This could either dump tgif input directly or
X(better) dump the picture as a simple (see above) PostScript file
Xwhich can be converted to tgif or other graphic editors by a postprocessor.
XIf anybody does this or has already done, please let me (glunz@ztivax.zfe.siemens.de) know.
X
X
XThere is one test included. To run it type `make test'
X
XUsage :
X
Xpstotgif [-t] [-m number] files
X
XOptions:
X-t : dont make polygons from text. This however does not take into
X     account the current font. So any text will be written horizontally
X     with a standard font.
X-m factor:
X     magnify by a factor. 
X
Xpstotgif writes the output to <inputfile>.obj so it can be read into tgif.
X
XSend any improvements to glunz@ztivax.zfe.siemens.de
X
X
XPermission to use and modify this software and its 
Xdocumentation for any purpose is hereby granted without fee
Xprovided, however, that the above copyright notice appear in all 
Xcopies, that both that copyright notice and this permission notice 
Xappear in supporting documentation. The author makes no representations 
Xabout the suitability of this software for any purpose. It is 
Xprovided ``as is'' without express or implied warranty. 
END_OF_FILE
if test 2234 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'escher.triang.ps' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'escher.triang.ps'\"
else
echo shar: Extracting \"'escher.triang.ps'\" \(1436 characters\)
sed "s/^X//" >'escher.triang.ps' <<'END_OF_FILE'
X%!
X% M. C. Escher style impossible triangle
X% written by Guy Shaw
X
X% Things that are easy to play with:
X% Position on paper, overall size, and linewidth
X/inch { 72 mul } bind def
X
X2 inch dup translate
X3 inch dup scale
X1 3 inch div setlinewidth
X
X% Thickness parameter:
X% /Thick is the thickness of the structural members of the triange,
X% as a fraction of the height of the triangle.
X% Reasonable looking impossible triangles can be obtained with Thick <= 1/6.
X% right at /Thick == 1/6, there is no space left inside the triangle.
X% /Thick > 1/6 yields bizarre, but not very interesting results.
X% /Thick < 1/20 is less interesting, because the "impossibility"
X% is not so striking when the structural members are that thin.
X% A good "standard" value is 1/8.
X
X/Thick 1 8 div def
X
X% You would not normally want to change anything that follows.
X
X/Tall 1 def
X/HalfThick Thick .5 mul def
X
Xnewpath
X	HalfThick Thick moveto
X	Thick  0 lineto
X	1 Thick sub  0 lineto
X	1 HalfThick sub  Thick lineto
X	.5 HalfThick add  Tall Thick sub lineto
X
X	1 Thick sub  0 moveto
X	.5 HalfThick add  Tall 3 Thick mul sub lineto
X	Thick 3 mul  Thick 2 mul lineto
X
X	1 Thick 2.5 mul sub  Thick moveto
X	.5  Tall Thick 4 mul sub lineto
Xstroke
X
Xnewpath
X	HalfThick Thick moveto
X	1 Thick 2.5 mul sub  Thick lineto
X	HalfThick neg  Thick rlineto
X	Thick Thick add  Thick Thick add lineto
X	.5 HalfThick add  Tall Thick sub lineto
X	Thick neg  0 rlineto
X	closepath
Xfill
X
Xshowpage
END_OF_FILE
if test 1436 -ne `wc -c <'escher.triang.ps'`; then
    echo shar: \"'escher.triang.ps'\" unpacked with wrong size!
fi
# end of 'escher.triang.ps'
fi
if test -f 'illusion.ps' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'illusion.ps'\"
else
echo shar: Extracting \"'illusion.ps'\" \(961 characters\)
sed "s/^X//" >'illusion.ps' <<'END_OF_FILE'
X%!
X% Optical illusion
X% written by Woody Baker
X% Rt.1 Box I
X% Manor, Tx. 78653
X%
X% hereby placed in the public domain.  Would appreciate the header
X% remaining in-tact.
X%
X
X%
X% do 1/4th of the drawing
X%
X/onequarter
X	{
X	60 160 moveto
X	20 160 lineto
X	20 80 lineto
X	160 80 lineto
X	60 180 moveto
X	0 180 lineto
X	0 60 lineto
X	160 60 lineto
X	40 160 moveto
X	40 100 lineto
X	160 100 lineto
X	60 200 moveto
X	20 200 lineto
X	0 180 lineto
X	40 100 moveto
X	20 80 lineto
X	} def
X%
X% draw the illusion and label it
X%	
X/optical
X	{	
X	0 0 moveto onequarter
X	gsave
X	-90 rotate -260 0 translate onequarter
X	-90 rotate -260 0 translate onequarter
X	-90 rotate -260 0 translate onequarter
X	stroke
X	grestore
X	/Helvetica findfont 20 scalefont setfont
X	-10 -25 moveto
X	(Brought to you By Woody Baker) show
X	} def
X%
X% application code.  Positions and scales and draws the actual
X% illusion.
X%	
X/xcoord 140 def
X/ycoord 240 def	
Xgsave	
Xxcoord ycoord translate
X1 1 scale
Xoptical
Xgrestore
Xshowpage
END_OF_FILE
if test 961 -ne `wc -c <'illusion.ps'`; then
    echo shar: \"'illusion.ps'\" unpacked with wrong size!
fi
# end of 'illusion.ps'
fi
if test -f 'maketgif.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'maketgif.l'\"
else
echo shar: Extracting \"'maketgif.l'\" \(5834 characters\)
sed "s/^X//" >'maketgif.l' <<'END_OF_FILE'
X%{
X/* 
X Title: maketgif.l, Version 1.3, September 1993
X
X lex program that converts the output from ghostscript to tgif input format
X if the redefinition prologue is used with ghostscript
X
X Copyright (C) 1993, Wolfgang Glunz, Siemens AG, glunz@ztivax.zfe.siemens.de
X
X Permission to use and modify this software and its 
X documentation for any purpose is hereby granted without fee
X provided, however, that the above copyright notice appear in all 
X copies, that both that copyright notice and this permission notice 
X appear in supporting documentation. The author makes no representations 
X about the suitability of this software for any purpose. It is 
X provided ``as is'' without express or implied warranty. 
X*/
X
X/* 
X History:
X 08.09.93 : multipage support plus changes regarding tgif file version 30
X 09.06.93 : recognition of rectangles
X 20.04.93 : fix in showpath
X		 suppress single point paths that some PostScript programs generate
X
X 19.04.93 : Version 1.0 released to comp.sources.postscript
X*/
X
X#include <stdio.h>
X#include <string.h>
Xfloat magnification = 1.0;
Xint page_empty = 1;
Xint tgifpagenr = 1;
Xint tgifid = 1;
Xchar *fontname = "'Courier'";
Xfloat tgifscale = 16.0 / 9.0;       /* tgif internal scale factor */
Xfloat number;
Xint currentlinewidth = 1;
Xfloat x_offset = 0.0;   /* set to fit to tgif page */
Xfloat y_offset = 89.61; /*          "              */
X
X#define MAXPOINTS 2000
X#define POLYGON 0
X#define POLY 1
Xint currenttype;
X
X#define TGIFFILL 7
X#define TGIFNOFILL 0
Xint filltype = TGIFNOFILL;
X
Xfloat coords[MAXPOINTS];
Xint pos = 0;
X
X#define addcoordinate(co) \
X if (pos < MAXPOINTS) { \
X     coords[pos++] = co; \
X } else { \
X   fprintf(stderr,"Too many points in path\n"); \
X   exit(1); \
X } 
X    
Xfloat origx,origy;
Xchar * start_of_text;
Xchar * end_of_text;
Xint is_a_rectangle()
X{
Xint i;
Xint dir; /* 1 - up/down (same x) 0 - left/right (same y) */
Xif ( pos != 10 ) return 0;
X/* it might be a  rectangle */
X
Xif (coords[0] == coords[2]) {
X	/* same x */
X	dir = 0;
X} else if (coords[1] == coords[3]) {
X	/* same y */
X	dir = 1;
X} else {
X	/* no rectangle */
X	return 0;
X}
X
Xfor (i=0;i<8;i++,i++) {
Xif (dir == 1) {
X	if (!(coords[i+1]==coords[i+1+2])) return 0;
X	dir = 0;
X} else {
X	if (!(coords[i]==coords[i+2])) return 0;
X	dir = 1;
X}
X}
Xreturn 1;
X}
X
Xvoid print_coords() 
X{
X int n;
X printf("%f",coords[0]);
X for (n=1;n<pos;n++) {
X 	if(n%2) { /* y coord */
X  		printf(",%f",coords[n]+y_offset); 
X	} else {
X  		printf(",%f",coords[n]+x_offset);
X  	}
X  	if ( (!((n+1)%16)) && ((n+1) != pos)) { printf("\n         ");}
X }
X}
Xvoid add_to_page()
X{
X	if (page_empty) {
X		page_empty = 0;
X		printf("page(%d,\"\").\n",tgifpagenr++);
X	}
X}
X
Xvoid showpath (poly,fillpat)
Xint poly;
Xint fillpat;
X{
X if (pos <= 2) {
X	/* cannot draw single points in TGIF */
X	pos = 0;  /* clear path */
X	return;
X }
X
X if ( pos % 2 ) { printf("%s\n","% odd number of data in next record"); } 
X add_to_page();
X if (poly == POLY) { 
X 	printf("%s%d%s\n%s","poly('black',",pos/2,",[","         ");
X	print_coords();
X       	printf("],0,%d%s%d%s%d%s\n%s\n",currentlinewidth,",1,",tgifid++,",0,",fillpat,",0,0,0,0,0,[","]).");
X } else {
X	if (is_a_rectangle()) {
X 		printf("box('black'");
X		printf(",%f",coords[0]+x_offset);
X		printf(",%f",coords[1]+y_offset);
X		printf(",%f",coords[4]+x_offset);
X		printf(",%f",coords[5]+y_offset);
X       		printf(",%d,%d%s%d%s\n%s\n",fillpat,currentlinewidth,",1,",tgifid++,",0,0,0,[","]).");
X	} else {
X 		printf("%s%d%s\n%s","polygon('black',",pos/2,",[","         ");
X		print_coords();
X       		printf("],%d,%d%s%d%s\n%s\n",fillpat,currentlinewidth,",1,0,",tgifid++,",0,0,0,[","]).");
X	}
X };
X pos = 0; /* clear path */
X}
X%}
X%s READPATH
X%%
X[0-9.][0-9.\-e]* 	{ 
X			 if (!sscanf(yytext,"%f",&number)) {
X			   fprintf(stderr,"sscanf failed:%s\n",yytext);
X			 }; 
X			 number = number * tgifscale;
X			 addcoordinate(number);
X			}
X<INITIAL>"showpage" { 
X			page_empty = 1;
X			}
X<INITIAL>"newpath" { 
X			BEGIN(READPATH); 
X			currenttype=POLY; /* init */
X			}
X<INITIAL>"setlinewidth" {
X			currentlinewidth = (int) number;
X			pos--; /* pop */
X			}
X<INITIAL>\((.)*\)" show" 	{ 
X			start_of_text = strchr (yytext,(int)'(') + 1 ;
X			end_of_text = strrchr (yytext,(int)')') ;
X			*end_of_text = (char) 0;
X			add_to_page();
X			printf("%s","text('black'");
X  			printf(",%f",coords[0]+x_offset);
X	  		printf(",%f",coords[1]+y_offset);
X	  		printf(",%s",fontname);
X			printf("%s%d%s\n",",0,17,1,0,0,1,70,17,",tgifid++,",0,14,3,0,0,0,0,[");
X			printf("\"%s\"]\n",start_of_text);
X 			pos = 0; /* clear path */
X			}
X"% setfillon" 		{ filltype=TGIFFILL;}
X"% setfilloff" 		{ filltype=TGIFNOFILL;}
X<INITIAL>.|\n { /* ignore any other stuff */ }
X<READPATH>"moveto" { 
X			origx = coords[pos-2];
X			origy = coords[pos-1];
X		    	if (pos > 2) {
X		       		/* this is an intermediate moveto */
X				pos = pos - 2; /* take away the last point */
X				showpath(currenttype,filltype);
X				/* start a new path */
X				addcoordinate(origx);
X				addcoordinate(origy);
X		     	}
X		   }
X<READPATH>"lineto" { }
X<READPATH>"closepath"  	{
X			 addcoordinate(origx);
X			 addcoordinate(origy);
X			 currenttype=POLYGON;
X			 /* show is done by next stroke, fill or moveto */
X			}
X<READPATH>"stroke"  	{ 
X			 BEGIN(INITIAL);
X			 showpath(currenttype,TGIFNOFILL);
X                       	};
X<READPATH>"fill"|"eofill"  { 
X			 BEGIN(INITIAL);
X			 showpath(currenttype,TGIFFILL); 
X                       	};
X<READPATH>.|\n {}
X%%
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X	if (argc > 1) {
X		if (!sscanf(argv[1],"%f",&magnification)) {
X			perror("scanning magnification");
X		}
X	}
X 	printf("%s%d%s\n","state(0,30,",(int)(magnification*100),",0,0,1,16,1,9,1,1,0,0,1,0,1,0,'Courier',0,17,0,0,1,5,0,0,1,1,0,16,1,0,1,PSTOTGIFPAGENR,1).");
X	printf("%s\n","%");
X	printf("%s\n","% @(#)$Header$");
X	printf("%s\n","%");
X	yylex();
X	printf("%s%d\n","%pstotgif: PAGENR ",tgifpagenr-1);
X	exit(0);
X}
END_OF_FILE
if test 5834 -ne `wc -c <'maketgif.l'`; then
    echo shar: \"'maketgif.l'\" unpacked with wrong size!
fi
# end of 'maketgif.l'
fi
if test -f 'pstotgif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pstotgif'\"
else
echo shar: Extracting \"'pstotgif'\" \(1518 characters\)
sed "s/^X//" >'pstotgif' <<'END_OF_FILE'
X#!/bin/sh
X#
X# Title: pstotgif, Version 1.0, April 1993
X#
X# Script to convert PostScript files to tgif input for editing
X#
X# Copyright (C) 1993, Wolfgang Glunz, Siemens AG, glunz@ztivax.zfe.siemens.de
X#
X# Permission to use and modify this software and its 
X# documentation for any purpose is hereby granted without fee
X# provided, however, that the above copyright notice appear in all 
X# copies, that both that copyright notice and this permission notice 
X# appear in supporting documentation. The author makes no representations 
X# about the suitability of this software for any purpose. It is 
X# provided ``as is'' without express or implied warranty. 
X#
X#
X# Change these lines according to the local environment
X#
X# Where the pstotgif.pro and maketgif is found
XLIB=/u/tangram/lib/pstotgif
X# Where GhostScript is found
XGHOSTSCRIPT=/usr/local/bin/gs
X
XUSAGE="pstotgif [-t] [-m magnification] psfiles"
XREDEF="/textastext false def"
XMAG=1
XFILES=""
Xwhile  [ x"$*" != x ]
Xdo
X	case $1 in
X	-t 	)
X		REDEF="/textastext true def"
X		shift
X		;;
X	-m	)
X		shift
X		MAG=$1
X		shift
X		;;
X	*	)
X		FILES="$FILES $1"
X		shift
X		;;
X	esac
Xdone
XTMPFILE=/tmp/pstotgif.$$
Xfor FILE in $FILES 
Xdo
X	FNAME=`basename $FILE`
X	{ /bin/cat - $LIB/pstotgif.pro $FILE << EOF ; } |\
X	$GHOSTSCRIPT -dNODISPLAY -q -  |\
X	$LIB/maketgif $MAG > $TMPFILE; \
X	PAGENR=`egrep "^%pstotgif: PAGENR" $TMPFILE | awk '{ print $3 }'` ;\
X	sed -e "s/PSTOTGIFPAGENR/$PAGENR/" $TMPFILE > $FNAME.obj ;\
X	rm -f $TMPFILE ;
X%!
X$REDEF
XEOF
X	echo Tgif file written to $FNAME.obj
Xdone
END_OF_FILE
if test 1518 -ne `wc -c <'pstotgif'`; then
    echo shar: \"'pstotgif'\" unpacked with wrong size!
fi
chmod +x 'pstotgif'
# end of 'pstotgif'
fi
if test -f 'pstotgif.pro' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pstotgif.pro'\"
else
echo shar: Extracting \"'pstotgif.pro'\" \(3016 characters\)
sed "s/^X//" >'pstotgif.pro' <<'END_OF_FILE'
X%%Title: pstotgif.pro, Version 1.3, September 1993
X% Copyright (C) 1993, Wolfgang Glunz, Siemens AG, glunz@ztivax.zfe.siemens.de
X%
X% Permission to use and modify this software and its 
X% documentation for any purpose is hereby granted without fee
X% provided, however, that the above copyright notice appear in all 
X% copies, that both that copyright notice and this permission notice 
X% appear in supporting documentation. The author makes no representations 
X% about the suitability of this software for any purpose. It is 
X% provided ``as is'' without express or implied warranty. 
X% 
X% This file contains some redefinitions of PostScript operators
X% useful for the conversion of PostScript into a vector format via Ghostscript
X%
X%%History:
X%
X% 07.09.93 : added widthshow, kshow, awidthshow, showpage
X% 28.05.93 : calculate effective line with in setlinewidth
X% 22.04.93 : added ashow
X% 20.04.93 : fixed a problem in stroke, fill, eofill (use {..} instead of /-... )
X%
X% 19.04.93 : Version 1.0 released to comp.sources.postscript
X%
X/-fill   /fill load def
X/-eofill /eofill load def
X/-stroke /stroke load def
X/-show   /show load def
X/-setlinewidth /setlinewidth load def
X/-showpage /showpage load def
X/s100 100 string def
X
X
X/printTOS {
X    ( ) print s100 cvs print 
X} def
X
X/prpoints {
X    -1 1 { pop        % the loop control variable
X	   transform  % transform to device coordinates
X	   exch
X	   printTOS   % the x value
X	   printTOS   % the y value
X	 } for
X} def
X
X/getcurrentscale { 
X% returns current scale on stack
X	100 0 transform  % x1' y1'
X	pop % x1'
X	  0 0 transform % x1' x2' y2'
X	pop % x1' x2'
X	sub 100 div abs
X%	dup ( scale is ) print == (\n) print
X} def
X
X/print-path {
X    { 1 prpoints ( moveto\n)    print }
X    { 1 prpoints ( lineto\n)    print }
X    { 3 prpoints ( curveto\n)   print }
X    {            ( closepath\n) print }
X    pathforall
X} def
X
X/dumppath {
X	/dumpstring exch def
X	/dumpop exch def
X	(\n) print
X	gsave
X	{
X		flattenpath % replaces curves by lines
X	} stopped {
X		grestore
X		gsave
X	} if
X	(newpath \n) print
X	print-path
X	dumpstring print ( \n) print
X	grestore
X	dumpop
X} def
X
X/eofill	{
X	{-eofill} (eofill) dumppath
X	} def
X
X/fill  	{
X	{-fill} (fill) dumppath
X	} def
X
X/stroke	{
X	{-stroke} (stroke) dumppath
X	} def
X
X/show {
X	/currentstring exch def
X	gsave
X	textastext
X	{
X		currentpoint 1 prpoints ( moveto\n)    print
X		(\() print
X		currentstring print 
X		(\) show\n) print
X	}
X	{
X		currentpoint
X		/currenty exch def
X		/currentx exch def
X		stroke % dump current path and start new path
X
X		currentx currenty moveto
X		currentstring
X		true charpath 
X		stroke 
X	}
X	ifelse
X	grestore
X	currentstring
X	-show
X} def
X
X/widthshow  {exch pop exch pop exch pop show} def
X/awidthshow {exch pop exch pop exch pop exch pop exch pop show} def
X/kshow      {exch pop show} def
X/ashow      {exch pop exch pop show} def
X
X/setlinewidth {  dup % for -setlinewidth
X	gsave
X	getcurrentscale mul
X	printTOS
X	( setlinewidth \n) print
X	grestore
X	-setlinewidth
X} def
X
X/showpage {
X    (showpage \n) print
X    -showpage
X} def
END_OF_FILE
if test 3016 -ne `wc -c <'pstotgif.pro'`; then
    echo shar: \"'pstotgif.pro'\" unpacked with wrong size!
fi
# end of 'pstotgif.pro'
fi
echo shar: End of shell archive.
exit 0
