sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
ftstroke.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftstroke.h
4 *
5 * FreeType path stroker (specification).
6 *
7 * Copyright (C) 2002-2025 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
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.
15 *
16 */
17
18
23#ifndef FTSTROKE_H_
24#define FTSTROKE_H_
25
26#include <freetype/ftoutln.h>
27#include <freetype/ftglyph.h>
28
29
30FT_BEGIN_HEADER
31
32
33 /**************************************************************************
34 *
35 * @section:
36 * glyph_stroker
37 *
38 * @title:
39 * Glyph Stroker
40 *
41 * @abstract:
42 * Generating bordered and stroked glyphs.
43 *
44 * @description:
45 * This component generates stroked outlines of a given vectorial glyph.
46 * It also allows you to retrieve the 'outside' and/or the 'inside'
47 * borders of the stroke.
48 *
49 * This can be useful to generate 'bordered' glyph, i.e., glyphs
50 * displayed with a colored (and anti-aliased) border around their
51 * shape.
52 *
53 * @order:
54 * FT_Stroker
55 *
56 * FT_Stroker_LineJoin
57 * FT_Stroker_LineCap
58 * FT_StrokerBorder
59 *
60 * FT_Outline_GetInsideBorder
61 * FT_Outline_GetOutsideBorder
62 *
63 * FT_Glyph_Stroke
64 * FT_Glyph_StrokeBorder
65 *
66 * FT_Stroker_New
67 * FT_Stroker_Set
68 * FT_Stroker_Rewind
69 * FT_Stroker_ParseOutline
70 * FT_Stroker_Done
71 *
72 * FT_Stroker_BeginSubPath
73 * FT_Stroker_EndSubPath
74 *
75 * FT_Stroker_LineTo
76 * FT_Stroker_ConicTo
77 * FT_Stroker_CubicTo
78 *
79 * FT_Stroker_GetBorderCounts
80 * FT_Stroker_ExportBorder
81 * FT_Stroker_GetCounts
82 * FT_Stroker_Export
83 *
84 */
85
86
87 /**************************************************************************
88 *
89 * @type:
90 * FT_Stroker
91 *
92 * @description:
93 * Opaque handle to a path stroker object.
94 */
95 typedef struct FT_StrokerRec_* FT_Stroker;
96
97
98 /**************************************************************************
99 *
100 * @enum:
101 * FT_Stroker_LineJoin
102 *
103 * @description:
104 * These values determine how two joining lines are rendered in a
105 * stroker.
106 *
107 * @values:
108 * FT_STROKER_LINEJOIN_ROUND ::
109 * Used to render rounded line joins. Circular arcs are used to join
110 * two lines smoothly.
111 *
112 * FT_STROKER_LINEJOIN_BEVEL ::
113 * Used to render beveled line joins. The outer corner of the joined
114 * lines is filled by enclosing the triangular region of the corner
115 * with a straight line between the outer corners of each stroke.
116 *
117 * FT_STROKER_LINEJOIN_MITER_FIXED ::
118 * Used to render mitered line joins, with fixed bevels if the miter
119 * limit is exceeded. The outer edges of the strokes for the two
120 * segments are extended until they meet at an angle. A bevel join
121 * (see above) is used if the segments meet at too sharp an angle and
122 * the outer edges meet beyond a distance corresponding to the meter
123 * limit. This prevents long spikes being created.
124 * `FT_STROKER_LINEJOIN_MITER_FIXED` generates a miter line join as
125 * used in PostScript and PDF.
126 *
127 * FT_STROKER_LINEJOIN_MITER_VARIABLE ::
128 * FT_STROKER_LINEJOIN_MITER ::
129 * Used to render mitered line joins, with variable bevels if the miter
130 * limit is exceeded. The intersection of the strokes is clipped
131 * perpendicularly to the bisector, at a distance corresponding to
132 * the miter limit. This prevents long spikes being created.
133 * `FT_STROKER_LINEJOIN_MITER_VARIABLE` generates a mitered line join
134 * as used in XPS. `FT_STROKER_LINEJOIN_MITER` is an alias for
135 * `FT_STROKER_LINEJOIN_MITER_VARIABLE`, retained for backward
136 * compatibility.
137 */
138 typedef enum FT_Stroker_LineJoin_
139 {
140 FT_STROKER_LINEJOIN_ROUND = 0,
141 FT_STROKER_LINEJOIN_BEVEL = 1,
142 FT_STROKER_LINEJOIN_MITER_VARIABLE = 2,
143 FT_STROKER_LINEJOIN_MITER = FT_STROKER_LINEJOIN_MITER_VARIABLE,
144 FT_STROKER_LINEJOIN_MITER_FIXED = 3
145
146 } FT_Stroker_LineJoin;
147
148
149 /**************************************************************************
150 *
151 * @enum:
152 * FT_Stroker_LineCap
153 *
154 * @description:
155 * These values determine how the end of opened sub-paths are rendered in
156 * a stroke.
157 *
158 * @values:
159 * FT_STROKER_LINECAP_BUTT ::
160 * The end of lines is rendered as a full stop on the last point
161 * itself.
162 *
163 * FT_STROKER_LINECAP_ROUND ::
164 * The end of lines is rendered as a half-circle around the last point.
165 *
166 * FT_STROKER_LINECAP_SQUARE ::
167 * The end of lines is rendered as a square around the last point.
168 */
169 typedef enum FT_Stroker_LineCap_
170 {
171 FT_STROKER_LINECAP_BUTT = 0,
172 FT_STROKER_LINECAP_ROUND,
173 FT_STROKER_LINECAP_SQUARE
174
175 } FT_Stroker_LineCap;
176
177
178 /**************************************************************************
179 *
180 * @enum:
181 * FT_StrokerBorder
182 *
183 * @description:
184 * These values are used to select a given stroke border in
185 * @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder.
186 *
187 * @values:
188 * FT_STROKER_BORDER_LEFT ::
189 * Select the left border, relative to the drawing direction.
190 *
191 * FT_STROKER_BORDER_RIGHT ::
192 * Select the right border, relative to the drawing direction.
193 *
194 * @note:
195 * Applications are generally interested in the 'inside' and 'outside'
196 * borders. However, there is no direct mapping between these and the
197 * 'left' and 'right' ones, since this really depends on the glyph's
198 * drawing orientation, which varies between font formats.
199 *
200 * You can however use @FT_Outline_GetInsideBorder and
201 * @FT_Outline_GetOutsideBorder to get these.
202 */
203 typedef enum FT_StrokerBorder_
204 {
205 FT_STROKER_BORDER_LEFT = 0,
206 FT_STROKER_BORDER_RIGHT
207
208 } FT_StrokerBorder;
209
210
211 /**************************************************************************
212 *
213 * @function:
214 * FT_Outline_GetInsideBorder
215 *
216 * @description:
217 * Retrieve the @FT_StrokerBorder value corresponding to the 'inside'
218 * borders of a given outline.
219 *
220 * @input:
221 * outline ::
222 * The source outline handle.
223 *
224 * @return:
225 * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid
226 * outlines.
227 */
228 FT_EXPORT( FT_StrokerBorder )
229 FT_Outline_GetInsideBorder( FT_Outline* outline );
230
231
232 /**************************************************************************
233 *
234 * @function:
235 * FT_Outline_GetOutsideBorder
236 *
237 * @description:
238 * Retrieve the @FT_StrokerBorder value corresponding to the 'outside'
239 * borders of a given outline.
240 *
241 * @input:
242 * outline ::
243 * The source outline handle.
244 *
245 * @return:
246 * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid
247 * outlines.
248 */
249 FT_EXPORT( FT_StrokerBorder )
250 FT_Outline_GetOutsideBorder( FT_Outline* outline );
251
252
253 /**************************************************************************
254 *
255 * @function:
256 * FT_Stroker_New
257 *
258 * @description:
259 * Create a new stroker object.
260 *
261 * @input:
262 * library ::
263 * FreeType library handle.
264 *
265 * @output:
266 * astroker ::
267 * A new stroker object handle. `NULL` in case of error.
268 *
269 * @return:
270 * FreeType error code. 0~means success.
271 */
272 FT_EXPORT( FT_Error )
273 FT_Stroker_New( FT_Library library,
274 FT_Stroker *astroker );
275
276
277 /**************************************************************************
278 *
279 * @function:
280 * FT_Stroker_Set
281 *
282 * @description:
283 * Reset a stroker object's attributes.
284 *
285 * @input:
286 * stroker ::
287 * The target stroker handle.
288 *
289 * radius ::
290 * The border radius.
291 *
292 * line_cap ::
293 * The line cap style.
294 *
295 * line_join ::
296 * The line join style.
297 *
298 * miter_limit ::
299 * The maximum reciprocal sine of half-angle at the miter join,
300 * expressed as 16.16 fixed-point value.
301 *
302 * @note:
303 * The `radius` is expressed in the same units as the outline
304 * coordinates.
305 *
306 * The `miter_limit` multiplied by the `radius` gives the maximum size
307 * of a miter spike, at which it is clipped for
308 * @FT_STROKER_LINEJOIN_MITER_VARIABLE or replaced with a bevel join for
309 * @FT_STROKER_LINEJOIN_MITER_FIXED.
310 *
311 * This function calls @FT_Stroker_Rewind automatically.
312 */
313 FT_EXPORT( void )
314 FT_Stroker_Set( FT_Stroker stroker,
315 FT_Fixed radius,
316 FT_Stroker_LineCap line_cap,
317 FT_Stroker_LineJoin line_join,
318 FT_Fixed miter_limit );
319
320
321 /**************************************************************************
322 *
323 * @function:
324 * FT_Stroker_Rewind
325 *
326 * @description:
327 * Reset a stroker object without changing its attributes. You should
328 * call this function before beginning a new series of calls to
329 * @FT_Stroker_BeginSubPath or @FT_Stroker_EndSubPath.
330 *
331 * @input:
332 * stroker ::
333 * The target stroker handle.
334 */
335 FT_EXPORT( void )
336 FT_Stroker_Rewind( FT_Stroker stroker );
337
338
339 /**************************************************************************
340 *
341 * @function:
342 * FT_Stroker_ParseOutline
343 *
344 * @description:
345 * A convenience function used to parse a whole outline with the stroker.
346 * The resulting outline(s) can be retrieved later by functions like
347 * @FT_Stroker_GetCounts and @FT_Stroker_Export.
348 *
349 * @input:
350 * stroker ::
351 * The target stroker handle.
352 *
353 * outline ::
354 * The source outline.
355 *
356 * opened ::
357 * A boolean. If~1, the outline is treated as an open path instead of
358 * a closed one.
359 *
360 * @return:
361 * FreeType error code. 0~means success.
362 *
363 * @note:
364 * If `opened` is~0 (the default), the outline is treated as a closed
365 * path, and the stroker generates two distinct 'border' outlines.
366 *
367 * If `opened` is~1, the outline is processed as an open path, and the
368 * stroker generates a single 'stroke' outline.
369 *
370 * This function calls @FT_Stroker_Rewind automatically.
371 */
372 FT_EXPORT( FT_Error )
373 FT_Stroker_ParseOutline( FT_Stroker stroker,
374 FT_Outline* outline,
375 FT_Bool opened );
376
377
378 /**************************************************************************
379 *
380 * @function:
381 * FT_Stroker_BeginSubPath
382 *
383 * @description:
384 * Start a new sub-path in the stroker.
385 *
386 * @input:
387 * stroker ::
388 * The target stroker handle.
389 *
390 * to ::
391 * A pointer to the start vector.
392 *
393 * open ::
394 * A boolean. If~1, the sub-path is treated as an open one.
395 *
396 * @return:
397 * FreeType error code. 0~means success.
398 *
399 * @note:
400 * This function is useful when you need to stroke a path that is not
401 * stored as an @FT_Outline object.
402 */
403 FT_EXPORT( FT_Error )
404 FT_Stroker_BeginSubPath( FT_Stroker stroker,
405 FT_Vector* to,
406 FT_Bool open );
407
408
409 /**************************************************************************
410 *
411 * @function:
412 * FT_Stroker_EndSubPath
413 *
414 * @description:
415 * Close the current sub-path in the stroker.
416 *
417 * @input:
418 * stroker ::
419 * The target stroker handle.
420 *
421 * @return:
422 * FreeType error code. 0~means success.
423 *
424 * @note:
425 * You should call this function after @FT_Stroker_BeginSubPath. If the
426 * subpath was not 'opened', this function 'draws' a single line segment
427 * to the start position when needed.
428 */
429 FT_EXPORT( FT_Error )
430 FT_Stroker_EndSubPath( FT_Stroker stroker );
431
432
433 /**************************************************************************
434 *
435 * @function:
436 * FT_Stroker_LineTo
437 *
438 * @description:
439 * 'Draw' a single line segment in the stroker's current sub-path, from
440 * the last position.
441 *
442 * @input:
443 * stroker ::
444 * The target stroker handle.
445 *
446 * to ::
447 * A pointer to the destination point.
448 *
449 * @return:
450 * FreeType error code. 0~means success.
451 *
452 * @note:
453 * You should call this function between @FT_Stroker_BeginSubPath and
454 * @FT_Stroker_EndSubPath.
455 */
456 FT_EXPORT( FT_Error )
457 FT_Stroker_LineTo( FT_Stroker stroker,
458 FT_Vector* to );
459
460
461 /**************************************************************************
462 *
463 * @function:
464 * FT_Stroker_ConicTo
465 *
466 * @description:
467 * 'Draw' a single quadratic Bezier in the stroker's current sub-path,
468 * from the last position.
469 *
470 * @input:
471 * stroker ::
472 * The target stroker handle.
473 *
474 * control ::
475 * A pointer to a Bezier control point.
476 *
477 * to ::
478 * A pointer to the destination point.
479 *
480 * @return:
481 * FreeType error code. 0~means success.
482 *
483 * @note:
484 * You should call this function between @FT_Stroker_BeginSubPath and
485 * @FT_Stroker_EndSubPath.
486 */
487 FT_EXPORT( FT_Error )
488 FT_Stroker_ConicTo( FT_Stroker stroker,
489 FT_Vector* control,
490 FT_Vector* to );
491
492
493 /**************************************************************************
494 *
495 * @function:
496 * FT_Stroker_CubicTo
497 *
498 * @description:
499 * 'Draw' a single cubic Bezier in the stroker's current sub-path, from
500 * the last position.
501 *
502 * @input:
503 * stroker ::
504 * The target stroker handle.
505 *
506 * control1 ::
507 * A pointer to the first Bezier control point.
508 *
509 * control2 ::
510 * A pointer to second Bezier control point.
511 *
512 * to ::
513 * A pointer to the destination point.
514 *
515 * @return:
516 * FreeType error code. 0~means success.
517 *
518 * @note:
519 * You should call this function between @FT_Stroker_BeginSubPath and
520 * @FT_Stroker_EndSubPath.
521 */
522 FT_EXPORT( FT_Error )
523 FT_Stroker_CubicTo( FT_Stroker stroker,
524 FT_Vector* control1,
525 FT_Vector* control2,
526 FT_Vector* to );
527
528
529 /**************************************************************************
530 *
531 * @function:
532 * FT_Stroker_GetBorderCounts
533 *
534 * @description:
535 * Call this function once you have finished parsing your paths with the
536 * stroker. It returns the number of points and contours necessary to
537 * export one of the 'border' or 'stroke' outlines generated by the
538 * stroker.
539 *
540 * @input:
541 * stroker ::
542 * The target stroker handle.
543 *
544 * border ::
545 * The border index.
546 *
547 * @output:
548 * anum_points ::
549 * The number of points.
550 *
551 * anum_contours ::
552 * The number of contours.
553 *
554 * @return:
555 * FreeType error code. 0~means success.
556 *
557 * @note:
558 * When an outline, or a sub-path, is 'closed', the stroker generates two
559 * independent 'border' outlines, named 'left' and 'right'.
560 *
561 * When the outline, or a sub-path, is 'opened', the stroker merges the
562 * 'border' outlines with caps. The 'left' border receives all points,
563 * while the 'right' border becomes empty.
564 *
565 * Use the function @FT_Stroker_GetCounts instead if you want to retrieve
566 * the counts associated to both borders.
567 */
568 FT_EXPORT( FT_Error )
569 FT_Stroker_GetBorderCounts( FT_Stroker stroker,
570 FT_StrokerBorder border,
571 FT_UInt *anum_points,
572 FT_UInt *anum_contours );
573
574
575 /**************************************************************************
576 *
577 * @function:
578 * FT_Stroker_ExportBorder
579 *
580 * @description:
581 * Call this function after @FT_Stroker_GetBorderCounts to export the
582 * corresponding border to your own @FT_Outline structure.
583 *
584 * Note that this function appends the border points and contours to your
585 * outline, but does not try to resize its arrays.
586 *
587 * @input:
588 * stroker ::
589 * The target stroker handle.
590 *
591 * border ::
592 * The border index.
593 *
594 * outline ::
595 * The target outline handle.
596 *
597 * @note:
598 * Always call this function after @FT_Stroker_GetBorderCounts to get
599 * sure that there is enough room in your @FT_Outline object to receive
600 * all new data.
601 *
602 * When an outline, or a sub-path, is 'closed', the stroker generates two
603 * independent 'border' outlines, named 'left' and 'right'.
604 *
605 * When the outline, or a sub-path, is 'opened', the stroker merges the
606 * 'border' outlines with caps. The 'left' border receives all points,
607 * while the 'right' border becomes empty.
608 *
609 * Use the function @FT_Stroker_Export instead if you want to retrieve
610 * all borders at once.
611 */
612 FT_EXPORT( void )
613 FT_Stroker_ExportBorder( FT_Stroker stroker,
614 FT_StrokerBorder border,
615 FT_Outline* outline );
616
617
618 /**************************************************************************
619 *
620 * @function:
621 * FT_Stroker_GetCounts
622 *
623 * @description:
624 * Call this function once you have finished parsing your paths with the
625 * stroker. It returns the number of points and contours necessary to
626 * export all points/borders from the stroked outline/path.
627 *
628 * @input:
629 * stroker ::
630 * The target stroker handle.
631 *
632 * @output:
633 * anum_points ::
634 * The number of points.
635 *
636 * anum_contours ::
637 * The number of contours.
638 *
639 * @return:
640 * FreeType error code. 0~means success.
641 */
642 FT_EXPORT( FT_Error )
643 FT_Stroker_GetCounts( FT_Stroker stroker,
644 FT_UInt *anum_points,
645 FT_UInt *anum_contours );
646
647
648 /**************************************************************************
649 *
650 * @function:
651 * FT_Stroker_Export
652 *
653 * @description:
654 * Call this function after @FT_Stroker_GetBorderCounts to export all
655 * borders to your own @FT_Outline structure.
656 *
657 * Note that this function appends the border points and contours to your
658 * outline, but does not try to resize its arrays.
659 *
660 * @input:
661 * stroker ::
662 * The target stroker handle.
663 *
664 * outline ::
665 * The target outline handle.
666 */
667 FT_EXPORT( void )
668 FT_Stroker_Export( FT_Stroker stroker,
669 FT_Outline* outline );
670
671
672 /**************************************************************************
673 *
674 * @function:
675 * FT_Stroker_Done
676 *
677 * @description:
678 * Destroy a stroker object.
679 *
680 * @input:
681 * stroker ::
682 * A stroker handle. Can be `NULL`.
683 */
684 FT_EXPORT( void )
685 FT_Stroker_Done( FT_Stroker stroker );
686
687
688 /**************************************************************************
689 *
690 * @function:
691 * FT_Glyph_Stroke
692 *
693 * @description:
694 * Stroke a given outline glyph object with a given stroker.
695 *
696 * @inout:
697 * pglyph ::
698 * Source glyph handle on input, new glyph handle on output.
699 *
700 * @input:
701 * stroker ::
702 * A stroker handle.
703 *
704 * destroy ::
705 * A Boolean. If~1, the source glyph object is destroyed on success.
706 *
707 * @return:
708 * FreeType error code. 0~means success.
709 *
710 * @note:
711 * The source glyph is untouched in case of error.
712 *
713 * Adding stroke may yield a significantly wider and taller glyph
714 * depending on how large of a radius was used to stroke the glyph. You
715 * may need to manually adjust horizontal and vertical advance amounts to
716 * account for this added size.
717 */
718 FT_EXPORT( FT_Error )
719 FT_Glyph_Stroke( FT_Glyph *pglyph,
720 FT_Stroker stroker,
721 FT_Bool destroy );
722
723
724 /**************************************************************************
725 *
726 * @function:
727 * FT_Glyph_StrokeBorder
728 *
729 * @description:
730 * Stroke a given outline glyph object with a given stroker, but only
731 * return either its inside or outside border.
732 *
733 * @inout:
734 * pglyph ::
735 * Source glyph handle on input, new glyph handle on output.
736 *
737 * @input:
738 * stroker ::
739 * A stroker handle.
740 *
741 * inside ::
742 * A Boolean. If~1, return the inside border, otherwise the outside
743 * border.
744 *
745 * destroy ::
746 * A Boolean. If~1, the source glyph object is destroyed on success.
747 *
748 * @return:
749 * FreeType error code. 0~means success.
750 *
751 * @note:
752 * The source glyph is untouched in case of error.
753 *
754 * Adding stroke may yield a significantly wider and taller glyph
755 * depending on how large of a radius was used to stroke the glyph. You
756 * may need to manually adjust horizontal and vertical advance amounts to
757 * account for this added size.
758 */
759 FT_EXPORT( FT_Error )
760 FT_Glyph_StrokeBorder( FT_Glyph *pglyph,
761 FT_Stroker stroker,
762 FT_Bool inside,
763 FT_Bool destroy );
764
765 /* */
766
767FT_END_HEADER
768
769#endif /* FTSTROKE_H_ */
770
771
772/* END */
773
774
775/* Local Variables: */
776/* coding: utf-8 */
777/* End: */