~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/src/sfnt/sfdriver.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************/
 
2
/*                                                                         */
 
3
/*  sfdriver.c                                                             */
 
4
/*                                                                         */
 
5
/*    High-level SFNT driver interface (body).                             */
 
6
/*                                                                         */
 
7
/*  Copyright 1996-2001, 2002, 2003, 2004 by                               */
 
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 
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_INTERNAL_SFNT_H
 
21
#include FT_INTERNAL_OBJECTS_H
 
22
 
 
23
#include "sfdriver.h"
 
24
#include "ttload.h"
 
25
#include "sfobjs.h"
 
26
 
 
27
#include "sferrors.h"
 
28
 
 
29
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
 
30
#include "ttsbit.h"
 
31
#endif
 
32
 
 
33
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
 
34
#include "ttpost.h"
 
35
#endif
 
36
 
 
37
#include "ttcmap0.h"
 
38
 
 
39
#include FT_SERVICE_GLYPH_DICT_H
 
40
#include FT_SERVICE_POSTSCRIPT_NAME_H
 
41
#include FT_SERVICE_SFNT_H
 
42
#include FT_SERVICE_TT_CMAP_H
 
43
 
 
44
 
 
45
 /*
 
46
  *  SFNT TABLE SERVICE
 
47
  *
 
48
  */
 
49
 
 
50
  static void*
 
51
  get_sfnt_table( TT_Face      face,
 
52
                  FT_Sfnt_Tag  tag )
 
53
  {
 
54
    void*  table;
 
55
 
 
56
 
 
57
    switch ( tag )
 
58
    {
 
59
    case ft_sfnt_head:
 
60
      table = &face->header;
 
61
      break;
 
62
 
 
63
    case ft_sfnt_hhea:
 
64
      table = &face->horizontal;
 
65
      break;
 
66
 
 
67
    case ft_sfnt_vhea:
 
68
      table = face->vertical_info ? &face->vertical : 0;
 
69
      break;
 
70
 
 
71
    case ft_sfnt_os2:
 
72
      table = face->os2.version == 0xFFFFU ? 0 : &face->os2;
 
73
      break;
 
74
 
 
75
    case ft_sfnt_post:
 
76
      table = &face->postscript;
 
77
      break;
 
78
 
 
79
    case ft_sfnt_maxp:
 
80
      table = &face->max_profile;
 
81
      break;
 
82
 
 
83
    case ft_sfnt_pclt:
 
84
      table = face->pclt.Version ? &face->pclt : 0;
 
85
      break;
 
86
 
 
87
    default:
 
88
      table = 0;
 
89
    }
 
90
 
 
91
    return table;
 
92
  }
 
93
 
 
94
 
 
95
  static const FT_Service_SFNT_TableRec  sfnt_service_sfnt_table =
 
96
  {
 
97
    (FT_SFNT_TableLoadFunc)tt_face_load_any,
 
98
    (FT_SFNT_TableGetFunc) get_sfnt_table
 
99
  };
 
100
 
 
101
 
 
102
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
 
103
 
 
104
 /*
 
105
  *  GLYPH DICT SERVICE
 
106
  *
 
107
  */
 
108
 
 
109
  static FT_Error
 
110
  sfnt_get_glyph_name( TT_Face     face,
 
111
                       FT_UInt     glyph_index,
 
112
                       FT_Pointer  buffer,
 
113
                       FT_UInt     buffer_max )
 
114
  {
 
115
    FT_String*  gname;
 
116
    FT_Error    error;
 
117
 
 
118
 
 
119
    error = tt_face_get_ps_name( face, glyph_index, &gname );
 
120
    if ( !error && buffer_max > 0 )
 
121
    {
 
122
      FT_UInt  len = (FT_UInt)( ft_strlen( gname ) );
 
123
 
 
124
 
 
125
      if ( len >= buffer_max )
 
126
        len = buffer_max - 1;
 
127
 
 
128
      FT_MEM_COPY( buffer, gname, len );
 
129
      ((FT_Byte*)buffer)[len] = 0;
 
130
    }
 
131
 
 
132
    return error;
 
133
  }
 
134
 
 
135
 
 
136
  static const FT_Service_GlyphDictRec  sfnt_service_glyph_dict =
 
137
  {
 
138
    (FT_GlyphDict_GetNameFunc)  sfnt_get_glyph_name,
 
139
    (FT_GlyphDict_NameIndexFunc)NULL
 
140
  };
 
141
 
 
142
#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
 
