shithub: freetype+ttf2subf

Download patch

ref: 4e711be9f55c5e56d7d60de112d26fffe6e6b521
parent: 24b110c6c61cc52713ba4f58dd41f08b5af05025
author: Oran Agra <[email protected]>
date: Sun Apr 5 14:20:16 EDT 2009

Position Independent Code (PIC) support in pshinter module.

* include/freetype/internal/pshints.h add macros to init
instances of PSHinter_Interface.

* src/pshinter/pshmod.h declare pshinter_module_class
using macros from ftmodapi.h,
when FT_CONFIG_OPTION_PIC is defined create and destroy
functions will be declared.
* src/pshinter/pshmod.c when FT_CONFIG_OPTION_PIC is defined
pshinter_interface and pshinter_module_class structs
will have functions to init or create and destroy them
instead of being allocated in the global scope.
And macros will be used from pshpic.h in order to access them.

New Files:
* src/pshinter/pshpic.h declare struct to hold PIC globals for pshinter
module and macros to access them.
* src/pshinter/pshpic.c implement functions to allocate, destroy and
initialize PIC globals for pshinter module.

* src/pshinter/pshinter.c add new file to build: pshpic.c.
* src/pshinter/jamfile add new files to FT2_MULTI build: pshpic.c.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,31 @@
 2009-04-05  Oran Agra  <[email protected]>
 
+	Position Independent Code (PIC) support in pshinter module.
+
+	* include/freetype/internal/pshints.h add macros to init 
+	instances of PSHinter_Interface.
+
+	* src/pshinter/pshmod.h declare pshinter_module_class 
+	using macros from ftmodapi.h, 
+	when FT_CONFIG_OPTION_PIC is defined create and destroy
+	functions will be declared.
+	* src/pshinter/pshmod.c when FT_CONFIG_OPTION_PIC is defined 
+	pshinter_interface and pshinter_module_class structs 
+	will have functions to init or create and destroy them
+	instead of being allocated in the global scope.
+	And macros will be used from pshpic.h in order to access them.
+
+	New Files:
+	* src/pshinter/pshpic.h declare struct to hold PIC globals for pshinter
+	module and macros to access them.
+	* src/pshinter/pshpic.c implement functions to allocate, destroy and 
+	initialize PIC globals for pshinter module.
+
+	* src/pshinter/pshinter.c add new file to build: pshpic.c.
+	* src/pshinter/jamfile add new files to FT2_MULTI build: pshpic.c.
+
+2009-04-05  Oran Agra  <[email protected]>
+
 	Position Independent Code (PIC) support in psnames module.
 
 	* include/freetype/internal/services/svpscmap.h add macros to init 
--- a/include/freetype/internal/pshints.h
+++ b/include/freetype/internal/pshints.h
@@ -678,6 +678,30 @@
 
   typedef PSHinter_Interface*  PSHinter_Service;
 
+#ifndef FT_CONFIG_OPTION_PIC
+
+#define FT_DEFINE_PSHINTER_INTERFACE(class_, get_globals_funcs_,             \
+                                     get_t1_funcs_, get_t2_funcs_)           \
+  static const PSHinter_Interface class_ =                                   \
+  {                                                                          \
+    get_globals_funcs_, get_t1_funcs_, get_t2_funcs_                         \
+  };
+
+#else /* FT_CONFIG_OPTION_PIC */ 
+
+#define FT_DEFINE_PSHINTER_INTERFACE(class_, get_globals_funcs_,             \
+                                     get_t1_funcs_, get_t2_funcs_)           \
+  void                                                                       \
+  FT_Init_Class_##class_( FT_Library library,                                \
+                          PSHinter_Interface*  clazz)                        \
+  {                                                                          \
+    FT_UNUSED(library);                                                      \
+    clazz->get_globals_funcs = get_globals_funcs_;                           \
+    clazz->get_t1_funcs = get_t1_funcs_;                                     \
+    clazz->get_t2_funcs = get_t2_funcs_;                                     \
+  } 
+
+#endif /* FT_CONFIG_OPTION_PIC */ 
 
 FT_END_HEADER
 
--- a/src/pshinter/Jamfile
+++ b/src/pshinter/Jamfile
@@ -16,7 +16,7 @@
 
   if $(FT2_MULTI)
   {
-    _sources = pshrec pshglob pshalgo pshmod ;
+    _sources = pshrec pshglob pshalgo pshmod pshpic ;
   }
   else
   {
--- a/src/pshinter/pshinter.c
+++ b/src/pshinter/pshinter.c
@@ -19,6 +19,7 @@
 #define FT_MAKE_OPTION_SINGLE_OBJECT
 
 #include <ft2build.h>
+#include "pshpic.c"
 #include "pshrec.c"
 #include "pshglob.c"
 #include "pshalgo.c"
--- a/src/pshinter/pshmod.c
+++ b/src/pshinter/pshmod.c
@@ -20,6 +20,7 @@
 #include FT_INTERNAL_OBJECTS_H
 #include "pshrec.h"
 #include "pshalgo.h"
+#include "pshpic.h"
 
 
   /* the Postscript Hinter module structure */
@@ -92,18 +93,15 @@
   }
 
 
