ftoutln.h 34 KB

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