shithub: freetype+ttf2subf

Download patch

ref: c4f622c3411141e1dfa94813a6c111b67f4f233e
parent: 21939455dc98cd8c1e60eca8f9b05ba2404c0ca0
author: David Turner <[email protected]>
date: Sun Oct 7 06:39:03 EDT 2001

* src/smooth/ftgrays: "setjmp/longjmp" is now used for rollback (i.e.
	when memory pool overflow occurs), function names are now all prefixed
	with "gray_", and a new type (TArea) is defined to store area value in
	each cell (using "int" was too small on 16-bit systems)..

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-10-07  David Turner  <[email protected]>
+
+	* src/smooth/ftgrays: "setjmp/longjmp" is now used for rollback (i.e.
+	when memory pool overflow occurs), function names are now all prefixed
+	with "gray_", and a new type (TArea) is defined to store area value in
+	each cell (using "int" was too small on 16-bit systems)..
+
 2001-09-20  Detlef W�rkner  <[email protected]>
 
 	* builds/amiga/*: Added port to Amiga with the SAS/C compiler.
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    A new `perfect' anti-aliasing renderer (body).                       */
 /*                                                                         */
-/*  Copyright 2000-2001 by                                                 */
+/*  Copyright 2000 by                                                      */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -32,8 +32,8 @@
   /*      cc -c -D_STANDALONE_ ftgrays.c                                   */
   /*                                                                       */
   /*  The renderer can be initialized with a call to                       */
-  /*  `ft_grays_raster.grays_raster_new'; an anti-aliased bitmap can be    */
-  /*  generated with a call to `ft_grays_raster.grays_raster_render'.      */
+  /*  `ft_gray_raster.gray_raster_new'; an anti-aliased bitmap can be    */
+  /*  generated with a call to `ft_gray_raster.gray_raster_render'.      */
   /*                                                                       */
   /*  See the comments and documentation in the file `ftimage.h' for       */
   /*  more details on how the raster works.                                */
@@ -82,8 +82,8 @@
 
 
 #include <string.h>             /* for memcpy() */
+#include <setjmp.h>
 
-
   /*************************************************************************/
   /*                                                                       */
   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
@@ -94,6 +94,8 @@
 #define FT_COMPONENT  trace_aaraster
 
 
+#define ErrRaster_MemoryOverflow   -4
+
 #ifdef _STANDALONE_
 
 
@@ -199,9 +201,35 @@
   /*                                                                       */
   /*   TYPE DEFINITIONS                                                    */
   /*                                                                       */
+  
+ /* don't change the following types to FT_Int or FT_Pos, since we might */
+ /* need to define them to "float" or "double" when experimenting with   */
+ /* new algorithms..                                                     */
+
   typedef int   TScan;   /* integer scanline/pixel coordinate */
   typedef long  TPos;    /* sub-pixel coordinate              */
 
+ /* determine the type used to store cell areas. This normally takes at */
+ /* least PIXEL_BYTES*2 + 1, on 16-bit systems, we need to use 'longs'  */
+ /* instead of 'ints'.. otherwise bad things happen..                   */
+ 
+#if PIXEL_BITS <= 7
+
+  typedef int   TArea;
+
+#else /* PIXEL_BITS >= 8 */
+
+ /* approximately determine the size of integers using an ANSI-C header */
+#  include <limits.h>
+#  if UINT_MAX == 0xFFFFU
+  typedef long  TArea;
+#  else
+  typedef int   TArea;
+#  endif
+
+#endif /* PIXEL_BITS >= 8 */
+
+
   /* maximal number of gray spans in a call to the span callback */
 #define FT_MAX_GRAY_SPANS  32
 
@@ -224,7 +252,7 @@
     TScan  x;
     TScan  y;
     int    cover;
-    int    area;
+    TArea  area;
 
   } TCell, *PCell;
 