-  static
-  const PSHinter_Interface  pshinter_interface =
-  {
+  FT_DEFINE_PSHINTER_INTERFACE(pshinter_interface,
     pshinter_get_globals_funcs,
     pshinter_get_t1_funcs,
     pshinter_get_t2_funcs
-  };
+  )
 
 
-  FT_CALLBACK_TABLE_DEF
-  const FT_Module_Class  pshinter_module_class =
-  {
+  FT_DEFINE_MODULE(pshinter_module_class,
+
     0,
     sizeof ( PS_Hinter_ModuleRec ),
     "pshinter",
@@ -110,12 +108,11 @@
     0x10000L,
     0x20000L,
 
-    &pshinter_interface,            /* module-specific interface */
+    &FTPSHINTER_INTERFACE_GET,            /* module-specific interface */
 
     (FT_Module_Constructor)ps_hinter_init,
     (FT_Module_Destructor) ps_hinter_done,
     (FT_Module_Requester)  0        /* no additional interface for now */
-  };
-
+  )
 
 /* END */
--- a/src/pshinter/pshmod.h
+++ b/src/pshinter/pshmod.h
@@ -27,7 +27,7 @@
 FT_BEGIN_HEADER
 
 
-  FT_EXPORT_VAR( const FT_Module_Class )  pshinter_module_class;
+  FT_DECLARE_MODULE( pshinter_module_class )
 
 
 FT_END_HEADER
--- /dev/null
+++ b/src/pshinter/pshpic.c
@@ -1,0 +1,67 @@
+/***************************************************************************/
+/*                                                                         */
+/*  pshpic.c                                                               */
+/*                                                                         */
+/*    The FreeType position independent code services for pshinter 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 "pshpic.h"
+
+#ifdef FT_CONFIG_OPTION_PIC
+
+  /* forward declaration of PIC init functions from pshmod.c */
+  void FT_Init_Class_pshinter_interface( FT_Library, PSHinter_Interface*);
+
+  void
+  pshinter_module_class_pic_free( FT_Library library )
+  {
+    FT_PIC_Container* pic_container = &library->pic_container;
+    FT_Memory memory = library->memory;
+    if ( pic_container->pshinter )
+    {
+      FT_FREE( pic_container->pshinter );
+      pic_container->pshinter = NULL;
+    }
+  }
+
+  FT_Error
+  pshinter_module_class_pic_init( FT_Library library )
+  {
+    FT_PIC_Container* pic_container = &library->pic_container;
+    FT_Error        error = FT_Err_Ok;
+    PSHinterPIC*  container;
+    FT_Memory memory = library->memory;
+
+    /* 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->pshinter = container;
+    
+    /* add call to initialization function when you add new scripts */
+    FT_Init_Class_pshinter_interface(library, &container->pshinter_interface);
+
+/*Exit:*/
+    if(error)
+      pshinter_module_class_pic_free(library);
+    return error;
+  }
+
+
+#endif /* FT_CONFIG_OPTION_PIC */
+
+/* END */
--- /dev/null
+++ b/src/pshinter/pshpic.h
@@ -1,0 +1,53 @@
+/***************************************************************************/
+/*                                                                         */
+/*  pshpic.h                                                               */
+/*                                                                         */
+/*    The FreeType position independent code services for pshinter 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 __PSHPIC_H__
+#define __PSHPIC_H__
+
+  
+FT_BEGIN_HEADER
+
+#include FT_INTERNAL_PIC_H
+
+#ifndef FT_CONFIG_OPTION_PIC
+
+#define FTPSHINTER_INTERFACE_GET        pshinter_interface
+
+#else /* FT_CONFIG_OPTION_PIC */
+
+#include FT_INTERNAL_POSTSCRIPT_HINTS_H
+
+  typedef struct PSHinterPIC_
+  {
+    PSHinter_Interface pshinter_interface;
+  } PSHinterPIC;
+
+#define GET_PIC(lib)                    ((PSHinterPIC*)((lib)->pic_container.autofit))
+#define FTPSHINTER_INTERFACE_GET        (GET_PIC(library)->pshinter_interface)
+
+
+#endif /* FT_CONFIG_OPTION_PIC */
+
+ /* */
+
+FT_END_HEADER
+
+#endif /* __PSHPIC_H__ */
+
+
+/* END */