2000-07-02 02:27:53 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftsmooth.c */
|
|
|
|
/* */
|
|
|
|
/* Anti-aliasing renderer interface (body). */
|
|
|
|
/* */
|
|
|
|
/* Copyright 2000 by */
|
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
|
|
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
|
|
|
/* this file you indicate that you have read the license and */
|
|
|
|
/* understand and accept it fully. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
#include FT_OUTLINE_H
|
2000-12-13 20:55:11 +01:00
|
|
|
#include FT_SOURCE_FILE(smooth,ftsmooth.h)
|
|
|
|
#include FT_SOURCE_FILE(smooth,ftgrays.h)
|
2000-07-02 02:27:53 +02:00
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
/* initialize renderer -- init its raster */
|
|
|
|
static
|
|
|
|
FT_Error ft_smooth_init( FT_Renderer render )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
2000-07-02 02:27:53 +02:00
|
|
|
FT_Library library = FT_MODULE_LIBRARY( render );
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
render->clazz->raster_class->raster_reset( render->raster,
|
2000-07-02 02:27:53 +02:00
|
|
|
library->raster_pool,
|
|
|
|
library->raster_pool_size );
|
2000-06-28 01:18:39 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
/* sets render-specific mode */
|
|
|
|
static
|
|
|
|
FT_Error ft_smooth_set_mode( FT_Renderer render,
|
|
|
|
FT_ULong mode_tag,
|
|
|
|
FT_Pointer data )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
|
|
|
/* we simply pass it to the raster */
|
2000-07-02 02:27:53 +02:00
|
|
|
return render->clazz->raster_class->raster_set_mode( render->raster,
|
|
|
|
mode_tag,
|
|
|
|
data );
|
2000-07-09 21:15:30 +02:00
|
|
|
}
|
2000-06-28 01:18:39 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
/* transform a given glyph image */
|
|
|
|
static
|
|
|
|
FT_Error ft_smooth_transform( FT_Renderer render,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
FT_Matrix* matrix,
|
|
|
|
FT_Vector* delta )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
2000-07-02 02:27:53 +02:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
|
|
|
|
if ( slot->format != render->glyph_format )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
goto Exit;
|
|
|
|
}
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( matrix )
|
2000-06-28 01:18:39 +02:00
|
|
|
FT_Outline_Transform( &slot->outline, matrix );
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( delta )
|
2000-06-28 01:18:39 +02:00
|
|
|
FT_Outline_Translate( &slot->outline, delta->x, delta->y );
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
|
|
|
|
/* return the glyph's control box */
|
|
|
|
static
|
|
|
|
void ft_smooth_get_cbox( FT_Renderer render,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
FT_BBox* cbox )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
2000-07-02 02:27:53 +02:00
|
|
|
MEM_Set( cbox, 0, sizeof ( *cbox ) );
|
2000-06-28 01:18:39 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( slot->format == render->glyph_format )
|
2000-06-28 01:18:39 +02:00
|
|
|
FT_Outline_Get_CBox( &slot->outline, cbox );
|
2000-07-09 21:15:30 +02:00
|
|
|
}
|
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
/* convert a slot's glyph image into a bitmap */
|
|
|
|
static
|
|
|
|
FT_Error ft_smooth_render( FT_Renderer render,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
FT_UInt mode,
|
|
|
|
FT_Vector* origin )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Outline* outline;
|
|
|
|
FT_BBox cbox;
|
|
|
|
FT_UInt width, height, pitch;
|
|
|
|
FT_Bitmap* bitmap;
|
|
|
|
FT_Memory memory;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
FT_Raster_Params params;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* check glyph image format */
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( slot->format != render->glyph_format )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
goto Exit;
|
|
|
|
}
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* check mode */
|
2000-07-01 01:12:55 +02:00
|
|
|
if ( mode != ft_render_mode_normal )
|
2000-06-28 01:18:39 +02:00
|
|
|
return FT_Err_Cannot_Render_Glyph;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
outline = &slot->outline;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* translate the outline to the new origin if needed */
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( origin )
|
2000-06-28 01:18:39 +02:00
|
|
|
FT_Outline_Translate( outline, origin->x, origin->y );
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* compute the control box, and grid fit it */
|
|
|
|
FT_Outline_Get_CBox( outline, &cbox );
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
cbox.xMin &= -64;
|
|
|
|
cbox.yMin &= -64;
|
2000-07-02 02:27:53 +02:00
|
|
|
cbox.xMax = ( cbox.xMax + 63 ) & -64;
|
|
|
|
cbox.yMax = ( cbox.yMax + 63 ) & -64;
|
2000-06-28 01:18:39 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
width = ( cbox.xMax - cbox.xMin ) >> 6;
|
|
|
|
height = ( cbox.yMax - cbox.yMin ) >> 6;
|
2000-06-28 01:18:39 +02:00
|
|
|
bitmap = &slot->bitmap;
|
2000-07-01 01:12:55 +02:00
|
|
|
memory = render->root.memory;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* release old bitmap buffer */
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( slot->flags & ft_glyph_own_bitmap )
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
2000-07-02 02:27:53 +02:00
|
|
|
FREE( bitmap->buffer );
|
2000-06-28 01:18:39 +02:00
|
|
|
slot->flags &= ~ft_glyph_own_bitmap;
|
|
|
|
}
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* allocate new one, depends on pixel format */
|
|
|
|
pitch = width;
|
|
|
|
bitmap->pixel_mode = ft_pixel_mode_grays;
|
|
|
|
bitmap->num_grays = 256;
|
|
|
|
bitmap->width = width;
|
|
|
|
bitmap->rows = height;
|
|
|
|
bitmap->pitch = pitch;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
|
2000-06-28 01:18:39 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
slot->flags |= ft_glyph_own_bitmap;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
/* 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 = ft_raster_flag_aa;
|
|
|
|
|
|
|
|
/* render outline into the bitmap */
|
|
|
|
error = render->raster_render( render->raster, ¶ms );
|
2000-07-02 02:27:53 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
slot->format = ft_glyph_format_bitmap;
|
|
|
|
slot->bitmap_left = cbox.xMin >> 6;
|
|
|
|
slot->bitmap_top = cbox.yMax >> 6;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const FT_Renderer_Class ft_smooth_renderer_class =
|
2000-06-28 01:18:39 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
ft_module_renderer,
|
|
|
|
sizeof( FT_RendererRec ),
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
"smooth",
|
2000-07-02 02:27:53 +02:00
|
|
|
0x10000L,
|
|
|
|
0x20000L,
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-06-28 01:18:39 +02:00
|
|
|
0, /* module specific interface */
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
(FT_Module_Constructor)ft_smooth_init,
|
|
|
|
(FT_Module_Destructor) 0,
|
|
|
|
(FT_Module_Requester) 0
|
2000-06-28 01:18:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ft_glyph_format_outline,
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
(FTRenderer_render) ft_smooth_render,
|
|
|
|
(FTRenderer_transform)ft_smooth_transform,
|
|
|
|
(FTRenderer_getCBox) ft_smooth_get_cbox,
|
|
|
|
(FTRenderer_setMode) ft_smooth_set_mode,
|
2000-07-09 21:15:30 +02:00
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
(FT_Raster_Funcs*) &ft_grays_raster
|
2000-06-28 01:18:39 +02:00
|
|
|
};
|
|
|
|
|
2000-07-02 02:27:53 +02:00
|
|
|
|
|
|
|
/* END */
|