@@ -240,7 +268,7 @@
     TScan  min_ex, max_ex;
     TScan  min_ey, max_ey;
 
-    int    area;
+    TArea  area;
     int    cover;
     int    invalid;
 
@@ -264,12 +292,13 @@
     void*                render_span_data;
     int                  span_y;
 
-    int    band_size;
-    int    band_shoot;
-    int    conic_level;
-    int    cubic_level;
+    int     band_size;
+    int     band_shoot;
+    int     conic_level;
+    int     cubic_level;
 
-    void*  memory;
+    void*   memory;
+    jmp_buf  jump_buffer;
 
   } TRaster, *PRaster;
 
@@ -279,8 +308,8 @@
   /* Initialize the cells table.                                           */
   /*                                                                       */
   static void
-  init_cells( RAS_ARG_ void*  buffer,
-                       long   byte_size )
+  gray_init_cells( RAS_ARG_ void*  buffer,
+                   long            byte_size )
   {
     ras.cells     = (PCell)buffer;
     ras.max_cells = byte_size / sizeof ( TCell );
@@ -296,10 +325,11 @@
   /* Compute the outline bounding box.                                     */
   /*                                                                       */
   static void
-  compute_cbox( RAS_ARG_ FT_Outline*  outline )
+  gray_compute_cbox( RAS_ARG )
   {
-    FT_Vector*  vec   = outline->points;
-    FT_Vector*  limit = vec + outline->n_points;
+    FT_Outline*  outline = &ras.outline;
+    FT_Vector*   vec     = outline->points;
+    FT_Vector*   limit   = vec + outline->n_points;
 
 
     if ( outline->n_points <= 0 )
@@ -338,8 +368,8 @@
   /*                                                                       */
   /* Record the current cell in the table.                                 */
   /*                                                                       */
-  static int
-  record_cell( RAS_ARG )
+  static void
+  gray_record_cell( RAS_ARG )
   {
     PCell  cell;
 
@@ -347,7 +377,7 @@
     if ( !ras.invalid && ( ras.area | ras.cover ) )
     {
       if ( ras.num_cells >= ras.max_cells )
-        return 1;
+        longjmp( ras.jump_buffer, 1 );
 
       cell        = ras.cells + ras.num_cells++;
       cell->x     = ras.ex - ras.min_ex;
@@ -355,8 +385,6 @@
       cell->area  = ras.area;
       cell->cover = ras.cover;
     }
-
-    return 0;
   }
 
 
@@ -364,9 +392,9 @@
   /*                                                                       */
   /* Set the current cell to a new position.                               */
   /*                                                                       */
-  static int
-  set_cell( RAS_ARG_ TScan  ex,
-                     TScan  ey )
+  static void
+  gray_set_cell( RAS_ARG_ TScan  ex,
+                          TScan  ey )
   {
     int  invalid, record, clean;
 
@@ -402,8 +430,8 @@
 
     /* record the previous cell if needed (i.e., if we changed the cell */
     /* position, of changed the `invalid' flag)                         */
-    if ( ( ras.invalid != invalid || record ) && record_cell( RAS_VAR ) )
-      return 1;
+    if ( ras.invalid != invalid || record )
+      gray_record_cell( RAS_VAR );
 
     if ( clean )
     {
@@ -414,7 +442,6 @@
     ras.invalid = invalid;
     ras.ex      = ex;
     ras.ey      = ey;
-    return 0;
   }
 
 
@@ -423,8 +450,8 @@
   /* Start a new contour at a given cell.                                  */
   /*                                                                       */
   static void
-  start_cell( RAS_ARG_  TScan  ex,
-                        TScan  ey )
+  gray_start_cell( RAS_ARG_  TScan  ex,
+                             TScan  ey )
   {
     if ( ex < ras.min_ex )
       ex = ras.min_ex - 1;
@@ -436,7 +463,7 @@
     ras.last_ey = SUBPIXELS( ey );
     ras.invalid = 0;
 
-    (void)set_cell( RAS_VAR_ ex, ey );
+    gray_set_cell( RAS_VAR_ ex, ey );
   }
 
 
@@ -444,12 +471,12 @@
   /*                                                                       */
   /* Render a scanline as one or more cells.                               */
   /*                                                                       */
-  static int
-  render_scanline( RAS_ARG_  TScan  ey,
-                             TPos   x1,
-                             TScan  y1,
-                             TPos   x2,
-                             TScan  y2 )
+  static void
+  gray_render_scanline( RAS_ARG_  TScan  ey,
+                                  TPos   x1,
+                                  TScan  y1,
+                                  TPos   x2,
+                                  TScan  y2 )
   {
     TScan  ex1, ex2, fx1, fx2, delta;
     long   p, first, dx;
@@ -465,7 +492,10 @@
 
     /* trivial case.  Happens often */
     if ( y1 == y2 )
-      return set_cell( RAS_VAR_ ex2, ey );
+    {
+      gray_set_cell( RAS_VAR_ ex2, ey );
+      return;
+    }
 
     /* everything is located in a single cell.  That is easy! */
     /*                                                        */
@@ -472,9 +502,9 @@
     if ( ex1 == ex2 )
     {
       delta      = y2 - y1;
-      ras.area  += ( fx1 + fx2 ) * delta;
+      ras.area  += (TArea)( fx1 + fx2 ) * delta;
       ras.cover += delta;
-      return 0;
+      return;
     }
 
     /* ok, we'll have to render a run of adjacent cells on the same */
@@ -500,12 +530,11 @@
       mod += dx;
     }
 
-    ras.area  += ( fx1 + first ) * delta;
+    ras.area  += (TArea)( fx1 + first ) * delta;
     ras.cover += delta;
 
     ex1 += incr;
-    if ( set_cell( RAS_VAR_ ex1, ey ) )
-      goto Error;
+    gray_set_cell( RAS_VAR_ ex1, ey );
     y1  += delta;
 
     if ( ex1 != ex2 )
@@ -531,23 +560,17 @@
           delta++;
         }
 
-        ras.area  += ONE_PIXEL * delta;
+        ras.area  += (TArea)ONE_PIXEL * delta;
         ras.cover += delta;
         y1        += delta;
         ex1       += incr;
-        if ( set_cell( RAS_VAR_ ex1, ey ) )
-          goto Error;
+        gray_set_cell( RAS_VAR_ ex1, ey );
       }
     }
 
     delta      = y2 - y1;
