1 /***************************************************************************/
5 /* Anti-aliasing renderer interface (body). */
7 /* Copyright 2000-2001 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 MEM_Set( cbox, 0, 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( FT_Renderer render,
105 FT_UInt width, height, pitch;
109 FT_Raster_Params params;
112 /* check glyph image format */
113 if ( slot->format != render->glyph_format )
115 error = Smooth_Err_Invalid_Argument;
120 if ( mode != ft_render_mode_normal )
121 return Smooth_Err_Cannot_Render_Glyph;
123 outline = &slot->outline;
125 /* translate the outline to the new origin if needed */
127 FT_Outline_Translate( outline, origin->x, origin->y );
129 /* compute the control box, and grid fit it */
130 FT_Outline_Get_CBox( outline, &cbox );
134 cbox.xMax = ( cbox.xMax + 63 ) & -64;
135 cbox.yMax = ( cbox.yMax + 63 ) & -64;
137 width = ( cbox.xMax - cbox.xMin ) >> 6;
138 height = ( cbox.yMax - cbox.yMin ) >> 6;
139 bitmap = &slot->bitmap;
140 memory = render->root.memory;
142 /* release old bitmap buffer */
143 if ( slot->flags & ft_glyph_own_bitmap )
145 FREE( bitmap->buffer );
146 slot->flags &= ~ft_glyph_own_bitmap;
149 /* allocate new one, depends on pixel format */
151 bitmap->pixel_mode = ft_pixel_mode_grays;
152 bitmap->num_grays = 256;
153 bitmap->width = width;
154 bitmap->rows = height;
155 bitmap->pitch = pitch;
157 if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
160 slot->flags |= ft_glyph_own_bitmap;
162 /* translate outline to render it into the bitmap */
163 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
165 /* set up parameters */
166 params.target = bitmap;
167 params.source = outline;
168 params.flags = ft_raster_flag_aa;
170 /* render outline into the bitmap */
171 error = render->raster_render( render->raster, ¶ms );
175 slot->format = ft_glyph_format_bitmap;
176 slot->bitmap_left = cbox.xMin >> 6;
177 slot->bitmap_top = cbox.yMax >> 6;
184 FT_CALLBACK_TABLE_DEF
185 const FT_Renderer_Class ft_smooth_renderer_class =
189 sizeof( FT_RendererRec ),
195 0, /* module specific interface */
197 (FT_Module_Constructor)ft_smooth_init,
198 (FT_Module_Destructor) 0,
199 (FT_Module_Requester) 0
202 ft_glyph_format_outline,
204 (FTRenderer_render) ft_smooth_render,
205 (FTRenderer_transform)ft_smooth_transform,
206 (FTRenderer_getCBox) ft_smooth_get_cbox,
207 (FTRenderer_setMode) ft_smooth_set_mode,
209 (FT_Raster_Funcs*) &ft_grays_raster