[CMAKE]
[reactos.git] / lib / 3rdparty / freetype / src / smooth / ftsmooth.c
index 85d04eb..eb12f18 100644 (file)
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Anti-aliasing renderer interface (body).                             */
 /*                                                                         */
-/*  Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006 by                   */
+/*  Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 by       */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
 
 
 #include <ft2build.h>
+#include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_OBJECTS_H
 #include FT_OUTLINE_H
 #include "ftsmooth.h"
 #include "ftgrays.h"
+#include "ftspic.h"
 
 #include "ftsmerrs.h"
 
     cbox.xMax = FT_PIX_CEIL( cbox.xMax );
     cbox.yMax = FT_PIX_CEIL( cbox.yMax );
 
-    width  = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
-    height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
+    if ( cbox.xMin < 0 && cbox.xMax > FT_INT_MAX + cbox.xMin )
+    {
+      FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
+                 " xMin = %d, xMax = %d\n",
+                 cbox.xMin >> 6, cbox.xMax >> 6 ));
+      return Smooth_Err_Raster_Overflow;
+    }
+    else
+      width  = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
+
+    if ( cbox.yMin < 0 && cbox.yMax > FT_INT_MAX + cbox.yMin )
+    {
+      FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
+                 " yMin = %d, yMax = %d\n",
+                 cbox.yMin >> 6, cbox.yMax >> 6 ));
+      return Smooth_Err_Raster_Overflow;
+    }
+    else
+      height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
+
     bitmap = &slot->bitmap;
     memory = render->root.memory;
 
       slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
     }
 
-    /* allocate new one, depends on pixel format */
+    /* allocate new one */
     pitch = width;
     if ( hmul )
     {
       }
     }
 
+#endif
+
+#if FT_UINT_MAX > 0xFFFFU
+
+    /* Required check is ( pitch * height < FT_ULONG_MAX ),     */
+    /* but we care realistic cases only. Always pitch <= width. */
+    if ( width > 0x7FFFU || height > 0x7FFFU )
+    {
+      FT_ERROR(( "ft_smooth_render_generic: glyph too large: %u x %u\n",
+                 width, height ));
+      return Smooth_Err_Raster_Overflow;
+    }
+
 #endif
 
     bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
 
       for ( hh = height_org; hh > 0; hh-- )
       {
-        memcpy( write, read, pitch );
+        ft_memcpy( write, read, pitch );
         write += pitch;
 
-        memcpy( write, read, pitch );
+        ft_memcpy( write, read, pitch );
         write += pitch;
 
-        memcpy( write, read, pitch );
+        ft_memcpy( write, read, pitch );
         write += pitch;
         read  += pitch;
       }
 
     FT_Outline_Translate( outline, x_shift, y_shift );
 
+    /*
+     * XXX: on 16bit system, we return an error for huge bitmap
+     * to prevent an overflow.
+     */
+    if ( x_left > FT_INT_MAX || y_top > FT_INT_MAX )
+      return Smooth_Err_Invalid_Pixel_Size;
+
     if ( error )
       goto Exit;
 
     slot->format      = FT_GLYPH_FORMAT_BITMAP;
-    slot->bitmap_left = x_left;
-    slot->bitmap_top  = y_top;
+    slot->bitmap_left = (FT_Int)x_left;
+    slot->bitmap_top  = (FT_Int)y_top;
 
   Exit:
     if ( outline && origin )
   }
 
 
-  FT_CALLBACK_TABLE_DEF
-  const FT_Renderer_Class  ft_smooth_renderer_class =
-  {
-    {
+  FT_DEFINE_RENDERER(ft_smooth_renderer_class,
+
       FT_MODULE_RENDERER,
       sizeof( FT_RendererRec ),
 
       (FT_Module_Constructor)ft_smooth_init,
       (FT_Module_Destructor) 0,
       (FT_Module_Requester)  0
-    },
+    ,
 
     FT_GLYPH_FORMAT_OUTLINE,
 
     (FT_Renderer_GetCBoxFunc)  ft_smooth_get_cbox,
     (FT_Renderer_SetModeFunc)  ft_smooth_set_mode,
 
-    (FT_Raster_Funcs*)    &ft_grays_raster
-  };
+    (FT_Raster_Funcs*)    &FT_GRAYS_RASTER_GET
+  )
 
 
-  FT_CALLBACK_TABLE_DEF
-  const FT_Renderer_Class  ft_smooth_lcd_renderer_class =
-  {
-    {
+  FT_DEFINE_RENDERER(ft_smooth_lcd_renderer_class,
+  
       FT_MODULE_RENDERER,
       sizeof( FT_RendererRec ),
 
       (FT_Module_Constructor)ft_smooth_init,
       (FT_Module_Destructor) 0,
       (FT_Module_Requester)  0
-    },
+    ,
 
     FT_GLYPH_FORMAT_OUTLINE,
 
     (FT_Renderer_GetCBoxFunc)  ft_smooth_get_cbox,
     (FT_Renderer_SetModeFunc)  ft_smooth_set_mode,
 
-    (FT_Raster_Funcs*)    &ft_grays_raster
-  };
-
+    (FT_Raster_Funcs*)    &FT_GRAYS_RASTER_GET
+  )
 
+  FT_DEFINE_RENDERER(ft_smooth_lcdv_renderer_class,
 
-  FT_CALLBACK_TABLE_DEF
-  const FT_Renderer_Class  ft_smooth_lcdv_renderer_class =
-  {
-    {
       FT_MODULE_RENDERER,
       sizeof( FT_RendererRec ),
 
       (FT_Module_Constructor)ft_smooth_init,
       (FT_Module_Destructor) 0,
       (FT_Module_Requester)  0
-    },
+    ,
 
     FT_GLYPH_FORMAT_OUTLINE,
 
     (FT_Renderer_GetCBoxFunc)  ft_smooth_get_cbox,
     (FT_Renderer_SetModeFunc)  ft_smooth_set_mode,
 
-    (FT_Raster_Funcs*)    &ft_grays_raster
-  };
+    (FT_Raster_Funcs*)    &FT_GRAYS_RASTER_GET
+  )
 
 
 /* END */