1 /* Copyright (C) 2005-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 _STEMDB_H_ 28 # define _STEMDB_H_ 29 30 # include "pfaedit.h" 31 32 typedef struct glyphdata { 33 SplineFont *sf; 34 BlueData bd; 35 int fuzz; 36 SplineChar *sc; 37 int layer; 38 int emsize; 39 int order2; 40 int has_slant; 41 BasePoint slant_unit; 42 int ccnt; 43 int *contourends; 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 */ 48 int stemcnt; 49 struct stemdata *stems; 50 int linecnt; 51 struct linedata *lines; 52 struct stembundle *hbundle; 53 struct stembundle *vbundle; 54 struct stembundle *ibundle; 55 56 /* Temporary values, quickly freed */ 57 int mcnt; 58 struct monotonic *ms; 59 struct monotonic **space; 60 int scnt; 61 Spline **sspace; 62 struct st *stspace; 63 DBounds size; 64 struct pointdata **pspace; 65 struct segment { 66 double start, end, sbase, ebase; 67 int curved, scurved, ecurved; 68 } *lspace, *rspace, *bothspace, *activespace; 69 70 int only_hv; 71 } GlyphData; 72 73 typedef struct pointdata { 74 SplinePoint *sp; 75 SplineSet *ss; 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 */ 81 Spline *bothedge; 82 double next_e_t[2], prev_e_t[2]; /* Location on other edge where our normal hits it */ 83 double both_e_t; 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; 88 int nextcnt, prevcnt; 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; 106 BasePoint newpos; 107 BasePoint newnext, newprev; 108 BasePoint posdir; /* If point has been positioned in 1 direction, this is that direction */ 109 double projection; /* temporary value */ 110 } PointData; 111 112 typedef struct linedata { 113 BasePoint unit; 114 BasePoint online; 115 uint8 is_left; 116 int pcnt; 117 double length; 118 struct pointdata **points; 119 } LineData; 120 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; 131 double width; 132 int chunk_cnt; /* number of separate point-pairs on this stem */ 133 struct stem_chunk { 134 struct stemdata *parent; 135 struct pointdata *l; 136 struct pointdata *r; 137 uint8 lpotential, rpotential; 138 uint8 lnext, rnext; /* are we using the next/prev side of the left/right points */ 139 uint8 ltick, rtick; 140 uint8 stub; 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 */ 144 } *chunks; 145 int activecnt; 146 struct segment *active; 147 uint8 toobig; /* Stem is fatter than tall, unlikely to be a real stem */ 148 uint8 positioned; 149 uint8 ticked; 150 uint8 ghost; 151 uint8 bbox; 152 uint8 ldone, rdone; 153 uint8 italic; 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; 160 int confl_cnt; 161 int dep_cnt; 162 int serif_cnt; 163 struct dependent_stem { 164 struct stemdata *stem; 165 uint8 lbase; 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 */ 171 uint8 lbase; 172 uint8 is_ball; 173 } *serifs; /* Lists serifs and other elements protruding from the base stem */ 174 } StemData; 175 176 typedef struct vchunk { 177 struct stem_chunk *chunk; 178 double dist; 179 int parallel; 180 int value; 181 } VChunk; 182 183 struct stembounds { 184 struct stembounds *next; 185 struct stemdata *stem; 186 double tstart, tend; 187 uint8 isr; 188 }; 189 190 struct splinesteminfo { 191 Spline *s; 192 struct stembounds *sb; 193 }; 194 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; 201 } StemBundle; 202 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); 209 210 #endif /* _STEMDB_H_ */ 211