-    ras.area  += ( fx2 + ONE_PIXEL - first ) * delta;
+    ras.area  += (TArea)( fx2 + ONE_PIXEL - first ) * delta;
     ras.cover += delta;
-
-    return 0;
-
-  Error:
-    return 1;
   }
 
 
@@ -555,9 +578,9 @@
   /*                                                                       */
   /* Render a given line as a series of scanlines.                         */
   /*                                                                       */
-  static int
-  render_line( RAS_ARG_ TPos  to_x,
-                        TPos  to_y )
+  static void
+  gray_render_line( RAS_ARG_ TPos  to_x,
+                             TPos  to_y )
   {
     TScan  ey1, ey2, fy1, fy2;
     TPos   dx, dy, x, x2;
@@ -594,8 +617,7 @@
     /* everything is on a single scanline */
     if ( ey1 == ey2 )
     {
-      if ( render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 ) )
-        goto Error;
+      gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 );
       goto End;
     }
 
@@ -621,12 +643,10 @@
     }
 
     x = ras.x + delta;
-    if ( render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first ) )
-      goto Error;
+    gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first );
 
     ey1 += incr;
-    if ( set_cell( RAS_VAR_ TRUNC( x ), ey1 ) )
-      goto Error;
+    gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
 
     if ( ey1 != ey2 )
     {
@@ -651,34 +671,25 @@
         }
 
         x2 = x + delta;
