1 /* Copyright (C) 2000-2008 by George Williams */
2 /*
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5 
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer.
8 
9  * Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12 
13  * The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef _EDGELIST_H
28 #define _EDGELIST_H
29 #include "splinefont.h"
30 
31 typedef struct hints {
32     real base, width;
33     real b1, b2, e1, e2;
34     real ab, ae;
35     unsigned int adjustb: 1;
36     unsigned int adjuste: 1;
37     struct hints *next;
38 } Hints;
39 
40 /* Instead of y and x coordinates these are based on major and other */
41 /*  major maybe either x or y depending on what we're interested in */
42 /*  at the moment, and other will be the other one. Of course it's */
43 /*  consistant accross the datastructure at any given time */
44 typedef struct edge {
45     real mmin, mmax;		/* relative to es->mmin */
46     real t_mmin, t_mmax;
47     real tmin, tmax;
48     real o_mmin, o_mmax;
49     real t_cur, o_cur, m_cur;
50     unsigned int up: 1;		/* line is directed up in the spline list */
51     unsigned int max_adjusted: 1;	/* by hstem hints */
52     unsigned int min_adjusted: 1;
53     Spline *spline;		/* spline which generated this segment */
54     struct edge *esnext, *aenext;
55     struct edge *before, *after;
56     int last_opos, last_mpos;
57     real oldt;		/* only used for FindIntersections of RemoveOverlap */
58 } Edge;
59 
60 typedef struct edgelist {
61     Edge **edges;
62     int cnt;
63     real mmin, mmax;
64     real omin, omax;
65     real scale;
66     int bytes_per_line;
67     uint8 *bitmap;
68     Edge *last, *splinesetfirst;
69     SplineChar *sc;
70     int layer;
71     char *interesting;
72     int major, other;
73     unsigned int genmajoredges: 1;	/* generate a list of edges parallel to the major axis */
74     Edge *majors;		/* ordered so that lowest edge is first */
75     Edge *majorhold;		/* to hold major edges as we pass them and they become useless */
76     Hints *hhints, *vhints;
77     int is_overlap;
78     DBounds bbox;		/* Not always set. {m,o}{min,max} a provide scaled bbox, this is in glyph units */
79 } EdgeList;
80 
81 extern void FreeEdges(EdgeList *es);
82 extern double TOfNextMajor(Edge *e, EdgeList *es, double sought_y );
83 extern void FindEdgesSplineSet(SplinePointList *spl, EdgeList *es, int ignore_clip);
84 extern Edge *ActiveEdgesInsertNew(EdgeList *es, Edge *active,int i);
85 extern Edge *ActiveEdgesRefigure(EdgeList *es, Edge *active,real i);
86 extern Edge *ActiveEdgesFindStem(Edge *apt, Edge **prev, real i);
87 
88 /* Version which is better for everything other than rasterization */
89 /*  (I think) */
90 typedef struct edgeinfo {
91     /* The spline is broken up at all extrema. So... */
92     /*  The spline between tmin and tmax is monotonic in both coordinates */
93     /*  If the spline becomes vert/horizontal that will be at one of the */
94     /*   end points too */
95     Spline *spline;
96     real tmin, tmax;
97     real coordmin[2];
98     real coordmax[2];
99     unsigned int up: 1;
100     unsigned int hv: 1;
101     unsigned int hvbottom: 1;
102     unsigned int hvtop: 1;
103     unsigned int hor: 1;
104     unsigned int vert: 1;
105     unsigned int almosthor: 1;
106     unsigned int almostvert: 1;
107     unsigned int horattmin: 1;
108     unsigned int horattmax: 1;
109     unsigned int vertattmin: 1;
110     unsigned int vertattmax: 1;
111     unsigned hup: 1;
112     unsigned vup: 1;
113     real tcur;		/* Value of t for current major coord */
114     real ocur;		/* Value of the other coord for current major coord */
115     struct edgeinfo *next;
116     struct edgeinfo *ordered;
117     struct edgeinfo *aenext;
118     struct edgeinfo *splinenext;
119     SplineChar *sc;
120     int major;
121 } EI;
122 
123 typedef struct eilist {
124     EI *edges;
125     real coordmin[2];
126     real coordmax[2];
127     int low, high, cnt;
128     EI **ordered;
129     char *ends;			/* flag to say an edge ends on this line */
130     SplineChar *sc;
131     int layer;
132     int major;
133     EI *splinelast, *splinefirst;
134     EI **bottoms, **tops;	/* Used only be FindNeeded in RemoveOverlap */
135     unsigned leavetiny: 1;
136     enum overlap_type ot;
137 } EIList;
138 
139 extern void ElFreeEI(EIList *el);
140 extern void ELFindEdges(SplineChar *sc, EIList *el);
141 extern void ELOrder(EIList *el, int major );
142 extern real EITOfNextMajor(EI *e, EIList *el, real sought_m );
143 extern int EISameLine(EI *e, EI *n, real i, int major);
144 extern int EISkipExtremum(EI *e, real i, int major);
145 extern EI *EIActiveEdgesFindStem(EI *apt, real i, int major);
146 extern EI *EIActiveListReorder(EI *active,int *change);
147 extern EI *EIActiveEdgesRefigure(EIList *el, EI *active,real i,int major,
148 	int *_change);
149 #endif
150