misc/libfreetype/src/smooth/ftgrays.c
author nemo
Thu, 28 Feb 2013 23:15:33 -0500
changeset 8617 e7bea88096d2
parent 5172 88f2e05288ba
permissions -rw-r--r--
So. A while ago, while trying to prevent hogs blowtorching getting turned around, unc0rr altered the old range of blowtorch from 1/8th of 180° up or down, to a 4° gain in upwards and a -4° loss in downwards. He also made it so that starting tunnels could fail to erase sufficient terrain, trapping hogs. Here are a couple of workarounds to more closely approximate old behaviour (do some initial erasure, adjust min/max angles)
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
/*  ftgrays.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
/*    A new `perfect' anti-aliasing renderer (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 2000-2003, 2005-2011 by                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  /* This file can be compiled without the rest of the FreeType engine, by */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* defining the _STANDALONE_ macro when compiling it.  You also need to  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /* put the files `ftgrays.h' and `ftimage.h' into the current            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
  /* compilation directory.  Typically, you could do something like        */
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
  /* - copy `src/smooth/ftgrays.c' (this file) to your current directory   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /* - copy `include/freetype/ftimage.h' and `src/smooth/ftgrays.h' to the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /*   same directory                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* - compile `ftgrays' with the _STANDALONE_ macro defined, as in        */
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
  /*     cc -c -D_STANDALONE_ ftgrays.c                                    */
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
  /* The renderer can be initialized with a call to                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* `ft_gray_raster.raster_new'; an anti-aliased bitmap can be generated  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /* with a call to `ft_gray_raster.raster_render'.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* See the comments and documentation in the file `ftimage.h' for more   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /* details on how the raster works.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /* This is a new anti-aliasing scan-converter for FreeType 2.  The       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /* algorithm used here is _very_ different from the one in the standard  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /* `ftraster' module.  Actually, `ftgrays' computes the _exact_          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* coverage of the outline on each pixel cell.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /* It is based on ideas that I initially found in Raph Levien's          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /* excellent LibArt graphics library (see http://www.levien.com/libart   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /* for more information, though the web pages do not tell anything       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /* about the renderer; you'll have to dive into the source code to       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /* understand how it works).                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /* Note, however, that this is a _very_ different implementation         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  /* compared to Raph's.  Coverage information is stored in a very         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /* different way, and I don't use sorted vector paths.  Also, it doesn't */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /* use floating point values.                                            */
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
  /* This renderer has the following advantages:                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /* - It doesn't need an intermediate bitmap.  Instead, one can supply a  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /*   callback function that will be called by the renderer to draw gray  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  /*   spans on any target surface.  You can thus do direct composition on */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  /*   any kind of bitmap, provided that you give the renderer the right   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /*   callback.                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  /* - A perfect anti-aliaser, i.e., it computes the _exact_ coverage on   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  /*   each pixel cell.                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  /* - It performs a single pass on the outline (the `standard' FT2        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  /*   renderer makes two passes).                                         */
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
  /* - It can easily be modified to render to _any_ number of gray levels  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /*   cheaply.                                                            */
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
  /* - For small (< 20) pixel sizes, it is faster than the standard        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
  /*   renderer.                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /* 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
    87
  /* 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
    88
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
#define FT_COMPONENT  trace_smooth
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
#ifdef _STANDALONE_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  /* define this to dump debugging information */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
/* #define FT_DEBUG_LEVEL_TRACE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
#include <stdio.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
#include <stdarg.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
#include <stddef.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
#include <string.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
#include <setjmp.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
#include <limits.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
#define FT_UINT_MAX  UINT_MAX
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
#define FT_INT_MAX   INT_MAX
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
#define ft_memset   memset
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
#define ft_setjmp   setjmp
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
#define ft_longjmp  longjmp
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
#define ft_jmp_buf  jmp_buf
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
typedef ptrdiff_t  FT_PtrDist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
#define ErrRaster_Invalid_Mode      -2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
#define ErrRaster_Invalid_Outline   -1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
#define ErrRaster_Invalid_Argument  -3
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
#define ErrRaster_Memory_Overflow   -4
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
#define FT_BEGIN_HEADER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
#define FT_END_HEADER
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
#include "ftimage.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
#include "ftgrays.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  /* This macro is used to indicate that a function parameter is unused. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  /* Its purpose is simply to reduce compiler warnings.  Note also that  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
  /* simply defining it as `(void)x' doesn't avoid warnings with certain */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
  /* ANSI compilers (e.g. LCC).                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
#define FT_UNUSED( x )  (x) = (x)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  /* we only use level 5 & 7 tracing messages; cf. ftdebug.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  FT_Message( const char*  fmt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
              ... )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    va_list  ap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    va_start( ap, fmt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    vfprintf( stderr, fmt, ap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    va_end( ap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  /* we don't handle tracing levels in stand-alone mode; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
#ifndef FT_TRACE5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
#define FT_TRACE5( varformat )  FT_Message varformat
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
#ifndef FT_TRACE7
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
#define FT_TRACE7( varformat )  FT_Message varformat
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
#ifndef FT_ERROR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
#define FT_ERROR( varformat )   FT_Message varformat
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
#else /* !FT_DEBUG_LEVEL_TRACE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
#define FT_TRACE5( x )  do { } while ( 0 )     /* nothing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
#define FT_TRACE7( x )  do { } while ( 0 )     /* nothing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
#define FT_ERROR( x )   do { } while ( 0 )     /* nothing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
#endif /* !FT_DEBUG_LEVEL_TRACE */
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
#define FT_DEFINE_OUTLINE_FUNCS( class_,               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
                                 move_to_, line_to_,   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
                                 conic_to_, cubic_to_, \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
                                 shift_, delta_ )      \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
          static const FT_Outline_Funcs class_ =       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
          {                                            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
            move_to_,                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
            line_to_,                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
            conic_to_,                                 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
            cubic_to_,                                 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
            shift_,                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
            delta_                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
         };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
#define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_,            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
                                raster_new_, raster_reset_,       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
                                raster_set_mode_, raster_render_, \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
                                raster_done_ )                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
          const FT_Raster_Funcs class_ =                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
          {                                                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
            glyph_format_,                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
            raster_new_,                                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
            raster_reset_,                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
            raster_set_mode_,                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
            raster_render_,                                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
            raster_done_                                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
         };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
