/src/freetype/src/autofit/aftypes.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 370 lines · 172 code · 86 blank · 112 comment · 9 complexity · f3cf4c6c6419c8b5325027ce7582cb48 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* aftypes.h */
  4. /* */
  5. /* Auto-fitter types (specification only). */
  6. /* */
  7. /* Copyright 2003-2009, 2011 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. * The auto-fitter is a complete rewrite of the old auto-hinter.
  20. * Its main feature is the ability to differentiate between different
  21. * scripts in order to apply language-specific rules.
  22. *
  23. * The code has also been compartmentized into several entities that
  24. * should make algorithmic experimentation easier than with the old
  25. * code.
  26. *
  27. * Finally, we get rid of the Catharon license, since this code is
  28. * released under the FreeType one.
  29. *
  30. *************************************************************************/
  31. #ifndef __AFTYPES_H__
  32. #define __AFTYPES_H__
  33. #include <ft2build.h>
  34. #include FT_FREETYPE_H
  35. #include FT_OUTLINE_H
  36. #include FT_INTERNAL_OBJECTS_H
  37. #include FT_INTERNAL_DEBUG_H
  38. FT_BEGIN_HEADER
  39. /*************************************************************************/
  40. /*************************************************************************/
  41. /***** *****/
  42. /***** D E B U G G I N G *****/
  43. /***** *****/
  44. /*************************************************************************/
  45. /*************************************************************************/
  46. #ifdef FT_DEBUG_AUTOFIT
  47. #include FT_CONFIG_STANDARD_LIBRARY_H
  48. extern int _af_debug_disable_horz_hints;
  49. extern int _af_debug_disable_vert_hints;
  50. extern int _af_debug_disable_blue_hints;
  51. extern void* _af_debug_hints;
  52. #endif /* FT_DEBUG_AUTOFIT */
  53. /*************************************************************************/
  54. /*************************************************************************/
  55. /***** *****/
  56. /***** U T I L I T Y S T U F F *****/
  57. /***** *****/
  58. /*************************************************************************/
  59. /*************************************************************************/
  60. typedef struct AF_WidthRec_
  61. {
  62. FT_Pos org; /* original position/width in font units */
  63. FT_Pos cur; /* current/scaled position/width in device sub-pixels */
  64. FT_Pos fit; /* current/fitted position/width in device sub-pixels */
  65. } AF_WidthRec, *AF_Width;
  66. FT_LOCAL( void )
  67. af_sort_pos( FT_UInt count,
  68. FT_Pos* table );
  69. FT_LOCAL( void )
  70. af_sort_widths( FT_UInt count,
  71. AF_Width widths );
  72. /*************************************************************************/
  73. /*************************************************************************/
  74. /***** *****/
  75. /***** A N G L E T Y P E S *****/
  76. /***** *****/
  77. /*************************************************************************/
  78. /*************************************************************************/
  79. /*
  80. * The auto-fitter doesn't need a very high angular accuracy;
  81. * this allows us to speed up some computations considerably with a
  82. * light Cordic algorithm (see afangles.c).
  83. */
  84. typedef FT_Int AF_Angle;
  85. #define AF_ANGLE_PI 256
  86. #define AF_ANGLE_2PI ( AF_ANGLE_PI * 2 )
  87. #define AF_ANGLE_PI2 ( AF_ANGLE_PI / 2 )
  88. #define AF_ANGLE_PI4 ( AF_ANGLE_PI / 4 )
  89. #if 0
  90. /*
  91. * compute the angle of a given 2-D vector
  92. */
  93. FT_LOCAL( AF_Angle )
  94. af_angle_atan( FT_Pos dx,
  95. FT_Pos dy );
  96. /*
  97. * compute `angle2 - angle1'; the result is always within
  98. * the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
  99. */
  100. FT_LOCAL( AF_Angle )
  101. af_angle_diff( AF_Angle angle1,
  102. AF_Angle angle2 );
  103. #endif /* 0 */
  104. #define AF_ANGLE_DIFF( result, angle1, angle2 ) \
  105. FT_BEGIN_STMNT \
  106. AF_Angle _delta = (angle2) - (angle1); \
  107. \
  108. \
  109. _delta %= AF_ANGLE_2PI; \
  110. if ( _delta < 0 ) \
  111. _delta += AF_ANGLE_2PI; \
  112. \
  113. if ( _delta > AF_ANGLE_PI ) \
  114. _delta -= AF_ANGLE_2PI; \
  115. \
  116. result = _delta; \
  117. FT_END_STMNT
  118. /* opaque handle to glyph-specific hints -- see `afhints.h' for more
  119. * details
  120. */
  121. typedef struct AF_GlyphHintsRec_* AF_GlyphHints;
  122. /*************************************************************************/
  123. /*************************************************************************/
  124. /***** *****/
  125. /***** S C A L E R S *****/
  126. /***** *****/
  127. /*************************************************************************/
  128. /*************************************************************************/
  129. /*
  130. * A scaler models the target pixel device that will receive the
  131. * auto-hinted glyph image.
  132. */
  133. typedef enum AF_ScalerFlags_
  134. {
  135. AF_SCALER_FLAG_NO_HORIZONTAL = 1, /* disable horizontal hinting */
  136. AF_SCALER_FLAG_NO_VERTICAL = 2, /* disable vertical hinting */
  137. AF_SCALER_FLAG_NO_ADVANCE = 4 /* disable advance hinting */
  138. } AF_ScalerFlags;
  139. typedef struct AF_ScalerRec_
  140. {
  141. FT_Face face; /* source font face */
  142. FT_Fixed x_scale; /* from font units to 1/64th device pixels */
  143. FT_Fixed y_scale; /* from font units to 1/64th device pixels */
  144. FT_Pos x_delta; /* in 1/64th device pixels */
  145. FT_Pos y_delta; /* in 1/64th device pixels */
  146. FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc. */
  147. FT_UInt32 flags; /* additional control flags, see above */
  148. } AF_ScalerRec, *AF_Scaler;
  149. #define AF_SCALER_EQUAL_SCALES( a, b ) \
  150. ( (a)->x_scale == (b)->x_scale && \
  151. (a)->y_scale == (b)->y_scale && \
  152. (a)->x_delta == (b)->x_delta && \
  153. (a)->y_delta == (b)->y_delta )
  154. /*************************************************************************/
  155. /*************************************************************************/
  156. /***** *****/
  157. /***** S C R I P T S *****/
  158. /***** *****/
  159. /*************************************************************************/
  160. /*************************************************************************/
  161. /*
  162. * The list of known scripts. Each different script corresponds to the
  163. * following information:
  164. *
  165. * - A set of Unicode ranges to test whether the face supports the
  166. * script.
  167. *
  168. * - A specific global analyzer that will compute global metrics
  169. * specific to the script.
  170. *
  171. * - A specific glyph analyzer that will compute segments and
  172. * edges for each glyph covered by the script.
  173. *
  174. * - A specific grid-fitting algorithm that will distort the
  175. * scaled glyph outline according to the results of the glyph
  176. * analyzer.
  177. *
  178. * Note that a given analyzer and/or grid-fitting algorithm can be
  179. * used by more than one script.
  180. */
  181. typedef enum AF_Script_
  182. {
  183. AF_SCRIPT_NONE = 0,
  184. AF_SCRIPT_LATIN = 1,
  185. AF_SCRIPT_CJK = 2,
  186. AF_SCRIPT_INDIC = 3,
  187. #ifdef FT_OPTION_AUTOFIT2
  188. AF_SCRIPT_LATIN2,
  189. #endif
  190. /* add new scripts here. Don't forget to update the list in */
  191. /* `afglobal.c'. */
  192. AF_SCRIPT_MAX /* do not remove */
  193. } AF_Script;
  194. typedef struct AF_ScriptClassRec_ const* AF_ScriptClass;
  195. typedef struct AF_ScriptMetricsRec_
  196. {
  197. AF_ScriptClass clazz;
  198. AF_ScalerRec scaler;
  199. FT_Bool digits_have_same_width;
  200. } AF_ScriptMetricsRec, *AF_ScriptMetrics;
  201. /* This function parses an FT_Face to compute global metrics for
  202. * a specific script.
  203. */
  204. typedef FT_Error
  205. (*AF_Script_InitMetricsFunc)( AF_ScriptMetrics metrics,
  206. FT_Face face );
  207. typedef void
  208. (*AF_Script_ScaleMetricsFunc)( AF_ScriptMetrics metrics,
  209. AF_Scaler scaler );
  210. typedef void
  211. (*AF_Script_DoneMetricsFunc)( AF_ScriptMetrics metrics );
  212. typedef FT_Error
  213. (*AF_Script_InitHintsFunc)( AF_GlyphHints hints,
  214. AF_ScriptMetrics metrics );
  215. typedef void
  216. (*AF_Script_ApplyHintsFunc)( AF_GlyphHints hints,
  217. FT_Outline* outline,
  218. AF_ScriptMetrics metrics );
  219. typedef struct AF_Script_UniRangeRec_
  220. {
  221. FT_UInt32 first;
  222. FT_UInt32 last;
  223. } AF_Script_UniRangeRec;
  224. #define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
  225. typedef const AF_Script_UniRangeRec *AF_Script_UniRange;
  226. typedef struct AF_ScriptClassRec_
  227. {
  228. AF_Script script;
  229. AF_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
  230. FT_Offset script_metrics_size;
  231. AF_Script_InitMetricsFunc script_metrics_init;
  232. AF_Script_ScaleMetricsFunc script_metrics_scale;
  233. AF_Script_DoneMetricsFunc script_metrics_done;
  234. AF_Script_InitHintsFunc script_hints_init;
  235. AF_Script_ApplyHintsFunc script_hints_apply;
  236. } AF_ScriptClassRec;
  237. /* Declare and define vtables for classes */
  238. #ifndef FT_CONFIG_OPTION_PIC
  239. #define AF_DECLARE_SCRIPT_CLASS( script_class ) \
  240. FT_CALLBACK_TABLE const AF_ScriptClassRec \
  241. script_class;
  242. #define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, m_size, \
  243. m_init, m_scale, m_done, h_init, h_apply ) \
  244. FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec \
  245. script_class = \
  246. { \
  247. script_, \
  248. ranges, \
  249. \
  250. m_size, \
  251. \
  252. m_init, \
  253. m_scale, \
  254. m_done, \
  255. \
  256. h_init, \
  257. h_apply \
  258. };
  259. #else /* FT_CONFIG_OPTION_PIC */
  260. #define AF_DECLARE_SCRIPT_CLASS( script_class ) \
  261. FT_LOCAL( void ) \
  262. FT_Init_Class_##script_class( AF_ScriptClassRec* ac );
  263. #define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, m_size, \
  264. m_init, m_scale, m_done, h_init, h_apply ) \
  265. FT_LOCAL_DEF( void ) \
  266. FT_Init_Class_##script_class( AF_ScriptClassRec* ac ) \
  267. { \
  268. ac->script = script_; \
  269. ac->script_uni_ranges = ranges; \
  270. \
  271. ac->script_metrics_size = m_size; \
  272. \
  273. ac->script_metrics_init = m_init; \
  274. ac->script_metrics_scale = m_scale; \
  275. ac->script_metrics_done = m_done; \
  276. \
  277. ac->script_hints_init = h_init; \
  278. ac->script_hints_apply = h_apply; \
  279. }
  280. #endif /* FT_CONFIG_OPTION_PIC */
  281. /* */
  282. FT_END_HEADER
  283. #endif /* __AFTYPES_H__ */
  284. /* END */