misc/libfreetype/src/base/ftcalc.c
author sheepluva
Thu, 03 May 2012 14:21:53 +0200
changeset 7017 19a434fc91fc
parent 5172 88f2e05288ba
permissions -rw-r--r--
visually indicate when map preview generation is in progress.
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.c                                                               */
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 (body).                                      */
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 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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  /* Support for 1-complement arithmetic has been totally dropped in this  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* release.  You can still write your own code if you need it.           */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
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
  /* Implementing basic computation routines.                              */
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
  /* FT_MulDiv(), FT_MulFix(), FT_DivFix(), FT_RoundFix(), FT_CeilFix(),   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* and FT_FloorFix() are declared in freetype.h.                         */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#include FT_GLYPH_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#include FT_INTERNAL_CALC_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#include FT_INTERNAL_OBJECTS_H
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
#ifdef FT_MULFIX_INLINED
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#undef FT_MulFix
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
/* we need to define a 64-bits data type here */
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
#ifdef FT_LONG64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  typedef FT_INT64  FT_Int64;
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
#else
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
  typedef struct  FT_Int64_
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
    FT_UInt32  lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    FT_UInt32  hi;
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
  } FT_Int64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
#endif /* FT_LONG64 */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /*************************************************************************/
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
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
#define FT_COMPONENT  trace_calc
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
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
  /* The following three functions are available regardless of whether */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  /* FT_LONG64 is defined.                                             */
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
  /* documentation is 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
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
  FT_RoundFix( FT_Fixed  a )
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
    return ( a >= 0 ) ?   ( a + 0x8000L ) & ~0xFFFFL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
                      : -((-a + 0x8000L ) & ~0xFFFFL );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /* documentation is in freetype.h */
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
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  FT_CeilFix( FT_Fixed  a )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    return ( a >= 0 ) ?   ( a + 0xFFFFL ) & ~0xFFFFL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
                      : -((-a + 0xFFFFL ) & ~0xFFFFL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
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
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  FT_FloorFix( FT_Fixed  a )
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 ( a >= 0 ) ?   a & ~0xFFFFL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
                      : -((-a) & ~0xFFFFL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
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
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  FT_EXPORT_DEF( FT_Int32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  FT_Sqrt32( FT_Int32  x )
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
    FT_UInt32  val, root, newroot, mask;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    root = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    mask = (FT_UInt32)0x40000000UL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    val  = (FT_UInt32)x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    do
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
      newroot = root + mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      if ( newroot <= val )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
        val -= newroot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
        root = newroot + mask;
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
      root >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      mask >>= 2;
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
    } while ( mask != 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    return root;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
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
#ifdef FT_LONG64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
  /* documentation is in freetype.h */
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_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  FT_MulDiv( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
             FT_Long  b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
             FT_Long  c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    FT_Int   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    FT_Long  d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    s = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    if ( a < 0 ) { a = -a; s = -1; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    if ( b < 0 ) { b = -b; s = -s; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    if ( c < 0 ) { c = -c; s = -s; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
                         : 0x7FFFFFFFL );
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
    return ( s > 0 ) ? d : -d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
  /* documentation is in ftcalc.h */
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
  FT_BASE_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
  FT_MulDiv_No_Round( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
                      FT_Long  b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
                      FT_Long  c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    FT_Int   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    FT_Long  d;
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
    s = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    if ( a < 0 ) { a = -a; s = -1; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    if ( b < 0 ) { b = -b; s = -s; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    if ( c < 0 ) { c = -c; s = -s; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
                         : 0x7FFFFFFFL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    return ( s > 0 ) ? d : -d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  FT_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
  FT_MulFix( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
             FT_Long  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
#ifdef FT_MULFIX_ASSEMBLER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    return FT_MULFIX_ASSEMBLER( a, b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    FT_Int   s = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    FT_Long  c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    if ( a < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      a = -a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      s = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    if ( b < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      b = -b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      s = -s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    return ( s > 0 ) ? c : -c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
#endif /* FT_MULFIX_ASSEMBLER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  FT_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  FT_DivFix( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
             FT_Long  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    FT_Int32   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    FT_UInt32  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    s = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    if ( a < 0 ) { a = -a; s = -1; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    if ( b < 0 ) { b = -b; s = -s; }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    if ( b == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
      /* check for division by 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
      q = 0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
      /* compute result directly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      q = (FT_UInt32)( ( ( (FT_Int64)a << 16 ) + ( b >> 1 ) ) / b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    return ( s < 0 ? -(FT_Long)q : (FT_Long)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
#else /* !FT_LONG64 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  ft_multo64( FT_UInt32  x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
              FT_UInt32  y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
              FT_Int64  *z )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    FT_UInt32  lo1, hi1, lo2, hi2, lo, hi, i1, i2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    lo1 = x & 0x0000FFFFU;  hi1 = x >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    lo2 = y & 0x0000FFFFU;  hi2 = y >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    lo = lo1 * lo2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    i1 = lo1 * hi2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    i2 = lo2 * hi1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    hi = hi1 * hi2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    /* Check carry overflow of i1 + i2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    i1 += i2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    hi += (FT_UInt32)( i1 < i2 ) << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    hi += i1 >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    i1  = i1 << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
    /* Check carry overflow of i1 + lo */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
    lo += i1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    hi += ( lo < i1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    z->lo = lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    z->hi = hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
  static FT_UInt32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
  ft_div64by32( FT_UInt32  hi,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
                FT_UInt32  lo,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
                FT_UInt32  y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    FT_UInt32  r, q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    FT_Int     i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    q = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    r = hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    if ( r >= y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      return (FT_UInt32)0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
    i = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      r <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
      q <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      r  |= lo >> 31;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      if ( r >= (FT_UInt32)y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
        r -= y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
        q |= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
      lo <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    } while ( --i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    return q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  FT_Add64( FT_Int64*  x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
            FT_Int64*  y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
            FT_Int64  *z )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    register FT_UInt32  lo, hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    lo = x->lo + y->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    hi = x->hi + y->hi + ( lo < x->lo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    z->lo = lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    z->hi = hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
  /* The FT_MulDiv function has been optimized thanks to ideas from      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
  /* Graham Asher.  The trick is to optimize computation when everything */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  /* fits within 32-bits (a rather common case).                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
  /*  we compute 'a*b+c/2', then divide it by 'c'. (positive values)     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  /*  46340 is FLOOR(SQRT(2^31-1)).                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
  /*  if ( a <= 46340 && b <= 46340 ) then ( a*b <= 0x7FFEA810 )         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
  /*  0x7FFFFFFF - 0x7FFEA810 = 0x157F0                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
  /*  if ( c < 0x157F0*2 ) then ( a*b+c/2 <= 0x7FFFFFFF )                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
  /*  and 2*0x157F0 = 176096                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  FT_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  FT_MulDiv( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
             FT_Long  b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
             FT_Long  c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    long  s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    /* XXX: this function does not allow 64-bit arguments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    if ( a == 0 || b == c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      return a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
    s  = a; a = FT_ABS( a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    s ^= b; b = FT_ABS( b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    s ^= c; c = FT_ABS( c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
      a = ( a * b + ( c >> 1 ) ) / c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
    else if ( c > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
      FT_Int64  temp, temp2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      temp2.hi = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      temp2.lo = (FT_UInt32)(c >> 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      FT_Add64( &temp, &temp2, &temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
      a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      a = 0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    return ( s < 0 ? -a : a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
  FT_BASE_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
  FT_MulDiv_No_Round( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
                      FT_Long  b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
                      FT_Long  c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    long  s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    if ( a == 0 || b == c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
      return a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    s  = a; a = FT_ABS( a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    s ^= b; b = FT_ABS( b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
    s ^= c; c = FT_ABS( c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
    if ( a <= 46340L && b <= 46340L && c > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
      a = a * b / c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    else if ( c > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      FT_Int64  temp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
      ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      a = 0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
    return ( s < 0 ? -a : a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
  FT_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
  FT_MulFix( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
             FT_Long  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
#ifdef FT_MULFIX_ASSEMBLER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
    return FT_MULFIX_ASSEMBLER( a, b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
#elif 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
     *  This code is nonportable.  See comment below.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
     *  However, on a platform where right-shift of a signed quantity fills
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
     *  the leftmost bits by copying the sign bit, it might be faster.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
    FT_Long   sa, sb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
    FT_ULong  ua, ub;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    if ( a == 0 || b == 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      return a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
     *  This is a clever way of converting a signed number `a' into its
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
     *  absolute value (stored back into `a') and its sign.  The sign is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
     *  stored in `sa'; 0 means `a' was positive or zero, and -1 means `a'
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
     *  was negative.  (Similarly for `b' and `sb').
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
     *  Unfortunately, it doesn't work (at least not portably).
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
     *  It makes the assumption that right-shift on a negative signed value
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
     *  fills the leftmost bits by copying the sign bit.  This is wrong. 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
     *  According to K&R 2nd ed, section `A7.8 Shift Operators' on page 206,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
     *  the result of right-shift of a negative signed value is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
     *  implementation-defined.  At least one implementation fills the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
     *  leftmost bits with 0s (i.e., it is exactly the same as an unsigned
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
     *  right shift).  This means that when `a' is negative, `sa' ends up
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
     *  with the value 1 rather than -1.  After that, everything else goes
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
     *  wrong.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
    sa = ( a >> ( sizeof ( a ) * 8 - 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    a  = ( a ^ sa ) - sa;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    sb = ( b >> ( sizeof ( b ) * 8 - 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    b  = ( b ^ sb ) - sb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    ua = (FT_ULong)a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    ub = (FT_ULong)b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    if ( ua <= 2048 && ub <= 1048576L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
      ua = ( ua * ub + 0x8000U ) >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      FT_ULong  al = ua & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      ua = ( ua >> 16 ) * ub +  al * ( ub >> 16 ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
           ( ( al * ( ub & 0xFFFFU ) + 0x8000U ) >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    sa ^= sb,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    ua  = (FT_ULong)(( ua ^ sa ) - sa);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
    return (FT_Long)ua;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
#else /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    FT_Long   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
    FT_ULong  ua, ub;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    if ( a == 0 || b == 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      return a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
    s  = a; a = FT_ABS( a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    s ^= b; b = FT_ABS( b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    ua = (FT_ULong)a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    ub = (FT_ULong)b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    if ( ua <= 2048 && ub <= 1048576L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      ua = ( ua * ub + 0x8000UL ) >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      FT_ULong  al = ua & 0xFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
      ua = ( ua >> 16 ) * ub +  al * ( ub >> 16 ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
           ( ( al * ( ub & 0xFFFFUL ) + 0x8000UL ) >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    return ( s < 0 ? -(FT_Long)ua : (FT_Long)ua );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
  FT_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
  FT_DivFix( FT_Long  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
             FT_Long  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    FT_Int32   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    FT_UInt32  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    /* XXX: this function does not allow 64-bit arguments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    s  = (FT_Int32)a; a = FT_ABS( a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    s ^= (FT_Int32)b; b = FT_ABS( b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
    if ( b == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
      /* check for division by 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
      q = (FT_UInt32)0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
    else if ( ( a >> 16 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
      /* compute result directly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
      q = (FT_UInt32)( (a << 16) + (b >> 1) ) / (FT_UInt32)b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
      /* we need more bits; we have to do it by hand */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      FT_Int64  temp, temp2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
      temp.hi  = (FT_Int32) (a >> 16);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      temp.lo  = (FT_UInt32)(a << 16);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      temp2.hi = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
      temp2.lo = (FT_UInt32)( b >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
      FT_Add64( &temp, &temp2, &temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
      q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
  FT_MulTo64( FT_Int32   x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
              FT_Int32   y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
              FT_Int64  *z )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
    FT_Int32  s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    s  = x; x = FT_ABS( x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    s ^= y; y = FT_ABS( y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    ft_multo64( x, y, z );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    if ( s < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      z->lo = (FT_UInt32)-(FT_Int32)z->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
      z->hi = ~z->hi + !( z->lo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
  /* apparently, the second version of this code is not compiled correctly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
  /* on Mac machines with the MPW C compiler..  tsk, tsk, tsk...           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
  FT_EXPORT_DEF( FT_Int32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
  FT_Div64by32( FT_Int64*  x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
                FT_Int32   y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
    FT_Int32   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
    FT_UInt32  q, r, i, lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
    s  = x->hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
    if ( s < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      x->lo = (FT_UInt32)-(FT_Int32)x->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
      x->hi = ~x->hi + !x->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
    s ^= y;  y = FT_ABS( y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    /* Shortcut */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    if ( x->hi == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      if ( y > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        q = x->lo / y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
        q = 0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    r  = x->hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    lo = x->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    if ( r >= (FT_UInt32)y ) /* we know y is to be treated as unsigned here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
      return ( s < 0 ? 0x80000001UL : 0x7FFFFFFFUL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
                             /* Return Max/Min Int32 if division overflow. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
                             /* This includes division by zero!            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    q = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    for ( i = 0; i < 32; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      r <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
      q <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
      r  |= lo >> 31;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
      if ( r >= (FT_UInt32)y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
        r -= y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
        q |= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      lo <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
    return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
#else /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
  FT_EXPORT_DEF( FT_Int32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
  FT_Div64by32( FT_Int64*  x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
                FT_Int32   y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    FT_Int32   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
    FT_UInt32  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
    s  = x->hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
    if ( s < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
      x->lo = (FT_UInt32)-(FT_Int32)x->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
      x->hi = ~x->hi + !x->lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    s ^= y;  y = FT_ABS( y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    /* Shortcut */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    if ( x->hi == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
      if ( y > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
        q = ( x->lo + ( y >> 1 ) ) / y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
        q = 0x7FFFFFFFL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
      return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    q = ft_div64by32( x->hi, x->lo, y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
#endif /* FT_LONG64 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
  /* documentation is in ftglyph.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
  FT_Matrix_Multiply( const FT_Matrix*  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
                      FT_Matrix        *b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    FT_Fixed  xx, xy, yx, yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    if ( !a || !b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
    xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
    yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
    b->xx = xx;  b->xy = xy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
    b->yx = yx;  b->yy = yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
  /* documentation is in ftglyph.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
  FT_Matrix_Invert( FT_Matrix*  matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
    FT_Pos  delta, xx, yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    if ( !matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    /* compute discriminant */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
    delta = FT_MulFix( matrix->xx, matrix->yy ) -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
            FT_MulFix( matrix->xy, matrix->yx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    if ( !delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
      return FT_Err_Invalid_Argument;  /* matrix can't be inverted */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    matrix->xy = - FT_DivFix( matrix->xy, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    matrix->yx = - FT_DivFix( matrix->yx, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
    xx = matrix->xx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    yy = matrix->yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
    matrix->xx = FT_DivFix( yy, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    matrix->yy = FT_DivFix( xx, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
  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
   755
                             FT_Matrix        *b,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
                             FT_Long           scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
    FT_Fixed  xx, xy, yx, yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
    FT_Long   val = 0x10000L * scaling;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
    if ( !a || !b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
    xx = FT_MulDiv( a->xx, b->xx, val ) + FT_MulDiv( a->xy, b->yx, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    xy = FT_MulDiv( a->xx, b->xy, val ) + FT_MulDiv( a->xy, b->yy, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    yx = FT_MulDiv( a->yx, b->xx, val ) + FT_MulDiv( a->yy, b->yx, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
    yy = FT_MulDiv( a->yx, b->xy, val ) + FT_MulDiv( a->yy, b->yy, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
    b->xx = xx;  b->xy = xy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
    b->yx = yx;  b->yy = yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
  FT_Vector_Transform_Scaled( FT_Vector*        vector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
                              const FT_Matrix*  matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
                              FT_Long           scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
    FT_Pos   xz, yz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
    FT_Long  val = 0x10000L * scaling;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    if ( !vector || !matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    xz = FT_MulDiv( vector->x, matrix->xx, val ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
         FT_MulDiv( vector->y, matrix->xy, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    yz = FT_MulDiv( vector->x, matrix->yx, val ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
         FT_MulDiv( vector->y, matrix->yy, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
    vector->x = xz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    vector->y = yz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
  FT_BASE_DEF( FT_Int32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
  FT_SqrtFixed( FT_Int32  x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
    FT_UInt32  root, rem_hi, rem_lo, test_div;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    FT_Int     count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
    root = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
    if ( x > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
      rem_hi = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
      rem_lo = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
      count  = 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
        rem_hi   = ( rem_hi << 2 ) | ( rem_lo >> 30 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
        rem_lo <<= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
        root   <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
        test_div = ( root << 1 ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
        if ( rem_hi >= test_div )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
          rem_hi -= test_div;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
          root   += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
      } while ( --count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
    return (FT_Int32)root;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
  FT_BASE_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
  ft_corner_orientation( FT_Pos  in_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
                         FT_Pos  in_y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
                         FT_Pos  out_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
                         FT_Pos  out_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
    FT_Long  result; /* avoid overflow on 16-bit system */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    /* deal with the trivial cases quickly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    if ( in_y == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
      if ( in_x >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
        result = out_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
        result = -out_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
    else if ( in_x == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
      if ( in_y >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
        result = -out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
        result = out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    else if ( out_y == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
      if ( out_x >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
        result = in_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
        result = -in_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
    else if ( out_x == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      if ( out_y >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
        result = -in_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
        result =  in_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
    else /* general case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
#ifdef FT_LONG64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
      FT_Int64  delta = (FT_Int64)in_x * out_y - (FT_Int64)in_y * out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      if ( delta == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
        result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
        result = 1 - 2 * ( delta < 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      FT_Int64  z1, z2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
      /* XXX: this function does not allow 64-bit arguments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
      ft_multo64( (FT_Int32)in_x, (FT_Int32)out_y, &z1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
      ft_multo64( (FT_Int32)in_y, (FT_Int32)out_x, &z2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
      if ( z1.hi > z2.hi )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
        result = +1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
      else if ( z1.hi < z2.hi )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
        result = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
      else if ( z1.lo > z2.lo )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
        result = +1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      else if ( z1.lo < z2.lo )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
        result = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
        result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
    /* XXX: only the sign of return value, +1/0/-1 must be used */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
    return (FT_Int)result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
  /* documentation is in ftcalc.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
  FT_BASE_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
  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
   921
                     FT_Pos  in_y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
                     FT_Pos  out_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
                     FT_Pos  out_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
    FT_Pos  ax = in_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
    FT_Pos  ay = in_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
    FT_Pos  d_in, d_out, d_corner;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
    d_in = ax + ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
    ax = out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
    ay = out_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
    d_out = ax + ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
    ax = out_x + in_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
    ay = out_y + in_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
    d_corner = ax + ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
    return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
/* END */