1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/***************************************************************************/
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  sfntpic.c                                                              */
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*    The FreeType position independent code services for sfnt module.     */
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
7ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*  Copyright 2009-2015 by                                                 */
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  Oran Agra and Mickey Gabel.                                            */
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  This file is part of the FreeType project, and may only be used,       */
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  modified, and distributed under the terms of the FreeType project      */
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  this file you indicate that you have read the license and              */
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  understand and accept it fully.                                        */
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/***************************************************************************/
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
19e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include <ft2build.h>
20e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include FT_FREETYPE_H
21e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include FT_INTERNAL_OBJECTS_H
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "sfntpic.h"
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "sferrors.h"
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef FT_CONFIG_OPTION_PIC
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* forward declaration of PIC init functions from sfdriver.c */
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Error
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Create_Class_sfnt_services( FT_Library           library,
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                 FT_ServiceDescRec**  output_class );
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Destroy_Class_sfnt_services( FT_Library          library,
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                  FT_ServiceDescRec*  clazz );
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Init_Class_sfnt_service_bdf( FT_Service_BDFRec*  clazz );
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Init_Class_sfnt_interface( FT_Library       library,
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                SFNT_Interface*  clazz );
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Init_Class_sfnt_service_glyph_dict(
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Library                library,
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Service_GlyphDictRec*  clazz );
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Init_Class_sfnt_service_ps_name(
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Library                 library,
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Service_PsFontNameRec*  clazz );
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Init_Class_tt_service_get_cmap_info(
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Library              library,
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Service_TTCMapsRec*  clazz );
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Init_Class_sfnt_service_sfnt_table(
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Service_SFNT_TableRec*  clazz );
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* forward declaration of PIC init functions from ttcmap.c */
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Error
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Create_Class_tt_cmap_classes( FT_Library       library,
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                   TT_CMap_Class**  output_class );
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Destroy_Class_tt_cmap_classes( FT_Library      library,
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                    TT_CMap_Class*  clazz );
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  void
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  sfnt_module_class_pic_free( FT_Library  library )
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  {
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_PIC_Container*  pic_container = &library->pic_container;
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Memory          memory        = library->memory;
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( pic_container->sfnt )
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      sfntModulePIC*  container = (sfntModulePIC*)pic_container->sfnt;
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      if ( container->sfnt_services )
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FT_Destroy_Class_sfnt_services( library,
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                        container->sfnt_services );
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      container->sfnt_services = NULL;
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      if ( container->tt_cmap_classes )
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FT_Destroy_Class_tt_cmap_classes( library,
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                          container->tt_cmap_classes );
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      container->tt_cmap_classes = NULL;
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      FT_FREE( container );
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      pic_container->sfnt = NULL;
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  }
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_Error
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  sfnt_module_class_pic_init( FT_Library  library )
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  {
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_PIC_Container*  pic_container = &library->pic_container;
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Error           error         = FT_Err_Ok;
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    sfntModulePIC*     container     = NULL;
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Memory          memory        = library->memory;
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    /* allocate pointer, clear and set global container pointer */
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( FT_ALLOC( container, sizeof ( *container ) ) )
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      return error;
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_MEM_SET( container, 0, sizeof ( *container ) );
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pic_container->sfnt = container;
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    /* initialize pointer table -                       */
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    /* this is how the module usually expects this data */
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    error = FT_Create_Class_sfnt_services( library,
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                           &container->sfnt_services );
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( error )
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      goto Exit;
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    error = FT_Create_Class_tt_cmap_classes( library,
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                             &container->tt_cmap_classes );
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( error )
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      goto Exit;
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Init_Class_sfnt_service_glyph_dict(
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      library, &container->sfnt_service_glyph_dict );
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Init_Class_sfnt_service_ps_name(
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      library, &container->sfnt_service_ps_name );
125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Init_Class_tt_service_get_cmap_info(
126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      library, &container->tt_service_get_cmap_info );
127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Init_Class_sfnt_service_sfnt_table(
128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      &container->sfnt_service_sfnt_table );
129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef TT_CONFIG_OPTION_BDF
130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Init_Class_sfnt_service_bdf( &container->sfnt_service_bdf );
131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Init_Class_sfnt_interface( library, &container->sfnt_interface );
133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  Exit:
135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( error )
136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov      sfnt_module_class_pic_free( library );
137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return error;
138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  }
139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif /* FT_CONFIG_OPTION_PIC */
141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/* END */
144