1 /***************************************************************************/
5 /* The FreeType glyph rasterizer interface (body). */
7 /* Copyright 1996-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 <raster1/ftrend1.h>
31 #include <raster1/ftraster.h>
36 /* initialize renderer -- init its raster */
38 FT_Error
ft_raster1_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 /* set render-specific mode */
53 FT_Error
ft_raster1_set_mode( FT_Renderer render
,
57 /* we simply pass it to the raster */
58 return render
->clazz
->raster_class
->raster_set_mode( render
->raster
,
64 /* transform a given glyph image */
66 FT_Error
ft_raster1_transform( FT_Renderer render
,
71 FT_Error error
= FT_Err_Ok
;
74 if ( slot
->format
!= render
->glyph_format
)
76 error
= FT_Err_Invalid_Argument
;
81 FT_Outline_Transform( &slot
->outline
, matrix
);
84 FT_Outline_Translate( &slot
->outline
, delta
->x
, delta
->y
);
91 /* return the glyph's control box */
93 void ft_raster1_get_cbox( FT_Renderer render
,
97 MEM_Set( cbox
, 0, sizeof ( *cbox
) );
99 if ( slot
->format
== render
->glyph_format
)
100 FT_Outline_Get_CBox( &slot
->outline
, cbox
);
104 /* convert a slot's glyph image into a bitmap */
106 FT_Error
ft_raster1_render( FT_Renderer render
,
114 FT_UInt width
, height
, pitch
;
118 FT_Raster_Params params
;
121 /* check glyph image format */
122 if ( slot
->format
!= render
->glyph_format
)
124 error
= FT_Err_Invalid_Argument
;
128 /* check rendering mode */
129 if ( mode
!= ft_render_mode_mono
)
131 /* raster1 is only capable of producing monochrome bitmaps */
132 if ( render
->clazz
== &ft_raster1_renderer_class
)
133 return FT_Err_Cannot_Render_Glyph
;
137 /* raster5 is only capable of producing 5-gray-levels bitmaps */
138 if ( render
->clazz
== &ft_raster5_renderer_class
)
139 return FT_Err_Cannot_Render_Glyph
;
142 outline
= &slot
->outline
;
144 /* translate the outline to the new origin if needed */
146 FT_Outline_Translate( outline
, origin
->x
, origin
->y
);
148 /* compute the control box, and grid fit it */
149 FT_Outline_Get_CBox( outline
, &cbox
);
153 cbox
.xMax
= ( cbox
.xMax
+ 63 ) & -64;
154 cbox
.yMax
= ( cbox
.yMax
+ 63 ) & -64;
156 width
= ( cbox
.xMax
- cbox
.xMin
) >> 6;
157 height
= ( cbox
.yMax
- cbox
.yMin
) >> 6;
158 bitmap
= &slot
->bitmap
;
159 memory
= render
->root
.memory
;
161 /* release old bitmap buffer */
162 if ( slot
->flags
& ft_glyph_own_bitmap
)
164 FREE( bitmap
->buffer
);
165 slot
->flags
&= ~ft_glyph_own_bitmap
;
168 /* allocate new one, depends on pixel format */
169 if ( !( mode
& ft_render_mode_mono
) )
171 /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
172 pitch
= ( width
+ 3 ) & -4;
173 bitmap
->pixel_mode
= ft_pixel_mode_grays
;
174 bitmap
->num_grays
= 256;
178 pitch
= ( width
+ 7 ) >> 3;
179 bitmap
->pixel_mode
= ft_pixel_mode_mono
;
182 bitmap
->width
= width
;
183 bitmap
->rows
= height
;
184 bitmap
->pitch
= pitch
;
186 if ( ALLOC( bitmap
->buffer
, (FT_ULong
)pitch
* height
) )
189 slot
->flags
|= ft_glyph_own_bitmap
;
191 /* translate outline to render it into the bitmap */
192 FT_Outline_Translate( outline
, -cbox
.xMin
, -cbox
.yMin
);
194 /* set up parameters */
195 params
.target
= bitmap
;
196 params
.source
= outline
;
199 if ( bitmap
->pixel_mode
== ft_pixel_mode_grays
)
200 params
.flags
|= ft_raster_flag_aa
;
202 /* render outline into the bitmap */
203 error
= render
->raster_render( render
->raster
, ¶ms
);
207 slot
->format
= ft_glyph_format_bitmap
;
208 slot
->bitmap_left
= cbox
.xMin
>> 6;
209 slot
->bitmap_top
= cbox
.yMax
>> 6;
216 const FT_Renderer_Class ft_raster1_renderer_class
=
220 sizeof( FT_RendererRec
),
226 0, /* module specific interface */
228 (FT_Module_Constructor
)ft_raster1_init
,
229 (FT_Module_Destructor
) 0,
230 (FT_Module_Requester
) 0
233 ft_glyph_format_outline
,
235 (FTRenderer_render
) ft_raster1_render
,
236 (FTRenderer_transform
)ft_raster1_transform
,
237 (FTRenderer_getCBox
) ft_raster1_get_cbox
,
238 (FTRenderer_setMode
) ft_raster1_set_mode
,
240 (FT_Raster_Funcs
*) &ft_standard_raster
244 /* this renderer is _NOT_ part of the default modules, you'll need */
245 /* to register it by hand in your application. It should only be */
246 /* used for backwards-compatibility with FT 1.x anyway. */
247 const FT_Renderer_Class ft_raster5_renderer_class
=
251 sizeof( FT_RendererRec
),
257 0, /* module specific interface */
259 (FT_Module_Constructor
)ft_raster1_init
,
260 (FT_Module_Destructor
) 0,
261 (FT_Module_Requester
) 0
264 ft_glyph_format_outline
,
266 (FTRenderer_render
) ft_raster1_render
,
267 (FTRenderer_transform
)ft_raster1_transform
,
268 (FTRenderer_getCBox
) ft_raster1_get_cbox
,
269 (FTRenderer_setMode
) ft_raster1_set_mode
,
271 (FT_Raster_Funcs
*) &ft_standard_raster