1 /***************************************************************************/
5 /* Anti-aliasing renderer interface (body). */
7 /* Copyright 2000 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 /***************************************************************************/
19 #include <freetype/internal/ftobjs.h>
20 #include <freetype/ftoutln.h>
23 #ifdef FT_FLAT_COMPILE
30 #include <freetype/src/smooth/ftsmooth.h>
31 #include <freetype/src/smooth/ftgrays.h>
36 /* initialize renderer -- init its raster */
38 FT_Error ft_smooth_init( FT_Renderer render )
40 FT_Library library = FT_MODULE_LIBRARY( render );
43 render->clazz->raster_class->raster_reset( render->raster,
45 library->raster_pool_size );
51 /* sets render-specific mode */
53 FT_Error ft_smooth_set_mode( FT_Renderer render,
57 /* we simply pass it to the raster */
58 return render->clazz->raster_class->raster_set_mode( render->raster,
63 /* transform a given glyph image */
65 FT_Error ft_smooth_transform( FT_Renderer render,
70 FT_Error error = FT_Err_Ok;
73 if ( slot->format != render->glyph_format )
75 error = FT_Err_Invalid_Argument;
80 FT_Outline_Transform( &slot->outline, matrix );
83 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
90 /* return the glyph's control box */
92 void ft_smooth_get_cbox( FT_Renderer render,
96 MEM_Set( cbox, 0, sizeof ( *cbox ) );
98 if ( slot->format == render->glyph_format )
99 FT_Outline_Get_CBox( &slot->outline, cbox );
103 /* convert a slot's glyph image into a bitmap */
105 FT_Error ft_smooth_render( FT_Renderer render,
113 FT_UInt width, height, pitch;
117 FT_Raster_Params params;
120 /* check glyph image format */
121 if ( slot->format != render->glyph_format )
123 error = FT_Err_Invalid_Argument;
128 if ( mode != ft_render_mode_normal )
129 return FT_Err_Cannot_Render_Glyph;
131 outline = &slot->outline;
133 /* translate the outline to the new origin if needed */
135 FT_Outline_Translate( outline, origin->x, origin->y );
137 /* compute the control box, and grid fit it */
138 FT_Outline_Get_CBox( outline, &cbox );
142 cbox.xMax = ( cbox.xMax + 63 ) & -64;
143 cbox.yMax = ( cbox.yMax + 63 ) & -64;
145 width = ( cbox.xMax - cbox.xMin ) >> 6;
146 height = ( cbox.yMax - cbox.yMin ) >> 6;
147 bitmap = &slot->bitmap;
148 memory = render->root.memory;
150 /* release old bitmap buffer */
151 if ( slot->flags & ft_glyph_own_bitmap )
153 FREE( bitmap->buffer );
154 slot->flags &= ~ft_glyph_own_bitmap;
157 /* allocate new one, depends on pixel format */
159 bitmap->pixel_mode = ft_pixel_mode_grays;
160 bitmap->num_grays = 256;
161 bitmap->width = width;
162 bitmap->rows = height;
163 bitmap->pitch = pitch;
165 if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
168 slot->flags |= ft_glyph_own_bitmap;
170 /* translate outline to render it into the bitmap */
171 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
173 /* set up parameters */
174 params.target = bitmap;
175 params.source = outline;
176 params.flags = ft_raster_flag_aa;
178 /* render outline into the bitmap */
179 error = render->raster_render( render->raster, ¶ms );
183 slot->format = ft_glyph_format_bitmap;
184 slot->bitmap_left = cbox.xMin >> 6;
185 slot->bitmap_top = cbox.yMax >> 6;
192 const FT_Renderer_Class ft_smooth_renderer_class =
196 sizeof( FT_RendererRec ),
202 0, /* module specific interface */
204 (FT_Module_Constructor)ft_smooth_init,
205 (FT_Module_Destructor) 0,
206 (FT_Module_Requester) 0
209 ft_glyph_format_outline,
211 (FTRenderer_render) ft_smooth_render,
212 (FTRenderer_transform)ft_smooth_transform,
213 (FTRenderer_getCBox) ft_smooth_get_cbox,
214 (FTRenderer_setMode) ft_smooth_set_mode,
216 (FT_Raster_Funcs*) &ft_grays_raster