1/***************************************************************************/
2/*                                                                         */
3/*  basepic.c                                                              */
4/*                                                                         */
5/*    The FreeType position independent code services for base.            */
6/*                                                                         */
7/*  Copyright 2009, 2012 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 "basepic.h"
23
24
25#ifdef FT_CONFIG_OPTION_PIC
26
27  /* forward declaration of PIC init functions from ftglyph.c */
28  void
29  FT_Init_Class_ft_outline_glyph_class( FT_Glyph_Class*  clazz );
30
31  void
32  FT_Init_Class_ft_bitmap_glyph_class( FT_Glyph_Class*  clazz );
33
34#ifdef FT_CONFIG_OPTION_MAC_FONTS
35  /* forward declaration of PIC init function from ftrfork.c */
36  /* (not modularized)                                       */
37  void
38  FT_Init_Table_raccess_guess_table( ft_raccess_guess_rec*  record );
39#endif
40
41  /* forward declaration of PIC init functions from ftinit.c */
42  FT_Error
43  ft_create_default_module_classes( FT_Library  library );
44
45  void
46  ft_destroy_default_module_classes( FT_Library  library );
47
48
49  void
50  ft_base_pic_free( FT_Library  library )
51  {
52    FT_PIC_Container*  pic_container = &library->pic_container;
53    FT_Memory          memory        = library->memory;
54
55
56    if ( pic_container->base )
57    {
58      /* destroy default module classes            */
59      /* (in case FT_Add_Default_Modules was used) */
60      ft_destroy_default_module_classes( library );
61
62      FT_FREE( pic_container->base );
63      pic_container->base = NULL;
64    }
65  }
66
67
68  FT_Error
69  ft_base_pic_init( FT_Library  library )
70  {
71    FT_PIC_Container*  pic_container = &library->pic_container;
72    FT_Error           error         = FT_Err_Ok;
73    BasePIC*           container     = NULL;
74    FT_Memory          memory        = library->memory;
75
76
77    /* allocate pointer, clear and set global container pointer */
78    if ( FT_ALLOC( container, sizeof ( *container ) ) )
79      return error;
80    FT_MEM_SET( container, 0, sizeof ( *container ) );
81    pic_container->base = container;
82
83    /* initialize default modules list and pointers */
84    error = ft_create_default_module_classes( library );
85    if ( error )
86      goto Exit;
87
88    /* initialize pointer table -                       */
89    /* this is how the module usually expects this data */
90    FT_Init_Class_ft_outline_glyph_class(
91      &container->ft_outline_glyph_class );
92    FT_Init_Class_ft_bitmap_glyph_class(
93      &container->ft_bitmap_glyph_class );
94#ifdef FT_CONFIG_OPTION_MAC_FONTS
95    FT_Init_Table_raccess_guess_table(
96      (ft_raccess_guess_rec*)&container->ft_raccess_guess_table );
97#endif
98
99  Exit:
100    if ( error )
101      ft_base_pic_free( library );
102    return error;
103  }
104
105#endif /* FT_CONFIG_OPTION_PIC */
106
107
108/* END */
109