1 /***************************************************************************/
5 /* Anti-aliasing renderer interface (body). */
7 /* Copyright 2000-2001, 2002 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
20 #include FT_INTERNAL_OBJECTS_H
28 /* initialize renderer -- init its raster */
30 ft_smooth_init( FT_Renderer render )
32 FT_Library library = FT_MODULE_LIBRARY( render );
35 render->clazz->raster_class->raster_reset( render->raster,
37 library->raster_pool_size );
43 /* sets render-specific mode */
45 ft_smooth_set_mode( FT_Renderer render,
49 /* we simply pass it to the raster */
50 return render->clazz->raster_class->raster_set_mode( render->raster,
55 /* transform a given glyph image */
57 ft_smooth_transform( FT_Renderer render,
62 FT_Error error = Smooth_Err_Ok;
65 if ( slot->format != render->glyph_format )
67 error = Smooth_Err_Invalid_Argument;
72 FT_Outline_Transform( &slot->outline, matrix );
75 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
82 /* return the glyph's control box */
84 ft_smooth_get_cbox( FT_Renderer render,
88 FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
90 if ( slot->format == render->glyph_format )
91 FT_Outline_Get_CBox( &slot->outline, cbox );
95 /* convert a slot's glyph image into a bitmap */
97 ft_smooth_render_generic( FT_Renderer render,
101 FT_Render_Mode required_mode,
106 FT_Outline* outline = NULL;
108 FT_UInt width, height, pitch;
112 FT_Raster_Params params;
115 /* check glyph image format */
116 if ( slot->format != render->glyph_format )
118 error = Smooth_Err_Invalid_Argument;
123 if ( mode != required_mode )
124 return Smooth_Err_Cannot_Render_Glyph;
126 outline = &slot->outline;
128 /* translate the outline to the new origin if needed */
130 FT_Outline_Translate( outline, origin->x, origin->y );
132 /* compute the control box, and grid fit it */
133 FT_Outline_Get_CBox( outline, &cbox );
137 cbox.xMax = ( cbox.xMax + 63 ) & -64;
138 cbox.yMax = ( cbox.yMax + 63 ) & -64;
140 width = ( cbox.xMax - cbox.xMin ) >> 6;
141 height = ( cbox.yMax - cbox.yMin ) >> 6;
142 bitmap = &slot->bitmap;
143 memory = render->root.memory;
145 /* release old bitmap buffer */
146 if ( slot->flags & FT_GLYPH_OWN_BITMAP )
148 FT_FREE( bitmap->buffer );
149 slot->flags &= ~FT_GLYPH_OWN_BITMAP;
152 /* allocate new one, depends on pixel format */
156 width = width * hmul;
157 pitch = ( width + 3 ) & -4;
163 bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
164 bitmap->num_grays = 256;
165 bitmap->width = width;
166 bitmap->rows = height;
167 bitmap->pitch = pitch;
169 if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
172 slot->flags |= FT_GLYPH_OWN_BITMAP;
174 /* translate outline to render it into the bitmap */
175 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
177 /* set up parameters */
178 params.target = bitmap;
179 params.source = outline;
180 params.flags = FT_RASTER_FLAG_AA;
182 /* implode outline if needed */
189 for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
193 for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
197 /* render outline into the bitmap */
198 error = render->raster_render( render->raster, ¶ms );
200 /* deflate outline if needed */
207 for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
211 for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
215 FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
220 slot->format = FT_GLYPH_FORMAT_BITMAP;
221 slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
222 slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 );
225 if ( outline && origin )
226 FT_Outline_Translate( outline, -origin->x, -origin->y );
232 /* convert a slot's glyph image into a bitmap */
234 ft_smooth_render( FT_Renderer render,
239 return ft_smooth_render_generic( render, slot, mode, origin,
240 FT_RENDER_MODE_NORMAL,
245 /* convert a slot's glyph image into a horizontal LCD bitmap */
247 ft_smooth_render_lcd( FT_Renderer render,
254 error = ft_smooth_render_generic( render, slot, mode, origin,
258 slot->bitmap.pixel_mode = FT_PIXEL_MODE_LCD;
264 /* convert a slot's glyph image into a vertical LCD bitmap */
266 ft_smooth_render_lcd_v( FT_Renderer render,
273 error = ft_smooth_render_generic( render, slot, mode, origin,
274 FT_RENDER_MODE_LCD_V,
277 slot->bitmap.pixel_mode = FT_PIXEL_MODE_LCD_V;
283 FT_CALLBACK_TABLE_DEF
284 const FT_Renderer_Class ft_smooth_renderer_class =
288 sizeof( FT_RendererRec ),
294 0, /* module specific interface */
296 (FT_Module_Constructor)ft_smooth_init,
297 (FT_Module_Destructor) 0,
298 (FT_Module_Requester) 0
301 FT_GLYPH_FORMAT_OUTLINE,
303 (FT_Renderer_RenderFunc) ft_smooth_render,
304 (FT_Renderer_TransformFunc)ft_smooth_transform,
305 (FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox,
306 (FT_Renderer_SetModeFunc) ft_smooth_set_mode,
308 (FT_Raster_Funcs*) &ft_grays_raster
312 FT_CALLBACK_TABLE_DEF
313 const FT_Renderer_Class ft_smooth_lcd_renderer_class =
317 sizeof( FT_RendererRec ),
323 0, /* module specific interface */
325 (FT_Module_Constructor)ft_smooth_init,
326 (FT_Module_Destructor) 0,
327 (FT_Module_Requester) 0
330 FT_GLYPH_FORMAT_OUTLINE,
332 (FT_Renderer_RenderFunc) ft_smooth_render_lcd,
333 (FT_Renderer_TransformFunc)ft_smooth_transform,
334 (FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox,
335 (FT_Renderer_SetModeFunc) ft_smooth_set_mode,
337 (FT_Raster_Funcs*) &ft_grays_raster
342 FT_CALLBACK_TABLE_DEF
343 const FT_Renderer_Class ft_smooth_lcdv_renderer_class =
347 sizeof( FT_RendererRec ),
353 0, /* module specific interface */
355 (FT_Module_Constructor)ft_smooth_init,
356 (FT_Module_Destructor) 0,
357 (FT_Module_Requester) 0
360 FT_GLYPH_FORMAT_OUTLINE,
362 (FT_Renderer_RenderFunc) ft_smooth_render_lcd_v,
363 (FT_Renderer_TransformFunc)ft_smooth_transform,
364 (FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox,
365 (FT_Renderer_SetModeFunc) ft_smooth_set_mode,
367 (FT_Raster_Funcs*) &ft_grays_raster