1 /***************************************************************************/
5 /* FreeType path stroker (specification). */
7 /* Copyright 2002-2006, 2008, 2009, 2011-2012 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. The outer corner of
79 * the joined lines is filled by enclosing the triangular
80 * region of the corner with a straight line between the
81 * outer corners of each stroke.
83 * FT_STROKER_LINEJOIN_MITER_FIXED ::
84 * Used to render mitered line joins, with fixed bevels if the
85 * miter limit is exceeded. The outer edges of the strokes
86 * for the two segments are extended until they meet at an
87 * angle. If the segments meet at too sharp an angle (such
88 * that the miter would extend from the intersection of the
89 * segments a distance greater than the product of the miter
90 * limit value and the border radius), then a bevel join (see
91 * above) is used instead. This prevents long spikes being
92 * created. FT_STROKER_LINEJOIN_MITER_FIXED generates a miter
93 * line join as used in PostScript and PDF.
95 * FT_STROKER_LINEJOIN_MITER_VARIABLE ::
96 * FT_STROKER_LINEJOIN_MITER ::
97 * Used to render mitered line joins, with variable bevels if
98 * the miter limit is exceeded. The intersection of the
99 * strokes is clipped at a line perpendicular to the bisector
100 * of the angle between the strokes, at the distance from the
101 * intersection of the segments equal to the product of the
102 * miter limit value and the border radius. This prevents
103 * long spikes being created.
104 * FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line
105 * join as used in XPS. FT_STROKER_LINEJOIN_MITER is an alias
106 * for FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for
107 * backwards compatibility.
109 typedef enum FT_Stroker_LineJoin_
111 FT_STROKER_LINEJOIN_ROUND = 0,
112 FT_STROKER_LINEJOIN_BEVEL = 1,
113 FT_STROKER_LINEJOIN_MITER_VARIABLE = 2,
114 FT_STROKER_LINEJOIN_MITER = FT_STROKER_LINEJOIN_MITER_VARIABLE,
115 FT_STROKER_LINEJOIN_MITER_FIXED = 3
117 } FT_Stroker_LineJoin;
120 /**************************************************************
126 * These values determine how the end of opened sub-paths are
127 * rendered in a stroke.
130 * FT_STROKER_LINECAP_BUTT ::
131 * The end of lines is rendered as a full stop on the last
134 * FT_STROKER_LINECAP_ROUND ::
135 * The end of lines is rendered as a half-circle around the
138 * FT_STROKER_LINECAP_SQUARE ::
139 * The end of lines is rendered as a square around the
142 typedef enum FT_Stroker_LineCap_
144 FT_STROKER_LINECAP_BUTT = 0,
145 FT_STROKER_LINECAP_ROUND,
146 FT_STROKER_LINECAP_SQUARE
148 } FT_Stroker_LineCap;
151 /**************************************************************
157 * These values are used to select a given stroke border
158 * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder.
161 * FT_STROKER_BORDER_LEFT ::
162 * Select the left border, relative to the drawing direction.
164 * FT_STROKER_BORDER_RIGHT ::
165 * Select the right border, relative to the drawing direction.
168 * Applications are generally interested in the `inside' and `outside'
169 * borders. However, there is no direct mapping between these and the
170 * `left' and `right' ones, since this really depends on the glyph's
171 * drawing orientation, which varies between font formats.
173 * You can however use @FT_Outline_GetInsideBorder and
174 * @FT_Outline_GetOutsideBorder to get these.
176 typedef enum FT_StrokerBorder_
178 FT_STROKER_BORDER_LEFT = 0,
179 FT_STROKER_BORDER_RIGHT
184 /**************************************************************
187 * FT_Outline_GetInsideBorder
190 * Retrieve the @FT_StrokerBorder value corresponding to the
191 * `inside' borders of a given outline.
195 * The source outline handle.
198 * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid
201 FT_EXPORT( FT_StrokerBorder )
202 FT_Outline_GetInsideBorder( FT_Outline* outline );
205 /**************************************************************
208 * FT_Outline_GetOutsideBorder
211 * Retrieve the @FT_StrokerBorder value corresponding to the
212 * `outside' borders of a given outline.
216 * The source outline handle.
219 * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid
222 FT_EXPORT( FT_StrokerBorder )
223 FT_Outline_GetOutsideBorder( FT_Outline* outline );
226 /**************************************************************
232 * Create a new stroker object.
236 * FreeType library handle.
240 * A new stroker object handle. NULL in case of error.
243 * FreeType error code. 0~means success.
245 FT_EXPORT( FT_Error )
246 FT_Stroker_New( FT_Library library,
247 FT_Stroker *astroker );
250 /**************************************************************
256 * Reset a stroker object's attributes.
260 * The target stroker handle.
266 * The line cap style.
269 * The line join style.
272 * The miter limit for the FT_STROKER_LINEJOIN_MITER_FIXED and
273 * FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles,
274 * expressed as 16.16 fixed-point value.
277 * The radius is expressed in the same units as the outline
281 FT_Stroker_Set( FT_Stroker stroker,
283 FT_Stroker_LineCap line_cap,
284 FT_Stroker_LineJoin line_join,
285 FT_Fixed miter_limit );
288 /**************************************************************
294 * Reset a stroker object without changing its attributes.
295 * You should call this function before beginning a new
296 * series of calls to @FT_Stroker_BeginSubPath or
297 * @FT_Stroker_EndSubPath.
301 * The target stroker handle.
304 FT_Stroker_Rewind( FT_Stroker stroker );
307 /**************************************************************
310 * FT_Stroker_ParseOutline
313 * A convenience function used to parse a whole outline with
314 * the stroker. The resulting outline(s) can be retrieved
315 * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export.
319 * The target stroker handle.
322 * The source outline.
325 * A boolean. If~1, the outline is treated as an open path instead
329 * FreeType error code. 0~means success.
332 * If `opened' is~0 (the default), the outline is treated as a closed
333 * path, and the stroker generates two distinct `border' outlines.
335 * If `opened' is~1, the outline is processed as an open path, and the
336 * stroker generates a single `stroke' outline.
338 * This function calls @FT_Stroker_Rewind automatically.
340 FT_EXPORT( FT_Error )
341 FT_Stroker_ParseOutline( FT_Stroker stroker,
346 /**************************************************************
349 * FT_Stroker_BeginSubPath
352 * Start a new sub-path in the stroker.
356 * The target stroker handle.
359 * A pointer to the start vector.
362 * A boolean. If~1, the sub-path is treated as an open one.
365 * FreeType error code. 0~means success.
368 * This function is useful when you need to stroke a path that is
369 * not stored as an @FT_Outline object.
371 FT_EXPORT( FT_Error )
372 FT_Stroker_BeginSubPath( FT_Stroker stroker,
377 /**************************************************************
380 * FT_Stroker_EndSubPath
383 * Close the current sub-path in the stroker.
387 * The target stroker handle.
390 * FreeType error code. 0~means success.
393 * You should call this function after @FT_Stroker_BeginSubPath.
394 * If the subpath was not `opened', this function `draws' a
395 * single line segment to the start position when needed.
397 FT_EXPORT( FT_Error )
398 FT_Stroker_EndSubPath( FT_Stroker stroker );
401 /**************************************************************
407 * `Draw' a single line segment in the stroker's current sub-path,
408 * from the last position.
412 * The target stroker handle.
415 * A pointer to the destination point.
418 * FreeType error code. 0~means success.
421 * You should call this function between @FT_Stroker_BeginSubPath and
422 * @FT_Stroker_EndSubPath.
424 FT_EXPORT( FT_Error )
425 FT_Stroker_LineTo( FT_Stroker stroker,
429 /**************************************************************
435 * `Draw' a single quadratic Bézier in the stroker's current sub-path,
436 * from the last position.
440 * The target stroker handle.
443 * A pointer to a Bézier control point.
446 * A pointer to the destination point.
449 * FreeType error code. 0~means success.
452 * You should call this function between @FT_Stroker_BeginSubPath and
453 * @FT_Stroker_EndSubPath.
455 FT_EXPORT( FT_Error )
456 FT_Stroker_ConicTo( FT_Stroker stroker,
461 /**************************************************************
467 * `Draw' a single cubic Bézier in the stroker's current sub-path,
468 * from the last position.
472 * The target stroker handle.
475 * A pointer to the first Bézier control point.
478 * A pointer to second Bézier control point.
481 * A pointer to the destination point.
484 * FreeType error code. 0~means success.
487 * You should call this function between @FT_Stroker_BeginSubPath and
488 * @FT_Stroker_EndSubPath.
490 FT_EXPORT( FT_Error )
491 FT_Stroker_CubicTo( FT_Stroker stroker,
497 /**************************************************************
500 * FT_Stroker_GetBorderCounts
503 * Call this function once you have finished parsing your paths
504 * with the stroker. It returns the number of points and
505 * contours necessary to export one of the `border' or `stroke'
506 * outlines generated by the stroker.
510 * The target stroker handle.
517 * The number of points.
520 * The number of contours.
523 * FreeType error code. 0~means success.
526 * When an outline, or a sub-path, is `closed', the stroker generates
527 * two independent `border' outlines, named `left' and `right'.
529 * When the outline, or a sub-path, is `opened', the stroker merges
530 * the `border' outlines with caps. The `left' border receives all
531 * points, while the `right' border becomes empty.
533 * Use the function @FT_Stroker_GetCounts instead if you want to
534 * retrieve the counts associated to both borders.
536 FT_EXPORT( FT_Error )
537 FT_Stroker_GetBorderCounts( FT_Stroker stroker,
538 FT_StrokerBorder border,
539 FT_UInt *anum_points,
540 FT_UInt *anum_contours );
543 /**************************************************************
546 * FT_Stroker_ExportBorder
549 * Call this function after @FT_Stroker_GetBorderCounts to
550 * export the corresponding border to your own @FT_Outline
553 * Note that this function appends the border points and
554 * contours to your outline, but does not try to resize its
559 * The target stroker handle.
565 * The target outline handle.
568 * Always call this function after @FT_Stroker_GetBorderCounts to
569 * get sure that there is enough room in your @FT_Outline object to
570 * receive all new data.
572 * When an outline, or a sub-path, is `closed', the stroker generates
573 * two independent `border' outlines, named `left' and `right'
575 * When the outline, or a sub-path, is `opened', the stroker merges
576 * the `border' outlines with caps. The `left' border receives all
577 * points, while the `right' border becomes empty.
579 * Use the function @FT_Stroker_Export instead if you want to
580 * retrieve all borders at once.
583 FT_Stroker_ExportBorder( FT_Stroker stroker,
584 FT_StrokerBorder border,
585 FT_Outline* outline );
588 /**************************************************************
591 * FT_Stroker_GetCounts
594 * Call this function once you have finished parsing your paths
595 * with the stroker. It returns the number of points and
596 * contours necessary to export all points/borders from the stroked
601 * The target stroker handle.
605 * The number of points.
608 * The number of contours.
611 * FreeType error code. 0~means success.
613 FT_EXPORT( FT_Error )
614 FT_Stroker_GetCounts( FT_Stroker stroker,
615 FT_UInt *anum_points,
616 FT_UInt *anum_contours );
619 /**************************************************************
625 * Call this function after @FT_Stroker_GetBorderCounts to
626 * export all borders to your own @FT_Outline structure.
628 * Note that this function appends the border points and
629 * contours to your outline, but does not try to resize its
634 * The target stroker handle.
637 * The target outline handle.
640 FT_Stroker_Export( FT_Stroker stroker,
641 FT_Outline* outline );
644 /**************************************************************
650 * Destroy a stroker object.
654 * A stroker handle. Can be NULL.
657 FT_Stroker_Done( FT_Stroker stroker );
660 /**************************************************************
666 * Stroke a given outline glyph object with a given stroker.
670 * Source glyph handle on input, new glyph handle on output.
677 * A Boolean. If~1, the source glyph object is destroyed
681 * FreeType error code. 0~means success.
684 * The source glyph is untouched in case of error.
686 * Adding stroke may yield a significantly wider and taller glyph
687 * depending on how large of a radius was used to stroke the glyph. You
688 * may need to manually adjust horizontal and vertical advance amounts
689 * to account for this added size.
691 FT_EXPORT( FT_Error )
692 FT_Glyph_Stroke( FT_Glyph *pglyph,
697 /**************************************************************
700 * FT_Glyph_StrokeBorder
703 * Stroke a given outline glyph object with a given stroker, but
704 * only return either its inside or outside border.
708 * Source glyph handle on input, new glyph handle on output.
715 * A Boolean. If~1, return the inside border, otherwise
716 * the outside border.
719 * A Boolean. If~1, the source glyph object is destroyed
723 * FreeType error code. 0~means success.
726 * The source glyph is untouched in case of error.
728 * Adding stroke may yield a significantly wider and taller glyph
729 * depending on how large of a radius was used to stroke the glyph. You
730 * may need to manually adjust horizontal and vertical advance amounts
731 * to account for this added size.
733 FT_EXPORT( FT_Error )
734 FT_Glyph_StrokeBorder( FT_Glyph *pglyph,
743 #endif /* __FT_STROKE_H__ */
749 /* Local Variables: */