1 /****************************************************************************
5 * FreeType path stroker (body).
7 * Copyright (C) 2002-2020 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.
19 #include <freetype/ftstroke.h>
20 #include <freetype/fttrigon.h>
21 #include <freetype/ftoutln.h>
22 #include <freetype/internal/ftmemory.h>
23 #include <freetype/internal/ftdebug.h>
24 #include <freetype/internal/ftobjs.h>
27 /* declare an extern to access `ft_outline_glyph_class' globally */
28 /* allocated in `ftglyph.c' */
29 FT_CALLBACK_TABLE const FT_Glyph_Class ft_outline_glyph_class;
32 /* documentation is in ftstroke.h */
34 FT_EXPORT_DEF( FT_StrokerBorder )
35 FT_Outline_GetInsideBorder( FT_Outline* outline )
37 FT_Orientation o = FT_Outline_Get_Orientation( outline );
40 return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_RIGHT
41 : FT_STROKER_BORDER_LEFT;
45 /* documentation is in ftstroke.h */
47 FT_EXPORT_DEF( FT_StrokerBorder )
48 FT_Outline_GetOutsideBorder( FT_Outline* outline )
50 FT_Orientation o = FT_Outline_Get_Orientation( outline );
53 return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_LEFT
54 : FT_STROKER_BORDER_RIGHT;
58 /*************************************************************************/
59 /*************************************************************************/
61 /***** BEZIER COMPUTATIONS *****/
63 /*************************************************************************/
64 /*************************************************************************/
66 #define FT_SMALL_CONIC_THRESHOLD ( FT_ANGLE_PI / 6 )
67 #define FT_SMALL_CUBIC_THRESHOLD ( FT_ANGLE_PI / 8 )
71 #define FT_IS_SMALL( x ) ( (x) > -FT_EPSILON && (x) < FT_EPSILON )
75 ft_pos_abs( FT_Pos x )
77 return x >= 0 ? x : -x;
82 ft_conic_split( FT_Vector* base )
87 base[4].x = base[2].x;
88 a = base[0].x + base[1].x;
89 b = base[1].x + base[2].x;
91 base[2].x = ( a + b ) >> 2;
94 base[4].y = base[2].y;
95 a = base[0].y + base[1].y;
96 b = base[1].y + base[2].y;
98 base[2].y = ( a + b ) >> 2;
104 ft_conic_is_small_enough( FT_Vector* base,
106 FT_Angle *angle_out )
110 FT_Int close1, close2;
113 d1.x = base[1].x - base[2].x;
114 d1.y = base[1].y - base[2].y;
115 d2.x = base[0].x - base[1].x;
116 d2.y = base[0].y - base[1].y;
118 close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
119 close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
125 /* basically a point; */
126 /* do nothing to retain original direction */
131 *angle_out = FT_Atan2( d2.x, d2.y );
139 *angle_out = FT_Atan2( d1.x, d1.y );
143 *angle_in = FT_Atan2( d1.x, d1.y );
144 *angle_out = FT_Atan2( d2.x, d2.y );
148 theta = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_out ) );
150 return FT_BOOL( theta < FT_SMALL_CONIC_THRESHOLD );
155 ft_cubic_split( FT_Vector* base )
160 base[6].x = base[3].x;
161 a = base[0].x + base[1].x;
162 b = base[1].x + base[2].x;
163 c = base[2].x + base[3].x;
170 base[3].x = ( a + c ) >> 3;
172 base[6].y = base[3].y;
173 a = base[0].y + base[1].y;
174 b = base[1].y + base[2].y;
175 c = base[2].y + base[3].y;
182 base[3].y = ( a + c ) >> 3;
186 /* Return the average of `angle1' and `angle2'. */
187 /* This gives correct result even if `angle1' and `angle2' */
188 /* have opposite signs. */
190 ft_angle_mean( FT_Angle angle1,
193 return angle1 + FT_Angle_Diff( angle1, angle2 ) / 2;
198 ft_cubic_is_small_enough( FT_Vector* base,
201 FT_Angle *angle_out )
203 FT_Vector d1, d2, d3;
204 FT_Angle theta1, theta2;
205 FT_Int close1, close2, close3;
208 d1.x = base[2].x - base[3].x;
209 d1.y = base[2].y - base[3].y;
210 d2.x = base[1].x - base[2].x;
211 d2.y = base[1].y - base[2].y;
212 d3.x = base[0].x - base[1].x;
213 d3.y = base[0].y - base[1].y;
215 close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
216 close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
217 close3 = FT_IS_SMALL( d3.x ) && FT_IS_SMALL( d3.y );
225 /* basically a point; */
226 /* do nothing to retain original direction */
232 *angle_out = FT_Atan2( d3.x, d3.y );
241 *angle_out = FT_Atan2( d2.x, d2.y );
246 *angle_mid = FT_Atan2( d2.x, d2.y );
247 *angle_out = FT_Atan2( d3.x, d3.y );
259 *angle_out = FT_Atan2( d1.x, d1.y );
263 *angle_in = FT_Atan2( d1.x, d1.y );
264 *angle_out = FT_Atan2( d3.x, d3.y );
265 *angle_mid = ft_angle_mean( *angle_in, *angle_out );
272 *angle_in = FT_Atan2( d1.x, d1.y );
274 *angle_out = FT_Atan2( d2.x, d2.y );
278 *angle_in = FT_Atan2( d1.x, d1.y );
279 *angle_mid = FT_Atan2( d2.x, d2.y );
280 *angle_out = FT_Atan2( d3.x, d3.y );
285 theta1 = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_mid ) );
286 theta2 = ft_pos_abs( FT_Angle_Diff( *angle_mid, *angle_out ) );
288 return FT_BOOL( theta1 < FT_SMALL_CUBIC_THRESHOLD &&
289 theta2 < FT_SMALL_CUBIC_THRESHOLD );
293 /*************************************************************************/
294 /*************************************************************************/
296 /***** STROKE BORDERS *****/
298 /*************************************************************************/
299 /*************************************************************************/
301 typedef enum FT_StrokeTags_
303 FT_STROKE_TAG_ON = 1, /* on-curve point */
304 FT_STROKE_TAG_CUBIC = 2, /* cubic off-point */
305 FT_STROKE_TAG_BEGIN = 4, /* sub-path start */
306 FT_STROKE_TAG_END = 8 /* sub-path end */
310 #define FT_STROKE_TAG_BEGIN_END ( FT_STROKE_TAG_BEGIN | FT_STROKE_TAG_END )
312 typedef struct FT_StrokeBorderRec_
318 FT_Bool movable; /* TRUE for ends of lineto borders */
319 FT_Int start; /* index of current sub-path start point */
323 } FT_StrokeBorderRec, *FT_StrokeBorder;
327 ft_stroke_border_grow( FT_StrokeBorder border,
330 FT_UInt old_max = border->max_points;
331 FT_UInt new_max = border->num_points + new_points;
332 FT_Error error = FT_Err_Ok;
335 if ( new_max > old_max )
337 FT_UInt cur_max = old_max;
338 FT_Memory memory = border->memory;
341 while ( cur_max < new_max )
342 cur_max += ( cur_max >> 1 ) + 16;
344 if ( FT_RENEW_ARRAY( border->points, old_max, cur_max ) ||
345 FT_RENEW_ARRAY( border->tags, old_max, cur_max ) )
348 border->max_points = cur_max;
357 ft_stroke_border_close( FT_StrokeBorder border,
360 FT_UInt start = (FT_UInt)border->start;
361 FT_UInt count = border->num_points;
364 FT_ASSERT( border->start >= 0 );
366 /* don't record empty paths! */
367 if ( count <= start + 1U )
368 border->num_points = start;
371 /* copy the last point to the start of this sub-path, since */
372 /* it contains the `adjusted' starting coordinates */
373 border->num_points = --count;
374 border->points[start] = border->points[count];
375 border->tags[start] = border->tags[count];
379 /* reverse the points */
381 FT_Vector* vec1 = border->points + start + 1;
382 FT_Vector* vec2 = border->points + count - 1;
385 for ( ; vec1 < vec2; vec1++, vec2-- )
398 FT_Byte* tag1 = border->tags + start + 1;
399 FT_Byte* tag2 = border->tags + count - 1;
402 for ( ; tag1 < tag2; tag1++, tag2-- )
414 border->tags[start ] |= FT_STROKE_TAG_BEGIN;
415 border->tags[count - 1] |= FT_STROKE_TAG_END;
419 border->movable = FALSE;
424 ft_stroke_border_lineto( FT_StrokeBorder border,
428 FT_Error error = FT_Err_Ok;
431 FT_ASSERT( border->start >= 0 );
433 if ( border->movable )
435 /* move last point */
436 border->points[border->num_points - 1] = *to;
440 /* don't add zero-length lineto, but always add moveto */
441 if ( border->num_points > (FT_UInt)border->start &&
442 FT_IS_SMALL( border->points[border->num_points - 1].x - to->x ) &&
443 FT_IS_SMALL( border->points[border->num_points - 1].y - to->y ) )
447 error = ft_stroke_border_grow( border, 1 );
450 FT_Vector* vec = border->points + border->num_points;
451 FT_Byte* tag = border->tags + border->num_points;
455 tag[0] = FT_STROKE_TAG_ON;
457 border->num_points += 1;
460 border->movable = movable;
466 ft_stroke_border_conicto( FT_StrokeBorder border,
473 FT_ASSERT( border->start >= 0 );
475 error = ft_stroke_border_grow( border, 2 );
478 FT_Vector* vec = border->points + border->num_points;
479 FT_Byte* tag = border->tags + border->num_points;
486 tag[1] = FT_STROKE_TAG_ON;
488 border->num_points += 2;
491 border->movable = FALSE;
498 ft_stroke_border_cubicto( FT_StrokeBorder border,
506 FT_ASSERT( border->start >= 0 );
508 error = ft_stroke_border_grow( border, 3 );
511 FT_Vector* vec = border->points + border->num_points;
512 FT_Byte* tag = border->tags + border->num_points;
519 tag[0] = FT_STROKE_TAG_CUBIC;
520 tag[1] = FT_STROKE_TAG_CUBIC;
521 tag[2] = FT_STROKE_TAG_ON;
523 border->num_points += 3;
526 border->movable = FALSE;
532 #define FT_ARC_CUBIC_ANGLE ( FT_ANGLE_PI / 2 )
536 ft_stroke_border_arcto( FT_StrokeBorder border,
539 FT_Angle angle_start,
540 FT_Angle angle_diff )
543 FT_Vector a0, a1, a2, a3;
545 FT_Error error = FT_Err_Ok;
548 /* number of cubic arcs to draw */
549 while ( angle_diff > FT_ARC_CUBIC_ANGLE * arcs ||
550 -angle_diff > FT_ARC_CUBIC_ANGLE * arcs )
553 /* control tangents */
554 coef = FT_Tan( angle_diff / ( 4 * arcs ) );
557 /* compute start and first control point */
558 FT_Vector_From_Polar( &a0, radius, angle_start );
559 a1.x = FT_MulFix( -a0.y, coef );
560 a1.y = FT_MulFix( a0.x, coef );
567 for ( i = 1; i <= arcs; i++ )
569 /* compute end and second control point */
570 FT_Vector_From_Polar( &a3, radius,
571 angle_start + i * angle_diff / arcs );
572 a2.x = FT_MulFix( a3.y, coef );
573 a2.y = FT_MulFix( -a3.x, coef );
581 error = ft_stroke_border_cubicto( border, &a1, &a2, &a3 );
586 a1.x = a3.x - a2.x + a3.x;
587 a1.y = a3.y - a2.y + a3.y;
595 ft_stroke_border_moveto( FT_StrokeBorder border,
598 /* close current open path if any ? */
599 if ( border->start >= 0 )
600 ft_stroke_border_close( border, FALSE );
602 border->start = (FT_Int)border->num_points;
603 border->movable = FALSE;
605 return ft_stroke_border_lineto( border, to, FALSE );
610 ft_stroke_border_init( FT_StrokeBorder border,
613 border->memory = memory;
614 border->points = NULL;
617 border->num_points = 0;
618 border->max_points = 0;
620 border->valid = FALSE;
625 ft_stroke_border_reset( FT_StrokeBorder border )
627 border->num_points = 0;
629 border->valid = FALSE;
634 ft_stroke_border_done( FT_StrokeBorder border )
636 FT_Memory memory = border->memory;
639 FT_FREE( border->points );
640 FT_FREE( border->tags );
642 border->num_points = 0;
643 border->max_points = 0;
645 border->valid = FALSE;
650 ft_stroke_border_get_counts( FT_StrokeBorder border,
651 FT_UInt *anum_points,
652 FT_UInt *anum_contours )
654 FT_Error error = FT_Err_Ok;
655 FT_UInt num_points = 0;
656 FT_UInt num_contours = 0;
658 FT_UInt count = border->num_points;
659 FT_Vector* point = border->points;
660 FT_Byte* tags = border->tags;
661 FT_Int in_contour = 0;
664 for ( ; count > 0; count--, num_points++, point++, tags++ )
666 if ( tags[0] & FT_STROKE_TAG_BEGIN )
668 if ( in_contour != 0 )
673 else if ( in_contour == 0 )
676 if ( tags[0] & FT_STROKE_TAG_END )
683 if ( in_contour != 0 )
686 border->valid = TRUE;
689 *anum_points = num_points;
690 *anum_contours = num_contours;
701 ft_stroke_border_export( FT_StrokeBorder border,
702 FT_Outline* outline )
704 /* copy point locations */
705 if ( border->num_points )
706 FT_ARRAY_COPY( outline->points + outline->n_points,
708 border->num_points );
712 FT_UInt count = border->num_points;
713 FT_Byte* read = border->tags;
714 FT_Byte* write = (FT_Byte*)outline->tags + outline->n_points;
717 for ( ; count > 0; count--, read++, write++ )
719 if ( *read & FT_STROKE_TAG_ON )
720 *write = FT_CURVE_TAG_ON;
721 else if ( *read & FT_STROKE_TAG_CUBIC )
722 *write = FT_CURVE_TAG_CUBIC;
724 *write = FT_CURVE_TAG_CONIC;
730 FT_UInt count = border->num_points;
731 FT_Byte* tags = border->tags;
732 FT_Short* write = outline->contours + outline->n_contours;
733 FT_Short idx = (FT_Short)outline->n_points;
736 for ( ; count > 0; count--, tags++, idx++ )
738 if ( *tags & FT_STROKE_TAG_END )
741 outline->n_contours++;
746 outline->n_points += (short)border->num_points;
748 FT_ASSERT( FT_Outline_Check( outline ) == 0 );
752 /*************************************************************************/
753 /*************************************************************************/
755 /***** STROKER *****/
757 /*************************************************************************/
758 /*************************************************************************/
760 #define FT_SIDE_TO_ROTATE( s ) ( FT_ANGLE_PI2 - (s) * FT_ANGLE_PI )
762 typedef struct FT_StrokerRec_
764 FT_Angle angle_in; /* direction into curr join */
765 FT_Angle angle_out; /* direction out of join */
766 FT_Vector center; /* current position */
767 FT_Fixed line_length; /* length of last lineto */
768 FT_Bool first_point; /* is this the start? */
769 FT_Bool subpath_open; /* is the subpath open? */
770 FT_Angle subpath_angle; /* subpath start direction */
771 FT_Vector subpath_start; /* subpath start position */
772 FT_Fixed subpath_line_length; /* subpath start lineto len */
773 FT_Bool handle_wide_strokes; /* use wide strokes logic? */
775 FT_Stroker_LineCap line_cap;
776 FT_Stroker_LineJoin line_join;
777 FT_Stroker_LineJoin line_join_saved;
778 FT_Fixed miter_limit;
781 FT_StrokeBorderRec borders[2];
787 /* documentation is in ftstroke.h */
789 FT_EXPORT_DEF( FT_Error )
790 FT_Stroker_New( FT_Library library,
791 FT_Stroker *astroker )
793 FT_Error error; /* assigned in FT_NEW */
795 FT_Stroker stroker = NULL;
799 return FT_THROW( Invalid_Library_Handle );
802 return FT_THROW( Invalid_Argument );
804 memory = library->memory;
806 if ( !FT_NEW( stroker ) )
808 stroker->library = library;
810 ft_stroke_border_init( &stroker->borders[0], memory );
811 ft_stroke_border_init( &stroker->borders[1], memory );
820 /* documentation is in ftstroke.h */
822 FT_EXPORT_DEF( void )
823 FT_Stroker_Set( FT_Stroker stroker,
825 FT_Stroker_LineCap line_cap,
826 FT_Stroker_LineJoin line_join,
827 FT_Fixed miter_limit )
832 stroker->radius = radius;
833 stroker->line_cap = line_cap;
834 stroker->line_join = line_join;
835 stroker->miter_limit = miter_limit;
837 /* ensure miter limit has sensible value */
838 if ( stroker->miter_limit < 0x10000L )
839 stroker->miter_limit = 0x10000L;
841 /* save line join style: */
842 /* line join style can be temporarily changed when stroking curves */
843 stroker->line_join_saved = line_join;
845 FT_Stroker_Rewind( stroker );
849 /* documentation is in ftstroke.h */
851 FT_EXPORT_DEF( void )
852 FT_Stroker_Rewind( FT_Stroker stroker )
856 ft_stroke_border_reset( &stroker->borders[0] );
857 ft_stroke_border_reset( &stroker->borders[1] );
862 /* documentation is in ftstroke.h */
864 FT_EXPORT_DEF( void )
865 FT_Stroker_Done( FT_Stroker stroker )
869 FT_Memory memory = stroker->library->memory;
872 ft_stroke_border_done( &stroker->borders[0] );
873 ft_stroke_border_done( &stroker->borders[1] );
875 stroker->library = NULL;
881 /* create a circular arc at a corner or cap */
883 ft_stroker_arcto( FT_Stroker stroker,
886 FT_Angle total, rotate;
887 FT_Fixed radius = stroker->radius;
888 FT_Error error = FT_Err_Ok;
889 FT_StrokeBorder border = stroker->borders + side;
892 rotate = FT_SIDE_TO_ROTATE( side );
894 total = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
895 if ( total == FT_ANGLE_PI )
898 error = ft_stroke_border_arcto( border,
901 stroker->angle_in + rotate,
903 border->movable = FALSE;
908 /* add a cap at the end of an opened path */
910 ft_stroker_cap( FT_Stroker stroker,
914 FT_Error error = FT_Err_Ok;
917 if ( stroker->line_cap == FT_STROKER_LINECAP_ROUND )
919 /* add a round cap */
920 stroker->angle_in = angle;
921 stroker->angle_out = angle + FT_ANGLE_PI;
923 error = ft_stroker_arcto( stroker, side );
927 /* add a square or butt cap */
928 FT_Vector middle, delta;
929 FT_Fixed radius = stroker->radius;
930 FT_StrokeBorder border = stroker->borders + side;
933 /* compute middle point and first angle point */
934 FT_Vector_From_Polar( &middle, radius, angle );
935 delta.x = side ? middle.y : -middle.y;
936 delta.y = side ? -middle.x : middle.x;
938 if ( stroker->line_cap == FT_STROKER_LINECAP_SQUARE )
940 middle.x += stroker->center.x;
941 middle.y += stroker->center.y;
943 else /* FT_STROKER_LINECAP_BUTT */
945 middle.x = stroker->center.x;
946 middle.y = stroker->center.y;
952 error = ft_stroke_border_lineto( border, &delta, FALSE );
956 /* compute second angle point */
957 delta.x = middle.x - delta.x + middle.x;
958 delta.y = middle.y - delta.y + middle.y;
960 error = ft_stroke_border_lineto( border, &delta, FALSE );
968 /* process an inside corner, i.e. compute intersection */
970 ft_stroker_inside( FT_Stroker stroker,
972 FT_Fixed line_length )
974 FT_StrokeBorder border = stroker->borders + side;
975 FT_Angle phi, theta, rotate;
977 FT_Vector sigma, delta;
978 FT_Error error = FT_Err_Ok;
979 FT_Bool intersect; /* use intersection of lines? */
982 rotate = FT_SIDE_TO_ROTATE( side );
984 theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ) / 2;
986 /* Only intersect borders if between two lineto's and both */
987 /* lines are long enough (line_length is zero for curves). */
988 /* Also avoid U-turns of nearly 180 degree. */
989 if ( !border->movable || line_length == 0 ||
990 theta > 0x59C000 || theta < -0x59C000 )
994 /* compute minimum required length of lines */
998 FT_Vector_Unit( &sigma, theta );
1000 ft_pos_abs( FT_MulDiv( stroker->radius, sigma.y, sigma.x ) );
1002 intersect = FT_BOOL( min_length &&
1003 stroker->line_length >= min_length &&
1004 line_length >= min_length );
1009 FT_Vector_From_Polar( &delta, stroker->radius,
1010 stroker->angle_out + rotate );
1011 delta.x += stroker->center.x;
1012 delta.y += stroker->center.y;
1014 border->movable = FALSE;
1018 /* compute median angle */
1019 phi = stroker->angle_in + theta + rotate;
1021 length = FT_DivFix( stroker->radius, sigma.x );
1023 FT_Vector_From_Polar( &delta, length, phi );
1024 delta.x += stroker->center.x;
1025 delta.y += stroker->center.y;
1028 error = ft_stroke_border_lineto( border, &delta, FALSE );
1034 /* process an outside corner, i.e. compute bevel/miter/round */
1036 ft_stroker_outside( FT_Stroker stroker,
1038 FT_Fixed line_length )
1040 FT_StrokeBorder border = stroker->borders + side;
1045 if ( stroker->line_join == FT_STROKER_LINEJOIN_ROUND )
1046 error = ft_stroker_arcto( stroker, side );
1049 /* this is a mitered (pointed) or beveled (truncated) corner */
1050 FT_Fixed radius = stroker->radius;
1052 FT_Angle theta = 0, phi = 0;
1053 FT_Bool bevel, fixed_bevel;
1056 rotate = FT_SIDE_TO_ROTATE( side );
1059 FT_BOOL( stroker->line_join == FT_STROKER_LINEJOIN_BEVEL );
1062 FT_BOOL( stroker->line_join != FT_STROKER_LINEJOIN_MITER_VARIABLE );
1064 /* check miter limit first */
1067 theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ) / 2;
1069 if ( theta == FT_ANGLE_PI2 )
1072 phi = stroker->angle_in + theta + rotate;
1074 FT_Vector_From_Polar( &sigma, stroker->miter_limit, theta );
1076 /* is miter limit exceeded? */
1077 if ( sigma.x < 0x10000L )
1079 /* don't create variable bevels for very small deviations; */
1080 /* FT_Sin(x) = 0 for x <= 57 */
1081 if ( fixed_bevel || ft_pos_abs( theta ) > 57 )
1086 if ( bevel ) /* this is a bevel (broken angle) */
1090 /* the outer corners are simply joined together */
1095 FT_Vector_From_Polar( &delta,
1097 stroker->angle_out + rotate );
1098 delta.x += stroker->center.x;
1099 delta.y += stroker->center.y;
1101 border->movable = FALSE;
1102 error = ft_stroke_border_lineto( border, &delta, FALSE );
1104 else /* variable bevel or clipped miter */
1106 /* the miter is truncated */
1107 FT_Vector middle, delta;
1111 /* compute middle point and first angle point */
1112 FT_Vector_From_Polar( &middle,
1113 FT_MulFix( radius, stroker->miter_limit ),
1116 coef = FT_DivFix( 0x10000L - sigma.x, sigma.y );
1117 delta.x = FT_MulFix( middle.y, coef );
1118 delta.y = FT_MulFix( -middle.x, coef );
1120 middle.x += stroker->center.x;
1121 middle.y += stroker->center.y;
1122 delta.x += middle.x;
1123 delta.y += middle.y;
1125 error = ft_stroke_border_lineto( border, &delta, FALSE );
1129 /* compute second angle point */
1130 delta.x = middle.x - delta.x + middle.x;
1131 delta.y = middle.y - delta.y + middle.y;
1133 error = ft_stroke_border_lineto( border, &delta, FALSE );
1137 /* finally, add an end point; only needed if not lineto */
1138 /* (line_length is zero for curves) */
1139 if ( line_length == 0 )
1141 FT_Vector_From_Polar( &delta,
1143 stroker->angle_out + rotate );
1145 delta.x += stroker->center.x;
1146 delta.y += stroker->center.y;
1148 error = ft_stroke_border_lineto( border, &delta, FALSE );
1152 else /* this is a miter (intersection) */
1158 length = FT_MulDiv( stroker->radius, stroker->miter_limit, sigma.x );
1160 FT_Vector_From_Polar( &delta, length, phi );
1161 delta.x += stroker->center.x;
1162 delta.y += stroker->center.y;
1164 error = ft_stroke_border_lineto( border, &delta, FALSE );
1168 /* now add an end point; only needed if not lineto */
1169 /* (line_length is zero for curves) */
1170 if ( line_length == 0 )
1172 FT_Vector_From_Polar( &delta,
1174 stroker->angle_out + rotate );
1175 delta.x += stroker->center.x;
1176 delta.y += stroker->center.y;
1178 error = ft_stroke_border_lineto( border, &delta, FALSE );
1189 ft_stroker_process_corner( FT_Stroker stroker,
1190 FT_Fixed line_length )
1192 FT_Error error = FT_Err_Ok;
1197 turn = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
1199 /* no specific corner processing is required if the turn is 0 */
1203 /* when we turn to the right, the inside side is 0 */
1204 /* otherwise, the inside side is 1 */
1205 inside_side = ( turn < 0 );
1207 /* process the inside side */
1208 error = ft_stroker_inside( stroker, inside_side, line_length );
1212 /* process the outside side */
1213 error = ft_stroker_outside( stroker, !inside_side, line_length );
1220 /* add two points to the left and right borders corresponding to the */
1221 /* start of the subpath */
1223 ft_stroker_subpath_start( FT_Stroker stroker,
1224 FT_Angle start_angle,
1225 FT_Fixed line_length )
1230 FT_StrokeBorder border;
1233 FT_Vector_From_Polar( &delta, stroker->radius,
1234 start_angle + FT_ANGLE_PI2 );
1236 point.x = stroker->center.x + delta.x;
1237 point.y = stroker->center.y + delta.y;
1239 border = stroker->borders;
1240 error = ft_stroke_border_moveto( border, &point );
1244 point.x = stroker->center.x - delta.x;
1245 point.y = stroker->center.y - delta.y;
1248 error = ft_stroke_border_moveto( border, &point );
1250 /* save angle, position, and line length for last join */
1251 /* (line_length is zero for curves) */
1252 stroker->subpath_angle = start_angle;
1253 stroker->first_point = FALSE;
1254 stroker->subpath_line_length = line_length;
1261 /* documentation is in ftstroke.h */
1263 FT_EXPORT_DEF( FT_Error )
1264 FT_Stroker_LineTo( FT_Stroker stroker,
1267 FT_Error error = FT_Err_Ok;
1268 FT_StrokeBorder border;
1272 FT_Fixed line_length;
1275 if ( !stroker || !to )
1276 return FT_THROW( Invalid_Argument );
1278 delta.x = to->x - stroker->center.x;
1279 delta.y = to->y - stroker->center.y;
1281 /* a zero-length lineto is a no-op; avoid creating a spurious corner */
1282 if ( delta.x == 0 && delta.y == 0 )
1285 /* compute length of line */
1286 line_length = FT_Vector_Length( &delta );
1288 angle = FT_Atan2( delta.x, delta.y );
1289 FT_Vector_From_Polar( &delta, stroker->radius, angle + FT_ANGLE_PI2 );
1291 /* process corner if necessary */
1292 if ( stroker->first_point )
1294 /* This is the first segment of a subpath. We need to */
1295 /* add a point to each border at their respective starting */
1296 /* point locations. */
1297 error = ft_stroker_subpath_start( stroker, angle, line_length );
1303 /* process the current corner */
1304 stroker->angle_out = angle;
1305 error = ft_stroker_process_corner( stroker, line_length );
1310 /* now add a line segment to both the `inside' and `outside' paths */
1311 for ( border = stroker->borders, side = 1; side >= 0; side--, border++ )
1316 point.x = to->x + delta.x;
1317 point.y = to->y + delta.y;
1319 /* the ends of lineto borders are movable */
1320 error = ft_stroke_border_lineto( border, &point, TRUE );
1328 stroker->angle_in = angle;
1329 stroker->center = *to;
1330 stroker->line_length = line_length;
1337 /* documentation is in ftstroke.h */
1339 FT_EXPORT_DEF( FT_Error )
1340 FT_Stroker_ConicTo( FT_Stroker stroker,
1344 FT_Error error = FT_Err_Ok;
1345 FT_Vector bez_stack[34];
1347 FT_Vector* limit = bez_stack + 30;
1348 FT_Bool first_arc = TRUE;
1351 if ( !stroker || !control || !to )
1353 error = FT_THROW( Invalid_Argument );
1357 /* if all control points are coincident, this is a no-op; */
1358 /* avoid creating a spurious corner */
1359 if ( FT_IS_SMALL( stroker->center.x - control->x ) &&
1360 FT_IS_SMALL( stroker->center.y - control->y ) &&
1361 FT_IS_SMALL( control->x - to->x ) &&
1362 FT_IS_SMALL( control->y - to->y ) )
1364 stroker->center = *to;
1371 arc[2] = stroker->center;
1373 while ( arc >= bez_stack )
1375 FT_Angle angle_in, angle_out;
1378 /* initialize with current direction */
1379 angle_in = angle_out = stroker->angle_in;
1382 !ft_conic_is_small_enough( arc, &angle_in, &angle_out ) )
1384 if ( stroker->first_point )
1385 stroker->angle_in = angle_in;
1387 ft_conic_split( arc );
1396 /* process corner if necessary */
1397 if ( stroker->first_point )
1398 error = ft_stroker_subpath_start( stroker, angle_in, 0 );
1401 stroker->angle_out = angle_in;
1402 error = ft_stroker_process_corner( stroker, 0 );
1405 else if ( ft_pos_abs( FT_Angle_Diff( stroker->angle_in, angle_in ) ) >
1406 FT_SMALL_CONIC_THRESHOLD / 4 )
1408 /* if the deviation from one arc to the next is too great, */
1409 /* add a round corner */
1410 stroker->center = arc[2];
1411 stroker->angle_out = angle_in;
1412 stroker->line_join = FT_STROKER_LINEJOIN_ROUND;
1414 error = ft_stroker_process_corner( stroker, 0 );
1416 /* reinstate line join style */
1417 stroker->line_join = stroker->line_join_saved;
1423 /* the arc's angle is small enough; we can add it directly to each */
1426 FT_Vector ctrl, end;
1427 FT_Angle theta, phi, rotate, alpha0 = 0;
1429 FT_StrokeBorder border;
1433 theta = FT_Angle_Diff( angle_in, angle_out ) / 2;
1434 phi = angle_in + theta;
1435 length = FT_DivFix( stroker->radius, FT_Cos( theta ) );
1437 /* compute direction of original arc */
1438 if ( stroker->handle_wide_strokes )
1439 alpha0 = FT_Atan2( arc[0].x - arc[2].x, arc[0].y - arc[2].y );
1441 for ( border = stroker->borders, side = 0;
1445 rotate = FT_SIDE_TO_ROTATE( side );
1447 /* compute control point */
1448 FT_Vector_From_Polar( &ctrl, length, phi + rotate );
1452 /* compute end point */
1453 FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
1457 if ( stroker->handle_wide_strokes )
1463 /* determine whether the border radius is greater than the */
1464 /* radius of curvature of the original arc */
1465 start = border->points[border->num_points - 1];
1467 alpha1 = FT_Atan2( end.x - start.x, end.y - start.y );
1469 /* is the direction of the border arc opposite to */
1470 /* that of the original arc? */
1471 if ( ft_pos_abs( FT_Angle_Diff( alpha0, alpha1 ) ) >
1474 FT_Angle beta, gamma;
1475 FT_Vector bvec, delta;
1476 FT_Fixed blen, sinA, sinB, alen;
1479 /* use the sine rule to find the intersection point */
1480 beta = FT_Atan2( arc[2].x - start.x, arc[2].y - start.y );
1481 gamma = FT_Atan2( arc[0].x - end.x, arc[0].y - end.y );
1483 bvec.x = end.x - start.x;
1484 bvec.y = end.y - start.y;
1486 blen = FT_Vector_Length( &bvec );
1488 sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) );
1489 sinB = ft_pos_abs( FT_Sin( beta - gamma ) );
1491 alen = FT_MulDiv( blen, sinA, sinB );
1493 FT_Vector_From_Polar( &delta, alen, beta );
1497 /* circumnavigate the negative sector backwards */
1498 border->movable = FALSE;
1499 error = ft_stroke_border_lineto( border, &delta, FALSE );
1502 error = ft_stroke_border_lineto( border, &end, FALSE );
1505 error = ft_stroke_border_conicto( border, &ctrl, &start );
1508 /* and then move to the endpoint */
1509 error = ft_stroke_border_lineto( border, &end, FALSE );
1516 /* else fall through */
1519 /* simply add an arc */
1520 error = ft_stroke_border_conicto( border, &ctrl, &end );
1528 stroker->angle_in = angle_out;
1531 stroker->center = *to;
1538 /* documentation is in ftstroke.h */
1540 FT_EXPORT_DEF( FT_Error )
1541 FT_Stroker_CubicTo( FT_Stroker stroker,
1542 FT_Vector* control1,
1543 FT_Vector* control2,
1546 FT_Error error = FT_Err_Ok;
1547 FT_Vector bez_stack[37];
1549 FT_Vector* limit = bez_stack + 32;
1550 FT_Bool first_arc = TRUE;
1553 if ( !stroker || !control1 || !control2 || !to )
1555 error = FT_THROW( Invalid_Argument );
1559 /* if all control points are coincident, this is a no-op; */
1560 /* avoid creating a spurious corner */
1561 if ( FT_IS_SMALL( stroker->center.x - control1->x ) &&
1562 FT_IS_SMALL( stroker->center.y - control1->y ) &&
1563 FT_IS_SMALL( control1->x - control2->x ) &&
1564 FT_IS_SMALL( control1->y - control2->y ) &&
1565 FT_IS_SMALL( control2->x - to->x ) &&
1566 FT_IS_SMALL( control2->y - to->y ) )
1568 stroker->center = *to;
1576 arc[3] = stroker->center;
1578 while ( arc >= bez_stack )
1580 FT_Angle angle_in, angle_mid, angle_out;
1583 /* initialize with current direction */
1584 angle_in = angle_out = angle_mid = stroker->angle_in;
1587 !ft_cubic_is_small_enough( arc, &angle_in,
1588 &angle_mid, &angle_out ) )
1590 if ( stroker->first_point )
1591 stroker->angle_in = angle_in;
1593 ft_cubic_split( arc );
1602 /* process corner if necessary */
1603 if ( stroker->first_point )
1604 error = ft_stroker_subpath_start( stroker, angle_in, 0 );
1607 stroker->angle_out = angle_in;
1608 error = ft_stroker_process_corner( stroker, 0 );
1611 else if ( ft_pos_abs( FT_Angle_Diff( stroker->angle_in, angle_in ) ) >
1612 FT_SMALL_CUBIC_THRESHOLD / 4 )
1614 /* if the deviation from one arc to the next is too great, */
1615 /* add a round corner */
1616 stroker->center = arc[3];
1617 stroker->angle_out = angle_in;
1618 stroker->line_join = FT_STROKER_LINEJOIN_ROUND;
1620 error = ft_stroker_process_corner( stroker, 0 );
1622 /* reinstate line join style */
1623 stroker->line_join = stroker->line_join_saved;
1629 /* the arc's angle is small enough; we can add it directly to each */
1632 FT_Vector ctrl1, ctrl2, end;
1633 FT_Angle theta1, phi1, theta2, phi2, rotate, alpha0 = 0;
1634 FT_Fixed length1, length2;
1635 FT_StrokeBorder border;
1639 theta1 = FT_Angle_Diff( angle_in, angle_mid ) / 2;
1640 theta2 = FT_Angle_Diff( angle_mid, angle_out ) / 2;
1641 phi1 = ft_angle_mean( angle_in, angle_mid );
1642 phi2 = ft_angle_mean( angle_mid, angle_out );
1643 length1 = FT_DivFix( stroker->radius, FT_Cos( theta1 ) );
1644 length2 = FT_DivFix( stroker->radius, FT_Cos( theta2 ) );
1646 /* compute direction of original arc */
1647 if ( stroker->handle_wide_strokes )
1648 alpha0 = FT_Atan2( arc[0].x - arc[3].x, arc[0].y - arc[3].y );
1650 for ( border = stroker->borders, side = 0;
1654 rotate = FT_SIDE_TO_ROTATE( side );
1656 /* compute control points */
1657 FT_Vector_From_Polar( &ctrl1, length1, phi1 + rotate );
1658 ctrl1.x += arc[2].x;
1659 ctrl1.y += arc[2].y;
1661 FT_Vector_From_Polar( &ctrl2, length2, phi2 + rotate );
1662 ctrl2.x += arc[1].x;
1663 ctrl2.y += arc[1].y;
1665 /* compute end point */
1666 FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
1670 if ( stroker->handle_wide_strokes )
1676 /* determine whether the border radius is greater than the */
1677 /* radius of curvature of the original arc */
1678 start = border->points[border->num_points - 1];
1680 alpha1 = FT_Atan2( end.x - start.x, end.y - start.y );
1682 /* is the direction of the border arc opposite to */
1683 /* that of the original arc? */
1684 if ( ft_pos_abs( FT_Angle_Diff( alpha0, alpha1 ) ) >
1687 FT_Angle beta, gamma;
1688 FT_Vector bvec, delta;
1689 FT_Fixed blen, sinA, sinB, alen;
1692 /* use the sine rule to find the intersection point */
1693 beta = FT_Atan2( arc[3].x - start.x, arc[3].y - start.y );
1694 gamma = FT_Atan2( arc[0].x - end.x, arc[0].y - end.y );
1696 bvec.x = end.x - start.x;
1697 bvec.y = end.y - start.y;
1699 blen = FT_Vector_Length( &bvec );
1701 sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) );
1702 sinB = ft_pos_abs( FT_Sin( beta - gamma ) );
1704 alen = FT_MulDiv( blen, sinA, sinB );
1706 FT_Vector_From_Polar( &delta, alen, beta );
1710 /* circumnavigate the negative sector backwards */
1711 border->movable = FALSE;
1712 error = ft_stroke_border_lineto( border, &delta, FALSE );
1715 error = ft_stroke_border_lineto( border, &end, FALSE );
1718 error = ft_stroke_border_cubicto( border,
1724 /* and then move to the endpoint */
1725 error = ft_stroke_border_lineto( border, &end, FALSE );
1732 /* else fall through */
1735 /* simply add an arc */
1736 error = ft_stroke_border_cubicto( border, &ctrl1, &ctrl2, &end );
1744 stroker->angle_in = angle_out;
1747 stroker->center = *to;
1754 /* documentation is in ftstroke.h */
1756 FT_EXPORT_DEF( FT_Error )
1757 FT_Stroker_BeginSubPath( FT_Stroker stroker,
1761 if ( !stroker || !to )
1762 return FT_THROW( Invalid_Argument );
1764 /* We cannot process the first point, because there is not enough */
1765 /* information regarding its corner/cap. The latter will be processed */
1766 /* in the `FT_Stroker_EndSubPath' routine. */
1768 stroker->first_point = TRUE;
1769 stroker->center = *to;
1770 stroker->subpath_open = open;
1772 /* Determine if we need to check whether the border radius is greater */
1773 /* than the radius of curvature of a curve, to handle this case */
1774 /* specially. This is only required if bevel joins or butt caps may */
1775 /* be created, because round & miter joins and round & square caps */
1776 /* cover the negative sector created with wide strokes. */
1777 stroker->handle_wide_strokes =
1778 FT_BOOL( stroker->line_join != FT_STROKER_LINEJOIN_ROUND ||
1779 ( stroker->subpath_open &&
1780 stroker->line_cap == FT_STROKER_LINECAP_BUTT ) );
1782 /* record the subpath start point for each border */
1783 stroker->subpath_start = *to;
1785 stroker->angle_in = 0;
1792 ft_stroker_add_reverse_left( FT_Stroker stroker,
1795 FT_StrokeBorder right = stroker->borders + 0;
1796 FT_StrokeBorder left = stroker->borders + 1;
1798 FT_Error error = FT_Err_Ok;
1801 FT_ASSERT( left->start >= 0 );
1803 new_points = (FT_Int)left->num_points - left->start;
1804 if ( new_points > 0 )
1806 error = ft_stroke_border_grow( right, (FT_UInt)new_points );
1811 FT_Vector* dst_point = right->points + right->num_points;
1812 FT_Byte* dst_tag = right->tags + right->num_points;
1813 FT_Vector* src_point = left->points + left->num_points - 1;
1814 FT_Byte* src_tag = left->tags + left->num_points - 1;
1817 while ( src_point >= left->points + left->start )
1819 *dst_point = *src_point;
1820 *dst_tag = *src_tag;
1823 dst_tag[0] &= ~FT_STROKE_TAG_BEGIN_END;
1827 (FT_Byte)( dst_tag[0] & FT_STROKE_TAG_BEGIN_END );
1830 /* switch begin/end tags if necessary */
1831 if ( ttag == FT_STROKE_TAG_BEGIN ||
1832 ttag == FT_STROKE_TAG_END )
1833 dst_tag[0] ^= FT_STROKE_TAG_BEGIN_END;
1843 left->num_points = (FT_UInt)left->start;
1844 right->num_points += (FT_UInt)new_points;
1846 right->movable = FALSE;
1847 left->movable = FALSE;
1855 /* documentation is in ftstroke.h */
1857 /* there's a lot of magic in this function! */
1858 FT_EXPORT_DEF( FT_Error )
1859 FT_Stroker_EndSubPath( FT_Stroker stroker )
1861 FT_Error error = FT_Err_Ok;
1866 error = FT_THROW( Invalid_Argument );
1870 if ( stroker->subpath_open )
1872 FT_StrokeBorder right = stroker->borders;
1875 /* All right, this is an opened path, we need to add a cap between */
1876 /* right & left, add the reverse of left, then add a final cap */
1877 /* between left & right. */
1878 error = ft_stroker_cap( stroker, stroker->angle_in, 0 );
1882 /* add reversed points from `left' to `right' */
1883 error = ft_stroker_add_reverse_left( stroker, TRUE );
1887 /* now add the final cap */
1888 stroker->center = stroker->subpath_start;
1889 error = ft_stroker_cap( stroker,
1890 stroker->subpath_angle + FT_ANGLE_PI, 0 );
1894 /* Now end the right subpath accordingly. The left one is */
1895 /* rewind and doesn't need further processing. */
1896 ft_stroke_border_close( right, FALSE );
1904 /* close the path if needed */
1905 if ( stroker->center.x != stroker->subpath_start.x ||
1906 stroker->center.y != stroker->subpath_start.y )
1908 error = FT_Stroker_LineTo( stroker, &stroker->subpath_start );
1913 /* process the corner */
1914 stroker->angle_out = stroker->subpath_angle;
1915 turn = FT_Angle_Diff( stroker->angle_in,
1916 stroker->angle_out );
1918 /* no specific corner processing is required if the turn is 0 */
1921 /* when we turn to the right, the inside side is 0 */
1922 /* otherwise, the inside side is 1 */
1923 inside_side = ( turn < 0 );
1925 error = ft_stroker_inside( stroker,
1927 stroker->subpath_line_length );
1931 /* process the outside side */
1932 error = ft_stroker_outside( stroker,
1934 stroker->subpath_line_length );
1939 /* then end our two subpaths */
1940 ft_stroke_border_close( stroker->borders + 0, FALSE );
1941 ft_stroke_border_close( stroker->borders + 1, TRUE );
1949 /* documentation is in ftstroke.h */
1951 FT_EXPORT_DEF( FT_Error )
1952 FT_Stroker_GetBorderCounts( FT_Stroker stroker,
1953 FT_StrokerBorder border,
1954 FT_UInt *anum_points,
1955 FT_UInt *anum_contours )
1957 FT_UInt num_points = 0, num_contours = 0;
1961 if ( !stroker || border > 1 )
1963 error = FT_THROW( Invalid_Argument );
1967 error = ft_stroke_border_get_counts( stroker->borders + border,
1968 &num_points, &num_contours );
1971 *anum_points = num_points;
1973 if ( anum_contours )
1974 *anum_contours = num_contours;
1980 /* documentation is in ftstroke.h */
1982 FT_EXPORT_DEF( FT_Error )
1983 FT_Stroker_GetCounts( FT_Stroker stroker,
1984 FT_UInt *anum_points,
1985 FT_UInt *anum_contours )
1987 FT_UInt count1, count2, num_points = 0;
1988 FT_UInt count3, count4, num_contours = 0;
1994 error = FT_THROW( Invalid_Argument );
1998 error = ft_stroke_border_get_counts( stroker->borders + 0,
2003 error = ft_stroke_border_get_counts( stroker->borders + 1,
2008 num_points = count1 + count3;
2009 num_contours = count2 + count4;
2013 *anum_points = num_points;
2015 if ( anum_contours )
2016 *anum_contours = num_contours;
2022 /* documentation is in ftstroke.h */
2024 FT_EXPORT_DEF( void )
2025 FT_Stroker_ExportBorder( FT_Stroker stroker,
2026 FT_StrokerBorder border,
2027 FT_Outline* outline )
2029 if ( !stroker || !outline )
2032 if ( border == FT_STROKER_BORDER_LEFT ||
2033 border == FT_STROKER_BORDER_RIGHT )
2035 FT_StrokeBorder sborder = & stroker->borders[border];
2038 if ( sborder->valid )
2039 ft_stroke_border_export( sborder, outline );
2044 /* documentation is in ftstroke.h */
2046 FT_EXPORT_DEF( void )
2047 FT_Stroker_Export( FT_Stroker stroker,
2048 FT_Outline* outline )
2050 FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_LEFT, outline );
2051 FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_RIGHT, outline );
2055 /* documentation is in ftstroke.h */
2058 * The following is very similar to FT_Outline_Decompose, except
2059 * that we do support opened paths, and do not scale the outline.
2061 FT_EXPORT_DEF( FT_Error )
2062 FT_Stroker_ParseOutline( FT_Stroker stroker,
2063 FT_Outline* outline,
2067 FT_Vector v_control;
2076 FT_Int n; /* index of contour in outline */
2077 FT_UInt first; /* index of first point in contour */
2078 FT_Int tag; /* current point's state */
2082 return FT_THROW( Invalid_Outline );
2085 return FT_THROW( Invalid_Argument );
2087 FT_Stroker_Rewind( stroker );
2091 for ( n = 0; n < outline->n_contours; n++ )
2093 FT_UInt last; /* index of last point in contour */
2096 last = (FT_UInt)outline->contours[n];
2097 limit = outline->points + last;
2099 /* skip empty points; we don't stroke these */
2100 if ( last <= first )
2106 v_start = outline->points[first];
2107 v_last = outline->points[last];
2109 v_control = v_start;
2111 point = outline->points + first;
2112 tags = outline->tags + first;
2113 tag = FT_CURVE_TAG( tags[0] );
2115 /* A contour cannot start with a cubic control point! */
2116 if ( tag == FT_CURVE_TAG_CUBIC )
2117 goto Invalid_Outline;
2119 /* check first point to determine origin */
2120 if ( tag == FT_CURVE_TAG_CONIC )
2122 /* First point is conic control. Yes, this happens. */
2123 if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON )
2125 /* start at last point if it is on the curve */
2131 /* if both first and last points are conic, */
2132 /* start at their middle */
2133 v_start.x = ( v_start.x + v_last.x ) / 2;
2134 v_start.y = ( v_start.y + v_last.y ) / 2;
2140 error = FT_Stroker_BeginSubPath( stroker, &v_start, opened );
2144 while ( point < limit )
2149 tag = FT_CURVE_TAG( tags[0] );
2152 case FT_CURVE_TAG_ON: /* emit a single line_to */
2160 error = FT_Stroker_LineTo( stroker, &vec );
2166 case FT_CURVE_TAG_CONIC: /* consume conic arcs */
2167 v_control.x = point->x;
2168 v_control.y = point->y;
2171 if ( point < limit )
2179 tag = FT_CURVE_TAG( tags[0] );
2183 if ( tag == FT_CURVE_TAG_ON )
2185 error = FT_Stroker_ConicTo( stroker, &v_control, &vec );
2191 if ( tag != FT_CURVE_TAG_CONIC )
2192 goto Invalid_Outline;
2194 v_middle.x = ( v_control.x + vec.x ) / 2;
2195 v_middle.y = ( v_control.y + vec.y ) / 2;
2197 error = FT_Stroker_ConicTo( stroker, &v_control, &v_middle );
2205 error = FT_Stroker_ConicTo( stroker, &v_control, &v_start );
2208 default: /* FT_CURVE_TAG_CUBIC */
2210 FT_Vector vec1, vec2;
2213 if ( point + 1 > limit ||
2214 FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC )
2215 goto Invalid_Outline;
2223 if ( point <= limit )
2230 error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &vec );
2236 error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &v_start );
2246 /* don't try to end the path if no segments have been generated */
2247 if ( !stroker->first_point )
2249 error = FT_Stroker_EndSubPath( stroker );
2263 return FT_THROW( Invalid_Outline );
2267 /* documentation is in ftstroke.h */
2269 FT_EXPORT_DEF( FT_Error )
2270 FT_Glyph_Stroke( FT_Glyph *pglyph,
2274 FT_Error error = FT_ERR( Invalid_Argument );
2275 FT_Glyph glyph = NULL;
2282 if ( !glyph || glyph->clazz != &ft_outline_glyph_class )
2289 error = FT_Glyph_Copy( glyph, © );
2297 FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
2298 FT_Outline* outline = &oglyph->outline;
2299 FT_UInt num_points, num_contours;
2302 error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
2306 FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
2308 FT_Outline_Done( glyph->library, outline );
2310 error = FT_Outline_New( glyph->library,
2312 (FT_Int)num_contours,
2317 outline->n_points = 0;
2318 outline->n_contours = 0;
2320 FT_Stroker_Export( stroker, outline );
2324 FT_Done_Glyph( *pglyph );
2330 FT_Done_Glyph( glyph );
2341 /* documentation is in ftstroke.h */
2343 FT_EXPORT_DEF( FT_Error )
2344 FT_Glyph_StrokeBorder( FT_Glyph *pglyph,
2349 FT_Error error = FT_ERR( Invalid_Argument );
2350 FT_Glyph glyph = NULL;
2357 if ( !glyph || glyph->clazz != &ft_outline_glyph_class )
2364 error = FT_Glyph_Copy( glyph, © );
2372 FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
2373 FT_StrokerBorder border;
2374 FT_Outline* outline = &oglyph->outline;
2375 FT_UInt num_points, num_contours;
2378 border = FT_Outline_GetOutsideBorder( outline );
2381 if ( border == FT_STROKER_BORDER_LEFT )
2382 border = FT_STROKER_BORDER_RIGHT;
2384 border = FT_STROKER_BORDER_LEFT;
2387 error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
2391 FT_Stroker_GetBorderCounts( stroker, border,
2392 &num_points, &num_contours );
2394 FT_Outline_Done( glyph->library, outline );
2396 error = FT_Outline_New( glyph->library,
2398 (FT_Int)num_contours,
2403 outline->n_points = 0;
2404 outline->n_contours = 0;
2406 FT_Stroker_ExportBorder( stroker, border, outline );
2410 FT_Done_Glyph( *pglyph );
2416 FT_Done_Glyph( glyph );