LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
gd_ft_stroker.h
1#ifndef GD_FT_STROKER_H
2#define GD_FT_STROKER_H
3/***************************************************************************/
4/* */
5/* ftstroke.h */
6/* */
7/* FreeType path stroker (specification). */
8/* */
9/* Copyright 2002-2006, 2008, 2009, 2011-2012 by */
10/* David Turner, Robert Wilhelm, and Werner Lemberg. */
11/* */
12/* This file is part of the FreeType project, and may only be used, */
13/* modified, and distributed under the terms of the FreeType project */
14/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
15/* this file you indicate that you have read the license and */
16/* understand and accept it fully. */
17/* */
18/***************************************************************************/
19
20#include "gd_ft_raster.h"
21
22/**************************************************************
23 *
24 * @type:
25 * GD_FT_Stroker
26 *
27 * @description:
28 * Opaque handler to a path stroker object.
29 */
30typedef struct GD_FT_StrokerRec_ *GD_FT_Stroker;
31
32/**************************************************************
33 *
34 * @enum:
35 * GD_FT_Stroker_LineJoin
36 *
37 * @description:
38 * These values determine how two joining lines are rendered
39 * in a stroker.
40 *
41 * @values:
42 * GD_FT_STROKER_LINEJOIN_ROUND ::
43 * Used to render rounded line joins. Circular arcs are used
44 * to join two lines smoothly.
45 *
46 * GD_FT_STROKER_LINEJOIN_BEVEL ::
47 * Used to render beveled line joins. The outer corner of
48 * the joined lines is filled by enclosing the triangular
49 * region of the corner with a straight line between the
50 * outer corners of each stroke.
51 *
52 * GD_FT_STROKER_LINEJOIN_MITER_FIXED ::
53 * Used to render mitered line joins, with fixed bevels if the
54 * miter limit is exceeded. The outer edges of the strokes
55 * for the two segments are extended until they meet at an
56 * angle. If the segments meet at too sharp an angle (such
57 * that the miter would extend from the intersection of the
58 * segments a distance greater than the product of the miter
59 * limit value and the border radius), then a bevel join (see
60 * above) is used instead. This prevents long spikes being
61 * created. GD_FT_STROKER_LINEJOIN_MITER_FIXED generates a miter
62 * line join as used in PostScript and PDF.
63 *
64 * GD_FT_STROKER_LINEJOIN_MITER_VARIABLE ::
65 * GD_FT_STROKER_LINEJOIN_MITER ::
66 * Used to render mitered line joins, with variable bevels if
67 * the miter limit is exceeded. The intersection of the
68 * strokes is clipped at a line perpendicular to the bisector
69 * of the angle between the strokes, at the distance from the
70 * intersection of the segments equal to the product of the
71 * miter limit value and the border radius. This prevents
72 * long spikes being created.
73 * GD_FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line
74 * join as used in XPS. GD_FT_STROKER_LINEJOIN_MITER is an alias
75 * for GD_FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for
76 * backwards compatibility.
77 */
78typedef enum GD_FT_Stroker_LineJoin_ {
79 GD_FT_STROKER_LINEJOIN_ROUND = 0,
80 GD_FT_STROKER_LINEJOIN_BEVEL = 1,
81 GD_FT_STROKER_LINEJOIN_MITER_VARIABLE = 2,
82 GD_FT_STROKER_LINEJOIN_MITER = GD_FT_STROKER_LINEJOIN_MITER_VARIABLE,
83 GD_FT_STROKER_LINEJOIN_MITER_FIXED = 3
84
85} GD_FT_Stroker_LineJoin;
86
87/**************************************************************
88 *
89 * @enum:
90 * GD_FT_Stroker_LineCap
91 *
92 * @description:
93 * These values determine how the end of opened sub-paths are
94 * rendered in a stroke.
95 *
96 * @values:
97 * GD_FT_STROKER_LINECAP_BUTT ::
98 * The end of lines is rendered as a full stop on the last
99 * point itself.
100 *
101 * GD_FT_STROKER_LINECAP_ROUND ::
102 * The end of lines is rendered as a half-circle around the
103 * last point.
104 *
105 * GD_FT_STROKER_LINECAP_SQUARE ::
106 * The end of lines is rendered as a square around the
107 * last point.
108 */
109typedef enum GD_FT_Stroker_LineCap_ {
110 GD_FT_STROKER_LINECAP_BUTT = 0,
111 GD_FT_STROKER_LINECAP_ROUND,
112 GD_FT_STROKER_LINECAP_SQUARE
113
114} GD_FT_Stroker_LineCap;
115
116/**************************************************************
117 *
118 * @enum:
119 * GD_FT_StrokerBorder
120 *
121 * @description:
122 * These values are used to select a given stroke border
123 * in @GD_FT_Stroker_GetBorderCounts and @GD_FT_Stroker_ExportBorder.
124 *
125 * @values:
126 * GD_FT_STROKER_BORDER_LEFT ::
127 * Select the left border, relative to the drawing direction.
128 *
129 * GD_FT_STROKER_BORDER_RIGHT ::
130 * Select the right border, relative to the drawing direction.
131 *
132 * @note:
133 * Applications are generally interested in the `inside' and `outside'
134 * borders. However, there is no direct mapping between these and the
135 * `left' and `right' ones, since this really depends on the glyph's
136 * drawing orientation, which varies between font formats.
137 *
138 * You can however use @GD_FT_Outline_GetInsideBorder and
139 * @GD_FT_Outline_GetOutsideBorder to get these.
140 */
141typedef enum GD_FT_StrokerBorder_ {
142 GD_FT_STROKER_BORDER_LEFT = 0,
143 GD_FT_STROKER_BORDER_RIGHT
144
145} GD_FT_StrokerBorder;
146
147/**************************************************************
148 *
149 * @function:
150 * GD_FT_Stroker_New
151 *
152 * @description:
153 * Create a new stroker object.
154 *
155 * @input:
156 * library ::
157 * FreeType library handle.
158 *
159 * @output:
160 * astroker ::
161 * A new stroker object handle. NULL in case of error.
162 *
163 * @return:
164 * FreeType error code. 0~means success.
165 */
166GD_FT_Error GD_FT_Stroker_New(GD_FT_Stroker *astroker);
167
168/**************************************************************
169 *
170 * @function:
171 * GD_FT_Stroker_Set
172 *
173 * @description:
174 * Reset a stroker object's attributes.
175 *
176 * @input:
177 * stroker ::
178 * The target stroker handle.
179 *
180 * radius ::
181 * The border radius.
182 *
183 * line_cap ::
184 * The line cap style.
185 *
186 * line_join ::
187 * The line join style.
188 *
189 * miter_limit ::
190 * The miter limit for the GD_FT_STROKER_LINEJOIN_MITER_FIXED and
191 * GD_FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles,
192 * expressed as 16.16 fixed-point value.
193 *
194 * @note:
195 * The radius is expressed in the same units as the outline
196 * coordinates.
197 */
198void GD_FT_Stroker_Set(GD_FT_Stroker stroker, GD_FT_Fixed radius, GD_FT_Stroker_LineCap line_cap,
199 GD_FT_Stroker_LineJoin line_join, GD_FT_Fixed miter_limit);
200
201/**************************************************************
202 *
203 * @function:
204 * GD_FT_Stroker_ParseOutline
205 *
206 * @description:
207 * A convenience function used to parse a whole outline with
208 * the stroker. The resulting outline(s) can be retrieved
209 * later by functions like @GD_FT_Stroker_GetCounts and @GD_FT_Stroker_Export.
210 *
211 * @input:
212 * stroker ::
213 * The target stroker handle.
214 *
215 * outline ::
216 * The source outline.
217 *
218 *
219 * @return:
220 * FreeType error code. 0~means success.
221 *
222 * @note:
223 * If `opened' is~0 (the default), the outline is treated as a closed
224 * path, and the stroker generates two distinct `border' outlines.
225 *
226 *
227 * This function calls @GD_FT_Stroker_Rewind automatically.
228 */
229GD_FT_Error GD_FT_Stroker_ParseOutline(GD_FT_Stroker stroker, const GD_FT_Outline *outline);
230
231/**************************************************************
232 *
233 * @function:
234 * GD_FT_Stroker_GetCounts
235 *
236 * @description:
237 * Call this function once you have finished parsing your paths
238 * with the stroker. It returns the number of points and
239 * contours necessary to export all points/borders from the stroked
240 * outline/path.
241 *
242 * @input:
243 * stroker ::
244 * The target stroker handle.
245 *
246 * @output:
247 * anum_points ::
248 * The number of points.
249 *
250 * anum_contours ::
251 * The number of contours.
252 *
253 * @return:
254 * FreeType error code. 0~means success.
255 */
256GD_FT_Error GD_FT_Stroker_GetCounts(GD_FT_Stroker stroker, GD_FT_UInt *anum_points,
257 GD_FT_UInt *anum_contours);
258
259/**************************************************************
260 *
261 * @function:
262 * GD_FT_Stroker_ExportBorder
263 *
264 * @description:
265 * Export a single border of a stroked outline.
266 *
267 * @input:
268 * stroker ::
269 * The target stroker handle.
270 *
271 * border ::
272 * The border to export (LEFT or RIGHT).
273 *
274 * outline ::
275 * The target outline handle.
276 *
277 * @note:
278 * Call this after GD_FT_Stroker_GetCounts to get individual borders.
279 * The outline must be pre-allocated with sufficient space.
280 */
281void GD_FT_Stroker_ExportBorder(GD_FT_Stroker stroker, GD_FT_StrokerBorder border,
282 GD_FT_Outline *outline);
283
284/**************************************************************
285 *
286 * @function:
287 * GD_FT_Stroker_Export
288 *
289 * @description:
290 * Call this function after @GD_FT_Stroker_GetBorderCounts to
291 * export all borders to your own @GD_FT_Outline structure.
292 *
293 * Note that this function appends the border points and
294 * contours to your outline, but does not try to resize its
295 * arrays.
296 *
297 * @input:
298 * stroker ::
299 * The target stroker handle.
300 *
301 * outline ::
302 * The target outline handle.
303 */
304void GD_FT_Stroker_Export(GD_FT_Stroker stroker, GD_FT_Outline *outline);
305
306/**************************************************************
307 *
308 * @function:
309 * GD_FT_Stroker_Done
310 *
311 * @description:
312 * Destroy a stroker object.
313 *
314 * @input:
315 * stroker ::
316 * A stroker handle. Can be NULL.
317 */
318void GD_FT_Stroker_Done(GD_FT_Stroker stroker);
319
320#endif // GD_FT_STROKER_H