Commit 7f316f22d1222484af9f7f62face6cb94be777b2

Werner Lemberg 2012-08-31T00:20:29

[autofit] Implement properties service framework. No properties are added yet. * src/autofit/afmodule.c: Include FT_SERVICE_PROPERTIES_H. (af_property_set, af_property_get): New dummy functions. (af_service_properties, af_services, af_get_interface): Provide service setup. (autofit_moduleclass): Add service interface. * src/autofit/afpic.c: Add necessary forward declarations. (autofit_module_class_pic_init): Add code for service addition. (autofit_module_pic_free): Add code for service removal. * src/autofit/afpic.h (AF_SERVICES_GET, AF_SERVICE_PROPERTIES_GET): New macros which provide necessary syntactical sugar for PIC support.

diff --git a/ChangeLog b/ChangeLog
index 0322f01..79ada24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2012-08-31  Werner Lemberg  <wl@gnu.org>
+
+	[autofit] Implement properties service framework.
+
+	No properties are added yet.
+
+	* src/autofit/afmodule.c: Include FT_SERVICE_PROPERTIES_H.
+	(af_property_set, af_property_get): New dummy functions.
+	(af_service_properties, af_services, af_get_interface): Provide
+	service setup.
+	(autofit_moduleclass): Add service interface.
+
+	* src/autofit/afpic.c: Add necessary forward declarations.
+	(autofit_module_class_pic_init): Add code for service addition.
+	(autofit_module_pic_free): Add code for service removal.
+	* src/autofit/afpic.h (AF_SERVICES_GET, AF_SERVICE_PROPERTIES_GET):
+	New macros which provide necessary syntactical sugar for PIC
+	support.
+
 2012-08-30  Werner Lemberg  <wl@gnu.org>
 
 	Implement properties to control FreeType modules.
diff --git a/src/autofit/afmodule.c b/src/autofit/afmodule.c
index 04cd894..ce20866 100644
--- a/src/autofit/afmodule.c
+++ b/src/autofit/afmodule.c
@@ -28,6 +28,68 @@
 #endif
 
 #include FT_INTERNAL_OBJECTS_H
+#include FT_SERVICE_PROPERTIES_H
+
+
+  FT_Error
+  af_property_set( FT_Library   library,
+                   const char*  property_name,
+                   const void*  value )
+  {
+    FT_UNUSED( library );
+    FT_UNUSED( value );
+
+    FT_TRACE0(( "af_property_get: missing property `%s'\n",
+                property_name ));
+    return FT_Err_Missing_Property;
+  }
+
+
+  FT_Error
+  af_property_get( FT_Library   library,
+                   const char*  property_name,
+                   void*        value )
+  {
+    FT_UNUSED( library );
+    FT_UNUSED( value );
+
+    FT_TRACE0(( "af_property_get: missing property `%s'\n",
+                property_name ));
+    return FT_Err_Missing_Property;
+  }
+
+
+  FT_DEFINE_SERVICE_PROPERTIESREC(
+    af_service_properties,
+    (FT_Properties_SetFunc)af_property_set,
+    (FT_Properties_GetFunc)af_property_get )
+
+
+  FT_DEFINE_SERVICEDESCREC1(
+    af_services,
+    FT_SERVICE_ID_PROPERTIES, &AF_SERVICE_PROPERTIES_GET )
+
+
+  FT_CALLBACK_DEF( FT_Module_Interface )
+  af_get_interface( FT_Module    module,
+                    const char*  module_interface )
+  {
+    /* AF_SERVICES_GET derefers `library' in PIC mode */
+#ifdef FT_CONFIG_OPTION_PIC
+    FT_Library  library;
+
+
+    if ( !module )
+      return NULL;
+    library = module->library;
+    if ( !library )
+      return NULL;
+#else
+    FT_UNUSED( module );
+#endif
+
+    return ft_service_list_lookup( AF_SERVICES_GET, module_interface );
+  }
 
 
   typedef struct  FT_AutofitterRec_
@@ -88,7 +150,7 @@
 
     (FT_Module_Constructor)af_autofitter_init,
     (FT_Module_Destructor) af_autofitter_done,
-    (FT_Module_Requester)  NULL )
+    (FT_Module_Requester)  af_get_interface )
 
 
 /* END */
