1 /***************************************************************************/
5 /* FreeType path stroker (body). */
7 /* Copyright 2002-2006, 2008-2011 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 /***************************************************************************/
21 #include FT_TRIGONOMETRY_H
23 #include FT_INTERNAL_MEMORY_H
24 #include FT_INTERNAL_DEBUG_H
25 #include FT_INTERNAL_OBJECTS_H
28 /* documentation is in ftstroke.h */
30 FT_EXPORT_DEF( FT_StrokerBorder )
31 FT_Outline_GetInsideBorder( FT_Outline* outline )
33 FT_Orientation o = FT_Outline_Get_Orientation( outline );
36 return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_RIGHT
37 : FT_STROKER_BORDER_LEFT;
41 /* documentation is in ftstroke.h */
43 FT_EXPORT_DEF( FT_StrokerBorder )
44 FT_Outline_GetOutsideBorder( FT_Outline* outline )
46 FT_Orientation o = FT_Outline_Get_Orientation( outline );
49 return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_LEFT
50 : FT_STROKER_BORDER_RIGHT;
54 /*************************************************************************/
55 /*************************************************************************/
57 /***** BEZIER COMPUTATIONS *****/
59 /*************************************************************************/
60 /*************************************************************************/
62 #define FT_SMALL_CONIC_THRESHOLD ( FT_ANGLE_PI / 6 )
63 #define FT_SMALL_CUBIC_THRESHOLD ( FT_ANGLE_PI / 8 )
67 #define FT_IS_SMALL( x ) ( (x) > -FT_EPSILON && (x) < FT_EPSILON )
71 ft_pos_abs( FT_Pos x )
73 return x >= 0 ? x : -x;
78 ft_conic_split( FT_Vector* base )
83 base[4].x = base[2].x;
85 a = base[3].x = ( base[2].x + b ) / 2;
86 b = base[1].x = ( base[0].x + b ) / 2;
87 base[2].x = ( a + b ) / 2;
89 base[4].y = base[2].y;
91 a = base[3].y = ( base[2].y + b ) / 2;
92 b = base[1].y = ( base[0].y + b ) / 2;
93 base[2].y = ( a + b ) / 2;
98 ft_conic_is_small_enough( FT_Vector* base,
100 FT_Angle *angle_out )
104 FT_Int close1, close2;
107 d1.x = base[1].x - base[2].x;
108 d1.y = base[1].y - base[2].y;
109 d2.x = base[0].x - base[1].x;
110 d2.y = base[0].y - base[1].y;
112 close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
113 close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
119 /* basically a point; */
120 /* do nothing to retain original direction */
125 *angle_out = FT_Atan2( d2.x, d2.y );
133 *angle_out = FT_Atan2( d1.x, d1.y );
137 *angle_in = FT_Atan2( d1.x, d1.y );
138 *angle_out = FT_Atan2( d2.x, d2.y );
142 theta = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_out ) );
144 return FT_BOOL( theta < FT_SMALL_CONIC_THRESHOLD );
149 ft_cubic_split( FT_Vector* base )
154 base[6].x = base[3].x;
157 base[1].x = a = ( base[0].x + c ) / 2;
158 base[5].x = b = ( base[3].x + d ) / 2;
160 base[2].x = a = ( a + c ) / 2;
161 base[4].x = b = ( b + c ) / 2;
162 base[3].x = ( a + b ) / 2;
164 base[6].y = base[3].y;
167 base[1].y = a = ( base[0].y + c ) / 2;
168 base[5].y = b = ( base[3].y + d ) / 2;
170 base[2].y = a = ( a + c ) / 2;
171 base[4].y = b = ( b + c ) / 2;
172 base[3].y = ( a + b ) / 2;
176 /* Return the average of `angle1' and `angle2'. */
177 /* This gives correct result even if `angle1' and `angle2' */
178 /* have opposite signs. */
180 ft_angle_mean( FT_Angle angle1,
183 return angle1 + FT_Angle_Diff( angle1, angle2 ) / 2;
188 ft_cubic_is_small_enough( FT_Vector* base,
191 FT_Angle *angle_out )
193 FT_Vector d1, d2, d3;
194 FT_Angle theta1, theta2;
195 FT_Int close1, close2, close3;
198 d1.x = base[2].x - base[3].x;
199 d1.y = base[2].y - base[3].y;
200 d2.x = base[1].x - base[2].x;
201 d2.y = base[1].y - base[2].y;
202 d3.x = base[0].x - base[1].x;
203 d3.y = base[0].y - base[1].y;
205 close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
206 close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
207 close3 = FT_IS_SMALL( d3.x ) && FT_IS_SMALL( d3.y );
215 /* basically a point; */
216 /* do nothing to retain original direction */
222 *angle_out = FT_Atan2( d3.x, d3.y );
231 *angle_out = FT_Atan2( d2.x, d2.y );
236 *angle_mid = FT_Atan2( d2.x, d2.y );
237 *angle_out = FT_Atan2( d3.x, d3.y );
249 *angle_out = FT_Atan2( d1.x, d1.y );
253 *angle_in = FT_Atan2( d1.x, d1.y );
254 *angle_out = FT_Atan2( d3.x, d3.y );
255 *angle_mid = ft_angle_mean( *angle_in, *angle_out );
262 *angle_in = FT_Atan2( d1.x, d1.y );
264 *angle_out = FT_Atan2( d2.x, d2.y );
268 *angle_in = FT_Atan2( d1.x, d1.y );
269 *angle_mid = FT_Atan2( d2.x, d2.y );
270 *angle_out = FT_Atan2( d3.x, d3.y );
275 theta1 = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_mid ) );
276 theta2 = ft_pos_abs( FT_Angle_Diff( *angle_mid, *angle_out ) );
278 return FT_BOOL( theta1 < FT_SMALL_CUBIC_THRESHOLD &&
279 theta2 < FT_SMALL_CUBIC_THRESHOLD );
283 /*************************************************************************/
284 /*************************************************************************/
286 /***** STROKE BORDERS *****/
288 /*************************************************************************/
289 /*************************************************************************/
291 typedef enum FT_StrokeTags_
293 FT_STROKE_TAG_ON = 1, /* on-curve point */
294 FT_STROKE_TAG_CUBIC = 2, /* cubic off-point */
295 FT_STROKE_TAG_BEGIN = 4, /* sub-path start */
296 FT_STROKE_TAG_END = 8 /* sub-path end */
300 #define FT_STROKE_TAG_BEGIN_END ( FT_STROKE_TAG_BEGIN | FT_STROKE_TAG_END )
302 typedef struct FT_StrokeBorderRec_
308 FT_Bool movable; /* TRUE for ends of lineto borders */
309 FT_Int start; /* index of current sub-path start point */
313 } FT_StrokeBorderRec, *FT_StrokeBorder;
317 ft_stroke_border_grow( FT_StrokeBorder border,
320 FT_UInt old_max = border->max_points;
321 FT_UInt new_max = border->num_points + new_points;
322 FT_Error error = FT_Err_Ok;
325 if ( new_max > old_max )
327 FT_UInt cur_max = old_max;
328 FT_Memory memory = border->memory;
331 while ( cur_max < new_max )
332 cur_max += ( cur_max >> 1 ) + 16;
334 if ( FT_RENEW_ARRAY( border->points, old_max, cur_max ) ||
335 FT_RENEW_ARRAY( border->tags, old_max, cur_max ) )
338 border->max_points = cur_max;
347 ft_stroke_border_close( FT_StrokeBorder border,
350 FT_UInt start = border->start;
351 FT_UInt count = border->num_points;
354 FT_ASSERT( border->start >= 0 );
356 /* don't record empty paths! */
357 if ( count <= start + 1U )
358 border->num_points = start;
361 /* copy the last point to the start of this sub-path, since */
362 /* it contains the `adjusted' starting coordinates */
363 border->num_points = --count;
364 border->points[start] = border->points[count];
368 /* reverse the points */
370 FT_Vector* vec1 = border->points + start + 1;
371 FT_Vector* vec2 = border->points + count - 1;
374 for ( ; vec1 < vec2; vec1++, vec2-- )
387 FT_Byte* tag1 = border->tags + start + 1;
388 FT_Byte* tag2 = border->tags + count - 1;
391 for ( ; tag1 < tag2; tag1++, tag2-- )
403 border->tags[start ] |= FT_STROKE_TAG_BEGIN;
404 border->tags[count - 1] |= FT_STROKE_TAG_END;
408 border->movable = FALSE;
413 ft_stroke_border_lineto( FT_StrokeBorder border,
417 FT_Error error = FT_Err_Ok;
420 FT_ASSERT( border->start >= 0 );
422 if ( border->movable )
424 /* move last point */
425 border->points[border->num_points - 1] = *to;
429 /* don't add zero-length lineto */
430 if ( border->num_points > 0 &&
431 FT_IS_SMALL( border->points[border->num_points - 1].x - to->x ) &&
432 FT_IS_SMALL( border->points[border->num_points - 1].y - to->y ) )
436 error = ft_stroke_border_grow( border, 1 );
439 FT_Vector* vec = border->points + border->num_points;
440 FT_Byte* tag = border->tags + border->num_points;
444 tag[0] = FT_STROKE_TAG_ON;
446 border->num_points += 1;
449 border->movable = movable;
455 ft_stroke_border_conicto( FT_StrokeBorder border,
462 FT_ASSERT( border->start >= 0 );
464 error = ft_stroke_border_grow( border, 2 );
467 FT_Vector* vec = border->points + border->num_points;
468 FT_Byte* tag = border->tags + border->num_points;
475 tag[1] = FT_STROKE_TAG_ON;
477 border->num_points += 2;
480 border->movable = FALSE;
487 ft_stroke_border_cubicto( FT_StrokeBorder border,
495 FT_ASSERT( border->start >= 0 );
497 error = ft_stroke_border_grow( border, 3 );
500 FT_Vector* vec = border->points + border->num_points;
501 FT_Byte* tag = border->tags + border->num_points;
508 tag[0] = FT_STROKE_TAG_CUBIC;
509 tag[1] = FT_STROKE_TAG_CUBIC;
510 tag[2] = FT_STROKE_TAG_ON;
512 border->num_points += 3;
515 border->movable = FALSE;
521 #define FT_ARC_CUBIC_ANGLE ( FT_ANGLE_PI / 2 )
525 ft_stroke_border_arcto( FT_StrokeBorder border,
528 FT_Angle angle_start,
529 FT_Angle angle_diff )
531 FT_Angle total, angle, step, rotate, next, theta;
532 FT_Vector a, b, a2, b2;
534 FT_Error error = FT_Err_Ok;
537 /* compute start point */
538 FT_Vector_From_Polar( &a, radius, angle_start );
544 rotate = ( angle_diff >= 0 ) ? FT_ANGLE_PI2 : -FT_ANGLE_PI2;
549 if ( step > FT_ARC_CUBIC_ANGLE )
550 step = FT_ARC_CUBIC_ANGLE;
552 else if ( step < -FT_ARC_CUBIC_ANGLE )
553 step = -FT_ARC_CUBIC_ANGLE;
562 /* compute end point */
563 FT_Vector_From_Polar( &b, radius, next );
567 /* compute first and second control points */
568 length = FT_MulDiv( radius, FT_Sin( theta ) * 4,
569 ( 0x10000L + FT_Cos( theta ) ) * 3 );
571 FT_Vector_From_Polar( &a2, length, angle + rotate );
575 FT_Vector_From_Polar( &b2, length, next - rotate );
580 error = ft_stroke_border_cubicto( border, &a2, &b2, &b );
584 /* process the rest of the arc ?? */
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 = 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 FT_ARRAY_COPY( outline->points + outline->n_points,
707 border->num_points );
711 FT_UInt count = border->num_points;
712 FT_Byte* read = border->tags;
713 FT_Byte* write = (FT_Byte*)outline->tags + outline->n_points;
716 for ( ; count > 0; count--, read++, write++ )
718 if ( *read & FT_STROKE_TAG_ON )
719 *write = FT_CURVE_TAG_ON;
720 else if ( *read & FT_STROKE_TAG_CUBIC )
721 *write = FT_CURVE_TAG_CUBIC;
723 *write = FT_CURVE_TAG_CONIC;
729 FT_UInt count = border->num_points;
730 FT_Byte* tags = border->tags;
731 FT_Short* write = outline->contours + outline->n_contours;
732 FT_Short idx = (FT_Short)outline->n_points;
735 for ( ; count > 0; count--, tags++, idx++ )
737 if ( *tags & FT_STROKE_TAG_END )
740 outline->n_contours++;
745 outline->n_points = (short)( outline->n_points + border->num_points );
747 FT_ASSERT( FT_Outline_Check( outline ) == 0 );
751 /*************************************************************************/
752 /*************************************************************************/
754 /***** STROKER *****/
756 /*************************************************************************/
757 /*************************************************************************/
759 #define FT_SIDE_TO_ROTATE( s ) ( FT_ANGLE_PI2 - (s) * FT_ANGLE_PI )
761 typedef struct FT_StrokerRec_
763 FT_Angle angle_in; /* direction into curr join */
764 FT_Angle angle_out; /* direction out of join */
765 FT_Vector center; /* current position */
766 FT_Fixed line_length; /* length of last lineto */
767 FT_Bool first_point; /* is this the start? */
768 FT_Bool subpath_open; /* is the subpath open? */
769 FT_Angle subpath_angle; /* subpath start direction */
770 FT_Vector subpath_start; /* subpath start position */
771 FT_Fixed subpath_line_length; /* subpath start lineto len */
772 FT_Bool handle_wide_strokes; /* use wide strokes logic? */
774 FT_Stroker_LineCap line_cap;
775 FT_Stroker_LineJoin line_join;
776 FT_Stroker_LineJoin line_join_saved;
777 FT_Fixed miter_limit;
780 FT_StrokeBorderRec borders[2];
786 /* documentation is in ftstroke.h */
788 FT_EXPORT_DEF( FT_Error )
789 FT_Stroker_New( FT_Library library,
790 FT_Stroker *astroker )
794 FT_Stroker stroker = NULL;
798 return FT_Err_Invalid_Argument;
800 memory = library->memory;
802 if ( !FT_NEW( stroker ) )
804 stroker->library = library;
806 ft_stroke_border_init( &stroker->borders[0], memory );
807 ft_stroke_border_init( &stroker->borders[1], memory );
816 /* documentation is in ftstroke.h */
818 FT_EXPORT_DEF( void )
819 FT_Stroker_Set( FT_Stroker stroker,
821 FT_Stroker_LineCap line_cap,
822 FT_Stroker_LineJoin line_join,
823 FT_Fixed miter_limit )
825 stroker->radius = radius;
826 stroker->line_cap = line_cap;
827 stroker->line_join = line_join;
828 stroker->miter_limit = miter_limit;
830 /* ensure miter limit has sensible value */
831 if ( stroker->miter_limit < 0x10000 )
832 stroker->miter_limit = 0x10000;
834 /* save line join style: */
835 /* line join style can be temporarily changed when stroking curves */
836 stroker->line_join_saved = line_join;
838 FT_Stroker_Rewind( stroker );
842 /* documentation is in ftstroke.h */
844 FT_EXPORT_DEF( void )
845 FT_Stroker_Rewind( FT_Stroker stroker )
849 ft_stroke_border_reset( &stroker->borders[0] );
850 ft_stroke_border_reset( &stroker->borders[1] );
855 /* documentation is in ftstroke.h */
857 FT_EXPORT_DEF( void )
858 FT_Stroker_Done( FT_Stroker stroker )
862 FT_Memory memory = stroker->library->memory;
865 ft_stroke_border_done( &stroker->borders[0] );
866 ft_stroke_border_done( &stroker->borders[1] );
868 stroker->library = NULL;
874 /* create a circular arc at a corner or cap */
876 ft_stroker_arcto( FT_Stroker stroker,
879 FT_Angle total, rotate;
880 FT_Fixed radius = stroker->radius;
881 FT_Error error = FT_Err_Ok;
882 FT_StrokeBorder border = stroker->borders + side;
885 rotate = FT_SIDE_TO_ROTATE( side );
887 total = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
888 if ( total == FT_ANGLE_PI )
891 error = ft_stroke_border_arcto( border,
894 stroker->angle_in + rotate,
896 border->movable = FALSE;
901 /* add a cap at the end of an opened path */
903 ft_stroker_cap( FT_Stroker stroker,
907 FT_Error error = FT_Err_Ok;
910 if ( stroker->line_cap == FT_STROKER_LINECAP_ROUND )
912 /* add a round cap */
913 stroker->angle_in = angle;
914 stroker->angle_out = angle + FT_ANGLE_PI;
916 error = ft_stroker_arcto( stroker, side );
918 else if ( stroker->line_cap == FT_STROKER_LINECAP_SQUARE )
920 /* add a square cap */
921 FT_Vector delta, delta2;
922 FT_Angle rotate = FT_SIDE_TO_ROTATE( side );
923 FT_Fixed radius = stroker->radius;
924 FT_StrokeBorder border = stroker->borders + side;
927 FT_Vector_From_Polar( &delta2, radius, angle + rotate );
928 FT_Vector_From_Polar( &delta, radius, angle );
930 delta.x += stroker->center.x + delta2.x;
931 delta.y += stroker->center.y + delta2.y;
933 error = ft_stroke_border_lineto( border, &delta, FALSE );
937 FT_Vector_From_Polar( &delta2, radius, angle - rotate );
938 FT_Vector_From_Polar( &delta, radius, angle );
940 delta.x += delta2.x + stroker->center.x;
941 delta.y += delta2.y + stroker->center.y;
943 error = ft_stroke_border_lineto( border, &delta, FALSE );
945 else if ( stroker->line_cap == FT_STROKER_LINECAP_BUTT )
947 /* add a butt ending */
949 FT_Angle rotate = FT_SIDE_TO_ROTATE( side );
950 FT_Fixed radius = stroker->radius;
951 FT_StrokeBorder border = stroker->borders + side;
954 FT_Vector_From_Polar( &delta, radius, angle + rotate );
956 delta.x += stroker->center.x;
957 delta.y += stroker->center.y;
959 error = ft_stroke_border_lineto( border, &delta, FALSE );
963 FT_Vector_From_Polar( &delta, radius, angle - rotate );
965 delta.x += stroker->center.x;
966 delta.y += stroker->center.y;
968 error = ft_stroke_border_lineto( border, &delta, FALSE );
976 /* process an inside corner, i.e. compute intersection */
978 ft_stroker_inside( FT_Stroker stroker,
980 FT_Fixed line_length )
982 FT_StrokeBorder border = stroker->borders + side;
983 FT_Angle phi, theta, rotate;
984 FT_Fixed length, thcos;
986 FT_Error error = FT_Err_Ok;
987 FT_Bool intersect; /* use intersection of lines? */
990 rotate = FT_SIDE_TO_ROTATE( side );
992 theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ) / 2;
994 /* Only intersect borders if between two lineto's and both */
995 /* lines are long enough (line_length is zero for curves). */
996 if ( !border->movable || line_length == 0 )
1000 /* compute minimum required length of lines */
1001 FT_Fixed min_length = ft_pos_abs( FT_MulFix( stroker->radius,
1002 FT_Tan( theta ) ) );
1005 intersect = FT_BOOL( stroker->line_length >= min_length &&
1006 line_length >= min_length );
1011 FT_Vector_From_Polar( &delta, stroker->radius,
1012 stroker->angle_out + rotate );
1013 delta.x += stroker->center.x;
1014 delta.y += stroker->center.y;
1016 border->movable = FALSE;
1020 /* compute median angle */
1021 phi = stroker->angle_in + theta;
1023 thcos = FT_Cos( theta );
1025 length = FT_DivFix( stroker->radius, thcos );
1027 FT_Vector_From_Polar( &delta, length, phi + rotate );
1028 delta.x += stroker->center.x;
1029 delta.y += stroker->center.y;
1032 error = ft_stroke_border_lineto( border, &delta, FALSE );
1038 /* process an outside corner, i.e. compute bevel/miter/round */
1040 ft_stroker_outside( FT_Stroker stroker,
1042 FT_Fixed line_length )
1044 FT_StrokeBorder border = stroker->borders + side;
1049 if ( stroker->line_join == FT_STROKER_LINEJOIN_ROUND )
1050 error = ft_stroker_arcto( stroker, side );
1053 /* this is a mitered (pointed) or beveled (truncated) corner */
1054 FT_Fixed sigma = 0, radius = stroker->radius;
1055 FT_Angle theta = 0, phi = 0;
1057 FT_Bool bevel, fixed_bevel;
1060 rotate = FT_SIDE_TO_ROTATE( side );
1063 FT_BOOL( stroker->line_join == FT_STROKER_LINEJOIN_BEVEL );
1066 FT_BOOL( stroker->line_join != FT_STROKER_LINEJOIN_MITER_VARIABLE );
1070 theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
1072 if ( theta == FT_ANGLE_PI )
1075 phi = stroker->angle_in;
1080 phi = stroker->angle_in + theta + rotate;
1083 thcos = FT_Cos( theta );
1084 sigma = FT_MulFix( stroker->miter_limit, thcos );
1086 /* is miter limit exceeded? */
1087 if ( sigma < 0x10000L )
1089 /* don't create variable bevels for very small deviations; */
1090 /* FT_Sin(x) = 0 for x <= 57 */
1091 if ( fixed_bevel || ft_pos_abs( theta ) > 57 )
1096 if ( bevel ) /* this is a bevel (broken angle) */
1100 /* the outer corners are simply joined together */
1105 FT_Vector_From_Polar( &delta,
1107 stroker->angle_out + rotate );
1108 delta.x += stroker->center.x;
1109 delta.y += stroker->center.y;
1111 border->movable = FALSE;
1112 error = ft_stroke_border_lineto( border, &delta, FALSE );
1114 else /* variable bevel */
1116 /* the miter is truncated */
1117 FT_Vector middle, delta;
1121 /* compute middle point */
1122 FT_Vector_From_Polar( &middle,
1123 FT_MulFix( radius, stroker->miter_limit ),
1125 middle.x += stroker->center.x;
1126 middle.y += stroker->center.y;
1128 /* compute first angle point */
1129 length = FT_MulFix( radius,
1130 FT_DivFix( 0x10000L - sigma,
1131 ft_pos_abs( FT_Sin( theta ) ) ) );
1133 FT_Vector_From_Polar( &delta, length, phi + rotate );
1134 delta.x += middle.x;
1135 delta.y += middle.y;
1137 error = ft_stroke_border_lineto( border, &delta, FALSE );
1141 /* compute second angle point */
1142 FT_Vector_From_Polar( &delta, length, phi - rotate );
1143 delta.x += middle.x;
1144 delta.y += middle.y;
1146 error = ft_stroke_border_lineto( border, &delta, FALSE );
1150 /* finally, add an end point; only needed if not lineto */
1151 /* (line_length is zero for curves) */
1152 if ( line_length == 0 )
1154 FT_Vector_From_Polar( &delta,
1156 stroker->angle_out + rotate );
1158 delta.x += stroker->center.x;
1159 delta.y += stroker->center.y;
1161 error = ft_stroke_border_lineto( border, &delta, FALSE );
1165 else /* this is a miter (intersection) */
1171 length = FT_DivFix( stroker->radius, thcos );
1173 FT_Vector_From_Polar( &delta, length, phi );
1174 delta.x += stroker->center.x;
1175 delta.y += stroker->center.y;
1177 error = ft_stroke_border_lineto( border, &delta, FALSE );
1181 /* now add an end point; only needed if not lineto */
1182 /* (line_length is zero for curves) */
1183 if ( line_length == 0 )
1185 FT_Vector_From_Polar( &delta,
1187 stroker->angle_out + rotate );
1188 delta.x += stroker->center.x;
1189 delta.y += stroker->center.y;
1191 error = ft_stroke_border_lineto( border, &delta, FALSE );
1202 ft_stroker_process_corner( FT_Stroker stroker,
1203 FT_Fixed line_length )
1205 FT_Error error = FT_Err_Ok;
1210 turn = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
1212 /* no specific corner processing is required if the turn is 0 */
1216 /* when we turn to the right, the inside side is 0 */
1219 /* otherwise, the inside side is 1 */
1223 /* process the inside side */
1224 error = ft_stroker_inside( stroker, inside_side, line_length );
1228 /* process the outside side */
1229 error = ft_stroker_outside( stroker, 1 - inside_side, line_length );
1236 /* add two points to the left and right borders corresponding to the */
1237 /* start of the subpath */
1239 ft_stroker_subpath_start( FT_Stroker stroker,
1240 FT_Angle start_angle,
1241 FT_Fixed line_length )
1246 FT_StrokeBorder border;
1249 FT_Vector_From_Polar( &delta, stroker->radius,
1250 start_angle + FT_ANGLE_PI2 );
1252 point.x = stroker->center.x + delta.x;
1253 point.y = stroker->center.y + delta.y;
1255 border = stroker->borders;
1256 error = ft_stroke_border_moveto( border, &point );
1260 point.x = stroker->center.x - delta.x;
1261 point.y = stroker->center.y - delta.y;
1264 error = ft_stroke_border_moveto( border, &point );
1266 /* save angle, position, and line length for last join */
1267 /* (line_length is zero for curves) */
1268 stroker->subpath_angle = start_angle;
1269 stroker->first_point = FALSE;
1270 stroker->subpath_line_length = line_length;
1277 /* documentation is in ftstroke.h */
1279 FT_EXPORT_DEF( FT_Error )
1280 FT_Stroker_LineTo( FT_Stroker stroker,
1283 FT_Error error = FT_Err_Ok;
1284 FT_StrokeBorder border;
1288 FT_Fixed line_length;
1291 delta.x = to->x - stroker->center.x;
1292 delta.y = to->y - stroker->center.y;
1294 /* a zero-length lineto is a no-op; avoid creating a spurious corner */
1295 if ( delta.x == 0 && delta.y == 0 )
1298 /* compute length of line */
1299 line_length = FT_Vector_Length( &delta );
1301 angle = FT_Atan2( delta.x, delta.y );
1302 FT_Vector_From_Polar( &delta, stroker->radius, angle + FT_ANGLE_PI2 );
1304 /* process corner if necessary */
1305 if ( stroker->first_point )
1307 /* This is the first segment of a subpath. We need to */
1308 /* add a point to each border at their respective starting */
1309 /* point locations. */
1310 error = ft_stroker_subpath_start( stroker, angle, line_length );
1316 /* process the current corner */
1317 stroker->angle_out = angle;
1318 error = ft_stroker_process_corner( stroker, line_length );
1323 /* now add a line segment to both the `inside' and `outside' paths */
1324 for ( border = stroker->borders, side = 1; side >= 0; side--, border++ )
1329 point.x = to->x + delta.x;
1330 point.y = to->y + delta.y;
1332 /* the ends of lineto borders are movable */
1333 error = ft_stroke_border_lineto( border, &point, TRUE );
1341 stroker->angle_in = angle;
1342 stroker->center = *to;
1343 stroker->line_length = line_length;
1350 /* documentation is in ftstroke.h */
1352 FT_EXPORT_DEF( FT_Error )
1353 FT_Stroker_ConicTo( FT_Stroker stroker,
1357 FT_Error error = FT_Err_Ok;
1358 FT_Vector bez_stack[34];
1360 FT_Vector* limit = bez_stack + 30;
1361 FT_Bool first_arc = TRUE;
1364 /* if all control points are coincident, this is a no-op; */
1365 /* avoid creating a spurious corner */
1366 if ( FT_IS_SMALL( stroker->center.x - control->x ) &&
1367 FT_IS_SMALL( stroker->center.y - control->y ) &&
1368 FT_IS_SMALL( control->x - to->x ) &&
1369 FT_IS_SMALL( control->y - to->y ) )
1371 stroker->center = *to;
1378 arc[2] = stroker->center;
1380 while ( arc >= bez_stack )
1382 FT_Angle angle_in, angle_out;
1385 /* initialize with current direction */
1386 angle_in = angle_out = stroker->angle_in;
1389 !ft_conic_is_small_enough( arc, &angle_in, &angle_out ) )
1391 if ( stroker->first_point )
1392 stroker->angle_in = angle_in;
1394 ft_conic_split( arc );
1403 /* process corner if necessary */
1404 if ( stroker->first_point )
1405 error = ft_stroker_subpath_start( stroker, angle_in, 0 );
1408 stroker->angle_out = angle_in;
1409 error = ft_stroker_process_corner( stroker, 0 );
1412 else if ( ft_pos_abs( FT_Angle_Diff( stroker->angle_in, angle_in ) ) >
1413 FT_SMALL_CONIC_THRESHOLD / 4 )
1415 /* if the deviation from one arc to the next is too great, */
1416 /* add a round corner */
1417 stroker->center = arc[2];
1418 stroker->angle_out = angle_in;
1419 stroker->line_join = FT_STROKER_LINEJOIN_ROUND;
1421 error = ft_stroker_process_corner( stroker, 0 );
1423 /* reinstate line join style */
1424 stroker->line_join = stroker->line_join_saved;
1430 /* the arc's angle is small enough; we can add it directly to each */
1433 FT_Vector ctrl, end;
1434 FT_Angle theta, phi, rotate, alpha0 = 0;
1436 FT_StrokeBorder border;
1440 theta = FT_Angle_Diff( angle_in, angle_out ) / 2;
1441 phi = angle_in + theta;
1442 length = FT_DivFix( stroker->radius, FT_Cos( theta ) );
1444 /* compute direction of original arc */
1445 if ( stroker->handle_wide_strokes )
1446 alpha0 = FT_Atan2( arc[0].x - arc[2].x, arc[0].y - arc[2].y );
1448 for ( border = stroker->borders, side = 0;
1452 rotate = FT_SIDE_TO_ROTATE( side );
1454 /* compute control point */
1455 FT_Vector_From_Polar( &ctrl, length, phi + rotate );
1459 /* compute end point */
1460 FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
1464 if ( stroker->handle_wide_strokes )
1470 /* determine whether the border radius is greater than the */
1471 /* radius of curvature of the original arc */
1472 start = border->points[border->num_points - 1];
1474 alpha1 = FT_Atan2( end.x - start.x, end.y - start.y );
1476 /* is the direction of the border arc opposite to */
1477 /* that of the original arc? */
1478 if ( ft_pos_abs( FT_Angle_Diff( alpha0, alpha1 ) ) >
1481 FT_Angle beta, gamma;
1482 FT_Vector bvec, delta;
1483 FT_Fixed blen, sinA, sinB, alen;
1486 /* use the sine rule to find the intersection point */
1487 beta = FT_Atan2( arc[2].x - start.x, arc[2].y - start.y );
1488 gamma = FT_Atan2( arc[0].x - end.x, arc[0].y - end.y );
1490 bvec.x = end.x - start.x;
1491 bvec.y = end.y - start.y;
1493 blen = FT_Vector_Length( &bvec );
1495 sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) );
1496 sinB = ft_pos_abs( FT_Sin( beta - gamma ) );
1498 alen = FT_DivFix( FT_MulFix( blen, sinA ), sinB );
1500 FT_Vector_From_Polar( &delta, alen, beta );
1504 /* circumnavigate the negative sector backwards */
1505 border->movable = FALSE;
1506 error = ft_stroke_border_lineto( border, &delta, FALSE );
1509 error = ft_stroke_border_lineto( border, &end, FALSE );
1512 error = ft_stroke_border_conicto( border, &ctrl, &start );
1515 /* and then move to the endpoint */
1516 error = ft_stroke_border_lineto( border, &end, FALSE );
1523 /* else fall through */
1526 /* simply add an arc */
1527 error = ft_stroke_border_conicto( border, &ctrl, &end );
1535 stroker->angle_in = angle_out;
1538 stroker->center = *to;
1545 /* documentation is in ftstroke.h */
1547 FT_EXPORT_DEF( FT_Error )
1548 FT_Stroker_CubicTo( FT_Stroker stroker,
1549 FT_Vector* control1,
1550 FT_Vector* control2,
1553 FT_Error error = FT_Err_Ok;
1554 FT_Vector bez_stack[37];
1556 FT_Vector* limit = bez_stack + 32;
1557 FT_Bool first_arc = TRUE;
1560 /* if all control points are coincident, this is a no-op; */
1561 /* avoid creating a spurious corner */
1562 if ( FT_IS_SMALL( stroker->center.x - control1->x ) &&
1563 FT_IS_SMALL( stroker->center.y - control1->y ) &&
1564 FT_IS_SMALL( control1->x - control2->x ) &&
1565 FT_IS_SMALL( control1->y - control2->y ) &&
1566 FT_IS_SMALL( control2->x - to->x ) &&
1567 FT_IS_SMALL( control2->y - to->y ) )
1569 stroker->center = *to;
1577 arc[3] = stroker->center;
1579 while ( arc >= bez_stack )
1581 FT_Angle angle_in, angle_mid, angle_out;
1584 /* initialize with current direction */
1585 angle_in = angle_out = angle_mid = stroker->angle_in;
1588 !ft_cubic_is_small_enough( arc, &angle_in,
1589 &angle_mid, &angle_out ) )
1591 if ( stroker->first_point )
1592 stroker->angle_in = angle_in;
1594 ft_cubic_split( arc );
1603 /* process corner if necessary */
1604 if ( stroker->first_point )
1605 error = ft_stroker_subpath_start( stroker, angle_in, 0 );
1608 stroker->angle_out = angle_in;
1609 error = ft_stroker_process_corner( stroker, 0 );
1612 else if ( ft_pos_abs( FT_Angle_Diff( stroker->angle_in, angle_in ) ) >
1613 FT_SMALL_CUBIC_THRESHOLD / 4 )
1615 /* if the deviation from one arc to the next is too great, */
1616 /* add a round corner */
1617 stroker->center = arc[3];
1618 stroker->angle_out = angle_in;
1619 stroker->line_join = FT_STROKER_LINEJOIN_ROUND;
1621 error = ft_stroker_process_corner( stroker, 0 );
1623 /* reinstate line join style */
1624 stroker->line_join = stroker->line_join_saved;
1630 /* the arc's angle is small enough; we can add it directly to each */
1633 FT_Vector ctrl1, ctrl2, end;
1634 FT_Angle theta1, phi1, theta2, phi2, rotate, alpha0 = 0;
1635 FT_Fixed length1, length2;
1636 FT_StrokeBorder border;
1640 theta1 = FT_Angle_Diff( angle_in, angle_mid ) / 2;
1641 theta2 = FT_Angle_Diff( angle_mid, angle_out ) / 2;
1642 phi1 = ft_angle_mean( angle_in, angle_mid );
1643 phi2 = ft_angle_mean( angle_mid, angle_out );
1644 length1 = FT_DivFix( stroker->radius, FT_Cos( theta1 ) );
1645 length2 = FT_DivFix( stroker->radius, FT_Cos( theta2 ) );
1647 /* compute direction of original arc */
1648 if ( stroker->handle_wide_strokes )
1649 alpha0 = FT_Atan2( arc[0].x - arc[3].x, arc[0].y - arc[3].y );
1651 for ( border = stroker->borders, side = 0;
1655 rotate = FT_SIDE_TO_ROTATE( side );
1657 /* compute control points */
1658 FT_Vector_From_Polar( &ctrl1, length1, phi1 + rotate );
1659 ctrl1.x += arc[2].x;
1660 ctrl1.y += arc[2].y;
1662 FT_Vector_From_Polar( &ctrl2, length2, phi2 + rotate );
1663 ctrl2.x += arc[1].x;
1664 ctrl2.y += arc[1].y;
1666 /* compute end point */
1667 FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
1671 if ( stroker->handle_wide_strokes )
1677 /* determine whether the border radius is greater than the */
1678 /* radius of curvature of the original arc */
1679 start = border->points[border->num_points - 1];
1681 alpha1 = FT_Atan2( end.x - start.x, end.y - start.y );
1683 /* is the direction of the border arc opposite to */
1684 /* that of the original arc? */
1685 if ( ft_pos_abs( FT_Angle_Diff( alpha0, alpha1 ) ) >
1688 FT_Angle beta, gamma;
1689 FT_Vector bvec, delta;
1690 FT_Fixed blen, sinA, sinB, alen;
1693 /* use the sine rule to find the intersection point */
1694 beta = FT_Atan2( arc[3].x - start.x, arc[3].y - start.y );
1695 gamma = FT_Atan2( arc[0].x - end.x, arc[0].y - end.y );
1697 bvec.x = end.x - start.x;
1698 bvec.y = end.y - start.y;
1700 blen = FT_Vector_Length( &bvec );
1702 sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) );
1703 sinB = ft_pos_abs( FT_Sin( beta - gamma ) );
1705 alen = FT_DivFix( FT_MulFix( blen, sinA ), sinB );
1707 FT_Vector_From_Polar( &delta, alen, beta );
1711 /* circumnavigate the negative sector backwards */
1712 border->movable = FALSE;
1713 error = ft_stroke_border_lineto( border, &delta, FALSE );
1716 error = ft_stroke_border_lineto( border, &end, FALSE );
1719 error = ft_stroke_border_cubicto( border,
1725 /* and then move to the endpoint */
1726 error = ft_stroke_border_lineto( border, &end, FALSE );
1733 /* else fall through */
1736 /* simply add an arc */
1737 error = ft_stroke_border_cubicto( border, &ctrl1, &ctrl2, &end );
1745 stroker->angle_in = angle_out;
1748 stroker->center = *to;
1755 /* documentation is in ftstroke.h */
1757 FT_EXPORT_DEF( FT_Error )
1758 FT_Stroker_BeginSubPath( FT_Stroker stroker,
1762 /* We cannot process the first point, because there is not enough */
1763 /* information regarding its corner/cap. The latter will be processed */
1764 /* in the `FT_Stroker_EndSubPath' routine. */
1766 stroker->first_point = TRUE;
1767 stroker->center = *to;
1768 stroker->subpath_open = open;
1770 /* Determine if we need to check whether the border radius is greater */
1771 /* than the radius of curvature of a curve, to handle this case */
1772 /* specially. This is only required if bevel joins or butt caps may */
1773 /* be created, because round & miter joins and round & square caps */
1774 /* cover the negative sector created with wide strokes. */
1775 stroker->handle_wide_strokes =
1776 FT_BOOL( stroker->line_join != FT_STROKER_LINEJOIN_ROUND ||
1777 ( stroker->subpath_open &&
1778 stroker->line_cap == FT_STROKER_LINECAP_BUTT ) );
1780 /* record the subpath start point for each border */
1781 stroker->subpath_start = *to;
1783 stroker->angle_in = 0;
1790 ft_stroker_add_reverse_left( FT_Stroker stroker,
1793 FT_StrokeBorder right = stroker->borders + 0;
1794 FT_StrokeBorder left = stroker->borders + 1;
1796 FT_Error error = FT_Err_Ok;
1799 FT_ASSERT( left->start >= 0 );
1801 new_points = left->num_points - left->start;
1802 if ( new_points > 0 )
1804 error = ft_stroke_border_grow( right, (FT_UInt)new_points );
1809 FT_Vector* dst_point = right->points + right->num_points;
1810 FT_Byte* dst_tag = right->tags + right->num_points;
1811 FT_Vector* src_point = left->points + left->num_points - 1;
1812 FT_Byte* src_tag = left->tags + left->num_points - 1;
1815 while ( src_point >= left->points + left->start )
1817 *dst_point = *src_point;
1818 *dst_tag = *src_tag;
1821 dst_tag[0] &= ~FT_STROKE_TAG_BEGIN_END;
1825 (FT_Byte)( dst_tag[0] & FT_STROKE_TAG_BEGIN_END );
1828 /* switch begin/end tags if necessary */
1829 if ( ttag == FT_STROKE_TAG_BEGIN ||
1830 ttag == FT_STROKE_TAG_END )
1831 dst_tag[0] ^= FT_STROKE_TAG_BEGIN_END;
1841 left->num_points = left->start;
1842 right->num_points += new_points;
1844 right->movable = FALSE;
1845 left->movable = FALSE;
1853 /* documentation is in ftstroke.h */
1855 /* there's a lot of magic in this function! */
1856 FT_EXPORT_DEF( FT_Error )
1857 FT_Stroker_EndSubPath( FT_Stroker stroker )
1859 FT_Error error = FT_Err_Ok;
1862 if ( stroker->subpath_open )
1864 FT_StrokeBorder right = stroker->borders;
1867 /* All right, this is an opened path, we need to add a cap between */
1868 /* right & left, add the reverse of left, then add a final cap */
1869 /* between left & right. */
1870 error = ft_stroker_cap( stroker, stroker->angle_in, 0 );
1874 /* add reversed points from `left' to `right' */
1875 error = ft_stroker_add_reverse_left( stroker, TRUE );
1879 /* now add the final cap */
1880 stroker->center = stroker->subpath_start;
1881 error = ft_stroker_cap( stroker,
1882 stroker->subpath_angle + FT_ANGLE_PI, 0 );
1886 /* Now end the right subpath accordingly. The left one is */
1887 /* rewind and doesn't need further processing. */
1888 ft_stroke_border_close( right, FALSE );
1896 /* close the path if needed */
1897 if ( stroker->center.x != stroker->subpath_start.x ||
1898 stroker->center.y != stroker->subpath_start.y )
1900 error = FT_Stroker_LineTo( stroker, &stroker->subpath_start );
1905 /* process the corner */
1906 stroker->angle_out = stroker->subpath_angle;
1907 turn = FT_Angle_Diff( stroker->angle_in,
1908 stroker->angle_out );
1910 /* no specific corner processing is required if the turn is 0 */
1913 /* when we turn to the right, the inside side is 0 */
1916 /* otherwise, the inside side is 1 */
1920 error = ft_stroker_inside( stroker,
1922 stroker->subpath_line_length );
1926 /* process the outside side */
1927 error = ft_stroker_outside( stroker,
1929 stroker->subpath_line_length );
1934 /* then end our two subpaths */
1935 ft_stroke_border_close( stroker->borders + 0, FALSE );
1936 ft_stroke_border_close( stroker->borders + 1, TRUE );
1944 /* documentation is in ftstroke.h */
1946 FT_EXPORT_DEF( FT_Error )
1947 FT_Stroker_GetBorderCounts( FT_Stroker stroker,
1948 FT_StrokerBorder border,
1949 FT_UInt *anum_points,
1950 FT_UInt *anum_contours )
1952 FT_UInt num_points = 0, num_contours = 0;
1956 if ( !stroker || border > 1 )
1958 error = FT_Err_Invalid_Argument;
1962 error = ft_stroke_border_get_counts( stroker->borders + border,
1963 &num_points, &num_contours );
1966 *anum_points = num_points;
1968 if ( anum_contours )
1969 *anum_contours = num_contours;
1975 /* documentation is in ftstroke.h */
1977 FT_EXPORT_DEF( FT_Error )
1978 FT_Stroker_GetCounts( FT_Stroker stroker,
1979 FT_UInt *anum_points,
1980 FT_UInt *anum_contours )
1982 FT_UInt count1, count2, num_points = 0;
1983 FT_UInt count3, count4, num_contours = 0;
1987 error = ft_stroke_border_get_counts( stroker->borders + 0,
1992 error = ft_stroke_border_get_counts( stroker->borders + 1,
1997 num_points = count1 + count3;
1998 num_contours = count2 + count4;
2001 *anum_points = num_points;
2002 *anum_contours = num_contours;
2007 /* documentation is in ftstroke.h */
2009 FT_EXPORT_DEF( void )
2010 FT_Stroker_ExportBorder( FT_Stroker stroker,
2011 FT_StrokerBorder border,
2012 FT_Outline* outline )
2014 if ( border == FT_STROKER_BORDER_LEFT ||
2015 border == FT_STROKER_BORDER_RIGHT )
2017 FT_StrokeBorder sborder = & stroker->borders[border];
2020 if ( sborder->valid )
2021 ft_stroke_border_export( sborder, outline );
2026 /* documentation is in ftstroke.h */
2028 FT_EXPORT_DEF( void )
2029 FT_Stroker_Export( FT_Stroker stroker,
2030 FT_Outline* outline )
2032 FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_LEFT, outline );
2033 FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_RIGHT, outline );
2037 /* documentation is in ftstroke.h */
2040 * The following is very similar to FT_Outline_Decompose, except
2041 * that we do support opened paths, and do not scale the outline.
2043 FT_EXPORT_DEF( FT_Error )
2044 FT_Stroker_ParseOutline( FT_Stroker stroker,
2045 FT_Outline* outline,
2049 FT_Vector v_control;
2058 FT_Int n; /* index of contour in outline */
2059 FT_UInt first; /* index of first point in contour */
2060 FT_Int tag; /* current point's state */
2063 if ( !outline || !stroker )
2064 return FT_Err_Invalid_Argument;
2066 FT_Stroker_Rewind( stroker );
2070 for ( n = 0; n < outline->n_contours; n++ )
2072 FT_UInt last; /* index of last point in contour */
2075 last = outline->contours[n];
2076 limit = outline->points + last;
2078 /* skip empty points; we don't stroke these */
2079 if ( last <= first )
2085 v_start = outline->points[first];
2086 v_last = outline->points[last];
2088 v_control = v_start;
2090 point = outline->points + first;
2091 tags = outline->tags + first;
2092 tag = FT_CURVE_TAG( tags[0] );
2094 /* A contour cannot start with a cubic control point! */
2095 if ( tag == FT_CURVE_TAG_CUBIC )
2096 goto Invalid_Outline;
2098 /* check first point to determine origin */
2099 if ( tag == FT_CURVE_TAG_CONIC )
2101 /* First point is conic control. Yes, this happens. */
2102 if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON )
2104 /* start at last point if it is on the curve */
2110 /* if both first and last points are conic, */
2111 /* start at their middle */
2112 v_start.x = ( v_start.x + v_last.x ) / 2;
2113 v_start.y = ( v_start.y + v_last.y ) / 2;
2119 error = FT_Stroker_BeginSubPath( stroker, &v_start, opened );
2123 while ( point < limit )
2128 tag = FT_CURVE_TAG( tags[0] );
2131 case FT_CURVE_TAG_ON: /* emit a single line_to */
2139 error = FT_Stroker_LineTo( stroker, &vec );
2145 case FT_CURVE_TAG_CONIC: /* consume conic arcs */
2146 v_control.x = point->x;
2147 v_control.y = point->y;
2150 if ( point < limit )
2158 tag = FT_CURVE_TAG( tags[0] );
2162 if ( tag == FT_CURVE_TAG_ON )
2164 error = FT_Stroker_ConicTo( stroker, &v_control, &vec );
2170 if ( tag != FT_CURVE_TAG_CONIC )
2171 goto Invalid_Outline;
2173 v_middle.x = ( v_control.x + vec.x ) / 2;
2174 v_middle.y = ( v_control.y + vec.y ) / 2;
2176 error = FT_Stroker_ConicTo( stroker, &v_control, &v_middle );
2184 error = FT_Stroker_ConicTo( stroker, &v_control, &v_start );
2187 default: /* FT_CURVE_TAG_CUBIC */
2189 FT_Vector vec1, vec2;
2192 if ( point + 1 > limit ||
2193 FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC )
2194 goto Invalid_Outline;
2202 if ( point <= limit )
2209 error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &vec );
2215 error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &v_start );
2225 /* don't try to end the path if no segments have been generated */
2226 if ( !stroker->first_point )
2228 error = FT_Stroker_EndSubPath( stroker );
2242 return FT_Err_Invalid_Outline;
2246 /* declare an extern to access `ft_outline_glyph_class' globally */
2247 /* allocated in `ftglyph.c', and use the FT_OUTLINE_GLYPH_CLASS_GET */
2248 /* macro to access it when FT_CONFIG_OPTION_PIC is defined */
2249 #ifndef FT_CONFIG_OPTION_PIC
2250 extern const FT_Glyph_Class ft_outline_glyph_class;
2252 #include "basepic.h"
2255 /* documentation is in ftstroke.h */
2257 FT_EXPORT_DEF( FT_Error )
2258 FT_Glyph_Stroke( FT_Glyph *pglyph,
2262 FT_Error error = FT_Err_Invalid_Argument;
2263 FT_Glyph glyph = NULL;
2264 FT_Library library = stroker->library;
2266 FT_UNUSED( library );
2269 if ( pglyph == NULL )
2273 if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
2280 error = FT_Glyph_Copy( glyph, © );
2288 FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
2289 FT_Outline* outline = &oglyph->outline;
2290 FT_UInt num_points, num_contours;
2293 error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
2297 (void)FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
2299 FT_Outline_Done( glyph->library, outline );
2301 error = FT_Outline_New( glyph->library,
2302 num_points, num_contours, outline );
2306 outline->n_points = 0;
2307 outline->n_contours = 0;
2309 FT_Stroker_Export( stroker, outline );
2313 FT_Done_Glyph( *pglyph );
2319 FT_Done_Glyph( glyph );
2330 /* documentation is in ftstroke.h */
2332 FT_EXPORT_DEF( FT_Error )
2333 FT_Glyph_StrokeBorder( FT_Glyph *pglyph,
2338 FT_Error error = FT_Err_Invalid_Argument;
2339 FT_Glyph glyph = NULL;
2340 FT_Library library = stroker->library;
2342 FT_UNUSED( library );
2345 if ( pglyph == NULL )
2349 if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
2356 error = FT_Glyph_Copy( glyph, © );
2364 FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
2365 FT_StrokerBorder border;
2366 FT_Outline* outline = &oglyph->outline;
2367 FT_UInt num_points, num_contours;
2370 border = FT_Outline_GetOutsideBorder( outline );
2373 if ( border == FT_STROKER_BORDER_LEFT )
2374 border = FT_STROKER_BORDER_RIGHT;
2376 border = FT_STROKER_BORDER_LEFT;
2379 error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
2383 (void)FT_Stroker_GetBorderCounts( stroker, border,
2384 &num_points, &num_contours );
2386 FT_Outline_Done( glyph->library, outline );
2388 error = FT_Outline_New( glyph->library,
2395 outline->n_points = 0;
2396 outline->n_contours = 0;
2398 FT_Stroker_ExportBorder( stroker, border, outline );
2402 FT_Done_Glyph( *pglyph );
2408 FT_Done_Glyph( glyph );