misc/libfreetype/src/base/ftoutln.c
author sheepluva
Wed, 02 May 2012 12:24:44 +0200
changeset 6991 1ec44dde5eb9
parent 5172 88f2e05288ba
permissions -rw-r--r--
make search filter field have a useable size on low frontend resolution
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
/*  ftoutln.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 outline management (body).                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 by */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* All functions are declared in freetype.h.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include FT_TRIGONOMETRY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#define FT_COMPONENT  trace_outline
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  const FT_Outline  null_outline = { 0, 0, 0, 0, 0, 0 };
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /* documentation is in ftoutln.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  FT_Outline_Decompose( FT_Outline*              outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
                        const FT_Outline_Funcs*  func_interface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
                        void*                    user )
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
#undef SCALED
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
#define SCALED( x )  ( ( (x) << shift ) - delta )
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
    FT_Vector   v_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    FT_Vector   v_control;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    FT_Vector   v_start;
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
    FT_Vector*  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    FT_Vector*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    char*       tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    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
    68
    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
    69
    FT_Int   tag;       /* current point's state           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    FT_Int   shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    FT_Pos   delta;
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
    if ( !outline || !func_interface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    shift = func_interface->shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    delta = func_interface->delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    first = 0;
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
    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
    83
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      FT_Int  last;  /* index of last point in contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
      FT_TRACE5(( "FT_Outline_Decompose: Outline %d\n", n ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      last = outline->contours[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      if ( last < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
        goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
      limit = outline->points + last;
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
      v_start   = outline->points[first];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      v_start.x = SCALED( v_start.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      v_start.y = SCALED( v_start.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      v_last   = outline->points[last];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
      v_last.x = SCALED( v_last.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
      v_last.y = SCALED( v_last.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      v_control = v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
      point = outline->points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
      tags  = outline->tags   + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
      tag   = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
      /* 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
   109
      if ( tag == FT_CURVE_TAG_CUBIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
      /* check first point to determine origin */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      if ( tag == FT_CURVE_TAG_CONIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
        /* 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
   116
        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
   117
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
          /* 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
   119
          v_start = v_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
          limit--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
          /* 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
   125
          /* start at their middle and record its position    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
          /* for closure                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
          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
   128
          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
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
          v_last = v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
        point--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
        tags--;
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
      FT_TRACE5(( "  move to (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
                  v_start.x / 64.0, v_start.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
      error = func_interface->move_to( &v_start, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
        goto Exit;
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
      while ( point < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
        point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        tags++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
        tag = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
        switch ( tag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
        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
   151
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
            FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
            vec.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
            vec.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
            FT_TRACE5(( "  line to (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
                        vec.x / 64.0, vec.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
            error = func_interface->line_to( &vec, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
            if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
        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
   167
          v_control.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
          v_control.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
        Do_Conic:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
          if ( point < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
            FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
            FT_Vector  v_middle;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
            point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
            tags++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
            tag = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
            vec.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
            vec.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
            if ( tag == FT_CURVE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
              FT_TRACE5(( "  conic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
                          " with control (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
                          vec.x / 64.0, vec.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
                          v_control.x / 64.0, v_control.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
              error = func_interface->conic_to( &v_control, &vec, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
              continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
            if ( tag != FT_CURVE_TAG_CONIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
              goto Invalid_Outline;
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
            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
   200
            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
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
            FT_TRACE5(( "  conic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
                        " with control (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
                        v_middle.x / 64.0, v_middle.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
                        v_control.x / 64.0, v_control.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
            error = func_interface->conic_to( &v_control, &v_middle, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
            if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
              goto Exit;
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
            v_control = vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
            goto Do_Conic;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
          FT_TRACE5(( "  conic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
                      " with control (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
                      v_start.x / 64.0, v_start.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
                      v_control.x / 64.0, v_control.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
          error = func_interface->conic_to( &v_control, &v_start, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
          goto Close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        default:  /* FT_CURVE_TAG_CUBIC */
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
            FT_Vector  vec1, vec2;
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
            if ( point + 1 > limit                             ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
                 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
   228
              goto Invalid_Outline;
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
            point += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
            tags  += 2;
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
            vec1.x = SCALED( point[-2].x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
            vec1.y = SCALED( point[-2].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
            vec2.x = SCALED( point[-1].x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
            vec2.y = SCALED( point[-1].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
            if ( point <= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
              FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
              vec.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
              vec.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
              FT_TRACE5(( "  cubic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
                          " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
                          vec.x / 64.0, vec.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
                          vec1.x / 64.0, vec1.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
                          vec2.x / 64.0, vec2.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
              error = func_interface->cubic_to( &vec1, &vec2, &vec, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
              continue;
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
            FT_TRACE5(( "  cubic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
                        " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
                        v_start.x / 64.0, v_start.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
                        vec1.x / 64.0, vec1.y / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
                        vec2.x / 64.0, vec2.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
            error = func_interface->cubic_to( &vec1, &vec2, &v_start, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
            goto Close;
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
      }
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
      /* close the contour with a line segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      FT_TRACE5(( "  line to (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
                  v_start.x / 64.0, v_start.y / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      error = func_interface->line_to( &v_start, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    Close:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      first = last + 1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    FT_TRACE5(( "FT_Outline_Decompose: Done\n", n ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    FT_TRACE5(( "FT_Outline_Decompose: Error %d\n", error ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    return error;
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
  Invalid_Outline:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    return FT_Err_Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
  FT_Outline_New_Internal( FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                           FT_UInt      numPoints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
                           FT_Int       numContours,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
                           FT_Outline  *anoutline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    if ( !anoutline || !memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
    *anoutline = null_outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    if ( FT_NEW_ARRAY( anoutline->points,   numPoints   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
         FT_NEW_ARRAY( anoutline->tags,     numPoints   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
         FT_NEW_ARRAY( anoutline->contours, numContours ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      goto Fail;
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
    anoutline->n_points    = (FT_UShort)numPoints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    anoutline->n_contours  = (FT_Short)numContours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    anoutline->flags      |= FT_OUTLINE_OWNER;
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
    return FT_Err_Ok;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    anoutline->flags |= FT_OUTLINE_OWNER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    FT_Outline_Done_Internal( memory, anoutline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  }
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
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  FT_Outline_New( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
                  FT_UInt      numPoints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
                  FT_Int       numContours,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
                  FT_Outline  *anoutline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      return FT_Err_Invalid_Library_Handle;
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
    return FT_Outline_New_Internal( library->memory, numPoints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
                                    numContours, anoutline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
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
  /* documentation is in ftoutln.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
  FT_Outline_Check( FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    if ( outline )
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
      FT_Int  n_points   = outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
      FT_Int  n_contours = outline->n_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
      FT_Int  end0, end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      FT_Int  n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      /* empty glyph? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
      if ( n_points == 0 && n_contours == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
        return 0;
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
      /* check point and contour counts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
      if ( n_points <= 0 || n_contours <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
        goto Bad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
      end0 = end = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      for ( n = 0; n < n_contours; n++ )
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
        end = outline->contours[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
        /* note that we don't accept empty contours */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
        if ( end <= end0 || end >= n_points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
          goto Bad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
        end0 = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      if ( end != n_points - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
        goto Bad;
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
      /* XXX: check the tags array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
  Bad:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    return FT_Err_Invalid_Argument;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  /* documentation is in ftoutln.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  FT_Outline_Copy( const FT_Outline*  source,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
                   FT_Outline        *target )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
    FT_Int  is_owner;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    if ( !source            || !target            ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
         source->n_points   != target->n_points   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
         source->n_contours != target->n_contours )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    if ( source == target )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
      return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    FT_ARRAY_COPY( target->points, source->points, source->n_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
    FT_ARRAY_COPY( target->tags, source->tags, source->n_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    FT_ARRAY_COPY( target->contours, source->contours, source->n_contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
    /* copy all flags, except the `FT_OUTLINE_OWNER' one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
    is_owner      = target->flags & FT_OUTLINE_OWNER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
    target->flags = source->flags;
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
    target->flags &= ~FT_OUTLINE_OWNER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    target->flags |= is_owner;
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
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
  FT_Outline_Done_Internal( FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
                            FT_Outline*  outline )
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
    if ( memory && outline )
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
      if ( outline->flags & FT_OUTLINE_OWNER )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
        FT_FREE( outline->points   );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
        FT_FREE( outline->tags     );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        FT_FREE( outline->contours );
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
      *outline = null_outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      return FT_Err_Ok;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
  FT_Outline_Done( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
                   FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    /* check for valid `outline' in FT_Outline_Done_Internal() */
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
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
    return FT_Outline_Done_Internal( library->memory, outline );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
  FT_Outline_Get_CBox( const FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
                       FT_BBox           *acbox )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
    FT_Pos  xMin, yMin, xMax, yMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    if ( outline && acbox )
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
      if ( outline->n_points == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
        xMin = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
        yMin = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
        xMax = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
        yMax = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      else
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
        FT_Vector*  vec   = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
        FT_Vector*  limit = vec + outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        xMin = xMax = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
        yMin = yMax = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
        vec++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
        for ( ; vec < limit; vec++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
          FT_Pos  x, y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
          x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
          if ( x < xMin ) xMin = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
          if ( x > xMax ) xMax = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
          y = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
          if ( y < yMin ) yMin = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
          if ( y > yMax ) yMax = 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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
      acbox->xMin = xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
      acbox->xMax = xMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
      acbox->yMin = yMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
      acbox->yMax = yMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
  FT_Outline_Translate( const FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
                        FT_Pos             xOffset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
                        FT_Pos             yOffset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    FT_UShort   n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    FT_Vector*  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      return;
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
    vec = outline->points;
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
    for ( n = 0; n < outline->n_points; n++ )
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
      vec->x += xOffset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      vec->y += yOffset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      vec++;
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
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
  FT_Outline_Reverse( FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    FT_UShort  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    FT_Int     first, last;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      return;
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
    first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    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
   547
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      last  = outline->contours[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
      /* reverse point table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
        FT_Vector*  p = outline->points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
        FT_Vector*  q = outline->points + last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
        FT_Vector   swap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
        while ( p < q )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
          swap = *p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
          *p   = *q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
          *q   = swap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
          p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
          q--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
      }
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
      /* reverse tags table */
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
        char*  p = outline->tags + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        char*  q = outline->tags + last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
        char   swap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
        while ( p < q )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
          swap = *p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
          *p   = *q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
          *q   = swap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
          p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
          q--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
      first = last + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    outline->flags ^= FT_OUTLINE_REVERSE_FILL;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
  FT_Outline_Render( FT_Library         library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
                     FT_Outline*        outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
                     FT_Raster_Params*  params )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    FT_Bool      update = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
    FT_Renderer  renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
    FT_ListNode  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
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
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
      return FT_Err_Invalid_Library_Handle;
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 ( !outline || !params )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
    renderer = library->cur_renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
    node     = library->renderers.head;
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
    params->source = (void*)outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
    error = FT_Err_Cannot_Render_Glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
    while ( renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      error = renderer->raster_render( renderer->raster, params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      if ( !error || FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
      /* FT_Err_Cannot_Render_Glyph is returned if the render mode   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      /* is unsupported by the current renderer for this glyph image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
      /* format                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
      /* now, look for another renderer that supports the same */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
      /* format                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
                                     &node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
      update   = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    /* if we changed the current renderer for the glyph image format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    /* we need to select it as the next current one                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    if ( !error && update && renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
      FT_Set_Renderer( library, renderer, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    return error;
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
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
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
  FT_Outline_Get_Bitmap( FT_Library        library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
                         FT_Outline*       outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
                         const FT_Bitmap  *abitmap )
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
    FT_Raster_Params  params;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    if ( !abitmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
    /* other checks are delayed to FT_Outline_Render() */
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
    params.target = abitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
    params.flags  = 0;
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
    if ( abitmap->pixel_mode == FT_PIXEL_MODE_GRAY  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
         abitmap->pixel_mode == FT_PIXEL_MODE_LCD   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
         abitmap->pixel_mode == FT_PIXEL_MODE_LCD_V )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      params.flags |= FT_RASTER_FLAG_AA;
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
    return FT_Outline_Render( library, outline, &params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
  FT_Vector_Transform( FT_Vector*        vector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
                       const FT_Matrix*  matrix )
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
    FT_Pos  xz, yz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    if ( !vector || !matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
      return;
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
    xz = FT_MulFix( vector->x, matrix->xx ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
         FT_MulFix( vector->y, matrix->xy );
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
    yz = FT_MulFix( vector->x, matrix->yx ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
         FT_MulFix( vector->y, matrix->yy );
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
    vector->x = xz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    vector->y = yz;
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
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
  /* documentation is in ftoutln.h */
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_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
  FT_Outline_Transform( const FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
                        const FT_Matrix*   matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    FT_Vector*  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    FT_Vector*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
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
    if ( !outline || !matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    vec   = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    limit = vec + outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    for ( ; vec < limit; vec++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
      FT_Vector_Transform( vec, matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
  }
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
#if 0
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
#define FT_OUTLINE_GET_CONTOUR( outline, c, first, last )  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
  do {                                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    (first) = ( c > 0 ) ? (outline)->points +              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
                            (outline)->contours[c - 1] + 1 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
                        : (outline)->points;               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    (last) = (outline)->points + (outline)->contours[c];   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
  } while ( 0 )
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
  /* Is a point in some contour?                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
  /*                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
  /* We treat every point of the contour as if it    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
  /* it were ON.  That is, we allow false positives, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
  /* but disallow false negatives.  (XXX really?)    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
  ft_contour_has( FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
                  FT_Short     c,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
                  FT_Vector*   point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    FT_Vector*  first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    FT_Vector*  last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    FT_Vector*  a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    FT_Vector*  b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    FT_UInt     n = 0;
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
    FT_OUTLINE_GET_CONTOUR( outline, c, first, last );
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
    for ( a = first; a <= last; a++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
      FT_Pos  x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      FT_Int  intersect;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
      b = ( a == last ) ? first : a + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
      intersect = ( a->y - point->y ) ^ ( b->y - point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      /* a and b are on the same side */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
      if ( intersect >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
        if ( intersect == 0 && a->y == point->y )
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
          if ( ( a->x <= point->x && b->x >= point->x ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
               ( a->x >= point->x && b->x <= point->x ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
            return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
      }
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
      x = a->x + ( b->x - a->x ) * (point->y - a->y ) / ( b->y - a->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
      if ( x < point->x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
        n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
      else if ( x == point->x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
        return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
    }
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
    return ( n % 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
  ft_contour_enclosed( FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
                       FT_UShort    c )
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_Vector*  first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
    FT_Vector*  last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
    FT_Short    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    FT_OUTLINE_GET_CONTOUR( outline, c, first, last );
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
    for ( i = 0; i < outline->n_contours; i++ )
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
      if ( i != c && ft_contour_has( outline, i, first ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
        FT_Vector*  pt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
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
        for ( pt = first + 1; pt <= last; pt++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
          if ( !ft_contour_has( outline, i, pt ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
            return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
        return 1;
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
    }
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
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
  /* This version differs from the public one in that each */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
  /* part (contour not enclosed in another contour) of the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
  /* outline is checked for orientation.  This is          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
  /* necessary for some buggy CJK fonts.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
  static FT_Orientation
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
  ft_outline_get_orientation( FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
    FT_Short        i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
    FT_Vector*      first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
    FT_Vector*      last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
    FT_Orientation  orient = FT_ORIENTATION_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
    first = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
    for ( i = 0; i < outline->n_contours; i++, first = last + 1 )
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_Vector*  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
      FT_Vector*  xmin_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
      FT_Pos      xmin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
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
      last = outline->points + outline->contours[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      /* skip degenerate contours */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
      if ( last < first + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
      if ( ft_contour_enclosed( outline, i ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      xmin       = first->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
      xmin_point = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
      for ( point = first + 1; point <= last; point++ )
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
        if ( point->x < xmin )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
          xmin       = point->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
          xmin_point = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
      /* check the orientation of the contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
        FT_Vector*      prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
        FT_Vector*      next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
        FT_Orientation  o;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
        prev = ( xmin_point == first ) ? last : xmin_point - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
        next = ( xmin_point == last ) ? first : xmin_point + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
        if ( FT_Atan2( prev->x - xmin_point->x, prev->y - xmin_point->y ) >
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
             FT_Atan2( next->x - xmin_point->x, next->y - xmin_point->y ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
          o = FT_ORIENTATION_POSTSCRIPT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
          o = FT_ORIENTATION_TRUETYPE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
        if ( orient == FT_ORIENTATION_NONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
          orient = o;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
        else if ( orient != o )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
          return FT_ORIENTATION_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
    return orient;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
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
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
  FT_Outline_Embolden( FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
                       FT_Pos       strength )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
    FT_Vector*  points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
    FT_Vector   v_prev, v_first, v_next, v_cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
    FT_Angle    rotate, angle_in, angle_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
    FT_Int      c, n, first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    FT_Int      orientation;
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
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
    strength /= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
    if ( strength == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
      return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
    orientation = FT_Outline_Get_Orientation( outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
    if ( orientation == FT_ORIENTATION_NONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
      if ( outline->n_contours )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
        return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
        return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
    if ( orientation == FT_ORIENTATION_TRUETYPE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
      rotate = -FT_ANGLE_PI2;
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
      rotate = FT_ANGLE_PI2;
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
    points = outline->points;
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
    first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    for ( c = 0; c < outline->n_contours; c++ )
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
      int  last = outline->contours[c];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
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
      v_first = points[first];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
      v_prev  = points[last];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
      v_cur   = v_first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
      for ( n = first; n <= last; n++ )
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
        FT_Vector  in, out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
        FT_Angle   angle_diff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
        FT_Pos     d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
        FT_Fixed   scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
        if ( n < last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
          v_next = points[n + 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
          v_next = v_first;
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
        /* compute the in and out vectors */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
        in.x = v_cur.x - v_prev.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
        in.y = v_cur.y - v_prev.y;
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
        out.x = v_next.x - v_cur.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
        out.y = v_next.y - v_cur.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
        angle_in   = FT_Atan2( in.x, in.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
        angle_out  = FT_Atan2( out.x, out.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
        angle_diff = FT_Angle_Diff( angle_in, angle_out );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
        scale      = FT_Cos( angle_diff / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
        if ( scale < 0x4000L && scale > -0x4000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
          in.x = in.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
          d = FT_DivFix( strength, scale );
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
          FT_Vector_From_Polar( &in, d, angle_in + angle_diff / 2 - rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
        outline->points[n].x = v_cur.x + strength + in.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
        outline->points[n].y = v_cur.y + strength + in.y;
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
        v_prev = v_cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
        v_cur  = v_next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
      }
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
      first = last + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
    }
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
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
  /* documentation is in ftoutln.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
  FT_EXPORT_DEF( FT_Orientation )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
  FT_Outline_Get_Orientation( FT_Outline*  outline )
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
    FT_Pos      xmin       = 32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
    FT_Pos      xmin_ymin  = 32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    FT_Pos      xmin_ymax  = -32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
    FT_Vector*  xmin_first = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
    FT_Vector*  xmin_last  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
    short*      contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
    FT_Vector*  first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
    FT_Vector*  last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
    FT_Vector*  prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    FT_Vector*  point;
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
    int             i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
    FT_Pos          ray_y[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
    FT_Orientation  result[3] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
      { FT_ORIENTATION_NONE, FT_ORIENTATION_NONE, FT_ORIENTATION_NONE };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    if ( !outline || outline->n_points <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
      return FT_ORIENTATION_TRUETYPE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
    /* We use the nonzero winding rule to find the orientation.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    /* Since glyph outlines behave much more `regular' than arbitrary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
    /* cubic or quadratic curves, this test deals with the polygon    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
    /* only which is spanned up by the control points.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    first = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
    for ( contour = outline->contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
          contour < outline->contours + outline->n_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
          contour++, first = last + 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
      FT_Pos  contour_xmin = 32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
      FT_Pos  contour_xmax = -32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
      FT_Pos  contour_ymin = 32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
      FT_Pos  contour_ymax = -32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
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
      last = outline->points + *contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
      /* skip degenerate contours */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
      if ( last < first + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
      for ( point = first; point <= last; ++point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
        if ( point->x < contour_xmin )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
          contour_xmin = point->x;
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
        if ( point->x > contour_xmax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
          contour_xmax = point->x;
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
        if ( point->y < contour_ymin )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
          contour_ymin = point->y;
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
        if ( point->y > contour_ymax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
          contour_ymax = point->y;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
      if ( contour_xmin < xmin          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
           contour_xmin != contour_xmax &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
           contour_ymin != contour_ymax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
        xmin       = contour_xmin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
        xmin_ymin  = contour_ymin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
        xmin_ymax  = contour_ymax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
        xmin_first = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
        xmin_last  = last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
    if ( xmin == 32768L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
      return FT_ORIENTATION_TRUETYPE;
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
    ray_y[0] = ( xmin_ymin * 3 + xmin_ymax     ) >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
    ray_y[1] = ( xmin_ymin     + xmin_ymax     ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
    ray_y[2] = ( xmin_ymin     + xmin_ymax * 3 ) >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
    for ( i = 0; i < 3; i++ )
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
      FT_Pos      left_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
      FT_Pos      right_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
      FT_Vector*  left1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
      FT_Vector*  left2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
      FT_Vector*  right1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
      FT_Vector*  right2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
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
    RedoRay:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
      left_x  = 32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
      right_x = -32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
      left1 = left2 = right1 = right2 = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
      prev = xmin_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
      for ( point = xmin_first; point <= xmin_last; prev = point, ++point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
        FT_Pos  tmp_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
        if ( point->y == ray_y[i] || prev->y == ray_y[i] )
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
          ray_y[i]++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
          goto RedoRay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
        if ( ( point->y < ray_y[i] && prev->y < ray_y[i] ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
             ( point->y > ray_y[i] && prev->y > ray_y[i] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
          continue;
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
        tmp_x = FT_MulDiv( point->x - prev->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
                           ray_y[i] - prev->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
                           point->y - prev->y ) + prev->x;
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
        if ( tmp_x < left_x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
          left_x = tmp_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
          left1  = prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
          left2  = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
        }
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
        if ( tmp_x > right_x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
          right_x = tmp_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
          right1  = prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
          right2  = point;
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
      if ( left1 && right1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
        if ( left1->y < left2->y && right1->y > right2->y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
          result[i] = FT_ORIENTATION_TRUETYPE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
        else if ( left1->y > left2->y && right1->y < right2->y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
          result[i] = FT_ORIENTATION_POSTSCRIPT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
          result[i] = FT_ORIENTATION_NONE;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
    if ( result[0] != FT_ORIENTATION_NONE                     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
         ( result[0] == result[1] || result[0] == result[2] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
      return result[0];
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
    if ( result[1] != FT_ORIENTATION_NONE && result[1] == result[2] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
      return result[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
    return FT_ORIENTATION_TRUETYPE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
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
/* END */