diff --git a/src/autofit/afpic.c b/src/autofit/afpic.c
index 36a9cca..e6022f9 100644
--- a/src/autofit/afpic.c
+++ b/src/autofit/afpic.c
@@ -26,10 +26,22 @@
 #ifdef FT_CONFIG_OPTION_PIC
 
   /* forward declaration of PIC init functions from afmodule.c */
+  FT_Error
+  FT_Create_Class_af_services( FT_Library           library,
+                               FT_ServiceDescRec**  output_class );
+
+  void
+  FT_Destroy_Class_af_services( FT_Library          library,
+                                FT_ServiceDescRec*  clazz );
+
+  void
+  FT_Init_Class_af_service_properties( FT_Service_PropertiesRec*  clazz );
+
   void FT_Init_Class_af_autofitter_interface(
     FT_Library                   library,
     FT_AutoHinter_InterfaceRec*  clazz );
 
+
   /* forward declaration of PIC init functions from script classes */
 #include "aflatin.h"
 #ifdef FT_OPTION_AUTOFIT2
@@ -49,7 +61,15 @@
 
     if ( pic_container->autofit )
     {
-      FT_FREE( pic_container->autofit );
+      AFModulePIC*  container = (AFModulePIC*)pic_container->autofit;
+
+
+      if ( container->af_services )
+        FT_Destroy_Class_af_services( library,
+                                      container->af_services );
+      container->af_services = NULL;
+
+      FT_FREE( container );
       pic_container->autofit = NULL;
     }
   }
@@ -73,6 +93,13 @@
 
     /* initialize pointer table -                       */
     /* this is how the module usually expects this data */
+    error = FT_Create_Class_af_services( library,
+                                         &container->af_services );
+    if ( error )
+      goto Exit;
+
+    FT_Init_Class_af_service_properties( &container->af_service_properties );
+
     for ( ss = 0 ; ss < AF_SCRIPT_CLASSES_REC_COUNT ; ss++ )
     {
       container->af_script_classes[ss] =
@@ -98,8 +125,7 @@
     FT_Init_Class_af_autofitter_interface(
       library, &container->af_autofitter_interface );
 
-/* Exit: */
-
+  Exit:
     if ( error )
       autofit_module_class_pic_free( library );
     return error;
diff --git a/src/autofit/afpic.h b/src/autofit/afpic.h
index 41c832a..7a07bdf 100644
--- a/src/autofit/afpic.h
+++ b/src/autofit/afpic.h
@@ -27,11 +27,17 @@ FT_BEGIN_HEADER
 
 #ifndef FT_CONFIG_OPTION_PIC
 
-#define AF_SCRIPT_CLASSES_GET  af_script_classes
-#define AF_INTERFACE_GET       af_autofitter_interface
+#define AF_SERVICES_GET            af_services
+#define AF_SERVICE_PROPERTIES_GET  af_service_properties
+
+#define AF_SCRIPT_CLASSES_GET      af_script_classes
+#define AF_INTERFACE_GET           af_autofitter_interface
 
 #else /* FT_CONFIG_OPTION_PIC */
 
+  /* some include files required for members of AFModulePIC */
+#include FT_SERVICE_PROPERTIES_H
+
 #include "aftypes.h"
 
   /* increase these when you add new scripts, */
@@ -47,6 +53,9 @@ FT_BEGIN_HEADER
 
   typedef struct  AFModulePIC_
   {
+    FT_ServiceDescRec*          af_services;
+    FT_Service_PropertiesRec    af_service_properties;
+
     AF_ScriptClass              af_script_classes[AF_SCRIPT_CLASSES_COUNT];
     AF_ScriptClassRec           af_script_classes_rec[AF_SCRIPT_CLASSES_REC_COUNT];
     FT_AutoHinter_InterfaceRec  af_autofitter_interface;
@@ -57,6 +66,11 @@ FT_BEGIN_HEADER
 #define GET_PIC( lib )  \
           ( (AFModulePIC*)((lib)->pic_container.autofit) )
 
+#define AF_SERVICES_GET  \
+          ( GET_PIC( library )->af_services )
+#define AF_SERVICE_PROPERTIES_GET  \
+          ( GET_PIC( library)->af_service_properties )
+
 #define AF_SCRIPT_CLASSES_GET  \
           ( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_script_classes )
 #define AF_INTERFACE_GET  \