]> git.saurik.com Git - wxWidgets.git/blob - src/freetype/raster1/ftrend1.c
changed version number
[wxWidgets.git] / src / freetype / raster1 / ftrend1.c
1 /***************************************************************************/
2 /* */
3 /* ftrend1.c */
4 /* */
5 /* The FreeType glyph rasterizer interface (body). */
6 /* */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
17
18
19 #include <freetype/internal/ftobjs.h>
20 #include <freetype/ftoutln.h>
21
22
23 #ifdef FT_FLAT_COMPILE
24
25 #include "ftrend1.h"
26 #include "ftraster.h"
27
28 #else
29
30 #include <raster1/ftrend1.h>
31 #include <raster1/ftraster.h>
32
33 #endif
34
35
36 /* initialize renderer -- init its raster */
37 static
38 FT_Error ft_raster1_init( FT_Renderer render )
39 {
40 FT_Library library = FT_MODULE_LIBRARY( render );
41
42
43 render->clazz->raster_class->raster_reset( render->raster,
44 library->raster_pool,
45 library->raster_pool_size );
46
47 return FT_Err_Ok;
48 }
49
50
51 /* set render-specific mode */
52 static
53 FT_Error ft_raster1_set_mode( FT_Renderer render,
54 FT_ULong mode_tag,
55 FT_Pointer data )
56 {
57 /* we simply pass it to the raster */
58 return render->clazz->raster_class->raster_set_mode( render->raster,
59 mode_tag,
60 data );
61 }
62
63
64 /* transform a given glyph image */
65 static
66 FT_Error ft_raster1_transform( FT_Renderer render,
67 FT_GlyphSlot slot,
68 FT_Matrix* matrix,
69 FT_Vector* delta )
70 {
71 FT_Error error = FT_Err_Ok;
72
73
74 if ( slot->format != render->glyph_format )
75 {
76 error = FT_Err_Invalid_Argument;
77 goto Exit;
78 }
79
80 if ( matrix )
81 FT_Outline_Transform( &slot->outline, matrix );
82
83 if ( delta )
84 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
85
86 Exit:
87 return error;
88 }
89
90
91 /* return the glyph's control box */
92 static
93 void ft_raster1_get_cbox( FT_Renderer render,
94 FT_GlyphSlot slot,
95 FT_BBox* cbox )
96 {
97 MEM_Set( cbox, 0, sizeof ( *cbox ) );
98
99 if ( slot->format == render->glyph_format )
100 FT_Outline_Get_CBox( &slot->outline, cbox );
101 }
102
103
104 /* convert a slot's glyph image into a bitmap */
105 static
106 FT_Error ft_raster1_render( FT_Renderer render,
107 FT_GlyphSlot slot,
108 FT_UInt mode,
109 FT_Vector* origin )
110 {
111 FT_Error error;
112 FT_Outline* outline;
113 FT_BBox cbox;
114 FT_UInt width, height, pitch;
115 FT_Bitmap* bitmap;
116 FT_Memory memory;
117
118 FT_Raster_Params params;
119
120
121 /* check glyph image format */
122 if ( slot->format != render->glyph_format )
123 {
124 error = FT_Err_Invalid_Argument;
125 goto Exit;
126 }
127
128 /* check rendering mode */
129 if ( mode != ft_render_mode_mono )
130 {
131 /* raster1 is only capable of producing monochrome bitmaps */
132 if ( render->clazz == &ft_raster1_renderer_class )
133 return FT_Err_Cannot_Render_Glyph;
134 }
135 else
136 {
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;
140 }
141
142 outline = &slot->outline;
143
144 /* translate the outline to the new origin if needed */
145 if ( origin )
146 FT_Outline_Translate( outline, origin->x, origin->y );
147
148 /* compute the control box, and grid fit it */
149 FT_Outline_Get_CBox( outline, &cbox );
150
151 cbox.xMin &= -64;
152 cbox.yMin &= -64;
153 cbox.xMax = ( cbox.xMax + 63 ) & -64;
154 cbox.yMax = ( cbox.yMax + 63 ) & -64;
155
156 width = ( cbox.xMax - cbox.xMin ) >> 6;
157 height = ( cbox.yMax - cbox.yMin ) >> 6;
158 bitmap = &slot->bitmap;
159 memory = render->root.memory;
160
161 /* release old bitmap buffer */
162 if ( slot->flags & ft_glyph_own_bitmap )
163 {
164 FREE( bitmap->buffer );
165 slot->flags &= ~ft_glyph_own_bitmap;
166 }
167
168 /* allocate new one, depends on pixel format */
169 if ( !( mode & ft_render_mode_mono ) )
170 {
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;
175 }
176 else
177 {
178 pitch = ( width + 7 ) >> 3;
179 bitmap->pixel_mode = ft_pixel_mode_mono;
180 }
181
182 bitmap->width = width;
183 bitmap->rows = height;
184 bitmap->pitch = pitch;
185
186 if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
187 goto Exit;
188
189 slot->flags |= ft_glyph_own_bitmap;
190
191 /* translate outline to render it into the bitmap */
192 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
193
194 /* set up parameters */
195 params.target = bitmap;
196 params.source = outline;
197 params.flags = 0;
198
199 if ( bitmap->pixel_mode == ft_pixel_mode_grays )
200 params.flags |= ft_raster_flag_aa;
201
202 /* render outline into the bitmap */
203 error = render->raster_render( render->raster, &params );
204 if ( error )
205 goto Exit;
206
207 slot->format = ft_glyph_format_bitmap;
208 slot->bitmap_left = cbox.xMin >> 6;
209 slot->bitmap_top = cbox.yMax >> 6;
210
211 Exit:
212 return error;
213 }
214
215
216 const FT_Renderer_Class ft_raster1_renderer_class =
217 {
218 {
219 ft_module_renderer,
220 sizeof( FT_RendererRec ),
221
222 "raster1",
223 0x10000L,
224 0x20000L,
225
226 0, /* module specific interface */
227
228 (FT_Module_Constructor)ft_raster1_init,
229 (FT_Module_Destructor) 0,
230 (FT_Module_Requester) 0
231 },
232
233 ft_glyph_format_outline,
234
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,
239
240 (FT_Raster_Funcs*) &ft_standard_raster
241 };
242
243
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 =
248 {
249 {
250 ft_module_renderer,
251 sizeof( FT_RendererRec ),
252
253 "raster5",
254 0x10000L,
255 0x20000L,
256
257 0, /* module specific interface */
258
259 (FT_Module_Constructor)ft_raster1_init,
260 (FT_Module_Destructor) 0,
261 (FT_Module_Requester) 0
262 },
263
264 ft_glyph_format_outline,
265
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,
270
271 (FT_Raster_Funcs*) &ft_standard_raster
272 };
273
274
275 /* END */