xref: /inferno-os/libfreetype/pshalgo2.h (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 /***************************************************************************/
2 /*                                                                         */
3 /*  pshalgo2.h                                                             */
4 /*                                                                         */
5 /*    PostScript hinting algorithm 2 (specification).                      */
6 /*                                                                         */
7 /*  Copyright 2001 by                                                      */
8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9 /*                                                                         */
10 /*  This file is part of the FreeType project, and may only be used,       */
11 /*  modified, and distributed under the terms of the FreeType project      */
12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13 /*  this file you indicate that you have read the license and              */
14 /*  understand and accept it fully.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17 
18 
19 #ifndef __PSHALGO2_H__
20 #define __PSHALGO2_H__
21 
22 
23 #include "pshrec.h"
24 #include "pshglob.h"
25 #include FT_TRIGONOMETRY_H
26 
27 
28 FT_BEGIN_HEADER
29 
30 
31   typedef struct PSH2_HintRec_*  PSH2_Hint;
32 
33   typedef enum
34   {
35     PSH2_HINT_GHOST  = PS_HINT_FLAG_GHOST,
36     PSH2_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM,
37     PSH2_HINT_ACTIVE = 4,
38     PSH2_HINT_FITTED = 8
39 
40   } PSH2_Hint_Flags;
41 
42 
43 #define psh2_hint_is_active( x )  ( ( (x)->flags & PSH2_HINT_ACTIVE ) != 0 )
44 #define psh2_hint_is_ghost( x )   ( ( (x)->flags & PSH2_HINT_GHOST  ) != 0 )
45 #define psh2_hint_is_fitted( x )  ( ( (x)->flags & PSH2_HINT_FITTED ) != 0 )
46 
47 #define psh2_hint_activate( x )    (x)->flags |=  PSH2_HINT_ACTIVE
48 #define psh2_hint_deactivate( x )  (x)->flags &= ~PSH2_HINT_ACTIVE
49 #define psh2_hint_set_fitted( x )  (x)->flags |=  PSH2_HINT_FITTED
50 
51 
52   typedef struct  PSH2_HintRec_
53   {
54     FT_Int     org_pos;
55     FT_Int     org_len;
56     FT_Pos     cur_pos;
57     FT_Pos     cur_len;
58     FT_UInt    flags;
59     PSH2_Hint  parent;
60     FT_Int     order;
61 
62   } PSH2_HintRec;
63 
64 
65   /* this is an interpolation zone used for strong points;  */
66   /* weak points are interpolated according to their strong */
67   /* neighbours                                             */
68   typedef struct  PSH2_ZoneRec_
69   {
70     FT_Fixed  scale;
71     FT_Fixed  delta;
72     FT_Pos    min;
73     FT_Pos    max;
74 
75   } PSH2_ZoneRec, *PSH2_Zone;
76 
77 
78   typedef struct  PSH2_Hint_TableRec_
79   {
80     FT_UInt        max_hints;
81     FT_UInt        num_hints;
82     PSH2_Hint      hints;
83     PSH2_Hint*     sort;
84     PSH2_Hint*     sort_global;
85     FT_UInt        num_zones;
86     PSH2_Zone      zones;
87     PSH2_Zone      zone;
88     PS_Mask_Table  hint_masks;
89     PS_Mask_Table  counter_masks;
90 
91   } PSH2_Hint_TableRec, *PSH2_Hint_Table;
92 
93 
94   typedef struct PSH2_PointRec_*    PSH2_Point;
95   typedef struct PSH2_ContourRec_*  PSH2_Contour;
96 
97   enum
98   {
99     PSH2_DIR_NONE  =  4,
100     PSH2_DIR_UP    =  1,
101     PSH2_DIR_DOWN  = -1,
102     PSH2_DIR_LEFT  = -2,
103     PSH2_DIR_RIGHT =  2
104   };
105 
106   enum
107   {
108     PSH2_POINT_OFF    = 1,   /* point is off the curve  */
109     PSH2_POINT_STRONG = 2,   /* point is strong         */
110     PSH2_POINT_SMOOTH = 4,   /* point is smooth         */
111     PSH2_POINT_FITTED = 8    /* point is already fitted */
112   };
113 
114 
115   typedef struct  PSH2_PointRec_
116   {
117     PSH2_Point    prev;
118     PSH2_Point    next;
119     PSH2_Contour  contour;
120     FT_UInt       flags;
121     FT_Char       dir_in;
122     FT_Char       dir_out;
123     FT_Angle      angle_in;
124     FT_Angle      angle_out;
125     PSH2_Hint     hint;
126     FT_Pos        org_u;
127     FT_Pos        cur_u;
128 #ifdef DEBUG_HINTER
129     FT_Pos        org_x;
130     FT_Pos        cur_x;
131     FT_Pos        org_y;
132     FT_Pos        cur_y;
133     FT_UInt       flags_x;
134     FT_UInt       flags_y;
135 #endif
136 
137   } PSH2_PointRec;
138 
139 
140 #define psh2_point_is_strong( p )   ( (p)->flags & PSH2_POINT_STRONG )
141 #define psh2_point_is_fitted( p )   ( (p)->flags & PSH2_POINT_FITTED )
142 #define psh2_point_is_smooth( p )   ( (p)->flags & PSH2_POINT_SMOOTH )
143 
144 #define psh2_point_set_strong( p )  (p)->flags |= PSH2_POINT_STRONG
145 #define psh2_point_set_fitted( p )  (p)->flags |= PSH2_POINT_FITTED
146 #define psh2_point_set_smooth( p )  (p)->flags |= PSH2_POINT_SMOOTH
147 
148 
149   typedef struct  PSH2_ContourRec_
150   {
151     PSH2_Point  start;
152     FT_UInt     count;
153 
154   } PSH2_ContourRec;
155 
156 
157   typedef struct  PSH2_GlyphRec_
158   {
159     FT_UInt             num_points;
160     FT_UInt             num_contours;
161 
162     PSH2_Point          points;
163     PSH2_Contour        contours;
164 
165     FT_Memory           memory;
166     FT_Outline*         outline;
167     PSH_Globals         globals;
168     PSH2_Hint_TableRec  hint_tables[2];
169 
170     FT_Bool             vertical;
171     FT_Int              major_dir;
172     FT_Int              minor_dir;
173 
174   } PSH2_GlyphRec, *PSH2_Glyph;
175 
176 
177 #ifdef DEBUG_HINTER
178   extern PSH2_Hint_Table  ps2_debug_hint_table;
179 
180   typedef void
181   (*PSH2_HintFunc)( PSH2_Hint  hint,
182                     FT_Bool    vertical );
183 
184   extern PSH2_HintFunc    ps2_debug_hint_func;
185 
186   extern PSH2_Glyph       ps2_debug_glyph;
187 #endif
188 
189 
190   extern FT_Error
191   ps2_hints_apply( PS_Hints        ps_hints,
192                    FT_Outline*     outline,
193                    PSH_Globals     globals,
194                    FT_Render_Mode  hint_mode );
195 
196 
197 FT_END_HEADER
198 
199 
200 #endif /* __PSHALGO2_H__ */
201 
202 
203 /* END */
204