ftcffdrv.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /***************************************************************************/
  2. /* */
  3. /* ftcffdrv.h */
  4. /* */
  5. /* FreeType API for controlling the CFF driver (specification only). */
  6. /* */
  7. /* Copyright 2013, 2014 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 __FTCFFDRV_H__
  18. #define __FTCFFDRV_H__
  19. #include <ft2build.h>
  20. #include FT_FREETYPE_H
  21. #ifdef FREETYPE_H
  22. #error "freetype.h of FreeType 1 has been loaded!"
  23. #error "Please fix the directory search order for header files"
  24. #error "so that freetype.h of FreeType 2 is found first."
  25. #endif
  26. FT_BEGIN_HEADER
  27. /**************************************************************************
  28. *
  29. * @section:
  30. * cff_driver
  31. *
  32. * @title:
  33. * The CFF driver
  34. *
  35. * @abstract:
  36. * Controlling the CFF driver module.
  37. *
  38. * @description:
  39. * While FreeType's CFF driver doesn't expose API functions by itself,
  40. * it is possible to control its behaviour with @FT_Property_Set and
  41. * @FT_Property_Get. The list below gives the available properties
  42. * together with the necessary macros and structures.
  43. *
  44. * The CFF driver's module name is `cff'.
  45. *
  46. * *Hinting* *and* *antialiasing* *principles* *of* *the* *new* *engine*
  47. *
  48. * The rasterizer is positioning horizontal features (e.g., ascender
  49. * height & x-height, or crossbars) on the pixel grid and minimizing the
  50. * amount of antialiasing applied to them, while placing vertical
  51. * features (vertical stems) on the pixel grid without hinting, thus
  52. * representing the stem position and weight accurately. Sometimes the
  53. * vertical stems may be only partially black. In this context,
  54. * `antialiasing' means that stems are not positioned exactly on pixel
  55. * borders, causing a fuzzy appearance.
  56. *
  57. * There are two principles behind this approach.
  58. *
  59. * 1) No hinting in the horizontal direction: Unlike `superhinted'
  60. * TrueType, which changes glyph widths to accommodate regular
  61. * inter-glyph spacing, Adobe's approach is `faithful to the design' in
  62. * representing both the glyph width and the inter-glyph spacing
  63. * designed for the font. This makes the screen display as close as it
  64. * can be to the result one would get with infinite resolution, while
  65. * preserving what is considered the key characteristics of each glyph.
  66. * Note that the distances between unhinted and grid-fitted positions at
  67. * small sizes are comparable to kerning values and thus would be
  68. * noticeable (and distracting) while reading if hinting were applied.
  69. *
  70. * One of the reasons to not hint horizontally is antialiasing for LCD
  71. * screens: The pixel geometry of modern displays supplies three
  72. * vertical sub-pixels as the eye moves horizontally across each visible
  73. * pixel. On devices where we can be certain this characteristic is
  74. * present a rasterizer can take advantage of the sub-pixels to add
  75. * increments of weight. In Western writing systems this turns out to
  76. * be the more critical direction anyway; the weights and spacing of
  77. * vertical stems (see above) are central to Armenian, Cyrillic, Greek,
  78. * and Latin type designs. Even when the rasterizer uses greyscale
  79. * antialiasing instead of color (a necessary compromise when one
  80. * doesn't know the screen characteristics), the unhinted vertical
  81. * features preserve the design's weight and spacing much better than
  82. * aliased type would.
  83. *
  84. * 2) Aligment in the vertical direction: Weights and spacing along the
  85. * y~axis are less critical; what is much more important is the visual
  86. * alignment of related features (like cap-height and x-height). The
  87. * sense of alignment for these is enhanced by the sharpness of grid-fit
  88. * edges, while the cruder vertical resolution (full pixels instead of
  89. * 1/3 pixels) is less of a problem.
  90. *
  91. * On the technical side, horizontal alignment zones for ascender,
  92. * x-height, and other important height values (traditionally called
  93. * `blue zones') as defined in the font are positioned independently,
  94. * each being rounded to the nearest pixel edge, taking care of
  95. * overshoot suppression at small sizes, stem darkening, and scaling.
  96. *
  97. * Hstems (this is, hint values defined in the font to help align
  98. * horizontal features) that fall within a blue zone are said to be
  99. * `captured' and are aligned to that zone. Uncaptured stems are moved
  100. * in one of four ways, top edge up or down, bottom edge up or down.
  101. * Unless there are conflicting hstems, the smallest movement is taken
  102. * to minimize distortion.
  103. *
  104. * @order:
  105. * hinting-engine
  106. * no-stem-darkening
  107. * darkening-parameters
  108. *
  109. */
  110. /**************************************************************************
  111. *
  112. * @property:
  113. * hinting-engine
  114. *
  115. * @description:
  116. * Thanks to Adobe, which contributed a new hinting (and parsing)
  117. * engine, an application can select between `freetype' and `adobe' if
  118. * compiled with CFF_CONFIG_OPTION_OLD_ENGINE. If this configuration
  119. * macro isn't defined, `hinting-engine' does nothing.
  120. *
  121. * The default engine is `freetype' if CFF_CONFIG_OPTION_OLD_ENGINE is
  122. * defined, and `adobe' otherwise.
  123. *
  124. * The following example code demonstrates how to select Adobe's hinting
  125. * engine (omitting the error handling).
  126. *
  127. * {
  128. * FT_Library library;
  129. * FT_UInt hinting_engine = FT_CFF_HINTING_ADOBE;
  130. *
  131. *
  132. * FT_Init_FreeType( &library );
  133. *
  134. * FT_Property_Set( library, "cff",
  135. * "hinting-engine", &hinting_engine );
  136. * }
  137. *
  138. * @note:
  139. * This property can be used with @FT_Property_Get also.
  140. *
  141. */
  142. /**************************************************************************
  143. *
  144. * @enum:
  145. * FT_CFF_HINTING_XXX
  146. *
  147. * @description:
  148. * A list of constants used for the @hinting-engine property to select
  149. * the hinting engine for CFF fonts.
  150. *
  151. * @values:
  152. * FT_CFF_HINTING_FREETYPE ::
  153. * Use the old FreeType hinting engine.
  154. *
  155. * FT_CFF_HINTING_ADOBE ::
  156. * Use the hinting engine contributed by Adobe.
  157. *
  158. */
  159. #define FT_CFF_HINTING_FREETYPE 0
  160. #define FT_CFF_HINTING_ADOBE 1
  161. /**************************************************************************
  162. *
  163. * @property:
  164. * no-stem-darkening
  165. *
  166. * @description:
  167. * By default, the Adobe CFF engine darkens stems at smaller sizes,
  168. * regardless of hinting, to enhance contrast. This feature requires
  169. * a rendering system with proper gamma correction. Setting this
  170. * property, stem darkening gets switched off.
  171. *
  172. * Note that stem darkening is never applied if @FT_LOAD_NO_SCALE is set.
  173. *
  174. * {
  175. * FT_Library library;
  176. * FT_Bool no_stem_darkening = TRUE;
  177. *
  178. *
  179. * FT_Init_FreeType( &library );
  180. *
  181. * FT_Property_Set( library, "cff",
  182. * "no-stem-darkening", &no_stem_darkening );
  183. * }
  184. *
  185. * @note:
  186. * This property can be used with @FT_Property_Get also.
  187. *
  188. */
  189. /**************************************************************************
  190. *
  191. * @property:
  192. * darkening-parameters
  193. *
  194. * @description:
  195. * By default, the Adobe CFF engine darkens stems as follows (if the
  196. * `no-stem-darkening' property isn't set):
  197. *
  198. * {
  199. * stem width <= 0.5px: darkening amount = 0.4px
  200. * stem width = 1px: darkening amount = 0.275px
  201. * stem width = 1.667px: darkening amount = 0.275px
  202. * stem width >= 2.333px: darkening amount = 0px
  203. * }
  204. *
  205. * and piecewise linear in-between. At configuration time, these four
  206. * control points can be set with the macro
  207. * `CFF_CONFIG_OPTION_DARKENING_PARAMETERS'. At runtime, the control
  208. * points can be changed using the `darkening-parameters' property, as
  209. * the following example demonstrates.
  210. *
  211. * {
  212. * FT_Library library;
  213. * FT_Int darken_params[8] = { 500, 300, // x1, y1
  214. * 1000, 200, // x2, y2
  215. * 1500, 100, // x3, y3
  216. * 2000, 0 }; // x4, y4
  217. *
  218. *
  219. * FT_Init_FreeType( &library );
  220. *
  221. * FT_Property_Set( library, "cff",
  222. * "darkening-parameters", darken_params );
  223. * }
  224. *
  225. * The x~values give the stem width, and the y~values the darkening
  226. * amount. The unit is 1000th of pixels. All coordinate values must be
  227. * positive; the x~values must be monotonically increasing; the
  228. * y~values must be monotonically decreasing and smaller than or
  229. * equal to 500 (corresponding to half a pixel); the slope of each
  230. * linear piece must be shallower than -1 (e.g., -.4).
  231. *
  232. * @note:
  233. * This property can be used with @FT_Property_Get also.
  234. *
  235. */
  236. /* */
  237. FT_END_HEADER
  238. #endif /* __FTCFFDRV_H__ */
  239. /* END */