]> git.saurik.com Git - wxWidgets.git/blob - src/freetype/smooth/ftsmooth.c
changed version number
[wxWidgets.git] / src / freetype / smooth / ftsmooth.c
1 /***************************************************************************/
2 /* */
3 /* ftsmooth.c */
4 /* */
5 /* Anti-aliasing renderer interface (body). */
6 /* */
7 /* Copyright 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 "ftsmooth.h"
26 #include "ftgrays.h"
27
28 #else
29
30 #include <smooth/ftsmooth.h>
31 #include <smooth/ftgrays.h>
32
33 #endif
34
35
36 /* initialize renderer -- init its raster */
37 static
38 FT_Error ft_smooth_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 0;
48 }
49
50
51 /* sets render-specific mode */
52 static
53 FT_Error ft_smooth_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 /* transform a given glyph image */
64 static
65 FT_Error ft_smooth_transform( FT_Renderer render,
66 FT_GlyphSlot slot,
67 FT_Matrix* matrix,
68 FT_Vector* delta )
69 {
70 FT_Error error = FT_Err_Ok;
71
72
73 if ( slot->format != render->glyph_format )
74 {
75 error = FT_Err_Invalid_Argument;
76 goto Exit;
77 }
78
79 if ( matrix )
80 FT_Outline_Transform( &slot->outline, matrix );
81
82 if ( delta )
83 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
84
85 Exit:
86 return error;
87 }
88
89
90 /* return the glyph's control box */
91 static
92 void ft_smooth_get_cbox( FT_Renderer render,
93 FT_GlyphSlot slot,
94 FT_BBox* cbox )
95 {
96 MEM_Set( cbox, 0, sizeof ( *cbox ) );
97
98 if ( slot->format == render->glyph_format )
99 FT_Outline_Get_CBox( &slot->outline, cbox );
100 }
101
102
103 /* convert a slot's glyph image into a bitmap */
104 static
105 FT_Error ft_smooth_render( FT_Renderer render,
106 FT_GlyphSlot slot,
107 FT_UInt mode,
108 FT_Vector* origin )
109 {
110 FT_Error error;
111 FT_Outline* outline;
112 FT_BBox cbox;
113 FT_UInt width, height, pitch;
114 FT_Bitmap* bitmap;
115 FT_Memory memory;
116
117 FT_Raster_Params params;
118
119
120 /* check glyph image format */
121 if ( slot->format != render->glyph_format )
122 {
123 error = FT_Err_Invalid_Argument;
124 goto Exit;
125 }
126
127 /* check mode */
128 if ( mode != ft_render_mode_normal )
129 return FT_Err_Cannot_Render_Glyph;
130
131 outline = &slot->outline;
132
133 /* translate the outline to the new origin if needed */
134 if ( origin )
135 FT_Outline_Translate( outline, origin->x, origin->y );
136
137 /* compute the control box, and grid fit it */
138 FT_Outline_Get_CBox( outline, &cbox );
139
140 cbox.xMin &= -64;
141 cbox.yMin &= -64;
142 cbox.xMax = ( cbox.xMax + 63 ) & -64;
143 cbox.yMax = ( cbox.yMax + 63 ) & -64;
144
145 width = ( cbox.xMax - cbox.xMin ) >> 6;
146 height = ( cbox.yMax - cbox.yMin ) >> 6;
147 bitmap = &slot->bitmap;
148 memory = render->root.memory;
149
150 /* release old bitmap buffer */
151 if ( slot->flags & ft_glyph_own_bitmap )
152 {
153 FREE( bitmap->buffer );
154 slot->flags &= ~ft_glyph_own_bitmap;
155 }
156
157 /* allocate new one, depends on pixel format */
158 pitch = width;
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;
164
165 if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
166 goto Exit;
167
168 slot->flags |= ft_glyph_own_bitmap;
169
170 /* translate outline to render it into the bitmap */
171 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
172
173 /* set up parameters */
174 params.target = bitmap;
175 params.source = outline;
176 params.flags = ft_raster_flag_aa;
177
178 /* render outline into the bitmap */
179 error = render->raster_render( render->raster, &params );
180 if ( error )
181 goto Exit;
182
183 slot->format = ft_glyph_format_bitmap;
184 slot->bitmap_left = cbox.xMin >> 6;
185 slot->bitmap_top = cbox.yMax >> 6;
186
187 Exit:
188 return error;
189 }
190
191
192 const FT_Renderer_Class ft_smooth_renderer_class =
193 {
194 {
195 ft_module_renderer,
196 sizeof( FT_RendererRec ),
197
198 "smooth",
199 0x10000L,
200 0x20000L,
201
202 0, /* module specific interface */
203
204 (FT_Module_Constructor)ft_smooth_init,
205 (FT_Module_Destructor) 0,
206 (FT_Module_Requester) 0
207 },
208
209 ft_glyph_format_outline,
210
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,
215
216 (FT_Raster_Funcs*) &ft_grays_raster
217 };
218
219
220 /* END */