143
 
 
144
 
 
145
 /*
 
146
  *  POSTSCRIPT NAME SERVICE
 
147
  *
 
148
  */
 
149
 
 
150
  static const char*
 
151
  sfnt_get_ps_name( TT_Face  face )
 
152
  {
 
153
    FT_Int       n, found_win, found_apple;
 
154
    const char*  result = NULL;
 
155
 
 
156
 
 
157
    /* shouldn't happen, but just in case to avoid memory leaks */
 
158
    if ( face->postscript_name )
 
159
      return face->postscript_name;
 
160
 
 
161
    /* scan the name table to see whether we have a Postscript name here, */
 
162
    /* either in Macintosh or Windows platform encodings                  */
 
163
    found_win   = -1;
 
164
    found_apple = -1;
 
165
 
 
166
    for ( n = 0; n < face->num_names; n++ )
 
167
    {
 
168
      TT_NameEntryRec*  name = face->name_table.names + n;
 
169
 
 
170
 
 
171
      if ( name->nameID == 6 && name->stringLength > 0 )
 
172
      {
 
173
        if ( name->platformID == 3     &&
 
174
             name->encodingID == 1     &&
 
175
             name->languageID == 0x409 )
 
176
          found_win = n;
 
177
 
 
178
        if ( name->platformID == 1 &&
 
179
             name->encodingID == 0 &&
 
180
             name->languageID == 0 )
 
181
          found_apple = n;
 
182
      }
 
183
    }
 
184
 
 
185
    if ( found_win != -1 )
 
186
    {
 
187
      FT_Memory         memory = face->root.memory;
 
188
      TT_NameEntryRec*  name   = face->name_table.names + found_win;
 
189
      FT_UInt           len    = name->stringLength / 2;
 
190
      FT_Error          error  = SFNT_Err_Ok;
 
191
 
 
192
      FT_UNUSED( error );
 
193
 
 
194
 
 
195
      if ( !FT_ALLOC( result, name->stringLength + 1 ) )
 
196
      {
 
197
        FT_Stream   stream = face->name_table.stream;
 
198
        FT_String*  r      = (FT_String*)result;
 
199
        FT_Byte*    p      = (FT_Byte*)name->string;
 
200
 
 
201
 
 
202
        if ( FT_STREAM_SEEK( name->stringOffset ) ||
 
203
             FT_FRAME_ENTER( name->stringLength ) )
 
204
        {
 
205
          FT_FREE( result );
 
206
          name->stringLength = 0;
 
207
          name->stringOffset = 0;
 
208
          FT_FREE( name->string );
 
209
 
 
210
          goto Exit;
 
211
        }
 
212
 
 
213
        p = (FT_Byte*)stream->cursor;
 
214
 
 
215
        for ( ; len > 0; len--, p += 2 )
 
216
        {
 
217
          if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 )
 
218
            *r++ = p[1];
 
219
        }
 
220
        *r = '\0';
 
221
 
 
222
        FT_FRAME_EXIT();
 
223
      }
 
224
      goto Exit;
 
225
    }
 
226
 
 
227
    if ( found_apple != -1 )
 
228
    {
 
229
      FT_Memory         memory = face->root.memory;
 
230
      TT_NameEntryRec*  name   = face->name_table.names + found_apple;
 
231
      FT_UInt           len    = name->stringLength;
 
232
      FT_Error          error  = SFNT_Err_Ok;
 
233
 
 
234
      FT_UNUSED( error );
 
235
 
 
236
 
 
237
      if ( !FT_ALLOC( result, len + 1 ) )
 
238
      {
 
239
        FT_Stream  stream = face->name_table.stream;
 
240
 
 
241
 
 
242
        if ( FT_STREAM_SEEK( name->stringOffset ) ||
 
243
             FT_STREAM_READ( result, len )        )
 
244
        {
 
245
          name->stringOffset = 0;
 
246
          name->stringLength = 0;
 
247
          FT_FREE( name->string );
 
248
          FT_FREE( result );
 
249
          goto Exit;
 
250
        }
 
251
        ((char*)result)[len] = '\0';
 
252
      }
 
253
    }
 
254
 
 
255
  Exit:
 
256
    face->postscript_name = result;
 
257
    return result;
 
258
  }
 
259
 
 
260
  static const FT_Service_PsFontNameRec  sfnt_service_ps_name =
 
261
  {
 
262
    (FT_PsName_GetFunc)sfnt_get_ps_name
 
263
  };
 
264
 
 
265
 
 
266
 /*
 
267
  *  TT CMAP INFO
 
268
  *
 
269
  */
 
