1 /**************************************************************************** 2 * 3 * pshalgo.h 4 * 5 * PostScript hinting algorithm (specification). 6 * 7 * Copyright (C) 2001-2023 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 PSHALGO_H_ 20 #define PSHALGO_H_ 21 22 23 #include "pshrec.h" 24 #include "pshglob.h" 25 26 27 FT_BEGIN_HEADER 28 29 30 /* handle to Hint structure */ 31 typedef struct PSH_HintRec_* PSH_Hint; 32 33 34 /* hint bit-flags */ 35 #define PSH_HINT_GHOST PS_HINT_FLAG_GHOST 36 #define PSH_HINT_BOTTOM PS_HINT_FLAG_BOTTOM 37 #define PSH_HINT_ACTIVE 4U 38 #define PSH_HINT_FITTED 8U 39 40 41 #define psh_hint_is_active( x ) ( ( (x)->flags & PSH_HINT_ACTIVE ) != 0 ) 42 #define psh_hint_is_ghost( x ) ( ( (x)->flags & PSH_HINT_GHOST ) != 0 ) 43 #define psh_hint_is_fitted( x ) ( ( (x)->flags & PSH_HINT_FITTED ) != 0 ) 44 45 #define psh_hint_activate( x ) (x)->flags |= PSH_HINT_ACTIVE 46 #define psh_hint_deactivate( x ) (x)->flags &= ~PSH_HINT_ACTIVE 47 #define psh_hint_set_fitted( x ) (x)->flags |= PSH_HINT_FITTED 48 49 50 /* hint structure */ 51 typedef struct PSH_HintRec_ 52 { 53 FT_Int org_pos; 54 FT_Int org_len; 55 FT_Pos cur_pos; 56 FT_Pos cur_len; 57 FT_UInt flags; 58 PSH_Hint parent; 59 FT_Int order; 60 61 } PSH_HintRec; 62 63 64 /* this is an interpolation zone used for strong points; */ 65 /* weak points are interpolated according to their strong */ 66 /* neighbours */ 67 typedef struct PSH_ZoneRec_ 68 { 69 FT_Fixed scale; 70 FT_Fixed delta; 71 FT_Pos min; 72 FT_Pos max; 73 74 } PSH_ZoneRec, *PSH_Zone; 75 76 77 typedef struct PSH_Hint_TableRec_ 78 { 79 FT_UInt max_hints; 80 FT_UInt num_hints; 81 PSH_Hint hints; 82 PSH_Hint* sort; 83 PSH_Hint* sort_global; 84 FT_UInt num_zones; 85 PSH_ZoneRec* zones; 86 PSH_Zone zone; 87 PS_Mask_Table hint_masks; 88 PS_Mask_Table counter_masks; 89 90 } PSH_Hint_TableRec, *PSH_Hint_Table; 91 92 93 typedef struct PSH_PointRec_* PSH_Point; 94 typedef struct PSH_ContourRec_* PSH_Contour; 95 96 typedef enum PSH_Dir_ 97 { 98 PSH_DIR_NONE = 0, 99 PSH_DIR_UP = 1, 100 PSH_DIR_DOWN = 2, 101 PSH_DIR_VERTICAL = 1 | 2, 102 PSH_DIR_LEFT = 4, 103 PSH_DIR_RIGHT = 8, 104 PSH_DIR_HORIZONTAL = 4 | 8 105 106 } PSH_Dir; 107 108 109 /* the following bit-flags are computed once by the glyph */ 110 /* analyzer, for both dimensions */ 111 #define PSH_POINT_OFF 1U /* point is off the curve */ 112 #define PSH_POINT_SMOOTH 2U /* point is smooth */ 113 #define PSH_POINT_INFLEX 4U /* point is inflection */ 114 115 116 #define psh_point_is_smooth( p ) ( (p)->flags & PSH_POINT_SMOOTH ) 117 #define psh_point_is_off( p ) ( (p)->flags & PSH_POINT_OFF ) 118 #define psh_point_is_inflex( p ) ( (p)->flags & PSH_POINT_INFLEX ) 119 120 #define psh_point_set_smooth( p ) (p)->flags |= PSH_POINT_SMOOTH 121 #define psh_point_set_off( p ) (p)->flags |= PSH_POINT_OFF 122 #define psh_point_set_inflex( p ) (p)->flags |= PSH_POINT_INFLEX 123 124 125 /* the following bit-flags are re-computed for each dimension */ 126 #define PSH_POINT_STRONG 16U /* point is strong */ 127 #define PSH_POINT_FITTED 32U /* point is already fitted */ 128 #define PSH_POINT_EXTREMUM 64U /* point is local extremum */ 129 #define PSH_POINT_POSITIVE 128U /* extremum has positive contour flow */ 130 #define PSH_POINT_NEGATIVE 256U /* extremum has negative contour flow */ 131 #define PSH_POINT_EDGE_MIN 512U /* point is aligned to left/bottom stem edge */ 132 #define PSH_POINT_EDGE_MAX 1024U /* point is aligned to top/right stem edge */ 133 134 135 #define psh_point_is_strong( p ) ( (p)->flags2 & PSH_POINT_STRONG ) 136 #define psh_point_is_fitted( p ) ( (p)->flags2 & PSH_POINT_FITTED ) 137 #define psh_point_is_extremum( p ) ( (p)->flags2 & PSH_POINT_EXTREMUM ) 138 #define psh_point_is_positive( p ) ( (p)->flags2 & PSH_POINT_POSITIVE ) 139 #define psh_point_is_negative( p ) ( (p)->flags2 & PSH_POINT_NEGATIVE ) 140 #define psh_point_is_edge_min( p ) ( (p)->flags2 & PSH_POINT_EDGE_MIN ) 141 #define psh_point_is_edge_max( p ) ( (p)->flags2 & PSH_POINT_EDGE_MAX ) 142 143 #define psh_point_set_strong( p ) (p)->flags2 |= PSH_POINT_STRONG 144 #define psh_point_set_fitted( p ) (p)->flags2 |= PSH_POINT_FITTED 145 #define psh_point_set_extremum( p ) (p)->flags2 |= PSH_POINT_EXTREMUM 146 #define psh_point_set_positive( p ) (p)->flags2 |= PSH_POINT_POSITIVE 147 #define psh_point_set_negative( p ) (p)->flags2 |= PSH_POINT_NEGATIVE 148 #define psh_point_set_edge_min( p ) (p)->flags2 |= PSH_POINT_EDGE_MIN 149 #define psh_point_set_edge_max( p ) (p)->flags2 |= PSH_POINT_EDGE_MAX 150 151 152 typedef struct PSH_PointRec_ 153 { 154 PSH_Point prev; 155 PSH_Point next; 156 PSH_Contour contour; 157 FT_UInt flags; 158 FT_UInt flags2; 159 PSH_Dir dir_in; 160 PSH_Dir dir_out; 161 PSH_Hint hint; 162 FT_Pos org_u; 163 FT_Pos org_v; 164 FT_Pos cur_u; 165 #ifdef DEBUG_HINTER 166 FT_Pos org_x; 167 FT_Pos cur_x; 168 FT_Pos org_y; 169 FT_Pos cur_y; 170 FT_UInt flags_x; 171 FT_UInt flags_y; 172 #endif 173 174 } PSH_PointRec; 175 176 177 typedef struct PSH_ContourRec_ 178 { 179 PSH_Point start; 180 FT_UInt count; 181 182 } PSH_ContourRec; 183 184 185 typedef struct PSH_GlyphRec_ 186 { 187 FT_UInt num_points; 188 FT_UInt num_contours; 189 190 PSH_Point points; 191 PSH_Contour contours; 192 193 FT_Memory memory; 194 FT_Outline* outline; 195 PSH_Globals globals; 196 PSH_Hint_TableRec hint_tables[2]; 197 198 FT_Bool do_horz_hints; 199 FT_Bool do_vert_hints; 200 FT_Bool do_horz_snapping; 201 FT_Bool do_vert_snapping; 202 FT_Bool do_stem_adjust; 203 204 } PSH_GlyphRec, *PSH_Glyph; 205 206 207 #ifdef DEBUG_HINTER 208 extern PSH_Hint_Table ps_debug_hint_table; 209 210 typedef void 211 (*PSH_HintFunc)( PSH_Hint hint, 212 FT_Bool vertical ); 213 214 extern PSH_HintFunc ps_debug_hint_func; 215 216 extern PSH_Glyph ps_debug_glyph; 217 #endif 218 219 220 extern FT_Error 221 ps_hints_apply( PS_Hints ps_hints, 222 FT_Outline* outline, 223 PSH_Globals globals, 224 FT_Render_Mode hint_mode ); 225 226 227 FT_END_HEADER 228 229 230 #endif /* PSHALGO_H_ */ 231 232 233 /* END */ 234