ftoutln.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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-2014 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 that 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. /* <Note> */
  98. /* A contour that contains a single point only is represented by a */
  99. /* `move to' operation followed by `line to' to the same point. In */
  100. /* most cases, it is best to filter this out before using the */
  101. /* outline for stroking purposes (otherwise it would result in a */
  102. /* visible dot when round caps are used). */
  103. /* */
  104. FT_EXPORT( FT_Error )
  105. FT_Outline_Decompose( FT_Outline* outline,
  106. const FT_Outline_Funcs* func_interface,
  107. void* user );
  108. /*************************************************************************/
  109. /* */
  110. /* <Function> */
  111. /* FT_Outline_New */
  112. /* */
  113. /* <Description> */
  114. /* Create a new outline of a given size. */
  115. /* */
  116. /* <Input> */
  117. /* library :: A handle to the library object from where the */
  118. /* outline is allocated. Note however that the new */
  119. /* outline will *not* necessarily be *freed*, when */
  120. /* destroying the library, by @FT_Done_FreeType. */
  121. /* */
  122. /* numPoints :: The maximum number of points within the outline. */
  123. /* Must be smaller than or equal to 0xFFFF (65535). */
  124. /* */
  125. /* numContours :: The maximum number of contours within the outline. */
  126. /* This value must be in the range 0 to `numPoints'. */
  127. /* */
  128. /* <Output> */
  129. /* anoutline :: A handle to the new outline. */
  130. /* */
  131. /* <Return> */
  132. /* FreeType error code. 0~means success. */
  133. /* */
  134. /* <Note> */
  135. /* The reason why this function takes a `library' parameter is simply */
  136. /* to use the library's memory allocator. */
  137. /* */
  138. FT_EXPORT( FT_Error )
  139. FT_Outline_New( FT_Library library,
  140. FT_UInt numPoints,
  141. FT_Int numContours,
  142. FT_Outline *anoutline );
  143. FT_EXPORT( FT_Error )
  144. FT_Outline_New_Internal( FT_Memory memory,
  145. FT_UInt numPoints,
  146. FT_Int numContours,
  147. FT_Outline *anoutline );
  148. /*************************************************************************/
  149. /* */
  150. /* <Function> */
  151. /* FT_Outline_Done */
  152. /* */
  153. /* <Description> */
  154. /* Destroy an outline created with @FT_Outline_New. */
  155. /* */
  156. /* <Input> */
  157. /* library :: A handle of the library object used to allocate the */
  158. /* outline. */
  159. /* */
  160. /* outline :: A pointer to the outline object to be discarded. */
  161. /* */
  162. /* <Return> */
  163. /* FreeType error code. 0~means success. */
  164. /* */
  165. /* <Note> */
  166. /* If the outline's `owner' field is not set, only the outline */
  167. /* descriptor will be released. */
  168. /* */
  169. /* The reason why this function takes an `library' parameter is */
  170. /* simply to use ft_mem_free(). */
  171. /* */
  172. FT_EXPORT( FT_Error )
  173. FT_Outline_Done( FT_Library library,
  174. FT_Outline* outline );
  175. FT_EXPORT( FT_Error )
  176. FT_Outline_Done_Internal( FT_Memory memory,
  177. FT_Outline* outline );
  178. /*************************************************************************/
  179. /* */
  180. /* <Function> */
  181. /* FT_Outline_Check */
  182. /* */
  183. /* <Description> */
  184. /* Check the contents of an outline descriptor. */
  185. /* */
  186. /* <Input> */
  187. /* outline :: A handle to a source outline. */
  188. /* */
  189. /* <Return> */
  190. /* FreeType error code. 0~means success. */
  191. /* */
  192. FT_EXPORT( FT_Error )
  193. FT_Outline_Check( FT_Outline* outline );
  194. /*************************************************************************/
  195. /* */
  196. /* <Function> */
  197. /* FT_Outline_Get_CBox */
  198. /* */
  199. /* <Description> */
  200. /* Return an outline's `control box'. The control box encloses all */
  201. /* the outline's points, including Bézier control points. Though it */
  202. /* coincides with the exact bounding box for most glyphs, it can be */
  203. /* slightly larger in some situations (like when rotating an outline */
  204. /* that contains Bézier outside arcs). */
  205. /* */
  206. /* Computing the control box is very fast, while getting the bounding */
  207. /* box can take much more time as it needs to walk over all segments */
  208. /* and arcs in the outline. To get the latter, you can use the */
  209. /* `ftbbox' component, which is dedicated to this single task. */
  210. /* */
  211. /* <Input> */
  212. /* outline :: A pointer to the source outline descriptor. */
  213. /* */
  214. /* <Output> */
  215. /* acbox :: The outline's control box. */
  216. /* */
  217. /* <Note> */
  218. /* See @FT_Glyph_Get_CBox for a discussion of tricky fonts. */
  219. /* */
  220. FT_EXPORT( void )
  221. FT_Outline_Get_CBox( const FT_Outline* outline,
  222. FT_BBox *acbox );
  223. /*************************************************************************/
  224. /* */
  225. /* <Function> */
  226. /* FT_Outline_Translate */
  227. /* */
  228. /* <Description> */
  229. /* Apply a simple translation to the points of an outline. */
  230. /* */
  231. /* <InOut> */
  232. /* outline :: A pointer to the target outline descriptor. */
  233. /* */
  234. /* <Input> */
  235. /* xOffset :: The horizontal offset. */
  236. /* */
  237. /* yOffset :: The vertical offset. */
  238. /* */
  239. FT_EXPORT( void )
  240. FT_Outline_Translate( const FT_Outline* outline,
  241. FT_Pos xOffset,
  242. FT_Pos yOffset );
  243. /*************************************************************************/
  244. /* */
  245. /* <Function> */
  246. /* FT_Outline_Copy */
  247. /* */
  248. /* <Description> */
  249. /* Copy an outline into another one. Both objects must have the */
  250. /* same sizes (number of points & number of contours) when this */
  251. /* function is called. */
  252. /* */
  253. /* <Input> */
  254. /* source :: A handle to the source outline. */
  255. /* */
  256. /* <Output> */
  257. /* target :: A handle to the target outline. */
  258. /* */
  259. /* <Return> */
  260. /* FreeType error code. 0~means success. */
  261. /* */
  262. FT_EXPORT( FT_Error )
  263. FT_Outline_Copy( const FT_Outline* source,
  264. FT_Outline *target );
  265. /*************************************************************************/
  266. /* */
  267. /* <Function> */
  268. /* FT_Outline_Transform */
  269. /* */
  270. /* <Description> */
  271. /* Apply a simple 2x2 matrix to all of an outline's points. Useful */
  272. /* for applying rotations, slanting, flipping, etc. */
  273. /* */
  274. /* <InOut> */
  275. /* outline :: A pointer to the target outline descriptor. */
  276. /* */
  277. /* <Input> */
  278. /* matrix :: A pointer to the transformation matrix. */
  279. /* */
  280. /* <Note> */
  281. /* You can use @FT_Outline_Translate if you need to translate the */
  282. /* outline's points. */
  283. /* */
  284. FT_EXPORT( void )
  285. FT_Outline_Transform( const FT_Outline* outline,
  286. const FT_Matrix* matrix );
  287. /*************************************************************************/
  288. /* */
  289. /* <Function> */
  290. /* FT_Outline_Embolden */
  291. /* */
  292. /* <Description> */
  293. /* Embolden an outline. The new outline will be at most 4~times */
  294. /* `strength' pixels wider and higher. You may think of the left and */
  295. /* bottom borders as unchanged. */
  296. /* */
  297. /* Negative `strength' values to reduce the outline thickness are */
  298. /* possible also. */
  299. /* */
  300. /* <InOut> */
  301. /* outline :: A handle to the target outline. */
  302. /* */
  303. /* <Input> */
  304. /* strength :: How strong the glyph is emboldened. Expressed in */
  305. /* 26.6 pixel format. */
  306. /* */
  307. /* <Return> */
  308. /* FreeType error code. 0~means success. */
  309. /* */
  310. /* <Note> */
  311. /* The used algorithm to increase or decrease the thickness of the */
  312. /* glyph doesn't change the number of points; this means that certain */
  313. /* situations like acute angles or intersections are sometimes */
  314. /* handled incorrectly. */
  315. /* */
  316. /* If you need `better' metrics values you should call */
  317. /* @FT_Outline_Get_CBox or @FT_Outline_Get_BBox. */
  318. /* */
  319. /* Example call: */
  320. /* */
  321. /* { */
  322. /* FT_Load_Glyph( face, index, FT_LOAD_DEFAULT ); */
  323. /* if ( face->slot->format == FT_GLYPH_FORMAT_OUTLINE ) */
  324. /* FT_Outline_Embolden( &face->slot->outline, strength ); */
  325. /* } */
  326. /* */
  327. /* To get meaningful results, font scaling values must be set with */
  328. /* functions like @FT_Set_Char_Size before calling FT_Render_Glyph. */
  329. /* */
  330. FT_EXPORT( FT_Error )
  331. FT_Outline_Embolden( FT_Outline* outline,
  332. FT_Pos strength );
  333. /*************************************************************************/
  334. /* */
  335. /* <Function> */
  336. /* FT_Outline_EmboldenXY */
  337. /* */
  338. /* <Description> */
  339. /* Embolden an outline. The new outline will be `xstrength' pixels */
  340. /* wider and `ystrength' pixels higher. Otherwise, it is similar to */
  341. /* @FT_Outline_Embolden, which uses the same strength in both */
  342. /* directions. */
  343. /* */
  344. FT_EXPORT( FT_Error )
  345. FT_Outline_EmboldenXY( FT_Outline* outline,
  346. FT_Pos xstrength,
  347. FT_Pos ystrength );
  348. /*************************************************************************/
  349. /* */
  350. /* <Function> */
  351. /* FT_Outline_Reverse */
  352. /* */
  353. /* <Description> */
  354. /* Reverse the drawing direction of an outline. This is used to */
  355. /* ensure consistent fill conventions for mirrored glyphs. */
  356. /* */
  357. /* <InOut> */
  358. /* outline :: A pointer to the target outline descriptor. */
  359. /* */
  360. /* <Note> */
  361. /* This function toggles the bit flag @FT_OUTLINE_REVERSE_FILL in */
  362. /* the outline's `flags' field. */
  363. /* */
  364. /* It shouldn't be used by a normal client application, unless it */
  365. /* knows what it is doing. */
  366. /* */
  367. FT_EXPORT( void )
  368. FT_Outline_Reverse( FT_Outline* outline );
  369. /*************************************************************************/
  370. /* */
  371. /* <Function> */
  372. /* FT_Outline_Get_Bitmap */
  373. /* */
  374. /* <Description> */
  375. /* Render an outline within a bitmap. The outline's image is simply */
  376. /* OR-ed to the target bitmap. */
  377. /* */
  378. /* <Input> */
  379. /* library :: A handle to a FreeType library object. */
  380. /* */
  381. /* outline :: A pointer to the source outline descriptor. */
  382. /* */
  383. /* <InOut> */
  384. /* abitmap :: A pointer to the target bitmap descriptor. */
  385. /* */
  386. /* <Return> */
  387. /* FreeType error code. 0~means success. */
  388. /* */
  389. /* <Note> */
  390. /* This function does NOT CREATE the bitmap, it only renders an */
  391. /* outline image within the one you pass to it! Consequently, the */
  392. /* various fields in `abitmap' should be set accordingly. */
  393. /* */
  394. /* It will use the raster corresponding to the default glyph format. */
  395. /* */
  396. /* The value of the `num_grays' field in `abitmap' is ignored. If */
  397. /* you select the gray-level rasterizer, and you want less than 256 */
  398. /* gray levels, you have to use @FT_Outline_Render directly. */
  399. /* */
  400. FT_EXPORT( FT_Error )
  401. FT_Outline_Get_Bitmap( FT_Library library,
  402. FT_Outline* outline,
  403. const FT_Bitmap *abitmap );
  404. /*************************************************************************/
  405. /* */
  406. /* <Function> */
  407. /* FT_Outline_Render */
  408. /* */
  409. /* <Description> */
  410. /* Render an outline within a bitmap using the current scan-convert. */
  411. /* This function uses an @FT_Raster_Params structure as an argument, */
  412. /* allowing advanced features like direct composition, translucency, */
  413. /* etc. */
  414. /* */
  415. /* <Input> */
  416. /* library :: A handle to a FreeType library object. */
  417. /* */
  418. /* outline :: A pointer to the source outline descriptor. */
  419. /* */
  420. /* <InOut> */
  421. /* params :: A pointer to an @FT_Raster_Params structure used to */
  422. /* describe the rendering operation. */
  423. /* */
  424. /* <Return> */
  425. /* FreeType error code. 0~means success. */
  426. /* */
  427. /* <Note> */
  428. /* You should know what you are doing and how @FT_Raster_Params works */
  429. /* to use this function. */
  430. /* */
  431. /* The field `params.source' will be set to `outline' before the scan */
  432. /* converter is called, which means that the value you give to it is */
  433. /* actually ignored. */
  434. /* */
  435. /* The gray-level rasterizer always uses 256 gray levels. If you */
  436. /* want less gray levels, you have to provide your own span callback. */
  437. /* See the @FT_RASTER_FLAG_DIRECT value of the `flags' field in the */
  438. /* @FT_Raster_Params structure for more details. */
  439. /* */
  440. FT_EXPORT( FT_Error )
  441. FT_Outline_Render( FT_Library library,
  442. FT_Outline* outline,
  443. FT_Raster_Params* params );
  444. /**************************************************************************
  445. *
  446. * @enum:
  447. * FT_Orientation
  448. *
  449. * @description:
  450. * A list of values used to describe an outline's contour orientation.
  451. *
  452. * The TrueType and PostScript specifications use different conventions
  453. * to determine whether outline contours should be filled or unfilled.
  454. *
  455. * @values:
  456. * FT_ORIENTATION_TRUETYPE ::
  457. * According to the TrueType specification, clockwise contours must
  458. * be filled, and counter-clockwise ones must be unfilled.
  459. *
  460. * FT_ORIENTATION_POSTSCRIPT ::
  461. * According to the PostScript specification, counter-clockwise contours
  462. * must be filled, and clockwise ones must be unfilled.
  463. *
  464. * FT_ORIENTATION_FILL_RIGHT ::
  465. * This is identical to @FT_ORIENTATION_TRUETYPE, but is used to
  466. * remember that in TrueType, everything that is to the right of
  467. * the drawing direction of a contour must be filled.
  468. *
  469. * FT_ORIENTATION_FILL_LEFT ::
  470. * This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to
  471. * remember that in PostScript, everything that is to the left of
  472. * the drawing direction of a contour must be filled.
  473. *
  474. * FT_ORIENTATION_NONE ::
  475. * The orientation cannot be determined. That is, different parts of
  476. * the glyph have different orientation.
  477. *
  478. */
  479. typedef enum FT_Orientation_
  480. {
  481. FT_ORIENTATION_TRUETYPE = 0,
  482. FT_ORIENTATION_POSTSCRIPT = 1,
  483. FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE,
  484. FT_ORIENTATION_FILL_LEFT = FT_ORIENTATION_POSTSCRIPT,
  485. FT_ORIENTATION_NONE
  486. } FT_Orientation;
  487. /**************************************************************************
  488. *
  489. * @function:
  490. * FT_Outline_Get_Orientation
  491. *
  492. * @description:
  493. * This function analyzes a glyph outline and tries to compute its
  494. * fill orientation (see @FT_Orientation). This is done by integrating
  495. * the total area covered by the outline. The positive integral
  496. * corresponds to the clockwise orientation and @FT_ORIENTATION_POSTSCRIPT
  497. * is returned. The negative integral corresponds to the counter-clockwise
  498. * orientation and @FT_ORIENTATION_TRUETYPE is returned.
  499. *
  500. * Note that this will return @FT_ORIENTATION_TRUETYPE for empty
  501. * outlines.
  502. *
  503. * @input:
  504. * outline ::
  505. * A handle to the source outline.
  506. *
  507. * @return:
  508. * The orientation.
  509. *
  510. */
  511. FT_EXPORT( FT_Orientation )
  512. FT_Outline_Get_Orientation( FT_Outline* outline );
  513. /* */
  514. FT_END_HEADER
  515. #endif /* __FTOUTLN_H__ */
  516. /* END */
  517. /* Local Variables: */
  518. /* coding: utf-8 */
  519. /* End: */