1 /***************************************************************************/
2 /*                                                                         */
3 /*  afpic.c                                                                */
4 /*                                                                         */
5 /*    The FreeType position independent code services for autofit module.  */
6 /*                                                                         */
7 /*  Copyright 2009-2015 by                                                 */
8 /*  Oran Agra and Mickey Gabel.                                            */
9 /*                                                                         */
10 /*  This file is part of the FreeType project, and may only be used,       */
11 /*  modified, and distributed under the terms of the FreeType project      */
12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13 /*  this file you indicate that you have read the license and              */
14 /*  understand and accept it fully.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17 
18 
19 #include <ft2build.h>
20 #include FT_FREETYPE_H
21 #include FT_INTERNAL_OBJECTS_H
22 #include "afpic.h"
23 #include "afglobal.h"
24 #include "aferrors.h"
25 
26 
27 #ifdef FT_CONFIG_OPTION_PIC
28 
29   /* forward declaration of PIC init functions from afmodule.c */
30   FT_Error
31   FT_Create_Class_af_services( FT_Library           library,
32                                FT_ServiceDescRec**  output_class );
33 
34   void
35   FT_Destroy_Class_af_services( FT_Library          library,
36                                 FT_ServiceDescRec*  clazz );
37 
38   void
39   FT_Init_Class_af_service_properties( FT_Service_PropertiesRec*  clazz );
40 
41   void FT_Init_Class_af_autofitter_interface(
42     FT_Library                   library,
43     FT_AutoHinter_InterfaceRec*  clazz );
44 
45 
46   /* forward declaration of PIC init functions from writing system classes */
47 #undef  WRITING_SYSTEM
48 #define WRITING_SYSTEM( ws, WS )  /* empty */
49 
50 #include "afwrtsys.h"
51 
52 
53   void
autofit_module_class_pic_free(FT_Library library)54   autofit_module_class_pic_free( FT_Library  library )
55   {
56     FT_PIC_Container*  pic_container = &library->pic_container;
57     FT_Memory          memory        = library->memory;
58 
59 
60     if ( pic_container->autofit )
61     {
62       AFModulePIC*  container = (AFModulePIC*)pic_container->autofit;
63 
64 
65       if ( container->af_services )
66         FT_Destroy_Class_af_services( library,
67                                       container->af_services );
68       container->af_services = NULL;
69 
70       FT_FREE( container );
71       pic_container->autofit = NULL;
72     }
73   }
74 
75 
76   FT_Error
autofit_module_class_pic_init(FT_Library library)77   autofit_module_class_pic_init( FT_Library  library )
78   {
79     FT_PIC_Container*  pic_container = &library->pic_container;
80     FT_UInt            ss;
81     FT_Error           error         = FT_Err_Ok;
82     AFModulePIC*       container     = NULL;
83     FT_Memory          memory        = library->memory;
84 
85 
86     /* allocate pointer, clear and set global container pointer */
87     if ( FT_ALLOC ( container, sizeof ( *container ) ) )
88       return error;
89     FT_MEM_SET( container, 0, sizeof ( *container ) );
90     pic_container->autofit = container;
91 
92     /* initialize pointer table -                       */
93     /* this is how the module usually expects this data */
94     error = FT_Create_Class_af_services( library,
95                                          &container->af_services );
96     if ( error )
97       goto Exit;
98 
99     FT_Init_Class_af_service_properties( &container->af_service_properties );
100 
101     for ( ss = 0; ss < AF_WRITING_SYSTEM_MAX; ss++ )
102       container->af_writing_system_classes[ss] =
103         &container->af_writing_system_classes_rec[ss];
104     container->af_writing_system_classes[AF_WRITING_SYSTEM_MAX] = NULL;
105 
106     for ( ss = 0; ss < AF_SCRIPT_MAX; ss++ )
107       container->af_script_classes[ss] =
108         &container->af_script_classes_rec[ss];
109     container->af_script_classes[AF_SCRIPT_MAX] = NULL;
110 
111     for ( ss = 0; ss < AF_STYLE_MAX; ss++ )
112       container->af_style_classes[ss] =
113         &container->af_style_classes_rec[ss];
114     container->af_style_classes[AF_STYLE_MAX] = NULL;
115 
116 #undef  WRITING_SYSTEM
117 #define WRITING_SYSTEM( ws, WS )                             \
118         FT_Init_Class_af_ ## ws ## _writing_system_class(    \
119           &container->af_writing_system_classes_rec[ss++] );
120 
121     ss = 0;
122 #include "afwrtsys.h"
123 
124 #undef  SCRIPT
125 #define SCRIPT( s, S, d, h, sc1, sc2, sc3 )          \
126         FT_Init_Class_af_ ## s ## _script_class(     \
127           &container->af_script_classes_rec[ss++] );
128 
129     ss = 0;
130 #include "afscript.h"
131 
132 #undef  STYLE
133 #define STYLE( s, S, d, ws, sc, bss, c )            \
134         FT_Init_Class_af_ ## s ## _style_class(     \
135           &container->af_style_classes_rec[ss++] );
136 
137     ss = 0;
138 #include "afstyles.h"
139 
140     FT_Init_Class_af_autofitter_interface(
141       library, &container->af_autofitter_interface );
142 
143   Exit:
144     if ( error )
145       autofit_module_class_pic_free( library );
146     return error;
147   }
148 
149 #endif /* FT_CONFIG_OPTION_PIC */
150 
151 
152 /* END */
153