1 /***************************************************************************/
5 /* FreeType path stroker (specification). */
7 /* Copyright 2002-2015 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
57 * FT_Outline_GetInsideBorder
58 * FT_Outline_GetOutsideBorder
61 * FT_Glyph_StrokeBorder
66 * FT_Stroker_ParseOutline
69 * FT_Stroker_BeginSubPath
70 * FT_Stroker_EndSubPath
76 * FT_Stroker_GetBorderCounts
77 * FT_Stroker_ExportBorder
78 * FT_Stroker_GetCounts
84 /**************************************************************
90 * Opaque handle to a path stroker object.
92 typedef struct FT_StrokerRec_
* FT_Stroker
;
95 /**************************************************************
101 * These values determine how two joining lines are rendered
105 * FT_STROKER_LINEJOIN_ROUND ::
106 * Used to render rounded line joins. Circular arcs are used
107 * to join two lines smoothly.
109 * FT_STROKER_LINEJOIN_BEVEL ::
110 * Used to render beveled line joins. The outer corner of
111 * the joined lines is filled by enclosing the triangular
112 * region of the corner with a straight line between the
113 * outer corners of each stroke.
115 * FT_STROKER_LINEJOIN_MITER_FIXED ::
116 * Used to render mitered line joins, with fixed bevels if the
117 * miter limit is exceeded. The outer edges of the strokes
118 * for the two segments are extended until they meet at an
119 * angle. If the segments meet at too sharp an angle (such
120 * that the miter would extend from the intersection of the
121 * segments a distance greater than the product of the miter
122 * limit value and the border radius), then a bevel join (see
123 * above) is used instead. This prevents long spikes being
124 * created. FT_STROKER_LINEJOIN_MITER_FIXED generates a miter
125 * line join as used in PostScript and PDF.
127 * FT_STROKER_LINEJOIN_MITER_VARIABLE ::
128 * FT_STROKER_LINEJOIN_MITER ::
129 * Used to render mitered line joins, with variable bevels if
130 * the miter limit is exceeded. The intersection of the
131 * strokes is clipped at a line perpendicular to the bisector
132 * of the angle between the strokes, at the distance from the
133 * intersection of the segments equal to the product of the
134 * miter limit value and the border radius. This prevents
135 * long spikes being created.
136 * FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line
137 * join as used in XPS. FT_STROKER_LINEJOIN_MITER is an alias
138 * for FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for
139 * backwards compatibility.
141 typedef enum FT_Stroker_LineJoin_
143 FT_STROKER_LINEJOIN_ROUND
= 0,
144 FT_STROKER_LINEJOIN_BEVEL
= 1,
145 FT_STROKER_LINEJOIN_MITER_VARIABLE
= 2,
146 FT_STROKER_LINEJOIN_MITER
= FT_STROKER_LINEJOIN_MITER_VARIABLE
,
147 FT_STROKER_LINEJOIN_MITER_FIXED
= 3
149 } FT_Stroker_LineJoin
;
152 /**************************************************************
158 * These values determine how the end of opened sub-paths are
159 * rendered in a stroke.
162 * FT_STROKER_LINECAP_BUTT ::
163 * The end of lines is rendered as a full stop on the last
166 * FT_STROKER_LINECAP_ROUND ::
167 * The end of lines is rendered as a half-circle around the
170 * FT_STROKER_LINECAP_SQUARE ::
171 * The end of lines is rendered as a square around the
174 typedef enum FT_Stroker_LineCap_
176 FT_STROKER_LINECAP_BUTT
= 0,
177 FT_STROKER_LINECAP_ROUND
,
178 FT_STROKER_LINECAP_SQUARE
180 } FT_Stroker_LineCap
;
183 /**************************************************************
189 * These values are used to select a given stroke border
190 * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder.
193 * FT_STROKER_BORDER_LEFT ::
194 * Select the left border, relative to the drawing direction.
196 * FT_STROKER_BORDER_RIGHT ::
197 * Select the right border, relative to the drawing direction.
200 * Applications are generally interested in the `inside' and `outside'
201 * borders. However, there is no direct mapping between these and the
202 * `left' and `right' ones, since this really depends on the glyph's
203 * drawing orientation, which varies between font formats.
205 * You can however use @FT_Outline_GetInsideBorder and
206 * @FT_Outline_GetOutsideBorder to get these.
208 typedef enum FT_StrokerBorder_
210 FT_STROKER_BORDER_LEFT
= 0,
211 FT_STROKER_BORDER_RIGHT
216 /**************************************************************
219 * FT_Outline_GetInsideBorder
222 * Retrieve the @FT_StrokerBorder value corresponding to the
223 * `inside' borders of a given outline.
227 * The source outline handle.
230 * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid
233 FT_EXPORT( FT_StrokerBorder
)
234 FT_Outline_GetInsideBorder( FT_Outline
* outline
);
237 /**************************************************************
240 * FT_Outline_GetOutsideBorder
243 * Retrieve the @FT_StrokerBorder value corresponding to the
244 * `outside' borders of a given outline.
248 * The source outline handle.
251 * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid
254 FT_EXPORT( FT_StrokerBorder
)
255 FT_Outline_GetOutsideBorder( FT_Outline
* outline
);
258 /**************************************************************
264 * Create a new stroker object.
268 * FreeType library handle.
272 * A new stroker object handle. NULL in case of error.
275 * FreeType error code. 0~means success.
277 FT_EXPORT( FT_Error
)
278 FT_Stroker_New( FT_Library library
,
279 FT_Stroker
*astroker
);
282 /**************************************************************
288 * Reset a stroker object's attributes.
292 * The target stroker handle.
298 * The line cap style.
301 * The line join style.
304 * The miter limit for the FT_STROKER_LINEJOIN_MITER_FIXED and
305 * FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles,
306 * expressed as 16.16 fixed-point value.
309 * The radius is expressed in the same units as the outline
312 * This function calls @FT_Stroker_Rewind automatically.
315 FT_Stroker_Set( FT_Stroker stroker
,
317 FT_Stroker_LineCap line_cap
,
318 FT_Stroker_LineJoin line_join
,
319 FT_Fixed miter_limit
);
322 /**************************************************************
328 * Reset a stroker object without changing its attributes.
329 * You should call this function before beginning a new
330 * series of calls to @FT_Stroker_BeginSubPath or
331 * @FT_Stroker_EndSubPath.
335 * The target stroker handle.
338 FT_Stroker_Rewind( FT_Stroker stroker
);
341 /**************************************************************
344 * FT_Stroker_ParseOutline
347 * A convenience function used to parse a whole outline with
348 * the stroker. The resulting outline(s) can be retrieved
349 * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export.
353 * The target stroker handle.
356 * The source outline.
359 * A boolean. If~1, the outline is treated as an open path instead
363 * FreeType error code. 0~means success.
366 * If `opened' is~0 (the default), the outline is treated as a closed
367 * path, and the stroker generates two distinct `border' outlines.
369 * If `opened' is~1, the outline is processed as an open path, and the
370 * stroker generates a single `stroke' outline.
372 * This function calls @FT_Stroker_Rewind automatically.
374 FT_EXPORT( FT_Error
)
375 FT_Stroker_ParseOutline( FT_Stroker stroker
,
380 /**************************************************************
383 * FT_Stroker_BeginSubPath
386 * Start a new sub-path in the stroker.
390 * The target stroker handle.
393 * A pointer to the start vector.
396 * A boolean. If~1, the sub-path is treated as an open one.
399 * FreeType error code. 0~means success.
402 * This function is useful when you need to stroke a path that is
403 * not stored as an @FT_Outline object.
405 FT_EXPORT( FT_Error
)
406 FT_Stroker_BeginSubPath( FT_Stroker stroker
,
411 /**************************************************************
414 * FT_Stroker_EndSubPath
417 * Close the current sub-path in the stroker.
421 * The target stroker handle.
424 * FreeType error code. 0~means success.
427 * You should call this function after @FT_Stroker_BeginSubPath.
428 * If the subpath was not `opened', this function `draws' a
429 * single line segment to the start position when needed.
431 FT_EXPORT( FT_Error
)
432 FT_Stroker_EndSubPath( FT_Stroker stroker
);
435 /**************************************************************
441 * `Draw' a single line segment in the stroker's current sub-path,
442 * from the last position.
446 * The target stroker handle.
449 * A pointer to the destination point.
452 * FreeType error code. 0~means success.
455 * You should call this function between @FT_Stroker_BeginSubPath and
456 * @FT_Stroker_EndSubPath.
458 FT_EXPORT( FT_Error
)
459 FT_Stroker_LineTo( FT_Stroker stroker
,
463 /**************************************************************
469 * `Draw' a single quadratic Bézier in the stroker's current sub-path,
470 * from the last position.
474 * The target stroker handle.
477 * A pointer to a Bézier control point.
480 * A pointer to the destination point.
483 * FreeType error code. 0~means success.
486 * You should call this function between @FT_Stroker_BeginSubPath and
487 * @FT_Stroker_EndSubPath.
489 FT_EXPORT( FT_Error
)
490 FT_Stroker_ConicTo( FT_Stroker stroker
,
495 /**************************************************************
501 * `Draw' a single cubic Bézier in the stroker's current sub-path,
502 * from the last position.
506 * The target stroker handle.
509 * A pointer to the first Bézier control point.
512 * A pointer to second Bézier control point.
515 * A pointer to the destination point.
518 * FreeType error code. 0~means success.
521 * You should call this function between @FT_Stroker_BeginSubPath and
522 * @FT_Stroker_EndSubPath.
524 FT_EXPORT( FT_Error
)
525 FT_Stroker_CubicTo( FT_Stroker stroker
,
531 /**************************************************************
534 * FT_Stroker_GetBorderCounts
537 * Call this function once you have finished parsing your paths
538 * with the stroker. It returns the number of points and
539 * contours necessary to export one of the `border' or `stroke'
540 * outlines generated by the stroker.
544 * The target stroker handle.
551 * The number of points.
554 * The number of contours.
557 * FreeType error code. 0~means success.
560 * When an outline, or a sub-path, is `closed', the stroker generates
561 * two independent `border' outlines, named `left' and `right'.
563 * When the outline, or a sub-path, is `opened', the stroker merges
564 * the `border' outlines with caps. The `left' border receives all
565 * points, while the `right' border becomes empty.
567 * Use the function @FT_Stroker_GetCounts instead if you want to
568 * retrieve the counts associated to both borders.
570 FT_EXPORT( FT_Error
)
571 FT_Stroker_GetBorderCounts( FT_Stroker stroker
,
572 FT_StrokerBorder border
,
573 FT_UInt
*anum_points
,
574 FT_UInt
*anum_contours
);
577 /**************************************************************
580 * FT_Stroker_ExportBorder
583 * Call this function after @FT_Stroker_GetBorderCounts to
584 * export the corresponding border to your own @FT_Outline
587 * Note that this function appends the border points and
588 * contours to your outline, but does not try to resize its
593 * The target stroker handle.
599 * The target outline handle.
602 * Always call this function after @FT_Stroker_GetBorderCounts to
603 * get sure that there is enough room in your @FT_Outline object to
604 * receive all new data.
606 * When an outline, or a sub-path, is `closed', the stroker generates
607 * two independent `border' outlines, named `left' and `right'.
609 * When the outline, or a sub-path, is `opened', the stroker merges
610 * the `border' outlines with caps. The `left' border receives all
611 * points, while the `right' border becomes empty.
613 * Use the function @FT_Stroker_Export instead if you want to
614 * retrieve all borders at once.
617 FT_Stroker_ExportBorder( FT_Stroker stroker
,
618 FT_StrokerBorder border
,
619 FT_Outline
* outline
);
622 /**************************************************************
625 * FT_Stroker_GetCounts
628 * Call this function once you have finished parsing your paths
629 * with the stroker. It returns the number of points and
630 * contours necessary to export all points/borders from the stroked
635 * The target stroker handle.
639 * The number of points.
642 * The number of contours.
645 * FreeType error code. 0~means success.
647 FT_EXPORT( FT_Error
)
648 FT_Stroker_GetCounts( FT_Stroker stroker
,
649 FT_UInt
*anum_points
,
650 FT_UInt
*anum_contours
);
653 /**************************************************************
659 * Call this function after @FT_Stroker_GetBorderCounts to
660 * export all borders to your own @FT_Outline structure.
662 * Note that this function appends the border points and
663 * contours to your outline, but does not try to resize its
668 * The target stroker handle.
671 * The target outline handle.
674 FT_Stroker_Export( FT_Stroker stroker
,
675 FT_Outline
* outline
);
678 /**************************************************************
684 * Destroy a stroker object.
688 * A stroker handle. Can be NULL.
691 FT_Stroker_Done( FT_Stroker stroker
);
694 /**************************************************************
700 * Stroke a given outline glyph object with a given stroker.
704 * Source glyph handle on input, new glyph handle on output.
711 * A Boolean. If~1, the source glyph object is destroyed
715 * FreeType error code. 0~means success.
718 * The source glyph is untouched in case of error.
720 * Adding stroke may yield a significantly wider and taller glyph
721 * depending on how large of a radius was used to stroke the glyph. You
722 * may need to manually adjust horizontal and vertical advance amounts
723 * to account for this added size.
725 FT_EXPORT( FT_Error
)
726 FT_Glyph_Stroke( FT_Glyph
*pglyph
,
731 /**************************************************************
734 * FT_Glyph_StrokeBorder
737 * Stroke a given outline glyph object with a given stroker, but
738 * only return either its inside or outside border.
742 * Source glyph handle on input, new glyph handle on output.
749 * A Boolean. If~1, return the inside border, otherwise
750 * the outside border.
753 * A Boolean. If~1, the source glyph object is destroyed
757 * FreeType error code. 0~means success.
760 * The source glyph is untouched in case of error.
762 * Adding stroke may yield a significantly wider and taller glyph
763 * depending on how large of a radius was used to stroke the glyph. You
764 * may need to manually adjust horizontal and vertical advance amounts
765 * to account for this added size.
767 FT_EXPORT( FT_Error
)
768 FT_Glyph_StrokeBorder( FT_Glyph
*pglyph
,
777 #endif /* __FT_STROKE_H__ */
783 /* Local Variables: */