Hash :
f0df85ba
Author :
Date :
2000-06-22T00:17:42
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
#include <freetype/internal/ftobjs.h>
/* initialise renderer - init its raster */
static FT_Error ft_renderer_init( FT_Renderer render )
{
FT_Library library = FT_MODULE_LIBRARY(render);
render->clazz->raster_class->raster_reset( render->raster,
library->raster_pool, library->raster_pool_size );
return 0;
}
/* sets render-specific mode */
static FT_Error ft_renderer_set_mode( FT_Renderer render,
FT_ULong mode_tag,
FT_Pointer data )
{
/* we simply pass it to the raster */
return render->clazz->raster_class->raster_set_mode(
render->raster, mode_tag, data );
}
/* transform a given glyph image */
static FT_Error ft_renderer_transform( FT_Renderer render,
FT_GlyphSlot slot,
FT_Matrix* matrix,
FT_Vector* delta )
{
FT_Error error = FT_Err_Ok;
if (slot->format != render->glyph_format)
{
error = FT_Err_Invalid_Argument;
goto Exit;
}
if (matrix)
FT_Outline_Transform( &slot->outline, matrix );
if (delta)
FT_Outline_Translate( &slot->outline, delta->x, delta->y );
Exit:
return error;
}
/* return the glyph's control box */
static void ft_renderer_get_cbox( FT_Renderer render,
FT_GlyphSlot slot,
FT_BBox *cbox )
{
MEM_Set( cbox, 0, sizeof(*cbox) );
if (slot->format == render->glyph_format)
FT_Outline_Get_CBox( &slot->outline, cbox );
}
/* convert a slot's glyph image into a bitmap */
static FT_Error ft_renderer_render( FT_Renderer render,
FT_GlyphSlot slot,
FT_UInt mode,
FT_Vector* origin )
{
FT_Error error;
FT_Outline* outline;
FT_BBox cbox;
FT_UInt width, height, pitch;
FT_Bitmap* bitmap;
FT_Memory memory;
FT_Raster_Params params;
/* check glyph image format */
if (slot->format != render->glyph_format)
{
error = FT_Err_Invalid_Argument;
goto Exit;
}
outline = &slot->outline;
/* translate the outline to the new origin if needed */
if (origin)
FT_Outline_Translate( outline, origin->x, origin->y );
/* compute the control box, and grid fit it */
FT_Outline_Get_CBox( outline, &cbox );
cbox.xMin &= -64;
cbox.yMin &= -64;
cbox.xMax = (cbox.xMax+63) & -64;
cbox.yMax = (cbox.yMax+63) & -64;
width = (cbox.xMax - cbox.xMin) >> 6;
height = (cbox.yMax - cbox.yMin) >> 6;
bitmap = &slot->bitmap;
memory = slot->face->memory;
/* release old bitmap buffer */
if ((slot->flags & ft_glyph_own_bitmap))
{
FREE(bitmap->buffer);
slot->flags &= ~ft_glyph_own_bitmap;
}
/* allocate new one, depends on pixel format */
if ( mode & ft_render_mode_antialias )
{
pitch = width;
bitmap->pixel_mode = ft_pixel_mode_grays;
bitmap->num_grays = 256;
}
else
{
pitch = (width+7) >> 3;
bitmap->pixel_mode = ft_pixel_mode_mono;
}
bitmap->width = width;
bitmap->rows = height;
bitmap->pitch = pitch;
if (ALLOC( bitmap->buffer, (FT_ULong)pitch * height ))
goto Exit;
slot->flags |= ft_glyph_own_bitmap;
/* translate outline to render it into the bitmap */
FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
/* set up parameters */
params.target = bitmap;
params.source = outline;
params.flags = 0;
if ( bitmap->pixel_mode == ft_pixel_mode_grays )
params.flags |= ft_raster_flag_aa;
/* render outline into the bitmap */
error = render->raster_render( render->raster, ¶ms );
if (error) goto Exit;
slot->format = ft_glyph_format_bitmap;
slot->bitmap_left = cbox.xMin >> 6;
slot->bitmap_top = cbox.yMax >> 6;
Exit:
return error;
}
#ifndef FT_CONFIG_OPTION_NO_STD_RASTER
#include <freetype/ftraster.h>
const FT_Renderer_Class ft_standard_renderer_class =
{
{
ft_module_renderer,
sizeof( FT_RendererRec ),
"standard renderer",
0x10000,
0x20000,
0, /* module specific interface */
(FT_Module_Constructor) ft_renderer_init,
(FT_Module_Destructor) 0,
(FT_Module_Requester) 0
},
ft_glyph_format_outline,
(FTRenderer_render) ft_renderer_render,
(FTRenderer_transform) ft_renderer_transform,
(FTRenderer_getCBox) ft_renderer_get_cbox,
(FTRenderer_setMode) ft_renderer_set_mode,
(FT_Raster_Funcs*) &ft_standard_raster
};
#endif /* !FT_CONFIG_OPTION_NO_STD_RASTER */
#ifndef FT_CONFIG_OPTION_NO_SMOOTH_RASTER
#include <freetype/ftgrays.h>
const FT_Renderer_Class ft_smooth_renderer_class =
{
{
ft_module_renderer,
sizeof( FT_RendererRec ),
"smooth renderer",
0x10000,
0x20000,
0, /* module specific interface */
(FT_Module_Constructor) ft_renderer_init,
(FT_Module_Destructor) 0,
(FT_Module_Requester) 0
},
ft_glyph_format_outline,
(FTRenderer_render) ft_renderer_render,
(FTRenderer_transform) ft_renderer_transform,
(FTRenderer_getCBox) ft_renderer_get_cbox,
(FTRenderer_setMode) ft_renderer_set_mode,
(FT_Raster_Funcs*) &ft_grays_raster
};
#endif /* !FT_CONFIG_OPTION_NO_SMOOTH_RASTER */