📄 paths.c
字号:
/* $XConsortium: paths.c,v 1.4 91/10/10 11:18:40 rws Exp $ *//* Copyright International Business Machines, Corp. 1991 * All Rights Reserved * Copyright Lexmark International, Inc. 1991 * All Rights Reserved * * License to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation, and that the name of IBM or Lexmark not be * used in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. * * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF THE * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN NO EVENT SHALL * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF * THIS SOFTWARE. */ /* PATHS CWEB V0021 ******** *//*:h1 id=paths.PATHS Module - Path Operator Handler This is the module that is responsible for building and transformingpath lists. &author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com) :h3.Include Files The included files are:*/#include <stdio.h>#include <stdlib.h> /* after the system includes (dsr) */#include "types.h"#include "objects.h"#include "spaces.h"#include "paths.h"#include "regions.h" /* understands about Union */#include "fonts.h" /* understands about TEXTTYPEs */#include "pictures.h" /* understands about handles */#include "strokes.h" /* understands how to coerce stroke paths */#include "trig.h"static int UnClose();/*:h3.Routines Available to the TYPE1IMAGER User The PATHS routines that are made available to the outside user are:*/ /*SHARED LINE(S) ORIGINATED HERE*//*:h3.Functions Provided to Other Modules The path routines that are made available to other TYPE1IMAGER modulesare defined here:*/ /*SHARED LINE(S) ORIGINATED HERE*//*NOTE: because of the casts put in the macros for Loc, ArcCA, Conic,RoundConic, PathSegment, and JoinSegment, we cannot use the macro nameswhen the functions are actually defined. We have to use the uniquenames with their unique first two characters. Thus, if anyone in thefuture ever decided to change the first two characters, it would not beenough just to change the macro (as it would for most other functions).He would have to also change the function definition.*//*:h3.Macros Provided to Other Modules The CONCAT macro is defined here and used in the STROKES module. See:hdref refid=pathmac..*/ /*SHARED LINE(S) ORIGINATED HERE*/ /*:h2.Path Segment Structures A path is represented as a linked list of the following structure:*/ /*SHARED LINE(S) ORIGINATED HERE*//*When 'link' is NULL, we are at the last segment in the path (surprise!). 'last' is only non-NULL on the first segment of a path,for all the other segments 'last' == NULL. We test for a non-NULL'last' (ISPATHANCHOR predicate) when we are given an alleged pathto make sure the user is not trying to pull a fast one on us. A path may be a collection of disjoint paths. Every break in thedisjoint path is represented by a MOVETYPE segment. Closed paths are discussed in :hdref refid=close.. :h3.CopyPath() - Physically Duplicating a Path This simple function illustrates moving through the path linked list.Duplicating a segment just involves making a copy of it, except fortext, which has some auxilliary things involved. We don't feelcompetent to duplicate text in this module, so we call someone whoknows how (in the FONTS module).*/struct segment *CopyPath(p0) register struct segment *p0; /* path to duplicate */{ register struct segment *p,*n=NULL,*last=NULL,*anchor; for (p = p0, anchor = NULL; p != NULL; p = p->link) { ARGCHECK((!ISPATHTYPE(p->type) || (p != p0 && p->last != NULL)), "CopyPath: invalid segment", p, NULL, (0), struct segment *); if (p->type == TEXTTYPE) n = (struct segment *) CopyText(p); else n = (struct segment *)Allocate(p->size, p, 0); n->last = NULL; if (anchor == NULL) anchor = n; else last->link = n; last = n; }/*At this point we have a chain of newly allocated segments hanging off'anchor'. We need to make sure the first segment points to the last:*/ if (anchor != NULL) { n->link = NULL; anchor->last = n; } return(anchor);}/*:h3.KillPath() - Destroying a Path Destroying a path is simply a matter of freeing each segment in thelinked list. Again, we let the experts handle text.*/void KillPath(p) register struct segment *p; /* path to destroy */{ register struct segment *linkp; /* temp register holding next segment*/ /* return conditional based on reference count 3-26-91 PNM */ if ( (--(p->references) > 1) || ( (p->references == 1) && !ISPERMANENT(p->flag) ) ) return; while (p != NULL) { if (!ISPATHTYPE(p->type)) { ArgErr("KillPath: bad segment", p, NULL); return; } linkp = p->link; if (p->type == TEXTTYPE) KillText(p); else Free(p); p = linkp; }} /*:h2 id=location."location" Objects The TYPE1IMAGER user creates and destroys objects of type "location". Theseobjects locate points for the primitive path operators. We play a trickhere and store these objects in the same "segment" structure used forpaths, with a type field == MOVETYPE. This allows the Line() operator, for example, to be very trivial:It merely stamps its input structure as a LINETYPE and returns it to thecaller--assuming, of course, the input structure was not permanent (asit usually isn't). :h3.The "movesegment" Template Structure This template is used as a generic segment structure for Allocate:*/ /* added reference field 1 to temporary template below 3-26-91 PNM */static struct segment movetemplate = { MOVETYPE, 0, 1, sizeof(struct segment), 0, NULL, NULL, {0, 0} };/*:h3.Loc() - Create an "Invisible Line" Between (0,0) and a Point */ struct segment *t1_Loc(S, x, y) register struct XYspace *S; /* coordinate space to interpret X,Y */ DOUBLE x,y; /* destination point */{ register struct segment *r; IfTrace3((MustTraceCalls),"..Loc(S=%p, x=%f, y=%f)\n", S, x, y); r = (struct segment *)Allocate(sizeof(struct segment), &movetemplate, 0); TYPECHECK("Loc", S, SPACETYPE, r, (0), struct segment *); r->last = r; r->context = S->context; (*S->convert)(&r->dest, S, x, y); ConsumeSpace(S); return(r);}/*:h3.ILoc() - Loc() With Integer Arguments */struct segment *ILoc(S, x, y) register struct XYspace *S; /* coordinate space to interpret X,Y */ register int x,y; /* destination point */{ register struct segment *r; IfTrace3((MustTraceCalls),"..ILoc(S=%p, x=%d, y=%d)\n", S, (LONG) x, (LONG) y); r = (struct segment *)Allocate(sizeof(struct segment), &movetemplate, 0); TYPECHECK("Loc", S, SPACETYPE, r, (0), struct segment *); r->last = r; r->context = S->context; (*S->iconvert)(&r->dest, S, (LONG) x, (LONG) y); ConsumeSpace(S); return(r);} /*:h3.SubLoc() - Vector Subtraction of Two Locition Objects This user operator subtracts two location objects, yielding a newlocation object that is the result. The symmetrical function AddLoc() is totally redundent with Join(),so it is not provided.*/ struct segment *SubLoc(p1, p2) register struct segment *p1; register struct segment *p2;{ IfTrace2((MustTraceCalls),"SubLoc(%p, %p)\n", p1, p2); ARGCHECK(!ISLOCATION(p1), "SubLoc: bad first arg", p1, NULL, (0), struct segment *); ARGCHECK(!ISLOCATION(p2), "SubLoc: bad second arg", p2, NULL, (0), struct segment *); p1 = UniquePath(p1); p1->dest.x -= p2->dest.x; p1->dest.y -= p2->dest.y; ConsumePath(p2); return(p1);} /*:h2.Straight Line Segments :h3.PathSegment() - Create a Generic Path Segment Many routines need a LINETYPE or MOVETYPE path segment, but do notwant to go through the external user's interface, because, for example,they already know the "fractpel" destination of the segment and theconversion is unnecessary. PathSegment() is an internal routineprovided to the rest of TYPE1IMAGER for handling these cases.*/ struct segment *t1_PathSegment(type, x, y) int type; /* LINETYPE or MOVETYPE */ fractpel x,y; /* where to go to, if known */{ register struct segment *r; /* newly created segment */ r = (struct segment *)Allocate(sizeof(struct segment), &movetemplate, 0); r->type = type; r->last = r; /* last points to itself for singleton */ r->dest.x = x; r->dest.y = y; return(r);}/*:h3.Line() - Create a Line Segment Between (0,0) and a Point P This involves just creating and filling out a segment structure:*/struct segment *Line(P) register struct segment *P; /* relevant coordinate space */{ IfTrace1((MustTraceCalls),"..Line(%p)\n", P); ARGCHECK(!ISLOCATION(P), "Line: arg not a location", P, NULL, (0), struct segment *); P = UniquePath(P); P->type = LINETYPE; return(P);}/*:h2.Curved Path Segments We need more points to describe curves. So, the structures for curvedpath segments are slightly different. The first part is identical;the curved structures are larger with the extra points on the end. :h3.Bezier Segment Structure We support third order Bezier curves. They are specified with fourcontrol points A, B, C, and D. The curve starts at A with slope ABand ends at D with slope CD. The curvature at the point A is inverselyrelated to the length |AB|, and the curvature at the point D isinversely related to the length |CD|. Point A is always point (0,0). */ /*SHARED LINE(S) ORIGINATED HERE*//*:h3.Bezier() - Generate a Bezier Segment This is just a simple matter of filling out a 'beziersegment' structure:*/ struct beziersegment *Bezier(B, C, D) register struct segment *B; /* second control point */ register struct segment *C; /* third control point */ register struct segment *D; /* fourth control point (ending point) */{/* added reference field of 1 to temporary template below 3-26-91 PNM */ static struct beziersegment template = { BEZIERTYPE, 0, 1, sizeof(struct beziersegment), 0, NULL, NULL, { 0, 0 }, { 0, 0 }, { 0, 0 } }; register struct beziersegment *r; /* output segment */ IfTrace3((MustTraceCalls),"..Bezier(%p, %p, %p)\n", B, C, D); ARGCHECK(!ISLOCATION(B), "Bezier: bad B", B, NULL, (2,C,D), struct beziersegment *); ARGCHECK(!ISLOCATION(C), "Bezier: bad C", C, NULL, (2,B,D), struct beziersegment *); ARGCHECK(!ISLOCATION(D), "Bezier: bad D", D, NULL, (2,B,C), struct beziersegment *); r = (struct beziersegment *)Allocate(sizeof(struct beziersegment), &template, 0); r->last = (struct segment *) r; r->dest.x = D->dest.x; r->dest.y = D->dest.y; r->B.x = B->dest.x; r->B.y = B->dest.y; r->C.x = C->dest.x; r->C.y = C->dest.y; ConsumePath(B); ConsumePath(C); ConsumePath(D); return(r);} /*:h2.Font "Hint" Segments :h3.Hint() - A Font 'Hint' Segment This is temporary code while we experiment with hints.*/ /*SHARED LINE(S) ORIGINATED HERE*/struct hintsegment *Hint(S, ref, width, orientation, hinttype, adjusttype, direction, label) struct XYspace *S;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -