v06i018: xfig, Part10/15
Dan Heller
argv%turnpike at Sun.COM
Tue Mar 6 08:49:51 AEST 1990
Submitted-by: Brian Smith <bvsmith at lbl.gov>
Posting-number: Volume 6, Issue 18
Archive-name: xfig2/part10
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix at uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
# "End of archive 10 (of 15)."
# Contents: xfig/FORMAT1.4 xfig/bound.c xfig/flip.c xfig/main.c
# xfig/move.c xfig/scale.c
# Wrapped by argv at turnpike on Wed Feb 28 10:53:22 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xfig/FORMAT1.4' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xfig/FORMAT1.4'\"
else
echo shar: Extracting \"'xfig/FORMAT1.4'\" \(9677 characters\)
sed "s/^X//" >'xfig/FORMAT1.4' <<'END_OF_FILE'
XThe following is the format of fig output (fig 1.4X).
X
X(0) The only difference between 1.4 and 1.4X is that the interpretation
X of the "pen" value in ARC_BOX is now the radius of the corners of the box.
X Also, the ARC_BOX is sub-type 4 of POLYLINE.
X
X(1) The very first line is a comment line containing the name and version:
X #FIG 1.4X
X
X The character # at the first column of a line indicates that the line
X is a comment line which will be ignored.
X
X(2) The first non-comment line consists of two numbers :
X
X int fig_resolution (pixels/inch)
X int coordinate_system (1 : origin is at the lower left corner
X 2 : Upper left)
X
X Fig_resolution is the resolution fig is using for the current file.
X It may not be the same as screen resolution (which can be higher or
X lower). I assume that a pixel is square, therefore this number
X represents drawing resolution in both direction. I've experimented
X with fig automatically changing this number according to the resolution
X of the monitor it is running on (The screen resolution, width and height
X in pixels, not pixel/inch, can be done by doing a ioctl on the /dev/fb).
X I've found that for monitors with higher resolution but same size
X (19" diagonal), I preferred using the pixels for other things than
X having fig occupying most of the screen. Thus I opted for a fixed
X pixel-per-inch number which make fig window smaller on higher resolution
X monitor (than the standard sun monitor). This however may change in
X the future version.
X
X(3) The rest of the file contains various objects. An object can be one
X of six classes (or types).
X
X i) Ellipse which is a generalization of circle.
X ii) Polyline which includes polygon and box.
X iii) Spline which includes closed/open control/interpolated spline.
X iv) Text.
X v) Arc.
X vi) Compound object which is composed of one or more objects.
X
X In the following elaboration on object formats, every value of fig
X output are separated by blank characters or new line ('\n'). The
X value of the not-used parameters will be -1.
X
X A number of values are described as unused or not applicable to some
X object even though they are defined for those objects. These value
X will (hopefully) be used in the future version of fig. The intention
X of their uses are the following.
X
X Value Usage
X ----- -----
X area_fill The stipple pattern (which will be align) for
X filling object internals. For example, an filled
X arc will look like a piece of pie.
X
X** pen This will be a structure defining the shape of
X pen used in drawing objects. It also includes
X the the stipple pattern for line filling.
X The default pen is a circular pen with black
X filling.
X
X ** In 1.4X, pen is the radius (pixels) of the rounded-corner boxes.
X
X thickness Every pen has the thickness of one.
X Thickness scales the size of a pen.
X
X depth This value adds a half dimension to fig.
X It is useful when we have overlapping filled
X objects and we want one to obliterate another.
X An object can have only one depth (including
X compound object). An object that is in less
X depth can obscure the one with greater depth
X if they overlap.
X
X style Only polyline (including polygon and box) can
X be rendered with dashed line. However the
X objects created when the dash-line mode was on
X will be recorded as such. Currently the filter
X f2ps (1) is able to render the desired line style
X effect on hard copy. Three line styles are defined.
X
X 0 : SOLID_LINE
X 1 : DASH_LINE
X 2 : DOTTED_LINE
X
X style_val For dash style, it is the length of a dash.
X For dotted line it indicates the approximated
X gap of consecutive dots.
X
X (3.1) ARC
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 5)
X int sub_type (always 1)
X int style (See the end of this section)
X int line_thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels, not used)
X int direction (0 : clockwise, 1 : counterclockwise)
X int forward_arrow (0: no forward arrow, 1: on)
X int backward_arrow (0: no forward arrow, 1: on)
X float center_x, center_y (center of the arc)
X int x1, y1 (pixels, the 1st point the user entered)
X int x2, y2 (pixels, the 2nd point)
X int x3, y3 (pixels, the last point)
X
X Forward arrow line (Optional; absent if forward_arrow is 0) :
X type name (brief description)
X ---- ---- -------------------
X int arrow_type (not used)
X int arrow_style (not used)
X float arrow_thickness (not used)
X float arrow_width (pixels)
X float arrow_height (pixels)
X
X Backward arrow line (Optional; absent if backward_arrow is 0) :
X type name (brief description)
X ---- ---- -------------------
X int arrow_type (not used)
X int arrow_style (not used)
X float arrow_thickness (not used)
X float arrow_width (pixels)
X float arrow_height (pixels)
X
X (3.2) COMPOUND
X
X A line with object code 6 signifies the start of a compound.
X There are four more numbers on this line which indicate the
X upper right corner and the lower left corner of the bounding
X box of this compound. A line with object code -6 signifies
X the end of the compound. Compound may be nested.
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 6)
X int upperright_corner_x (pixels)
X int upperright_corner_y (pixels)
X int lowerleft_corner_x (pixels)
X int lowerleft_corner_y (pixels)
X
X Subsequent lines :
X objects
X .
X .
X
X Last line :
X -6
X
X (3.3) ELLIPSE
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 1)
X int sub_type (1 : ellipse defined by radiuses
X 2 : ellipse defined by diameters
X 3 : circle defined by radius
X 4 : circle defined by diameter)
X int style (See the end of this section)
X int thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels, not used)
X int direction (always 1)
X float angle (radian, the angle of the x-axis)
X int center_x, center_y (pixels)
X int radius_x, radius_y (pixels)
X int start_x, start_y (pixels; the 1st point entered)
X int end_x, end_y (pixels; the last point entered)
X
X (3.4) POLYLINE
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 2)
X int sub_type (1 : polyline, 2 : box,
X 3 : polygon, 4 : rounded-corner box)
X int style (See the end of this section)
X int thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen **** (pixels, radius of rounded-corner boxes)
X int area_fill (not used)
X float style_val (pixels)
X int forward_arrow (0: off, 1: on)
X int backward_arrow (0: off, 1: on)
X
X Forward arrow line : same as ARC object
X
X Backward arrow line : same as ARC object
X
X Points line :
X type name (brief description)
X ---- ---- -------------------
X int x1, y1 (pixels)
X int x2, y2 (pixels)
X .
X .
X int xn, yn (this will be the same as the 1st
X point for polygon and box)
X int x, y (always 9999, 9999; marks the end of
X point for polygon and box)
X
X (3.5) SPLINE
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 3)
X int sub_type (0 : open spline
X 1 : closed spline
X 2 : open interpolated spline
X 3 : closed interpolated spline)
X int style (See the end of this section)
X int thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels, not used)
X int forward_arrow (0: off, 1: on)
X int backward_arrow (0: off, 1: on)
X
X Forward arrow line : same as ARC object
X
X Backward arrow line : same as ARC object
X
X Points line : same as POLYLINE object
X
X Control points line (absent if sub_type is 1 or 2) :
X Control points of interpolated spline. There are two control
X points for each knots. A section i, of the spline is drawn
X using Bezier cubic with the following four points:
X (x ,y ), (rx ,ry ), (lx , ly ), (x , y ).
X i i i i i+1 i+1 i+1 i+1
X For closed interpolated spline the last pair of control points,
X (lxn,lyn) and (rxn,ryn) (which can be ignored), are the same as
X (lx1,ly1) and (rx1,ry1) respectively.
X
X type name (brief description)
X ---- ---- -------------------
X float lx1, ly1 (pixels)
X float rx1, ry1 (pixels)
X float lx2, ly2 (pixels)
X float rx2, ry2 (pixels)
X .
X .
X float lxn, lyn (pixels)
X float rxn, ryn (pixels)
X
X (3.6) TEXT
X type name (brief description)
X ---- ---- -------------------
X int object (always 4)
X int sub_type (0 : Left justified
X 1 : Center justified
X 2 : Right justified)
X int font (font number 0-...)
X int font_size (point size)
X int pen (not used)
X int color (not used)
X int depth (not used)
X int angle (radian, not used, the angle of the
X the base line of the string)
X int font_style (not used)
X int height (pixels)
X int length (pixels)
X int x, y (pixels, coordinate of the origin
X of the string. If sub_type = 0, it is
X the lower left corner of the string.
X If sub_type = 1, it is the lower
X center. Otherwise it is the lower
X right corner of the string.)
X char string[] (ascii characters; starts after a blank
X character following the last number and
X ends before the character '\1'. This
X character is not part of the string.
X Note that the string may contain '\n'.)
END_OF_FILE
if test 9677 -ne `wc -c <'xfig/FORMAT1.4'`; then
echo shar: \"'xfig/FORMAT1.4'\" unpacked with wrong size!
fi
# end of 'xfig/FORMAT1.4'
fi
if test -f 'xfig/bound.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xfig/bound.c'\"
else
echo shar: Extracting \"'xfig/bound.c'\" \(9642 characters\)
sed "s/^X//" >'xfig/bound.c' <<'END_OF_FILE'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : August 1985.
X * 2nd revision : April 1988.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "object.h"
X
X#define Ninety_deg M_PI_2
X#define One_eighty_deg M_PI
X#define Two_seventy_deg (M_PI + M_PI_2)
X#define Three_sixty_deg (M_PI + M_PI)
X#define round(x) ((int)((x) + .5))
X#define half(z1 ,z2) ((z1+z2)/2.0)
X#define max(a, b) (((a) > (b)) ? (a) : (b))
X#define min(a, b) (((a) < (b)) ? (a) : (b))
X
Xarc_bound(arc, xmin, ymin, xmax, ymax)
XF_arc *arc;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X float alpha, beta;
X double dx, dy, radius;
X int bx, by, sx, sy;
X
X dx = arc->point[0].x - arc->center.x;
X dy = arc->center.y - arc->point[0].y;
X alpha = atan2(dy, dx);
X if (alpha < 0.0) alpha += Three_sixty_deg;
X /* compute_angle returns value between 0 to 2PI */
X
X radius = sqrt((double)(dx * dx + dy * dy));
X
X dx = arc->point[2].x - arc->center.x;
X dy = arc->center.y - arc->point[2].y;
X beta = atan2(dy, dx);
X if (beta < 0.0) beta += Three_sixty_deg;
X
X bx = max(arc->point[0].x, arc->point[1].x);
X bx = max(arc->point[2].x, bx);
X by = max(arc->point[0].y, arc->point[1].y);
X by = max(arc->point[2].y, by);
X sx = min(arc->point[0].x, arc->point[1].x);
X sx = min(arc->point[2].x, sx);
X sy = min(arc->point[0].y, arc->point[1].y);
X sy = min(arc->point[2].y, sy);
X
X if (arc->direction == 1) { /* counter clockwise */
X if (alpha > beta) {
X if (alpha <= 0 || 0 <= beta)
X bx = (int)(arc->center.x + radius + 1.0);
X if (alpha <= Ninety_deg || Ninety_deg <= beta)
X sy = (int)(arc->center.y - radius - 1.0);
X if (alpha <= One_eighty_deg || One_eighty_deg <= beta)
X sx = (int)(arc->center.x - radius - 1.0);
X if (alpha <= Two_seventy_deg || Two_seventy_deg <= beta)
X by = (int)(arc->center.y + radius + 1.0);
X }
X else {
X if (0 <= beta && alpha <= 0)
X bx = (int)(arc->center.x + radius + 1.0);
X if (Ninety_deg <= beta && alpha <= Ninety_deg)
X sy = (int)(arc->center.y - radius - 1.0);
X if (One_eighty_deg <= beta && alpha <= One_eighty_deg)
X sx = (int)(arc->center.x - radius - 1.0);
X if (Two_seventy_deg <= beta && alpha <= Two_seventy_deg)
X by = (int)(arc->center.y + radius + 1.0);
X }
X }
X else { /* clockwise */
X if (alpha > beta) {
X if (beta <= 0 && 0 <= alpha)
X bx = (int)(arc->center.x + radius + 1.0);
X if (beta <= Ninety_deg && Ninety_deg <= alpha)
X sy = (int)(arc->center.y - radius - 1.0);
X if (beta <= One_eighty_deg && One_eighty_deg <= alpha)
X sx = (int)(arc->center.x - radius - 1.0);
X if (beta <= Two_seventy_deg && Two_seventy_deg <= alpha)
X by = (int)(arc->center.y + radius + 1.0);
X }
X else {
X if (0 <= alpha || beta <= 0)
X bx = (int)(arc->center.x + radius + 1.0);
X if (Ninety_deg <= alpha || beta <= Ninety_deg)
X sy = (int)(arc->center.y - radius - 1.0);
X if (One_eighty_deg <= alpha || beta <= One_eighty_deg)
X sx = (int)(arc->center.x - radius - 1.0);
X if (Two_seventy_deg <= alpha || beta <= Two_seventy_deg)
X by = (int)(arc->center.y + radius + 1.0);
X }
X }
X *xmax = bx; *ymax = by;
X *xmin = sx; *ymin = sy;
X }
X
Xcompound_bound(compound, xmin, ymin, xmax, ymax)
XF_compound *compound;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X F_arc *a;
X F_ellipse *e;
X F_compound *c;
X F_spline *s;
X F_line *l;
X F_text *t;
X int bx, by, sx, sy, first = 1;
X int llx, lly, urx, ury;
X
X for (a = compound->arcs; a != NULL; a = a->next) {
X arc_bound(a, &sx, &sy, &bx, &by);
X if (first) {
X first = 0;
X llx = sx; lly = sy;
X urx = bx; ury = by;
X }
X else {
X llx = min(llx, sx); lly = min(lly, sy);
X urx = max(urx, bx); ury = max(ury, by);
X }
X }
X
X for (c = compound->compounds; c != NULL; c = c->next) {
X compound_bound(c, &sx, &sy, &bx, &by);
X if (first) {
X first = 0;
X llx = sx; lly = sy;
X urx = bx; ury = by;
X }
X else {
X llx = min(llx, sx); lly = min(lly, sy);
X urx = max(urx, bx); ury = max(ury, by);
X }
X }
X
X for (e = compound->ellipses; e != NULL; e = e->next) {
X ellipse_bound(e, &sx, &sy, &bx, &by);
X if (first) {
X first = 0;
X llx = sx; lly = sy;
X urx = bx; ury = by;
X }
X else {
X llx = min(llx, sx); lly = min(lly, sy);
X urx = max(urx, bx); ury = max(ury, by);
X }
X }
X
X for (l = compound->lines; l != NULL; l = l->next) {
X line_bound(l, &sx, &sy, &bx, &by);
X if (first) {
X first = 0;
X llx = sx; lly = sy;
X urx = bx; ury = by;
X }
X else {
X llx = min(llx, sx); lly = min(lly, sy);
X urx = max(urx, bx); ury = max(ury, by);
X }
X }
X
X for (s = compound->splines; s != NULL; s = s->next) {
X spline_bound(s, &sx, &sy, &bx, &by);
X if (first) {
X first = 0;
X llx = sx; lly = sy;
X urx = bx; ury = by;
X }
X else {
X llx = min(llx, sx); lly = min(lly, sy);
X urx = max(urx, bx); ury = max(ury, by);
X }
X }
X
X for (t = compound->texts; t != NULL; t = t->next) {
X text_bound(t, &sx, &sy, &bx, &by);
X if (first) {
X first = 0;
X llx = sx; lly = sy;
X urx = bx; ury = by;
X }
X else {
X llx = min(llx, sx); lly = min(lly, sy);
X urx = max(urx, bx); ury = max(ury, by);
X }
X }
X
X *xmin = llx; *ymin = lly;
X *xmax = urx; *ymax = ury;
X }
X
Xellipse_bound(e, xmin, ymin, xmax, ymax)
XF_ellipse *e;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X *xmin = e->center.x - e->radiuses.x;
X *ymin = e->center.y - e->radiuses.y;
X *xmax = e->center.x + e->radiuses.x;
X *ymax = e->center.y + e->radiuses.y;
X }
X
Xline_bound(l, xmin, ymin, xmax, ymax)
XF_line *l;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X points_bound(l->points, xmin, ymin, xmax, ymax);
X }
X
Xspline_bound(s, xmin, ymin, xmax, ymax)
XF_spline *s;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X if (int_spline(s)) {
X int_spline_bound(s, xmin, ymin, xmax, ymax);
X }
X else {
X normal_spline_bound(s, xmin, ymin, xmax, ymax);
X }
X }
X
Xint_spline_bound(s, xmin, ymin, xmax, ymax)
XF_spline *s;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X F_point *p1, *p2;
X F_control *cp1, *cp2;
X float x0, y0, x1, y1, x2, y2, x3, y3, sx1, sy1, sx2, sy2;
X float tx, ty, tx1, ty1, tx2, ty2;
X float sx, sy, bx, by;
X
X p1 = s->points;
X sx = bx = p1->x;
X sy = by = p1->y;
X cp1 = s->controls;
X for (p2 = p1->next, cp2 = cp1->next; p2 != NULL;
X p1 = p2, cp1 = cp2, p2 = p2->next, cp2 = cp2->next) {
X x0 = p1->x; y0 = p1->y;
X x1 = cp1->rx; y1 = cp1->ry;
X x2 = cp2->lx; y2 = cp2->ly;
X x3 = p2->x; y3 = p2->y;
X tx = half(x1, x2); ty = half(y1, y2);
X sx1 = half(x0, x1); sy1 = half(y0, y1);
X sx2 = half(sx1, tx); sy2 = half(sy1, ty);
X tx2 = half(x2, x3); ty2 = half(y2, y3);
X tx1 = half(tx2, tx); ty1 = half(ty2, ty);
X
X sx = min(x0, sx); sy = min(y0, sy);
X sx = min(sx1, sx); sy = min(sy1, sy);
X sx = min(sx2, sx); sy = min(sy2, sy);
X sx = min(tx1, sx); sy = min(ty1, sy);
X sx = min(tx2, sx); sy = min(ty2, sy);
X sx = min(x3, sx); sy = min(y3, sy);
X
X bx = max(x0, bx); by = max(y0, by);
X bx = max(sx1, bx); by = max(sy1, by);
X bx = max(sx2, bx); by = max(sy2, by);
X bx = max(tx1, bx); by = max(ty1, by);
X bx = max(tx2, bx); by = max(ty2, by);
X bx = max(x3, bx); by = max(y3, by);
X }
X *xmin = round(sx);
X *ymin = round(sy);
X *xmax = round(bx);
X *ymax = round(by);
X }
X
Xnormal_spline_bound(s, xmin, ymin, xmax, ymax)
XF_spline *s;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X F_point *p;
X float cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
X float x1, y1, x2, y2, sx, sy, bx, by;
X float px, py, qx, qy;
X
X p = s->points;
X x1 = p->x; y1 = p->y;
X p = p->next;
X x2 = p->x; y2 = p->y;
X cx1 = (x1 + x2) / 2.0; cy1 = (y1 + y2) / 2.0;
X cx2 = (cx1 + x2) / 2.0; cy2 = (cy1 + y2) / 2.0;
X if (closed_spline(s)) {
X x1 = (cx1 + x1) / 2.0;
X y1 = (cy1 + y1) / 2.0;
X }
X sx = min(x1, cx2); sy = min(y1, cy2);
X bx = max(x1, cx2); by = max(y1, cy2);
X
X for (p = p->next; p != NULL; p = p->next) {
X x1 = x2; y1 = y2;
X x2 = p->x; y2 = p->y;
X cx4 = (x1 + x2) / 2.0; cy4 = (y1 + y2) / 2.0;
X cx3 = (x1 + cx4) / 2.0; cy3 = (y1 + cy4) / 2.0;
X cx2 = (cx4 + x2) / 2.0; cy2 = (cy4 + y2) / 2.0;
X
X px = min(cx2, cx3); py = min(cy2, cy3);
X qx = max(cx2, cx3); qy = max(cy2, cy3);
X
X sx = min(sx, px); sy = min(sy, py);
X bx = max(bx, qx); by = max(by, qy);
X }
X if (closed_spline(s)) {
X *xmin = round(sx); *ymin = round(sy);
X *xmax = round(bx); *ymax = round(by);
X }
X else {
X *xmin = round(min(sx, x2)); *ymin = round(min(sy, y2));
X *xmax = round(max(bx, x2)); *ymax = round(max(by, y2));
X }
X }
X
Xtext_bound(t, xmin, ymin, xmax, ymax)
XF_text *t;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X *xmin = t->base_x;
X *ymin = t->base_y - t->height;
X *xmax = t->base_x + t->length;
X *ymax = t->base_y;
X }
X
Xpoints_bound(points, xmin, ymin, xmax, ymax)
XF_point *points;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X int bx, by, sx, sy;
X F_point *p;
X
X bx = sx = points->x; by = sy = points->y;
X for (p = points->next; p != NULL; p = p->next) {
X sx = min(sx, p->x); sy = min(sy, p->y);
X bx = max(bx, p->x); by = max(by, p->y);
X }
X *xmin = sx; *ymin = sy;
X *xmax = bx; *ymax = by;
X }
X
Xcontrol_points_bound(cps, xmin, ymin, xmax, ymax)
XF_control *cps;
Xint *xmin, *ymin, *xmax, *ymax;
X{
X F_control *c;
X float bx, by, sx, sy;
X
X bx = sx = cps->lx;
X by = sy = cps->ly;
X sx = min(sx, cps->rx); sy = min(sy, cps->ry);
X bx = max(bx, cps->rx); by = max(by, cps->ry);
X for (c = cps->next; c != NULL; c = c->next) {
X sx = min(sx, c->lx); sy = min(sy, c->ly);
X bx = max(bx, c->lx); by = max(by, c->ly);
X sx = min(sx, c->rx); sy = min(sy, c->ry);
X bx = max(bx, c->rx); by = max(by, c->ry);
X }
X *xmin = round(sx); *ymin = round(sy);
X *xmax = round(bx); *ymax = round(by);
X }
END_OF_FILE
if test 9642 -ne `wc -c <'xfig/bound.c'`; then
echo shar: \"'xfig/bound.c'\" unpacked with wrong size!
fi
# end of 'xfig/bound.c'
fi
if test -f 'xfig/flip.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xfig/flip.c'\"
else
echo shar: Extracting \"'xfig/flip.c'\" \(9464 characters\)
sed "s/^X//" >'xfig/flip.c' <<'END_OF_FILE'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define TOLERANCE 7
X#define min(a, b) (((a) < (b)) ? (a) : (b))
X#define max(a, b) (((a) > (b)) ? (a) : (b))
X
Xextern (*canvas_kbd_proc)();
Xextern (*canvas_locmove_proc)();
Xextern (*canvas_leftbut_proc)();
Xextern (*canvas_middlebut_proc)();
Xextern (*canvas_rightbut_proc)();
Xextern null_proc();
Xextern set_popupmenu();
X
Xextern F_line *line_search(), *copy_line();
Xextern F_ellipse *ellipse_search(), *copy_ellipse();
Xextern F_ellipse *ellipse_point_search();
Xextern F_text *copy_text();
Xextern F_spline *spline_search(), *copy_spline();
Xextern F_arc *arc_point_search(), *copy_arc();
Xextern F_compound *compound_search(), *copy_compound();
X
Xextern F_compound objects;
X
Xextern int flip_axis;
Xextern int pointmarker_shown;
Xextern int foreground_color, background_color;
X
Xstatic int copy;
X init_flip();
X init_copynflip();
X
Xflip_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_copynflip;
X canvas_middlebut_proc = init_flip;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&pick15_cursor);
X }
X
Xinit_flip(x, y)
Xint x, y;
X{
X copy = 0;
X flip_search(x, y);
X flip_selected();
X }
X
Xinit_copynflip(x, y)
Xint x, y;
X{
X copy = 1;
X flip_search(x, y);
X flip_selected();
X }
X
Xflip_search(x, y)
Xint x, y;
X{
X F_line *l;
X F_arc *a;
X F_ellipse *e;
X F_spline *s;
X F_compound *c;
X int px, py;
X
X if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipline(l, px, py);
X }
X else if ((a = arc_point_search(x, y, TOLERANCE, &px)) != NULL) {
X init_fliparc(a, a->point[px].x, a->point[px].y);
X }
X else if ((e = ellipse_point_search(x, y, TOLERANCE, &px)) != NULL) {
X if (px == 0) /* start point */
X init_flipellipse(e, e->start.x, e->start.y);
X else
X init_flipellipse(e, e->end.x, e->end.y);
X }
X else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipellipse(e, px, py);
X }
X else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipspline(s, px, py);
X }
X else if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipcompound(c, px, py);
X }
X set_modifiedflag();
X }
X
Xinit_fliparc(a, px, py)
XF_arc *a;
Xint px, py;
X{
X F_arc *arc;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_arcpointmarker(a);
X if (copy) {
X arc = copy_arc(a);
X flip_arc(arc, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_ARC);
X insert_arc(&objects.arcs, arc);
X }
X else {
X draw_arc(a, background_color);
X flip_arc(a, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_ARC);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X arc = a;
X }
X draw_arc(arc, foreground_color);
X if (pointmarker_shown) {
X toggle_arcpointmarker(arc);
X if (copy) toggle_arcpointmarker(a);
X }
X set_latestarc(arc);
X }
X
Xinit_flipcompound(c, px, py)
XF_compound *c;
Xint px, py;
X{
X F_compound *compound;
X
X win_setmouseposition(canvas_swfd, px, py);
X set_temp_cursor(&wait_cursor);
X if (copy) {
X compound = copy_compound(c);
X flip_compound(compound, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_COMPOUND);
X insert_compound(&objects.compounds, compound);
X }
X else {
X draw_compoundbox(c, INV_PAINT);
X erase_compound(c);
X flip_compound(c, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_COMPOUND);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X compound = c;
X }
X draw_compoundbox(compound, INV_PAINT);
X draw_compound(compound);
X set_latestcompound(compound);
X set_temp_cursor(cur_cursor);
X }
X
Xinit_flipellipse(e, px, py)
XF_ellipse *e;
X{
X F_ellipse *ellipse;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_ellipsepointmarker(e);
X if (copy) {
X ellipse = copy_ellipse(e);
X flip_ellipse(ellipse, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_ELLIPSE);
X insert_ellipse(&objects.ellipses, ellipse);
X }
X else {
X draw_ellipse(e, background_color);
X flip_ellipse(e, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_ELLIPSE);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X ellipse = e;
X }
X draw_ellipse(ellipse, foreground_color);
X if (pointmarker_shown) {
X toggle_ellipsepointmarker(ellipse);
X if (copy) toggle_ellipsepointmarker(e);
X }
X set_latestellipse(ellipse);
X }
X
Xinit_flipline(l, px, py)
XF_line *l;
Xint px, py;
X{
X F_line *line;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_linepointmarker(l);
X if (copy) {
X line = copy_line(l);
X flip_line(line, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_POLYLINE);
X insert_line(&objects.lines, line);
X }
X else {
X draw_line(l, ERASE);
X flip_line(l, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_POLYLINE);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X line = l;
X }
X draw_line(line, PAINT);
X if (pointmarker_shown) {
X toggle_linepointmarker(line);
X if (copy) toggle_linepointmarker(l);
X }
X set_latestline(line);
X }
X
Xinit_flipspline(s, px, py)
XF_spline *s;
Xint px, py;
X{
X F_spline *spline;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_splinepointmarker(s);
X if (copy) {
X spline = copy_spline(s);
X flip_spline(spline, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_SPLINE);
X insert_spline(&objects.splines, spline);
X }
X else { /* delete the original */
X draw_spline(s, ERASE);
X flip_spline(s, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_SPLINE);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X spline = s;
X }
X draw_spline(spline, PAINT);
X if (pointmarker_shown) {
X toggle_splinepointmarker(spline);
X if (copy) toggle_splinepointmarker(s);
X }
X set_latestspline(spline);
X }
X
Xflip_line(l, x, y, flip_axis)
XF_line *l;
Xint x, y, flip_axis;
X{
X F_point *p;
X
X switch(flip_axis) {
X case 1 : /* x axis */
X for (p = l->points; p != NULL; p = p->next)
X p->y = y + (y - p->y);
X break;
X case 2 : /* y axis */
X for (p = l->points; p != NULL; p = p->next)
X p->x = x + (x - p->x);
X break;
X }
X }
X
Xflip_spline(s, x, y, flip_axis)
XF_spline *s;
Xint x, y, flip_axis;
X{
X F_point *p;
X F_control *cp;
X
X switch(flip_axis) {
X case 1 : /* x axis */
X for (p = s->points; p != NULL; p = p->next)
X p->y = y + (y - p->y);
X for (cp = s->controls; cp != NULL; cp = cp->next) {
X cp->ly = y + (y - cp->ly);
X cp->ry = y + (y - cp->ry);
X }
X break;
X case 2 : /* y axis */
X for (p = s->points; p != NULL; p = p->next)
X p->x = x + (x - p->x);
X for (cp = s->controls; cp != NULL; cp = cp->next) {
X cp->lx = x + (x - cp->lx);
X cp->rx = x + (x - cp->rx);
X }
X break;
X }
X }
X
Xflip_text(t, x, y, flip_axis)
XF_text *t;
Xint x, y, flip_axis;
X{
X switch(flip_axis) {
X case 1 : /* x axis */
X t->base_y = y + (y - t->base_y);
X break;
X case 2 : /* y axis */
X t->base_x = x + (x - t->base_x);
X break;
X }
X }
X
Xflip_ellipse(e, x, y, flip_axis)
XF_ellipse *e;
Xint x, y, flip_axis;
X{
X switch(flip_axis) {
X case 1 : /* x axis */
X e->direction ^= 1;
X e->center.y = y + (y - e->center.y);
X e->start.y = y + (y - e->start.y);
X e->end.y = y + (y - e->end.y);
X break;
X case 2 : /* y axis */
X e->direction ^= 1;
X e->center.x = x + (x - e->center.x);
X e->start.x = x + (x - e->start.x);
X e->end.x = x + (x - e->end.x);
X break;
X }
X }
X
Xflip_arc(a, x, y, flip_axis)
XF_arc *a;
Xint x, y, flip_axis;
X{
X switch(flip_axis) {
X case 1 : /* x axis */
X a->direction ^= 1;
X a->center.y = y + (y - a->center.y);
X a->point[0].y = y + (y - a->point[0].y);
X a->point[1].y = y + (y - a->point[1].y);
X a->point[2].y = y + (y - a->point[2].y);
X break;
X case 2 : /* y axis */
X a->direction ^= 1;
X a->center.x = x + (x - a->center.x);
X a->point[0].x = x + (x - a->point[0].x);
X a->point[1].x = x + (x - a->point[1].x);
X a->point[2].x = x + (x - a->point[2].x);
X break;
X }
X }
X
Xflip_compound(c, x, y, flip_axis)
XF_compound *c;
Xint x, y, flip_axis;
X{
X F_line *l;
X F_arc *a;
X F_ellipse *e;
X F_spline *s;
X F_text *t;
X F_compound *c1;
X int p, q;
X
X switch(flip_axis) {
X case 1 : /* x axis */
X p = y + (y - c->nwcorner.y);
X q = y + (y - c->secorner.y);
X c->nwcorner.y = min(p, q);
X c->secorner.y = max(p, q);
X break;
X case 2 : /* y axis */
X p = x + (x - c->nwcorner.x);
X q = x + (x - c->secorner.x);
X c->nwcorner.x = min(p, q);
X c->secorner.x = max(p, q);
X break;
X }
X for (l = c->lines; l != NULL; l = l->next)
X flip_line(l, x, y, flip_axis);
X for (a = c->arcs; a != NULL; a = a->next)
X flip_arc(a, x, y, flip_axis);
X for (e = c->ellipses; e != NULL; e = e->next)
X flip_ellipse(e, x, y, flip_axis);
X for (s = c->splines; s != NULL; s = s->next)
X flip_spline(s, x, y, flip_axis);
X for (t = c->texts; t != NULL; t = t->next)
X flip_text(t, x, y, flip_axis);
X for (c1 = c->compounds; c1 != NULL; c1 = c1->next)
X flip_compound(c1, x, y, flip_axis);
X }
END_OF_FILE
if test 9464 -ne `wc -c <'xfig/flip.c'`; then
echo shar: \"'xfig/flip.c'\" unpacked with wrong size!
fi
# end of 'xfig/flip.c'
fi
if test -f 'xfig/main.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xfig/main.c'\"
else
echo shar: Extracting \"'xfig/main.c'\" \(9698 characters\)
sed "s/^X//" >'xfig/main.c' <<'END_OF_FILE'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "const.h"
X#include "version.h"
X#include "patchlevel.h"
X#include "resources.h"
X#include "font.h"
X
Xextern int borderwid, windowspacing, toolstripeht;
Xextern int ICON_COLUMN;
Xextern int CANVAS_HEIGHT, CANVAS_WIDTH;
Xextern int CANVAS_LEFT, CANVAS_TOP;
Xextern int PANEL_LEFT, PANEL_TOP, PANEL_HEIGHT, PANEL_WID;
Xextern int PANEL2_LEFT, PANEL2_TOP, PANEL2_HEIGHT, PANEL2_WID;
Xextern int MSG_LEFT, MSG_TOP, MSG_WIDTH;
Xextern int SIDERULER_LEFT, SIDERULER_TOP;
Xextern int SIDERULER_WIDTH, SIDERULER_HEIGHT;
Xextern int SIDERULER_START;
Xextern int TOPRULER_LEFT, TOPRULER_TOP;
Xextern int TOPRULER_WIDTH, TOPRULER_HEIGHT;
Xextern int INCHES;
Xextern (*canvas_rightbut_proc)();
Xextern set_popupmenu();
Xextern int cur_areafill;
Xextern int landscape;
Xextern int print_landscape;
Xextern int size_button;
X
X#include "fig.icon.X"
XPixmap fig_icon;
Xextern char *boldFont;
Xextern char *normalFont;
X
X#define SCREEN_WIDTH 1152 /* only used in Sunview */
X#define SCREEN_HEIGHT 900
X#define min(a,b) (((a) < (b)) ? (a) : (b))
X
Xstatic char tool_name[100] = " FIG : FACILITY FOR INTERACTIVE GENERATION OF FIGURES ";
Xstatic RECT icon_rect, tool_rect;
Xstatic sigwinched();
X
X/************** FIG options ******************/
X
Xextern int DEBUG;
Xextern int RHS_PANEL;
Xextern int INVERSE;
Xextern int TRACKING;
X
XTOOL tool;
Xint WINDOW_WIDTH, WINDOW_HEIGHT;
Xchar file_header[32] = "#FIG ";
Xstatic char *file = NULL;
X
Xstatic int true = True;
Xstatic int false = False;
Xstatic int zero = 0;
Xstatic float tmp_width = 0.0, tmp_height = 0.0;
X
Xstatic XtResource application_resources[] = {
X {XtNjustify, XtCJustify, XtRBoolean, sizeof(int),
X (Cardinal)&RHS_PANEL, XtRBoolean, (caddr_t)&false},
X {"debug", "Debug", XtRBoolean, sizeof(int),
X (Cardinal)&DEBUG, XtRBoolean, (caddr_t)&false},
X {"landscape", XtCOrientation, XtRBoolean, sizeof(int),
X (Cardinal)&landscape, XtRBoolean, (caddr_t)&true},
X {XtNwidth, XtCWidth, XtRFloat, sizeof(float),
X (Cardinal)&tmp_width, XtRInt, (caddr_t)&zero},
X {XtNheight, XtCHeight, XtRFloat, sizeof(float),
X (Cardinal)&tmp_height, XtRInt, (caddr_t)&zero},
X {XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof(int),
X (Cardinal)&INVERSE, XtRBoolean, (caddr_t)&false},
X {"trackCursor", "Track", XtRBoolean, sizeof(int),
X (Cardinal)&TRACKING, XtRBoolean, (caddr_t)&false},
X {"inches", "Inches", XtRBoolean, sizeof(int),
X (Cardinal)&INCHES, XtRBoolean, (caddr_t)&true},
X {"boldFont", "BoldFont", XtRString, sizeof(caddr_t),
X (Cardinal)&boldFont, XtRString, (caddr_t)NULL},
X {"normalFont", "NormalFont", XtRString, sizeof(caddr_t),
X (Cardinal)&normalFont, XtRString, (caddr_t)NULL},
X};
X
Xstatic XrmOptionDescRec options[] =
X{
X {"-right", ".justify", XrmoptionNoArg, "True" },
X {"-left", ".justify", XrmoptionNoArg, "False"},
X {"-debug", ".debug", XrmoptionNoArg, "True"},
X {"-landscape", ".landscape", XrmoptionNoArg, "True"},
X {"-Landscape", ".landscape", XrmoptionNoArg, "True"},
X {"-portrait", ".landscape", XrmoptionNoArg, "False"},
X {"-Portrait", ".landscape", XrmoptionNoArg, "False"},
X {"-width", ".width", XrmoptionSepArg, 0},
X {"-height", ".height", XrmoptionSepArg, 0},
X {"-inverse", ".reverseVideo", XrmoptionNoArg, "True"},
X {"-notrack", ".trackCursor", XrmoptionNoArg, "False"},
X {"-track", ".trackCursor", XrmoptionNoArg, "True"},
X {"-inches", ".inches", XrmoptionNoArg, "True"},
X {"-imperial", ".inches", XrmoptionNoArg, "True"},
X {"-centimeters", ".inches", XrmoptionNoArg, "False"},
X {"-metric", ".inches", XrmoptionNoArg, "False"},
X {"-boldFont", ".boldFont", XrmoptionSepArg, 0},
X {"-normalFont", ".normalFont", XrmoptionSepArg, 0},
X};
X
Xstatic XtCallbackRec callbacks[] =
X{
X { NULL, NULL },
X};
X
Xstatic Arg form_args[] =
X{
X { XtNcallback, (XtArgVal)callbacks },
X { XtNinput, (XtArgVal) TRUE },
X};
X
Xmain(argc,argv)
X int argc;
X char *argv[];
X{
X#define NCHILDREN 10
X TOOL form, children[NCHILDREN];
X Arg tmp_arg[2];
X int ichild;
X char tstr[10];
X XWMHints *wmhints;
X
X strcat(tool_name, " V. ");
X strcat(tool_name, FIG_VERSION);
X strcat(tool_name, " Protocol V. ");
X strcat(tool_name, PROTOCOL_VERSION);
X strcat(tool_name, " Patch Lev. ");
X sprintf(tstr,"%d",PATCHLEVEL);
X strcat(tool_name, tstr);
X strcat(file_header, PROTOCOL_VERSION);
X printf("Initializing FIG v%s Protocol v%s (X11 patchlevel %d) ... \n",
X FIG_VERSION, PROTOCOL_VERSION, PATCHLEVEL);
X tool = XtInitialize("fig", "Fig", options, XtNumber(options),
X &argc, argv);
X
X fix_converters();
X XtGetApplicationResources(tool, 0, application_resources,
X XtNumber(application_resources), NULL, 0 );
X if (argc > 1)
X file = argv[1];
X
X if (landscape==0) /* match print and screen format to start */
X print_landscape=0;
X
X tool_d = XtDisplay(tool);
X tool_s = XtScreen(tool);
X tool_sn = DefaultScreen(tool_d);
X
X if( CellsOfScreen(tool_s) == 2 && INVERSE )
X {
X XrmValue value;
X XrmDatabase newdb = (XrmDatabase) 0;
X /* extern XrmDatabase XtDefaultDB; */
X extern XrmDatabase XtDatabase();
X
X /* XtDefaultDB = XtDatabase(tool_d); */
X value.size = sizeof("White");
X value.addr = "White";
X XrmPutResource(&newdb, "xfig*borderColor", "String",
X &value);
X value.size = sizeof("White");
X value.addr = "White";
X XrmPutResource(&newdb, "xfig*foreground", "String",
X &value);
X value.size = sizeof("Black");
X value.addr = "Black";
X XrmPutResource(&newdb, "xfig*background", "String",
X &value);
X /* XrmMergeDatabases(newdb, &XtDefaultDB); */
X XrmMergeDatabases(newdb, XtDatabase(tool_d));
X
X /* now set the tool part, since its already created */
X XtSetArg(tmp_arg[0], XtNborderColor,
X WhitePixelOfScreen(tool_s));
X XtSetArg(tmp_arg[1], XtNforeground,
X WhitePixelOfScreen(tool_s));
X XtSetArg(tmp_arg[2], XtNbackground,
X BlackPixelOfScreen(tool_s));
X XtSetValues(tool, tmp_arg, 3);
X }
X
X init_font();
X
X gc = DefaultGC(tool_d, tool_sn);
X bold_gc = DefaultGC(tool_d, tool_sn);
X
X /* set the roman and bold fonts for the message windows */
X XSetFont(tool_d, gc, roman_font->fid);
X XSetFont(tool_d, bold_gc, bold_font->fid);
X
X init_cursor();
X form = XtCreateManagedWidget("form", formWidgetClass, tool,
X form_args, XtNumber(form_args));
X
X if (size_button == 0)
X size_button = DEF_PRINTFONTSIZE;
X
X ICON_COLUMN = ICON_COLUMN_PORT;
X CANVAS_WIDTH = tmp_width * (INCHES ? PIX_PER_INCH : PIX_PER_CM);
X CANVAS_HEIGHT = tmp_height * (INCHES ? PIX_PER_INCH : PIX_PER_CM);
X
X if( CANVAS_WIDTH == 0 )
X CANVAS_WIDTH = landscape ? DEF_CANVAS_WIDTH_L : DEF_CANVAS_WIDTH_P;
X
X if( CANVAS_HEIGHT == 0 )
X CANVAS_HEIGHT = landscape ? DEF_CANVAS_HEIGHT_L : DEF_CANVAS_HEIGHT_P;
X
X
X if( (CANVAS_HEIGHT < DEF_CANVAS_HEIGHT_P) ||
X (HeightOfScreen(tool_s) < DEF_CANVAS_HEIGHT_P) )
X ICON_COLUMN = ICON_COLUMN_LAND;
X
X (void) init_panel(form);
X (void) init_topruler(form) ;
X (void) init_menu(form); /* command menu */
X (void) init_canvas(form);
X (void) init_fontmenu(form); /* printer font menu */
X (void) init_sideruler(form);
X (void) init_msg(form);
X (void) init_panel2(form); /* second panel */
X (void) init_indicator_panel(form); /* current line size, area fill, etc */
X
X ichild = 0;
X children[ichild++] = panel_sw;
X children[ichild++] = topruler_sw;
X children[ichild++] = psfont; /* shows current printer font name */
X children[ichild++] = canvas_sw; /* main drawing canvas */
X children[ichild++] = msg_sw; /* message window */
X children[ichild++] = sideruler_sw; /* side ruler */
X children[ichild++] = panel2_sw; /* lower button panel */
X children[ichild++] = fill_panel; /* current fill pattern window */
X children[ichild++] = line_thick_panel; /* current line thickness window */
X children[ichild++] = radius_panel; /* current arc-corner box radius window */
X
X /* until the following XtRealizeWidget() is called, there
X are NO windows in existence */
X
X XtManageChildren(children, NCHILDREN);
X XtRealizeWidget(tool);
X
X /* Set the input field to true to allow keyboard input */
X wmhints = XGetWMHints(tool_d, XtWindow(tool));
X wmhints->flags = InputHint;
X wmhints->input = True;
X XSetWMHints(tool_d, XtWindow(tool),wmhints);
X
X if( RHS_PANEL )
X {
X XtSetArg(tmp_arg[0], XtNfromHoriz, 0);
X XtSetArg(tmp_arg[1], XtNhorizDistance, RULER_WIDTH+2);
X XtSetValues(topruler_sw, tmp_arg, 2);
X XtSetArg(tmp_arg[0], XtNfromHoriz, 0);
X XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw);
X XtSetValues(sideruler_sw, tmp_arg, 2);
X XtUnmanageChild(msg_sw);
X XtSetArg(tmp_arg[0], XtNfromHoriz, sideruler_sw);
X XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw);
X XtSetValues(canvas_sw, tmp_arg, 2);
X XtManageChild(msg_sw);
X XtSetArg(tmp_arg[0], XtNfromHoriz, canvas_sw);
X XtSetArg(tmp_arg[1], XtNfromVert, 0);
X XtSetValues(panel_sw, tmp_arg, 2);
X XtSetArg(tmp_arg[0], XtNfromHoriz, sideruler_sw);
X XtSetArg(tmp_arg[1], XtNfromVert, canvas_sw);
X XtSetValues(msg_sw, tmp_arg, 2);
X XtUnmanageChild(msg_sw);
X XtManageChild(msg_sw);
X }
X
X init_gc();
X init_fill_gc();
X show_fill_color();
X show_radius();
X setup_panel();
X setup_rulers();
X setup_canvas();
X setup_msg();
X setup_fontmenu(); /* install bitmaps in printer font menu */
X printer_select();
X show_fontsize();
X show_line_thickness();
X put_msg("READY");
X canvas_rightbut_proc = set_popupmenu;
X if (file != NULL)
X edit_file(file);
X (void)signal(SIGINT, SIG_IGN); /* so we don't lose work accidentally */
X fig_icon = XCreateBitmapFromData(tool_d, XtWindow(tool),
X fig_bits, fig_width, fig_height);
X
X XtSetArg(tmp_arg[0], XtNtitle, tool_name);
X XtSetArg(tmp_arg[1], XtNiconPixmap, fig_icon);
X XtSetValues(tool, tmp_arg, 2);
X
X XtMainLoop();
X}
END_OF_FILE
if test 9698 -ne `wc -c <'xfig/main.c'`; then
echo shar: \"'xfig/main.c'\" unpacked with wrong size!
fi
# end of 'xfig/main.c'
fi
if test -f 'xfig/move.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xfig/move.c'\"
else
echo shar: Extracting \"'xfig/move.c'\" \(4187 characters\)
sed "s/^X//" >'xfig/move.c' <<'END_OF_FILE'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "font.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define TOLERANCE 3
X
Xextern (*canvas_kbd_proc)();
Xextern (*canvas_locmove_proc)();
Xextern (*canvas_leftbut_proc)();
Xextern (*canvas_middlebut_proc)();
Xextern (*canvas_rightbut_proc)();
Xextern (*return_proc)();
Xextern null_proc();
Xextern set_popupmenu();
X
Xextern F_line *line_search();
Xextern F_arc *arc_search();
Xextern F_ellipse *ellipse_search();
Xextern F_text *text_search();
Xextern F_spline *spline_search();
Xextern F_compound *compound_search();
X
Xextern int foreground_color, background_color;
Xextern int pointmarker_shown, compoundbox_shown;
Xextern int last_object;
Xextern int last_action;
X
X init_move();
X
Xmove_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_move;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X return_proc = move_selected;
X set_cursor(&pick9_cursor);
X reset_action_on();
X }
X
Xinit_move(x, y)
Xint x, y;
X{
X F_line *l;
X F_arc *a;
X F_ellipse *e;
X F_text *t;
X F_spline *s;
X F_compound *c;
X int px, py;
X PR_SIZE size;
X
X if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X if (compoundbox_shown) draw_compoundbox(c, INV_PAINT);
X erase_compound(c);
X init_compounddragging(c, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_COMPOUND);
X set_latestcompound(c);
X }
X else if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X win_setmouseposition(canvas_swfd, px, py);
X draw_line(l, ERASE);
X init_linedragging(l, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_POLYLINE);
X set_latestline(l);
X }
X else if ((t = text_search(x, y)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X px = 0;
X if (t->type == T_CENTER_JUSTIFIED || t->type == T_RIGHT_JUSTIFIED)
X {
X size = pf_textwidth(t->font, t->size, strlen(t->cstring), t->cstring);
X if (t->type == T_CENTER_JUSTIFIED)
X px = size.x/2;
X else
X px = size.x;
X }
X pw_text(canvas_pixwin, t->base_x - px, t->base_y, INV_PAINT,
X t->font, t->size, t->cstring);
X init_textdragging(t, x, y);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_TEXT);
X set_latesttext(t);
X }
X else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X pw_batch_on(canvas_pixwin);
X draw_ellipse(e, background_color);
X pw_batch_off(canvas_pixwin);
X init_ellipsedragging(e, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_ELLIPSE);
X set_latestellipse(e);
X }
X else if ((a = arc_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X win_setmouseposition(canvas_swfd, px, py);
X pw_batch_on(canvas_pixwin);
X draw_arc(a, background_color);
X pw_batch_off(canvas_pixwin);
X init_arcdragging(a, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_ARC);
X set_latestarc(a);
X }
X else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X erase_pointmarker();
X pw_batch_on(canvas_pixwin);
X draw_spline(s, ERASE);
X pw_batch_off(canvas_pixwin);
X init_splinedragging(s, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_SPLINE);
X set_latestspline(s);
X }
X else
X return;
X canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X }
END_OF_FILE
if test 4187 -ne `wc -c <'xfig/move.c'`; then
echo shar: \"'xfig/move.c'\" unpacked with wrong size!
fi
# end of 'xfig/move.c'
fi
if test -f 'xfig/scale.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xfig/scale.c'\"
else
echo shar: Extracting \"'xfig/scale.c'\" \(8385 characters\)
sed "s/^X//" >'xfig/scale.c' <<'END_OF_FILE'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define TOLERANCE 7
X#define min(a, b) (((a) < (b)) ? (a) : (b))
X#define max(a, b) (((a) > (b)) ? (a) : (b))
X#define round(a) (int)(a + 0.5)
X
Xextern int fix_x, fix_y, cur_x, cur_y;
Xextern F_pos last_position, new_position; /* used in undo */
X
Xextern F_compound *compound_point_search(), *compound_search();
Xextern (*canvas_kbd_proc)();
Xextern (*canvas_locmove_proc)();
Xextern (*canvas_leftbut_proc)();
Xextern (*canvas_middlebut_proc)();
Xextern (*canvas_rightbut_proc)();
Xextern null_proc();
Xextern set_popupmenu();
X
X prescale_compound(), elastic_compoundbox();
X
Xstatic enum {WEST, NORTH, EAST, SOUTH, CORNER} side;
Xstatic int save_coord;
Xstatic F_compound *compound;
Xstatic double cosa, sina;
Xstatic int fromx, fromy;
X init_scale_compound();
X
Xscale_compound_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_scale_compound;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&pick15_cursor);
X reset_action_on();
X }
X
Xinit_scale_compound(x, y)
Xint x, y;
X{
X double dx, dy, l;
X
X if ((compound = compound_point_search(x, y, TOLERANCE, &cur_x,
X &cur_y)) != NULL)
X {
X if (compound->nwcorner.x == cur_x)
X fix_x = compound->secorner.x;
X else
X fix_x = compound->nwcorner.x;
X if (compound->nwcorner.y == cur_y)
X fix_y = compound->secorner.y;
X else
X fix_y = compound->nwcorner.y;
X
X side = CORNER;
X dx = cur_x - fix_x; dy = cur_y - fix_y;
X l = sqrt(dx*dx + dy*dy);
X cosa = fabs(dx / l); sina = fabs(dy / l);
X
X fromx = cur_x; fromy = cur_y;
X win_setmouseposition(canvas_swfd, cur_x, cur_y);
X draw_compoundbox(compound, INV_PAINT);
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT, 1);
X set_latestcompound(compound);
X canvas_locmove_proc = elastic_compoundbox;
X canvas_middlebut_proc = prescale_compound;
X canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X set_action_on();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, x, y);
X }
X else if ((compound = compound_search(x, y, TOLERANCE, &cur_x, &cur_y))
X != NULL )
X {
X /* figure out which side the cursor is close to. */
X if (compound->nwcorner.x == cur_x)
X side = WEST;
X else if (compound->nwcorner.y == cur_y)
X side = NORTH;
X else if (compound->secorner.x == cur_x)
X side = EAST;
X else if (compound->secorner.y == cur_y)
X side = SOUTH;
X else
X return;
X
X /* figure out a fixed point of the compound for scaling */
X switch (side) {
X case WEST:
X case NORTH:
X fix_x = compound->secorner.x;
X fix_y = compound->secorner.y;
X cur_x = compound->nwcorner.x;
X cur_y = compound->nwcorner.y;
X break;
X case EAST:
X case SOUTH:
X fix_x = compound->nwcorner.x;
X fix_y = compound->nwcorner.y;
X cur_x = compound->secorner.x;
X cur_y = compound->secorner.y;
X break;
X }
X
X /* save initial corner position */
X fromx = cur_x; fromy = cur_y;
X /* save x or y coordinate for restoring the cursor */
X /* at the end of the scaling */
X switch (side) {
X case NORTH: case SOUTH:
X save_coord = x;
X break;
X case EAST: case WEST:
X save_coord = y;
X break;
X }
X /* erase the compound box. */
X win_setmouseposition(canvas_swfd, cur_x, cur_y);
X draw_compoundbox(compound, INV_PAINT);
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT, 1);
X set_latestcompound(compound);
X canvas_locmove_proc = elastic_compoundbox;
X canvas_middlebut_proc = prescale_compound;
X canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X set_action_on();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, x, y);
X }
X}
X
X
Xelastic_compoundbox(x, y)
Xint x, y;
X{
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT, 1);
X compute_adjustposition(x, y);
X win_setmouseposition(canvas_swfd, cur_x, cur_y);
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT, 1);
X }
X
Xcompute_adjustposition(x, y)
Xint x, y;
X{
X double xx, yy, d;
X
X switch(side) {
X case CORNER:
X xx = x - fix_x;
X yy = y - fix_y;
X d = sqrt(xx*xx + yy*yy);
X if (xx < 0)
X cur_x = fix_x - round(d * cosa);
X else
X cur_x = fix_x + round(d * cosa);
X if (yy < 0)
X cur_y = fix_y - round(d * sina);
X else
X cur_y = fix_y + round(d * sina);
X break;
X case NORTH:
X case SOUTH:
X cur_y = y;
X break;
X case EAST:
X case WEST:
X cur_x = x;
X break;
X }
X}
X
Xprescale_compound(x, y)
Xint x, y;
X{
X float scalex, scaley;
X
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT, 1);
X compute_adjustposition(x, y);
X erase_compound(compound);
X
X scalex = ((float) (cur_x - fix_x)) / (fromx - fix_x);
X scaley = ((float) (cur_y - fix_y)) / (fromy - fix_y);
X scale_compound(compound, scalex, scaley, fix_x, fix_y);
X
X draw_compound(compound);
X draw_compoundbox(compound, INV_PAINT);
X last_position.x = fromx;
X last_position.y = fromy;
X new_position.x = cur_x;
X new_position.y = cur_y;
X /* update cursor position for single axis scaling. */
X switch (side) {
X case NORTH: case SOUTH:
X /* maintain old horiz. pos. */
X cur_x = save_coord;
X break;
X case EAST: case WEST:
X /* maintain old vert. pos. */
X cur_y = save_coord;
X break;
X }
X clean_up();
X set_action_object(F_SCALE, O_COMPOUND);
X set_latestcompound(compound);
X set_modifiedflag();
X scale_compound_selected();
X }
X
Xscale_compound(c, sx, sy, refx, refy)
XF_compound *c;
Xfloat sx, sy;
Xint refx, refy;
X{
X F_line *l;
X F_spline *s;
X F_ellipse *e;
X F_text *t;
X F_arc *a;
X F_compound *c1;
X int x1, y1, x2, y2;
X
X x1 = round(refx + (c->nwcorner.x - refx) * sx);
X y1 = round(refy + (c->nwcorner.y - refy) * sy);
X x2 = round(refx + (c->secorner.x - refx) * sx);
X y2 = round(refy + (c->secorner.y - refy) * sy);
X c->nwcorner.x = min(x1, x2);
X c->nwcorner.y = min(y1, y2);
X c->secorner.x = max(x1, x2);
X c->secorner.y = max(y1, y2);
X
X for (l = c->lines; l != NULL; l = l->next) {
X scale_line(l, sx, sy, refx, refy);
X }
X for (s = c->splines; s != NULL; s = s->next) {
X scale_spline(s, sx, sy, refx, refy);
X }
X for (a = c->arcs; a != NULL; a = a->next) {
X scale_arc(a, sx, sy, refx, refy);
X }
X for (e = c->ellipses; e != NULL; e = e->next) {
X scale_ellipse(e, sx, sy, refx, refy);
X }
X for (t = c->texts; t != NULL; t = t->next) {
X scale_text(t, sx, sy, refx, refy);
X }
X for (c1 = c->compounds; c1 != NULL; c1 = c1->next) {
X scale_compound(c1, sx, sy, refx, refy);
X }
X }
X
Xscale_line(l, sx, sy, refx, refy)
XF_line *l;
Xfloat sx, sy;
Xint refx, refy;
X{
X F_point *p;
X
X for (p = l->points; p != NULL; p = p->next) {
X p->x = round(refx + (p->x - refx) * sx);
X p->y = round(refy + (p->y - refy) * sy);
X }
X }
X
Xscale_spline(s, sx, sy, refx, refy)
XF_spline *s;
Xfloat sx, sy;
Xint refx, refy;
X{
X F_point *p;
X F_control *c;
X
X for (p = s->points; p != NULL; p = p->next) {
X p->x = round(refx + (p->x - refx) * sx);
X p->y = round(refy + (p->y - refy) * sy);
X }
X for (c = s->controls; c != NULL; c = c->next) {
X c->lx = refx + (c->lx - refx) * sx;
X c->ly = refy + (c->ly - refy) * sy;
X c->rx = refx + (c->rx - refx) * sx;
X c->ry = refy + (c->ry - refy) * sy;
X }
X }
X
Xscale_arc(a, sx, sy, refx, refy)
XF_arc *a;
Xfloat sx, sy;
Xint refx, refy;
X{
X int i;
X
X for (i = 0; i < 3; i++) {
X a->point[i].x = round(refx + (a->point[i].x - refx) * sx);
X a->point[i].y = round(refy + (a->point[i].y - refy) * sy);
X }
X compute_arccenter(a->point[0], a->point[1], a->point[2],
X &a->center.x, &a->center.y);
X a->direction = compute_direction(a->point[0], a->point[1], a->point[2]);
X }
X
Xscale_ellipse(e, sx, sy, refx, refy)
XF_ellipse *e;
Xfloat sx, sy;
Xint refx, refy;
X{
X e->center.x = round(refx + (e->center.x - refx) * sx);
X e->center.y = round(refy + (e->center.y - refy) * sy);
X e->start.x = round(refx + (e->start.x - refx) * sx);
X e->start.y = round(refy + (e->start.y - refy) * sy);
X e->end.x = round(refx + (e->end.x - refx) * sx);
X e->end.y = round(refy + (e->end.y - refy) * sy);
X e->radiuses.x = round(e->radiuses.x * sx);
X e->radiuses.y = round(e->radiuses.y * sy);
X }
X
Xscale_text(t, sx, sy, refx, refy)
XF_text *t;
Xfloat sx, sy;
Xint refx, refy;
X{
X t->base_x = round(refx + (t->base_x - refx) * sx);
X t->base_y = round(refy + (t->base_y - refy) * sy);
X }
END_OF_FILE
if test 8385 -ne `wc -c <'xfig/scale.c'`; then
echo shar: \"'xfig/scale.c'\" unpacked with wrong size!
fi
# end of 'xfig/scale.c'
fi
echo shar: End of archive 10 \(of 15\).
cp /dev/null ark10isdone
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
dan
-----------------------------------------------------------
O'Reilly && Associates
argv at sun.com / argv at ora.com
632 Petaluma Ave, Sebastopol, CA 95472
800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list