ftstroke.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /***************************************************************************/
  2. /* */
  3. /* ftstroke.h */
  4. /* */
  5. /* FreeType path stroker (specification). */
  6. /* */
  7. /* Copyright 2002-2006, 2008, 2009, 2011-2012 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 __FT_STROKE_H__
  18. #define __FT_STROKE_H__
  19. #include <ft2build.h>
  20. #include FT_OUTLINE_H
  21. #include FT_GLYPH_H
  22. FT_BEGIN_HEADER
  23. /************************************************************************
  24. *
  25. * @section:
  26. * glyph_stroker
  27. *
  28. * @title:
  29. * Glyph Stroker
  30. *
  31. * @abstract:
  32. * Generating bordered and stroked glyphs.
  33. *
  34. * @description:
  35. * This component generates stroked outlines of a given vectorial
  36. * glyph. It also allows you to retrieve the `outside' and/or the
  37. * `inside' borders of the stroke.
  38. *
  39. * This can be useful to generate `bordered' glyph, i.e., glyphs
  40. * displayed with a coloured (and anti-aliased) border around their
  41. * shape.
  42. */
  43. /**************************************************************
  44. *
  45. * @type:
  46. * FT_Stroker
  47. *
  48. * @description:
  49. * Opaque handler to a path stroker object.
  50. */
  51. typedef struct FT_StrokerRec_* FT_Stroker;
  52. /**************************************************************
  53. *
  54. * @enum:
  55. * FT_Stroker_LineJoin
  56. *
  57. * @description:
  58. * These values determine how two joining lines are rendered
  59. * in a stroker.
  60. *
  61. * @values:
  62. * FT_STROKER_LINEJOIN_ROUND ::
  63. * Used to render rounded line joins. Circular arcs are used
  64. * to join two lines smoothly.
  65. *
  66. * FT_STROKER_LINEJOIN_BEVEL ::
  67. * Used to render beveled line joins. The outer corner of
  68. * the joined lines is filled by enclosing the triangular
  69. * region of the corner with a straight line between the
  70. * outer corners of each stroke.
  71. *
  72. * FT_STROKER_LINEJOIN_MITER_FIXED ::
  73. * Used to render mitered line joins, with fixed bevels if the
  74. * miter limit is exceeded. The outer edges of the strokes
  75. * for the two segments are extended until they meet at an
  76. * angle. If the segments meet at too sharp an angle (such
  77. * that the miter would extend from the intersection of the
  78. * segments a distance greater than the product of the miter
  79. * limit value and the border radius), then a bevel join (see
  80. * above) is used instead. This prevents long spikes being
  81. * created. FT_STROKER_LINEJOIN_MITER_FIXED generates a miter
  82. * line join as used in PostScript and PDF.
  83. *
  84. * FT_STROKER_LINEJOIN_MITER_VARIABLE ::
  85. * FT_STROKER_LINEJOIN_MITER ::
  86. * Used to render mitered line joins, with variable bevels if
  87. * the miter limit is exceeded. The intersection of the
  88. * strokes is clipped at a line perpendicular to the bisector
  89. * of the angle between the strokes, at the distance from the
  90. * intersection of the segments equal to the product of the
  91. * miter limit value and the border radius. This prevents
  92. * long spikes being created.
  93. * FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line
  94. * join as used in XPS. FT_STROKER_LINEJOIN_MITER is an alias
  95. * for FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for
  96. * backwards compatibility.
  97. */
  98. typedef enum FT_Stroker_LineJoin_
  99. {
  100. FT_STROKER_LINEJOIN_ROUND = 0,
  101. FT_STROKER_LINEJOIN_BEVEL = 1,
  102. FT_STROKER_LINEJOIN_MITER_VARIABLE = 2,
  103. FT_STROKER_LINEJOIN_MITER = FT_STROKER_LINEJOIN_MITER_VARIABLE,
  104. FT_STROKER_LINEJOIN_MITER_FIXED = 3
  105. } FT_Stroker_LineJoin;
  106. /**************************************************************
  107. *
  108. * @enum:
  109. * FT_Stroker_LineCap
  110. *
  111. * @description:
  112. * These values determine how the end of opened sub-paths are
  113. * rendered in a stroke.
  114. *
  115. * @values:
  116. * FT_STROKER_LINECAP_BUTT ::
  117. * The end of lines is rendered as a full stop on the last
  118. * point itself.
  119. *
  120. * FT_STROKER_LINECAP_ROUND ::
  121. * The end of lines is rendered as a half-circle around the
  122. * last point.
  123. *
  124. * FT_STROKER_LINECAP_SQUARE ::
  125. * The end of lines is rendered as a square around the
  126. * last point.
  127. */
  128. typedef enum FT_Stroker_LineCap_
  129. {
  130. FT_STROKER_LINECAP_BUTT = 0,
  131. FT_STROKER_LINECAP_ROUND,
  132. FT_STROKER_LINECAP_SQUARE
  133. } FT_Stroker_LineCap;
  134. /**************************************************************
  135. *
  136. * @enum:
  137. * FT_StrokerBorder
  138. *
  139. * @description:
  140. * These values are used to select a given stroke border
  141. * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder.
  142. *
  143. * @values:
  144. * FT_STROKER_BORDER_LEFT ::
  145. * Select the left border, relative to the drawing direction.
  146. *
  147. * FT_STROKER_BORDER_RIGHT ::
  148. * Select the right border, relative to the drawing direction.
  149. *
  150. * @note:
  151. * Applications are generally interested in the `inside' and `outside'
  152. * borders. However, there is no direct mapping between these and the
  153. * `left' and `right' ones, since this really depends on the glyph's
  154. * drawing orientation, which varies between font formats.
  155. *
  156. * You can however use @FT_Outline_GetInsideBorder and
  157. * @FT_Outline_GetOutsideBorder to get these.
  158. */
  159. typedef enum FT_StrokerBorder_
  160. {
  161. FT_STROKER_BORDER_LEFT = 0,
  162. FT_STROKER_BORDER_RIGHT
  163. } FT_StrokerBorder;
  164. /**************************************************************
  165. *
  166. * @function:
  167. * FT_Outline_GetInsideBorder
  168. *
  169. * @description:
  170. * Retrieve the @FT_StrokerBorder value corresponding to the
  171. * `inside' borders of a given outline.
  172. *
  173. * @input:
  174. * outline ::
  175. * The source outline handle.
  176. *
  177. * @return:
  178. * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid
  179. * outlines.
  180. */
  181. FT_EXPORT( FT_StrokerBorder )
  182. FT_Outline_GetInsideBorder( FT_Outline* outline );
  183. /**************************************************************
  184. *
  185. * @function:
  186. * FT_Outline_GetOutsideBorder
  187. *
  188. * @description:
  189. * Retrieve the @FT_StrokerBorder value corresponding to the
  190. * `outside' borders of a given outline.
  191. *
  192. * @input:
  193. * outline ::
  194. * The source outline handle.
  195. *
  196. * @return:
  197. * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid
  198. * outlines.
  199. */
  200. FT_EXPORT( FT_StrokerBorder )
  201. FT_Outline_GetOutsideBorder( FT_Outline* outline );
  202. /**************************************************************
  203. *
  204. * @function:
  205. * FT_Stroker_New
  206. *
  207. * @description:
  208. * Create a new stroker object.
  209. *
  210. * @input:
  211. * library ::
  212. * FreeType library handle.
  213. *
  214. * @output:
  215. * astroker ::
  216. * A new stroker object handle. NULL in case of error.
  217. *
  218. * @return:
  219. * FreeType error code. 0~means success.
  220. */
  221. FT_EXPORT( FT_Error )
  222. FT_Stroker_New( FT_Library library,
  223. FT_Stroker *astroker );
  224. /**************************************************************
  225. *
  226. * @function:
  227. * FT_Stroker_Set
  228. *
  229. * @description:
  230. * Reset a stroker object's attributes.
  231. *
  232. * @input:
  233. * stroker ::
  234. * The target stroker handle.
  235. *
  236. * radius ::
  237. * The border radius.
  238. *
  239. * line_cap ::
  240. * The line cap style.
  241. *
  242. * line_join ::
  243. * The line join style.
  244. *
  245. * miter_limit ::
  246. * The miter limit for the FT_STROKER_LINEJOIN_MITER_FIXED and
  247. * FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles,
  248. * expressed as 16.16 fixed-point value.
  249. *
  250. * @note:
  251. * The radius is expressed in the same units as the outline
  252. * coordinates.
  253. */
  254. FT_EXPORT( void )
  255. FT_Stroker_Set( FT_Stroker stroker,
  256. FT_Fixed radius,
  257. FT_Stroker_LineCap line_cap,
  258. FT_Stroker_LineJoin line_join,
  259. FT_Fixed miter_limit );
  260. /**************************************************************
  261. *
  262. * @function:
  263. * FT_Stroker_Rewind
  264. *
  265. * @description:
  266. * Reset a stroker object without changing its attributes.
  267. * You should call this function before beginning a new
  268. * series of calls to @FT_Stroker_BeginSubPath or
  269. * @FT_Stroker_EndSubPath.
  270. *
  271. * @input:
  272. * stroker ::
  273. * The target stroker handle.
  274. */
  275. FT_EXPORT( void )
  276. FT_Stroker_Rewind( FT_Stroker stroker );
  277. /**************************************************************
  278. *
  279. * @function:
  280. * FT_Stroker_ParseOutline
  281. *
  282. * @description:
  283. * A convenience function used to parse a whole outline with
  284. * the stroker. The resulting outline(s) can be retrieved
  285. * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export.
  286. *
  287. * @input:
  288. * stroker ::
  289. * The target stroker handle.
  290. *
  291. * outline ::
  292. * The source outline.
  293. *
  294. * opened ::
  295. * A boolean. If~1, the outline is treated as an open path instead
  296. * of a closed one.
  297. *
  298. * @return:
  299. * FreeType error code. 0~means success.
  300. *
  301. * @note:
  302. * If `opened' is~0 (the default), the outline is treated as a closed
  303. * path, and the stroker generates two distinct `border' outlines.
  304. *
  305. * If `opened' is~1, the outline is processed as an open path, and the
  306. * stroker generates a single `stroke' outline.
  307. *
  308. * This function calls @FT_Stroker_Rewind automatically.
  309. */
  310. FT_EXPORT( FT_Error )
  311. FT_Stroker_ParseOutline( FT_Stroker stroker,
  312. FT_Outline* outline,
  313. FT_Bool opened );
  314. /**************************************************************
  315. *
  316. * @function:
  317. * FT_Stroker_BeginSubPath
  318. *
  319. * @description:
  320. * Start a new sub-path in the stroker.
  321. *
  322. * @input:
  323. * stroker ::
  324. * The target stroker handle.
  325. *
  326. * to ::
  327. * A pointer to the start vector.
  328. *
  329. * open ::
  330. * A boolean. If~1, the sub-path is treated as an open one.
  331. *
  332. * @return:
  333. * FreeType error code. 0~means success.
  334. *
  335. * @note:
  336. * This function is useful when you need to stroke a path that is
  337. * not stored as an @FT_Outline object.
  338. */
  339. FT_EXPORT( FT_Error )
  340. FT_Stroker_BeginSubPath( FT_Stroker stroker,
  341. FT_Vector* to,
  342. FT_Bool open );
  343. /**************************************************************
  344. *
  345. * @function:
  346. * FT_Stroker_EndSubPath
  347. *
  348. * @description:
  349. * Close the current sub-path in the stroker.
  350. *
  351. * @input:
  352. * stroker ::
  353. * The target stroker handle.
  354. *
  355. * @return:
  356. * FreeType error code. 0~means success.
  357. *
  358. * @note:
  359. * You should call this function after @FT_Stroker_BeginSubPath.
  360. * If the subpath was not `opened', this function `draws' a
  361. * single line segment to the start position when needed.
  362. */
  363. FT_EXPORT( FT_Error )
  364. FT_Stroker_EndSubPath( FT_Stroker stroker );
  365. /**************************************************************
  366. *
  367. * @function:
  368. * FT_Stroker_LineTo
  369. *
  370. * @description:
  371. * `Draw' a single line segment in the stroker's current sub-path,
  372. * from the last position.
  373. *
  374. * @input:
  375. * stroker ::
  376. * The target stroker handle.
  377. *
  378. * to ::
  379. * A pointer to the destination point.
  380. *
  381. * @return:
  382. * FreeType error code. 0~means success.
  383. *
  384. * @note:
  385. * You should call this function between @FT_Stroker_BeginSubPath and
  386. * @FT_Stroker_EndSubPath.
  387. */
  388. FT_EXPORT( FT_Error )
  389. FT_Stroker_LineTo( FT_Stroker stroker,
  390. FT_Vector* to );
  391. /**************************************************************
  392. *
  393. * @function:
  394. * FT_Stroker_ConicTo
  395. *
  396. * @description:
  397. * `Draw' a single quadratic Bézier in the stroker's current sub-path,
  398. * from the last position.
  399. *
  400. * @input:
  401. * stroker ::
  402. * The target stroker handle.
  403. *
  404. * control ::
  405. * A pointer to a Bézier control point.
  406. *
  407. * to ::
  408. * A pointer to the destination point.
  409. *
  410. * @return:
  411. * FreeType error code. 0~means success.
  412. *
  413. * @note:
  414. * You should call this function between @FT_Stroker_BeginSubPath and
  415. * @FT_Stroker_EndSubPath.
  416. */
  417. FT_EXPORT( FT_Error )
  418. FT_Stroker_ConicTo( FT_Stroker stroker,
  419. FT_Vector* control,
  420. FT_Vector* to );
  421. /**************************************************************
  422. *
  423. * @function:
  424. * FT_Stroker_CubicTo
  425. *
  426. * @description:
  427. * `Draw' a single cubic Bézier in the stroker's current sub-path,
  428. * from the last position.
  429. *
  430. * @input:
  431. * stroker ::
  432. * The target stroker handle.
  433. *
  434. * control1 ::
  435. * A pointer to the first Bézier control point.
  436. *
  437. * control2 ::
  438. * A pointer to second Bézier control point.
  439. *
  440. * to ::
  441. * A pointer to the destination point.
  442. *
  443. * @return:
  444. * FreeType error code. 0~means success.
  445. *
  446. * @note:
  447. * You should call this function between @FT_Stroker_BeginSubPath and
  448. * @FT_Stroker_EndSubPath.
  449. */
  450. FT_EXPORT( FT_Error )
  451. FT_Stroker_CubicTo( FT_Stroker stroker,
  452. FT_Vector* control1,
  453. FT_Vector* control2,
  454. FT_Vector* to );
  455. /**************************************************************
  456. *
  457. * @function:
  458. * FT_Stroker_GetBorderCounts
  459. *
  460. * @description:
  461. * Call this function once you have finished parsing your paths
  462. * with the stroker. It returns the number of points and
  463. * contours necessary to export one of the `border' or `stroke'
  464. * outlines generated by the stroker.
  465. *
  466. * @input:
  467. * stroker ::
  468. * The target stroker handle.
  469. *
  470. * border ::
  471. * The border index.
  472. *
  473. * @output:
  474. * anum_points ::
  475. * The number of points.
  476. *
  477. * anum_contours ::
  478. * The number of contours.
  479. *
  480. * @return:
  481. * FreeType error code. 0~means success.
  482. *
  483. * @note:
  484. * When an outline, or a sub-path, is `closed', the stroker generates
  485. * two independent `border' outlines, named `left' and `right'.
  486. *
  487. * When the outline, or a sub-path, is `opened', the stroker merges
  488. * the `border' outlines with caps. The `left' border receives all
  489. * points, while the `right' border becomes empty.
  490. *
  491. * Use the function @FT_Stroker_GetCounts instead if you want to
  492. * retrieve the counts associated to both borders.
  493. */
  494. FT_EXPORT( FT_Error )
  495. FT_Stroker_GetBorderCounts( FT_Stroker stroker,
  496. FT_StrokerBorder border,
  497. FT_UInt *anum_points,
  498. FT_UInt *anum_contours );
  499. /**************************************************************
  500. *
  501. * @function:
  502. * FT_Stroker_ExportBorder
  503. *
  504. * @description:
  505. * Call this function after @FT_Stroker_GetBorderCounts to
  506. * export the corresponding border to your own @FT_Outline
  507. * structure.
  508. *
  509. * Note that this function appends the border points and
  510. * contours to your outline, but does not try to resize its
  511. * arrays.
  512. *
  513. * @input:
  514. * stroker ::
  515. * The target stroker handle.
  516. *
  517. * border ::
  518. * The border index.
  519. *
  520. * outline ::
  521. * The target outline handle.
  522. *
  523. * @note:
  524. * Always call this function after @FT_Stroker_GetBorderCounts to
  525. * get sure that there is enough room in your @FT_Outline object to
  526. * receive all new data.
  527. *
  528. * When an outline, or a sub-path, is `closed', the stroker generates
  529. * two independent `border' outlines, named `left' and `right'
  530. *
  531. * When the outline, or a sub-path, is `opened', the stroker merges
  532. * the `border' outlines with caps. The `left' border receives all
  533. * points, while the `right' border becomes empty.
  534. *
  535. * Use the function @FT_Stroker_Export instead if you want to
  536. * retrieve all borders at once.
  537. */
  538. FT_EXPORT( void )
  539. FT_Stroker_ExportBorder( FT_Stroker stroker,
  540. FT_StrokerBorder border,
  541. FT_Outline* outline );
  542. /**************************************************************
  543. *
  544. * @function:
  545. * FT_Stroker_GetCounts
  546. *
  547. * @description:
  548. * Call this function once you have finished parsing your paths
  549. * with the stroker. It returns the number of points and
  550. * contours necessary to export all points/borders from the stroked
  551. * outline/path.
  552. *
  553. * @input:
  554. * stroker ::
  555. * The target stroker handle.
  556. *
  557. * @output:
  558. * anum_points ::
  559. * The number of points.
  560. *
  561. * anum_contours ::
  562. * The number of contours.
  563. *
  564. * @return:
  565. * FreeType error code. 0~means success.
  566. */
  567. FT_EXPORT( FT_Error )
  568. FT_Stroker_GetCounts( FT_Stroker stroker,
  569. FT_UInt *anum_points,
  570. FT_UInt *anum_contours );
  571. /**************************************************************
  572. *
  573. * @function:
  574. * FT_Stroker_Export
  575. *
  576. * @description:
  577. * Call this function after @FT_Stroker_GetBorderCounts to
  578. * export all borders to your own @FT_Outline structure.
  579. *
  580. * Note that this function appends the border points and
  581. * contours to your outline, but does not try to resize its
  582. * arrays.
  583. *
  584. * @input:
  585. * stroker ::
  586. * The target stroker handle.
  587. *
  588. * outline ::
  589. * The target outline handle.
  590. */
  591. FT_EXPORT( void )
  592. FT_Stroker_Export( FT_Stroker stroker,
  593. FT_Outline* outline );
  594. /**************************************************************
  595. *
  596. * @function:
  597. * FT_Stroker_Done
  598. *
  599. * @description:
  600. * Destroy a stroker object.
  601. *
  602. * @input:
  603. * stroker ::
  604. * A stroker handle. Can be NULL.
  605. */
  606. FT_EXPORT( void )
  607. FT_Stroker_Done( FT_Stroker stroker );
  608. /**************************************************************
  609. *
  610. * @function:
  611. * FT_Glyph_Stroke
  612. *
  613. * @description:
  614. * Stroke a given outline glyph object with a given stroker.
  615. *
  616. * @inout:
  617. * pglyph ::
  618. * Source glyph handle on input, new glyph handle on output.
  619. *
  620. * @input:
  621. * stroker ::
  622. * A stroker handle.
  623. *
  624. * destroy ::
  625. * A Boolean. If~1, the source glyph object is destroyed
  626. * on success.
  627. *
  628. * @return:
  629. * FreeType error code. 0~means success.
  630. *
  631. * @note:
  632. * The source glyph is untouched in case of error.
  633. *
  634. * Adding stroke may yield a significantly wider and taller glyph
  635. * depending on how large of a radius was used to stroke the glyph. You
  636. * may need to manually adjust horizontal and vertical advance amounts
  637. * to account for this added size.
  638. */
  639. FT_EXPORT( FT_Error )
  640. FT_Glyph_Stroke( FT_Glyph *pglyph,
  641. FT_Stroker stroker,
  642. FT_Bool destroy );
  643. /**************************************************************
  644. *
  645. * @function:
  646. * FT_Glyph_StrokeBorder
  647. *
  648. * @description:
  649. * Stroke a given outline glyph object with a given stroker, but
  650. * only return either its inside or outside border.
  651. *
  652. * @inout:
  653. * pglyph ::
  654. * Source glyph handle on input, new glyph handle on output.
  655. *
  656. * @input:
  657. * stroker ::
  658. * A stroker handle.
  659. *
  660. * inside ::
  661. * A Boolean. If~1, return the inside border, otherwise
  662. * the outside border.
  663. *
  664. * destroy ::
  665. * A Boolean. If~1, the source glyph object is destroyed
  666. * on success.
  667. *
  668. * @return:
  669. * FreeType error code. 0~means success.
  670. *
  671. * @note:
  672. * The source glyph is untouched in case of error.
  673. *
  674. * Adding stroke may yield a significantly wider and taller glyph
  675. * depending on how large of a radius was used to stroke the glyph. You
  676. * may need to manually adjust horizontal and vertical advance amounts
  677. * to account for this added size.
  678. */
  679. FT_EXPORT( FT_Error )
  680. FT_Glyph_StrokeBorder( FT_Glyph *pglyph,
  681. FT_Stroker stroker,
  682. FT_Bool inside,
  683. FT_Bool destroy );
  684. /* */
  685. FT_END_HEADER
  686. #endif /* __FT_STROKE_H__ */
  687. /* END */
  688. /* Local Variables: */
  689. /* coding: utf-8 */
  690. /* End: */