-        if ( render_scanline( RAS_VAR_ ey1,
-                              x, ONE_PIXEL - first, x2, first ) )
-          goto Error;
+        gray_render_scanline( RAS_VAR_ ey1, x, ONE_PIXEL - first, x2, first );
         x = x2;
+
         ey1 += incr;
-        if ( set_cell( RAS_VAR_ TRUNC( x ), ey1 ) )
-          goto Error;
+        gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
       }
     }
 
-    if ( render_scanline( RAS_VAR_ ey1,
-                          x, ONE_PIXEL - first, to_x, fy2 ) )
-      goto Error;
+    gray_render_scanline( RAS_VAR_ ey1, x, ONE_PIXEL - first, to_x, fy2 );
 
   End:
     ras.x       = to_x;
     ras.y       = to_y;
     ras.last_ey = SUBPIXELS( ey2 );
-
-    return 0;
-
-  Error:
-    return 1;
   }
 
 
   static void
-  split_conic( FT_Vector*  base )
+  gray_split_conic( FT_Vector*  base )
   {
     TPos  a, b;
 
@@ -697,9 +708,9 @@
   }
 
 
-  static int
-  render_conic( RAS_ARG_ FT_Vector*  control,
-                         FT_Vector*  to )
+  static void
+  gray_render_conic( RAS_ARG_ FT_Vector*  control,
+                              FT_Vector*  to )
   {
     TPos        dx, dy;
     int         top, level;
@@ -728,7 +739,7 @@
     if ( level <= 1 )
     {
       /* we compute the mid-point directly in order to avoid */
-      /* calling split_conic()                               */
+      /* calling gray_split_conic()                               */
       TPos   to_x, to_y, mid_x, mid_y;
 
 
@@ -737,8 +748,9 @@
       mid_x = ( ras.x + to_x + 2 * UPSCALE( control->x ) ) / 4;
       mid_y = ( ras.y + to_y + 2 * UPSCALE( control->y ) ) / 4;
 
-      return render_line( RAS_VAR_ mid_x, mid_y ) ||
-             render_line( RAS_VAR_ to_x, to_y );
+      gray_render_line( RAS_VAR_ mid_x, mid_y );
+      gray_render_line( RAS_VAR_ to_x, to_y );
+      return;
     }
 
     arc       = ras.bez_stack;
@@ -775,7 +787,7 @@
         if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < 0 )
           goto Draw;
 
-        split_conic( arc );
+        gray_split_conic( arc );
         arc += 2;
         top++;
         levels[top] = levels[top - 1] = level - 1;
@@ -792,20 +804,19 @@
         mid_x = ( ras.x + to_x + 2 * arc[1].x ) / 4;
         mid_y = ( ras.y + to_y + 2 * arc[1].y ) / 4;
 
-        if ( render_line( RAS_VAR_ mid_x, mid_y ) ||
-             render_line( RAS_VAR_ to_x, to_y )   )
-          return 1;
+        gray_render_line( RAS_VAR_ mid_x, mid_y );
+        gray_render_line( RAS_VAR_ to_x, to_y );
 
         top--;
         arc -= 2;
       }
     }
-    return 0;
+    return;
   }
 
 
   static void
-  split_cubic( FT_Vector*  base )
+  gray_split_cubic( FT_Vector*  base )
   {
     TPos  a, b, c, d;
 
@@ -832,10 +843,10 @@
   }
 
 
