summaryrefslogtreecommitdiff
path: root/src/otlayout/otobjs.c
blob: 199cddb3de6bc832a474f43cececcd1863abf73b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/***************************************************************************/
/*                                                                         */
/*  otobjs.c                                                               */
/*                                                                         */
/*    OpenType objects manager (body).                                     */
/*                                                                         */
/***************************************************************************/

#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_TRUETYPE_TAGS_H
#include FT_LIST_H
#include FT_ERRORS_H
#include FT_LAYOUT_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_LAYOUT_H
#include FT_OTLAYOUT_H
#include "otobjs.h"
#include "ot-types.h"
#include "ot-info.h"
#include "oterrors.h"
#include "otdriver.h"
#include "otltypes.h"


  extern const FT_Driver_ClassRec tt_driver_class;

  /*************************************************************************/
  /*                                                                       */
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
  /* messages during execution.                                            */
  /*                                                                       */
#undef  FT_COMPONENT
#define FT_COMPONENT  trace_otobjs

  static FT_Error
  ot_face_init( FT_Stream      stream,
                OT_Face        face,
                FT_Int         face_index,
                FT_Int         num_params,
                FT_Parameter*  params );

  static FT_Error
  ot_font_load ( OT_Face  face );

  static void
  ot_font_done( void * object );

  static FT_Module_Interface
  ot_module_get_interface ( FT_Module module,
			    const char* ot_interface );

  static const FT_Service_LayoutRec  ot_service_layout =
  {
    (FTL_Get_Font_Func)                   otl_get_font,
    (FTL_Get_EngineType_Func)             otl_get_engine_type,
    (FTL_New_FeaturesRequest_Func)        otl_new_features_request,
    (FTL_Done_FeaturesRequest_Func)       otl_done_features_request,
    (FTL_Copy_FeaturesRequest_Func)       otl_copy_features_request,
    (FTL_Get_LigatureCaret_Count_Func)    NULL, /* TODO */
    (FTL_Get_LigatureCaret_Division_Func) NULL, /* TODO */
    (FTL_Substitute_Glyphs_Func)          otl_substitute_glyphs 
  };

  static const FT_ServiceDescRec  ot_services[] =
  {
    { FT_SERVICE_ID_LAYOUT, &ot_service_layout },
    { NULL, NULL }
  };

  FT_LOCAL_DEF( FT_Error )
  ot_driver_init( OT_Driver  driver )
  {
    FT_Error error;
    
    const void * module_name;
    FT_Driver ot_driver_root = &driver->root;
    FT_Driver_Class ot_driver_class = ot_driver_root->clazz;

    module_name = ot_driver_class->root.module_name;

    *ot_driver_class = tt_driver_class;
    driver->root.clazz->root.module_name  = module_name;
    
    if (( error = ((FT_Module_Class*)ot_driver_class)->module_init( (FT_Module)driver ) ))
      return error;
    
    ot_driver_class->init_face 			       = (FT_Face_InitFunc)ot_face_init;
    ((FT_Module_Class*)ot_driver_class)->get_interface = ot_module_get_interface;

    return OT_Err_Ok;
  }
  
  static FT_Error
  ot_face_init( FT_Stream      stream,
                OT_Face        face,
                FT_Int         face_index,
                FT_Int         num_params,
                FT_Parameter*  params )
  {
    FT_Error error;
    
    /* TODO */
    error = tt_driver_class.init_face ( stream, (FT_Face)face, face_index, num_params, params );
    if ( error )
      goto Exit;
    
    error = ot_font_load ( face );
    if ( error )
      goto Exit;
  Exit:
    return error;
  }

  static FT_Error
  ot_font_load( OT_Face  face )
  {
    FT_Error error;
    FT_Memory memory = FT_FACE_MEMORY( face );
    
    OTL_Font font = NULL;
    OTL_FeaturesRequest features_request;
    OTInfo * ot_info;
    
    if ( face->extra.data )
      {
	error = OT_Err_Busy_Extra_Data;
	goto Exit;
      }

    ot_info = ot_info_get ( (FT_Face) face );
    if ( !ot_info )
      {
	error = OT_Err_Unknown_File_Format;
	goto Exit;
      }

    if ( FT_NEW ( font ) )
      goto Exit;

    font->info = ot_info;
    if (( error = FTL_Font_Init ( (FTL_Font)font, (FT_Face)face ) ))
      goto Failure;

    face->extra.finalizer = ot_font_done;
    face->extra.data = font;
    if (( error = FTL_New_FeaturesRequest ( (FT_Face)face, 
					    (FTL_FeaturesRequest*)(&features_request) ) ))
      goto Failure;
    face->root.face_flags |= FT_FACE_FLAG_GLYPH_SUBSTITUTION; /* ??? */
    error =  OT_Err_Ok;
  Exit:
    return error;
  Failure:
    if ( font )
      FT_FREE( font );
    face->extra.finalizer = NULL;
    face->extra.data = NULL;
    return error;
  }
  
  static void
  ot_font_done( void * object )
  {
    OTL_Font font     = object;
    FT_Face face      = FTL_FONT_FACE( font );
    FT_Memory memory  = FT_FACE_MEMORY( face );
    
    FTL_Font_Finalize((FTL_Font)font);
    FT_FREE( object );
  }

  static FT_Module_Interface
  ot_module_get_interface( FT_Module module,
			   const char* ot_interface )
  {
    FT_Module_Interface ot;

    ot = ft_service_list_lookup( ot_services, ot_interface );
    if ( ot )
      return ot;
    
    /* TODO */
    if ( tt_driver_class.root.get_interface )
      return tt_driver_class.root.get_interface( module, ot_interface );
    return NULL;
  }