- Remove svn:needs-lock, svn:eol-type, and svn:eol-tyle properties.
[reactos.git] / reactos / lib / 3rdparty / freetype / src / raster / ftrend1.c
index afc8f9a..3cc8d07 100644 (file)
-/***************************************************************************/\r
-/*                                                                         */\r
-/*  ftrend1.c                                                              */\r
-/*                                                                         */\r
-/*    The FreeType glyph rasterizer interface (body).                      */\r
-/*                                                                         */\r
-/*  Copyright 1996-2001, 2002, 2003, 2005, 2006 by                         */\r
-/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */\r
-/*                                                                         */\r
-/*  This file is part of the FreeType project, and may only be used,       */\r
-/*  modified, and distributed under the terms of the FreeType project      */\r
-/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */\r
-/*  this file you indicate that you have read the license and              */\r
-/*  understand and accept it fully.                                        */\r
-/*                                                                         */\r
-/***************************************************************************/\r
-\r
-\r
-#include <ft2build.h>\r
-#include FT_INTERNAL_OBJECTS_H\r
-#include FT_OUTLINE_H\r
-#include "ftrend1.h"\r
-#include "ftraster.h"\r
-\r
-#include "rasterrs.h"\r
-\r
-\r
-  /* initialize renderer -- init its raster */\r
-  static FT_Error\r
-  ft_raster1_init( FT_Renderer  render )\r
-  {\r
-    FT_Library  library = FT_MODULE_LIBRARY( render );\r
-\r
-\r
-    render->clazz->raster_class->raster_reset( render->raster,\r
-                                               library->raster_pool,\r
-                                               library->raster_pool_size );\r
-\r
-    return Raster_Err_Ok;\r
-  }\r
-\r
-\r
-  /* set render-specific mode */\r
-  static FT_Error\r
-  ft_raster1_set_mode( FT_Renderer  render,\r
-                       FT_ULong     mode_tag,\r
-                       FT_Pointer   data )\r
-  {\r
-    /* we simply pass it to the raster */\r
-    return render->clazz->raster_class->raster_set_mode( render->raster,\r
-                                                         mode_tag,\r
-                                                         data );\r
-  }\r
-\r
-\r
-  /* transform a given glyph image */\r
-  static FT_Error\r
-  ft_raster1_transform( FT_Renderer       render,\r
-                        FT_GlyphSlot      slot,\r
-                        const FT_Matrix*  matrix,\r
-                        const FT_Vector*  delta )\r
-  {\r
-    FT_Error error = Raster_Err_Ok;\r
-\r
-\r
-    if ( slot->format != render->glyph_format )\r
-    {\r
-      error = Raster_Err_Invalid_Argument;\r
-      goto Exit;\r
-    }\r
-\r
-    if ( matrix )\r
-      FT_Outline_Transform( &slot->outline, matrix );\r
-\r
-    if ( delta )\r
-      FT_Outline_Translate( &slot->outline, delta->x, delta->y );\r
-\r
-  Exit:\r
-    return error;\r
-  }\r
-\r
-\r
-  /* return the glyph's control box */\r
-  static void\r
-  ft_raster1_get_cbox( FT_Renderer   render,\r
-                       FT_GlyphSlot  slot,\r
-                       FT_BBox*      cbox )\r
-  {\r
-    FT_MEM_ZERO( cbox, sizeof ( *cbox ) );\r
-\r
-    if ( slot->format == render->glyph_format )\r
-      FT_Outline_Get_CBox( &slot->outline, cbox );\r
-  }\r
-\r
-\r
-  /* convert a slot's glyph image into a bitmap */\r
-  static FT_Error\r
-  ft_raster1_render( FT_Renderer       render,\r
-                     FT_GlyphSlot      slot,\r
-                     FT_Render_Mode    mode,\r
-                     const FT_Vector*  origin )\r
-  {\r
-    FT_Error     error;\r
-    FT_Outline*  outline;\r
-    FT_BBox      cbox;\r
-    FT_UInt      width, height, pitch;\r
-    FT_Bitmap*   bitmap;\r
-    FT_Memory    memory;\r
-\r
-    FT_Raster_Params  params;\r
-\r
-\r
-    /* check glyph image format */\r
-    if ( slot->format != render->glyph_format )\r
-    {\r
-      error = Raster_Err_Invalid_Argument;\r
-      goto Exit;\r
-    }\r
-\r
-    /* check rendering mode */\r
-    if ( mode != FT_RENDER_MODE_MONO )\r
-    {\r
-      /* raster1 is only capable of producing monochrome bitmaps */\r
-      if ( render->clazz == &ft_raster1_renderer_class )\r
-        return Raster_Err_Cannot_Render_Glyph;\r
-    }\r
-    else\r
-    {\r
-      /* raster5 is only capable of producing 5-gray-levels bitmaps */\r
-      if ( render->clazz == &ft_raster5_renderer_class )\r
-        return Raster_Err_Cannot_Render_Glyph;\r
-    }\r
-\r
-    outline = &slot->outline;\r
-\r
-    /* translate the outline to the new origin if needed */\r
-    if ( origin )\r
-      FT_Outline_Translate( outline, origin->x, origin->y );\r
-\r
-    /* compute the control box, and grid fit it */\r
-    FT_Outline_Get_CBox( outline, &cbox );\r
-\r
-    cbox.xMin = FT_PIX_FLOOR( cbox.xMin );\r
-    cbox.yMin = FT_PIX_FLOOR( cbox.yMin );\r
-    cbox.xMax = FT_PIX_CEIL( cbox.xMax );\r
-    cbox.yMax = FT_PIX_CEIL( cbox.yMax );\r
-\r
-    width  = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );\r
-    height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );\r
-    bitmap = &slot->bitmap;\r
-    memory = render->root.memory;\r
-\r
-    /* release old bitmap buffer */\r
-    if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )\r
-    {\r
-      FT_FREE( bitmap->buffer );\r
-      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;\r
-    }\r
-\r
-    /* allocate new one, depends on pixel format */\r
-    if ( !( mode & FT_RENDER_MODE_MONO ) )\r
-    {\r
-      /* we pad to 32 bits, only for backwards compatibility with FT 1.x */\r
-      pitch              = FT_PAD_CEIL( width, 4 );\r
-      bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;\r
-      bitmap->num_grays  = 256;\r
-    }\r
-    else\r
-    {\r
-      pitch              = ( ( width + 15 ) >> 4 ) << 1;\r
-      bitmap->pixel_mode = FT_PIXEL_MODE_MONO;\r
-    }\r
-\r
-    bitmap->width = width;\r
-    bitmap->rows  = height;\r
-    bitmap->pitch = pitch;\r
-\r
-    if ( FT_ALLOC_MULT( bitmap->buffer, pitch, height ) )\r
-      goto Exit;\r
-\r
-    slot->internal->flags |= FT_GLYPH_OWN_BITMAP;\r
-\r
-    /* translate outline to render it into the bitmap */\r
-    FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );\r
-\r
-    /* set up parameters */\r
-    params.target = bitmap;\r
-    params.source = outline;\r
-    params.flags  = 0;\r
-\r
-    if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )\r
-      params.flags |= FT_RASTER_FLAG_AA;\r
-\r
-    /* render outline into the bitmap */\r
-    error = render->raster_render( render->raster, &params );\r
-\r
-    FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );\r
-\r
-    if ( error )\r
-      goto Exit;\r
-\r
-    slot->format      = FT_GLYPH_FORMAT_BITMAP;\r
-    slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );\r
-    slot->bitmap_top  = (FT_Int)( cbox.yMax >> 6 );\r
-\r
-  Exit:\r
-    return error;\r
-  }\r
-\r
-\r
-  FT_CALLBACK_TABLE_DEF\r
-  const FT_Renderer_Class  ft_raster1_renderer_class =\r
-  {\r
-    {\r
-      FT_MODULE_RENDERER,\r
-      sizeof( FT_RendererRec ),\r
-\r
-      "raster1",\r
-      0x10000L,\r
-      0x20000L,\r
-\r
-      0,    /* module specific interface */\r
-\r
-      (FT_Module_Constructor)ft_raster1_init,\r
-      (FT_Module_Destructor) 0,\r
-      (FT_Module_Requester)  0\r
-    },\r
-\r
-    FT_GLYPH_FORMAT_OUTLINE,\r
-\r
-    (FT_Renderer_RenderFunc)   ft_raster1_render,\r
-    (FT_Renderer_TransformFunc)ft_raster1_transform,\r
-    (FT_Renderer_GetCBoxFunc)  ft_raster1_get_cbox,\r
-    (FT_Renderer_SetModeFunc)  ft_raster1_set_mode,\r
-\r
-    (FT_Raster_Funcs*)    &ft_standard_raster\r
-  };\r
-\r
-\r
-  /* This renderer is _NOT_ part of the default modules; you will need */\r
-  /* to register it by hand in your application.  It should only be    */\r
-  /* used for backwards-compatibility with FT 1.x anyway.              */\r
-  /*                                                                   */\r
-  FT_CALLBACK_TABLE_DEF\r
-  const FT_Renderer_Class  ft_raster5_renderer_class =\r
-  {\r
-    {\r
-      FT_MODULE_RENDERER,\r
-      sizeof( FT_RendererRec ),\r
-\r
-      "raster5",\r
-      0x10000L,\r
-      0x20000L,\r
-\r
-      0,    /* module specific interface */\r
-\r
-      (FT_Module_Constructor)ft_raster1_init,\r
-      (FT_Module_Destructor) 0,\r
-      (FT_Module_Requester)  0\r
-    },\r
-\r
-    FT_GLYPH_FORMAT_OUTLINE,\r
-\r
-    (FT_Renderer_RenderFunc)   ft_raster1_render,\r
-    (FT_Renderer_TransformFunc)ft_raster1_transform,\r
-    (FT_Renderer_GetCBoxFunc)  ft_raster1_get_cbox,\r
-    (FT_Renderer_SetModeFunc)  ft_raster1_set_mode,\r
-\r
-    (FT_Raster_Funcs*)    &ft_standard_raster\r
-  };\r
-\r
-\r
-/* END */\r
+/***************************************************************************/
+/*                                                                         */
+/*  ftrend1.c                                                              */
+/*                                                                         */
+/*    The FreeType glyph rasterizer interface (body).                      */
+/*                                                                         */
+/*  Copyright 1996-2001, 2002, 2003, 2005, 2006 by                         */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_OBJECTS_H
+#include FT_OUTLINE_H
+#include "ftrend1.h"
+#include "ftraster.h"
+
+#include "rasterrs.h"
+
+
+  /* initialize renderer -- init its raster */
+  static FT_Error
+  ft_raster1_init( FT_Renderer  render )
+  {
+    FT_Library  library = FT_MODULE_LIBRARY( render );
+
+
+    render->clazz->raster_class->raster_reset( render->raster,
+                                               library->raster_pool,
+                                               library->raster_pool_size );
+
+    return Raster_Err_Ok;
+  }
+
+
+  /* set render-specific mode */
+  static FT_Error
+  ft_raster1_set_mode( FT_Renderer  render,
+                       FT_ULong     mode_tag,
+                       FT_Pointer   data )
+  {
+    /* we simply pass it to the raster */
+    return render->clazz->raster_class->raster_set_mode( render->raster,
+                                                         mode_tag,
+                                                         data );
+  }
+
+
+  /* transform a given glyph image */
+  static FT_Error
+  ft_raster1_transform( FT_Renderer       render,
+                        FT_GlyphSlot      slot,
+                        const FT_Matrix*  matrix,
+                        const FT_Vector*  delta )
+  {
+    FT_Error error = Raster_Err_Ok;
+
+
+    if ( slot->format != render->glyph_format )
+    {
+      error = Raster_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    if ( matrix )
+      FT_Outline_Transform( &slot->outline, matrix );
+
+    if ( delta )
+      FT_Outline_Translate( &slot->outline, delta->x, delta->y );
+
+  Exit:
+    return error;
+  }
+
+
+  /* return the glyph's control box */
+  static void
+  ft_raster1_get_cbox( FT_Renderer   render,
+                       FT_GlyphSlot  slot,
+                       FT_BBox*      cbox )
+  {
+    FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
+
+    if ( slot->format == render->glyph_format )
+      FT_Outline_Get_CBox( &slot->outline, cbox );
+  }
+
+
+  /* convert a slot's glyph image into a bitmap */
+  static FT_Error
+  ft_raster1_render( FT_Renderer       render,
+                     FT_GlyphSlot      slot,
+                     FT_Render_Mode    mode,
+                     const FT_Vector*  origin )
+  {
+    FT_Error     error;
+    FT_Outline*  outline;
+    FT_BBox      cbox;
+    FT_UInt      width, height, pitch;
+    FT_Bitmap*   bitmap;
+    FT_Memory    memory;
+
+    FT_Raster_Params  params;
+
+
+    /* check glyph image format */
+    if ( slot->format != render->glyph_format )
+    {
+      error = Raster_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    /* check rendering mode */
+    if ( mode != FT_RENDER_MODE_MONO )
+    {
+      /* raster1 is only capable of producing monochrome bitmaps */
+      if ( render->clazz == &ft_raster1_renderer_class )
+        return Raster_Err_Cannot_Render_Glyph;
+    }
+    else
+    {
+      /* raster5 is only capable of producing 5-gray-levels bitmaps */
+      if ( render->clazz == &ft_raster5_renderer_class )
+        return Raster_Err_Cannot_Render_Glyph;
+    }
+
+    outline = &slot->outline;
+
+    /* translate the outline to the new origin if needed */
+    if ( origin )
+      FT_Outline_Translate( outline, origin->x, origin->y );
+
+    /* compute the control box, and grid fit it */
+    FT_Outline_Get_CBox( outline, &cbox );
+
+    cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
+    cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
+    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 );
+    bitmap = &slot->bitmap;
+    memory = render->root.memory;
+
+    /* release old bitmap buffer */
+    if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+    {
+      FT_FREE( bitmap->buffer );
+      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+    }
+
+    /* allocate new one, depends on pixel format */
+    if ( !( mode & FT_RENDER_MODE_MONO ) )
+    {
+      /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
+      pitch              = FT_PAD_CEIL( width, 4 );
+      bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
+      bitmap->num_grays  = 256;
+    }
+    else
+    {
+      pitch              = ( ( width + 15 ) >> 4 ) << 1;
+      bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
+    }
+
+    bitmap->width = width;
+    bitmap->rows  = height;
+    bitmap->pitch = pitch;
+
+    if ( FT_ALLOC_MULT( bitmap->buffer, pitch, height ) )
+      goto Exit;
+
+    slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
+
+    /* translate outline to render it into the bitmap */
+    FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
+
+    /* set up parameters */
+    params.target = bitmap;
+    params.source = outline;
+    params.flags  = 0;
+
+    if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
+      params.flags |= FT_RASTER_FLAG_AA;
+
+    /* render outline into the bitmap */
+    error = render->raster_render( render->raster, &params );
+
+    FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
+
+    if ( error )
+      goto Exit;
+
+    slot->format      = FT_GLYPH_FORMAT_BITMAP;
+    slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
+    slot->bitmap_top  = (FT_Int)( cbox.yMax >> 6 );
+
+  Exit:
+    return error;
+  }
+
+
+  FT_CALLBACK_TABLE_DEF
+  const FT_Renderer_Class  ft_raster1_renderer_class =
+  {
+    {
+      FT_MODULE_RENDERER,
+      sizeof( FT_RendererRec ),
+
+      "raster1",
+      0x10000L,
+      0x20000L,
+
+      0,    /* module specific interface */
+
+      (FT_Module_Constructor)ft_raster1_init,
+      (FT_Module_Destructor) 0,
+      (FT_Module_Requester)  0
+    },
+
+    FT_GLYPH_FORMAT_OUTLINE,
+
+    (FT_Renderer_RenderFunc)   ft_raster1_render,
+    (FT_Renderer_TransformFunc)ft_raster1_transform,
+    (FT_Renderer_GetCBoxFunc)  ft_raster1_get_cbox,
+    (FT_Renderer_SetModeFunc)  ft_raster1_set_mode,
+
+    (FT_Raster_Funcs*)    &ft_standard_raster
+  };
+
+
+  /* This renderer is _NOT_ part of the default modules; you will need */
+  /* to register it by hand in your application.  It should only be    */
+  /* used for backwards-compatibility with FT 1.x anyway.              */
+  /*                                                                   */
+  FT_CALLBACK_TABLE_DEF
+  const FT_Renderer_Class  ft_raster5_renderer_class =
+  {
+    {
+      FT_MODULE_RENDERER,
+      sizeof( FT_RendererRec ),
+
+      "raster5",
+      0x10000L,
+      0x20000L,
+
+      0,    /* module specific interface */
+
+      (FT_Module_Constructor)ft_raster1_init,
+      (FT_Module_Destructor) 0,
+      (FT_Module_Requester)  0
+    },
+
+    FT_GLYPH_FORMAT_OUTLINE,
+
+    (FT_Renderer_RenderFunc)   ft_raster1_render,
+    (FT_Renderer_TransformFunc)ft_raster1_transform,
+    (FT_Renderer_GetCBoxFunc)  ft_raster1_get_cbox,
+    (FT_Renderer_SetModeFunc)  ft_raster1_set_mode,
+
+    (FT_Raster_Funcs*)    &ft_standard_raster
+  };
+
+
+/* END */