summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOran Agra <oran@monfort.co.il>2009-04-05 18:16:13 +0300
committerOran Agra <oran@monfort.co.il>2009-04-05 18:16:13 +0300
commit056095096fdce9084e23116f7825784a2ad5e677 (patch)
tree75a520a3c90344eb9411e5dcb8b2ceb4e2282d64
parentc1e22f3986d8f7df115f9e5a627c396390cac679 (diff)
downloadfreetype2-056095096fdce9084e23116f7825784a2ad5e677.tar.gz
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.
-rw-r--r--ChangeLog32
-rw-r--r--src/raster/Jamfile2
-rw-r--r--src/raster/ftraster.c6
-rw-r--r--src/raster/ftrend1.c46
-rw-r--r--src/raster/ftrend1.h4
-rw-r--r--src/raster/raster.c1
-rw-r--r--src/raster/rastpic.c89
-rw-r--r--src/raster/rastpic.h50
8 files changed, 210 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 713485de5..da4c854c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,37 @@
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.
* src/smooth/ftsmooth.h declare ft_smooth_renderer_class,
diff --git a/src/raster/Jamfile b/src/raster/Jamfile
index f6e4251cb..4f60e87c7 100644
--- a/src/raster/Jamfile
+++ b/src/raster/Jamfile
@@ -16,7 +16,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) raster ;
if $(FT2_MULTI)
{
- _sources = ftraster ftrend1 ;
+ _sources = ftraster ftrend1 rastpic ;
}
else
{
diff --git a/src/raster/ftraster.c b/src/raster/ftraster.c
index eb9c4a45f..6724e8f4a 100644
--- a/src/raster/ftraster.c
+++ b/src/raster/ftraster.c
@@ -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 */
diff --git a/src/raster/ftrend1.c b/src/raster/ftrend1.c
index 3cc8d0741..1ed8af612 100644
--- a/src/raster/ftrend1.c
+++ b/src/raster/ftrend1.c
@@ -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 */
diff --git a/src/raster/ftrend1.h b/src/raster/ftrend1.h
index 76e9a5f58..4cf128622 100644
--- a/src/raster/ftrend1.h
+++ b/src/raster/ftrend1.h
@@ -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
diff --git a/src/raster/raster.c b/src/raster/raster.c
index f13a67a20..1202a116c 100644
--- a/src/raster/raster.c
+++ b/src/raster/raster.c
@@ -19,6 +19,7 @@
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
+#include "rastpic.c"
#include "ftraster.c"
#include "ftrend1.c"
diff --git a/src/raster/rastpic.c b/src/raster/rastpic.c
new file mode 100644
index 000000000..3c264877b
--- /dev/null
+++ b/src/raster/rastpic.c
@@ -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 */
diff --git a/src/raster/rastpic.h b/src/raster/rastpic.h
new file mode 100644
index 000000000..dcd82b8ca
--- /dev/null
+++ b/src/raster/rastpic.h
@@ -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 */