ahtypes.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /***************************************************************************/
  2. /* */
  3. /* ahtypes.h */
  4. /* */
  5. /* General types and definitions for the auto-hint module */
  6. /* (specification only). */
  7. /* */
  8. /* Copyright 2000-2001, 2002 Catharon Productions Inc. */
  9. /* Author: David Turner */
  10. /* */
  11. /* This file is part of the Catharon Typography Project and shall only */
  12. /* be used, modified, and distributed under the terms of the Catharon */
  13. /* Open Source License that should come with this file under the name */
  14. /* `CatharonLicense.txt'. By continuing to use, modify, or distribute */
  15. /* this file you indicate that you have read the license and */
  16. /* understand and accept it fully. */
  17. /* */
  18. /* Note that this license is compatible with the FreeType license. */
  19. /* */
  20. /***************************************************************************/
  21. #ifndef __AHTYPES_H__
  22. #define __AHTYPES_H__
  23. #include <ft2build.h>
  24. #include FT_INTERNAL_OBJECTS_H
  25. #ifdef DEBUG_HINTER
  26. #include <../src/autohint/ahloader.h>
  27. #else
  28. #include "ahloader.h"
  29. #endif
  30. #define xxAH_DEBUG
  31. #ifdef AH_DEBUG
  32. #include <stdio.h>
  33. #define AH_LOG( x ) printf ## x
  34. #else
  35. #define AH_LOG( x ) do ; while ( 0 ) /* nothing */
  36. #endif /* AH_DEBUG */
  37. FT_BEGIN_HEADER
  38. /*************************************************************************/
  39. /*************************************************************************/
  40. /*************************************************************************/
  41. /**** ****/
  42. /**** COMPILE-TIME BUILD OPTIONS ****/
  43. /**** ****/
  44. /**** Toggle these configuration macros to experiment with `features' ****/
  45. /**** of the auto-hinter. ****/
  46. /**** ****/
  47. /*************************************************************************/
  48. /*************************************************************************/
  49. /*************************************************************************/
  50. /*************************************************************************/
  51. /* */
  52. /* If this option is defined, only strong interpolation will be used to */
  53. /* place the points between edges. Otherwise, `smooth' points are */
  54. /* detected and later hinted through weak interpolation to correct some */
  55. /* unpleasant artefacts. */
  56. /* */
  57. #undef AH_OPTION_NO_WEAK_INTERPOLATION
  58. /*************************************************************************/
  59. /* */
  60. /* If this option is defined, only weak interpolation will be used to */
  61. /* place the points between edges. Otherwise, `strong' points are */
  62. /* detected and later hinted through strong interpolation to correct */
  63. /* some unpleasant artefacts. */
  64. /* */
  65. #undef AH_OPTION_NO_STRONG_INTERPOLATION
  66. /*************************************************************************/
  67. /* */
  68. /* Undefine this macro if you don't want to hint the metrics. There is */
  69. /* no reason to do this (at least for non-CJK scripts), except for */
  70. /* experimentation. */
  71. /* */
  72. #undef AH_HINT_METRICS
  73. /*************************************************************************/
  74. /* */
  75. /* Define this macro if you do not want to insert extra edges at a */
  76. /* glyph's x and y extremum (if there isn't one already available). */
  77. /* This helps to reduce a number of artefacts and allows hinting of */
  78. /* metrics. */
  79. /* */
  80. #undef AH_OPTION_NO_EXTREMUM_EDGES
  81. /* don't touch for now */
  82. #define AH_MAX_WIDTHS 12
  83. #define AH_MAX_HEIGHTS 12
  84. /*************************************************************************/
  85. /*************************************************************************/
  86. /*************************************************************************/
  87. /**** ****/
  88. /**** TYPE DEFINITIONS ****/
  89. /**** ****/
  90. /*************************************************************************/
  91. /*************************************************************************/
  92. /*************************************************************************/
  93. /* see agangles.h */
  94. typedef FT_Int AH_Angle;
  95. /* hint flags */
  96. #define AH_FLAG_NONE 0
  97. /* bezier control points flags */
  98. #define AH_FLAG_CONIC 1
  99. #define AH_FLAG_CUBIC 2
  100. #define AH_FLAG_CONTROL ( AH_FLAG_CONIC | AH_FLAG_CUBIC )
  101. /* extrema flags */
  102. #define AH_FLAG_EXTREMA_X 4
  103. #define AH_FLAG_EXTREMA_Y 8
  104. /* roundness */
  105. #define AH_FLAG_ROUND_X 16
  106. #define AH_FLAG_ROUND_Y 32
  107. /* touched */
  108. #define AH_FLAG_TOUCH_X 64
  109. #define AH_FLAG_TOUCH_Y 128
  110. /* weak interpolation */
  111. #define AH_FLAG_WEAK_INTERPOLATION 256
  112. #define AH_FLAG_INFLECTION 512
  113. typedef FT_Int AH_Flags;
  114. /* edge hint flags */
  115. #define AH_EDGE_NORMAL 0
  116. #define AH_EDGE_ROUND 1
  117. #define AH_EDGE_SERIF 2
  118. #define AH_EDGE_DONE 4
  119. typedef FT_Int AH_Edge_Flags;
  120. /* hint directions -- the values are computed so that two vectors are */
  121. /* in opposite directions iff `dir1+dir2 == 0' */
  122. #define AH_DIR_NONE 4
  123. #define AH_DIR_RIGHT 1
  124. #define AH_DIR_LEFT -1
  125. #define AH_DIR_UP 2
  126. #define AH_DIR_DOWN -2
  127. typedef FT_Int AH_Direction;
  128. typedef struct AH_PointRec_* AH_Point;
  129. typedef struct AH_SegmentRec_* AH_Segment;
  130. typedef struct AH_EdgeRec_* AH_Edge;
  131. /*************************************************************************/
  132. /* */
  133. /* <Struct> */
  134. /* AH_PointRec */
  135. /* */
  136. /* <Description> */
  137. /* A structure used to model an outline point to the AH_OutlineRec */
  138. /* type. */
  139. /* */
  140. /* <Fields> */
  141. /* flags :: The current point hint flags. */
  142. /* */
  143. /* ox, oy :: The current original scaled coordinates. */
  144. /* */
  145. /* fx, fy :: The current coordinates in font units. */
  146. /* */
  147. /* x, y :: The current hinted coordinates. */
  148. /* */
  149. /* u, v :: Point coordinates -- meaning varies with context. */
  150. /* */
  151. /* in_dir :: The direction of the inwards vector (prev->point). */
  152. /* */
  153. /* out_dir :: The direction of the outwards vector (point->next). */
  154. /* */
  155. /* in_angle :: The angle of the inwards vector. */
  156. /* */
  157. /* out_angle :: The angle of the outwards vector. */
  158. /* */
  159. /* next :: The next point in same contour. */
  160. /* */
  161. /* prev :: The previous point in same contour. */
  162. /* */
  163. typedef struct AH_PointRec_
  164. {
  165. AH_Flags flags; /* point flags used by hinter */
  166. FT_Pos ox, oy;
  167. FT_Pos fx, fy;
  168. FT_Pos x, y;
  169. FT_Pos u, v;
  170. AH_Direction in_dir; /* direction of inwards vector */
  171. AH_Direction out_dir; /* direction of outwards vector */
  172. AH_Angle in_angle;
  173. AH_Angle out_angle;
  174. AH_Point next; /* next point in contour */
  175. AH_Point prev; /* previous point in contour */
  176. } AH_PointRec;
  177. /*************************************************************************/
  178. /* */
  179. /* <Struct> */
  180. /* AH_SegmentRec */
  181. /* */
  182. /* <Description> */
  183. /* A structure used to describe an edge segment to the auto-hinter. */
  184. /* A segment is simply a sequence of successive points located on the */
  185. /* same horizontal or vertical `position', in a given direction. */
  186. /* */
  187. /* <Fields> */
  188. /* flags :: The segment edge flags (straight, rounded, etc.). */
  189. /* */
  190. /* dir :: The segment direction. */
  191. /* */
  192. /* first :: The first point in the segment. */
  193. /* */
  194. /* last :: The last point in the segment. */
  195. /* */
  196. /* contour :: A pointer to the first point of the segment's */
  197. /* contour. */
  198. /* */
  199. /* pos :: The segment position in font units. */
  200. /* */
  201. /* size :: The segment size. */
  202. /* */
  203. /* edge :: The edge of the current segment. */
  204. /* */
  205. /* edge_next :: The next segment on the same edge. */
  206. /* */
  207. /* link :: The pairing segment for this edge. */
  208. /* */
  209. /* serif :: The primary segment for serifs. */
  210. /* */
  211. /* num_linked :: The number of other segments that link to this one. */
  212. /* */
  213. /* score :: Used to score the segment when selecting them. */
  214. /* */
  215. typedef struct AH_SegmentRec_
  216. {
  217. AH_Edge_Flags flags;
  218. AH_Direction dir;
  219. AH_Point first; /* first point in edge segment */
  220. AH_Point last; /* last point in edge segment */
  221. AH_Point* contour; /* ptr to first point of segment's contour */
  222. FT_Pos pos; /* position of segment */
  223. FT_Pos min_coord; /* minimum coordinate of segment */
  224. FT_Pos max_coord; /* maximum coordinate of segment */
  225. AH_Edge edge;
  226. AH_Segment edge_next;
  227. AH_Segment link; /* link segment */
  228. AH_Segment serif; /* primary segment for serifs */
  229. FT_Pos num_linked; /* number of linked segments */
  230. FT_Pos score;
  231. } AH_SegmentRec;
  232. /*************************************************************************/
  233. /* */
  234. /* <Struct> */
  235. /* AH_EdgeRec */
  236. /* */
  237. /* <Description> */
  238. /* A structure used to describe an edge, which really is a horizontal */
  239. /* or vertical coordinate to be hinted depending on the segments */
  240. /* located on it. */
  241. /* */
  242. /* <Fields> */
  243. /* flags :: The segment edge flags (straight, rounded, etc.). */
  244. /* */
  245. /* dir :: The main segment direction on this edge. */
  246. /* */
  247. /* first :: The first edge segment. */
  248. /* */
  249. /* last :: The last edge segment. */
  250. /* */
  251. /* fpos :: The original edge position in font units. */
  252. /* */
  253. /* opos :: The original scaled edge position. */
  254. /* */
  255. /* pos :: The hinted edge position. */
  256. /* */
  257. /* link :: The linked edge. */
  258. /* */
  259. /* serif :: The serif edge. */
  260. /* */
  261. /* num_paired :: The number of other edges that pair to this one. */
  262. /* */
  263. /* score :: Used to score the edge when selecting them. */
  264. /* */
  265. /* blue_edge :: Indicate the blue zone edge this edge is related to. */
  266. /* Only set for some of the horizontal edges in a Latin */
  267. /* font. */
  268. /* */
  269. typedef struct AH_EdgeRec_
  270. {
  271. AH_Edge_Flags flags;
  272. AH_Direction dir;
  273. AH_Segment first;
  274. AH_Segment last;
  275. FT_Pos fpos;
  276. FT_Pos opos;
  277. FT_Pos pos;
  278. AH_Edge link;
  279. AH_Edge serif;
  280. FT_Int num_linked;
  281. FT_Int score;
  282. FT_Pos* blue_edge;
  283. } AH_EdgeRec;
  284. /* an outline as seen by the hinter */
  285. typedef struct AH_OutlineRec_
  286. {
  287. FT_Memory memory;
  288. AH_Direction vert_major_dir; /* vertical major direction */
  289. AH_Direction horz_major_dir; /* horizontal major direction */
  290. FT_Fixed x_scale;
  291. FT_Fixed y_scale;
  292. FT_Pos edge_distance_threshold;
  293. FT_Int max_points;
  294. FT_Int num_points;
  295. AH_Point points;
  296. FT_Int max_contours;
  297. FT_Int num_contours;
  298. AH_Point * contours;
  299. FT_Int num_hedges;
  300. AH_Edge horz_edges;
  301. FT_Int num_vedges;
  302. AH_Edge vert_edges;
  303. FT_Int num_hsegments;
  304. AH_Segment horz_segments;
  305. FT_Int num_vsegments;
  306. AH_Segment vert_segments;
  307. } AH_OutlineRec, *AH_Outline;
  308. #define AH_BLUE_CAPITAL_TOP 0 /* THEZOCQS */
  309. #define AH_BLUE_CAPITAL_BOTTOM ( AH_BLUE_CAPITAL_TOP + 1 ) /* HEZLOCUS */
  310. #define AH_BLUE_SMALL_TOP ( AH_BLUE_CAPITAL_BOTTOM + 1 ) /* xzroesc */
  311. #define AH_BLUE_SMALL_BOTTOM ( AH_BLUE_SMALL_TOP + 1 ) /* xzroesc */
  312. #define AH_BLUE_SMALL_MINOR ( AH_BLUE_SMALL_BOTTOM + 1 ) /* pqgjy */
  313. #define AH_BLUE_MAX ( AH_BLUE_SMALL_MINOR + 1 )
  314. typedef FT_Int AH_Blue;
  315. #define AH_HINTER_MONOCHROME 1
  316. #define AH_HINTER_OPTIMIZE 2
  317. typedef FT_Int AH_Hinter_Flags;
  318. /*************************************************************************/
  319. /* */
  320. /* <Struct> */
  321. /* AH_GlobalsRec */
  322. /* */
  323. /* <Description> */
  324. /* Holds the global metrics for a given font face (be it in design */
  325. /* units or scaled pixel values). */
  326. /* */
  327. /* <Fields> */
  328. /* num_widths :: The number of widths. */
  329. /* */
  330. /* num_heights :: The number of heights. */
  331. /* */
  332. /* widths :: Snap widths, including standard one. */
  333. /* */
  334. /* heights :: Snap height, including standard one. */
  335. /* */
  336. /* blue_refs :: The reference positions of blue zones. */
  337. /* */
  338. /* blue_shoots :: The overshoot positions of blue zones. */
  339. /* */
  340. typedef struct AH_GlobalsRec_
  341. {
  342. FT_Int num_widths;
  343. FT_Int num_heights;
  344. FT_Pos stds[2];
  345. FT_Pos widths [AH_MAX_WIDTHS];
  346. FT_Pos heights[AH_MAX_HEIGHTS];
  347. FT_Pos blue_refs [AH_BLUE_MAX];
  348. FT_Pos blue_shoots[AH_BLUE_MAX];
  349. } AH_GlobalsRec, *AH_Globals;
  350. /*************************************************************************/
  351. /* */
  352. /* <Struct> */
  353. /* AH_Face_GlobalsRec */
  354. /* */
  355. /* <Description> */
  356. /* Holds the complete global metrics for a given font face (i.e., the */
  357. /* design units version + a scaled version + the current scales */
  358. /* used). */
  359. /* */
  360. /* <Fields> */
  361. /* face :: A handle to the source face object */
  362. /* */
  363. /* design :: The globals in font design units. */
  364. /* */
  365. /* scaled :: Scaled globals in sub-pixel values. */
  366. /* */
  367. /* x_scale :: The current horizontal scale. */
  368. /* */
  369. /* y_scale :: The current vertical scale. */
  370. /* */
  371. typedef struct AH_Face_GlobalsRec_
  372. {
  373. FT_Face face;
  374. AH_GlobalsRec design;
  375. AH_GlobalsRec scaled;
  376. FT_Fixed x_scale;
  377. FT_Fixed y_scale;
  378. FT_Bool control_overshoot;
  379. } AH_Face_GlobalsRec, *AH_Face_Globals;
  380. typedef struct AH_HinterRec
  381. {
  382. FT_Memory memory;
  383. AH_Hinter_Flags flags;
  384. FT_Int algorithm;
  385. FT_Face face;
  386. AH_Face_Globals globals;
  387. AH_Outline glyph;
  388. AH_Loader loader;
  389. FT_Vector pp1;
  390. FT_Vector pp2;
  391. FT_Bool transformed;
  392. FT_Vector trans_delta;
  393. FT_Matrix trans_matrix;
  394. FT_Bool do_horz_hints; /* disable X hinting */
  395. FT_Bool do_vert_hints; /* disable Y hinting */
  396. FT_Bool do_horz_snapping; /* disable X stem size snapping */
  397. FT_Bool do_vert_snapping; /* disable Y stem size snapping */
  398. } AH_HinterRec, *AH_Hinter;
  399. #ifdef DEBUG_HINTER
  400. extern AH_Hinter ah_debug_hinter;
  401. extern FT_Bool ah_debug_disable_horz;
  402. extern FT_Bool ah_debug_disable_vert;
  403. #else
  404. #define ah_debug_disable_horz 0
  405. #define ah_debug_disable_vert 0
  406. #endif /* DEBUG_HINTER */
  407. FT_END_HEADER
  408. #endif /* __AHTYPES_H__ */
  409. /* END */