/src/freetype/src/pshinter/pshalgo.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 255 lines · 168 code · 61 blank · 26 comment · 9 complexity · aa83c2ff5920b28bce38bfce94bb927b MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* pshalgo.h */
  4. /* */
  5. /* PostScript hinting algorithm (specification). */
  6. /* */
  7. /* Copyright 2001, 2002, 2003, 2008 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 __PSHALGO_H__
  18. #define __PSHALGO_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 PSH_HintRec_* PSH_Hint;
  25. /* hint bit-flags */
  26. typedef enum PSH_Hint_Flags_
  27. {
  28. PSH_HINT_GHOST = PS_HINT_FLAG_GHOST,
  29. PSH_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM,
  30. PSH_HINT_ACTIVE = 4,
  31. PSH_HINT_FITTED = 8
  32. } PSH_Hint_Flags;
  33. #define psh_hint_is_active( x ) ( ( (x)->flags & PSH_HINT_ACTIVE ) != 0 )
  34. #define psh_hint_is_ghost( x ) ( ( (x)->flags & PSH_HINT_GHOST ) != 0 )
  35. #define psh_hint_is_fitted( x ) ( ( (x)->flags & PSH_HINT_FITTED ) != 0 )
  36. #define psh_hint_activate( x ) (x)->flags |= PSH_HINT_ACTIVE
  37. #define psh_hint_deactivate( x ) (x)->flags &= ~PSH_HINT_ACTIVE
  38. #define psh_hint_set_fitted( x ) (x)->flags |= PSH_HINT_FITTED
  39. /* hint structure */
  40. typedef struct PSH_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. PSH_Hint parent;
  48. FT_Int order;
  49. } PSH_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 PSH_ZoneRec_
  54. {
  55. FT_Fixed scale;
  56. FT_Fixed delta;
  57. FT_Pos min;
  58. FT_Pos max;
  59. } PSH_ZoneRec, *PSH_Zone;
  60. typedef struct PSH_Hint_TableRec_
  61. {
  62. FT_UInt max_hints;
  63. FT_UInt num_hints;
  64. PSH_Hint hints;
  65. PSH_Hint* sort;
  66. PSH_Hint* sort_global;
  67. FT_UInt num_zones;
  68. PSH_ZoneRec* zones;
  69. PSH_Zone zone;
  70. PS_Mask_Table hint_masks;
  71. PS_Mask_Table counter_masks;
  72. } PSH_Hint_TableRec, *PSH_Hint_Table;
  73. typedef struct PSH_PointRec_* PSH_Point;
  74. typedef struct PSH_ContourRec_* PSH_Contour;
  75. enum
  76. {
  77. PSH_DIR_NONE = 4,
  78. PSH_DIR_UP = -1,
  79. PSH_DIR_DOWN = 1,
  80. PSH_DIR_LEFT = -2,
  81. PSH_DIR_RIGHT = 2
  82. };
  83. #define PSH_DIR_HORIZONTAL 2
  84. #define PSH_DIR_VERTICAL 1
  85. #define PSH_DIR_COMPARE( d1, d2 ) ( (d1) == (d2) || (d1) == -(d2) )
  86. #define PSH_DIR_IS_HORIZONTAL( d ) PSH_DIR_COMPARE( d, PSH_DIR_HORIZONTAL )
  87. #define PSH_DIR_IS_VERTICAL( d ) PSH_DIR_COMPARE( d, PSH_DIR_VERTICAL )
  88. /* the following bit-flags are computed once by the glyph */
  89. /* analyzer, for both dimensions */
  90. enum
  91. {
  92. PSH_POINT_OFF = 1, /* point is off the curve */
  93. PSH_POINT_SMOOTH = 2, /* point is smooth */
  94. PSH_POINT_INFLEX = 4 /* point is inflection */
  95. };
  96. #define psh_point_is_smooth( p ) ( (p)->flags & PSH_POINT_SMOOTH )
  97. #define psh_point_is_off( p ) ( (p)->flags & PSH_POINT_OFF )
  98. #define psh_point_is_inflex( p ) ( (p)->flags & PSH_POINT_INFLEX )
  99. #define psh_point_set_smooth( p ) (p)->flags |= PSH_POINT_SMOOTH
  100. #define psh_point_set_off( p ) (p)->flags |= PSH_POINT_OFF
  101. #define psh_point_set_inflex( p ) (p)->flags |= PSH_POINT_INFLEX
  102. /* the following bit-flags are re-computed for each dimension */
  103. enum
  104. {
  105. PSH_POINT_STRONG = 16, /* point is strong */
  106. PSH_POINT_FITTED = 32, /* point is already fitted */
  107. PSH_POINT_EXTREMUM = 64, /* point is local extremum */
  108. PSH_POINT_POSITIVE = 128, /* extremum has positive contour flow */
  109. PSH_POINT_NEGATIVE = 256, /* extremum has negative contour flow */
  110. PSH_POINT_EDGE_MIN = 512, /* point is aligned to left/bottom stem edge */
  111. PSH_POINT_EDGE_MAX = 1024 /* point is aligned to top/right stem edge */
  112. };
  113. #define psh_point_is_strong( p ) ( (p)->flags2 & PSH_POINT_STRONG )
  114. #define psh_point_is_fitted( p ) ( (p)->flags2 & PSH_POINT_FITTED )
  115. #define psh_point_is_extremum( p ) ( (p)->flags2 & PSH_POINT_EXTREMUM )
  116. #define psh_point_is_positive( p ) ( (p)->flags2 & PSH_POINT_POSITIVE )
  117. #define psh_point_is_negative( p ) ( (p)->flags2 & PSH_POINT_NEGATIVE )
  118. #define psh_point_is_edge_min( p ) ( (p)->flags2 & PSH_POINT_EDGE_MIN )
  119. #define psh_point_is_edge_max( p ) ( (p)->flags2 & PSH_POINT_EDGE_MAX )
  120. #define psh_point_set_strong( p ) (p)->flags2 |= PSH_POINT_STRONG
  121. #define psh_point_set_fitted( p ) (p)->flags2 |= PSH_POINT_FITTED
  122. #define psh_point_set_extremum( p ) (p)->flags2 |= PSH_POINT_EXTREMUM
  123. #define psh_point_set_positive( p ) (p)->flags2 |= PSH_POINT_POSITIVE
  124. #define psh_point_set_negative( p ) (p)->flags2 |= PSH_POINT_NEGATIVE
  125. #define psh_point_set_edge_min( p ) (p)->flags2 |= PSH_POINT_EDGE_MIN
  126. #define psh_point_set_edge_max( p ) (p)->flags2 |= PSH_POINT_EDGE_MAX
  127. typedef struct PSH_PointRec_
  128. {
  129. PSH_Point prev;
  130. PSH_Point next;
  131. PSH_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. PSH_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. } PSH_PointRec;
  151. #define PSH_POINT_EQUAL_ORG( a, b ) ( (a)->org_u == (b)->org_u && \
  152. (a)->org_v == (b)->org_v )
  153. #define PSH_POINT_ANGLE( a, b ) FT_Atan2( (b)->org_u - (a)->org_u, \
  154. (b)->org_v - (a)->org_v )
  155. typedef struct PSH_ContourRec_
  156. {
  157. PSH_Point start;
  158. FT_UInt count;
  159. } PSH_ContourRec;
  160. typedef struct PSH_GlyphRec_
  161. {
  162. FT_UInt num_points;
  163. FT_UInt num_contours;
  164. PSH_Point points;
  165. PSH_Contour contours;
  166. FT_Memory memory;
  167. FT_Outline* outline;
  168. PSH_Globals globals;
  169. PSH_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. FT_Bool do_stem_adjust;
  178. } PSH_GlyphRec, *PSH_Glyph;
  179. #ifdef DEBUG_HINTER
  180. extern PSH_Hint_Table ps_debug_hint_table;
  181. typedef void
  182. (*PSH_HintFunc)( PSH_Hint hint,
  183. FT_Bool vertical );
  184. extern PSH_HintFunc ps_debug_hint_func;
  185. extern PSH_Glyph ps_debug_glyph;
  186. #endif
  187. extern FT_Error
  188. ps_hints_apply( PS_Hints ps_hints,
  189. FT_Outline* outline,
  190. PSH_Globals globals,
  191. FT_Render_Mode hint_mode );
  192. FT_END_HEADER
  193. #endif /* __PSHALGO_H__ */
  194. /* END */