summaryrefslogtreecommitdiff
path: root/src/static_libs/freetype/sw_ft_stroker.h
blob: 75830fb25c5aebb49ab50048e0d5c3300d4f2b36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#ifndef SW_FT_STROKER_H
#define SW_FT_STROKER_H
/***************************************************************************/
/*                                                                         */
/*  ftstroke.h                                                             */
/*                                                                         */
/*    FreeType path stroker (specification).                               */
/*                                                                         */
/*  Copyright 2002-2006, 2008, 2009, 2011-2012 by                          */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/***************************************************************************/

#include "sw_ft_raster.h"

 /**************************************************************
  *
  * @type:
  *   SW_FT_Stroker
  *
  * @description:
  *   Opaque handler to a path stroker object.
  */
  typedef struct SW_FT_StrokerRec_*  SW_FT_Stroker;


  /**************************************************************
   *
   * @enum:
   *   SW_FT_Stroker_LineJoin
   *
   * @description:
   *   These values determine how two joining lines are rendered
   *   in a stroker.
   *
   * @values:
   *   SW_FT_STROKER_LINEJOIN_ROUND ::
   *     Used to render rounded line joins.  Circular arcs are used
   *     to join two lines smoothly.
   *
   *   SW_FT_STROKER_LINEJOIN_BEVEL ::
   *     Used to render beveled line joins.  The outer corner of
   *     the joined lines is filled by enclosing the triangular
   *     region of the corner with a straight line between the
   *     outer corners of each stroke.
   *
   *   SW_FT_STROKER_LINEJOIN_MITER_FIXED ::
   *     Used to render mitered line joins, with fixed bevels if the
   *     miter limit is exceeded.  The outer edges of the strokes
   *     for the two segments are extended until they meet at an
   *     angle.  If the segments meet at too sharp an angle (such
   *     that the miter would extend from the intersection of the
   *     segments a distance greater than the product of the miter
   *     limit value and the border radius), then a bevel join (see
   *     above) is used instead.  This prevents long spikes being
   *     created.  SW_FT_STROKER_LINEJOIN_MITER_FIXED generates a miter
   *     line join as used in PostScript and PDF.
   *
   *   SW_FT_STROKER_LINEJOIN_MITER_VARIABLE ::
   *   SW_FT_STROKER_LINEJOIN_MITER ::
   *     Used to render mitered line joins, with variable bevels if
   *     the miter limit is exceeded.  The intersection of the
   *     strokes is clipped at a line perpendicular to the bisector
   *     of the angle between the strokes, at the distance from the
   *     intersection of the segments equal to the product of the
   *     miter limit value and the border radius.  This prevents
   *     long spikes being created.
   *     SW_FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line
   *     join as used in XPS.  SW_FT_STROKER_LINEJOIN_MITER is an alias
   *     for SW_FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for
   *     backwards compatibility.
   */
  typedef enum  SW_FT_Stroker_LineJoin_
  {
    SW_FT_STROKER_LINEJOIN_ROUND          = 0,
    SW_FT_STROKER_LINEJOIN_BEVEL          = 1,
    SW_FT_STROKER_LINEJOIN_MITER_VARIABLE = 2,
    SW_FT_STROKER_LINEJOIN_MITER          = SW_FT_STROKER_LINEJOIN_MITER_VARIABLE,
    SW_FT_STROKER_LINEJOIN_MITER_FIXED    = 3

  } SW_FT_Stroker_LineJoin;


  /**************************************************************
   *
   * @enum:
   *   SW_FT_Stroker_LineCap
   *
   * @description:
   *   These values determine how the end of opened sub-paths are
   *   rendered in a stroke.
   *
   * @values:
   *   SW_FT_STROKER_LINECAP_BUTT ::
   *     The end of lines is rendered as a full stop on the last
   *     point itself.
   *
   *   SW_FT_STROKER_LINECAP_ROUND ::
   *     The end of lines is rendered as a half-circle around the
   *     last point.
   *
   *   SW_FT_STROKER_LINECAP_SQUARE ::
   *     The end of lines is rendered as a square around the
   *     last point.
   */
  typedef enum  SW_FT_Stroker_LineCap_
  {
    SW_FT_STROKER_LINECAP_BUTT = 0,
    SW_FT_STROKER_LINECAP_ROUND,
    SW_FT_STROKER_LINECAP_SQUARE

  } SW_FT_Stroker_LineCap;


  /**************************************************************
   *
   * @enum:
   *   SW_FT_StrokerBorder
   *
   * @description:
   *   These values are used to select a given stroke border
   *   in @SW_FT_Stroker_GetBorderCounts and @SW_FT_Stroker_ExportBorder.
   *
   * @values:
   *   SW_FT_STROKER_BORDER_LEFT ::
   *     Select the left border, relative to the drawing direction.
   *
   *   SW_FT_STROKER_BORDER_RIGHT ::
   *     Select the right border, relative to the drawing direction.
   *
   * @note:
   *   Applications are generally interested in the `inside' and `outside'
   *   borders.  However, there is no direct mapping between these and the
   *   `left' and `right' ones, since this really depends on the glyph's
   *   drawing orientation, which varies between font formats.
   *
   *   You can however use @SW_FT_Outline_GetInsideBorder and
   *   @SW_FT_Outline_GetOutsideBorder to get these.
   */
  typedef enum  SW_FT_StrokerBorder_
  {
    SW_FT_STROKER_BORDER_LEFT = 0,
    SW_FT_STROKER_BORDER_RIGHT

  } SW_FT_StrokerBorder;


  /**************************************************************
   *
   * @function:
   *   SW_FT_Stroker_New
   *
   * @description:
   *   Create a new stroker object.
   *
   * @input:
   *   library ::
   *     FreeType library handle.
   *
   * @output:
   *   astroker ::
   *     A new stroker object handle.  NULL in case of error.
   *
   * @return:
   *    FreeType error code.  0~means success.
   */
  SW_FT_Error
  SW_FT_Stroker_New( SW_FT_Stroker  *astroker );


  /**************************************************************
   *
   * @function:
   *   SW_FT_Stroker_Set
   *
   * @description:
   *   Reset a stroker object's attributes.
   *
   * @input:
   *   stroker ::
   *     The target stroker handle.
   *
   *   radius ::
   *     The border radius.
   *
   *   line_cap ::
   *     The line cap style.
   *
   *   line_join ::
   *     The line join style.
   *
   *   miter_limit ::
   *     The miter limit for the SW_FT_STROKER_LINEJOIN_MITER_FIXED and
   *     SW_FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles,
   *     expressed as 16.16 fixed-point value.
   *
   * @note:
   *   The radius is expressed in the same units as the outline
   *   coordinates.
   */
  void
  SW_FT_Stroker_Set( SW_FT_Stroker           stroker,
                  SW_FT_Fixed             radius,
                  SW_FT_Stroker_LineCap   line_cap,
                  SW_FT_Stroker_LineJoin  line_join,
                  SW_FT_Fixed             miter_limit );

  /**************************************************************
   *
   * @function:
   *   SW_FT_Stroker_ParseOutline
   *
   * @description:
   *   A convenience function used to parse a whole outline with
   *   the stroker.  The resulting outline(s) can be retrieved
   *   later by functions like @SW_FT_Stroker_GetCounts and @SW_FT_Stroker_Export.
   *
   * @input:
   *   stroker ::
   *     The target stroker handle.
   *
   *   outline ::
   *     The source outline.
   *
   *   opened ::
   *     A boolean.  If~1, the outline is treated as an open path instead
   *     of a closed one.
   *
   * @return:
   *   FreeType error code.  0~means success.
   *
   * @note:
   *   If `opened' is~0 (the default), the outline is treated as a closed
   *   path, and the stroker generates two distinct `border' outlines.
   *
   *   If `opened' is~1, the outline is processed as an open path, and the
   *   stroker generates a single `stroke' outline.
   *
   *   This function calls @SW_FT_Stroker_Rewind automatically.
   */
  SW_FT_Error
  SW_FT_Stroker_ParseOutline( SW_FT_Stroker   stroker,
                           SW_FT_Outline*  outline,
                           SW_FT_Bool      opened );


  /**************************************************************
   *
   * @function:
   *   SW_FT_Stroker_GetCounts
   *
   * @description:
   *   Call this function once you have finished parsing your paths
   *   with the stroker.  It returns the number of points and
   *   contours necessary to export all points/borders from the stroked
   *   outline/path.
   *
   * @input:
   *   stroker ::
   *     The target stroker handle.
   *
   * @output:
   *   anum_points ::
   *     The number of points.
   *
   *   anum_contours ::
   *     The number of contours.
   *
   * @return:
   *   FreeType error code.  0~means success.
   */
  SW_FT_Error
  SW_FT_Stroker_GetCounts( SW_FT_Stroker  stroker,
                        SW_FT_UInt    *anum_points,
                        SW_FT_UInt    *anum_contours );


  /**************************************************************
   *
   * @function:
   *   SW_FT_Stroker_Export
   *
   * @description:
   *   Call this function after @SW_FT_Stroker_GetBorderCounts to
   *   export all borders to your own @SW_FT_Outline structure.
   *
   *   Note that this function appends the border points and
   *   contours to your outline, but does not try to resize its
   *   arrays.
   *
   * @input:
   *   stroker ::
   *     The target stroker handle.
   *
   *   outline ::
   *     The target outline handle.
   */
  void
  SW_FT_Stroker_Export( SW_FT_Stroker   stroker,
                     SW_FT_Outline*  outline );


  /**************************************************************
   *
   * @function:
   *   SW_FT_Stroker_Done
   *
   * @description:
   *   Destroy a stroker object.
   *
   * @input:
   *   stroker ::
   *     A stroker handle.  Can be NULL.
   */
  void
  SW_FT_Stroker_Done( SW_FT_Stroker  stroker );


#endif // SW_FT_STROKER_H