* src/base/ftstroke.c (ft_stroke_border_arcto): Speed up calculations.

This commit is contained in:
Alexei Podtelezhnikov 2019-09-23 22:57:00 -04:00
parent 5327092bb2
commit 4881f75b7c
2 changed files with 38 additions and 45 deletions

View File

@ -1,3 +1,7 @@
2019-09-23 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/base/ftstroke.c (ft_stroke_border_arcto): Speed up calculations.
2019-09-20 Nikhil Ramakrishnan <ramakrishnan.nikhil@gmail.com> 2019-09-20 Nikhil Ramakrishnan <ramakrishnan.nikhil@gmail.com>
[woff2] Fix memory leaks. [woff2] Fix memory leaks.

View File

@ -540,63 +540,52 @@
FT_Angle angle_start, FT_Angle angle_start,
FT_Angle angle_diff ) FT_Angle angle_diff )
{ {
FT_Angle total, angle, step, rotate, next, theta; FT_Fixed coef;
FT_Vector a, b, a2, b2; FT_Vector a0, a1, a2, a3;
FT_Fixed length; FT_Int i, arcs = 1;
FT_Error error = FT_Err_Ok; FT_Error error = FT_Err_Ok;
/* compute start point */ /* number of cubic arcs to draw */
FT_Vector_From_Polar( &a, radius, angle_start ); while ( angle_diff > FT_ARC_CUBIC_ANGLE * arcs ||
a.x += center->x; -angle_diff > FT_ARC_CUBIC_ANGLE * arcs )
a.y += center->y; arcs++;
total = angle_diff; /* control tangents */
angle = angle_start; coef = FT_Tan( angle_diff / ( 4 * arcs ) );
rotate = ( angle_diff >= 0 ) ? FT_ANGLE_PI2 : -FT_ANGLE_PI2; coef += coef / 3;
while ( total != 0 ) /* compute start and first control point */
FT_Vector_From_Polar( &a0, radius, angle_start );
a1.x = FT_MulFix( -a0.y, coef );
a1.y = FT_MulFix( a0.x, coef );
a0.x += center->x;
a0.y += center->y;
a1.x += a0.x;
a1.y += a0.y;
for ( i = 1; i <= arcs; i++ )
{ {
step = total; /* compute end and second control point */
if ( step > FT_ARC_CUBIC_ANGLE ) FT_Vector_From_Polar( &a3, radius,
step = FT_ARC_CUBIC_ANGLE; angle_start + i * angle_diff / arcs );
a2.x = FT_MulFix( a3.y, coef );
a2.y = FT_MulFix( -a3.x, coef );
else if ( step < -FT_ARC_CUBIC_ANGLE ) a3.x += center->x;
step = -FT_ARC_CUBIC_ANGLE; a3.y += center->y;
a2.x += a3.x;
next = angle + step; a2.y += a3.y;
theta = step;
if ( theta < 0 )
theta = -theta;
theta >>= 1;
/* compute end point */
FT_Vector_From_Polar( &b, radius, next );
b.x += center->x;
b.y += center->y;
/* compute first and second control points */
length = FT_MulDiv( radius, FT_Sin( theta ) * 4,
( 0x10000L + FT_Cos( theta ) ) * 3 );
FT_Vector_From_Polar( &a2, length, angle + rotate );
a2.x += a.x;
a2.y += a.y;
FT_Vector_From_Polar( &b2, length, next - rotate );
b2.x += b.x;
b2.y += b.y;
/* add cubic arc */ /* add cubic arc */
error = ft_stroke_border_cubicto( border, &a2, &b2, &b ); error = ft_stroke_border_cubicto( border, &a1, &a2, &a3 );
if ( error ) if ( error )
break; break;
/* process the rest of the arc ?? */ /* a0 = a3; */
a = b; a1.x = a3.x - a2.x + a3.x;
total -= step; a1.y = a3.y - a2.y + a3.y;
angle = next;
} }
return error; return error;