misc/libfreetype/src/base/ftstroke.c
author Leonard
Sat, 03 Dec 2011 15:15:14 +0100
changeset 6482 07eeb905620e
parent 5172 88f2e05288ba
permissions -rw-r--r--
GCI task: iOS German
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
/*  ftstroke.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 path stroker (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 2002-2006, 2008-2011 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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_STROKER_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_TRIGONOMETRY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_MEMORY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_INTERNAL_OBJECTS_H
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  FT_EXPORT_DEF( FT_StrokerBorder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  FT_Outline_GetInsideBorder( FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    FT_Orientation  o = FT_Outline_Get_Orientation( outline );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
    return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_RIGHT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
                                        : FT_STROKER_BORDER_LEFT ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /* documentation is in ftstroke.h */
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
  FT_EXPORT_DEF( FT_StrokerBorder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  FT_Outline_GetOutsideBorder( FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_Orientation  o = FT_Outline_Get_Orientation( outline );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_LEFT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
                                        : FT_STROKER_BORDER_RIGHT ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
 /***************************************************************************/
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
 /*****                       BEZIER COMPUTATIONS                       *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
 /*****                                                                 *****/
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
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
#define FT_SMALL_CONIC_THRESHOLD  ( FT_ANGLE_PI / 6 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
#define FT_SMALL_CUBIC_THRESHOLD  ( FT_ANGLE_PI / 6 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
#define FT_EPSILON  2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
#define FT_IS_SMALL( x )  ( (x) > -FT_EPSILON && (x) < FT_EPSILON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  static FT_Pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  ft_pos_abs( FT_Pos  x )
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
    return x >= 0 ? x : -x ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  ft_conic_split( FT_Vector*  base )
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
    FT_Pos  a, b;
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
    base[4].x = base[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    b = base[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    a = base[3].x = ( base[2].x + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    b = base[1].x = ( base[0].x + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    base[2].x = ( a + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    base[4].y = base[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    b = base[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    a = base[3].y = ( base[2].y + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    b = base[1].y = ( base[0].y + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    base[2].y = ( a + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  ft_conic_is_small_enough( FT_Vector*  base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
                            FT_Angle   *angle_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
                            FT_Angle   *angle_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    FT_Vector  d1, d2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    FT_Angle   theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_Int     close1, close2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    d1.x = base[1].x - base[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    d1.y = base[1].y - base[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    d2.x = base[0].x - base[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    d2.y = base[0].y - base[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
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 ( close1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
      if ( close2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
        *angle_in = *angle_out = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
        *angle_in = *angle_out = FT_Atan2( d2.x, d2.y );
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
    else if ( close2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      *angle_in = *angle_out = FT_Atan2( d1.x, d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    else
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
      *angle_in  = FT_Atan2( d1.x, d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      *angle_out = FT_Atan2( d2.x, d2.y );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    theta = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_out ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    return FT_BOOL( theta < FT_SMALL_CONIC_THRESHOLD );
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
  ft_cubic_split( FT_Vector*  base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    FT_Pos  a, b, c, d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    base[6].x = base[3].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    c = base[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    d = base[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    base[1].x = a = ( base[0].x + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    base[5].x = b = ( base[3].x + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    c = ( c + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    base[2].x = a = ( a + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    base[4].x = b = ( b + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    base[3].x = ( a + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    base[6].y = base[3].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    c = base[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    d = base[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    base[1].y = a = ( base[0].y + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    base[5].y = b = ( base[3].y + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    c = ( c + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    base[2].y = a = ( a + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    base[4].y = b = ( b + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    base[3].y = ( a + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  ft_cubic_is_small_enough( FT_Vector*  base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
                            FT_Angle   *angle_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
                            FT_Angle   *angle_mid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
                            FT_Angle   *angle_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    FT_Vector  d1, d2, d3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    FT_Angle   theta1, theta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    FT_Int     close1, close2, close3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    d1.x = base[2].x - base[3].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    d1.y = base[2].y - base[3].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    d2.x = base[1].x - base[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    d2.y = base[1].y - base[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    d3.x = base[0].x - base[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    d3.y = base[0].y - base[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    close3 = FT_IS_SMALL( d3.x ) && FT_IS_SMALL( d3.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    if ( close1 || close3 )
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
      if ( close2 )
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
        /* basically a point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
        *angle_in = *angle_out = *angle_mid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      else if ( close1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
        *angle_in  = *angle_mid = FT_Atan2( d2.x, d2.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
        *angle_out = FT_Atan2( d3.x, d3.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      else  /* close2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
        *angle_in  = FT_Atan2( d1.x, d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        *angle_mid = *angle_out = FT_Atan2( d2.x, d2.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      }
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
    else if ( close2 )
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
      *angle_in  = *angle_mid = FT_Atan2( d1.x, d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
      *angle_out = FT_Atan2( d3.x, d3.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    else
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
      *angle_in  = FT_Atan2( d1.x, d1.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      *angle_mid = FT_Atan2( d2.x, d2.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      *angle_out = FT_Atan2( d3.x, d3.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    }
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
    theta1 = ft_pos_abs( FT_Angle_Diff( *angle_in,  *angle_mid ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    theta2 = ft_pos_abs( FT_Angle_Diff( *angle_mid, *angle_out ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    return FT_BOOL( theta1 < FT_SMALL_CUBIC_THRESHOLD &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
                    theta2 < FT_SMALL_CUBIC_THRESHOLD );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
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
 /***************************************************************************/
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
 /*****                       STROKE BORDERS                            *****/
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
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  typedef enum  FT_StrokeTags_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    FT_STROKE_TAG_ON    = 1,   /* on-curve point  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    FT_STROKE_TAG_CUBIC = 2,   /* cubic off-point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    FT_STROKE_TAG_BEGIN = 4,   /* sub-path start  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    FT_STROKE_TAG_END   = 8    /* sub-path end    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  } FT_StrokeTags;
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
#define  FT_STROKE_TAG_BEGIN_END  (FT_STROKE_TAG_BEGIN|FT_STROKE_TAG_END)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  typedef struct  FT_StrokeBorderRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
    FT_UInt     num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    FT_UInt     max_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    FT_Vector*  points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    FT_Byte*    tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    FT_Bool     movable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    FT_Int      start;    /* index of current sub-path start point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    FT_Memory   memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    FT_Bool     valid;
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
  } FT_StrokeBorderRec, *FT_StrokeBorder;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
  ft_stroke_border_grow( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
                         FT_UInt          new_points )
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
    FT_UInt   old_max = border->max_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    FT_UInt   new_max = border->num_points + new_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    FT_Error  error   = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    if ( new_max > old_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      FT_UInt    cur_max = old_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      FT_Memory  memory  = border->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      while ( cur_max < new_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
        cur_max += ( cur_max >> 1 ) + 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
      if ( FT_RENEW_ARRAY( border->points, old_max, cur_max ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
           FT_RENEW_ARRAY( border->tags,   old_max, cur_max ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
      border->max_points = cur_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
  ft_stroke_border_close( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
                          FT_Bool          reverse )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    FT_UInt  start = border->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    FT_UInt  count = border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    FT_ASSERT( border->start >= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    /* don't record empty paths! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    if ( count <= start + 1U )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
      border->num_points = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
      /* copy the last point to the start of this sub-path, since */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      /* it contains the `adjusted' starting coordinates          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      border->num_points    = --count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      border->points[start] = border->points[count];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      if ( reverse )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
        /* reverse the points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
          FT_Vector*  vec1 = border->points + start + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
          FT_Vector*  vec2 = border->points + count - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
          for ( ; vec1 < vec2; vec1++, vec2-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
            FT_Vector  tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
            tmp   = *vec1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
            *vec1 = *vec2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
            *vec2 = tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
          }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
        /* then the tags */
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
          FT_Byte*  tag1 = border->tags + start + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
          FT_Byte*  tag2 = border->tags + count - 1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
          for ( ; tag1 < tag2; tag1++, tag2-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
            FT_Byte  tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
            tmp   = *tag1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
            *tag1 = *tag2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
            *tag2 = tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
        }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      border->tags[start    ] |= FT_STROKE_TAG_BEGIN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
      border->tags[count - 1] |= FT_STROKE_TAG_END;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    border->start   = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    border->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  ft_stroke_border_lineto( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
                           FT_Vector*       to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
                           FT_Bool          movable )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    FT_Error  error = FT_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    FT_ASSERT( border->start >= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    if ( border->movable )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
      /* move last point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      border->points[border->num_points - 1] = *to;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
      /* add one point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      error = ft_stroke_border_grow( border, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
        FT_Vector*  vec = border->points + border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
        FT_Byte*    tag = border->tags   + border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
        vec[0] = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
        tag[0] = FT_STROKE_TAG_ON;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
        border->num_points += 1;
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
    border->movable = movable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
  ft_stroke_border_conicto( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
                            FT_Vector*       control,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
                            FT_Vector*       to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
    FT_ASSERT( border->start >= 0 );
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
    error = ft_stroke_border_grow( border, 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    if ( !error )
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
      FT_Vector*  vec = border->points + border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      FT_Byte*    tag = border->tags   + border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
      vec[0] = *control;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
      vec[1] = *to;
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
      tag[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
      tag[1] = FT_STROKE_TAG_ON;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
      border->num_points += 2;
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
    border->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
  ft_stroke_border_cubicto( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
                            FT_Vector*       control1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
                            FT_Vector*       control2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
                            FT_Vector*       to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    FT_ASSERT( border->start >= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    error = ft_stroke_border_grow( border, 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      FT_Vector*  vec = border->points + border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      FT_Byte*    tag = border->tags   + border->num_points;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      vec[0] = *control1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      vec[1] = *control2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      vec[2] = *to;
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
      tag[0] = FT_STROKE_TAG_CUBIC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      tag[1] = FT_STROKE_TAG_CUBIC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
      tag[2] = FT_STROKE_TAG_ON;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
      border->num_points += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
    border->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
#define FT_ARC_CUBIC_ANGLE  ( FT_ANGLE_PI / 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
  ft_stroke_border_arcto( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
                          FT_Vector*       center,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
                          FT_Fixed         radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
                          FT_Angle         angle_start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
                          FT_Angle         angle_diff )
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
    FT_Angle   total, angle, step, rotate, next, theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
    FT_Vector  a, b, a2, b2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    FT_Fixed   length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    FT_Error   error = FT_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    /* compute start point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    FT_Vector_From_Polar( &a, radius, angle_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    a.x += center->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    a.y += center->y;
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
    total  = angle_diff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    angle  = angle_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
    rotate = ( angle_diff >= 0 ) ? FT_ANGLE_PI2 : -FT_ANGLE_PI2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    while ( total != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
      step = total;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      if ( step > FT_ARC_CUBIC_ANGLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        step = FT_ARC_CUBIC_ANGLE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
      else if ( step < -FT_ARC_CUBIC_ANGLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
        step = -FT_ARC_CUBIC_ANGLE;
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
      next  = angle + step;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      theta = step;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      if ( theta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
        theta = -theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      theta >>= 1;
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
      /* compute end point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
      FT_Vector_From_Polar( &b, radius, next );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
      b.x += center->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      b.y += center->y;
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
      /* compute first and second control points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
      length = FT_MulDiv( radius, FT_Sin( theta ) * 4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
                          ( 0x10000L + FT_Cos( theta ) ) * 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
      FT_Vector_From_Polar( &a2, length, angle + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
      a2.x += a.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
      a2.y += a.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
      FT_Vector_From_Polar( &b2, length, next - rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      b2.x += b.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      b2.y += b.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
      /* add cubic arc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
      error = ft_stroke_border_cubicto( border, &a2, &b2, &b );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
      /* process the rest of the arc ?? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      a      = b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
      total -= step;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
      angle  = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    }
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
  ft_stroke_border_moveto( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
                           FT_Vector*       to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    /* close current open path if any ? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    if ( border->start >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      ft_stroke_border_close( border, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
    border->start   = border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    border->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    return ft_stroke_border_lineto( border, to, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
  ft_stroke_border_init( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
                         FT_Memory        memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    border->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    border->points = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    border->tags   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
    border->num_points = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
    border->max_points = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
    border->start      = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
    border->valid      = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
  ft_stroke_border_reset( FT_StrokeBorder  border )
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
    border->num_points = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    border->start      = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    border->valid      = FALSE;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
  ft_stroke_border_done( FT_StrokeBorder  border )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    FT_Memory  memory = border->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    FT_FREE( border->points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    FT_FREE( border->tags );
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
    border->num_points = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
    border->max_points = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
    border->start      = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    border->valid      = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
  ft_stroke_border_get_counts( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
                               FT_UInt         *anum_points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
                               FT_UInt         *anum_contours )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    FT_Error  error        = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    FT_UInt   num_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    FT_UInt   num_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    FT_UInt     count      = border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
    FT_Vector*  point      = border->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    FT_Byte*    tags       = border->tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    FT_Int      in_contour = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    for ( ; count > 0; count--, num_points++, point++, tags++ )
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
      if ( tags[0] & FT_STROKE_TAG_BEGIN )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
        if ( in_contour != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
        in_contour = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
      else if ( in_contour == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      if ( tags[0] & FT_STROKE_TAG_END )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
        in_contour = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
        num_contours++;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
    if ( in_contour != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
    border->valid = TRUE;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    *anum_points   = num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    *anum_contours = num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
    num_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    num_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
    goto Exit;
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
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
  ft_stroke_border_export( FT_StrokeBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
                           FT_Outline*      outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    /* copy point locations */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    FT_ARRAY_COPY( outline->points + outline->n_points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
                   border->points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
                   border->num_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    /* copy tags */
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
      FT_UInt   count = border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
      FT_Byte*  read  = border->tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      FT_Byte*  write = (FT_Byte*)outline->tags + outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
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
      for ( ; count > 0; count--, read++, write++ )
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
        if ( *read & FT_STROKE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
          *write = FT_CURVE_TAG_ON;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        else if ( *read & FT_STROKE_TAG_CUBIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
          *write = FT_CURVE_TAG_CUBIC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
          *write = FT_CURVE_TAG_CONIC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
    }
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
    /* copy contours */
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
      FT_UInt    count = border->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
      FT_Byte*   tags  = border->tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
      FT_Short*  write = outline->contours + outline->n_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      FT_Short   idx   = (FT_Short)outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
      for ( ; count > 0; count--, tags++, idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
        if ( *tags & FT_STROKE_TAG_END )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
          *write++ = idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
          outline->n_contours++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    outline->n_points  = (short)( outline->n_points + border->num_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    FT_ASSERT( FT_Outline_Check( outline ) == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
 /*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
 /*****                           STROKER                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
 /*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
 /***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
#define FT_SIDE_TO_ROTATE( s )   ( FT_ANGLE_PI2 - (s) * FT_ANGLE_PI )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
  typedef struct  FT_StrokerRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
    FT_Angle             angle_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
    FT_Angle             angle_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
    FT_Vector            center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
    FT_Bool              first_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    FT_Bool              subpath_open;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    FT_Angle             subpath_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    FT_Vector            subpath_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    FT_Stroker_LineCap   line_cap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    FT_Stroker_LineJoin  line_join;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    FT_Fixed             miter_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    FT_Fixed             radius;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    FT_StrokeBorderRec   borders[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    FT_Library           library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
  } FT_StrokerRec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
  FT_Stroker_New( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
                  FT_Stroker  *astroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    FT_Memory   memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    FT_Stroker  stroker;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
    if ( !FT_NEW( stroker ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      stroker->library = library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
      ft_stroke_border_init( &stroker->borders[0], memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
      ft_stroke_border_init( &stroker->borders[1], memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    *astroker = stroker;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
  FT_Stroker_Set( FT_Stroker           stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
                  FT_Fixed             radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
                  FT_Stroker_LineCap   line_cap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
                  FT_Stroker_LineJoin  line_join,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
                  FT_Fixed             miter_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
    stroker->radius      = radius;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
    stroker->line_cap    = line_cap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
    stroker->line_join   = line_join;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
    stroker->miter_limit = miter_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
    FT_Stroker_Rewind( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
  FT_Stroker_Rewind( FT_Stroker  stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
    if ( stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
      ft_stroke_border_reset( &stroker->borders[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
      ft_stroke_border_reset( &stroker->borders[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
  FT_Stroker_Done( FT_Stroker  stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
    if ( stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
      FT_Memory  memory = stroker->library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
      ft_stroke_border_done( &stroker->borders[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
      ft_stroke_border_done( &stroker->borders[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
      stroker->library = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
      FT_FREE( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
  /* creates a circular arc at a corner or cap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
  ft_stroker_arcto( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
                    FT_Int      side )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
    FT_Angle         total, rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
    FT_Fixed         radius = stroker->radius;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    FT_Error         error  = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
    FT_StrokeBorder  border = stroker->borders + side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
    total = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
    if ( total == FT_ANGLE_PI )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
      total = -rotate * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    error = ft_stroke_border_arcto( border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
                                    &stroker->center,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
                                    radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
                                    stroker->angle_in + rotate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
                                    total );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
    border->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
  /* adds a cap at the end of an opened path */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
  ft_stroker_cap( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
                  FT_Angle    angle,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
                  FT_Int      side )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
    if ( stroker->line_cap == FT_STROKER_LINECAP_ROUND )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
      /* add a round cap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
      stroker->angle_in  = angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      stroker->angle_out = angle + FT_ANGLE_PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
      error = ft_stroker_arcto( stroker, side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
    else if ( stroker->line_cap == FT_STROKER_LINECAP_SQUARE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
      /* add a square cap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
      FT_Vector        delta, delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      FT_Angle         rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
      FT_Fixed         radius = stroker->radius;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
      FT_StrokeBorder  border = stroker->borders + side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
      FT_Vector_From_Polar( &delta2, radius, angle + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
      FT_Vector_From_Polar( &delta,  radius, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
      delta.x += stroker->center.x + delta2.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
      delta.y += stroker->center.y + delta2.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
      error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
      FT_Vector_From_Polar( &delta2, radius, angle - rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
      FT_Vector_From_Polar( &delta,  radius, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
      delta.x += delta2.x + stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
      delta.y += delta2.y + stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
      error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
    else if ( stroker->line_cap == FT_STROKER_LINECAP_BUTT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
      /* add a butt ending */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      FT_Vector        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
      FT_Angle         rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
      FT_Fixed         radius = stroker->radius;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
      FT_StrokeBorder  border = stroker->borders + side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
      FT_Vector_From_Polar( &delta, radius, angle + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
      delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
      error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
      FT_Vector_From_Polar( &delta, radius, angle - rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
      delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
      delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      error = ft_stroke_border_lineto( border, &delta, FALSE );   
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
  /* process an inside corner, i.e. compute intersection */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
  ft_stroker_inside( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
                     FT_Int      side)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
    FT_StrokeBorder  border = stroker->borders + side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
    FT_Angle         phi, theta, rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
    FT_Fixed         length, thcos, sigma;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
    FT_Vector        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
    FT_Error         error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
    rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
    /* compute median angle */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
    theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
    if ( theta == FT_ANGLE_PI )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
      theta = rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
      theta = theta / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
    phi = stroker->angle_in + theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
    thcos = FT_Cos( theta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    sigma = FT_MulFix( stroker->miter_limit, thcos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
    /* TODO: find better criterion to switch off the optimization */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    if ( sigma < 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
      FT_Vector_From_Polar( &delta, stroker->radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
                            stroker->angle_out + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
      delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
      delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
      border->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
      length = FT_DivFix( stroker->radius, thcos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
      FT_Vector_From_Polar( &delta, length, phi + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
      delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
      delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
  /* process an outside corner, i.e. compute bevel/miter/round */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
  ft_stroker_outside( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
                      FT_Int      side )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
    FT_StrokeBorder  border = stroker->borders + side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
    FT_Angle         rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    if ( stroker->line_join == FT_STROKER_LINEJOIN_ROUND )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
      error = ft_stroker_arcto( stroker, side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
      /* this is a mitered or beveled corner */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
      FT_Fixed  sigma, radius = stroker->radius;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
      FT_Angle  theta, phi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
      FT_Fixed  thcos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
      FT_Bool   miter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
      rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
      miter  = FT_BOOL( stroker->line_join == FT_STROKER_LINEJOIN_MITER );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
      theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
      if ( theta == FT_ANGLE_PI )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
        theta = rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
        phi   = stroker->angle_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
        theta = theta / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
        phi   = stroker->angle_in + theta + rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
      thcos = FT_Cos( theta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
      sigma = FT_MulFix( stroker->miter_limit, thcos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
      /* FT_Sin(x) = 0 for x <= 57 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
      if ( sigma >= 0x10000L || ft_pos_abs( theta ) <= 57 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
        miter = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
      if ( miter )  /* this is a miter (broken angle) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
        FT_Vector  middle, delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
        FT_Fixed   length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
        /* compute middle point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
        FT_Vector_From_Polar( &middle,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
                              FT_MulFix( radius, stroker->miter_limit ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
                              phi );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
        middle.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
        middle.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
        /* compute first angle point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
        length = FT_MulFix( radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
                            FT_DivFix( 0x10000L - sigma,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
                                       ft_pos_abs( FT_Sin( theta ) ) ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
        FT_Vector_From_Polar( &delta, length, phi + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
        delta.x += middle.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
        delta.y += middle.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
        error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
        /* compute second angle point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
        FT_Vector_From_Polar( &delta, length, phi - rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
        delta.x += middle.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
        delta.y += middle.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
        error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
        /* finally, add a movable end point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
        FT_Vector_From_Polar( &delta, radius, stroker->angle_out + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
        delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
        delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
        error = ft_stroke_border_lineto( border, &delta, TRUE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
      else /* this is a bevel (intersection) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
        FT_Fixed   length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
        FT_Vector  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
        length = FT_DivFix( stroker->radius, thcos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
        FT_Vector_From_Polar( &delta, length, phi );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
        delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
        delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
        error = ft_stroke_border_lineto( border, &delta, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
        /* now add end point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
        FT_Vector_From_Polar( &delta, stroker->radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
                              stroker->angle_out + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
        delta.x += stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
        delta.y += stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
        error = ft_stroke_border_lineto( border, &delta, TRUE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
  ft_stroker_process_corner( FT_Stroker  stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
    FT_Angle  turn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
    FT_Int    inside_side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
    turn = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
    /* no specific corner processing is required if the turn is 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
    if ( turn == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
    /* when we turn to the right, the inside side is 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
    inside_side = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
    /* otherwise, the inside side is 1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
    if ( turn < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
      inside_side = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
    /* process the inside side */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
    error = ft_stroker_inside( stroker, inside_side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
    /* process the outside side */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
    error = ft_stroker_outside( stroker, 1 - inside_side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
  /* add two points to the left and right borders corresponding to the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
  /* start of the subpath                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
  ft_stroker_subpath_start( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
                            FT_Angle    start_angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
    FT_Vector        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
    FT_Vector        point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
    FT_StrokeBorder  border;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
    FT_Vector_From_Polar( &delta, stroker->radius,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
                          start_angle + FT_ANGLE_PI2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
    point.x = stroker->center.x + delta.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
    point.y = stroker->center.y + delta.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
    border = stroker->borders;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
    error = ft_stroke_border_moveto( border, &point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
    point.x = stroker->center.x - delta.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
    point.y = stroker->center.y - delta.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
    border++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
    error = ft_stroke_border_moveto( border, &point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
    /* save angle for last cap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
    stroker->subpath_angle = start_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
    stroker->first_point   = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
  FT_Stroker_LineTo( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
                     FT_Vector*  to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
    FT_Error         error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
    FT_StrokeBorder  border;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
    FT_Vector        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
    FT_Angle         angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
    FT_Int           side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
    delta.x = to->x - stroker->center.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
    delta.y = to->y - stroker->center.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
    angle = FT_Atan2( delta.x, delta.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    FT_Vector_From_Polar( &delta, stroker->radius, angle + FT_ANGLE_PI2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
    /* process corner if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
    if ( stroker->first_point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
      /* This is the first segment of a subpath.  We need to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
      /* add a point to each border at their respective starting */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
      /* point locations.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
      error = ft_stroker_subpath_start( stroker, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
      /* process the current corner */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
      stroker->angle_out = angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
      error = ft_stroker_process_corner( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
    /* now add a line segment to both the `inside' and `outside' paths */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
    for ( border = stroker->borders, side = 1; side >= 0; side--, border++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
      FT_Vector  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
      point.x = to->x + delta.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      point.y = to->y + delta.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
      error = ft_stroke_border_lineto( border, &point, TRUE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
      delta.x = -delta.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
      delta.y = -delta.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
    stroker->angle_in = angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
    stroker->center   = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
  FT_Stroker_ConicTo( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
                      FT_Vector*  control,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
                      FT_Vector*  to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
    FT_Error    error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
    FT_Vector   bez_stack[34];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
    FT_Vector*  arc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
    FT_Vector*  limit = bez_stack + 30;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
    FT_Angle    start_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
    FT_Bool     first_arc = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
    arc    = bez_stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
    arc[0] = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
    arc[1] = *control;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
    arc[2] = stroker->center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
    while ( arc >= bez_stack )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
      FT_Angle  angle_in, angle_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
      angle_in = angle_out = 0;  /* remove compiler warnings */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
      if ( arc < limit                                             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
           !ft_conic_is_small_enough( arc, &angle_in, &angle_out ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
        ft_conic_split( arc );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
        arc += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
      if ( first_arc )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
        first_arc = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
        start_angle = angle_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
        /* process corner if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
        if ( stroker->first_point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
          error = ft_stroker_subpath_start( stroker, start_angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
          stroker->angle_out = start_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
          error = ft_stroker_process_corner( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
      /* the arc's angle is small enough; we can add it directly to each */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
      /* border                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
        FT_Vector  ctrl, end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
        FT_Angle   theta, phi, rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
        FT_Fixed   length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
        FT_Int     side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
        theta  = FT_Angle_Diff( angle_in, angle_out ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
        phi    = angle_in + theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
        length = FT_DivFix( stroker->radius, FT_Cos( theta ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
        for ( side = 0; side <= 1; side++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
          rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
          /* compute control point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
          FT_Vector_From_Polar( &ctrl, length, phi + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
          ctrl.x += arc[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
          ctrl.y += arc[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
          /* compute end point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
          FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
          end.x += arc[0].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
          end.y += arc[0].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
          error = ft_stroke_border_conicto( stroker->borders + side,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
                                            &ctrl, &end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
      arc -= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
      if ( arc < bez_stack )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
        stroker->angle_in = angle_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
    stroker->center = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
  FT_Stroker_CubicTo( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
                      FT_Vector*  control1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
                      FT_Vector*  control2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
                      FT_Vector*  to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
    FT_Error    error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
    FT_Vector   bez_stack[37];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
    FT_Vector*  arc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
    FT_Vector*  limit = bez_stack + 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
    FT_Angle    start_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
    FT_Bool     first_arc = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
    arc    = bez_stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
    arc[0] = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
    arc[1] = *control2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
    arc[2] = *control1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
    arc[3] = stroker->center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
    while ( arc >= bez_stack )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
      FT_Angle  angle_in, angle_mid, angle_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
      /* remove compiler warnings */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
      angle_in = angle_out = angle_mid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
      if ( arc < limit                                         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
           !ft_cubic_is_small_enough( arc, &angle_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
                                      &angle_mid, &angle_out ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
        ft_cubic_split( arc );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
        arc += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
      if ( first_arc )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
        first_arc = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
        /* process corner if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
        start_angle = angle_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
        if ( stroker->first_point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
          error = ft_stroker_subpath_start( stroker, start_angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
          stroker->angle_out = start_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
          error = ft_stroker_process_corner( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
      /* the arc's angle is small enough; we can add it directly to each */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
      /* border                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
        FT_Vector  ctrl1, ctrl2, end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
        FT_Angle   theta1, phi1, theta2, phi2, rotate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
        FT_Fixed   length1, length2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
        FT_Int     side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
        theta1  = ft_pos_abs( angle_mid - angle_in ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
        theta2  = ft_pos_abs( angle_out - angle_mid ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
        phi1    = (angle_mid + angle_in ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
        phi2    = (angle_mid + angle_out ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
        length1 = FT_DivFix( stroker->radius, FT_Cos( theta1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
        length2 = FT_DivFix( stroker->radius, FT_Cos( theta2 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
        for ( side = 0; side <= 1; side++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
          rotate = FT_SIDE_TO_ROTATE( side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
          /* compute control points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
          FT_Vector_From_Polar( &ctrl1, length1, phi1 + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
          ctrl1.x += arc[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
          ctrl1.y += arc[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
          FT_Vector_From_Polar( &ctrl2, length2, phi2 + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
          ctrl2.x += arc[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
          ctrl2.y += arc[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
          /* compute end point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
          FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
          end.x += arc[0].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
          end.y += arc[0].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
          error = ft_stroke_border_cubicto( stroker->borders + side,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
                                            &ctrl1, &ctrl2, &end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
      arc -= 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
      if ( arc < bez_stack )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
        stroker->angle_in = angle_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
    stroker->center = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
  FT_Stroker_BeginSubPath( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
                           FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
                           FT_Bool     open )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
    /* We cannot process the first point, because there is not enough      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
    /* information regarding its corner/cap.  The latter will be processed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
    /* in the `FT_Stroker_EndSubPath' routine.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
    stroker->first_point  = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
    stroker->center       = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
    stroker->subpath_open = open;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
    /* record the subpath start point for each border */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
    stroker->subpath_start = *to;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
  ft_stroker_add_reverse_left( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
                               FT_Bool     open )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
    FT_StrokeBorder  right = stroker->borders + 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
    FT_StrokeBorder  left  = stroker->borders + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
    FT_Int           new_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
    FT_Error         error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
    FT_ASSERT( left->start >= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
    new_points = left->num_points - left->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
    if ( new_points > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
      error = ft_stroke_border_grow( right, (FT_UInt)new_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
        FT_Vector*  dst_point = right->points + right->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
        FT_Byte*    dst_tag   = right->tags   + right->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
        FT_Vector*  src_point = left->points  + left->num_points - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
        FT_Byte*    src_tag   = left->tags    + left->num_points - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
        while ( src_point >= left->points + left->start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
          *dst_point = *src_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
          *dst_tag   = *src_tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
          if ( open )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
            dst_tag[0] &= ~FT_STROKE_TAG_BEGIN_END;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
            FT_Byte  ttag = (FT_Byte)( dst_tag[0] & FT_STROKE_TAG_BEGIN_END );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
            /* switch begin/end tags if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
            if ( ttag == FT_STROKE_TAG_BEGIN ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
                 ttag == FT_STROKE_TAG_END   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
              dst_tag[0] ^= FT_STROKE_TAG_BEGIN_END;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
          src_point--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
          src_tag--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
          dst_point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
          dst_tag++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
      left->num_points   = left->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
      right->num_points += new_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
      right->movable = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
      left->movable  = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
  /* there's a lot of magic in this function! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
  FT_Stroker_EndSubPath( FT_Stroker  stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
    if ( stroker->subpath_open )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
      FT_StrokeBorder  right = stroker->borders;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
      /* All right, this is an opened path, we need to add a cap between */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
      /* right & left, add the reverse of left, then add a final cap     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
      /* between left & right.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
      error = ft_stroker_cap( stroker, stroker->angle_in, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
      /* add reversed points from `left' to `right' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
      error = ft_stroker_add_reverse_left( stroker, TRUE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
      /* now add the final cap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
      stroker->center = stroker->subpath_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
      error = ft_stroker_cap( stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
                              stroker->subpath_angle + FT_ANGLE_PI, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
      /* Now end the right subpath accordingly.  The left one is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
      /* rewind and doesn't need further processing.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
      ft_stroke_border_close( right, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
      FT_Angle  turn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
      FT_Int    inside_side;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
      /* close the path if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
      if ( stroker->center.x != stroker->subpath_start.x ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
           stroker->center.y != stroker->subpath_start.y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
        error = FT_Stroker_LineTo( stroker, &stroker->subpath_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
      /* process the corner */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
      stroker->angle_out = stroker->subpath_angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
      turn               = FT_Angle_Diff( stroker->angle_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
                                          stroker->angle_out );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
      /* no specific corner processing is required if the turn is 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
      if ( turn != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
        /* when we turn to the right, the inside side is 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
        inside_side = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
        /* otherwise, the inside side is 1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
        if ( turn < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
          inside_side = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
        error = ft_stroker_inside( stroker, inside_side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
        /* process the outside side */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
        error = ft_stroker_outside( stroker, 1 - inside_side );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
      /* then end our two subpaths */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
      ft_stroke_border_close( stroker->borders + 0, TRUE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
      ft_stroke_border_close( stroker->borders + 1, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
  FT_Stroker_GetBorderCounts( FT_Stroker        stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
                              FT_StrokerBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
                              FT_UInt          *anum_points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
                              FT_UInt          *anum_contours )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
    FT_UInt   num_points = 0, num_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
    if ( !stroker || border > 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
      error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
    error = ft_stroke_border_get_counts( stroker->borders + border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
                                         &num_points, &num_contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
    if ( anum_points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
      *anum_points = num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
    if ( anum_contours )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
      *anum_contours = num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
  FT_Stroker_GetCounts( FT_Stroker  stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
                        FT_UInt    *anum_points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
                        FT_UInt    *anum_contours )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
    FT_UInt   count1, count2, num_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
    FT_UInt   count3, count4, num_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
    error = ft_stroke_border_get_counts( stroker->borders + 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
                                         &count1, &count2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
    error = ft_stroke_border_get_counts( stroker->borders + 1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
                                         &count3, &count4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
    num_points   = count1 + count3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
    num_contours = count2 + count4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
    *anum_points   = num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
    *anum_contours = num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
  FT_Stroker_ExportBorder( FT_Stroker        stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
                           FT_StrokerBorder  border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
                           FT_Outline*       outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
    if ( border == FT_STROKER_BORDER_LEFT  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
         border == FT_STROKER_BORDER_RIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
      FT_StrokeBorder  sborder = & stroker->borders[border];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
      if ( sborder->valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
        ft_stroke_border_export( sborder, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
  FT_Stroker_Export( FT_Stroker   stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
                     FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
    FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_LEFT, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
    FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_RIGHT, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
   *  The following is very similar to FT_Outline_Decompose, except
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
   *  that we do support opened paths, and do not scale the outline.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
  FT_Stroker_ParseOutline( FT_Stroker   stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
                           FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
                           FT_Bool      opened )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
    FT_Vector   v_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
    FT_Vector   v_control;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
    FT_Vector   v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
    FT_Vector*  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
    FT_Vector*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
    char*       tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
    FT_Int   n;         /* index of contour in outline     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
    FT_UInt  first;     /* index of first point in contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
    FT_Int   tag;       /* current point's state           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
    if ( !outline || !stroker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
    FT_Stroker_Rewind( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
    first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
    for ( n = 0; n < outline->n_contours; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
      FT_UInt  last;  /* index of last point in contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
      last  = outline->contours[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
      limit = outline->points + last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
      /* skip empty points; we don't stroke these */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
      if ( last <= first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
        first = last + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
      v_start = outline->points[first];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
      v_last  = outline->points[last];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
      v_control = v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
      point = outline->points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
      tags  = outline->tags   + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
      tag   = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
      /* A contour cannot start with a cubic control point! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
      if ( tag == FT_CURVE_TAG_CUBIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
        goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
      /* check first point to determine origin */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
      if ( tag == FT_CURVE_TAG_CONIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
        /* First point is conic control.  Yes, this happens. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
        if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
          /* start at last point if it is on the curve */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
          v_start = v_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
          limit--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
          /* if both first and last points are conic, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
          /* start at their middle                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
          v_start.x = ( v_start.x + v_last.x ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
          v_start.y = ( v_start.y + v_last.y ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
        point--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
        tags--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
      error = FT_Stroker_BeginSubPath( stroker, &v_start, opened );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
      while ( point < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
        point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
        tags++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
        tag = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
        switch ( tag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
        case FT_CURVE_TAG_ON:  /* emit a single line_to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1761
            FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
            vec.x = point->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
            vec.y = point->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
            error = FT_Stroker_LineTo( stroker, &vec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
            if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
        case FT_CURVE_TAG_CONIC:  /* consume conic arcs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
          v_control.x = point->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
          v_control.y = point->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
        Do_Conic:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
          if ( point < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
            FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
            FT_Vector  v_middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
            point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
            tags++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
            tag = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
            vec = point[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
            if ( tag == FT_CURVE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
              error = FT_Stroker_ConicTo( stroker, &v_control, &vec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1794
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1795
              continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1798
            if ( tag != FT_CURVE_TAG_CONIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1799
              goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
            v_middle.x = ( v_control.x + vec.x ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
            v_middle.y = ( v_control.y + vec.y ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
            error = FT_Stroker_ConicTo( stroker, &v_control, &v_middle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
            if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
            v_control = vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
            goto Do_Conic;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
          error = FT_Stroker_ConicTo( stroker, &v_control, &v_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
          goto Close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
        default:  /* FT_CURVE_TAG_CUBIC */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
            FT_Vector  vec1, vec2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
            if ( point + 1 > limit                             ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
                 FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
              goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
            point += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
            tags  += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
            vec1 = point[-2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
            vec2 = point[-1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
            if ( point <= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
              FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
              vec = point[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
              error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &vec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
              continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
            error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &v_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
            goto Close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
    Close:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
      error = FT_Stroker_EndSubPath( stroker );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1855
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
      first = last + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
  Invalid_Outline:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
    return FT_Err_Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
/* declare an extern to access ft_outline_glyph_class global allocated 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
   in ftglyph.c, and use the FT_OUTLINE_GLYPH_CLASS_GET macro to access 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
   it when FT_CONFIG_OPTION_PIC is defined */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
#ifndef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
  extern const FT_Glyph_Class  ft_outline_glyph_class;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
#include "basepic.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
  FT_Glyph_Stroke( FT_Glyph    *pglyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
                   FT_Stroker   stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
                   FT_Bool      destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
    FT_Error  error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
    FT_Glyph  glyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
    FT_Library library = stroker->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
    FT_UNUSED(library);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
    if ( pglyph == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
    glyph = *pglyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
    if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1898
      FT_Glyph  copy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
      error = FT_Glyph_Copy( glyph, &copy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
      glyph = copy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
      FT_OutlineGlyph  oglyph  = (FT_OutlineGlyph) glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
      FT_Outline*      outline = &oglyph->outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
      FT_UInt          num_points, num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
      error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
      (void)FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
      FT_Outline_Done( glyph->library, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
      error = FT_Outline_New( glyph->library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
                              num_points, num_contours, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
      outline->n_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
      outline->n_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
      FT_Stroker_Export( stroker, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
    if ( destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
      FT_Done_Glyph( *pglyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
    *pglyph = glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
    FT_Done_Glyph( glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
    glyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
    if ( !destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
      *pglyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
  /* documentation is in ftstroke.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
  FT_Glyph_StrokeBorder( FT_Glyph    *pglyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
                         FT_Stroker   stroker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
                         FT_Bool      inside,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
                         FT_Bool      destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
    FT_Error  error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
    FT_Glyph  glyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
    FT_Library library = stroker->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
    FT_UNUSED(library);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
    if ( pglyph == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
    glyph = *pglyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
    if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
      FT_Glyph  copy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
      error = FT_Glyph_Copy( glyph, &copy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
      glyph = copy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
      FT_OutlineGlyph   oglyph  = (FT_OutlineGlyph) glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
      FT_StrokerBorder  border;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
      FT_Outline*       outline = &oglyph->outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
      FT_UInt           num_points, num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
      border = FT_Outline_GetOutsideBorder( outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
      if ( inside )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
        if ( border == FT_STROKER_BORDER_LEFT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
          border = FT_STROKER_BORDER_RIGHT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
          border = FT_STROKER_BORDER_LEFT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
      error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
      (void)FT_Stroker_GetBorderCounts( stroker, border,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
                                        &num_points, &num_contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
      FT_Outline_Done( glyph->library, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
      error = FT_Outline_New( glyph->library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
                              num_points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
                              num_contours,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
                              outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
      outline->n_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
      outline->n_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
      FT_Stroker_ExportBorder( stroker, border, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
    if ( destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
      FT_Done_Glyph( *pglyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
    *pglyph = glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
    FT_Done_Glyph( glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
    glyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
    if ( !destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
      *pglyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
/* END */