Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / freetype2 / src / raster / ftrend1.c
blob3cc8d07413b578713a13d470ef8dc64848620378
1 /***************************************************************************/
2 /* */
3 /* ftrend1.c */
4 /* */
5 /* The FreeType glyph rasterizer interface (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2003, 2005, 2006 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
19 #include <ft2build.h>
20 #include FT_INTERNAL_OBJECTS_H
21 #include FT_OUTLINE_H
22 #include "ftrend1.h"
23 #include "ftraster.h"
25 #include "rasterrs.h"
28 /* initialize renderer -- init its raster */
29 static FT_Error
30 ft_raster1_init( FT_Renderer render )
32 FT_Library library = FT_MODULE_LIBRARY( render );
35 render->clazz->raster_class->raster_reset( render->raster,
36 library->raster_pool,
37 library->raster_pool_size );
39 return Raster_Err_Ok;
43 /* set render-specific mode */
44 static FT_Error
45 ft_raster1_set_mode( FT_Renderer render,
46 FT_ULong mode_tag,
47 FT_Pointer data )
49 /* we simply pass it to the raster */
50 return render->clazz->raster_class->raster_set_mode( render->raster,
51 mode_tag,
52 data );
56 /* transform a given glyph image */
57 static FT_Error
58 ft_raster1_transform( FT_Renderer render,
59 FT_GlyphSlot slot,
60 const FT_Matrix* matrix,
61 const FT_Vector* delta )
63 FT_Error error = Raster_Err_Ok;
66 if ( slot->format != render->glyph_format )
68 error = Raster_Err_Invalid_Argument;
69 goto Exit;
72 if ( matrix )
73 FT_Outline_Transform( &slot->outline, matrix );
75 if ( delta )
76 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
78 Exit:
79 return error;
83 /* return the glyph's control box */
84 static void
85 ft_raster1_get_cbox( FT_Renderer render,
86 FT_GlyphSlot slot,
87 FT_BBox* cbox )
89 FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
91 if ( slot->format == render->glyph_format )
92 FT_Outline_Get_CBox( &slot->outline, cbox );
96 /* convert a slot's glyph image into a bitmap */
97 static FT_Error
98 ft_raster1_render( FT_Renderer render,
99 FT_GlyphSlot slot,
100 FT_Render_Mode mode,
101 const FT_Vector* origin )
103 FT_Error error;
104 FT_Outline* outline;
105 FT_BBox cbox;
106 FT_UInt width, height, pitch;
107 FT_Bitmap* bitmap;
108 FT_Memory memory;
110 FT_Raster_Params params;
113 /* check glyph image format */
114 if ( slot->format != render->glyph_format )
116 error = Raster_Err_Invalid_Argument;
117 goto Exit;
120 /* check rendering mode */
121 if ( mode != FT_RENDER_MODE_MONO )
123 /* raster1 is only capable of producing monochrome bitmaps */
124 if ( render->clazz == &ft_raster1_renderer_class )
125 return Raster_Err_Cannot_Render_Glyph;
127 else
129 /* raster5 is only capable of producing 5-gray-levels bitmaps */
130 if ( render->clazz == &ft_raster5_renderer_class )
131 return Raster_Err_Cannot_Render_Glyph;
134 outline = &slot->outline;
136 /* translate the outline to the new origin if needed */
137 if ( origin )
138 FT_Outline_Translate( outline, origin->x, origin->y );
140 /* compute the control box, and grid fit it */
141 FT_Outline_Get_CBox( outline, &cbox );
143 cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
144 cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
145 cbox.xMax = FT_PIX_CEIL( cbox.xMax );
146 cbox.yMax = FT_PIX_CEIL( cbox.yMax );
148 width = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
149 height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
150 bitmap = &slot->bitmap;
151 memory = render->root.memory;
153 /* release old bitmap buffer */
154 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
156 FT_FREE( bitmap->buffer );
157 slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
160 /* allocate new one, depends on pixel format */
161 if ( !( mode & FT_RENDER_MODE_MONO ) )
163 /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
164 pitch = FT_PAD_CEIL( width, 4 );
165 bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
166 bitmap->num_grays = 256;
168 else
170 pitch = ( ( width + 15 ) >> 4 ) << 1;
171 bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
174 bitmap->width = width;
175 bitmap->rows = height;
176 bitmap->pitch = pitch;
178 if ( FT_ALLOC_MULT( bitmap->buffer, pitch, height ) )
179 goto Exit;
181 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
183 /* translate outline to render it into the bitmap */
184 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
186 /* set up parameters */
187 params.target = bitmap;
188 params.source = outline;
189 params.flags = 0;
191 if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
192 params.flags |= FT_RASTER_FLAG_AA;
194 /* render outline into the bitmap */
195 error = render->raster_render( render->raster, &params );
197 FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
199 if ( error )
200 goto Exit;
202 slot->format = FT_GLYPH_FORMAT_BITMAP;
203 slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
204 slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 );
206 Exit:
207 return error;
211 FT_CALLBACK_TABLE_DEF
212 const FT_Renderer_Class ft_raster1_renderer_class =
215 FT_MODULE_RENDERER,
216 sizeof( FT_RendererRec ),
218 "raster1",
219 0x10000L,
220 0x20000L,
222 0, /* module specific interface */
224 (FT_Module_Constructor)ft_raster1_init,
225 (FT_Module_Destructor) 0,
226 (FT_Module_Requester) 0
229 FT_GLYPH_FORMAT_OUTLINE,
231 (FT_Renderer_RenderFunc) ft_raster1_render,
232 (FT_Renderer_TransformFunc)ft_raster1_transform,
233 (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
234 (FT_Renderer_SetModeFunc) ft_raster1_set_mode,
236 (FT_Raster_Funcs*) &ft_standard_raster
240 /* This renderer is _NOT_ part of the default modules; you will need */
241 /* to register it by hand in your application. It should only be */
242 /* used for backwards-compatibility with FT 1.x anyway. */
243 /* */
244 FT_CALLBACK_TABLE_DEF
245 const FT_Renderer_Class ft_raster5_renderer_class =
248 FT_MODULE_RENDERER,
249 sizeof( FT_RendererRec ),
251 "raster5",
252 0x10000L,
253 0x20000L,
255 0, /* module specific interface */
257 (FT_Module_Constructor)ft_raster1_init,
258 (FT_Module_Destructor) 0,
259 (FT_Module_Requester) 0
262 FT_GLYPH_FORMAT_OUTLINE,
264 (FT_Renderer_RenderFunc) ft_raster1_render,
265 (FT_Renderer_TransformFunc)ft_raster1_transform,
266 (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
267 (FT_Renderer_SetModeFunc) ft_raster1_set_mode,
269 (FT_Raster_Funcs*) &ft_standard_raster
273 /* END */