misc/libfreetype/include/freetype/internal/ftcalc.h
author koda
Fri, 11 Oct 2013 11:55:31 +0200
branchwebgl
changeset 9282 92af50454cf2
parent 5172 88f2e05288ba
permissions -rw-r--r--
force clang dependency when NOPASCAL is set
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftcalc.h                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    Arithmetic computations (specification).                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 by       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#ifndef __FTCALC_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#define __FTCALC_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
FT_BEGIN_HEADER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /*    FT_FixedSqrt                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /*    Computes the square root of a 16.16 fixed point value.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /*    x :: The value to compute the root for.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*    The result of `sqrt(x)'.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /*    This function is not very fast.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  FT_BASE( FT_Int32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  FT_SqrtFixed( FT_Int32  x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /*    FT_Sqrt32                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /*    Computes the square root of an Int32 integer (which will be        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  /*    handled as an unsigned long value).                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /*    x :: The value to compute the root for.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  /*    The result of `sqrt(x)'.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  FT_EXPORT( FT_Int32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  FT_Sqrt32( FT_Int32  x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /* FT_MulDiv() and FT_MulFix() are declared in freetype.h.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /*    FT_MulDiv_No_Round                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  /*    A very simple function used to perform the computation `(a*b)/c'   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  /*    (without rounding) with maximal accuracy (it uses a 64-bit         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  /*    intermediate integer whenever necessary).                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  /*    This function isn't necessarily as fast as some processor specific */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  /*    operations, but is at least completely portable.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  /*    a :: The first multiplier.                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  /*    b :: The second multiplier.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  /*    c :: The divisor.                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  /*    The result of `(a*b)/c'.  This function never traps when trying to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  /*    divide by zero; it simply returns `MaxInt' or `MinInt' depending   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  /*    on the signs of `a' and `b'.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  FT_BASE( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  FT_MulDiv_No_Round( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
                      FT_Long  b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
                      FT_Long  c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
   *  A variant of FT_Matrix_Multiply which scales its result afterwards.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
   *  The idea is that both `a' and `b' are scaled by factors of 10 so that
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
   *  the values are as precise as possible to get a correct result during
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
   *  the 64bit multiplication.  Let `sa' and `sb' be the scaling factors of
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
   *  `a' and `b', respectively, then the scaling factor of the result is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
   *  `sa*sb'.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  FT_BASE( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  FT_Matrix_Multiply_Scaled( const FT_Matrix*  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
                             FT_Matrix        *b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
                             FT_Long           scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
   *  A variant of FT_Vector_Transform.  See comments for
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
   *  FT_Matrix_Multiply_Scaled.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
  FT_BASE( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  FT_Vector_Transform_Scaled( FT_Vector*        vector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
                              const FT_Matrix*  matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
                              FT_Long           scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
   *  Return -1, 0, or +1, depending on the orientation of a given corner.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
   *  We use the Cartesian coordinate system, with positive vertical values
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
   *  going upwards.  The function returns +1 if the corner turns to the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
   *  left, -1 to the right, and 0 for undecidable cases.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  FT_BASE( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  ft_corner_orientation( FT_Pos  in_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
                         FT_Pos  in_y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
                         FT_Pos  out_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
                         FT_Pos  out_y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
   *  Return TRUE if a corner is flat or nearly flat.  This is equivalent to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
   *  saying that the angle difference between the `in' and `out' vectors is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
   *  very small.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  FT_BASE( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  ft_corner_is_flat( FT_Pos  in_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
                     FT_Pos  in_y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
                     FT_Pos  out_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
                     FT_Pos  out_y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
#define INT_TO_F26DOT6( x )    ( (FT_Long)(x) << 6  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
#define INT_TO_F2DOT14( x )    ( (FT_Long)(x) << 14 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
#define INT_TO_FIXED( x )      ( (FT_Long)(x) << 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
#define F2DOT14_TO_FIXED( x )  ( (FT_Long)(x) << 2  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
#define FLOAT_TO_FIXED( x )    ( (FT_Long)( x * 65536.0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
#define FIXED_TO_INT( x )      ( FT_RoundFix( x ) >> 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
#define ROUND_F26DOT6( x )     ( x >= 0 ? (    ( (x) + 32 ) & -64 )     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
                                        : ( -( ( 32 - (x) ) & -64 ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
FT_END_HEADER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
#endif /* __FTCALC_H__ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
/* END */