v04i073: xpic -- pic previewer for X11, Part08/15

Dan Heller argv at island.uu.net
Sat Jul 22 17:40:46 AEST 1989


Submitted-by: Mark Moraes <moraes at ai.toronto.edu>
Posting-number: Volume 4, Issue 73
Archive-name: xpic/part08



#! /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 archive 8 (of 15)."
# Contents:  xpic/doc/tex/xpic.tex xpic/null.c xpic/test/triple.x
#   xpic/x2pic.c
# Wrapped by moraes at neat.ai on Thu Jul 13 22:36:09 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xpic/doc/tex/xpic.tex' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpic/doc/tex/xpic.tex'\"
else
echo shar: Extracting \"'xpic/doc/tex/xpic.tex'\" \(10668 characters\)
sed "s/^X//" >'xpic/doc/tex/xpic.tex' <<'END_OF_FILE'
X% Document type: LaTeX
X%
X% $Header: xpic.tex,v 1.2 88/11/04 23:01:46 moraes Exp $
X%
X%  Copyright 1988, Mark Moraes
X%  May be freely used for non-commercial purposes provided acknowledgement
X%  to the source is given.
X%
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X% Specifies the document style.
X\documentstyle[twoside,fullpage,notes]{article}
X
X\def\Ps{Post\-Script}
X\newcommand{\postscript}{Post\-Script\ }
X\newcommand{\psfigtex}{Psfig/\TeX\ }
X\newcommand{\tex}{\TeX\ }
X\newcommand{\nodeeqn}{$ {\displaystyle y = f \left( \sum_{i=1}^{n-1}
Xw_{i} x_{i} - \theta \right)} $}
X
X% From the TeXbook, Appendix E, pg 419
X\def\dbend{{\manual\char127}} % "dangerous bend" sign
X\def\d at nger{\medbreak\begingroup\clubpenalty=10000
X  \def\par{\endgraf\endgroup\mdebreak} \noindent\hang\hangafter=-1
X  \hbox to0pt{\hskip-\hangindent\dbend\hfill}\ninepoint}
X\outer\def\danger{\d at nger}
X
X\input{psfig}
X\title{Including {\tt xpic} figures in \LaTeX}
X\author{Mark Moraes\\
Xmoraes at csri.toronto.edu}
X\date{November 5, 1988}    % Deleting this command produces today's date.
X
X\begin{document}           % End of preamble and beginning of text.
X\maketitle                 % Produces the title.
X
X\section{Introduction}
X
X{\tt Xpic} is a program for drawing figures under {\em the X Window
Xsystem}. It produces a file in a special format. Various programs
Xexist to translate from this format to formats which may be included
Xin \tex documents to eliminate the pains of manual paste-up.
XThis document describes two ways to do just that.
X\begin{figure}[h]
X\centerline{\psfig{figure=texwarning.ps,height=1.5in}}
X\caption{A simple example. Don't take the warning seriously!}
X\label{fig:texwarning}
X\end{figure}
X\section{\psfigtex} The first method is to convert the {\tt xpic}
Xfigure to \postscript and include the \postscript in the document.
XThe conversion is done with the {\tt x2ps} program, which can be run
Xas follows
X\begin{quote}
X\tt
Xx2ps file.x > file.ps
X\end{quote}
Xwhere {\tt file.x} is the {\tt xpic} figure and {\tt file.ps} is the
Xresulting \postscript figure.
X
X\psfigtex is a macro package for \tex that facilitates the inclusion of
Xarbitrary \postscript figures into \tex documents. Figures are
Xautomatically scaled and positioned on the page, and the proper amount
Xof space is reserved. The only restriction is that the \postscript
Xfigures must be {\em well behaved} and
Xmust adhere to the bounding box comment convention.\footnote[1]{
XSee `Appendix J: \Ps\ File Structuring Conventions' in
X{\it The \Ps\ Language Reference Manual}}
X{\tt xpic} follows
Xthis convention, so inclusion of such figures in \psfigtex is easy.
X
XTo include a \Ps\ figure with {\tt psfig}, first load the {\tt psfig}
Xmacros at the beginning of your document with
X\begin{quote}
X{\tt\verb+\input{psfig}+}
X\end{quote}
X\postscript files may then be included in the document using the commands
X\begin{quote}
X\tt
X{\tt\verb+\+psfig\{figure={\it file.ps}\}}
X\end{quote}
XPsfig will automatically position the figure at the current point on the page, 
Xand reserve the proper amount of space in \TeX\ so that it doesn't conflict
Xwith any other objects on the page.
X
XFor example, we included the {\tt xpic} figure in the file {\tt
Xtexwarning.x} as figure \ref{fig:texwarning} by first converting it to the
X\postscript file {\tt texwarning.ps} using the {\tt x2ps} command as
Xfollows ---
X\begin{quote}
X\begin{verbatim}
Xx2ps texwarning.x > texwarning.ps
X\end{verbatim}
X\end{quote}
XWe could then use the commands
X\begin{quote}
X\tt
X\begin{verbatim}
X\begin{figure}[h]
X\centerline{\psfig{figure=texwarning.ps}}
X\caption{A simple example. Don't take the warning seriously!}
X\label{fig:texwarning}
X\end{figure}
X\end{verbatim}
X\end{quote} 
Xto include it as a centered paragraph.  Since no mention
Xof size was made in the above example, \psfigtex draws the figure at
Xits natural size (as if it was printed directly on a \Ps\ printer.) The
Xfigure's natural size is several inches high, which is a little large;
XFigure \ref{fig:texwarning} in the introduction was produced with the actual
X{\tt psfig} invocation changed to:
X\begin{quote}
X\tt\verb+\+centerline\{\verb+\+psfig\{figure=texwarning.ps,height=1.5in\}\}
X\end{quote} 
XThe {\tt height} option specifies how tall the figure
Xshould be on the page. Since no {\tt width} was specified, the figure
Xwas scaled equally in both dimensions. By listing both a {\tt height}
Xand a {\tt width}, figures can be scaled disproportionately, with
Xinteresting results.  For example:
X
X\begin{figure}[h]
X\centerline{\hbox{
X\psfig{figure=funstuff.ps,height=.8in,width=.15in}
X\psfig{figure=funstuff.ps,height=.8in,width=.35in}
X\psfig{figure=funstuff.ps,height=.8in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.2in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.5in}
X}}
X\caption{Abstract art. Untitled}
X\label{fig:funstuff}
X\end{figure}
X
Xwas produced with:
X
X\begin{quote}
X\tt
X\begin{verbatim}
X\begin{figure}[h]
X\centerline{\hbox{
X\psfig{figure=funstuff.ps,height=.8in,width=.15in}
X\psfig{figure=funstuff.ps,height=.8in,width=.35in}
X\psfig{figure=funstuff.ps,height=.8in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.2in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.5in}
X}}
X\caption{Abstract art. Untitled}
X\label{fig:funstuff}
X\end{figure}
X\end{verbatim}
X\end{quote}
X
X\section{\tt Tpic}
X
XEven though \psfigtex is a powerful and easy-to-use method of
Xincluding \postscript figures in a document, it has two drawbacks. The
Xfirst is that all output devices used for \tex do not have
X\Ps. The other problem is that strings put in a
X\postscript figure are not processed by \TeX, so if you want to put
Xequations in, you have to overlay them on top of the picture.
X(You can measure distances with a ruler and use the {\tt\verb+\picture+} 
Xenvironment to do this, using {\tt \verb+\put+} commands to place the 
Xequations.)
X
XA way of getting around this is to use a picture drawing preprocessor that
Xpasses the text through \TeX. One such preprocessor is {\tt tpic}.\footnote{
X{\tt Tpic} is a port of {\tt troff} 's {\tt pic} preprocessor.}
X
XTo convert {\tt xpic} output to {\tt tpic} format, use the {\tt x2tpic}
Xcommand, then run {\tt tpic} to convert this to \TeX. You can then include
Xthis \tex file produced in a document. For instance we include the
Xfigure
X{\tt node.x}, with the following commands:\footnote{
XThe command {\tt x2tex} does the same thing as running the following two
Xcommands. It is sometimes more flexible to use the two commands separately.}
X\begin{quote}
X\tt
Xx2tpic node.x > node.pic \\
Xtpic node.pic 
X\end{quote}
XWe now have a file called {\tt node.tex} with a picture called
X{\tt\verb+\graph+} in it --- the following \LaTeX\
Xcommands are used to include it:
X\begin{quote}
X\tt
X\begin{verbatim}
X\begin{figure} [h]
X\input{node}		% This reads in the picture definition
X\centerline{\box\graph}		% This positions the picture and draws it
X\caption{Computational element or node which forms a weighting 
Xsum of $ n $ inputs}
X\label{fig:node}
X\end{figure}
X\end{verbatim}
X\end{quote}
XThis produces the picture in figure \ref{fig:node}.
X\begin{figure} [h]
X\input{node}
X\centerline{\box\graph}
X\caption{Computational element or node which forms a weighting 
Xsum of $ n $ inputs}
X\label{fig:node}
X\end{figure}
XThe figure is little large, so we generate a smaller version asking
X{\tt x2tpic} to scale it down for us with:
X\begin{quote}
X\tt
Xx2tpic -s 0.6 node.x > shrunknode.pic \\
Xtpic shrunknode.pic 
X\end{quote}
Xand include it as figure \ref{fig:shrunknode}.
X\begin{figure}[h]
X\input{shrunknode}
X\centerline{\box\graph}
X\caption{Computational element or node which forms a weighting 
Xsum of $ n $ inputs}
X\label{fig:shrunknode}
X\end{figure}
X\par
X{\small {\em Hint} --- The text for the equation
Xin the box above is 
X\begin{verbatim}
X$ {\displaystyle y = f \left( \sum_{i=1}^{n-1} w_{i} x_{i} - \theta \right)} $
X\end{verbatim}
Xwhich is quite long, and appears literally in the {\tt xpic} figure
Xsince {\tt xpic} does not process equations on the screen.  This looks
Xslightly messy onscreen and overflows the edges of the picture --- a
Xbetter way to do it is to define a command to generate the equation,
Xand use that in the figure. Then in the document, you could say
Xsomething like
X\begin{verbatim}
X\newcommand{\nodeeqn}{ $ {\displaystyle y = f \left( \sum_{i=1}^{n-1} 
Xw_{i} x_{i} - \theta \right)} $ }
X\end{verbatim}
Xand put \verb+\+nodeeqn in the picture instead of the long equation.}
X\par
X{\small {\em Hint} --- {\tt xpic}'s text alignment options are
Ximportant if you want to get good results. For instance, in the figure
Xabove, most text, including the equation in the box uses the default {\tt
XCentered, Middle} attributes, which mean that the single {\em control
Xpoint} whose location is guaranteed is the centre of the text. For the
Xlabels $ x_{0}, x_{1}, x_{n-1} $ along the left edge, we use the {\tt
XRight Justified, Middle} attributes so that we ensure that they are all
Xaligned along the same right edge. Remember that {\tt xpic} screen
Xfonts are only approximations of the actual fonts used by \TeX, and
Xaren't too accurate.}
X\section{Further Reading}
XFor more information on \psfigtex --- see the {\em
X\psfigtex 1.2 Users Guide} by Trevor Darrell ({\em
Xtrevor at grasp.cis.upenn.edu}). Some of
Xthe examples used in this note are based on that document.
X
X{\tt Pic} is a powerful language for describing pictures --- {\tt xpic}
Xuses only a small subset. For more information on the {\tt pic}language, see {\em PIC --- A Graphics Language for Typesetting} by
XBrian W. Kernighan. {\tt Pic} is really a preprocessor for the {\tt
Xtroff} typesetting program, but the language is quite independent of
Xthe underlying typesetter. A few differences are listed in the {\tt
Xtpic} manual page.
X
X{\tt Xpic, x2ps} and {\tt x2tpic} are described in {\em Using xpic} by
XMark Moraes. {\em moraes at csri.toronto.edu}. These programs also have
Xmanual pages.
X
X\section{Availability}
X\psfigtex is available by anonymous ftp from {\em linc.cis.upenn.edu}
X(Internet host number 128.91.2.8), in the tar file
X{\tt ~ftp/dist/psfig/tex.tar.Z}. There exists a corresponding {\tt troff}
Xversion.
X
X{\tt Pic} is part of the {\em Documenter's Workbench} sold by AT\&T
X(and many vendors of Unix.\footnote{Unix is a trademark of AT\&T}). It
Xis also supplied with research editions of Unix. (eg) Eighth Edition.
X
X{\tt Tpic} is a port of {\tt pic}. Therefore, you need a Unix source
Xlicense to get it. Contact Tim Morgan {\em morgan at rome.ics.uci.edu}
Xfor more details.
X
X{\tt Xpic, x2ps} and {\tt x2pic} are part of the user-contributed
Xsoftware for the X Windows System Version 11 Release 3.  This document
Xis part of the source.
X
X\end{document}             % End of document.
END_OF_FILE
if test 10668 -ne `wc -c <'xpic/doc/tex/xpic.tex'`; then
    echo shar: \"'xpic/doc/tex/xpic.tex'\" unpacked with wrong size!
fi
# end of 'xpic/doc/tex/xpic.tex'
fi
if test -f 'xpic/null.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpic/null.c'\"
else
echo shar: Extracting \"'xpic/null.c'\" \(12179 characters\)
sed "s/^X//" >'xpic/null.c' <<'END_OF_FILE'
X/* $Header: null.c,v 1.4 89/02/23 02:48:22 xwindows Exp $ */
X#include <values.h>
X
X#include "xpic.h"
X#include "gels.h"
X#include "assert.h"
X#include "newfonts.h"
X
X/*
X *  Removes all gels from 'gel' that are strictly within the limits
X *  defined by xmin, ymin and xmax, ymax.
X */
XGel *FindContainedGels(gel, xmin, ymin, xmax, ymax)
XGel **gel;
X{
X	register Gel *g;
X	register Gel *tmp;
X	Gel *contained = NULL;
X	Gel *others = NULL;
X	Box clip;
X
X	if (!gel || !*gel)
X		return ((Gel *) NULL);
X	clip.ll.x = xmin;
X	clip.ll.y = ymin;
X	clip.ur.x = xmax;
X	clip.ur.y = ymax;
X	for (g = *gel; g != NULL; g = tmp) {
X		tmp = g->next;
X		if (within(&g->b_box, &clip)) {
X			g->next = contained;
X			contained = g;
X		} else {
X			g->next = others;
X			others = g;
X		}
X	}
X	*gel = others;
X	return(contained);
X}
X
X/* 
X *  Removes all gels from 'gel' that intersect the box defined by xmin,
X *  ymin and xmax, ymax.
X */
XGel *FindIntersectingGels(gel, xmin, ymin, xmax, ymax)
XGel **gel;
X{
X	register Gel *g;
X	register Gel *tmp;
X	Gel *intersecting = NULL;
X	Gel *others = NULL;
X	Box clip;
X
X	if (!gel || !*gel)
X		return ((Gel *) NULL);
X	clip.ll.x = xmin;
X	clip.ll.y = ymin;
X	clip.ur.x = xmax;
X	clip.ur.y = ymax;
X	for (g = *gel; g != NULL; g = tmp) {
X		tmp = g->next;
X		if (intersects(&g->b_box, &clip)) {
X			g->next = intersecting;
X			intersecting = g;
X		} else {
X			g->next = others;
X			others = g;
X		}
X	}
X	*gel = others;
X	return(intersecting);
X}
X
X
X
X/************MAKE SURE THESE UPDATE THE BBOX***************/
X/*
X *  Move those points in the gel list that are in the box 'clip' by (dx, dy)
X */
Xvoid AdjustGel(g, clip, dx, dy)
XGel *g;
XBox *clip;
Xint dx, dy;
X{
X	register XPoint *v;
X	register int i;
X	Conic *conic;
X	PointList *ptlist;
X	TextString *text;
X
X	for (; g != NULL; g = g->next) {
X		switch (g->type) {
X		case BOX:
X			g->b_box.ll.x += dx;
X			g->b_box.ll.y += dy;
X			g->b_box.ur.x += dx;
X			g->b_box.ur.y += dy;
X			break;
X		case CIRCLE:
X		case ELLIPSE:
X			conic = (Conic *)g->data;
X			if (contains(&conic->centre, clip)) {
X				conic->centre.x += dx;
X				conic->centre.y += dy;
X				g->b_box.ll.x += dx;
X				g->b_box.ll.y += dy;
X				g->b_box.ur.x += dx;
X				g->b_box.ur.y += dy;
X			}
X			break;
X		case LINE:
X		case SPLINE:
X			ptlist = (PointList *)g->data;
X			for(i = ptlist->nVerts, v = ptlist->v; i > 0; i--, v++) {
X				if (containsXY((int) v->x, (int) v->y, clip)) {
X					v->x += dx;
X					v->y += dy;
X				}
X			}
X			CalcBBox(g, 1);
X			break;
X		case TEXT:
X			text = (TextString *)g->data;
X			if (containsXY((int) text->x, (int) text->y, clip)) {
X				text->x += dx;
X				text->y += dy;
X				g->b_box.ll.x += dx;
X				g->b_box.ll.y += dy;
X				g->b_box.ur.x += dx;
X				g->b_box.ur.y += dy;
X			}
X			break;
X		default:
X			break;
X		}
X	}
X}
X
X
X/* Move all the gels in the gellist g by dx, dy */
Xvoid MoveGel(g, dx, dy)
XGel *g;
Xint dx, dy;
X{
X	register XPoint *v;
X	register int i;
X	Conic *conic;
X	PointList *ptlist;
X	TextString *text;
X
X	for(; g != NULL; g = g->next) {
X		g->b_box.ll.x += dx;
X		g->b_box.ll.y += dy;
X		g->b_box.ur.x += dx;
X		g->b_box.ur.y += dy;
X		switch (g->type) {
X		case BOX:
X			break;
X		case CIRCLE:
X		case ELLIPSE:
X			conic = (Conic *)g->data;
X			conic->centre.x += dx;
X			conic->centre.y += dy;
X			break;
X		case LINE:
X		case SPLINE:
X			ptlist = (PointList *)g->data;
X			for(i = ptlist->nVerts, v = ptlist->v; i > 0; i--, v++) {
X				v->x += dx;
X				v->y += dy;
X			}
X			break;
X		case TEXT:
X			text = (TextString *)g->data;
X			text->x += dx;
X			text->y += dy;
X			break;
X		default:
X			break;
X		}
X	}
X}
X
X/* Makes a copy of the first N gels in g and returns a pointer to them */
XGel *CopyGel(g, n)
XGel *g;
Xint n;
X{
X	Gel *newgel = NULL;
X	char *s;
X	PointList *ptlistdata;
X	char *malloc();
X	int x1, x2, y1, y2;
X	Conic *conic;
X	PointList *ptlist;
X	TextString *text;
X
X	for(;(g != NULL) && n--; g = g->next) {
X		x1 = g->b_box.ll.x;
X		y1 = g->b_box.ll.y;
X		x2 = g->b_box.ur.x;;
X		y2 = g->b_box.ur.y;
X		switch (g->type) {
X		case BOX:
X			AddBoxGel(&newgel, x1, y1, x2, y2, g->attributes, g->linewidth);
X			break;
X		case CIRCLE:
X		case ELLIPSE:
X			conic = (Conic *)g->data;
X			AddConicGel(&newgel, g->type, conic->centre.x, conic->centre.y,
X			 conic->xrad, conic->yrad, g->attributes, x1, y1, x2, y2, 
X			 g->linewidth);
X			break;
X		case LINE:
X		case SPLINE:
X			ptlist = (PointList *)g->data;
X			if ((ptlistdata = (PointList *) 
X			 NewPtList(ptlist->v, ptlist->nVerts)) == NULL) {
X			 	message("Can't make new point list in copy");
X				FreeGel(newgel);
X				return((Gel *) NULL);
X			}
X			AddLineGel(&newgel, g->type, ptlistdata, g->attributes, x1, y1,
X			 x2, y2, g->linewidth);
X			break;
X		case TEXT:
X			text = (TextString *)g->data;
X			if ((s = malloc((unsigned) (text->length + 1))) == NULL) {
X				message("Can't make a new string in copy");
X				FreeGel(newgel);
X				return((Gel *) NULL);
X			}
X			bcopy(text->str, s, text->length);
X			s[text->length] = '\0';
X			AddTextGel(&newgel, s, text->length, text->font, 
X			 text->sizeindex, text->fontname, text->fontsize, 
X			 g->attributes, text->x, text->y, x1, y1, x2, y2);
X			break;
X		default:
X			break;
X		}
X	}
X	return (newgel);
X}
X
X
X
X/*
X *  Finds the closest gel to the point mx, my.  Closeness is measured
X *  from the centre of the Gel bounding box. The gels flags are marked
X *  to indicate selection
X */
XGel *SelectGel(gel, mx, my)
XGel *gel;
X{
X	Gel *closest = NULL;
X	register Gel *g;
X	int min_distance = MAXINT;
X	int dist;
X	
X	if (!gel) {
X		message("Nothing to select!");
X		return(NULL);
X	}
Xagain:
X	for(g = gel;g != NULL; g = g->next) {
X		if (g->int_flags & SELECTED)
X			continue;
X		switch (g->type) {
X		case TEXT:
X		case BOX:
X			dist = box_distance(g, mx, my);
X			break;
X		case ELLIPSE:
X			dist = ellipse_distance(g, mx, my);
X			break;
X		case CIRCLE:
X			dist = circle_distance(g, mx, my);
X			break;
X		case LINE:
X		case SPLINE:
X			dist = line_distance(g, mx, my);
X			break;
X		}
X		if (dist < min_distance) {
X			min_distance = dist;
X			closest = g;
X		}
X	}
X	if (closest)
X		closest->int_flags |= SELECTED;
X	else {
X		ClearGelFlags(gel);
X		message("Looping around again");
X		goto again;
X	}
X#ifdef DEBUG
X	printf("closest distance = %d\n", min_distance);
X	PrintGel(closest, 1);
X#endif
X	return(closest);
X}
X
X
X/*
X *  Removes the gel g2 from the list g1 and returns. g2 must be a gel in
X *  g1
X */
XGel *RemoveGel(g1, g2)
XGel **g1;
XGel *g2;
X{
X	register Gel *g;
X	Gel *gtmp;
X	
X	ASSERT (g1 && *g1 && g2, "RemoveGel null")
X	if (*g1 == g2) {
X		g = *g1;
X		*g1 = g->next;
X		g->next = NULL;
X		return(g);
X	}
X	for(g = *g1; g->next != NULL; g = g->next) {
X		if (g->next == g2) {
X			gtmp = g->next;
X			g->next = (g->next)->next;
X			gtmp->next = NULL;;
X			return(gtmp);
X		}
X	}
X	/* Shouldn't ever reach here */
X	ASSERT(0, "RemoveGel not found");
X	/* NOTREACHED */
X}
X
X
X/* Changes the attributes of a Gel to the ones passed as arguments */
XChangeAttrib(gel, lineattr, arrowattr, linewidth, fillattr, 
X	textattr, textfont, textsize)
XFontFamily *textfont;
XGel *gel;
X{
X	TextString *text;
X	
X	for(;gel != NULL; gel = gel->next) {
X		gel->attributes = 0;
X		gel->linewidth = linewidth;
X		switch(gel->type) {
X		case BOX:
X			gel->attributes = lineattr | fillattr;
X			break;
X		case ELLIPSE:
X		case CIRCLE:
X			gel->attributes = lineattr | fillattr;
X			break;
X		case TEXT:
X			gel->attributes = textattr;
X			text = (TextString *) gel->data;
X			text->font = textfont;
X			text->sizeindex = textfont->cursize;
X			text->fontname = textfont->name;
X			text->fontsize = textsize;
X			CalcBBox(gel, 1);
X			break;
X		case LINE:
X		case SPLINE:
X			gel->attributes = lineattr | arrowattr;
X			break;
X		default:
X#ifdef DEBUG
X			(void) sprintf(errstring, "Unknown gel type in Change Attribute");
X			message(errstring);
X#endif
X			break;
X		}
X	}
X}
X
X
X/*
X *  This recalculates the bounding boxes of the first 'n' gels in the
X *  'gel'. (or as many as there are, if there are less than n)
X */
XCalcBBox(g, n)
Xregister Gel *g;
X{
X	register int i;
X	register XPoint *vert;
X	int twidth, theight, dx, dy, pad;
X	XFontStruct *font;
X	Conic *conic;
X	TextString *text;
X	PointList *ptlist;
X	
X	for (; g != NULL && n--; g = g->next) {
X		switch (g->type) {
X		case BOX:
X			break;
X		case CIRCLE:
X		case ELLIPSE:
X			conic = (Conic *) g->data;
X			g->b_box.ll.x = conic->centre.x - conic->xrad;
X			g->b_box.ll.y = conic->centre.y - conic->yrad;
X			g->b_box.ur.x = conic->centre.x + conic->xrad;
X			g->b_box.ur.y = conic->centre.y + conic->yrad;
X			break;
X		case LINE:
X		case SPLINE:
X			ptlist = (PointList *) g->data;
X			g->b_box.ll.x = g->b_box.ll.y = MAXINT;
X			g->b_box.ur.x = g->b_box.ur.y = 0;
X			i = ptlist->nVerts;
X			vert = ptlist->v;
X			if (g->type == SPLINE) {
X				vert++;
X				i -= 2;
X			}
X			for (; i != 0; i--, vert++) {
X				update_box(g->b_box, vert->x, vert->y);
X			}
X			break;
X		case TEXT:
X			text = (TextString *) g->data;
X			/* Only need the font for calculation - so we don't setfont() */
X			font = ChangeFont(&text->font->sizes[text->sizeindex], &pad);
X			ComputeTextPosition(text->str, text->length, font, 
X			 &dx, &dy, &twidth, &theight, 
X			 g->attributes & HALIGN, g->attributes & VALIGN, pad);
X			g->b_box.ll.x = text->x + dx;
X			g->b_box.ur.x = g->b_box.ll.x + twidth;
X			g->b_box.ur.y = text->y + dy;
X			g->b_box.ll.y = g->b_box.ur.y - theight;
X			break;
X		default:
X			(void) sprintf(errstring, "Unknown gel type %d in CalcBBox",
X			 g->type);
X			message(errstring);
X			break;
X		}
X	}
X}
X			
X			
X#ifdef DEBUG
Xstatic char *geltypes[] = {"CELL", "LINE", "SPLINE", "BOX", "CIRCLE",
X	"ELLIPSE", "TEXT", "BLOCK", "ELEMENT" };
Xstatic char *linestyles[] = {"SOLID", "DOTTED", "SDASH", "LDASH", "DDASH"};
Xstatic char *arrowstyles[] = {"NO_ARROW", "ST_ARROW", "EN_ARROW", "BOTH"};
Xstatic char *texthalign[] = {"CENTRE", "LJUST", "RJUST"};
Xstatic char *textvalign[] = {"MID", "TOP", "BOT"};
Xstatic char *flags[] = {"NOTHING", "SELECTED", "HILITED", "SELECTED, HILITED"};
X
XPrintCell(cell)
XCell *cell;
X{
X	printf("*********************************************************\n");
X	printf("Cell \"%s\", file \"%s\"\n", cell->name? cell->name: "(null)",
X	 cell->filename? cell->filename: "(null)");
X	printf("Last modified filetime is %ld, cell is %smodified\n", 
X	 cell->mtime, cell->saved? "" : "not ");
X	printf("Cell Gel list is : \n");
X	PrintGel(cell->gelList, MAXINT);
X	printf("-----------------------------------------------------------\n");
X	printf("\n\nNumber of elements to pop in an undo is %d\n", cell->undo);
X	printf("Undo list to push:\n");
X	PrintGel(cell->undoList, MAXINT);
X	printf("-----------------------------------------------------------\n");
X}
X	
X	
XPrintGel(g, n)
XGel *g;
X{
X	printf("=========================================================");
X	for (; g && n--; g = g->next) {
X		printf("\n%d width=%d %8s ", g->number, g->linewidth, geltypes[g->type]);
X		printf("%8s ", linestyles[getlinestyle(g->attributes)]);
X		printf("%8s ", arrowstyles[getlinearrow(g->attributes)]);
X		printf("%8s ", texthalign[gettext_halign(g->attributes)]);
X		printf("%8s ", textvalign[gettext_valign(g->attributes)]);
X		printf("%s\n", flags[g->int_flags]);
X		PrintBox(&g->b_box);
X		switch(g->type) {
X		case BOX:
X			break;
X		case TEXT:
X			PrintText((TextString *) g->data);
X			break;
X		case CIRCLE:
X		case ELLIPSE:
X			PrintConic((Conic *) g->data);
X			break;
X		case LINE:
X		case SPLINE:
X			PrintPtlist((PointList *) g->data);
X			break;
X		default:
X			printf("\tI don't think I know this type\n");
X		}
X		printf("\tnext = 0x%x\n", g->next);
X	}
X}
X
XPrintPoint(p)
XPoint *p;
X{
X	printf("%d, %d", p->x, p->y);
X}
X
XPrintBox(b)
XBox *b;
X{
X	printf("\tll = ");
X	PrintPoint(&b->ll);
X	printf(", ur = ");
X	PrintPoint(&b->ur);
X	printf("\n");
X}
X
XPrintText(text)
XTextString *text;
X{
X	printf("\t%d, %d \"%s\", %d, %s,(%s) %d(%d)\n", text->x, text->y, 
X	 text->str, text->length, text->font? text->font->name : "No font", 
X	 text->fontname, text->font->sizes[text->sizeindex].pointsize, 
X	 text->fontsize);
X}
X
XPrintConic(conic)
XConic *conic;
X{
X	printf("\t");
X	PrintPoint(&conic->centre);
X	printf(" with radii %d, %d\n", conic->xrad, conic->yrad);
X}
X
XPrintXPoint(v, n)
XXPoint *v;
Xint n;
X{
X	int i, j;
X	
X	printf("\t");
X	j = 0;
X	for (i = 0; i < n; i++) {
X		printf("%d, %d   ",  (int) v[i].x, (int) v[i].y);
X		if (++j == 5) {
X			j = 0;
X			printf("\n\t");
X		}
X	}
X}
X
X
XPrintPtlist(pt)
XPointList *pt;
X{
X	printf("\tn = %d\n", pt->nVerts);
X	PrintXPoint(pt->v, pt->nVerts);
X}
X
X#endif DEBUG
X
END_OF_FILE
if test 12179 -ne `wc -c <'xpic/null.c'`; then
    echo shar: \"'xpic/null.c'\" unpacked with wrong size!
fi
# end of 'xpic/null.c'
fi
if test -f 'xpic/test/triple.x' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpic/test/triple.x'\"
else
echo shar: Extracting \"'xpic/test/triple.x'\" \(12226 characters\)
sed "s/^X//" >'xpic/test/triple.x' <<'END_OF_FILE'
X#! /local/bin/X11/xpic
X18 14 622 815 8
X2 1038 484 713 608 800 0 0
X4
X 484 800 535 768 576 738 608 713
X2 1036 415 670 608 800 0 0
X5
X 415 800 463 775 512 745 560 710
X 608 670
X2 1034 378 648 608 800 0 0
X6
X 378 800 432 775 480 745 528 714
X 565 685 608 648
X2 1032 334 626 608 801 0 0
X6
X 334 801 416 764 496 717 545 681
X 577 654 608 626
X2 1030 287 604 608 800 0 0
X10
X 287 800 320 790 368 770 409 749
X 449 728 484 705 513 686 560 648
X 593 618 608 604
X2 1028 39 483 607 760 0 0
X15
X 39 760 95 759 139 753 193 744
X 240 732 291 715 336 696 384 673
X 432 645 463 624 492 600 529 569
X 559 539 581 515 607 483
X2 1026 39 369 608 696 0 0
X20
X 39 696 88 695 128 691 160 685
X 193 679 239 666 274 653 305 641
X 336 626 369 607 398 589 432 566
X 457 547 478 529 511 496 533 474
X 553 448 577 416 599 384 608 369
X2 1024 40 335 608 680 0 0
X15
X 40 680 99 677 145 672 192 662
X 240 649 290 629 335 609 383 580
X 432 548 482 502 511 473 538 441
X 552 424 577 388 608 335
X2 1022 39 297 608 664 0 0
X18
X 39 664 87 662 139 656 200 643
X 252 628 280 616 323 596 368 571
X 401 549 431 527 462 500 492 470
X 516 444 537 417 559 386 579 354
X 592 330 608 297
X2 1020 40 206 608 632 0 0
X15
X 40 632 96 630 159 620 210 608
X 283 581 346 546 398 513 447 470
X 487 430 513 395 539 357 560 326
X 576 290 591 257 608 206
X2 1018 39 41 600 600 0 0
X22
X 39 600 81 598 128 592 176 584
X 209 574 241 563 273 549 313 529
X 344 510 372 491 409 461 443 430
X 485 380 511 342 531 309 550 272
X 563 240 579 192 588 158 595 112
X 599 72 600 41
X2 1016 40 39 584 584 0 0
X21
X 40 584 96 581 144 574 192 563
X 239 547 289 523 336 497 368 474
X 400 448 432 417 454 393 480 360
X 497 336 517 304 532 271 546 239
X 563 191 571 158 580 112 583 68
X 584 39
X2 1014 40 40 520 520 0 0
X20
X 40 520 96 516 144 509 192 496
X 232 480 272 460 304 441 336 419
X 367 391 391 368 416 339 440 305
X 460 272 476 240 489 208 500 176
X 508 144 514 112 518 81 520 40
X6 828 230 178 236 191 0 0
X233 188 1 Roman 10
X*
X2 1011 40 40 504 504 0 0
X20
X 40 504 96 501 144 493 184 481
X 225 466 260 450 288 432 321 410
X 349 386 372 364 397 337 415 312
X 440 277 459 240 472 208 484 176
X 492 144 501 96 503 69 504 40
X2 1009 40 40 456 456 0 0
X19
X 40 456 80 455 128 447 176 434
X 215 418 249 400 279 380 309 358
X 335 332 360 306 382 278 400 248
X 418 214 432 179 443 144 450 110
X 453 82 455 60 456 40
X2 1007 39 40 440 440 0 0
X18
X 39 440 80 439 112 433 145 426
X 189 412 221 397 250 381 288 354
X 317 328 341 304 365 273 386 240
X 403 209 417 176 426 143 434 112
X 438 80 440 40
X2 1005 39 40 360 360 0 0
X13
X 39 360 80 357 128 347 176 330
X 223 303 263 271 289 240 321 192
X 336 160 348 128 355 96 358 74
X 360 40
X2 1003 39 40 312 312 0 0
X12
X 39 312 80 309 128 297 176 277
X 208 254 240 225 266 191 284 161
X 297 128 307 96 311 64 312 40
X2 1001 39 40 279 280 0 0
X11
X 39 280 80 277 112 269 144 257
X 176 238 208 211 238 176 256 145
X 269 112 277 80 279 40
X2 999 40 40 248 248 0 0
X13
X 40 248 80 244 112 235 144 220
X 182 192 197 176 211 160 223 138
X 233 118 240 96 244 80 247 58
X 248 40
X2 997 40 41 199 200 0 0
X11
X 40 200 64 198 91 192 112 183
X 136 168 159 148 167 136 184 109
X 194 85 198 64 199 41
X2 995 39 41 120 119 0 0
X7
X 39 119 64 116 80 109 97 96
X 108 81 117 64 120 41
X6 697 261 802 267 815 0 0
X264 812 1 Roman 10
X*
X6 695 469 802 475 815 0 0
X472 812 1 Roman 10
X*
X6 700 565 738 571 751 0 0
X568 748 1 Roman 10
X*
X6 702 485 754 491 767 0 0
X488 764 1 Roman 10
X*
X6 698 421 754 427 767 0 0
X424 764 1 Roman 10
X*
X6 701 517 674 523 687 0 0
X520 684 1 Roman 10
X*
X6 696 181 674 187 687 0 0
X184 684 1 Roman 10
X*
X6 703 469 610 475 623 0 0
X472 620 1 Roman 10
X*
X6 699 277 610 283 623 0 0
X280 620 1 Roman 10
X*
X6 805 229 594 235 607 0 0
X232 604 1 Roman 10
X*
X6 822 421 546 427 559 0 0
X424 556 1 Roman 10
X*
X6 823 373 482 379 495 0 0
X376 492 1 Roman 10
X*
X6 810 293 514 299 527 0 0
X296 524 1 Roman 10
X*
X6 808 149 418 155 431 0 0
X152 428 1 Roman 10
X*
X6 815 197 418 203 431 0 0
X200 428 1 Roman 10
X*
X6 824 325 418 331 431 0 0
X328 428 1 Roman 10
X*
X6 818 549 418 555 431 0 0
X552 428 1 Roman 10
X*
X6 819 485 370 491 383 0 0
X488 380 1 Roman 10
X*
X6 807 357 370 363 383 0 0
X360 380 1 Roman 10
X*
X6 806 373 354 379 367 0 0
X376 364 1 Roman 10
X*
X6 825 277 354 283 367 0 0
X280 364 1 Roman 10
X*
X6 820 421 322 427 335 0 0
X424 332 1 Roman 10
X*
X6 821 357 274 363 287 0 0
X360 284 1 Roman 10
X*
X6 826 229 290 235 303 0 0
X232 300 1 Roman 10
X*
X6 812 165 274 171 287 0 0
X168 284 1 Roman 10
X*
X6 827 293 226 299 239 0 0
X296 236 1 Roman 10
X*
X6 829 181 226 187 239 0 0
X184 236 1 Roman 10
X*
X6 816 117 226 123 239 0 0
X120 236 1 Roman 10
X*
X6 811 517 290 523 303 0 0
X520 300 1 Roman 10
X*
X6 804 597 226 603 239 0 0
X600 236 1 Roman 10
X*
X6 814 421 194 427 207 0 0
X424 204 1 Roman 10
X*
X6 809 421 146 427 159 0 0
X424 156 1 Roman 10
X*
X6 813 277 162 283 175 0 0
X280 172 1 Roman 10
X*
X6 817 229 114 235 127 0 0
X232 124 1 Roman 10
X*
X6 830 165 130 171 143 0 0
X168 140 1 Roman 10
X*
X6 831 133 162 139 175 0 0
X136 172 1 Roman 10
X*
X6 833 101 82 107 95 0 0
X104 92 1 Roman 10
X*
X6 832 85 98 91 111 0 0
X88 108 1 Roman 10
X*
X6 954 37 754 43 767 0 0
X40 764 1 Roman 10
X*
X6 953 37 786 43 799 0 0
X40 796 1 Roman 10
X*
X6 952 37 770 43 783 0 0
X40 780 1 Roman 10
X*
X6 951 37 738 43 751 0 0
X40 748 1 Roman 10
X*
X6 950 37 722 43 735 0 0
X40 732 1 Roman 10
X*
X6 949 37 706 43 719 0 0
X40 716 1 Roman 10
X*
X6 948 37 690 43 703 0 0
X40 700 1 Roman 10
X*
X6 947 37 674 43 687 0 0
X40 684 1 Roman 10
X*
X6 946 37 658 43 671 0 0
X40 668 1 Roman 10
X*
X6 945 37 642 43 655 0 0
X40 652 1 Roman 10
X*
X6 944 37 626 43 639 0 0
X40 636 1 Roman 10
X*
X6 943 37 610 43 623 0 0
X40 620 1 Roman 10
X*
X6 723 37 594 43 607 0 0
X40 604 1 Roman 10
X*
X6 724 37 578 43 591 0 0
X40 588 1 Roman 10
X*
X6 725 37 562 43 575 0 0
X40 572 1 Roman 10
X*
X6 726 37 546 43 559 0 0
X40 556 1 Roman 10
X*
X6 727 37 530 43 543 0 0
X40 540 1 Roman 10
X*
X6 728 37 514 43 527 0 0
X40 524 1 Roman 10
X*
X6 729 37 498 43 511 0 0
X40 508 1 Roman 10
X*
X6 730 37 482 43 495 0 0
X40 492 1 Roman 10
X*
X6 731 37 466 43 479 0 0
X40 476 1 Roman 10
X*
X6 732 37 450 43 463 0 0
X40 460 1 Roman 10
X*
X6 733 37 434 43 447 0 0
X40 444 1 Roman 10
X*
X6 734 37 418 43 431 0 0
X40 428 1 Roman 10
X*
X6 735 37 402 43 415 0 0
X40 412 1 Roman 10
X*
X6 736 37 386 43 399 0 0
X40 396 1 Roman 10
X*
X6 737 37 370 43 383 0 0
X40 380 1 Roman 10
X*
X6 738 37 354 43 367 0 0
X40 364 1 Roman 10
X*
X1 858 32 32 608 608 0 0
X73
X 48 32 48 608 80 608 80 32
X 112 32 112 608 144 608 144 32
X 176 32 176 608 208 608 208 32
X 240 32 240 608 272 608 272 32
X 304 32 304 608 336 608 336 32
X 368 32 368 608 400 608 400 32
X 432 32 432 608 464 608 464 32
X 496 32 496 608 528 608 528 32
X 560 32 560 608 592 608 592 32
X 608 32 608 48 32 48 32 80
X 608 80 608 112 32 112 32 144
X 608 144 608 176 32 176 32 208
X 608 208 608 240 32 240 32 272
X 608 272 608 304 32 304 32 336
X 608 336 608 368 32 368 32 400
X 608 400 608 432 32 432 32 464
X 608 464 608 496 32 496 32 528
X 608 528 608 560 32 560 32 592
X 608 592
X6 739 37 338 43 351 0 0
X40 348 1 Roman 10
X*
X6 722 37 322 43 335 0 0
X40 332 1 Roman 10
X*
X6 721 37 306 43 319 0 0
X40 316 1 Roman 10
X*
X6 740 37 290 43 303 0 0
X40 300 1 Roman 10
X*
X6 741 37 274 43 287 0 0
X40 284 1 Roman 10
X*
X6 742 37 258 43 271 0 0
X40 268 1 Roman 10
X*
X6 743 37 242 43 255 0 0
X40 252 1 Roman 10
X*
X6 744 37 226 43 239 0 0
X40 236 1 Roman 10
X*
X6 745 37 210 43 223 0 0
X40 220 1 Roman 10
X*
X6 746 37 194 43 207 0 0
X40 204 1 Roman 10
X*
X6 747 37 178 43 191 0 0
X40 188 1 Roman 10
X*
X6 720 37 162 43 175 0 0
X40 172 1 Roman 10
X*
X6 748 37 146 43 159 0 0
X40 156 1 Roman 10
X*
X6 719 37 130 43 143 0 0
X40 140 1 Roman 10
X*
X6 749 37 114 43 127 0 0
X40 124 1 Roman 10
X*
X6 750 37 98 43 111 0 0
X40 108 1 Roman 10
X*
X6 751 37 82 43 95 0 0
X40 92 1 Roman 10
X*
X1 859 32 32 608 608 0 0
X69
X 64 32 64 608 96 608 96 32
X 128 32 128 608 160 608 160 32
X 192 32 192 608 224 608 224 32
X 256 32 256 608 288 608 288 32
X 320 32 320 608 352 608 352 32
X 384 32 384 608 416 608 416 32
X 448 32 448 608 480 608 480 32
X 512 32 512 608 544 608 544 32
X 576 32 576 608 608 608 608 576
X 32 576 32 544 608 544 608 512
X 32 512 32 480 608 480 608 448
X 32 448 32 416 608 416 608 384
X 32 384 32 352 608 352 608 320
X 32 320 32 288 608 288 608 256
X 32 256 32 224 608 224 608 192
X 32 192 32 160 608 160 608 128
X 32 128 32 96 608 96 608 64
X 32 64
X6 752 37 66 43 79 0 0
X40 76 1 Roman 10
X*
X6 753 37 50 43 63 0 0
X40 60 1 Roman 10
X*
X6 757 597 34 603 47 0 0
X600 44 1 Roman 10
X*
X6 756 581 34 587 47 0 0
X584 44 1 Roman 10
X*
X6 758 565 34 571 47 0 0
X568 44 1 Roman 10
X*
X6 759 549 34 555 47 0 0
X552 44 1 Roman 10
X*
X6 760 533 34 539 47 0 0
X536 44 1 Roman 10
X*
X6 761 517 34 523 47 0 0
X520 44 1 Roman 10
X*
X6 762 501 34 507 47 0 0
X504 44 1 Roman 10
X*
X6 763 485 34 491 47 0 0
X488 44 1 Roman 10
X*
X6 764 469 34 475 47 0 0
X472 44 1 Roman 10
X*
X6 765 453 34 459 47 0 0
X456 44 1 Roman 10
X*
X6 766 437 34 443 47 0 0
X440 44 1 Roman 10
X*
X6 767 421 34 427 47 0 0
X424 44 1 Roman 10
X*
X6 768 405 34 411 47 0 0
X408 44 1 Roman 10
X*
X6 769 389 34 395 47 0 0
X392 44 1 Roman 10
X*
X6 770 373 34 379 47 0 0
X376 44 1 Roman 10
X*
X6 771 357 34 363 47 0 0
X360 44 1 Roman 10
X*
X6 772 341 34 347 47 0 0
X344 44 1 Roman 10
X*
X6 773 325 34 331 47 0 0
X328 44 1 Roman 10
X*
X6 774 309 34 315 47 0 0
X312 44 1 Roman 10
X*
X6 775 293 34 299 47 0 0
X296 44 1 Roman 10
X*
X6 755 277 34 283 47 0 0
X280 44 1 Roman 10
X*
X6 754 261 34 267 47 0 0
X264 44 1 Roman 10
X*
X6 776 245 34 251 47 0 0
X248 44 1 Roman 10
X*
X6 777 229 34 235 47 0 0
X232 44 1 Roman 10
X*
X6 778 213 34 219 47 0 0
X216 44 1 Roman 10
X*
X6 779 197 34 203 47 0 0
X200 44 1 Roman 10
X*
X6 780 181 34 187 47 0 0
X184 44 1 Roman 10
X*
X6 781 165 34 171 47 0 0
X168 44 1 Roman 10
X*
X6 782 149 34 155 47 0 0
X152 44 1 Roman 10
X*
X6 783 133 34 139 47 0 0
X136 44 1 Roman 10
X*
X6 784 117 34 123 47 0 0
X120 44 1 Roman 10
X*
X6 785 101 34 107 47 0 0
X104 44 1 Roman 10
X*
X6 786 85 34 91 47 0 0
X88 44 1 Roman 10
X*
X6 787 69 34 75 47 0 0
X72 44 1 Roman 10
X*
X6 788 53 34 59 47 0 0
X56 44 1 Roman 10
X*
X6 789 37 34 43 47 0 0
X40 44 1 Roman 10
X*
X3 860 32 32 608 608 0 0
X6 857 117 14 123 27 0 0
X120 24 1 Roman 10
X5
X6 856 37 14 43 27 0 0
X40 24 1 Roman 10
X0
X6 855 194 14 206 27 0 0
X200 24 2 Roman 10
X10
X6 854 274 14 286 27 0 0
X280 24 2 Roman 10
X15
X6 853 354 14 366 27 0 0
X360 24 2 Roman 10
X20
X6 852 434 14 446 27 0 0
X440 24 2 Roman 10
X25
X6 851 514 14 526 27 0 0
X520 24 2 Roman 10
X30
X6 850 594 14 606 27 0 0
X600 24 2 Roman 10
X35
X6 849 21 30 27 43 0 0
X24 40 1 Roman 10
X0
X6 848 21 110 27 123 0 0
X24 120 1 Roman 10
X5
X6 847 18 190 30 203 0 0
X24 200 2 Roman 10
X10
X6 846 18 270 30 283 0 0
X24 280 2 Roman 10
X15
X6 845 610 350 622 363 0 0
X616 360 2 Roman 10
X20
X6 844 18 430 30 443 0 0
X24 440 2 Roman 10
X25
X6 843 18 510 30 523 0 0
X24 520 2 Roman 10
X30
X6 842 18 590 30 603 0 0
X24 600 2 Roman 10
X35
X6 841 610 590 622 603 0 0
X616 600 2 Roman 10
X35
X6 840 610 510 622 523 0 0
X616 520 2 Roman 10
X30
X6 839 613 30 619 43 0 0
X616 40 1 Roman 10
X0
X6 838 613 110 619 123 0 0
X616 120 1 Roman 10
X5
X6 837 610 190 622 203 0 0
X616 200 2 Roman 10
X10
X6 836 610 270 622 283 0 0
X616 280 2 Roman 10
X15
X6 835 610 430 622 443 0 0
X616 440 2 Roman 10
X25
X6 834 18 350 30 363 0 0
X24 360 2 Roman 10
X20
X3 718 32 608 608 800 0 0
X1 717 32 624 608 784 0 0
X22
X 32 624 608 624 608 640 32 640
X 32 656 608 656 608 672 32 672
X 32 688 608 688 608 704 32 704
X 32 720 608 720 608 736 32 736
X 32 752 608 752 608 768 32 768
X 32 784 608 784
X6 716 610 670 622 683 0 0
X616 680 2 Roman 10
X40
X6 715 18 750 30 763 0 0
X24 760 2 Roman 10
X45
X6 714 18 670 30 683 0 0
X24 680 2 Roman 10
X40
X6 713 610 750 622 763 0 0
X616 760 2 Roman 10
X45
X1 712 48 608 592 800 0 0
X70
X 48 608 48 800 64 800 64 608
X 80 608 80 800 96 800 96 608
X 112 608 112 800 128 800 128 608
X 144 608 144 800 160 800 160 608
X 176 608 176 800 192 800 192 608
X 208 608 208 800 224 800 224 608
X 240 608 240 800 256 800 256 608
X 272 608 272 800 288 800 288 608
X 304 608 304 800 320 800 320 608
X 336 608 336 800 352 800 352 608
X 368 608 368 800 384 800 384 608
X 400 608 400 800 416 800 416 608
X 432 608 432 800 448 800 448 608
X 464 608 464 800 480 800 480 608
X 496 608 496 800 512 800 512 608
X 528 608 528 800 544 800 544 608
X 560 608 560 800 576 800 576 608
X 592 608 592 800
X6 711 37 798 43 811 0 0
X40 808 1 Roman 10
X0
X6 710 117 798 123 811 0 0
X120 808 1 Roman 10
X5
X6 709 194 798 206 811 0 0
X200 808 2 Roman 10
X10
X6 708 274 798 286 811 0 0
X280 808 2 Roman 10
X15
X6 707 354 798 366 811 0 0
X360 808 2 Roman 10
X20
X6 706 434 798 446 811 0 0
X440 808 2 Roman 10
X25
X6 705 514 798 526 811 0 0
X520 808 2 Roman 10
X30
X6 704 594 798 606 811 0 0
X600 808 2 Roman 10
X35
X6 687 357 798 363 811 0 0
X360 808 1 Roman 10
X*
END_OF_FILE
if test 12226 -ne `wc -c <'xpic/test/triple.x'`; then
    echo shar: \"'xpic/test/triple.x'\" unpacked with wrong size!
fi
# end of 'xpic/test/triple.x'
fi
if test -f 'xpic/x2pic.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpic/x2pic.c'\"
else
echo shar: Extracting \"'xpic/x2pic.c'\" \(10507 characters\)
sed "s/^X//" >'xpic/x2pic.c' <<'END_OF_FILE'
X/* $Header: x2pic.c,v 1.5 89/04/21 03:31:52 xwindows Exp $ */
X#include <X11/Xos.h>
X#include <stdio.h>
X#include <ctype.h>
X#include "defs.h"
X#include "tune.h"
X
X/*
X *  Define this is your pic does not reset the scale between consecutive
X *  pictures, resulting in successive xpic pictures in a document
X *  shrinking more and more - or apply pic.fix to your pic source, if
X *  you have it - or complain to your pic vendor.
X */
X/* define BROKENPIC */
X
X/* To do:
X	2. Allow some sort of scaling and positioning arguments.
X */
X
X#define MAXFONTS 127
X#define FONTDESCFILE "x2pic"
X
Xextern char *malloc();
X
X#define xtransform(x)	((double) ((x) - orgX))
X#define ytransform(y)	((double) (picHeight - (y)))
X
Xstatic char *progname;
Xstatic int orgX, orgY, picWidth, picHeight, delX, delY;
X
Xstatic double width, height;
Xstatic double x, y;
Xstatic char *style_words[NSTYLES] = {
X	"", "dotted", "dashed", "dashed 0.1 * scale", "dashed 0.15 * scale"
X};
Xstatic int style;
Xstatic int linewidth = 0;
X
Xstatic char *halign_words[] = {
X	"", "ljust", "rjust"
X};
Xstatic int halign;
Xstatic int valign;
X
Xstatic char *arrows[] = {
X	"", "<-", "->", "<->"
X};
Xstatic int arrow_type;
Xstatic char *name;
Xstatic double picScale = 1.0;
X
XFILE *outFile;
XFILE *inFile;
X
Xextern int optind;
Xextern char *optarg;
X
Xstatic void ChangeThickness(t)
X{
X	if (linewidth != t) {
X		linewidth = t;
X		if (linewidth == 0)
X			(void) fprintf(outFile, ".ps 10\n");
X		else
X			(void) fprintf(outFile, ".ps %d\n", linewidth * 20);
X	}
X}
X
Xstatic void MakeBox(x1, y1, x2, y2, attr)
X{
X	style = getlinestyle(attr);
X	if ((style < 0) || (style >= NSTYLES)) {
X		(void) fprintf(stderr, "Unknown style - %d\n", style);
X		style = 0;
X	}
X	width = x2 - x1;
X	height = y2 - y1;
X	x = xtransform(((double) (x1 + x2)) / 2.0);
X	y = ytransform(((double) (y1 + y2)) / 2.0);
X	(void) fprintf(outFile, "box %s wid %g ht %g at %g, %g\n", 
X	 style_words[style], width, height, x, y);
X}
X
X
X/* Ellipses and circles have no attributes in pic - not yet, anyway. */
X/*ARGSUSED*/
Xstatic void MakeEllipse(xc, yc, xr, yr, attr, x1, y1, x2, y2)
X{
X	if (attr != 0) {
X		fputs("warning: ellipses have no attributes in pic\n", stderr);
X	}
X	width = 2.0 * xr;
X	height = 2.0 * yr;
X	x = xtransform((double) xc);
X	y = ytransform((double) yc);
X	(void) fprintf(outFile, "ellipse wid %g ht %g at %g, %g\n", 
X	 width, height, x, y);
X}
X
X/*ARGSUSED*/
Xstatic void MakeCircle(xc, yc, r, attr, x1, y1, x2, y2)
X{
X	if (attr != 0) {
X		(void) fprintf(stderr, "warning: circles have no attributes in pic\n");
X	}
X	x = xtransform((double) xc);
X	y = ytransform((double) yc);
X	(void) fprintf(outFile, "circle radius %d at %g, %g\n", 
X	 r, x, y);
X}
X
X
X/*
X *  print out a string, escaping '"' with a \ - we don't escape \, to
X *  give people a mechanism for sending strange numbers to the lw
X */
Xstatic void PrintText(s)
Xchar *s;
X{
X	register char *cp = s;
X
X	for(; *cp != 0; cp++) {
X		if (isascii(*cp) && isprint(*cp)) {
X 			if (*cp != '"')
X		 		(void) fputc(*cp, outFile);
X			else
X				(void) fprintf(outFile, "\\%c", *cp);
X		} else {
X			/* We don't want to print these! */
X			(void) fprintf(stderr, "Ignoring weird character \\%o in \"%s\"", 
X				*cp & 0xff, s);
X		} 
X	}
X}
X			
X
X
X/*ARGSUSED*/
Xstatic void MakeText(s, len, font, size, attr, xc, yc, x1, y1, x2, y2)
Xchar *s;
Xchar *font;
X{
X	char *troff_font;
X	char *lastfont = "P";
X	extern char *HashSearch();
X	
X	if ((troff_font = HashSearch(font)) == NULL) {
X		(void) fprintf(stderr, "Unavailable font %s\n", font);
X		font = "";
X		lastfont = "";
X	}
X	if (size < 0) {
X		(void) fprintf(stderr, "Incorrect font size %d\n", size);
X		size = 10;
X	}
X	valign = gettext_valign(attr);
X	if ((valign < 0) || (valign >= 3)) {
X		(void) fprintf(stderr, "Incorrect vert alignment %d\n", valign);
X		valign = 0;
X	}
X	halign = gettext_halign(attr);
X	if ((halign < 0) || (halign >= 3)) {
X		(void) fprintf(stderr, "Incorrect horiz. alignment %d\n", halign);
X		halign = 0;
X	}
X	size = (int) (picScale * size);
X	x = xtransform(xc);
X	switch (valign) {
X	case 0: /* MIDLINE */
X		y = ytransform( yc );
X		break;
X	case 1: /* TOPLINE */
X		y = ytransform( yc + ((double) (y2 - y1)) / 2.0 );
X		break;
X	case 2: /* BOTLINE */
X		y = ytransform( yc - ((double) (y2 - y1)) / 2.0 );
X		break;
X	}
X	(void) fprintf(outFile, "\"%s\\s%d", troff_font, size);
X	PrintText(s);
X	(void) fprintf(outFile, "\\s0\\f%s\" %s at %g, %g\n", lastfont, 
X	 halign_words[halign], x, y);
X}
X	
X
X/*ARGSUSED*/
Xstatic void StartLine(xc, yc, n, attr, type)
X{
X	arrow_type = getlinearrow(attr);
X	if ((arrow_type < 0) || (arrow_type >= 4)) {
X		(void) fprintf(stderr, "Unknown arrow type %d\n", arrow_type);
X		arrow_type = 0;
X	}
X	style = getlinestyle(attr);
X	if ((style < 0) || (style >= NSTYLES)) {
X		(void) fprintf(stderr, "Unknown style - %d\n", style);
X		style = 0;
X	}
X	x = xtransform(xc);
X	y = ytransform(yc);
X	name = "line";
X	if (type != LINE) {
X		name = "spline";
X		if (style != 0) {
X			(void) fprintf(stderr,
X			 "warning: splines have no attributes in pic\n");
X			style = 0;
X		}
X	}
X	(void) fprintf(outFile, "%s %s %s from %g, %g ",
X	 name, arrows[arrow_type], style_words[style], x, y);
X}
X
X
Xstatic void NextAt(xc, yc)
X{
X	x = xtransform(xc);
X	y = ytransform(yc);
X	(void) fprintf(outFile, "\\\n\tto %g, %g ", x, y);
X}
X
X
Xstatic void EndLine()
X{
X	(void) fprintf(outFile, "\n");
X}
X
X/*
X *  Read in a file output by xpic, and emit the appropriate pic text
X */
Xstatic void convert()
X{
X	int type;
X	int xc, yc, xr, yr, len, attr;
X	int size;
X	int x1, y1, x2, y2;
X	char *s;
X	int c, i, n;
X	int err, nf, gs;
X	int num, thickness;
X	char font[MAXSTR];
X
X
X#define INPERR 2
X#define INPEOF 3
X
X	err = 0;
X#ifdef MAGIC
X	/* Check for the magic header that the new xpic puts out */
X	if ((c = fgetc(inFile)) == EOF) {
X		(void) fprintf(stderr, "Incorrect input format");
X		return;
X	}
X	(void) ungetc(c, inFile);
X	if (c == '#') {
X		/* Magic header - ignore */
X		(void) fscanf(inFile, "%*[^\n]");
X	}
X#endif MAGIC
X	/* Read in (and ignore) the gel bounding box */
X	(void) fscanf(inFile, " %d %d %d %d %d", &x1, &y1, &x2, &y2, &gs);
X	/* Set up constants for scaling, translation etc. */
X	orgX = x1;
X	orgY = y1;
X	delX = x2 - x1;
X	delY = y2 - y1;
X	picWidth = x2;
X	picHeight = y2;
X	(void) fprintf(outFile, ".PS\nscale = %lg\n",
X	 (double) (gs * 10 / picScale));
X	/* Read in the actual picture */
X	do {
X		if ((nf = fscanf(inFile, " %d", &type)) != 1) {
X			err = INPEOF;
X			break;
X		}
X		nf = fscanf(inFile, " %d %d %d %d %d %x %d", &num, &x1, &y1, 
X		 &x2, &y2, &attr, &thickness);
X		if (nf != 7) {
X			err = INPERR;
X			break;
X		}
X		ChangeThickness(thickness);
X		switch (type) {
X		case BOX:
X			MakeBox(x1, y1,x2, y2, attr);
X			break;
X		case ELLIPSE:
X			nf = fscanf(inFile, " %d %d %d %d", &xc, &yc, &xr, &yr) ;
X			if (nf != 4) {
X				err = INPERR;
X				break;
X			}
X			MakeEllipse(xc, yc, xr, yr, attr, x1, y1, x2, y2);
X			break;
X		case CIRCLE:
X			nf = fscanf(inFile, " %d %d %d", &xc, &yc, &xr);
X			if (nf != 3) {
X				err = INPERR;
X				break;
X			}
X			MakeCircle(xc, yc, xr, attr, x1, y1, x2, y2);
X			break;
X		case TEXT:
X			nf = fscanf(inFile, " %d %d %d %s %d", &xc, &yc, &len, font, 
X			 &size);
X			if (nf != 5) {
X				err = INPERR;
X				break;
X			}
X			/*
X			 *  For backward compatibility with the bad old days. The
X			 *  old convention of storing font information was really
X			 *  ugly - a font number from 0-3, (corresponding to Roman,
X			 *  Bolld, Italic, Special) and a size from 0-9
X			 *  (corresponding to point sizes 6 - 24)
X			 */
X			if (font[1] == '\0') {
X				int oldfontconvention = TRUE;
X				
X				switch (font[0]) {
X				case '0':
X					(void) strcpy(font, "Roman");
X					break;
X				case '1':
X					(void) strcpy(font, "Bold");
X					break;
X				case '2':
X					(void) strcpy(font, "Italic");
X					break;
X				case '3':
X					(void) strcpy(font, "Special");
X					break;
X				default:
X					/* Must a new font with a one letter name. Eeep! */
X					oldfontconvention = FALSE;
X				}
X				if (oldfontconvention)
X					/* Convert to pointsize */
X					size = size * 2 + 6;
X			}
X			/* Go to the next line */
X			while ((c = fgetc(inFile)) != '\n' && c != EOF)
X				;
X			if (c == EOF) {
X				err = INPERR;
X				break;
X			}
X			if (( s = malloc((unsigned) (len + 2))) == NULL) {
X				(void) fprintf(stderr, "No more memory for text string");
X				break;
X			}
X			if (fgets(s, len + 1, inFile) == NULL) {
X				free(s);
X				err = INPERR;
X				break;
X			}
X			s[len] = '\0';
X			MakeText(s, len, font, size, attr, xc, yc, x1, y1, x2, y2);
X			free(s);
X			break;
X		case LINE:
X		case SPLINE:
X			if (fscanf(inFile, " %d %d %d", &n, &xc, &yc) != 3) {
X				err = INPERR;
X				break;
X			}
X			StartLine(xc, yc, n, attr, type);
X			for (i = 1; i < n; i++) {
X				if (fscanf(inFile, " %d %d", &xc, &yc) != 2) {
X					err = INPERR;
X					break;
X				}
X				NextAt(xc, yc);
X			}
X			if (err != INPERR)
X				EndLine();
X			break;
X		}
X	} while (err == 0);
X	(void) fprintf(outFile, ".PE\n");
X#ifdef BROKENPIC
X	(void) fprintf(outFile, ".PS\nscale = 0\n.PE\n");
X#endif
X	if (err == INPERR)
X		(void) fprintf(stderr, "Incorrect input format");
X
X	return;
X
X#undef INPEOF
X#undef INPERR
X}
X
X
Xusage(s)
Xchar *s;
X{
X	(void) fprintf(stderr, "Usage: %s [-s scale] [-f maxfonts] [filename]\n",
X	 s);
X	exit(-1);
X}
X
X/* Font tables are of the form
X	xpic-font-name	PostScript-font-name
X */
Xreadfonttable(file)
Xchar *file;
X{
X	FILE *fp;
X	char xfontname[MAXSTR], psfontname[MAXSTR];
X	char *s1, *s2;
X	extern char *strsave();
X	
X	if ((fp = fopen(file, "r")) == NULL)
X		return;
X	while(fscanf(fp, " %s %s", xfontname, psfontname) == 2) {
X		if ((s1 = strsave(xfontname)) && (s2 = strsave(psfontname)))
X			HashInsert(s1, s2);
X		else {
X			(void) fprintf(stderr, "Out of memory\n");
X			exit(-1);
X		}
X	}
X	(void) fclose(fp);
X}
X
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X	double atof();
X	int c;
X	int nfonts = MAXFONTS;
X	char fontfile[MAXSTR];
X	char *hdir;
X	char *getenv();
X	
X	progname = argv[0];
X	inFile = stdin;
X	outFile = stdout;
X	while((c = getopt(argc, argv, "s:f:")) != EOF) {
X		switch (c) {
X		case 's':
X			picScale = atof(optarg);
X			break;
X		case 'f':
X			nfonts = atoi(optarg);
X			break;
X		case '?':
X			usage(progname);
X			break;
X		}
X	}
X
X	HashInit(nfonts);
X	(void) sprintf(fontfile, "%s/fontdesc/%s", LIBDIR, FONTDESCFILE);
X	readfonttable(fontfile);
X	if (hdir = getenv("HOME")) {
X		(void) sprintf(fontfile, "%s/.%s", hdir, FONTDESCFILE);
X		readfonttable(fontfile);
X	}
X	/* Must have some files */
X	if (optind >= argc) {
X		convert();
X	} else {
X		while (optind < argc) {
X			if ((inFile = fopen(argv[optind], "r")) == NULL) {
X				(void) fprintf(stderr, "Can't open %s for reading\n", 
X				 argv[optind]);
X				break;
X			}
X			outFile = stdout;
X			convert();
X			optind++;
X		}
X	}
X}
END_OF_FILE
if test 10507 -ne `wc -c <'xpic/x2pic.c'`; then
    echo shar: \"'xpic/x2pic.c'\" unpacked with wrong size!
fi
# end of 'xpic/x2pic.c'
fi
echo shar: End of archive 8 \(of 15\).
cp /dev/null ark8isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 15 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Comp.sources.x mailing list