[base, truetype] New internal FT_Hypot function.

* include/freetype/fttrigon.h (FT_Hypot): Declare it.
* src/base/fttrigon.c (FT_Hypot): Define it.
* src/truetype/ttgload.c (TT_Process_Composite_Component): Use it
instead of explicit expressions.
* src/truetype/ttinterp.c (Current_Ratio, Normalize): Use it instead
of TT_VecLen.
(TT_VecLen): Removed.
This commit is contained in:
Alexei Podtelezhnikov 2013-01-23 23:31:41 -05:00
parent dcc0d070e0
commit b6de8e6612
5 changed files with 44 additions and 29 deletions

View File

@ -1,3 +1,15 @@
2013-01-23 Alexei Podtelezhnikov <apodtele@gmail.com>
[base, truetype] New internal FT_Hypot function.
* include/freetype/fttrigon.h (FT_Hypot): Declare it.
* src/base/fttrigon.c (FT_Hypot): Define it.
* src/truetype/ttgload.c (TT_Process_Composite_Component): Use it
instead of explicit expressions.
* src/truetype/ttinterp.c (Current_Ratio, Normalize): Use it instead
of TT_VecLen.
(TT_VecLen): Removed.
2013-01-23 Alexei Podtelezhnikov <apodtele@gmail.com>
[base] Fix integer overflow.

View File

@ -4,7 +4,7 @@
/* */
/* FreeType trigonometric functions (specification). */
/* */
/* Copyright 2001, 2003, 2005, 2007 by */
/* Copyright 2001, 2003, 2005, 2007, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -339,6 +339,14 @@ FT_BEGIN_HEADER
FT_Fixed length,
FT_Angle angle );
/*
* Return sqrt(x*x+y*y), which is the same as FT_Vector_Length but uses
* two fixed-point arguments instead.
*/
FT_BASE( FT_Fixed )
FT_Hypot( FT_Fixed x,
FT_Fixed y );
/* */

View File

@ -492,4 +492,19 @@
}
/* documentation is in fttrigon.h */
FT_BASE_DEF( FT_Fixed )
FT_Hypot( FT_Fixed x,
FT_Fixed y )
{
FT_Vector v;
v.x = x;
v.y = y;
return FT_Vector_Length( &v );
}
/* END */

View File

@ -22,6 +22,7 @@
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_SFNT_H
#include FT_TRUETYPE_TAGS_H
#include FT_TRIGONOMETRY_H
#include FT_OUTLINE_H
#include "ttgload.h"
@ -1082,16 +1083,10 @@
/* */
/* This algorithm is a guess and works much better than the above. */
/* */
FT_Fixed mac_xscale = FT_SqrtFixed(
(FT_Int32)FT_MulFix( subglyph->transform.xx,
subglyph->transform.xx ) +
(FT_Int32)FT_MulFix( subglyph->transform.xy,
subglyph->transform.xy ) );
FT_Fixed mac_yscale = FT_SqrtFixed(
(FT_Int32)FT_MulFix( subglyph->transform.yy,
subglyph->transform.yy ) +
(FT_Int32)FT_MulFix( subglyph->transform.yx,
subglyph->transform.yx ) );
FT_Fixed mac_xscale = FT_Hypot( subglyph->transform.xx,
subglyph->transform.xy );
FT_Fixed mac_yscale = FT_Hypot( subglyph->transform.yy,
subglyph->transform.yx );
x = FT_MulFix( x, mac_xscale );

View File

@ -4,7 +4,7 @@
/* */
/* TrueType bytecode interpreter (body). */
/* */
/* Copyright 1996-2012 */
/* Copyright 1996-2013 */
/* by David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -1542,21 +1542,6 @@
}
/* return length of given vector */
static FT_F26Dot6
TT_VecLen( FT_F26Dot6 X,
FT_F26Dot6 Y )
{
FT_Vector v;
v.x = X;
v.y = Y;
return FT_Vector_Length( &v );
}
/*************************************************************************/
/* */
/* <Function> */
@ -1600,7 +1585,7 @@
CUR.GS.projVector.x );
y = TT_MulFix14( CUR.tt_metrics.y_ratio,
CUR.GS.projVector.y );
CUR.tt_metrics.ratio = TT_VecLen( x, y );
CUR.tt_metrics.ratio = FT_Hypot( x, y );
}
}
}
@ -2658,7 +2643,7 @@
Vy *= 0x4000;
}
W = TT_VecLen( Vx, Vy );
W = FT_Hypot( Vx, Vy );
R->x = (FT_F2Dot14)TT_DivFix14( Vx, W );
R->y = (FT_F2Dot14)TT_DivFix14( Vy, W );