misc/libfreetype/src/base/ftbbox.c
author unc0rr
Wed, 10 Oct 2012 00:40:00 +0400
changeset 7738 abcc7012de0b
parent 5172 88f2e05288ba
permissions -rw-r--r--
Please pas2c
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
/*  ftbbox.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
/*    FreeType bbox computation (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, 2004, 2006, 2010 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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* This component has a _single_ role: to compute exact outline bounding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /* boxes.                                                                */
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include FT_BBOX_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include FT_IMAGE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#include FT_INTERNAL_CALC_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#include FT_INTERNAL_OBJECTS_H
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
  typedef struct  TBBox_Rec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    FT_Vector  last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    FT_BBox    bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  } TBBox_Rec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*    BBox_Move_To                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*    This function is used as a `move_to' and `line_to' emitter during  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /*    FT_Outline_Decompose().  It simply records the destination point   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /*    in `user->last'; no further computations are necessary since we    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /*    use the cbox as the starting bbox which must be refined.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /*    to   :: A pointer to the destination vector.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /*    user :: A pointer to the current walk context.                     */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /*    Always 0.  Needed for the interface only.                          */
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
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  BBox_Move_To( FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
                TBBox_Rec*  user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    user->last = *to;
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
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
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
#define CHECK_X( p, bbox )  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
          ( p->x < bbox.xMin || p->x > bbox.xMax )
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
#define CHECK_Y( p, bbox )  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
          ( p->y < bbox.yMin || p->y > bbox.yMax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  /*    BBox_Conic_Check                                                   */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /*    Finds the extrema of a 1-dimensional conic Bezier curve and update */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
  /*    a bounding range.  This version uses direct computation, as it     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  /*    doesn't need square roots.                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  /*    y1  :: The start coordinate.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  /*    y2  :: The coordinate of the control point.                        */
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
  /*    y3  :: The end coordinate.                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  /*    min :: The address of the current minimum.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  /*    max :: The address of the current maximum.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  BBox_Conic_Check( FT_Pos   y1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
                    FT_Pos   y2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
                    FT_Pos   y3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
                    FT_Pos*  min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
                    FT_Pos*  max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    if ( y1 <= y3 && y2 == y1 )     /* flat arc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
      goto Suite;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    if ( y1 < y3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      if ( y2 >= y1 && y2 <= y3 )   /* ascending arc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
        goto Suite;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      if ( y2 >= y3 && y2 <= y1 )   /* descending arc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        y2 = y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        y1 = y3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
        y3 = y2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
        goto Suite;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    y1 = y3 = y1 - FT_MulDiv( y2 - y1, y2 - y1, y1 - 2*y2 + y3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  Suite:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    if ( y1 < *min ) *min = y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    if ( y3 > *max ) *max = y3;
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
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
  /*    BBox_Conic_To                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  /*    This function is used as a `conic_to' emitter during               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
  /*    FT_Outline_Decompose().  It checks a conic Bezier curve with the   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  /*    current bounding box, and computes its extrema if necessary to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  /*    update it.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  /*    control :: A pointer to a control point.                           */
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
  /*    to      :: A pointer to the destination vector.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
  /*    user    :: The address of the current walk context.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  /*    Always 0.  Needed for the interface only.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  /*    In the case of a non-monotonous arc, we compute directly the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  /*    extremum coordinates, as it is sufficiently fast.                  */
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
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  BBox_Conic_To( FT_Vector*  control,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
                 FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
                 TBBox_Rec*  user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    /* we don't need to check `to' since it is always an `on' point, thus */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    /* within the bbox                                                    */
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
    if ( CHECK_X( control, user->bbox ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      BBox_Conic_Check( user->last.x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
                        control->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
                        to->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
                        &user->bbox.xMin,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
                        &user->bbox.xMax );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    if ( CHECK_Y( control, user->bbox ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      BBox_Conic_Check( user->last.y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
                        control->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
                        to->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
                        &user->bbox.yMin,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
                        &user->bbox.yMax );
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
    user->last = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  }
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
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  /*    BBox_Cubic_Check                                                   */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
  /*    Finds the extrema of a 1-dimensional cubic Bezier curve and        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
  /*    updates a bounding range.  This version uses splitting because we  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
  /*    don't want to use square roots and extra accuracy.                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
  /*    p1  :: The start coordinate.                                       */
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
  /*    p2  :: The coordinate of the first control point.                  */
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
  /*    p3  :: The coordinate of the second control point.                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  /*    p4  :: The end coordinate.                                         */
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
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /*    min :: The address of the current minimum.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
  /*    max :: The address of the current maximum.                         */
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 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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
  BBox_Cubic_Check( FT_Pos   p1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
                    FT_Pos   p2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
                    FT_Pos   p3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
                    FT_Pos   p4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
                    FT_Pos*  min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
                    FT_Pos*  max )
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
    FT_Pos  stack[32*3 + 1], *arc;
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
    arc = stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    arc[0] = p1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    arc[1] = p2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    arc[2] = p3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    arc[3] = p4;
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
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      FT_Pos  y1 = arc[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      FT_Pos  y2 = arc[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      FT_Pos  y3 = arc[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      FT_Pos  y4 = arc[3];
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
      if ( y1 == y4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
        if ( y1 == y2 && y1 == y3 )                         /* flat */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
          goto Test;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
      else if ( y1 < y4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
        if ( y2 >= y1 && y2 <= y4 && y3 >= y1 && y3 <= y4 ) /* ascending */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
          goto Test;
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
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
        if ( y2 >= y4 && y2 <= y1 && y3 >= y4 && y3 <= y1 ) /* descending */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
          y2 = y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
          y1 = y4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
          y4 = y2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
          goto Test;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
        }
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
      /* unknown direction -- split the arc in two */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
      arc[6] = y4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
      arc[1] = y1 = ( y1 + y2 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      arc[5] = y4 = ( y4 + y3 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
      y2 = ( y2 + y3 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      arc[2] = y1 = ( y1 + y2 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      arc[4] = y4 = ( y4 + y2 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      arc[3] = ( y1 + y4 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      arc += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      goto Suite;
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
   Test:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
      if ( y1 < *min ) *min = y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      if ( y4 > *max ) *max = y4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      arc -= 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    Suite:
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
    } while ( arc >= stack );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  }
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
#else
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 void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
  test_cubic_extrema( FT_Pos    y1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
                      FT_Pos    y2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
                      FT_Pos    y3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
                      FT_Pos    y4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
                      FT_Fixed  u,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
                      FT_Pos*   min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                      FT_Pos*   max )
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
 /* FT_Pos    a = y4 - 3*y3 + 3*y2 - y1; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    FT_Pos    b = y3 - 2*y2 + y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    FT_Pos    c = y2 - y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    FT_Pos    d = y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    FT_Pos    y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    FT_Fixed  uu;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    FT_UNUSED ( y4 );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    /* The polynomial is                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
    /*                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
    /*    P(x) = a*x^3 + 3b*x^2 + 3c*x + d  , */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    /*                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    /*   dP/dx = 3a*x^2 + 6b*x + 3c         . */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    /*                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    /* However, we also have                  */
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
    /*   dP/dx(u) = 0                       , */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    /*                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    /* which implies by subtraction that      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    /*                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    /*   P(u) = b*u^2 + 2c*u + d            . */
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
    if ( u > 0 && u < 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
      uu = FT_MulFix( u, u );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
      y  = d + FT_MulFix( c, 2*u ) + FT_MulFix( b, uu );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
      if ( y < *min ) *min = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      if ( y > *max ) *max = y;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  BBox_Cubic_Check( FT_Pos   y1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
                    FT_Pos   y2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
                    FT_Pos   y3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
                    FT_Pos   y4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
                    FT_Pos*  min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
                    FT_Pos*  max )
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
    /* always compare first and last points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    if      ( y1 < *min )  *min = y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    else if ( y1 > *max )  *max = y1;
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
    if      ( y4 < *min )  *min = y4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    else if ( y4 > *max )  *max = y4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    /* now, try to see if there are split points here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    if ( y1 <= y4 )
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
      /* flat or ascending arc test */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
      if ( y1 <= y2 && y2 <= y4 && y1 <= y3 && y3 <= y4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
        return;
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
    else /* y1 > y4 */
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
      /* descending arc test */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
      if ( y1 >= y2 && y2 >= y4 && y1 >= y3 && y3 >= y4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    /* There are some split points.  Find them. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
      FT_Pos    a = y4 - 3*y3 + 3*y2 - y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      FT_Pos    b = y3 - 2*y2 + y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
      FT_Pos    c = y2 - y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
      FT_Pos    d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      FT_Fixed  t;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
      /* We need to solve `ax^2+2bx+c' here, without floating points!      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
      /* The trick is to normalize to a different representation in order  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      /* to use our 16.16 fixed point routines.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
      /* We compute FT_MulFix(b,b) and FT_MulFix(a,c) after normalization. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      /* These values must fit into a single 16.16 value.                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
      /* We normalize a, b, and c to `8.16' fixed float values to ensure   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
      /* that its product is held in a `16.16' value.                      */
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_ULong  t1, t2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
        int       shift = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
        /* The following computation is based on the fact that for   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        /* any value `y', if `n' is the position of the most         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
        /* significant bit of `abs(y)' (starting from 0 for the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
        /* least significant bit), then `y' is in the range          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
        /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
        /*   -2^n..2^n-1                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
        /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
        /* We want to shift `a', `b', and `c' concurrently in order  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
        /* to ensure that they all fit in 8.16 values, which maps    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
        /* to the integer range `-2^23..2^23-1'.                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
        /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
        /* Necessarily, we need to shift `a', `b', and `c' so that   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
        /* the most significant bit of its absolute values is at     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
        /* _most_ at position 23.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
        /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
        /* We begin by computing `t1' as the bitwise `OR' of the     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
        /* absolute values of `a', `b', `c'.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
        t1  = (FT_ULong)( ( a >= 0 ) ? a : -a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
        t2  = (FT_ULong)( ( b >= 0 ) ? b : -b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
        t1 |= t2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
        t2  = (FT_ULong)( ( c >= 0 ) ? c : -c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
        t1 |= t2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        /* Now we can be sure that the most significant bit of `t1'  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
        /* is the most significant bit of either `a', `b', or `c',   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
        /* depending on the greatest integer range of the particular */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
        /* variable.                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
        /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
        /* Next, we compute the `shift', by shifting `t1' as many    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
        /* times as necessary to move its MSB to position 23.  This  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
        /* corresponds to a value of `t1' that is in the range       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
        /* 0x40_0000..0x7F_FFFF.                                     */
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
        /* Finally, we shift `a', `b', and `c' by the same amount.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
        /* This ensures that all values are now in the range         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
        /* -2^23..2^23, i.e., they are now expressed as 8.16         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
        /* fixed-float numbers.  This also means that we are using   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
        /* 24 bits of precision to compute the zeros, independently  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
        /* of the range of the original polynomial coefficients.     */
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
        /* This algorithm should ensure reasonably accurate values   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
        /* for the zeros.  Note that they are only expressed with    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
        /* 16 bits when computing the extrema (the zeros need to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
        /* be in 0..1 exclusive to be considered part of the arc).   */
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
        if ( t1 == 0 )  /* all coefficients are 0! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
          return;
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
        if ( t1 > 0x7FFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
          do
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
            shift++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
            t1 >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
          } while ( t1 > 0x7FFFFFUL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
          /* this loses some bits of precision, but we use 24 of them */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
          /* for the computation anyway                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
          a >>= shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
          b >>= shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
          c >>= shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
        else if ( t1 < 0x400000UL )
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
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
            shift++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
            t1 <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
          } while ( t1 < 0x400000UL );
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
          a <<= shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
          b <<= shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
          c <<= shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      }
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
      /* handle a == 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
      if ( a == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
        if ( b != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
          t = - FT_DivFix( c, b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
          test_cubic_extrema( y1, y2, y3, y4, t, min, max );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
        /* solve the equation now */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
        d = FT_MulFix( b, b ) - FT_MulFix( a, c );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
        if ( d < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
          return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
        if ( d == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
          /* there is a single split point at -b/a */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
          t = - FT_DivFix( b, a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
          test_cubic_extrema( y1, y2, y3, y4, t, min, max );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
        }
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
          /* there are two solutions; we need to filter them */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
          d = FT_SqrtFixed( (FT_Int32)d );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
          t = - FT_DivFix( b - d, a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
          test_cubic_extrema( y1, y2, y3, y4, t, min, max );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
          t = - FT_DivFix( b + d, a );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
          test_cubic_extrema( y1, y2, y3, y4, t, min, max );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      }
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
  }
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
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
  /*    BBox_Cubic_To                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
  /*    This function is used as a `cubic_to' emitter during               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
  /*    FT_Outline_Decompose().  It checks a cubic Bezier curve with the   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
  /*    current bounding box, and computes its extrema if necessary to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
  /*    update it.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  /*    control1 :: A pointer to the first control point.                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
  /*    control2 :: A pointer to the second control point.                 */
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
  /*    to       :: A pointer to the destination vector.                   */
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
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
  /*    user     :: The address of the current walk context.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
  /*    Always 0.  Needed for the interface only.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
  /*    In the case of a non-monotonous arc, we don't compute directly     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
  /*    extremum coordinates, we subdivide instead.                        */
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
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
  BBox_Cubic_To( FT_Vector*  control1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
                 FT_Vector*  control2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
                 FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
                 TBBox_Rec*  user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    /* we don't need to check `to' since it is always an `on' point, thus */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    /* within the bbox                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    if ( CHECK_X( control1, user->bbox ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
         CHECK_X( control2, user->bbox ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      BBox_Cubic_Check( user->last.x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
                        control1->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
                        control2->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
                        to->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
                        &user->bbox.xMin,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
                        &user->bbox.xMax );
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
    if ( CHECK_Y( control1, user->bbox ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
         CHECK_Y( control2, user->bbox ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      BBox_Cubic_Check( user->last.y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
                        control1->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
                        control2->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
                        to->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
                        &user->bbox.yMin,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
                        &user->bbox.yMax );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    user->last = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    return 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
FT_DEFINE_OUTLINE_FUNCS(bbox_interface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
    (FT_Outline_MoveTo_Func) BBox_Move_To,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
    (FT_Outline_LineTo_Func) BBox_Move_To,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
    (FT_Outline_ConicTo_Func)BBox_Conic_To,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    (FT_Outline_CubicTo_Func)BBox_Cubic_To,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    0, 0
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
  /* documentation is in ftbbox.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
  FT_Outline_Get_BBox( FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
                       FT_BBox     *abbox )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    FT_BBox     cbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
    FT_BBox     bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    FT_Vector*  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
    FT_UShort   n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
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
    if ( !abbox )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
      return FT_Err_Invalid_Argument;
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
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
      return FT_Err_Invalid_Outline;
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
    /* if outline is empty, return (0,0,0,0) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
    if ( outline->n_points == 0 || outline->n_contours <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      abbox->xMin = abbox->xMax = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      abbox->yMin = abbox->yMax = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
      return 0;
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
    /* We compute the control box as well as the bounding box of  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    /* all `on' points in the outline.  Then, if the two boxes    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    /* coincide, we exit immediately.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
    vec = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
    bbox.xMin = bbox.xMax = cbox.xMin = cbox.xMax = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    bbox.yMin = bbox.yMax = cbox.yMin = cbox.yMax = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
    vec++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    for ( n = 1; n < outline->n_points; n++ )
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_Pos  x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
      FT_Pos  y = vec->y;
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
      /* update control box */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      if ( x < cbox.xMin ) cbox.xMin = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
      if ( x > cbox.xMax ) cbox.xMax = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
      if ( y < cbox.yMin ) cbox.yMin = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      if ( y > cbox.yMax ) cbox.yMax = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      if ( FT_CURVE_TAG( outline->tags[n] ) == FT_CURVE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
        /* update bbox for `on' points only */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        if ( x < bbox.xMin ) bbox.xMin = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
        if ( x > bbox.xMax ) bbox.xMax = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        if ( y < bbox.yMin ) bbox.yMin = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
        if ( y > bbox.yMax ) bbox.yMax = y;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
      vec++;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    /* test two boxes for equality */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    if ( cbox.xMin < bbox.xMin || cbox.xMax > bbox.xMax ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
         cbox.yMin < bbox.yMin || cbox.yMax > bbox.yMax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
      /* the two boxes are different, now walk over the outline to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
      /* get the Bezier arc extrema.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
      FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      TBBox_Rec  user;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
      FT_Outline_Funcs bbox_interface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      Init_Class_bbox_interface(&bbox_interface);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
#endif
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
      user.bbox = bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      error = FT_Outline_Decompose( outline, &bbox_interface, &user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        return error;
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
      *abbox = user.bbox;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
      *abbox = bbox;
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
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
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
/* END */