summaryrefslogtreecommitdiff
path: root/src/otlayout/otlayout.c
blob: 18bb55aa431aabaf13a6d23883427551d44d657c (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/***************************************************************************/
/*                                                                         */
/*  otlayout.c                                                             */
/*                                                                         */
/*    OpenType based layout engine(body).                                  */
/*                                                                         */
/*  Copyright 2003 by                                                      */
/*  Masatake YAMATO and Redhat K.K.                                        */
/*                                                                         */
/*  This file may only be used,                                            */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/***************************************************************************/

/***************************************************************************/
/* Development of the code in this file is support of                      */
/* Information-technology Promotion Agency, Japan.                         */
/***************************************************************************/

/*
 * Experimental: No support for gpos now.
 */

#include <ft2build.h>
#include FT_LIST_H
#include FT_OTLAYOUT_H

#include "otltypes.h"
#include "ot-types.h"
#include "ot-ruleset.h"
#include "ot-info.h"
#include "oterrors.h"

  FT_LOCAL_DEF ( FT_Error )
  otl_get_font ( FT_Face face, FTL_Font * font)
  {
    *font = ((OT_Face)face)->extra.data;
    
    if ( *font )
      return FT_Err_Ok;
    else
      return OT_Err_Invalid_Face_Handle;
  }

  FT_LOCAL_DEF ( FTL_EngineType )
  otl_get_engine_type ( FT_Face face )
  {
    return FTL_OPENTYPE_ENGINE;
  }

  FT_LOCAL ( FT_Error ) 
  otl_new_features_request( FT_Face face, FTL_FeaturesRequest * ftl_request)
  {
    FT_Error error;
    FT_Memory memory = FT_FACE_MEMORY(face);
    OTL_Font font;
    OTL_FeaturesRequest request;
    
    if (( error = otl_get_font ( face, (FTL_Font*)&font ) ))
      goto Exit;
    
    if ( FT_NEW(request) )
      goto Exit;
    
    request->ruleset = ot_ruleset_new ( font->info );
    if ( !request->ruleset )
      {
	error = OT_Err_Invalid_Argument; /* ??? */
	goto Failure;
      }
    
    if (( error =  FTL_FeaturesRequest_Init ( face, (FTL_FeaturesRequest)request ) ))
	goto Failure;
    *ftl_request = (FTL_FeaturesRequest)request;
  Exit:
    return error;    
  Failure:
    if ( request->ruleset )
      ot_ruleset_delete( request->ruleset );
    FT_FREE( request );
    return error;
  }

  FT_LOCAL ( FT_Error ) 
  otl_done_features_request( FTL_FeaturesRequest request)
  {
    FT_Error error;
    FTL_Font font;
    FT_Face face;
    FT_Memory memory;
    
    FT_ASSERT( request );
    font = FTL_FEATURES_REQUEST_FONT ( request );
    
    FT_ASSERT( font );
    face = FTL_FONT_FACE(font);

    if ( !face )
      return OT_Err_Invalid_Argument;
    memory = FT_FACE_MEMORY( face );
    ot_ruleset_delete ( ((OTL_FeaturesRequest)request)->ruleset );
    error = FTL_FeaturesRequest_Finalize ( request );
    FT_FREE( request );		/* broken */
    return error;
  }

  FT_LOCAL ( FT_Error ) 
  otl_copy_features_request( FTL_FeaturesRequest from,
			     FTL_FeaturesRequest to)
  {
    FT_Error error;
    ot_ruleset_copy(((OTL_FeaturesRequest)from)->ruleset, ((OTL_FeaturesRequest)to)->ruleset);
    error = FTL_FeaturesRequest_Copy( from, to );
    return error;
  }

  FT_LOCAL ( FT_Error )
  otl_substitute_glyphs ( FT_Face face,
			  FTL_FeaturesRequest request,
			  FTL_Glyphs_Array in,
			  FTL_Glyphs_Array out )
  {
    FT_Error error = FT_Err_Ok;
    if (( error = FTL_Copy_Glyphs_Array ( in, out ) ))
      return error;
    ot_ruleset_shape ( ((OTL_FeaturesRequest)request)->ruleset, out );
    return FT_Err_Ok;
  }

  FT_EXPORT( FT_Bool )
  OTL_FeaturesRequest_Find_Script    ( OTL_FeaturesRequest request,
				       OTTableType table_type,
				       OTTag       script_tag,
				       FT_UInt    *script_index)
  {
    OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
    return ot_info_find_script ( font->info, 
				 table_type, 
				 script_tag, 
				 script_index )
      ? 1: 0;
      
  }

  FT_EXPORT( FT_Bool )
  OTL_FeaturesRequest_Find_Language  ( OTL_FeaturesRequest request,
				       OTTableType table_type,
				       FT_UInt     script_index,
				       OTTag       language_tag,
				       FT_UInt    *language_index,
				       FT_UInt    *required_feature_index )
  {
    OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
    return ot_info_find_language ( font->info, 
				   table_type, 
				   script_index, 
				   language_tag,
				   language_index,
				   required_feature_index )
      ? 1: 0;
  }

  FT_EXPORT ( FT_Bool )
  OTL_FeaturesRequest_Find_Feature   ( OTL_FeaturesRequest request,
				       OTTableType         table_type,
				       OTTag               feature_tag,
				       FT_UInt             script_index,
				       FT_UInt             language_index,
				       FT_UInt            *feature_index )
  {
    OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
    return ot_info_find_feature ( font->info, 
				  table_type,
				  feature_tag,
				  script_index, 
				  language_index,
				  feature_index )
      ? 1: 0;
  }

  FT_EXPORT ( OTL_Tag_List )
  OTL_FeaturesRequest_List_Scripts   ( OTL_FeaturesRequest request,
				       OTTableType         table_type )
  {
    FT_Error error;
    OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
    FT_Face face = FTL_FONT_FACE(font);
    FT_Memory memory = FT_FACE_MEMORY(face);
    OTL_Tag_List tag_list;
    if ( FT_NEW(tag_list) )
      return NULL;

    tag_list->request = request;
    tag_list->tags 	       = ot_info_list_scripts( font->info, table_type );
    return tag_list;
  }

  FT_EXPORT ( OTL_Tag_List ) 
  OTL_FeaturesRequest_List_Languages ( OTL_FeaturesRequest request,
				       OTTableType         table_type,
				       FT_UInt             script_index )
  {
    FT_Error error;
    OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
    FT_Face face = FTL_FONT_FACE( font );
    FT_Memory memory = FT_FACE_MEMORY( face );
    OTL_Tag_List tag_list;
    if ( FT_NEW(tag_list) )
      return NULL;

    tag_list->request = request;
    tag_list->tags 	       = ot_info_list_languages( font->info, 
							 table_type,
							 script_index,
							 0 );
    return tag_list;
  }

  FT_EXPORT ( OTL_Tag_List )
  OTL_FeaturesRequest_List_Features  ( OTL_FeaturesRequest request,
				       OTTableType         table_type,
				       FT_UInt             script_index,
				       FT_UInt             language_index )
  {
    FT_Error error;
    OTL_Font font = (OTL_Font)FTL_FEATURES_REQUEST_FONT( request );
    FT_Face face = FTL_FONT_FACE(font);
    FT_Memory memory = FT_FACE_MEMORY( face );
    OTL_Tag_List tag_list;
    if ( FT_NEW(tag_list) )
      return NULL;

    tag_list->request = request;
    tag_list->tags 	       = ot_info_list_features( font->info,
							table_type,
							0,
							script_index,
							language_index );
    return tag_list;
  }

  FT_EXPORT ( FT_Error )
  OTL_Tag_List_Done                  ( OTL_Tag_List taglist )
  {
    FTL_FeaturesRequest request = (FTL_FeaturesRequest)taglist->request;
    FTL_Font font = FTL_FEATURES_REQUEST_FONT( request );
    FT_Face face  = FTL_FONT_FACE(font);
    FT_Memory memory = FT_FACE_MEMORY( face );
    FT_FREE ( taglist );
    return FT_Err_Ok;
  }

  FT_EXPORT ( FT_Error )
  OTL_FeaturesRequest_Add_Feature  ( OTL_FeaturesRequest request,
				     OTTableType         table_type,
				     FT_UInt             feature_index,
				     FT_ULong            property_bit)
  {
    ot_ruleset_add_feature( request->ruleset,
			    table_type,
			    feature_index,
			    property_bit );
    return FT_Err_Ok;
  }

/* END */