1 /***************************************************************************/
5 /* The FreeType glyph rasterizer interface (body). */
7 /* Copyright 1996-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_raster1_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 /* set render-specific mode */
45 ft_raster1_set_mode( FT_Renderer render,
49 /* we simply pass it to the raster */
50 return render->clazz->raster_class->raster_set_mode( render->raster,
56 /* transform a given glyph image */
58 ft_raster1_transform( FT_Renderer render,
63 FT_Error error = Raster_Err_Ok;
66 if ( slot->format != render->glyph_format )
68 error = Raster_Err_Invalid_Argument;
73 FT_Outline_Transform( &slot->outline, matrix );
76 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
83 /* return the glyph's control box */
85 ft_raster1_get_cbox( FT_Renderer render,
89 MEM_Set( cbox, 0, 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 */
98 ft_raster1_render( FT_Renderer render,
106 FT_UInt width, height, pitch;
110 FT_Raster_Params params;
113 /* check glyph image format */
114 if ( slot->format != render->glyph_format )
116 error = Raster_Err_Invalid_Argument;
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;
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 */
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 );
145 cbox.xMax = ( cbox.xMax + 63 ) & -64;
146 cbox.yMax = ( cbox.yMax + 63 ) & -64;
148 width = ( cbox.xMax - cbox.xMin ) >> 6;
149 height = ( cbox.yMax - cbox.yMin ) >> 6;
150 bitmap = &slot->bitmap;
151 memory = render->root.memory;
153 /* release old bitmap buffer */
154 if ( slot->flags & ft_glyph_own_bitmap )
156 FREE( bitmap->buffer );
157 slot->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 = ( width + 3 ) & -4;
165 bitmap->pixel_mode = ft_pixel_mode_grays;
166 bitmap->num_grays = 256;
170 pitch = ( width + 7 ) >> 3;
171 bitmap->pixel_mode = ft_pixel_mode_mono;
174 bitmap->width = width;
175 bitmap->rows = height;
176 bitmap->pitch = pitch;
178 if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
181 slot->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;
191 if ( bitmap->pixel_mode == ft_pixel_mode_grays )
192 params.flags |= ft_raster_flag_aa;
194 /* render outline into the bitmap */
195 error = render->raster_render( render->raster, ¶ms );
199 slot->format = ft_glyph_format_bitmap;
200 slot->bitmap_left = cbox.xMin >> 6;
201 slot->bitmap_top = cbox.yMax >> 6;
208 FT_CALLBACK_TABLE_DEF
209 const FT_Renderer_Class ft_raster1_renderer_class =
213 sizeof( FT_RendererRec ),
219 0, /* module specific interface */
221 (FT_Module_Constructor)ft_raster1_init,
222 (FT_Module_Destructor) 0,
223 (FT_Module_Requester) 0
226 ft_glyph_format_outline,
228 (FTRenderer_render) ft_raster1_render,
229 (FTRenderer_transform)ft_raster1_transform,
230 (FTRenderer_getCBox) ft_raster1_get_cbox,
231 (FTRenderer_setMode) ft_raster1_set_mode,
233 (FT_Raster_Funcs*) &ft_standard_raster
237 /* This renderer is _NOT_ part of the default modules; you will need */
238 /* to register it by hand in your application. It should only be */
239 /* used for backwards-compatibility with FT 1.x anyway. */
241 FT_CALLBACK_TABLE_DEF
242 const FT_Renderer_Class ft_raster5_renderer_class =
246 sizeof( FT_RendererRec ),
252 0, /* module specific interface */
254 (FT_Module_Constructor)ft_raster1_init,
255 (FT_Module_Destructor) 0,
256 (FT_Module_Requester) 0
259 ft_glyph_format_outline,
261 (FTRenderer_render) ft_raster1_render,
262 (FTRenderer_transform)ft_raster1_transform,
263 (FTRenderer_getCBox) ft_raster1_get_cbox,
264 (FTRenderer_setMode) ft_raster1_set_mode,
266 (FT_Raster_Funcs*) &ft_standard_raster