/modules/freetype2/src/autofit/aftypes.h

http://github.com/zpao/v8monkey · C Header · 403 lines · 187 code · 93 blank · 123 comment · 12 complexity · 3568e69752b08f6dda71130127a85296 MD5 · raw file

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