-  static int
-  render_cubic( RAS_ARG_ FT_Vector*  control1,
-                         FT_Vector*  control2,
-                         FT_Vector*  to )
+  static void
+  gray_render_cubic( RAS_ARG_ FT_Vector*  control1,
+                              FT_Vector*  control2,
+                              FT_Vector*  to )
   {
     TPos        dx, dy, da, db;
     int         top, level;
@@ -885,8 +896,9 @@
       mid_y = ( ras.y + to_y +
                 3 * UPSCALE( control1->y + control2->y ) ) / 8;
 
-      return render_line( RAS_VAR_ mid_x, mid_y ) ||
-             render_line( RAS_VAR_ to_x, to_y );
+      gray_render_line( RAS_VAR_ mid_x, mid_y );
+      gray_render_line( RAS_VAR_ to_x, to_y );
+      return;
     }
 
     arc      = ras.bez_stack;
@@ -924,7 +936,7 @@
         if ( y > max ) max = y;
         if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < 0 )
           goto Draw;
-        split_cubic( arc );
+        gray_split_cubic( arc );
         arc += 3;
         top ++;
         levels[top] = levels[top - 1] = level - 1;
@@ -941,14 +953,13 @@
         mid_x = ( ras.x + to_x + 3 * ( arc[1].x + arc[2].x ) ) / 8;
         mid_y = ( ras.y + to_y + 3 * ( arc[1].y + arc[2].y ) ) / 8;
 
-        if ( render_line( RAS_VAR_ mid_x, mid_y ) ||
-             render_line( RAS_VAR_ to_x, to_y )   )
-          return 1;
+        gray_render_line( RAS_VAR_ mid_x, mid_y );
+        gray_render_line( RAS_VAR_ to_x, to_y );
         top --;
         arc -= 3;
       }
     }
-    return 0;
+    return;
   }
 
 
@@ -979,8 +990,8 @@
   /* a simple shell sort algorithm that works directly on our */
   /* cells table                                              */
   static void
