ftoutln.h 17 KB

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