ftoutln.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /***************************************************************************/
  2. /* */
  3. /* ftoutln.h */
  4. /* */
  5. /* Support for the FT_Outline type used to store glyph shapes of */
  6. /* most scalable font formats (specification). */
  7. /* */
  8. /* Copyright 1996-2003, 2005-2012 by */
  9. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  10. /* */
  11. /* This file is part of the FreeType project, and may only be used, */
  12. /* modified, and distributed under the terms of the FreeType project */
  13. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  14. /* this file you indicate that you have read the license and */
  15. /* understand and accept it fully. */
  16. /* */
  17. /***************************************************************************/
  18. #ifndef __FTOUTLN_H__
  19. #define __FTOUTLN_H__
  20. #include <ft2build.h>
  21. #include FT_FREETYPE_H
  22. #ifdef FREETYPE_H
  23. #error "freetype.h of FreeType 1 has been loaded!"
  24. #error "Please fix the directory search order for header files"
  25. #error "so that freetype.h of FreeType 2 is found first."
  26. #endif
  27. FT_BEGIN_HEADER
  28. /*************************************************************************/
  29. /* */
  30. /* <Section> */
  31. /* outline_processing */
  32. /* */
  33. /* <Title> */
  34. /* Outline Processing */
  35. /* */
  36. /* <Abstract> */
  37. /* Functions to create, transform, and render vectorial glyph images. */
  38. /* */
  39. /* <Description> */
  40. /* This section contains routines used to create and destroy scalable */
  41. /* glyph images known as `outlines'. These can also be measured, */
  42. /* transformed, and converted into bitmaps and pixmaps. */
  43. /* */
  44. /* <Order> */
  45. /* FT_Outline */
  46. /* FT_OUTLINE_FLAGS */
  47. /* FT_Outline_New */
  48. /* FT_Outline_Done */
  49. /* FT_Outline_Copy */
  50. /* FT_Outline_Translate */
  51. /* FT_Outline_Transform */
  52. /* FT_Outline_Embolden */
  53. /* FT_Outline_EmboldenXY */
  54. /* FT_Outline_Reverse */
  55. /* FT_Outline_Check */
  56. /* */
  57. /* FT_Outline_Get_CBox */
  58. /* FT_Outline_Get_BBox */
  59. /* */
  60. /* FT_Outline_Get_Bitmap */
  61. /* FT_Outline_Render */
  62. /* */
  63. /* FT_Outline_Decompose */
  64. /* FT_Outline_Funcs */
  65. /* FT_Outline_MoveTo_Func */
  66. /* FT_Outline_LineTo_Func */
  67. /* FT_Outline_ConicTo_Func */
  68. /* FT_Outline_CubicTo_Func */
  69. /* */
  70. /*************************************************************************/
  71. /*************************************************************************/
  72. /* */
  73. /* <Function> */
  74. /* FT_Outline_Decompose */
  75. /* */
  76. /* <Description> */
  77. /* Walk over an outline's structure to decompose it into individual */
  78. /* segments and Bézier arcs. This function also emits `move to' */
  79. /* operations to indicate the start of new contours in the outline. */
  80. /* */
  81. /* <Input> */
  82. /* outline :: A pointer to the source target. */
  83. /* */
  84. /* func_interface :: A table of `emitters', i.e., function pointers */
  85. /* called during decomposition to indicate path */
  86. /* operations. */
  87. /* */
  88. /* <InOut> */
  89. /* user :: A typeless pointer which is passed to each */
  90. /* emitter during the decomposition. It can be */
  91. /* used to store the state during the */
  92. /* decomposition. */
  93. /* */
  94. /* <Return> */
  95. /* FreeType error code. 0~means success. */
  96. /* */
  97. FT_EXPORT( FT_Error )
  98. FT_Outline_Decompose( FT_Outline* outline,
  99. const FT_Outline_Funcs* func_interface,
  100. void* user );
  101. /*************************************************************************/
  102. /* */
  103. /* <Function> */
  104. /* FT_Outline_New */
  105. /* */
  106. /* <Description> */
  107. /* Create a new outline of a given size. */
  108. /* */
  109. /* <Input> */
  110. /* library :: A handle to the library object from where the */
  111. /* outline is allocated. Note however that the new */
  112. /* outline will *not* necessarily be *freed*, when */
  113. /* destroying the library, by @FT_Done_FreeType. */
  114. /* */
  115. /* numPoints :: The maximum number of points within the outline. */
  116. /* Must be smaller than or equal to 0xFFFF (65535). */
  117. /* */
  118. /* numContours :: The maximum number of contours within the outline. */
  119. /* This value must be in the range 0 to `numPoints'. */
  120. /* */
  121. /* <Output> */
  122. /* anoutline :: A handle to the new outline. */
  123. /* */
  124. /* <Return> */
  125. /* FreeType error code. 0~means success. */
  126. /* */
  127. /* <Note> */
  128. /* The reason why this function takes a `library' parameter is simply */
  129. /* to use the library's memory allocator. */
  130. /* */
  131. FT_EXPORT( FT_Error )
  132. FT_Outline_New( FT_Library library,
  133. FT_UInt numPoints,
  134. FT_Int numContours,
  135. FT_Outline *anoutline );
  136. FT_EXPORT( FT_Error )
  137. FT_Outline_New_Internal( FT_Memory memory,
  138. FT_UInt numPoints,
  139. FT_Int numContours,
  140. FT_Outline *anoutline );
  141. /*************************************************************************/
  142. /* */
  143. /* <Function> */
  144. /* FT_Outline_Done */
  145. /* */
  146. /* <Description> */
  147. /* Destroy an outline created with @FT_Outline_New. */
  148. /* */
  149. /* <Input> */
  150. /* library :: A handle of the library object used to allocate the */
  151. /* outline. */
  152. /* */
  153. /* outline :: A pointer to the outline object to be discarded. */
  154. /* */
  155. /* <Return> */
  156. /* FreeType error code. 0~means success. */
  157. /* */
  158. /* <Note> */
  159. /* If the outline's `owner' field is not set, only the outline */
  160. /* descriptor will be released. */
  161. /* */
  162. /* The reason why this function takes an `library' parameter is */
  163. /* simply to use ft_mem_free(). */
  164. /* */
  165. FT_EXPORT( FT_Error )
  166. FT_Outline_Done( FT_Library library,
  167. FT_Outline* outline );
  168. FT_EXPORT( FT_Error )
  169. FT_Outline_Done_Internal( FT_Memory memory,
  170. FT_Outline* outline );
  171. /*************************************************************************/
  172. /* */
  173. /* <Function> */
  174. /* FT_Outline_Check */
  175. /* */
  176. /* <Description> */
  177. /* Check the contents of an outline descriptor. */
  178. /* */
  179. /* <Input> */
  180. /* outline :: A handle to a source outline. */
  181. /* */
  182. /* <Return> */
  183. /* FreeType error code. 0~means success. */
  184. /* */
  185. FT_EXPORT( FT_Error )
  186. FT_Outline_Check( FT_Outline* outline );
  187. /*************************************************************************/
  188. /* */
  189. /* <Function> */
  190. /* FT_Outline_Get_CBox */
  191. /* */
  192. /* <Description> */
  193. /* Return an outline's `control box'. The control box encloses all */
  194. /* the outline's points, including Bézier control points. Though it */
  195. /* coincides with the exact bounding box for most glyphs, it can be */
  196. /* slightly larger in some situations (like when rotating an outline */
  197. /* which contains Bézier outside arcs). */
  198. /* */
  199. /* Computing the control box is very fast, while getting the bounding */
  200. /* box can take much more time as it needs to walk over all segments */
  201. /* and arcs in the outline. To get the latter, you can use the */
  202. /* `ftbbox' component which is dedicated to this single task. */
  203. /* */
  204. /* <Input> */
  205. /* outline :: A pointer to the source outline descriptor. */
  206. /* */
  207. /* <Output> */
  208. /* acbox :: The outline's control box. */
  209. /* */
  210. /* <Note> */
  211. /* See @FT_Glyph_Get_CBox for a discussion of tricky fonts. */
  212. /* */
  213. FT_EXPORT( void )
  214. FT_Outline_Get_CBox( const FT_Outline* outline,
  215. FT_BBox *acbox );
  216. /*************************************************************************/
  217. /* */
  218. /* <Function> */
  219. /* FT_Outline_Translate */
  220. /* */
  221. /* <Description> */
  222. /* Apply a simple translation to the points of an outline. */
  223. /* */
  224. /* <InOut> */
  225. /* outline :: A pointer to the target outline descriptor. */
  226. /* */
  227. /* <Input> */
  228. /* xOffset :: The horizontal offset. */
  229. /* */
  230. /* yOffset :: The vertical offset. */
  231. /* */
  232. FT_EXPORT( void )
  233. FT_Outline_Translate( const FT_Outline* outline,
  234. FT_Pos xOffset,
  235. FT_Pos yOffset );
  236. /*************************************************************************/
  237. /* */
  238. /* <Function> */
  239. /* FT_Outline_Copy */
  240. /* */
  241. /* <Description> */
  242. /* Copy an outline into another one. Both objects must have the */
  243. /* same sizes (number of points & number of contours) when this */
  244. /* function is called. */
  245. /* */
  246. /* <Input> */
  247. /* source :: A handle to the source outline. */
  248. /* */
  249. /* <Output> */
  250. /* target :: A handle to the target outline. */
  251. /* */
  252. /* <Return> */
  253. /* FreeType error code. 0~means success. */
  254. /* */
  255. FT_EXPORT( FT_Error )
  256. FT_Outline_Copy( const FT_Outline* source,
  257. FT_Outline *target );
  258. /*************************************************************************/
  259. /* */
  260. /* <Function> */
  261. /* FT_Outline_Transform */
  262. /* */
  263. /* <Description> */
  264. /* Apply a simple 2x2 matrix to all of an outline's points. Useful */
  265. /* for applying rotations, slanting, flipping, etc. */
  266. /* */
  267. /* <InOut> */
  268. /* outline :: A pointer to the target outline descriptor. */
  269. /* */
  270. /* <Input> */
  271. /* matrix :: A pointer to the transformation matrix. */
  272. /* */
  273. /* <Note> */
  274. /* You can use @FT_Outline_Translate if you need to translate the */
  275. /* outline's points. */
  276. /* */
  277. FT_EXPORT( void )
  278. FT_Outline_Transform( const FT_Outline* outline,
  279. const FT_Matrix* matrix );
  280. /*************************************************************************/
  281. /* */
  282. /* <Function> */
  283. /* FT_Outline_Embolden */
  284. /* */
  285. /* <Description> */
  286. /* Embolden an outline. The new outline will be at most 4~times */
  287. /* `strength' pixels wider and higher. You may think of the left and */
  288. /* bottom borders as unchanged. */
  289. /* */
  290. /* Negative `strength' values to reduce the outline thickness are */
  291. /* possible also. */
  292. /* */
  293. /* <InOut> */
  294. /* outline :: A handle to the target outline. */
  295. /* */
  296. /* <Input> */
  297. /* strength :: How strong the glyph is emboldened. Expressed in */
  298. /* 26.6 pixel format. */
  299. /* */
  300. /* <Return> */
  301. /* FreeType error code. 0~means success. */
  302. /* */
  303. /* <Note> */
  304. /* The used algorithm to increase or decrease the thickness of the */
  305. /* glyph doesn't change the number of points; this means that certain */
  306. /* situations like acute angles or intersections are sometimes */
  307. /* handled incorrectly. */
  308. /* */
  309. /* If you need `better' metrics values you should call */
  310. /* @FT_Outline_Get_CBox or @FT_Outline_Get_BBox. */
  311. /* */
  312. /* Example call: */
  313. /* */
  314. /* { */
  315. /* FT_Load_Glyph( face, index, FT_LOAD_DEFAULT ); */
  316. /* if ( face->slot->format == FT_GLYPH_FORMAT_OUTLINE ) */
  317. /* FT_Outline_Embolden( &face->slot->outline, strength ); */
  318. /* } */
  319. /* */
  320. FT_EXPORT( FT_Error )
  321. FT_Outline_Embolden( FT_Outline* outline,
  322. FT_Pos strength );
  323. /*************************************************************************/
  324. /* */
  325. /* <Function> */
  326. /* FT_Outline_EmboldenXY */
  327. /* */
  328. /* <Description> */
  329. /* Embolden an outline. The new outline will be `xstrength' pixels */
  330. /* wider and `ystrength' pixels higher. Otherwise, it is similar to */
  331. /* @FT_Outline_Embolden, which uses the same strength in both */
  332. /* directions. */
  333. /* */
  334. FT_EXPORT( FT_Error )
  335. FT_Outline_EmboldenXY( FT_Outline* outline,
  336. FT_Pos xstrength,
  337. FT_Pos ystrength );
  338. /*************************************************************************/
  339. /* */
  340. /* <Function> */
  341. /* FT_Outline_Reverse */
  342. /* */
  343. /* <Description> */
  344. /* Reverse the drawing direction of an outline. This is used to */
  345. /* ensure consistent fill conventions for mirrored glyphs. */
  346. /* */
  347. /* <InOut> */
  348. /* outline :: A pointer to the target outline descriptor. */
  349. /* */
  350. /* <Note> */
  351. /* This function toggles the bit flag @FT_OUTLINE_REVERSE_FILL in */
  352. /* the outline's `flags' field. */
  353. /* */
  354. /* It shouldn't be used by a normal client application, unless it */
  355. /* knows what it is doing. */
  356. /* */
  357. FT_EXPORT( void )
  358. FT_Outline_Reverse( FT_Outline* outline );
  359. /*************************************************************************/
  360. /* */
  361. /* <Function> */
  362. /* FT_Outline_Get_Bitmap */
  363. /* */
  364. /* <Description> */
  365. /* Render an outline within a bitmap. The outline's image is simply */
  366. /* OR-ed to the target bitmap. */
  367. /* */
  368. /* <Input> */
  369. /* library :: A handle to a FreeType library object. */
  370. /* */
  371. /* outline :: A pointer to the source outline descriptor. */
  372. /* */
  373. /* <InOut> */
  374. /* abitmap :: A pointer to the target bitmap descriptor. */
  375. /* */
  376. /* <Return> */
  377. /* FreeType error code. 0~means success. */
  378. /* */
  379. /* <Note> */
  380. /* This function does NOT CREATE the bitmap, it only renders an */
  381. /* outline image within the one you pass to it! Consequently, the */
  382. /* various fields in `abitmap' should be set accordingly. */
  383. /* */
  384. /* It will use the raster corresponding to the default glyph format. */
  385. /* */
  386. /* The value of the `num_grays' field in `abitmap' is ignored. If */
  387. /* you select the gray-level rasterizer, and you want less than 256 */
  388. /* gray levels, you have to use @FT_Outline_Render directly. */
  389. /* */
  390. FT_EXPORT( FT_Error )
  391. FT_Outline_Get_Bitmap( FT_Library library,
  392. FT_Outline* outline,
  393. const FT_Bitmap *abitmap );
  394. /*************************************************************************/
  395. /* */
  396. /* <Function> */
  397. /* FT_Outline_Render */
  398. /* */
  399. /* <Description> */
  400. /* Render an outline within a bitmap using the current scan-convert. */
  401. /* This function uses an @FT_Raster_Params structure as an argument, */
  402. /* allowing advanced features like direct composition, translucency, */
  403. /* etc. */
  404. /* */
  405. /* <Input> */
  406. /* library :: A handle to a FreeType library object. */
  407. /* */
  408. /* outline :: A pointer to the source outline descriptor. */
  409. /* */
  410. /* <InOut> */
  411. /* params :: A pointer to an @FT_Raster_Params structure used to */
  412. /* describe the rendering operation. */
  413. /* */
  414. /* <Return> */
  415. /* FreeType error code. 0~means success. */
  416. /* */
  417. /* <Note> */
  418. /* You should know what you are doing and how @FT_Raster_Params works */
  419. /* to use this function. */
  420. /* */
  421. /* The field `params.source' will be set to `outline' before the scan */
  422. /* converter is called, which means that the value you give to it is */
  423. /* actually ignored. */
  424. /* */
  425. /* The gray-level rasterizer always uses 256 gray levels. If you */
  426. /* want less gray levels, you have to provide your own span callback. */
  427. /* See the @FT_RASTER_FLAG_DIRECT value of the `flags' field in the */
  428. /* @FT_Raster_Params structure for more details. */
  429. /* */
  430. FT_EXPORT( FT_Error )
  431. FT_Outline_Render( FT_Library library,
  432. FT_Outline* outline,
  433. FT_Raster_Params* params );
  434. /**************************************************************************
  435. *
  436. * @enum:
  437. * FT_Orientation
  438. *
  439. * @description:
  440. * A list of values used to describe an outline's contour orientation.
  441. *
  442. * The TrueType and PostScript specifications use different conventions
  443. * to determine whether outline contours should be filled or unfilled.
  444. *
  445. * @values:
  446. * FT_ORIENTATION_TRUETYPE ::
  447. * According to the TrueType specification, clockwise contours must
  448. * be filled, and counter-clockwise ones must be unfilled.
  449. *
  450. * FT_ORIENTATION_POSTSCRIPT ::
  451. * According to the PostScript specification, counter-clockwise contours
  452. * must be filled, and clockwise ones must be unfilled.
  453. *
  454. * FT_ORIENTATION_FILL_RIGHT ::
  455. * This is identical to @FT_ORIENTATION_TRUETYPE, but is used to
  456. * remember that in TrueType, everything that is to the right of
  457. * the drawing direction of a contour must be filled.
  458. *
  459. * FT_ORIENTATION_FILL_LEFT ::
  460. * This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to
  461. * remember that in PostScript, everything that is to the left of
  462. * the drawing direction of a contour must be filled.
  463. *
  464. * FT_ORIENTATION_NONE ::
  465. * The orientation cannot be determined. That is, different parts of
  466. * the glyph have different orientation.
  467. *
  468. */
  469. typedef enum FT_Orientation_
  470. {
  471. FT_ORIENTATION_TRUETYPE = 0,
  472. FT_ORIENTATION_POSTSCRIPT = 1,
  473. FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE,
  474. FT_ORIENTATION_FILL_LEFT = FT_ORIENTATION_POSTSCRIPT,
  475. FT_ORIENTATION_NONE
  476. } FT_Orientation;
  477. /**************************************************************************
  478. *
  479. * @function:
  480. * FT_Outline_Get_Orientation
  481. *
  482. * @description:
  483. * This function analyzes a glyph outline and tries to compute its
  484. * fill orientation (see @FT_Orientation). This is done by computing
  485. * the direction of each global horizontal and/or vertical extrema
  486. * within the outline.
  487. *
  488. * Note that this will return @FT_ORIENTATION_TRUETYPE for empty
  489. * outlines.
  490. *
  491. * @input:
  492. * outline ::
  493. * A handle to the source outline.
  494. *
  495. * @return:
  496. * The orientation.
  497. *
  498. */
  499. FT_EXPORT( FT_Orientation )
  500. FT_Outline_Get_Orientation( FT_Outline* outline );
  501. /* */
  502. FT_END_HEADER
  503. #endif /* __FTOUTLN_H__ */
  504. /* END */
  505. /* Local Variables: */
  506. /* coding: utf-8 */
  507. /* End: */