-  shell_sort ( PCell  cells,
-               int    count )
+  gray_shell_sort ( PCell  cells,
+                    int    count )
   {
     PCell  i, j, limit = cells + count;
     TCell  temp;
@@ -1025,8 +1036,8 @@
                             /* through a normal insertion sort             */
 
   static void
-  quick_sort( PCell  cells,
-              int    count )
+  gray_quick_sort( PCell  cells,
+                   int    count )
   {
     PCell   stack[40];  /* should be enough ;-) */
     PCell*  top;        /* top of stack */
@@ -1125,8 +1136,8 @@
 #ifdef DEBUG_SORT
 
   static int
-  check_sort( PCell  cells,
-              int    count )
+  gray_check_sort( PCell  cells,
+                   int    count )
   {
     PCell  p, q;
 
@@ -1145,19 +1156,21 @@
 
 
   static int
-  Move_To( FT_Vector*  to,
-           FT_Raster   raster )
+  gray_move_to( FT_Vector*  to,
+                FT_Raster   raster )
   {
     TPos  x, y;
 
 
     /* record current cell, if any */
-    record_cell( (PRaster)raster );
+    gray_record_cell( (PRaster)raster );
 
     /* start to a new position */
     x = UPSCALE( to->x );
     y = UPSCALE( to->y );
-    start_cell( (PRaster)raster, TRUNC( x ), TRUNC( y ) );
+    
+    gray_start_cell( (PRaster)raster, TRUNC( x ), TRUNC( y ) );
+      
     ((PRaster)raster)->x = x;
     ((PRaster)raster)->y = y;
     return 0;
@@ -1165,38 +1178,41 @@
 
 
   static int
-  Line_To( FT_Vector*  to,
-           FT_Raster   raster )
+  gray_line_to( FT_Vector*  to,
+                FT_Raster   raster )
   {
-    return render_line( (PRaster)raster,
-                        UPSCALE( to->x ), UPSCALE( to->y ) );
+    gray_render_line( (PRaster)raster,
+                  UPSCALE( to->x ), UPSCALE( to->y ) );
+    return 0;
   }
 
 
   static int
-  Conic_To( FT_Vector*  control,
-            FT_Vector*  to,
-            FT_Raster   raster )
+  gray_conic_to( FT_Vector*  control,
+                 FT_Vector*  to,
+                 FT_Raster   raster )
   {
-    return render_conic( (PRaster)raster, control, to );
+    gray_render_conic( (PRaster)raster, control, to );
+    return 0;
   }
 
 
   static int
-  Cubic_To( FT_Vector*  control1,
-            FT_Vector*  control2,
-            FT_Vector*  to,
-            FT_Raster   raster )
+  gray_cubic_to( FT_Vector*  control1,
+                 FT_Vector*  control2,
+                 FT_Vector*  to,
+                 FT_Raster   raster )
   {
-    return render_cubic( (PRaster)raster, control1, control2, to );
+    gray_render_cubic( (PRaster)raster, control1, control2, to );
+    return 0;
   }
 
 
   static void
-  grays_render_span( int       y,
-                     int       count,
-                     FT_Span*  spans,
-                     PRaster   raster )
+  gray_render_span( int       y,
+                    int       count,
+                    FT_Span*  spans,
+                    PRaster   raster )
   {
     unsigned char*  p;
     FT_Bitmap*      map = &raster->target;
@@ -1229,7 +1245,7 @@
 #include <stdio.h>
 
   static void
-  dump_cells( RAS_ARG )
+  gray_dump_cells( RAS_ARG )
   {
     PCell  cell, limit;
     int    y = -1;
@@ -1255,10 +1271,10 @@
 
 
   static void
-  grays_hline( RAS_ARG_ TScan  x,
-                        TScan  y,
-                        TPos   area,
-                        int    acount )
+  gray_hline( RAS_ARG_ TScan  x,
+                       TScan  y,
+                       TPos   area,
+                       int    acount )
   {
     FT_Span*   span;
     int        count;
@@ -1355,9 +1371,10 @@
 
 
   static void
-  grays_sweep( RAS_ARG_ FT_Bitmap*  target )
+  gray_sweep( RAS_ARG_ FT_Bitmap*  target )
   {
-    TScan  x, y, cover, area;
+    TScan  x, y, cover;
+    TArea  area;
     PCell  start, cur, limit;
 
     FT_UNUSED( target );
@@ -1364,7 +1381,7 @@
 
     if ( ras.num_cells == 0 )
       return;
-
+      
     cur   = ras.cells;
     limit = cur + ras.num_cells;
 
@@ -1396,7 +1413,7 @@
       /* individual gray pixel there                            */
       if ( area && x >= 0 )
       {
-        grays_hline( RAS_VAR_ x, y, cover * ( ONE_PIXEL * 2 ) - area, 1 );
+        gray_hline( RAS_VAR_ x, y, cover * ( ONE_PIXEL * 2 ) - area, 1 );
         x++;
       }
 
@@ -1407,7 +1424,7 @@
       {
         /* draw a gray span between the start cell and the current one */
         if ( cur->x > x )
-          grays_hline( RAS_VAR_ x, y,
+          gray_hline( RAS_VAR_ x, y,
                        cover * ( ONE_PIXEL * 2 ), cur->x - x );
       }
       else
@@ -1414,7 +1431,7 @@
       {
         /* draw a gray span until the end of the clipping region */
         if ( cover && x < ras.max_ex - ras.min_ex )
-          grays_hline( RAS_VAR_ x, y,
+          gray_hline( RAS_VAR_ x, y,
                        cover * ( ONE_PIXEL * 2 ),
                        ras.max_ex - x - ras.min_ex );
         cover = 0;
@@ -1481,13 +1498,17 @@
   /* <Return>                                                              */
   /*    Error code.  0 means sucess.                                       */
   /*                                                                       */
-  static int
-  FT_Outline_Decompose( FT_Outline*              outline,
-                        const FT_Outline_Funcs*  interface,
-                        void*                    user )
+  static
+  int  FT_Outline_Decompose( FT_Outline*              outline,
+                             const FT_Outline_Funcs*  interface,
+                             void*                    user )
   {
 #undef SCALED
-#define SCALED( x )  ( ( (x) << shift ) - delta )
+#if 0
+#  define SCALED( x )  ( ( (x) << shift ) - delta )
+#else
+#  define SCALED( x)   (x)
+#endif
 
     FT_Vector   v_last;
     FT_Vector   v_control;
@@ -1502,8 +1523,10 @@
     int     error;
     char    tag;       /* current point's state           */
 
+#if 0
     int     shift = interface->shift;
     FT_Pos  delta = interface->delta;
+#endif
 
 
     first = 0;
@@ -1692,19 +1715,38 @@
 
 
   static int
-  grays_convert_glyph( RAS_ARG_ FT_Outline*  outline )
+  gray_convert_glyph_inner( RAS_ARG )
   {
     static
     const FT_Outline_Funcs  interface =
     {
-      (FT_Outline_MoveTo_Func) Move_To,
-      (FT_Outline_LineTo_Func) Line_To,
-      (FT_Outline_ConicTo_Func)Conic_To,
-      (FT_Outline_CubicTo_Func)Cubic_To,
+      (FT_Outline_MoveTo_Func)  gray_move_to,
+      (FT_Outline_LineTo_Func)  gray_line_to,
+      (FT_Outline_ConicTo_Func) gray_conic_to,
+      (FT_Outline_CubicTo_Func) gray_cubic_to,
       0,
       0
     };
 
+    volatile int  error = 0;
+    
+    if ( setjmp( ras.jump_buffer ) == 0 )
+    {
+      error = FT_Outline_Decompose( &ras.outline, &interface, &ras );
+      gray_record_cell( RAS_VAR );
+    }
+    else
+    {
+      error = ErrRaster_MemoryOverflow;
+    }
+
+    return error;
+  }
+
+
+  static int
+  gray_convert_glyph( RAS_ARG )
+  {
     TBand     bands[40], *band;
     int       n, num_bands;
     TPos      min, max, max_y;
@@ -1712,11 +1754,11 @@
 
 
     /* Set up state in the raster object */
-    compute_cbox( RAS_VAR_ outline );
+    gray_compute_cbox( RAS_VAR );
 
     /* clip to target bitmap, exit if nothing to do */
     clip = &ras.clip_box;
-
+    
     if ( ras.max_ex <= clip->xMin || ras.min_ex >= clip->xMax ||
          ras.max_ey <= clip->yMin || ras.min_ey >= clip->yMax )
       return 0;
@@ -1728,7 +1770,7 @@
     if ( ras.max_ey > clip->yMax ) ras.max_ey = clip->yMax;
 
     /* simple heuristic used to speed-up the bezier decomposition -- see */
-    /* the code in render_conic() and render_cubic() for more details    */
+    /* the code in gray_render_conic() and gray_render_cubic() for more details    */
     ras.conic_level = 32;
     ras.cubic_level = 16;
 
@@ -1776,26 +1818,32 @@
         ras.min_ey    = band->min;
         ras.max_ey    = band->max;
 
+#if 1
+        error = gray_convert_glyph_inner( RAS_VAR );
+#else       
         error = FT_Outline_Decompose( outline, &interface, &ras ) ||
-                record_cell( RAS_VAR );
+                gray_record_cell( RAS_VAR );
+#endif
 
         if ( !error )
         {
 #ifdef SHELL_SORT
-          shell_sort( ras.cells, ras.num_cells );
+          gray_shell_sort( ras.cells, ras.num_cells );
 #else
-          quick_sort( ras.cells, ras.num_cells );
+          gray_quick_sort( ras.cells, ras.num_cells );
 #endif
 
 #ifdef DEBUG_GRAYS
-          check_sort( ras.cells, ras.num_cells );
-          dump_cells( RAS_VAR );
+          gray_check_sort( ras.cells, ras.num_cells );
+          gray_dump_cells( RAS_VAR );
 #endif
 
-          grays_sweep( RAS_VAR_  &ras.target );
+          gray_sweep( RAS_VAR_  &ras.target );
           band--;
           continue;
         }
+        else if ( error != ErrRaster_MemoryOverflow )
+          return 1;
 
         /* render pool overflow, we will reduce the render band by half */
         bottom = band->min;
@@ -1831,8 +1879,8 @@
 
 
   extern int
-  grays_raster_render( PRaster            raster,
-                       FT_Raster_Params*  params )
+  gray_raster_render( PRaster            raster,
+                      FT_Raster_Params*  params )
   {
     FT_Outline*  outline = (FT_Outline*)params->source;
     FT_Bitmap*   target_map = params->target;
@@ -1889,7 +1937,7 @@
     if ( target_map )
       ras.target = *target_map;
 
-    ras.render_span      = (FT_Raster_Span_Func)grays_render_span;
+    ras.render_span      = (FT_Raster_Span_Func)gray_render_span;
     ras.render_span_data = &ras;
 
     if ( params->flags & ft_raster_flag_direct )
@@ -1898,7 +1946,7 @@
       ras.render_span_data = params->user;
     }
 
-    return grays_convert_glyph( (PRaster)raster, outline );
+    return gray_convert_glyph( (PRaster)raster );
   }
 
 
@@ -1908,8 +1956,8 @@
 #ifdef _STANDALONE_
 
   static int
-  grays_raster_new( void*       memory,
-                    FT_Raster*  araster )
+  gray_raster_new( void*       memory,
+                   FT_Raster*  araster )
   {
     static TRaster  the_raster;
 
@@ -1924,7 +1972,7 @@
 
 
   static void
-  grays_raster_done( FT_Raster  raster )
+  gray_raster_done( FT_Raster  raster )
   {
     /* nothing */
     FT_UNUSED( raster );
@@ -1933,8 +1981,8 @@
 #else /* _STANDALONE_ */
 
   static int
-  grays_raster_new( FT_Memory   memory,
-                    FT_Raster*  araster )
+  gray_raster_new( FT_Memory   memory,
+                   FT_Raster*  araster )
   {
     FT_Error  error;
     PRaster   raster;
@@ -1952,7 +2000,7 @@
 
 
   static void
-  grays_raster_done( FT_Raster  raster )
+  gray_raster_done( FT_Raster  raster )
   {
     FT_Memory  memory = (FT_Memory)((PRaster)raster)->memory;
 
@@ -1964,15 +2012,15 @@
 
 
   static void
-  grays_raster_reset( FT_Raster    raster,
-                      const char*  pool_base,
-                      long         pool_size )
+  gray_raster_reset( FT_Raster    raster,
+                     const char*  pool_base,
+                     long         pool_size )
   {
     PRaster  rast = (PRaster)raster;
 
 
     if ( raster && pool_base && pool_size >= 4096 )
-      init_cells( rast, (char*)pool_base, pool_size );
+      gray_init_cells( rast, (char*)pool_base, pool_size );
 
     rast->band_size  = ( pool_size / sizeof ( TCell ) ) / 8;
   }
@@ -1982,11 +2030,11 @@
   {
     ft_glyph_format_outline,
 
-    (FT_Raster_New_Func)     grays_raster_new,
-    (FT_Raster_Reset_Func)   grays_raster_reset,
-    (FT_Raster_Set_Mode_Func)0,
-    (FT_Raster_Render_Func)  grays_raster_render,
-    (FT_Raster_Done_Func)    grays_raster_done
+    (FT_Raster_New_Func)      gray_raster_new,
+    (FT_Raster_Reset_Func)    gray_raster_reset,
+    (FT_Raster_Set_Mode_Func) 0,
+    (FT_Raster_Render_Func)   gray_raster_render,
+    (FT_Raster_Done_Func)     gray_raster_done
   };