1 /***************************************************************************/
5 /* FreeType path stroker (specification). */
7 /* Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
19 #ifndef __FT_STROKE_H__
20 #define __FT_STROKE_H__
30 /************************************************************************
39 * Generating bordered and stroked glyphs.
42 * This component generates stroked outlines of a given vectorial
43 * glyph. It also allows you to retrieve the `outside' and/or the
44 * `inside' borders of the stroke.
46 * This can be useful to generate `bordered' glyph, i.e., glyphs
47 * displayed with a coloured (and anti-aliased) border around their
52 /**************************************************************
58 * Opaque handler to a path stroker object.
60 typedef struct FT_StrokerRec_
* FT_Stroker
;
63 /**************************************************************
69 * These values determine how two joining lines are rendered
73 * FT_STROKER_LINEJOIN_ROUND ::
74 * Used to render rounded line joins. Circular arcs are used
75 * to join two lines smoothly.
77 * FT_STROKER_LINEJOIN_BEVEL ::
78 * Used to render beveled line joins; i.e., the two joining lines
79 * are extended until they intersect.
81 * FT_STROKER_LINEJOIN_MITER ::
82 * Same as beveled rendering, except that an additional line
83 * break is added if the angle between the two joining lines
84 * is too closed (this is useful to avoid unpleasant spikes
85 * in beveled rendering).
87 typedef enum FT_Stroker_LineJoin_
89 FT_STROKER_LINEJOIN_ROUND
= 0,
90 FT_STROKER_LINEJOIN_BEVEL
,
91 FT_STROKER_LINEJOIN_MITER
93 } FT_Stroker_LineJoin
;
96 /**************************************************************
102 * These values determine how the end of opened sub-paths are
103 * rendered in a stroke.
106 * FT_STROKER_LINECAP_BUTT ::
107 * The end of lines is rendered as a full stop on the last
110 * FT_STROKER_LINECAP_ROUND ::
111 * The end of lines is rendered as a half-circle around the
114 * FT_STROKER_LINECAP_SQUARE ::
115 * The end of lines is rendered as a square around the
118 typedef enum FT_Stroker_LineCap_
120 FT_STROKER_LINECAP_BUTT
= 0,
121 FT_STROKER_LINECAP_ROUND
,
122 FT_STROKER_LINECAP_SQUARE
124 } FT_Stroker_LineCap
;
127 /**************************************************************
133 * These values are used to select a given stroke border
134 * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder.
137 * FT_STROKER_BORDER_LEFT ::
138 * Select the left border, relative to the drawing direction.
140 * FT_STROKER_BORDER_RIGHT ::
141 * Select the right border, relative to the drawing direction.
144 * Applications are generally interested in the `inside' and `outside'
145 * borders. However, there is no direct mapping between these and the
146 * `left' and `right' ones, since this really depends on the glyph's
147 * drawing orientation, which varies between font formats.
149 * You can however use @FT_Outline_GetInsideBorder and
150 * @FT_Outline_GetOutsideBorder to get these.
152 typedef enum FT_StrokerBorder_
154 FT_STROKER_BORDER_LEFT
= 0,
155 FT_STROKER_BORDER_RIGHT
160 /**************************************************************
163 * FT_Outline_GetInsideBorder
166 * Retrieve the @FT_StrokerBorder value corresponding to the
167 * `inside' borders of a given outline.
171 * The source outline handle.
174 * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid
177 FT_EXPORT( FT_StrokerBorder
)
178 FT_Outline_GetInsideBorder( FT_Outline
* outline
);
181 /**************************************************************
184 * FT_Outline_GetOutsideBorder
187 * Retrieve the @FT_StrokerBorder value corresponding to the
188 * `outside' borders of a given outline.
192 * The source outline handle.
195 * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid
198 FT_EXPORT( FT_StrokerBorder
)
199 FT_Outline_GetOutsideBorder( FT_Outline
* outline
);
202 /**************************************************************
208 * Create a new stroker object.
212 * FreeType library handle.
216 * A new stroker object handle. NULL in case of error.
219 * FreeType error code. 0~means success.
221 FT_EXPORT( FT_Error
)
222 FT_Stroker_New( FT_Library library
,
223 FT_Stroker
*astroker
);
226 /**************************************************************
232 * Reset a stroker object's attributes.
236 * The target stroker handle.
242 * The line cap style.
245 * The line join style.
248 * The miter limit for the FT_STROKER_LINEJOIN_MITER style,
249 * expressed as 16.16 fixed point value.
252 * The radius is expressed in the same units as the outline
256 FT_Stroker_Set( FT_Stroker stroker
,
258 FT_Stroker_LineCap line_cap
,
259 FT_Stroker_LineJoin line_join
,
260 FT_Fixed miter_limit
);
263 /**************************************************************
269 * Reset a stroker object without changing its attributes.
270 * You should call this function before beginning a new
271 * series of calls to @FT_Stroker_BeginSubPath or
272 * @FT_Stroker_EndSubPath.
276 * The target stroker handle.
279 FT_Stroker_Rewind( FT_Stroker stroker
);
282 /**************************************************************
285 * FT_Stroker_ParseOutline
288 * A convenience function used to parse a whole outline with
289 * the stroker. The resulting outline(s) can be retrieved
290 * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export.
294 * The target stroker handle.
297 * The source outline.
300 * A boolean. If~1, the outline is treated as an open path instead
304 * FreeType error code. 0~means success.
307 * If `opened' is~0 (the default), the outline is treated as a closed
308 * path, and the stroker generates two distinct `border' outlines.
310 * If `opened' is~1, the outline is processed as an open path, and the
311 * stroker generates a single `stroke' outline.
313 * This function calls @FT_Stroker_Rewind automatically.
315 FT_EXPORT( FT_Error
)
316 FT_Stroker_ParseOutline( FT_Stroker stroker
,
321 /**************************************************************
324 * FT_Stroker_BeginSubPath
327 * Start a new sub-path in the stroker.
331 * The target stroker handle.
334 * A pointer to the start vector.
337 * A boolean. If~1, the sub-path is treated as an open one.
340 * FreeType error code. 0~means success.
343 * This function is useful when you need to stroke a path that is
344 * not stored as an @FT_Outline object.
346 FT_EXPORT( FT_Error
)
347 FT_Stroker_BeginSubPath( FT_Stroker stroker
,
352 /**************************************************************
355 * FT_Stroker_EndSubPath
358 * Close the current sub-path in the stroker.
362 * The target stroker handle.
365 * FreeType error code. 0~means success.
368 * You should call this function after @FT_Stroker_BeginSubPath.
369 * If the subpath was not `opened', this function `draws' a
370 * single line segment to the start position when needed.
372 FT_EXPORT( FT_Error
)
373 FT_Stroker_EndSubPath( FT_Stroker stroker
);
376 /**************************************************************
382 * `Draw' a single line segment in the stroker's current sub-path,
383 * from the last position.
387 * The target stroker handle.
390 * A pointer to the destination point.
393 * FreeType error code. 0~means success.
396 * You should call this function between @FT_Stroker_BeginSubPath and
397 * @FT_Stroker_EndSubPath.
399 FT_EXPORT( FT_Error
)
400 FT_Stroker_LineTo( FT_Stroker stroker
,
404 /**************************************************************
410 * `Draw' a single quadratic Bézier in the stroker's current sub-path,
411 * from the last position.
415 * The target stroker handle.
418 * A pointer to a Bézier control point.
421 * A pointer to the destination point.
424 * FreeType error code. 0~means success.
427 * You should call this function between @FT_Stroker_BeginSubPath and
428 * @FT_Stroker_EndSubPath.
430 FT_EXPORT( FT_Error
)
431 FT_Stroker_ConicTo( FT_Stroker stroker
,
436 /**************************************************************
442 * `Draw' a single cubic Bézier in the stroker's current sub-path,
443 * from the last position.
447 * The target stroker handle.
450 * A pointer to the first Bézier control point.
453 * A pointer to second Bézier control point.
456 * A pointer to the destination point.
459 * FreeType error code. 0~means success.
462 * You should call this function between @FT_Stroker_BeginSubPath and
463 * @FT_Stroker_EndSubPath.
465 FT_EXPORT( FT_Error
)
466 FT_Stroker_CubicTo( FT_Stroker stroker
,
472 /**************************************************************
475 * FT_Stroker_GetBorderCounts
478 * Call this function once you have finished parsing your paths
479 * with the stroker. It returns the number of points and
480 * contours necessary to export one of the `border' or `stroke'
481 * outlines generated by the stroker.
485 * The target stroker handle.
492 * The number of points.
495 * The number of contours.
498 * FreeType error code. 0~means success.
501 * When an outline, or a sub-path, is `closed', the stroker generates
502 * two independent `border' outlines, named `left' and `right'.
504 * When the outline, or a sub-path, is `opened', the stroker merges
505 * the `border' outlines with caps. The `left' border receives all
506 * points, while the `right' border becomes empty.
508 * Use the function @FT_Stroker_GetCounts instead if you want to
509 * retrieve the counts associated to both borders.
511 FT_EXPORT( FT_Error
)
512 FT_Stroker_GetBorderCounts( FT_Stroker stroker
,
513 FT_StrokerBorder border
,
514 FT_UInt
*anum_points
,
515 FT_UInt
*anum_contours
);
518 /**************************************************************
521 * FT_Stroker_ExportBorder
524 * Call this function after @FT_Stroker_GetBorderCounts to
525 * export the corresponding border to your own @FT_Outline
528 * Note that this function appends the border points and
529 * contours to your outline, but does not try to resize its
534 * The target stroker handle.
540 * The target outline handle.
543 * Always call this function after @FT_Stroker_GetBorderCounts to
544 * get sure that there is enough room in your @FT_Outline object to
545 * receive all new data.
547 * When an outline, or a sub-path, is `closed', the stroker generates
548 * two independent `border' outlines, named `left' and `right'
550 * When the outline, or a sub-path, is `opened', the stroker merges
551 * the `border' outlines with caps. The `left' border receives all
552 * points, while the `right' border becomes empty.
554 * Use the function @FT_Stroker_Export instead if you want to
555 * retrieve all borders at once.
558 FT_Stroker_ExportBorder( FT_Stroker stroker
,
559 FT_StrokerBorder border
,
560 FT_Outline
* outline
);
563 /**************************************************************
566 * FT_Stroker_GetCounts
569 * Call this function once you have finished parsing your paths
570 * with the stroker. It returns the number of points and
571 * contours necessary to export all points/borders from the stroked
576 * The target stroker handle.
580 * The number of points.
583 * The number of contours.
586 * FreeType error code. 0~means success.
588 FT_EXPORT( FT_Error
)
589 FT_Stroker_GetCounts( FT_Stroker stroker
,
590 FT_UInt
*anum_points
,
591 FT_UInt
*anum_contours
);
594 /**************************************************************
600 * Call this function after @FT_Stroker_GetBorderCounts to
601 * export all borders to your own @FT_Outline structure.
603 * Note that this function appends the border points and
604 * contours to your outline, but does not try to resize its
609 * The target stroker handle.
612 * The target outline handle.
615 FT_Stroker_Export( FT_Stroker stroker
,
616 FT_Outline
* outline
);
619 /**************************************************************
625 * Destroy a stroker object.
629 * A stroker handle. Can be NULL.
632 FT_Stroker_Done( FT_Stroker stroker
);
635 /**************************************************************
641 * Stroke a given outline glyph object with a given stroker.
645 * Source glyph handle on input, new glyph handle on output.
652 * A Boolean. If~1, the source glyph object is destroyed
656 * FreeType error code. 0~means success.
659 * The source glyph is untouched in case of error.
661 FT_EXPORT( FT_Error
)
662 FT_Glyph_Stroke( FT_Glyph
*pglyph
,
667 /**************************************************************
670 * FT_Glyph_StrokeBorder
673 * Stroke a given outline glyph object with a given stroker, but
674 * only return either its inside or outside border.
678 * Source glyph handle on input, new glyph handle on output.
685 * A Boolean. If~1, return the inside border, otherwise
686 * the outside border.
689 * A Boolean. If~1, the source glyph object is destroyed
693 * FreeType error code. 0~means success.
696 * The source glyph is untouched in case of error.
698 FT_EXPORT( FT_Error
)
699 FT_Glyph_StrokeBorder( FT_Glyph
*pglyph
,
708 #endif /* __FT_STROKE_H__ */
714 /* Local Variables: */