Upload tizen 2.0 beta source
[framework/graphics/freetype.git] / src / autofit / afpic.c
1 /***************************************************************************/
2 /*                                                                         */
3 /*  afpic.c                                                                */
4 /*                                                                         */
5 /*    The FreeType position independent code services for autofit module.  */
6 /*                                                                         */
7 /*  Copyright 2009, 2010, 2011 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 "aferrors.h"
24
25 #ifdef FT_CONFIG_OPTION_PIC
26
27   /* forward declaration of PIC init functions from afmodule.c */
28   void FT_Init_Class_af_autofitter_service(
29     FT_Library                 library,
30     FT_AutoHinter_ServiceRec*  clazz );
31
32   /* forward declaration of PIC init functions from script classes */
33 #include "aflatin.h"
34 #ifdef FT_OPTION_AUTOFIT2
35 #include "aflatin2.h"
36 #endif
37 #include "afcjk.h"
38 #include "afdummy.h"
39 #include "afindic.h"
40
41   void
42   autofit_module_class_pic_free( FT_Library  library )
43   {
44     FT_PIC_Container*  pic_container = &library->pic_container;
45     FT_Memory          memory        = library->memory;
46
47
48     if ( pic_container->autofit )
49     {
50       FT_FREE( pic_container->autofit );
51       pic_container->autofit = NULL;
52     }
53   }
54
55
56   FT_Error
57   autofit_module_class_pic_init( FT_Library  library )
58   {
59     FT_PIC_Container*  pic_container = &library->pic_container;
60     FT_UInt            ss;
61     FT_Error           error         = AF_Err_Ok;
62     AFModulePIC*       container;
63     FT_Memory          memory        = library->memory;
64
65
66     /* allocate pointer, clear and set global container pointer */
67     if ( FT_ALLOC ( container, sizeof ( *container ) ) )
68       return error;
69     FT_MEM_SET( container, 0, sizeof ( *container ) );
70     pic_container->autofit = container;
71
72     /* initialize pointer table -                       */
73     /* this is how the module usually expects this data */
74     for ( ss = 0 ; ss < AF_SCRIPT_CLASSES_REC_COUNT ; ss++ )
75     {
76       container->af_script_classes[ss] =
77         &container->af_script_classes_rec[ss];
78     }
79     container->af_script_classes[AF_SCRIPT_CLASSES_COUNT - 1] = NULL;
80
81     /* add call to initialization function when you add new scripts */
82     ss = 0;
83     FT_Init_Class_af_dummy_script_class(
84       &container->af_script_classes_rec[ss++] );
85 #ifdef FT_OPTION_AUTOFIT2
86     FT_Init_Class_af_latin2_script_class(
87       &container->af_script_classes_rec[ss++] );
88 #endif
89     FT_Init_Class_af_latin_script_class(
90       &container->af_script_classes_rec[ss++] );
91     FT_Init_Class_af_cjk_script_class(
92       &container->af_script_classes_rec[ss++] );
93     FT_Init_Class_af_indic_script_class(
94       &container->af_script_classes_rec[ss++] );
95
96     FT_Init_Class_af_autofitter_service(
97       library, &container->af_autofitter_service );
98
99 /* Exit: */
100
101     if ( error )
102       autofit_module_class_pic_free( library );
103     return error;
104   }
105
106
107 #endif /* FT_CONFIG_OPTION_PIC */
108
109
110 /* END */