1 /* Copyright (C) 2005-2008 by George Williams */
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
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.
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.
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.
32 typedef struct glyphdata
{
44 int realcnt
; /* Includes control points, excludes implied points */
45 int norefpcnt
; /* Does not include points in glyphs with references */
46 int pcnt
; /* Includes control points, includes implied points */
47 struct pointdata
*points
; /* Entries corresponding to control points are empty */
49 struct stemdata
*stems
;
51 struct linedata
*lines
;
52 struct stembundle
*hbundle
;
53 struct stembundle
*vbundle
;
54 struct stembundle
*ibundle
;
56 /* Temporary values, quickly freed */
59 struct monotonic
**space
;
64 struct pointdata
**pspace
;
66 double start
, end
, sbase
, ebase
;
67 int curved
, scurved
, ecurved
;
68 } *lspace
, *rspace
, *bothspace
, *activespace
;
73 typedef struct pointdata
{
76 int ttfindex
; /* normally same as sp->ttfindex, but needed for offcurve points */
77 BasePoint base
; /* normally same as sp->me, but needed for offcurve points */
78 BasePoint nextunit
, prevunit
; /* unit vectors pointing in the next/prev directions */
79 struct linedata
*nextline
, *prevline
; /* any other points lying on approximately the same line */
80 Spline
*nextedges
[2], *prevedges
[2]; /* There should always be a matching spline, which may end up as part of a stem, and may not */
82 double next_e_t
[2], prev_e_t
[2]; /* Location on other edge where our normal hits it */
84 int next_e_cnt
, prev_e_cnt
;
85 double next_dist
[2], prev_dist
[2]; /* Distance from the point to the matching edge */
86 struct stemdata
**nextstems
, **prevstems
;
87 int *next_is_l
, *prev_is_l
;
89 double nextlen
, prevlen
;
90 int value
; /* Temporary value, used to compare points assigned to the same edge and determine which one can be used as a reference point*/
91 unsigned int nextlinear
: 1;
92 unsigned int nextzero
: 1;
93 unsigned int prevlinear
: 1;
94 unsigned int prevzero
: 1;
95 unsigned int colinear
: 1;
96 unsigned int symetrical_h
: 1; /* Are next & prev symetrical? */
97 unsigned int symetrical_v
: 1; /* Are next & prev symetrical? */
98 unsigned int next_hor
: 1;
99 unsigned int next_ver
: 1;
100 unsigned int prev_hor
: 1;
101 unsigned int prev_ver
: 1;
102 unsigned int ticked
: 1;
103 uint8 touched
, affected
;
104 uint8 x_extr
, y_extr
;
105 uint8 x_corner
, y_corner
;
107 BasePoint newnext
, newprev
;
108 BasePoint posdir
; /* If point has been positioned in 1 direction, this is that direction */
109 double projection
; /* temporary value */
112 typedef struct linedata
{
118 struct pointdata
**points
;
121 typedef struct stemdata
{
122 BasePoint unit
; /* Unit vector pointing in direction of stem */
123 BasePoint l_to_r
; /* Unit vector pointing from left to right (across stem) */
124 BasePoint left
; /* a point on one side of the stem (not necissarily left, even for vertical stems) */
125 BasePoint right
; /* and one on the other */
126 BasePoint newunit
; /* Unit vector after repositioning (e. g. in Metafont routines) */
127 BasePoint newleft
, newright
;/* Left and right edges after repositioning */
128 int leftidx
, rightidx
; /* TTF indices of the left and right key points */
129 struct pointdata
*keypts
[4];/* Uppest and lowest points on left and right edges. Used for positioning diagonal stems */
130 double lmin
, lmax
, rmin
, rmax
;
132 int chunk_cnt
; /* number of separate point-pairs on this stem */
134 struct stemdata
*parent
;
137 uint8 lpotential
, rpotential
;
138 uint8 lnext
, rnext
; /* are we using the next/prev side of the left/right points */
141 uint8 stemcheat
; /* It's not a real stem, but it's something we'd like PostScript to hint for us */
142 uint8 is_ball
; /* Specifies if this chunk marks the opposite sides of a ball terminal (useful for TTF instructions) */
143 int l_e_idx
, r_e_idx
; /* Which of the opposed edges assigned to the left and right points corresponds to this chunk */
146 struct segment
*active
;
147 uint8 toobig
; /* Stem is fatter than tall, unlikely to be a real stem */
154 int blue
; /* Blue zone a ghost hint is attached to */
155 double len
, clen
; /* Length of linear segments. clen adds "length" of curved bits */
156 struct stembundle
*bundle
;
157 int lpcnt
, rpcnt
; /* Count of points assigned to left and right edges of this stem */
158 struct linedata
*leftline
, *rightline
;
159 struct stemdata
*master
, *next_c_m
, *prev_c_m
;
163 struct dependent_stem
{
164 struct stemdata
*stem
;
166 char dep_type
; /* can be 'a' (align), 'i' (interpolate), 'm' (move) or 's' (serif) */
167 } *dependent
; /* Lists other stems dependent from the given stem */
168 struct dependent_serif
{
169 struct stemdata
*stem
;
170 double width
; /* The distance from an edge of the main stem to the opposite edge of the serif stem */
173 } *serifs
; /* Lists serifs and other elements protruding from the base stem */
176 typedef struct vchunk
{
177 struct stem_chunk
*chunk
;
184 struct stembounds
*next
;
185 struct stemdata
*stem
;
190 struct splinesteminfo
{
192 struct stembounds
*sb
;
195 typedef struct stembundle
{
196 BasePoint unit
; /* All these stems are parallel, pointing in unit direction */
197 BasePoint l_to_r
; /* Axis along which these stems are ordered (normal to unit) */
198 BasePoint bp
; /* Base point for measuring by l_to_r (stem->lpos,rpos) */
199 int cnt
; /* Number of stems in the bundle */
200 struct stemdata
**stemlist
;
203 extern struct glyphdata
*GlyphDataBuild(SplineChar
*sc
, int layer
, BlueData
*bd
, int use_existing
);
204 extern struct glyphdata
*GlyphDataInit(SplineChar
*sc
, int layer
, double em_size
, int only_hv
);
205 extern struct glyphdata
*StemInfoToStemData( struct glyphdata
*gd
,StemInfo
*si
,int is_v
);
206 extern struct glyphdata
*DStemInfoToStemData( struct glyphdata
*gd
,DStemInfo
*dsi
);
207 extern int IsStemAssignedToPoint( struct pointdata
*pd
,struct stemdata
*stem
,int is_next
);
208 extern void GlyphDataFree(struct glyphdata
*gd
);
210 #endif /* _STEMDB_H_ */