pshalgo3.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /***************************************************************************/
  2. /* */
  3. /* pshalgo3.h */
  4. /* */
  5. /* PostScript hinting algorithm 3 (specification). */
  6. /* */
  7. /* Copyright 2001, 2002 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. #ifndef __PSHALGO3_H__
  18. #define __PSHALGO3_H__
  19. #include "pshrec.h"
  20. #include "pshglob.h"
  21. #include FT_TRIGONOMETRY_H
  22. FT_BEGIN_HEADER
  23. /* handle to Hint structure */
  24. typedef struct PSH3_HintRec_* PSH3_Hint;
  25. /* hint bit-flags */
  26. typedef enum
  27. {
  28. PSH3_HINT_GHOST = PS_HINT_FLAG_GHOST,
  29. PSH3_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM,
  30. PSH3_HINT_ACTIVE = 4,
  31. PSH3_HINT_FITTED = 8
  32. } PSH3_Hint_Flags;
  33. #define psh3_hint_is_active( x ) ( ( (x)->flags & PSH3_HINT_ACTIVE ) != 0 )
  34. #define psh3_hint_is_ghost( x ) ( ( (x)->flags & PSH3_HINT_GHOST ) != 0 )
  35. #define psh3_hint_is_fitted( x ) ( ( (x)->flags & PSH3_HINT_FITTED ) != 0 )
  36. #define psh3_hint_activate( x ) (x)->flags |= PSH3_HINT_ACTIVE
  37. #define psh3_hint_deactivate( x ) (x)->flags &= ~PSH3_HINT_ACTIVE
  38. #define psh3_hint_set_fitted( x ) (x)->flags |= PSH3_HINT_FITTED
  39. /* hint structure */
  40. typedef struct PSH3_HintRec_
  41. {
  42. FT_Int org_pos;
  43. FT_Int org_len;
  44. FT_Pos cur_pos;
  45. FT_Pos cur_len;
  46. FT_UInt flags;
  47. PSH3_Hint parent;
  48. FT_Int order;
  49. } PSH3_HintRec;
  50. /* this is an interpolation zone used for strong points; */
  51. /* weak points are interpolated according to their strong */
  52. /* neighbours */
  53. typedef struct PSH3_ZoneRec_
  54. {
  55. FT_Fixed scale;
  56. FT_Fixed delta;
  57. FT_Pos min;
  58. FT_Pos max;
  59. } PSH3_ZoneRec, *PSH3_Zone;
  60. typedef struct PSH3_Hint_TableRec_
  61. {
  62. FT_UInt max_hints;
  63. FT_UInt num_hints;
  64. PSH3_Hint hints;
  65. PSH3_Hint* sort;
  66. PSH3_Hint* sort_global;
  67. FT_UInt num_zones;
  68. PSH3_ZoneRec* zones;
  69. PSH3_Zone zone;
  70. PS_Mask_Table hint_masks;
  71. PS_Mask_Table counter_masks;
  72. } PSH3_Hint_TableRec, *PSH3_Hint_Table;
  73. typedef struct PSH3_PointRec_* PSH3_Point;
  74. typedef struct PSH3_ContourRec_* PSH3_Contour;
  75. enum
  76. {
  77. PSH3_DIR_NONE = 4,
  78. PSH3_DIR_UP = -1,
  79. PSH3_DIR_DOWN = 1,
  80. PSH3_DIR_LEFT = -2,
  81. PSH3_DIR_RIGHT = 2
  82. };
  83. #define PSH3_DIR_HORIZONTAL 2
  84. #define PSH3_DIR_VERTICAL 1
  85. #define PSH3_DIR_COMPARE( d1, d2 ) ( (d1) == (d2) || (d1) == -(d2) )
  86. #define PSH3_DIR_IS_HORIZONTAL( d ) PSH3_DIR_COMPARE( d, PSH3_DIR_HORIZONTAL )
  87. #define PSH3_DIR_IS_VERTICAL( d ) PSH3_DIR_COMPARE( d, PSH3_DIR_VERTICAL )
  88. /* the following bit-flags are computed once by the glyph */
  89. /* analyzer, for both dimensions */
  90. enum
  91. {
  92. PSH3_POINT_OFF = 1, /* point is off the curve */
  93. PSH3_POINT_SMOOTH = 2, /* point is smooth */
  94. PSH3_POINT_INFLEX = 4 /* point is inflection */
  95. };
  96. #define psh3_point_is_smooth( p ) ( (p)->flags & PSH3_POINT_SMOOTH )
  97. #define psh3_point_is_off( p ) ( (p)->flags & PSH3_POINT_OFF )
  98. #define psh3_point_is_inflex( p ) ( (p)->flags & PSH3_POINT_INFLEX )
  99. #define psh3_point_set_smooth( p ) (p)->flags |= PSH3_POINT_SMOOTH
  100. #define psh3_point_set_off( p ) (p)->flags |= PSH3_POINT_OFF
  101. #define psh3_point_set_inflex( p ) (p)->flags |= PSH3_POINT_INFLEX
  102. /* the following bit-flags are re-computed for each dimension */
  103. enum
  104. {
  105. PSH3_POINT_STRONG = 16, /* point is strong */
  106. PSH3_POINT_FITTED = 32, /* point is already fitted */
  107. PSH3_POINT_EXTREMUM = 64, /* point is local extremum */
  108. PSH3_POINT_POSITIVE = 128, /* extremum has positive contour flow */
  109. PSH3_POINT_NEGATIVE = 256, /* extremum has negative contour flow */
  110. PSH3_POINT_EDGE_MIN = 512, /* point is aligned to left/bottom stem edge */
  111. PSH3_POINT_EDGE_MAX = 1024 /* point is aligned to top/right stem edge */
  112. };
  113. #define psh3_point_is_strong( p ) ( (p)->flags2 & PSH3_POINT_STRONG )
  114. #define psh3_point_is_fitted( p ) ( (p)->flags2 & PSH3_POINT_FITTED )
  115. #define psh3_point_is_extremum( p ) ( (p)->flags2 & PSH3_POINT_EXTREMUM )
  116. #define psh3_point_is_positive( p ) ( (p)->flags2 & PSH3_POINT_POSITIVE )
  117. #define psh3_point_is_negative( p ) ( (p)->flags2 & PSH3_POINT_NEGATIVE )
  118. #define psh3_point_is_edge_min( p ) ( (p)->flags2 & PSH3_POINT_EDGE_MIN )
  119. #define psh3_point_is_edge_max( p ) ( (p)->flags2 & PSH3_POINT_EDGE_MAX )
  120. #define psh3_point_set_strong( p ) (p)->flags2 |= PSH3_POINT_STRONG
  121. #define psh3_point_set_fitted( p ) (p)->flags2 |= PSH3_POINT_FITTED
  122. #define psh3_point_set_extremum( p ) (p)->flags2 |= PSH3_POINT_EXTREMUM
  123. #define psh3_point_set_positive( p ) (p)->flags2 |= PSH3_POINT_POSITIVE
  124. #define psh3_point_set_negative( p ) (p)->flags2 |= PSH3_POINT_NEGATIVE
  125. #define psh3_point_set_edge_min( p ) (p)->flags2 |= PSH3_POINT_EDGE_MIN
  126. #define psh3_point_set_edge_max( p ) (p)->flags2 |= PSH3_POINT_EDGE_MAX
  127. typedef struct PSH3_PointRec_
  128. {
  129. PSH3_Point prev;
  130. PSH3_Point next;
  131. PSH3_Contour contour;
  132. FT_UInt flags;
  133. FT_UInt flags2;
  134. FT_Char dir_in;
  135. FT_Char dir_out;
  136. FT_Angle angle_in;
  137. FT_Angle angle_out;
  138. PSH3_Hint hint;
  139. FT_Pos org_u;
  140. FT_Pos org_v;
  141. FT_Pos cur_u;
  142. #ifdef DEBUG_HINTER
  143. FT_Pos org_x;
  144. FT_Pos cur_x;
  145. FT_Pos org_y;
  146. FT_Pos cur_y;
  147. FT_UInt flags_x;
  148. FT_UInt flags_y;
  149. #endif
  150. } PSH3_PointRec;
  151. #define PSH3_POINT_EQUAL_ORG( a, b ) ( (a)->org_u == (b)->org_u && \
  152. (a)->org_v == (b)->org_v )
  153. #define PSH3_POINT_ANGLE( a, b ) FT_Atan2( (b)->org_u - (a)->org_u, \
  154. (b)->org_v - (a)->org_v )
  155. typedef struct PSH3_ContourRec_
  156. {
  157. PSH3_Point start;
  158. FT_UInt count;
  159. } PSH3_ContourRec;
  160. typedef struct PSH3_GlyphRec_
  161. {
  162. FT_UInt num_points;
  163. FT_UInt num_contours;
  164. PSH3_Point points;
  165. PSH3_Contour contours;
  166. FT_Memory memory;
  167. FT_Outline* outline;
  168. PSH_Globals globals;
  169. PSH3_Hint_TableRec hint_tables[2];
  170. FT_Bool vertical;
  171. FT_Int major_dir;
  172. FT_Int minor_dir;
  173. FT_Bool do_horz_hints;
  174. FT_Bool do_vert_hints;
  175. FT_Bool do_horz_snapping;
  176. FT_Bool do_vert_snapping;
  177. } PSH3_GlyphRec, *PSH3_Glyph;
  178. #ifdef DEBUG_HINTER
  179. extern PSH3_Hint_Table ps3_debug_hint_table;
  180. typedef void
  181. (*PSH3_HintFunc)( PSH3_Hint hint,
  182. FT_Bool vertical );
  183. extern PSH3_HintFunc ps3_debug_hint_func;
  184. extern PSH3_Glyph ps3_debug_glyph;
  185. #endif
  186. extern FT_Error
  187. ps3_hints_apply( PS_Hints ps_hints,
  188. FT_Outline* outline,
  189. PSH_Globals globals,
  190. FT_Render_Mode hint_mode );
  191. FT_END_HEADER
  192. #endif /* __PSHALGO3_H__ */
  193. /* END */