#else /* !_STANDALONE_ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
#include "ftgrays.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
#include FT_OUTLINE_H
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
#include "ftsmerrs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
#include "ftspic.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
#define ErrRaster_Invalid_Mode      Smooth_Err_Cannot_Render_Glyph
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
#define ErrRaster_Invalid_Outline   Smooth_Err_Invalid_Outline
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
#define ErrRaster_Memory_Overflow   Smooth_Err_Out_Of_Memory
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
#define ErrRaster_Invalid_Argument  Smooth_Err_Invalid_Argument
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
#endif /* !_STANDALONE_ */
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
#ifndef FT_MEM_SET
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
#define FT_MEM_SET( d, s, c )  ft_memset( d, s, c )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
#ifndef FT_MEM_ZERO
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
#define FT_MEM_ZERO( dest, count )  FT_MEM_SET( dest, 0, count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
#endif
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
  /* as usual, for the speed hungry :-) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
#ifndef FT_STATIC_RASTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
#define RAS_ARG   PWorker  worker
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
#define RAS_ARG_  PWorker  worker,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
#define RAS_VAR   worker
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
#define RAS_VAR_  worker,
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
#else /* FT_STATIC_RASTER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
#define RAS_ARG   /* empty */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
#define RAS_ARG_  /* empty */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
#define RAS_VAR   /* empty */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
#define RAS_VAR_  /* empty */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
#endif /* FT_STATIC_RASTER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
  /* must be at least 6 bits! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
#define PIXEL_BITS  8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
#define ONE_PIXEL       ( 1L << PIXEL_BITS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
#define PIXEL_MASK      ( -1L << PIXEL_BITS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
#define TRUNC( x )      ( (TCoord)( (x) >> PIXEL_BITS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
#define SUBPIXELS( x )  ( (TPos)(x) << PIXEL_BITS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
#define FLOOR( x )      ( (x) & -ONE_PIXEL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
#define CEILING( x )    ( ( (x) + ONE_PIXEL - 1 ) & -ONE_PIXEL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
#define ROUND( x )      ( ( (x) + ONE_PIXEL / 2 ) & -ONE_PIXEL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
#if PIXEL_BITS >= 6
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
#define UPSCALE( x )    ( (x) << ( PIXEL_BITS - 6 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
#define DOWNSCALE( x )  ( (x) >> ( PIXEL_BITS - 6 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
#define UPSCALE( x )    ( (x) >> ( 6 - PIXEL_BITS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
#define DOWNSCALE( x )  ( (x) << ( 6 - PIXEL_BITS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
  /*   TYPE DEFINITIONS                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
  /*                                                                       */
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
  /* don't change the following types to FT_Int or FT_Pos, since we might */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
  /* need to define them to "float" or "double" when experimenting with   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
  /* new algorithms                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
  typedef long  TCoord;   /* integer scanline/pixel coordinate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
  typedef long  TPos;     /* sub-pixel coordinate              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  /* determine the type used to store cell areas.  This normally takes at */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
  /* least PIXEL_BITS*2 + 1 bits.  On 16-bit systems, we need to use      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
  /* `long' instead of `int', otherwise bad things happen                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
#if PIXEL_BITS <= 7
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
  typedef int  TArea;
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
#else /* PIXEL_BITS >= 8 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
  /* approximately determine the size of integers using an ANSI-C header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
#if FT_UINT_MAX == 0xFFFFU
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
  typedef long  TArea;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
  typedef int   TArea;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
#endif
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
#endif /* PIXEL_BITS >= 8 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
  /* maximal number of gray spans in a call to the span callback */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
