Position Independent Code (PIC) support in raster renderer.
* src/raster/ftrend1.h declare ft_raster1_renderer_class and ft_raster5_renderer_class using macros from ftrender.h, when FT_CONFIG_OPTION_PIC is defined create and destroy functions will be declared. * src/smooth/ftrend1.c when FT_CONFIG_OPTION_PIC is defined ft_raster1_renderer_class and ft_raster5_renderer_class structs will have functions to init or create and destroy them instead of being allocated in the global scope. Macros will be used from rastpic.h in order to access ft_standard_raster from the pic_container (allocated in ftraster.c). In ft_raster1_render when PIC is enabled, the last letter of module_name is used to verfy the renderer class rather than the class pointer. * src/raster/ftraster.c when FT_CONFIG_OPTION_PIC is defined ft_standard_raster struct will have function to init it instead of being allocated in the global scope. New Files: * src/raster/rastpic.h declare struct to hold PIC globals for raster renderer and macros to access them. * src/raster/rastpic.c implement functions to allocate, destroy and initialize PIC globals for raster renderer. * src/raster/raster.c add new file to build: rastpic.c. * src/raster/jamfile add new files to FT2_MULTI build: rastpic.c.
This commit is contained in:
parent
c1e22f3986
commit
056095096f
32
ChangeLog
32
ChangeLog
@ -1,3 +1,35 @@
|
||||
2009-04-05 Oran Agra <oran@monfort.co.il>
|
||||
|
||||
Position Independent Code (PIC) support in raster renderer.
|
||||
|
||||
* src/raster/ftrend1.h declare ft_raster1_renderer_class
|
||||
and ft_raster5_renderer_class
|
||||
using macros from ftrender.h,
|
||||
when FT_CONFIG_OPTION_PIC is defined create and destroy
|
||||
functions will be declared.
|
||||
* src/smooth/ftrend1.c when FT_CONFIG_OPTION_PIC is defined
|
||||
ft_raster1_renderer_class and ft_raster5_renderer_class structs
|
||||
will have functions to init or create and destroy them
|
||||
instead of being allocated in the global scope.
|
||||
Macros will be used from rastpic.h in order to access
|
||||
ft_standard_raster from the pic_container (allocated in ftraster.c).
|
||||
In ft_raster1_render when PIC is enabled, the last letter of
|
||||
module_name is used to verfy the renderer class rather than the
|
||||
class pointer.
|
||||
|
||||
* src/raster/ftraster.c when FT_CONFIG_OPTION_PIC is defined
|
||||
ft_standard_raster struct will have function to init it
|
||||
instead of being allocated in the global scope.
|
||||
|
||||
New Files:
|
||||
* src/raster/rastpic.h declare struct to hold PIC globals for raster
|
||||
renderer and macros to access them.
|
||||
* src/raster/rastpic.c implement functions to allocate, destroy and
|
||||
initialize PIC globals for raster renderer.
|
||||
|
||||
* src/raster/raster.c add new file to build: rastpic.c.
|
||||
* src/raster/jamfile add new files to FT2_MULTI build: rastpic.c.
|
||||
|
||||
2009-04-05 Oran Agra <oran@monfort.co.il>
|
||||
|
||||
Position Independent Code (PIC) support in smooth renderer.
|
||||
|
@ -16,7 +16,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) raster ;
|
||||
|
||||
if $(FT2_MULTI)
|
||||
{
|
||||
_sources = ftraster ftrend1 ;
|
||||
_sources = ftraster ftrend1 rastpic ;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -60,6 +60,7 @@
|
||||
|
||||
#endif /* !_STANDALONE_ */
|
||||
|
||||
#include "rastpic.h"
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
@ -3419,15 +3420,14 @@ a };
|
||||
}
|
||||
|
||||
|
||||
const FT_Raster_Funcs ft_standard_raster =
|
||||
{
|
||||
FT_DEFINE_RASTER_FUNCS(ft_standard_raster,
|
||||
FT_GLYPH_FORMAT_OUTLINE,
|
||||
(FT_Raster_New_Func) ft_black_new,
|
||||
(FT_Raster_Reset_Func) ft_black_reset,
|
||||
(FT_Raster_Set_Mode_Func)ft_black_set_mode,
|
||||
(FT_Raster_Render_Func) ft_black_render,
|
||||
(FT_Raster_Done_Func) ft_black_done
|
||||
};
|
||||
)
|
||||
|
||||
|
||||
/* END */
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include FT_OUTLINE_H
|
||||
#include "ftrend1.h"
|
||||
#include "ftraster.h"
|
||||
#include "rastpic.h"
|
||||
|
||||
#include "rasterrs.h"
|
||||
|
||||
@ -118,6 +119,7 @@
|
||||
}
|
||||
|
||||
/* check rendering mode */
|
||||
#ifndef FT_CONFIG_OPTION_PIC
|
||||
if ( mode != FT_RENDER_MODE_MONO )
|
||||
{
|
||||
/* raster1 is only capable of producing monochrome bitmaps */
|
||||
@ -130,6 +132,25 @@
|
||||
if ( render->clazz == &ft_raster5_renderer_class )
|
||||
return Raster_Err_Cannot_Render_Glyph;
|
||||
}
|
||||
#else /* FT_CONFIG_OPTION_PIC */
|
||||
/* When PIC is enabled, we cannot get to the class object */
|
||||
/* so instead we check the final character in the class name */
|
||||
/* ("raster5" or "raster1"). Yes this is a hack. */
|
||||
/* The "correct" thing to do is have different render function */
|
||||
/* for each of the classes. */
|
||||
if ( mode != FT_RENDER_MODE_MONO )
|
||||
{
|
||||
/* raster1 is only capable of producing monochrome bitmaps */
|
||||
if ( render->clazz->root.module_name[6] == '1' )
|
||||
return Raster_Err_Cannot_Render_Glyph;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* raster5 is only capable of producing 5-gray-levels bitmaps */
|
||||
if ( render->clazz->root.module_name[6] == '5' )
|
||||
return Raster_Err_Cannot_Render_Glyph;
|
||||
}
|
||||
#endif /* FT_CONFIG_OPTION_PIC */
|
||||
|
||||
outline = &slot->outline;
|
||||
|
||||
@ -208,10 +229,8 @@
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_TABLE_DEF
|
||||
const FT_Renderer_Class ft_raster1_renderer_class =
|
||||
{
|
||||
{
|
||||
FT_DEFINE_RENDERER(ft_raster1_renderer_class,
|
||||
|
||||
FT_MODULE_RENDERER,
|
||||
sizeof( FT_RendererRec ),
|
||||
|
||||
@ -224,7 +243,7 @@
|
||||
(FT_Module_Constructor)ft_raster1_init,
|
||||
(FT_Module_Destructor) 0,
|
||||
(FT_Module_Requester) 0
|
||||
},
|
||||
,
|
||||
|
||||
FT_GLYPH_FORMAT_OUTLINE,
|
||||
|
||||
@ -233,18 +252,17 @@
|
||||
(FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
|
||||
(FT_Renderer_SetModeFunc) ft_raster1_set_mode,
|
||||
|
||||
(FT_Raster_Funcs*) &ft_standard_raster
|
||||
};
|
||||
(FT_Raster_Funcs*) &FT_STANDARD_RASTER_GET
|
||||
)
|
||||
|
||||
|
||||
/* This renderer is _NOT_ part of the default modules; you will need */
|
||||
/* to register it by hand in your application. It should only be */
|
||||
/* used for backwards-compatibility with FT 1.x anyway. */
|
||||
/* */
|
||||
FT_CALLBACK_TABLE_DEF
|
||||
const FT_Renderer_Class ft_raster5_renderer_class =
|
||||
{
|
||||
{
|
||||
FT_DEFINE_RENDERER(ft_raster5_renderer_class,
|
||||
|
||||
|
||||
FT_MODULE_RENDERER,
|
||||
sizeof( FT_RendererRec ),
|
||||
|
||||
@ -257,7 +275,7 @@
|
||||
(FT_Module_Constructor)ft_raster1_init,
|
||||
(FT_Module_Destructor) 0,
|
||||
(FT_Module_Requester) 0
|
||||
},
|
||||
,
|
||||
|
||||
FT_GLYPH_FORMAT_OUTLINE,
|
||||
|
||||
@ -266,8 +284,8 @@
|
||||
(FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
|
||||
(FT_Renderer_SetModeFunc) ft_raster1_set_mode,
|
||||
|
||||
(FT_Raster_Funcs*) &ft_standard_raster
|
||||
};
|
||||
(FT_Raster_Funcs*) &FT_STANDARD_RASTER_GET
|
||||
)
|
||||
|
||||
|
||||
/* END */
|
||||
|
@ -27,13 +27,13 @@
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
FT_EXPORT_VAR( const FT_Renderer_Class ) ft_raster1_renderer_class;
|
||||
FT_DECLARE_RENDERER( ft_raster1_renderer_class )
|
||||
|
||||
/* this renderer is _NOT_ part of the default modules, you'll need */
|
||||
/* to register it by hand in your application. It should only be */
|
||||
/* used for backwards-compatibility with FT 1.x anyway. */
|
||||
/* */
|
||||
FT_EXPORT_VAR( const FT_Renderer_Class ) ft_raster5_renderer_class;
|
||||
FT_DECLARE_RENDERER( ft_raster5_renderer_class )
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define FT_MAKE_OPTION_SINGLE_OBJECT
|
||||
|
||||
#include <ft2build.h>
|
||||
#include "rastpic.c"
|
||||
#include "ftraster.c"
|
||||
#include "ftrend1.c"
|
||||
|
||||
|
89
src/raster/rastpic.c
Normal file
89
src/raster/rastpic.c
Normal file
@ -0,0 +1,89 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* rastpic.c */
|
||||
/* */
|
||||
/* The FreeType position independent code services for raster module. */
|
||||
/* */
|
||||
/* Copyright 2009 by */
|
||||
/* Oran Agra and Mickey Gabel. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_INTERNAL_OBJECTS_H
|
||||
#include "rastpic.h"
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_PIC
|
||||
|
||||
/* forward declaration of PIC init functions from ftraster.c */
|
||||
void FT_Init_Class_ft_standard_raster(FT_Raster_Funcs*);
|
||||
|
||||
void
|
||||
ft_raster1_renderer_class_pic_free( FT_Library library )
|
||||
{
|
||||
FT_PIC_Container* pic_container = &library->pic_container;
|
||||
FT_Memory memory = library->memory;
|
||||
if ( pic_container->raster )
|
||||
{
|
||||
RasterPIC* container = (RasterPIC*)pic_container->raster;
|
||||
if(--container->ref_count)
|
||||
return;
|
||||
FT_FREE( container );
|
||||
pic_container->raster = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FT_Error
|
||||
ft_raster1_renderer_class_pic_init( FT_Library library )
|
||||
{
|
||||
FT_PIC_Container* pic_container = &library->pic_container;
|
||||
FT_Error error = FT_Err_Ok;
|
||||
RasterPIC* container;
|
||||
FT_Memory memory = library->memory;
|
||||
|
||||
/* since this function also serve raster5 renderer,
|
||||
it implements reference counting */
|
||||
if(pic_container->raster)
|
||||
{
|
||||
((RasterPIC*)pic_container->raster)->ref_count++;
|
||||
return error;
|
||||
}
|
||||
|
||||
/* allocate pointer, clear and set global container pointer */
|
||||
if ( FT_ALLOC ( container, sizeof ( *container ) ) )
|
||||
return error;
|
||||
FT_MEM_SET( container, 0, sizeof(*container) );
|
||||
pic_container->raster = container;
|
||||
container->ref_count = 1;
|
||||
|
||||
/* initialize pointer table - this is how the module usually expects this data */
|
||||
FT_Init_Class_ft_standard_raster(&container->ft_standard_raster);
|
||||
/*Exit:*/
|
||||
if(error)
|
||||
ft_raster1_renderer_class_pic_free(library);
|
||||
return error;
|
||||
}
|
||||
|
||||
/* re-route these init and free functions to the above functions */
|
||||
FT_Error ft_raster5_renderer_class_pic_init(FT_Library library)
|
||||
{
|
||||
return ft_raster1_renderer_class_pic_init(library);
|
||||
}
|
||||
void ft_raster5_renderer_class_pic_free(FT_Library library)
|
||||
{
|
||||
ft_raster1_renderer_class_pic_free(library);
|
||||
}
|
||||
|
||||
#endif /* FT_CONFIG_OPTION_PIC */
|
||||
|
||||
|
||||
/* END */
|
50
src/raster/rastpic.h
Normal file
50
src/raster/rastpic.h
Normal file
@ -0,0 +1,50 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* rastpic.h */
|
||||
/* */
|
||||
/* The FreeType position independent code services for raster module. */
|
||||
/* */
|
||||
/* Copyright 2009 by */
|
||||
/* Oran Agra and Mickey Gabel. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#ifndef __RASTPIC_H__
|
||||
#define __RASTPIC_H__
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
#include FT_INTERNAL_PIC_H
|
||||
|
||||
#ifndef FT_CONFIG_OPTION_PIC
|
||||
#define FT_STANDARD_RASTER_GET ft_standard_raster
|
||||
|
||||
#else /* FT_CONFIG_OPTION_PIC */
|
||||
|
||||
typedef struct RasterPIC_
|
||||
{
|
||||
int ref_count;
|
||||
FT_Raster_Funcs ft_standard_raster;
|
||||
} RasterPIC;
|
||||
|
||||
#define GET_PIC(lib) ((RasterPIC*)((lib)->pic_container.raster))
|
||||
#define FT_STANDARD_RASTER_GET (GET_PIC(library)->ft_standard_raster)
|
||||
|
||||
#endif /* FT_CONFIG_OPTION_PIC */
|
||||
|
||||
/* */
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* __RASTPIC_H__ */
|
||||
|
||||
|
||||
/* END */
|
Loading…
Reference in New Issue
Block a user