270
  static const FT_Service_TTCMapsRec  tt_service_get_cmap_info =
 
271
  {
 
272
    (TT_CMap_Info_GetFunc)tt_get_cmap_info
 
273
  };
 
274
 
 
275
 
 
276
 /*
 
277
  *  SERVICE LIST
 
278
  *
 
279
  */
 
280
 
 
281
  static const FT_ServiceDescRec  sfnt_services[] =
 
282
  {
 
283
    { FT_SERVICE_ID_SFNT_TABLE,           &sfnt_service_sfnt_table },
 
284
    { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name },
 
285
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
 
286
    { FT_SERVICE_ID_GLYPH_DICT,           &sfnt_service_glyph_dict },
 
287
#endif
 
288
    { FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info },
 
289
 
 
290
    { NULL, NULL }
 
291
  };
 
292
 
 
293
 
 
294
  FT_CALLBACK_DEF( FT_Module_Interface )
 
295
  sfnt_get_interface( FT_Module    module,
 
296
                      const char*  module_interface )
 
297
  {
 
298
    FT_UNUSED( module );
 
299
 
 
300
    if ( ft_strcmp( module_interface, "get_sfnt" ) == 0 )
 
301
      return (FT_Module_Interface)get_sfnt_table;
 
302
 
 
303
    if ( ft_strcmp( module_interface, "load_sfnt" ) == 0 )
 
304
      return (FT_Module_Interface)tt_face_load_any;
 
305
 
 
306
    return ft_service_list_lookup( sfnt_services, module_interface );
 
307
  }
 
308
 
 
309
 
 
310
  static
 
311
  const SFNT_Interface  sfnt_interface =
 
312
  {
 
313
    tt_face_goto_table,
 
314
 
 
315
    sfnt_init_face,
 
316
    sfnt_load_face,
 
317
    sfnt_done_face,
 
318
    sfnt_get_interface,
 
319
 
 
320
    tt_face_load_any,
 
321
    tt_face_load_sfnt_header,
 
322
    tt_face_load_directory,
 
323
 
 
324
    tt_face_load_header,
 
325
    tt_face_load_metrics_header,
 
326
    tt_face_load_cmap,
 
327
    tt_face_load_max_profile,
 
328
    tt_face_load_os2,
 
329
    tt_face_load_postscript,
 
330
 
 
331
    tt_face_load_names,
 
332
    tt_face_free_names,
 
333
 
 
334
    tt_face_load_hdmx,
 
335
    tt_face_free_hdmx,
 
336
 
 
337
    tt_face_load_kern,
 
338
    tt_face_load_gasp,
 
339
    tt_face_load_pclt,
 
340
 
 
341
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
 
342
 
 
343
    /* see `ttload.h' */
 
344
    tt_face_load_bitmap_header,
 
345
 
 
346
    /* see `ttsbit.h' and `sfnt.h' */
 
347
    tt_face_set_sbit_strike,
 
348
    tt_face_load_sbit_strikes,
 
349
    tt_find_sbit_image,
 
350
    tt_load_sbit_metrics,
 
351
    tt_face_load_sbit_image,
 
352
    tt_face_free_sbit_strikes,
 
353
 
 
354
#else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
 
355
 
 
356
    0,
 
357
    0,
 
358
    0,
 
359
    0, 
 
360
    0, 
 
361
    0,
 
362
    0,
 
363
 
 
364
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
 
365
 
 
366
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
 
367
 
 
368
    /* see `ttpost.h' */
 
369
    tt_face_get_ps_name,
 
370
    tt_face_free_ps_names,
 
371
 
 
372
#else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
 
373
 
 
374
    0,
 
375
    0,
 
376
 
 
377
#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
 
378
 
 
379
  };
 
380
 
 
381
 
 
382
  FT_CALLBACK_TABLE_DEF
 
383
  const FT_Module_Class  sfnt_module_class =
 
384
  {
 
385
    0,  /* not a font driver or renderer */
 
386
    sizeof( FT_ModuleRec ),
 
387
 
 
388
    "sfnt",     /* driver name                            */
 
389
    0x10000L,   /* driver version 1.0                     */
 
390
    0x20000L,   /* driver requires FreeType 2.0 or higher */
 
391
 
 
392
    (const void*)&sfnt_interface,  /* module specific interface */
 
393
 
 
394
    (FT_Module_Constructor)0,
 
395
    (FT_Module_Destructor) 0,
 
396
    (FT_Module_Requester)  sfnt_get_interface
 
397
  };
 
398
 
 
399
 
 
400
/* END */