#define FT_MAX_GRAY_SPANS  32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
  typedef struct TCell_*  PCell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  typedef struct  TCell_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    TPos   x;     /* same with TWorker.ex */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    TCoord cover; /* same with TWorker.cover */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    TArea  area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    PCell  next;
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
  } TCell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
  typedef struct  TWorker_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    TCoord  ex, ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    TPos    min_ex, max_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    TPos    min_ey, max_ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    TPos    count_ex, count_ey;
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
    TArea   area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
    TCoord  cover;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    int     invalid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    PCell   cells;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    FT_PtrDist  max_cells;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    FT_PtrDist  num_cells;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    TCoord  cx, cy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    TPos    x,  y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
    TPos    last_ey;
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
    FT_Vector   bez_stack[32 * 3 + 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    int         lev_stack[32];
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_Outline  outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    FT_Bitmap   target;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    FT_BBox     clip_box;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    FT_Span     gray_spans[FT_MAX_GRAY_SPANS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    int         num_gray_spans;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    FT_Raster_Span_Func  render_span;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    void*                render_span_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    int                  span_y;
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
    int  band_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
    int  band_shoot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
    ft_jmp_buf  jump_buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    void*       buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    long        buffer_size;
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
    PCell*     ycells;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    TPos       ycount;
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
  } TWorker, *PWorker;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
#ifndef FT_STATIC_RASTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
#define ras  (*worker)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
  static TWorker  ras;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
  typedef struct TRaster_
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
    void*    buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    long     buffer_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    int      band_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
    void*    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
    PWorker  worker;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
  } TRaster, *PRaster;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  /* Initialize the cells table.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
  gray_init_cells( RAS_ARG_ void*  buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
                   long            byte_size )
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
    ras.buffer      = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    ras.buffer_size = byte_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    ras.ycells      = (PCell*) buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
    ras.cells       = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    ras.max_cells   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    ras.num_cells   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
    ras.area        = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    ras.cover       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    ras.invalid     = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
  }
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
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
  /* Compute the outline bounding box.                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  gray_compute_cbox( RAS_ARG )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    FT_Outline*  outline = &ras.outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
    FT_Vector*   vec     = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
    FT_Vector*   limit   = vec + outline->n_points;
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
    if ( outline->n_points <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
      ras.min_ex = ras.max_ex = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      ras.min_ey = ras.max_ey = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    ras.min_ex = ras.max_ex = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    ras.min_ey = ras.max_ey = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    vec++;
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
    for ( ; vec < limit; vec++ )
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
      TPos  x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      TPos  y = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      if ( x < ras.min_ex ) ras.min_ex = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      if ( x > ras.max_ex ) ras.max_ex = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      if ( y < ras.min_ey ) ras.min_ey = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      if ( y > ras.max_ey ) ras.max_ey = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    /* truncate the bounding box to integer pixels */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    ras.min_ex = ras.min_ex >> 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
    ras.min_ey = ras.min_ey >> 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    ras.max_ex = ( ras.max_ex + 63 ) >> 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
    ras.max_ey = ( ras.max_ey + 63 ) >> 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
  /* Record the current cell in the table.                                 */
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
  static PCell
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
  gray_find_cell( RAS_ARG )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    PCell  *pcell, cell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
    TPos    x = ras.ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    if ( x > ras.count_ex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
      x = ras.count_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    pcell = &ras.ycells[ras.ey];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    for (;;)
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
      cell = *pcell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
      if ( cell == NULL || cell->x > x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
      if ( cell->x == x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
        goto Exit;
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
      pcell = &cell->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    if ( ras.num_cells >= ras.max_cells )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
      ft_longjmp( ras.jump_buffer, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    cell        = ras.cells + ras.num_cells++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    cell->x     = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    cell->area  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    cell->cover = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    cell->next  = *pcell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
    *pcell      = cell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    return cell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
  gray_record_cell( RAS_ARG )
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
    if ( !ras.invalid && ( ras.area | ras.cover ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
      PCell  cell = gray_find_cell( RAS_VAR );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
      cell->area  += ras.area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
      cell->cover += ras.cover;
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
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
  /* Set the current cell to a new position.                               */
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  gray_set_cell( RAS_ARG_ TCoord  ex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
                          TCoord  ey )
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
    /* Move the cell pointer to a new position.  We set the `invalid'      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    /* flag to indicate that the cell isn't part of those we're interested */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
    /* in during the render phase.  This means that:                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    /* . the new vertical position must be within min_ey..max_ey-1.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    /* . the new horizontal position must be strictly less than max_ex     */
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
    /* Note that if a cell is to the left of the clipping region, it is    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    /* actually set to the (min_ex-1) horizontal position.                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
    /* All cells that are on the left of the clipping region go to the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    /* min_ex - 1 horizontal position.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    ey -= ras.min_ey;
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
    if ( ex > ras.max_ex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
      ex = ras.max_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    ex -= ras.min_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    if ( ex < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
      ex = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    /* are we moving to a different cell ? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    if ( ex != ras.ex || ey != ras.ey )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      /* record the current one if it is valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
      if ( !ras.invalid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
        gray_record_cell( RAS_VAR );
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
      ras.area  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      ras.cover = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
    ras.ex      = ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
    ras.ey      = ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
    ras.invalid = ( (unsigned)ey >= (unsigned)ras.count_ey ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
                              ex >= ras.count_ex           );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
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
  /*************************************************************************/
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
  /* Start a new contour at a given cell.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
  gray_start_cell( RAS_ARG_ TCoord  ex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
                            TCoord  ey )
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
    if ( ex > ras.max_ex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
      ex = (TCoord)( ras.max_ex );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    if ( ex < ras.min_ex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      ex = (TCoord)( ras.min_ex - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    ras.area    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    ras.cover   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
    ras.ex      = ex - ras.min_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
    ras.ey      = ey - ras.min_ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
    ras.last_ey = SUBPIXELS( ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    ras.invalid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
    gray_set_cell( RAS_VAR_ ex, ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
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
  /* Render a scanline as one or more cells.                               */
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
  gray_render_scanline( RAS_ARG_ TCoord  ey,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
                                 TPos    x1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
                                 TCoord  y1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
                                 TPos    x2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
                                 TCoord  y2 )
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
    TCoord  ex1, ex2, fx1, fx2, delta, mod, lift, rem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    long    p, first, dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    int     incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    dx = x2 - x1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
    ex1 = TRUNC( x1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
    ex2 = TRUNC( x2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
    fx1 = (TCoord)( x1 - SUBPIXELS( ex1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    fx2 = (TCoord)( x2 - SUBPIXELS( ex2 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
    /* trivial case.  Happens often */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    if ( y1 == y2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      gray_set_cell( RAS_VAR_ ex2, ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
    /* everything is located in a single cell.  That is easy! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
    /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
    if ( ex1 == ex2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
      delta      = y2 - y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      ras.area  += (TArea)(( fx1 + fx2 ) * delta);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      ras.cover += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    /* ok, we'll have to render a run of adjacent cells on the same */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
    /* scanline...                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
    /*                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
    p     = ( ONE_PIXEL - fx1 ) * ( y2 - y1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    first = ONE_PIXEL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
    incr  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    if ( dx < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
      p     = fx1 * ( y2 - y1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
      first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
      incr  = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
      dx    = -dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    delta = (TCoord)( p / dx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    mod   = (TCoord)( p % dx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    if ( mod < 0 )
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
      delta--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
      mod += (TCoord)dx;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    ras.area  += (TArea)(( fx1 + first ) * delta);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    ras.cover += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
    ex1 += incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
    gray_set_cell( RAS_VAR_ ex1, ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
    y1  += delta;
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 ( ex1 != ex2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
      p    = ONE_PIXEL * ( y2 - y1 + delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
      lift = (TCoord)( p / dx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
      rem  = (TCoord)( p % dx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
      if ( rem < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
        lift--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
        rem += (TCoord)dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      mod -= (int)dx;
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
      while ( ex1 != ex2 )
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
        delta = lift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
        mod  += rem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
        if ( mod >= 0 )
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
          mod -= (TCoord)dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
          delta++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
        ras.area  += (TArea)(ONE_PIXEL * delta);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
        ras.cover += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
        y1        += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
        ex1       += incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
        gray_set_cell( RAS_VAR_ ex1, ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    delta      = y2 - y1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
    ras.area  += (TArea)(( fx2 + ONE_PIXEL - first ) * delta);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    ras.cover += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
  /* Render a given line as a series of scanlines.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  gray_render_line( RAS_ARG_ TPos  to_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
                             TPos  to_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
    TCoord  ey1, ey2, fy1, fy2, mod;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    TPos    dx, dy, x, x2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    long    p, first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    int     delta, rem, lift, incr;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    ey1 = TRUNC( ras.last_ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    ey2 = TRUNC( to_y );     /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    fy1 = (TCoord)( ras.y - ras.last_ey );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    fy2 = (TCoord)( to_y - SUBPIXELS( ey2 ) );
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
    dx = to_x - ras.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    dy = to_y - ras.y;
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
    /* XXX: we should do something about the trivial case where dx == 0, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    /*      as it happens very often!                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    /* perform vertical clipping */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
      TCoord  min, max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
      min = ey1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      max = ey2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
      if ( ey1 > ey2 )
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
        min = ey2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
        max = ey1;
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
      if ( min >= ras.max_ey || max < ras.min_ey )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
        goto End;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    /* everything is on a single scanline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    if ( ey1 == ey2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
      gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
      goto End;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    /* vertical line - avoid calling gray_render_scanline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    incr = 1;
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
    if ( dx == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
      TCoord  ex     = TRUNC( ras.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
      TCoord  two_fx = (TCoord)( ( ras.x - SUBPIXELS( ex ) ) << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
      TArea   area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      first = ONE_PIXEL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
      if ( dy < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
        first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
        incr  = -1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
      delta      = (int)( first - fy1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
      ras.area  += (TArea)two_fx * delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
      ras.cover += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
      ey1       += incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
      gray_set_cell( RAS_VAR_ ex, ey1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
      delta = (int)( first + first - ONE_PIXEL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
      area  = (TArea)two_fx * delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
      while ( ey1 != ey2 )
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
        ras.area  += area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
        ras.cover += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
        ey1       += incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
        gray_set_cell( RAS_VAR_ ex, ey1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
      delta      = (int)( fy2 - ONE_PIXEL + first );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
      ras.area  += (TArea)two_fx * delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
      ras.cover += delta;
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
      goto End;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
    /* ok, we have to render several scanlines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    p     = ( ONE_PIXEL - fy1 ) * dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
    first = ONE_PIXEL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    incr  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
    if ( dy < 0 )
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
      p     = fy1 * dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
      first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
      incr  = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
      dy    = -dy;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
    delta = (int)( p / dy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    mod   = (int)( p % dy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    if ( mod < 0 )
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
      delta--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
      mod += (TCoord)dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    }
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
    x = ras.x + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
    gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, (TCoord)first );
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
    ey1 += incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
    gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
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
    if ( ey1 != ey2 )
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
      p     = ONE_PIXEL * dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
      lift  = (int)( p / dy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
      rem   = (int)( p % dy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
      if ( rem < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
        lift--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
        rem += (int)dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
      mod -= (int)dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
      while ( ey1 != ey2 )
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
        delta = lift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
        mod  += rem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
        if ( mod >= 0 )
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
          mod -= (int)dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
          delta++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
        x2 = x + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
        gray_render_scanline( RAS_VAR_ ey1, x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
                                       (TCoord)( ONE_PIXEL - first ), x2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
                                       (TCoord)first );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        x = x2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
        ey1 += incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
        gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
    gray_render_scanline( RAS_VAR_ ey1, x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
                                   (TCoord)( ONE_PIXEL - first ), to_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
                                   fy2 );
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
  End:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
    ras.x       = to_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
    ras.y       = to_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
    ras.last_ey = SUBPIXELS( ey2 );
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
  gray_split_conic( FT_Vector*  base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
    TPos  a, b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
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
    base[4].x = base[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    b = base[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    a = base[3].x = ( base[2].x + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    b = base[1].x = ( base[0].x + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    base[2].x = ( a + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
    base[4].y = base[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    b = base[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
    a = base[3].y = ( base[2].y + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
    b = base[1].y = ( base[0].y + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
    base[2].y = ( a + b ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
  gray_render_conic( RAS_ARG_ const FT_Vector*  control,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
                              const FT_Vector*  to )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
    TPos        dx, dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
    int         top, level;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
    int*        levels;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
    FT_Vector*  arc;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
    arc      = ras.bez_stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
    arc[0].x = UPSCALE( to->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
    arc[0].y = UPSCALE( to->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
    arc[1].x = UPSCALE( control->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
    arc[1].y = UPSCALE( control->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
    arc[2].x = ras.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
    arc[2].y = ras.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
    dx = FT_ABS( arc[2].x + arc[0].x - 2 * arc[1].x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    dy = FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
    if ( dx < dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      dx = dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
    level = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
    while ( dx > ONE_PIXEL / 6 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
      dx >>= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
      level++;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
    levels    = ras.lev_stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
    levels[0] = level;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
    top       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
      level = levels[top];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
      if ( level > 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
        /* check that the arc crosses the current band */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
        TPos  min, max, y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
        min = max = arc[0].y;
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
        y = arc[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
        if ( y < min ) min = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
        if ( y > max ) max = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
        y = arc[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
        if ( y < min ) min = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
        if ( y > max ) max = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
        if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < ras.min_ey )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
          goto Draw;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
        gray_split_conic( arc );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
        arc += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
        top++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
        levels[top] = levels[top - 1] = level - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
        continue;
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
    Draw:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
      gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
      top--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
      arc -= 2;
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
    } while ( top >= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
  gray_split_cubic( FT_Vector*  base )
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
    TPos  a, b, c, d;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
    base[6].x = base[3].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
    c = base[1].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
    d = base[2].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
    base[1].x = a = ( base[0].x + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    base[5].x = b = ( base[3].x + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
    c = ( c + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
    base[2].x = a = ( a + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
    base[4].x = b = ( b + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    base[3].x = ( a + b ) / 2;
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
    base[6].y = base[3].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
    c = base[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    d = base[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
    base[1].y = a = ( base[0].y + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
    base[5].y = b = ( base[3].y + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    c = ( c + d ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
    base[2].y = a = ( a + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
    base[4].y = b = ( b + c ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
    base[3].y = ( a + b ) / 2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
  gray_render_cubic( RAS_ARG_ const FT_Vector*  control1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
                              const FT_Vector*  control2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
                              const FT_Vector*  to )
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_Vector*  arc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
    arc      = ras.bez_stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
    arc[0].x = UPSCALE( to->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    arc[0].y = UPSCALE( to->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
    arc[1].x = UPSCALE( control2->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
    arc[1].y = UPSCALE( control2->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
    arc[2].x = UPSCALE( control1->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
    arc[2].y = UPSCALE( control1->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
    arc[3].x = ras.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
    arc[3].y = ras.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
      /* Check that the arc crosses the current band. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
      TPos  min, max, y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
      min = max = arc[0].y;
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
      y = arc[1].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
      if ( y < min )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
        min = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
      if ( y > max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
        max = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
      y = arc[2].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
      if ( y < min )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
        min = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
      if ( y > max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
        max = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
      y = arc[3].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
      if ( y < min )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
        min = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
      if ( y > max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
        max = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
      if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < ras.min_ey )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
        goto Draw;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
      /* Decide whether to split or draw. See `Rapid Termination          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
      /* Evaluation for Recursive Subdivision of Bezier Curves' by Thomas */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
      /* F. Hain, at                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
      /* http://www.cis.southalabama.edu/~hain/general/Publications/Bezier/Camera-ready%20CISST02%202.pdf */
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
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
        TPos  dx, dy, dx_, dy_;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
        TPos  dx1, dy1, dx2, dy2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
        TPos  L, s, s_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
        /* dx and dy are x and y components of the P0-P3 chord vector. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
        dx = arc[3].x - arc[0].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
        dy = arc[3].y - arc[0].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
        /* L is an (under)estimate of the Euclidean distance P0-P3.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
        /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
        /* If dx >= dy, then r = sqrt(dx^2 + dy^2) can be overestimated   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
        /* with least maximum error by                                    */
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
        /*   r_upperbound = dx + (sqrt(2) - 1) * dy  ,                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
        /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
        /* where sqrt(2) - 1 can be (over)estimated by 107/256, giving an */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
        /* error of no more than 8.4%.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
        /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
        /* Similarly, some elementary calculus shows that r can be        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
        /* underestimated with least maximum error by                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
        /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
        /*   r_lowerbound = sqrt(2 + sqrt(2)) / 2 * dx                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
        /*                  + sqrt(2 - sqrt(2)) / 2 * dy  .               */
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
        /* 236/256 and 97/256 are (under)estimates of the two algebraic   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
        /* numbers, giving an error of no more than 8.1%.                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
        dx_ = FT_ABS( dx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
        dy_ = FT_ABS( dy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
        /* This is the same as                     */
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
        /*   L = ( 236 * FT_MAX( dx_, dy_ )        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
        /*       + 97 * FT_MIN( dx_, dy_ ) ) >> 8; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
        L = ( dx_ > dy_ ? 236 * dx_ +  97 * dy_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
                        :  97 * dx_ + 236 * dy_ ) >> 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
        /* Avoid possible arithmetic overflow below by splitting. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
        if ( L > 32767 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
          goto Split;
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
        /* Max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1). */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
        s_limit = L * (TPos)( ONE_PIXEL / 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
        /* s is L * the perpendicular distance from P1 to the line P0-P3. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
        dx1 = arc[1].x - arc[0].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
        dy1 = arc[1].y - arc[0].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
        s = FT_ABS( dy * dx1 - dx * dy1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
        if ( s > s_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
          goto Split;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
        /* s is L * the perpendicular distance from P2 to the line P0-P3. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
        dx2 = arc[2].x - arc[0].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
        dy2 = arc[2].y - arc[0].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
        s = FT_ABS( dy * dx2 - dx * dy2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
        if ( s > s_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
          goto Split;
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 P1 or P2 is outside P0-P3, split the curve. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
        if ( dy * dy1 + dx * dx1 < 0                                     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
             dy * dy2 + dx * dx2 < 0                                     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
             dy * (arc[3].y - arc[1].y) + dx * (arc[3].x - arc[1].x) < 0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
             dy * (arc[3].y - arc[2].y) + dx * (arc[3].x - arc[2].x) < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
          goto Split;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
        /* No reason to split. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
        goto Draw;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
    Split:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
      gray_split_cubic( arc );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
      arc += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
      continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
    Draw:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
      gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
      if ( arc == ras.bez_stack )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
        return;
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
      arc -= 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
  gray_move_to( const FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
                PWorker           worker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
    TPos  x, y;
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
    /* record current cell, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
    gray_record_cell( RAS_VAR );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
    /* start to a new position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
    x = UPSCALE( to->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
    y = UPSCALE( to->y );
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
    gray_start_cell( RAS_VAR_ TRUNC( x ), TRUNC( y ) );
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
    worker->x = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
    worker->y = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
  gray_line_to( const FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
                PWorker           worker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
    gray_render_line( RAS_VAR_ UPSCALE( to->x ), UPSCALE( to->y ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
  gray_conic_to( const FT_Vector*  control,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
                 const FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
                 PWorker           worker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    gray_render_conic( RAS_VAR_ control, to );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
  gray_cubic_to( const FT_Vector*  control1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
                 const FT_Vector*  control2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
                 const FT_Vector*  to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
                 PWorker           worker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
    gray_render_cubic( RAS_VAR_ control1, control2, to );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
  gray_render_span( int             y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
                    int             count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
                    const FT_Span*  spans,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
                    PWorker         worker )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
    unsigned char*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
    FT_Bitmap*      map = &worker->target;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
    /* first of all, compute the scanline offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
    p = (unsigned char*)map->buffer - y * map->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
    if ( map->pitch >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      p += (unsigned)( ( map->rows - 1 ) * map->pitch );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
    for ( ; count > 0; count--, spans++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
      unsigned char  coverage = spans->coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
      if ( coverage )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
        /* For small-spans it is faster to do it by ourselves than
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
         * calling `memset'.  This is mainly due to the cost of the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
         * function call.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
        if ( spans->len >= 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
          FT_MEM_SET( p + spans->x, (unsigned char)coverage, spans->len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
          unsigned char*  q = p + spans->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
          switch ( spans->len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
          case 7: *q++ = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
          case 6: *q++ = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
          case 5: *q++ = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
          case 4: *q++ = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
          case 3: *q++ = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
          case 2: *q++ = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
          case 1: *q   = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
          default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
            ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
  gray_hline( RAS_ARG_ TCoord  x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
                       TCoord  y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
                       TPos    area,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
                       TCoord  acount )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
    FT_Span*  span;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
    int       count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
    int       coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
    /* compute the coverage line's coverage, depending on the    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
    /* outline fill rule                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
    /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
    /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
    /*                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
    coverage = (int)( area >> ( PIXEL_BITS * 2 + 1 - 8 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
                                                    /* use range 0..256 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
    if ( coverage < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
      coverage = -coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
    if ( ras.outline.flags & FT_OUTLINE_EVEN_ODD_FILL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
      coverage &= 511;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
      if ( coverage > 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
        coverage = 512 - coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
      else if ( coverage == 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
        coverage = 255;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
      /* normal non-zero winding rule */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
      if ( coverage >= 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
        coverage = 255;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
    y += (TCoord)ras.min_ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
    x += (TCoord)ras.min_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
    /* FT_Span.x is a 16-bit short, so limit our coordinates appropriately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
    if ( x >= 32767 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
      x = 32767;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
    /* FT_Span.y is an integer, so limit our coordinates appropriately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
    if ( y >= FT_INT_MAX )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
      y = FT_INT_MAX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
    if ( coverage )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
      /* see whether we can add this span to the current list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
      count = ras.num_gray_spans;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
      span  = ras.gray_spans + count - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
      if ( count > 0                          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
           ras.span_y == y                    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
           (int)span->x + span->len == (int)x &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
           span->coverage == coverage         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
        span->len = (unsigned short)( span->len + acount );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
      if ( ras.span_y != y || count >= FT_MAX_GRAY_SPANS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
        if ( ras.render_span && count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
          ras.render_span( ras.span_y, count, ras.gray_spans,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
                           ras.render_span_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
        if ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
          int  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
          FT_TRACE7(( "y = %3d ", ras.span_y ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
          span = ras.gray_spans;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
          for ( n = 0; n < count; n++, span++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
            FT_TRACE7(( "[%d..%d]:%02x ",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
                        span->x, span->x + span->len - 1, span->coverage ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
          FT_TRACE7(( "\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
#endif /* FT_DEBUG_LEVEL_TRACE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
        ras.num_gray_spans = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
        ras.span_y         = (int)y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
        count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
        span  = ras.gray_spans;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
        span++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
      /* add a gray span to the current list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
      span->x        = (short)x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
      span->len      = (unsigned short)acount;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
      span->coverage = (unsigned char)coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
      ras.num_gray_spans++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
  /* to be called while in the debugger --                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
  /* this function causes a compiler warning since it is unused otherwise */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
  gray_dump_cells( RAS_ARG )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
    int  yindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
    for ( yindex = 0; yindex < ras.ycount; yindex++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
      PCell  cell;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
      printf( "%3d:", yindex );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
      for ( cell = ras.ycells[yindex]; cell != NULL; cell = cell->next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
        printf( " (%3ld, c:%4ld, a:%6d)", cell->x, cell->cover, cell->area );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
      printf( "\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
#endif /* FT_DEBUG_LEVEL_TRACE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
  gray_sweep( RAS_ARG_ const FT_Bitmap*  target )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    int  yindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
    FT_UNUSED( target );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
    if ( ras.num_cells == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
    ras.num_gray_spans = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
    FT_TRACE7(( "gray_sweep: start\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
    for ( yindex = 0; yindex < ras.ycount; yindex++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
      PCell   cell  = ras.ycells[yindex];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
      TCoord  cover = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
      TCoord  x     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
      for ( ; cell != NULL; cell = cell->next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
        TPos  area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
        if ( cell->x > x && cover != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
          gray_hline( RAS_VAR_ x, yindex, cover * ( ONE_PIXEL * 2 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
                      cell->x - x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
        cover += cell->cover;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
        area   = cover * ( ONE_PIXEL * 2 ) - cell->area;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
        if ( area != 0 && cell->x >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
          gray_hline( RAS_VAR_ cell->x, yindex, area, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
        x = cell->x + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
      if ( cover != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
        gray_hline( RAS_VAR_ x, yindex, cover * ( ONE_PIXEL * 2 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
                    ras.count_ex - x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
    if ( ras.render_span && ras.num_gray_spans > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
      ras.render_span( ras.span_y, ras.num_gray_spans,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
                       ras.gray_spans, ras.render_span_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
    FT_TRACE7(( "gray_sweep: end\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
#ifdef _STANDALONE_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
  /*  The following function should only compile in stand-alone mode,      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
  /*  i.e., when building this component without the rest of FreeType.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
  /*    FT_Outline_Decompose                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
  /*    Walk over an outline's structure to decompose it into individual   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
  /*    segments and Bézier arcs.  This function is also able to emit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
  /*    `move to' and `close to' operations to indicate the start and end  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
  /*    of new contours in the outline.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
  /*    outline        :: A pointer to the source target.                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
  /*    func_interface :: A table of `emitters', i.e., function pointers   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
  /*                      called during decomposition to indicate path     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
  /*                      operations.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
  /*    user           :: A typeless pointer which is passed to each       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
  /*                      emitter during the decomposition.  It can be     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
  /*                      used to store the state during the               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
  /*                      decomposition.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
  /*    Error code.  0 means success.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
  FT_Outline_Decompose( const FT_Outline*        outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
                        const FT_Outline_Funcs*  func_interface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
                        void*                    user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
#undef SCALED
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
#define SCALED( x )  ( ( (x) << shift ) - delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
    FT_Vector   v_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
    FT_Vector   v_control;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
    FT_Vector   v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
    FT_Vector*  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
    FT_Vector*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
    char*       tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
    int         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
    int   n;         /* index of contour in outline     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
    int   first;     /* index of first point in contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
    char  tag;       /* current point's state           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
    int   shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
    TPos  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
    if ( !outline || !func_interface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
      return ErrRaster_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
    shift = func_interface->shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
    delta = func_interface->delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
    first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
    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
  1467
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
      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
  1469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
      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
  1472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
      last  = outline->contours[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
      if ( last < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
        goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
      limit = outline->points + last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
      v_start   = outline->points[first];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
      v_start.x = SCALED( v_start.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
      v_start.y = SCALED( v_start.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
      v_last   = outline->points[last];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
      v_last.x = SCALED( v_last.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
      v_last.y = SCALED( v_last.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
      v_control = v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
      point = outline->points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
      tags  = outline->tags   + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
      tag   = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
      /* 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
  1493
      if ( tag == FT_CURVE_TAG_CUBIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
        goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
      /* check first point to determine origin */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
      if ( tag == FT_CURVE_TAG_CONIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
        /* 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
  1500
        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
  1501
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
          /* 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
  1503
          v_start = v_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
          limit--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
          /* 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
  1509
          /* 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
  1510
          /* for closure                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
          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
  1512
          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
  1513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
          v_last = v_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
        point--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
        tags--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
      FT_TRACE5(( "  move to (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
                  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
  1522
      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
  1523
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
      while ( point < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
        point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
        tags++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
        tag = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
        switch ( tag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
        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
  1535
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
            FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
            vec.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
            vec.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
            FT_TRACE5(( "  line to (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
                        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
  1544
            error = func_interface->line_to( &vec, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
            if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
        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
  1551
          v_control.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
          v_control.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
        Do_Conic:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
          if ( point < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
            FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
            FT_Vector  v_middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
            point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
            tags++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
            tag = FT_CURVE_TAG( tags[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
            vec.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
            vec.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
            if ( tag == FT_CURVE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
              FT_TRACE5(( "  conic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
                          " with control (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
                          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
  1573
                          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
  1574
              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
  1575
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
              continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
            if ( tag != FT_CURVE_TAG_CONIC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
              goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
            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
  1584
            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
  1585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
            FT_TRACE5(( "  conic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
                        " with control (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
                        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
  1589
                        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
  1590
            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
  1591
            if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
            v_control = vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
            goto Do_Conic;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
          FT_TRACE5(( "  conic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
                      " with control (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
                      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
  1601
                      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
  1602
          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
  1603
          goto Close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
        default:  /* FT_CURVE_TAG_CUBIC */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
            FT_Vector  vec1, vec2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
            if ( point + 1 > limit                             ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
                 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
  1612
              goto Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
            point += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
            tags  += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
            vec1.x = SCALED( point[-2].x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
            vec1.y = SCALED( point[-2].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
            vec2.x = SCALED( point[-1].x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
            vec2.y = SCALED( point[-1].y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
            if ( point <= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
              FT_Vector  vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
              vec.x = SCALED( point->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
              vec.y = SCALED( point->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
              FT_TRACE5(( "  cubic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
                          " 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
  1633
                          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
  1634
                          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
  1635
                          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
  1636
              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
  1637
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
              continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
            FT_TRACE5(( "  cubic to (%.2f, %.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
                        " 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
  1644
                        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
  1645
                        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
  1646
                        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
  1647
            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
  1648
            goto Close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
      /* close the contour with a line segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
      FT_TRACE5(( "  line to (%.2f, %.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
                  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
  1656
      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
  1657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
   Close:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
      first = last + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
    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
  1666
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
    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
  1670
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
  Invalid_Outline:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
    return ErrRaster_Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
#endif /* _STANDALONE_ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
  typedef struct  TBand_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
    TPos  min, max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
  } TBand;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
    FT_DEFINE_OUTLINE_FUNCS(func_interface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
      (FT_Outline_MoveTo_Func) gray_move_to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
      (FT_Outline_LineTo_Func) gray_line_to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
      (FT_Outline_ConicTo_Func)gray_conic_to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
      (FT_Outline_CubicTo_Func)gray_cubic_to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
      0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
      0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
    )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
  gray_convert_glyph_inner( RAS_ARG )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
    volatile int  error = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
      FT_Outline_Funcs func_interface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
      Init_Class_func_interface(&func_interface);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
    if ( ft_setjmp( ras.jump_buffer ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
      error = FT_Outline_Decompose( &ras.outline, &func_interface, &ras );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
      gray_record_cell( RAS_VAR );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
      error = ErrRaster_Memory_Overflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
  gray_convert_glyph( RAS_ARG )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
    TBand            bands[40];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
    TBand* volatile  band;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
    int volatile     n, num_bands;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
    TPos volatile    min, max, max_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
    FT_BBox*         clip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
    /* Set up state in the raster object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
    gray_compute_cbox( RAS_VAR );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
    /* clip to target bitmap, exit if nothing to do */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
    clip = &ras.clip_box;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
    if ( ras.max_ex <= clip->xMin || ras.min_ex >= clip->xMax ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
         ras.max_ey <= clip->yMin || ras.min_ey >= clip->yMax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
    if ( ras.min_ex < clip->xMin ) ras.min_ex = clip->xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
    if ( ras.min_ey < clip->yMin ) ras.min_ey = clip->yMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
    if ( ras.max_ex > clip->xMax ) ras.max_ex = clip->xMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
    if ( ras.max_ey > clip->yMax ) ras.max_ey = clip->yMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
    ras.count_ex = ras.max_ex - ras.min_ex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
    ras.count_ey = ras.max_ey - ras.min_ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
    /* set up vertical bands */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
    num_bands = (int)( ( ras.max_ey - ras.min_ey ) / ras.band_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
    if ( num_bands == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
      num_bands = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
    if ( num_bands >= 39 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
      num_bands = 39;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
    ras.band_shoot = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
    min   = ras.min_ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
    max_y = ras.max_ey;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
    for ( n = 0; n < num_bands; n++, min = max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
      max = min + ras.band_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1761
      if ( n == num_bands - 1 || max > max_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
        max = max_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
      bands[0].min = min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
      bands[0].max = max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
      band         = bands;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
      while ( band >= bands )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
        TPos  bottom, top, middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
        int   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
          PCell  cells_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
          int    yindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
          long   cell_start, cell_end, cell_mod;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
          ras.ycells = (PCell*)ras.buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
          ras.ycount = band->max - band->min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
          cell_start = sizeof ( PCell ) * ras.ycount;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
          cell_mod   = cell_start % sizeof ( TCell );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
          if ( cell_mod > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
            cell_start += sizeof ( TCell ) - cell_mod;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
          cell_end  = ras.buffer_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
          cell_end -= cell_end % sizeof( TCell );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
          cells_max = (PCell)( (char*)ras.buffer + cell_end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
          ras.cells = (PCell)( (char*)ras.buffer + cell_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
          if ( ras.cells >= cells_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
            goto ReduceBands;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1794
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1795
          ras.max_cells = cells_max - ras.cells;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
          if ( ras.max_cells < 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
            goto ReduceBands;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1798
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1799
          for ( yindex = 0; yindex < ras.ycount; yindex++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1800
            ras.ycells[yindex] = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
        ras.num_cells = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
        ras.invalid   = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
        ras.min_ey    = band->min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
        ras.max_ey    = band->max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
        ras.count_ey  = band->max - band->min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
        error = gray_convert_glyph_inner( RAS_VAR );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
        if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
          gray_sweep( RAS_VAR_ &ras.target );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
          band--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
        else if ( error != ErrRaster_Memory_Overflow )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
          return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
      ReduceBands:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
        /* render pool overflow; we will reduce the render band by half */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
        bottom = band->min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
        top    = band->max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
        middle = bottom + ( ( top - bottom ) >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
        /* This is too complex for a single scanline; there must */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
        /* be some problems.                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
        if ( middle == bottom )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
          FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
          return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
        if ( bottom-top >= ras.band_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
          ras.band_shoot++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
        band[1].min = bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
        band[1].max = middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
        band[0].min = middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
        band[0].max = top;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
        band++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
    if ( ras.band_shoot > 8 && ras.band_size > 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
      ras.band_size = ras.band_size / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1855
  gray_raster_render( PRaster                  raster,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1856
                      const FT_Raster_Params*  params )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
    const FT_Outline*  outline    = (const FT_Outline*)params->source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
    const FT_Bitmap*   target_map = params->target;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
    PWorker            worker;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
    if ( !raster || !raster->buffer || !raster->buffer_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
      return ErrRaster_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
      return ErrRaster_Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
    /* return immediately if the outline is empty */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
    if ( outline->n_points == 0 || outline->n_contours <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
    if ( !outline->contours || !outline->points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
      return ErrRaster_Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
    if ( outline->n_points !=
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
           outline->contours[outline->n_contours - 1] + 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
      return ErrRaster_Invalid_Outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
    worker = raster->worker;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
    /* if direct mode is not set, we must have a target bitmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
    if ( !( params->flags & FT_RASTER_FLAG_DIRECT ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
      if ( !target_map )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
        return ErrRaster_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
      /* nothing to do */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
      if ( !target_map->width || !target_map->rows )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
        return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
      if ( !target_map->buffer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
        return ErrRaster_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
    /* this version does not support monochrome rendering */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
    if ( !( params->flags & FT_RASTER_FLAG_AA ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1898
      return ErrRaster_Invalid_Mode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
    /* compute clipping box */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
    if ( !( params->flags & FT_RASTER_FLAG_DIRECT ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
      /* compute clip box from target pixmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
      ras.clip_box.xMin = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
      ras.clip_box.yMin = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
      ras.clip_box.xMax = target_map->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
      ras.clip_box.yMax = target_map->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
    else if ( params->flags & FT_RASTER_FLAG_CLIP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
      ras.clip_box = params->clip_box;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
      ras.clip_box.xMin = -32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
      ras.clip_box.yMin = -32768L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
      ras.clip_box.xMax =  32767L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
      ras.clip_box.yMax =  32767L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
    gray_init_cells( RAS_VAR_ raster->buffer, raster->buffer_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
    ras.outline        = *outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
    ras.num_cells      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
    ras.invalid        = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
    ras.band_size      = raster->band_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
    ras.num_gray_spans = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
    if ( params->flags & FT_RASTER_FLAG_DIRECT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
      ras.render_span      = (FT_Raster_Span_Func)params->gray_spans;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
      ras.render_span_data = params->user;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
      ras.target           = *target_map;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
      ras.render_span      = (FT_Raster_Span_Func)gray_render_span;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
      ras.render_span_data = &ras;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
    return gray_convert_glyph( RAS_VAR );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
  /**** RASTER OBJECT CREATION: In stand-alone mode, we simply use *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
  /****                         a static object.                   *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
#ifdef _STANDALONE_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
  gray_raster_new( void*       memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
                   FT_Raster*  araster )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
    static TRaster  the_raster;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
    FT_UNUSED( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
    *araster = (FT_Raster)&the_raster;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
    FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
  gray_raster_done( FT_Raster  raster )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
    /* nothing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
    FT_UNUSED( raster );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
#else /* !_STANDALONE_ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
  gray_raster_new( FT_Memory   memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
                   FT_Raster*  araster )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
    PRaster   raster = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
    *araster = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
    if ( !FT_ALLOC( raster, sizeof ( TRaster ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
      raster->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
      *araster = (FT_Raster)raster;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
  gray_raster_done( FT_Raster  raster )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
    FT_Memory  memory = (FT_Memory)((PRaster)raster)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
    FT_FREE( raster );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
#endif /* !_STANDALONE_ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
  gray_raster_reset( FT_Raster  raster,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
                     char*      pool_base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
                     long       pool_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
    PRaster  rast = (PRaster)raster;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
    if ( raster )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
      if ( pool_base && pool_size >= (long)sizeof ( TWorker ) + 2048 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
        PWorker  worker = (PWorker)pool_base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
        rast->worker      = worker;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
        rast->buffer      = pool_base +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
                              ( ( sizeof ( TWorker ) + sizeof ( TCell ) - 1 ) &
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
                                ~( sizeof ( TCell ) - 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
        rast->buffer_size = (long)( ( pool_base + pool_size ) -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
                                    (char*)rast->buffer ) &
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
                                      ~( sizeof ( TCell ) - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
        rast->band_size   = (int)( rast->buffer_size /
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
                                     ( sizeof ( TCell ) * 8 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
        rast->buffer      = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
        rast->buffer_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
        rast->worker      = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
  FT_DEFINE_RASTER_FUNCS(ft_grays_raster,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
    FT_GLYPH_FORMAT_OUTLINE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
    (FT_Raster_New_Func)     gray_raster_new,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
    (FT_Raster_Reset_Func)   gray_raster_reset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
    (FT_Raster_Set_Mode_Func)0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
    (FT_Raster_Render_Func)  gray_raster_render,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
    (FT_Raster_Done_Func)    gray_raster_done
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
/* END */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
/* Local Variables: */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
/* coding: utf-8    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
/* End:             */