1
/***************************************************************************/
5
/* Anti-aliasing renderer interface (body). */
7
/* Copyright 2000-2001, 2002, 2003, 2004 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_smooth_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
/* sets render-specific mode */
45
ft_smooth_set_mode( FT_Renderer render,
49
/* we simply pass it to the raster */
50
return render->clazz->raster_class->raster_set_mode( render->raster,
55
/* transform a given glyph image */
57
ft_smooth_transform( FT_Renderer render,
62
FT_Error error = Smooth_Err_Ok;
65
if ( slot->format != render->glyph_format )
67
error = Smooth_Err_Invalid_Argument;
72
FT_Outline_Transform( &slot->outline, matrix );
75
FT_Outline_Translate( &slot->outline, delta->x, delta->y );
82
/* return the glyph's control box */
84
ft_smooth_get_cbox( FT_Renderer render,
88
FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
90
if ( slot->format == render->glyph_format )
91
FT_Outline_Get_CBox( &slot->outline, cbox );
95
/* convert a slot's glyph image into a bitmap */
97
ft_smooth_render_generic( FT_Renderer render,
101
FT_Render_Mode required_mode,
106
FT_Outline* outline = NULL;
108
FT_UInt width, height, pitch;
112
FT_Raster_Params params;
115
/* check glyph image format */
116
if ( slot->format != render->glyph_format )
118
error = Smooth_Err_Invalid_Argument;
123
if ( mode != required_mode )
124
return Smooth_Err_Cannot_Render_Glyph;
126
outline = &slot->outline;
128
/* translate the outline to the new origin if needed */
130
FT_Outline_Translate( outline, origin->x, origin->y );
132
/* compute the control box, and grid fit it */
133
FT_Outline_Get_CBox( outline, &cbox );
135
cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
136
cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
137
cbox.xMax = FT_PIX_CEIL( cbox.xMax );
138
cbox.yMax = FT_PIX_CEIL( cbox.yMax );
140
width = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
141
height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
142
bitmap = &slot->bitmap;
143
memory = render->root.memory;
145
/* release old bitmap buffer */
146
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
148
FT_FREE( bitmap->buffer );
149
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
152
/* allocate new one, depends on pixel format */
156
width = width * hmul;
157
pitch = FT_PAD_CEIL( width, 4 );
163
bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
164
bitmap->num_grays = 256;
165
bitmap->width = width;
166
bitmap->rows = height;
167
bitmap->pitch = pitch;
169
if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
172
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
174
/* translate outline to render it into the bitmap */
175
FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
177
/* set up parameters */
178
params.target = bitmap;
179
params.source = outline;
180
params.flags = FT_RASTER_FLAG_AA;
182
/* implode outline if needed */
189
for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
193
for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
197
/* render outline into the bitmap */
198
error = render->raster_render( render->raster, ¶ms );
200
/* deflate outline if needed */
207
for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
211
for ( vec = outline->points, n = 0; n < outline->n_points; n++, vec++ )
215
FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
220
slot->format = FT_GLYPH_FORMAT_BITMAP;
221
slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
222
slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 );
225
if ( outline && origin )
226
FT_Outline_Translate( outline, -origin->x, -origin->y );
232
/* convert a slot's glyph image into a bitmap */
234
ft_smooth_render( FT_Renderer render,
239
if ( mode == FT_RENDER_MODE_LIGHT )
240
mode = FT_RENDER_MODE_NORMAL;
242
return ft_smooth_render_generic( render, slot, mode, origin,
243
FT_RENDER_MODE_NORMAL,
248
/* convert a slot's glyph image into a horizontal LCD bitmap */
250
ft_smooth_render_lcd( FT_Renderer render,
257
error = ft_smooth_render_generic( render, slot, mode, origin,
261
slot->bitmap.pixel_mode = FT_PIXEL_MODE_LCD;
267
/* convert a slot's glyph image into a vertical LCD bitmap */
269
ft_smooth_render_lcd_v( FT_Renderer render,
276
error = ft_smooth_render_generic( render, slot, mode, origin,
277
FT_RENDER_MODE_LCD_V,
280
slot->bitmap.pixel_mode = FT_PIXEL_MODE_LCD_V;
286
FT_CALLBACK_TABLE_DEF
287
const FT_Renderer_Class ft_smooth_renderer_class =
291
sizeof( FT_RendererRec ),
297
0, /* module specific interface */
299
(FT_Module_Constructor)ft_smooth_init,
300
(FT_Module_Destructor) 0,
301
(FT_Module_Requester) 0
304
FT_GLYPH_FORMAT_OUTLINE,
306
(FT_Renderer_RenderFunc) ft_smooth_render,
307
(FT_Renderer_TransformFunc)ft_smooth_transform,
308
(FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox,
309
(FT_Renderer_SetModeFunc) ft_smooth_set_mode,
311
(FT_Raster_Funcs*) &ft_grays_raster
315
FT_CALLBACK_TABLE_DEF
316
const FT_Renderer_Class ft_smooth_lcd_renderer_class =
320
sizeof( FT_RendererRec ),
326
0, /* module specific interface */
328
(FT_Module_Constructor)ft_smooth_init,
329
(FT_Module_Destructor) 0,
330
(FT_Module_Requester) 0
333
FT_GLYPH_FORMAT_OUTLINE,
335
(FT_Renderer_RenderFunc) ft_smooth_render_lcd,
336
(FT_Renderer_TransformFunc)ft_smooth_transform,
337
(FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox,
338
(FT_Renderer_SetModeFunc) ft_smooth_set_mode,
340
(FT_Raster_Funcs*) &ft_grays_raster
345
FT_CALLBACK_TABLE_DEF
346
const FT_Renderer_Class ft_smooth_lcdv_renderer_class =
350
sizeof( FT_RendererRec ),
356
0, /* module specific interface */
358
(FT_Module_Constructor)ft_smooth_init,
359
(FT_Module_Destructor) 0,
360
(FT_Module_Requester) 0
363
FT_GLYPH_FORMAT_OUTLINE,
365
(FT_Renderer_RenderFunc) ft_smooth_render_lcd_v,
366
(FT_Renderer_TransformFunc)ft_smooth_transform,
367
(FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox,
368
(FT_Renderer_SetModeFunc) ft_smooth_set_mode,
370
(FT_Raster_Funcs*) &ft_grays_raster