misc/libfreetype/src/base/ftobjs.c
author unc0rr
Wed, 31 Oct 2012 14:50:45 +0400
branch0.9.18
changeset 7900 e5e7678e4b2f
parent 5172 88f2e05288ba
permissions -rw-r--r--
Fix white background in players list on halloween, christmas and easter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftobjs.c                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    The FreeType private base classes (body).                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2011 by                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_LIST_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_VALIDATE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_INTERNAL_RFORK_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include FT_INTERNAL_SFNT_H    /* for SFNT_Load_Table_Func */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include FT_TRUETYPE_TABLES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include FT_TRUETYPE_IDS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#include FT_SERVICE_SFNT_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#include FT_SERVICE_POSTSCRIPT_NAME_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#include FT_SERVICE_GLYPH_DICT_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#include FT_SERVICE_TT_CMAP_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#include FT_SERVICE_KERNING_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#include FT_SERVICE_TRUETYPE_ENGINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#ifdef FT_CONFIG_OPTION_MAC_FONTS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#include "ftbase.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
#define GRID_FIT_METRICS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  ft_service_list_lookup( FT_ServiceDesc  service_descriptors,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
                          const char*     service_id )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    FT_Pointer      result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_ServiceDesc  desc   = service_descriptors;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    if ( desc && service_id )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
      for ( ; desc->serv_id != NULL; desc++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
        if ( ft_strcmp( desc->serv_id, service_id ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
          result = (FT_Pointer)desc->serv_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  ft_validator_init( FT_Validator        valid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
                     const FT_Byte*      base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
                     const FT_Byte*      limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
                     FT_ValidationLevel  level )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    valid->base  = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    valid->limit = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    valid->level = level;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    valid->error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  FT_BASE_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  ft_validator_run( FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    /* This function doesn't work!  None should call it. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    FT_UNUSED( valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  ft_validator_error( FT_Validator  valid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
                      FT_Error      error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    /* since the cast below also disables the compiler's */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    /* type check, we introduce a dummy variable, which  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    /* will be optimized away                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    volatile ft_jmp_buf* jump_buffer = &valid->jump_buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    valid->error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    /* throw away volatileness; use `jump_buffer' or the  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    /* compiler may warn about an unused local variable   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    ft_longjmp( *(ft_jmp_buf*) jump_buffer, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  /****                           S T R E A M                           ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  /* create a new input stream from an FT_Open_Args structure */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
  /*                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  FT_Stream_New( FT_Library           library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
                 const FT_Open_Args*  args,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
                 FT_Stream           *astream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    FT_Stream  stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    *astream = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    if ( !args )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    if ( FT_NEW( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    stream->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    if ( args->flags & FT_OPEN_MEMORY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
      /* create a memory-based stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      FT_Stream_OpenMemory( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
                            (const FT_Byte*)args->memory_base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
                            args->memory_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    else if ( args->flags & FT_OPEN_PATHNAME )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
      /* create a normal system stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      error = FT_Stream_Open( stream, args->pathname );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      stream->pathname.pointer = args->pathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      /* use an existing, user-provided stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      /* in this case, we do not need to allocate a new stream object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      /* since the caller is responsible for closing it himself       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      FT_FREE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      stream = args->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      FT_FREE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      stream->memory = memory;  /* just to be certain */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    *astream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
  FT_Stream_Free( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
                  FT_Int     external )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    if ( stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      FT_Stream_Close( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      if ( !external )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
        FT_FREE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
#define FT_COMPONENT  trace_objs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  /****               FACE, SIZE & GLYPH SLOT OBJECTS                   ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  ft_glyphslot_init( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    FT_Driver         driver   = slot->face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    FT_Driver_Class   clazz    = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    FT_Memory         memory   = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    FT_Error          error    = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    FT_Slot_Internal  internal = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    slot->library = driver->root.library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    if ( FT_NEW( internal ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
    slot->internal = internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    if ( FT_DRIVER_USES_OUTLINES( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
      error = FT_GlyphLoader_New( memory, &internal->loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    if ( !error && clazz->init_slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
      error = clazz->init_slot( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  ft_glyphslot_free_bitmap( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      FT_Memory  memory = FT_FACE_MEMORY( slot->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      FT_FREE( slot->bitmap.buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      /* assume that the bitmap buffer was stolen or not */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      /* allocated from the heap                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      slot->bitmap.buffer = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
  ft_glyphslot_set_bitmap( FT_GlyphSlot  slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
                           FT_Byte*      buffer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
    ft_glyphslot_free_bitmap( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    slot->bitmap.buffer = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    FT_ASSERT( (slot->internal->flags & FT_GLYPH_OWN_BITMAP) == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
  ft_glyphslot_alloc_bitmap( FT_GlyphSlot  slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
                             FT_ULong      size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    FT_Memory  memory = FT_FACE_MEMORY( slot->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
      FT_FREE( slot->bitmap.buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    (void)FT_ALLOC( slot->bitmap.buffer, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
  ft_glyphslot_clear( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
    /* free bitmap if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    ft_glyphslot_free_bitmap( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    /* clear all public fields in the glyph slot */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    FT_ZERO( &slot->metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    FT_ZERO( &slot->outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    slot->bitmap.width      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    slot->bitmap.rows       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    slot->bitmap.pitch      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    slot->bitmap.pixel_mode = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    /* `slot->bitmap.buffer' has been handled by ft_glyphslot_free_bitmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    slot->bitmap_left   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    slot->bitmap_top    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    slot->num_subglyphs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    slot->subglyphs     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    slot->control_data  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    slot->control_len   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    slot->other         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
    slot->format        = FT_GLYPH_FORMAT_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    slot->linearHoriAdvance = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    slot->linearVertAdvance = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    slot->lsb_delta         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    slot->rsb_delta         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  ft_glyphslot_done( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    FT_Driver        driver = slot->face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    FT_Driver_Class  clazz  = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    FT_Memory        memory = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    if ( clazz->done_slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      clazz->done_slot( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    /* free bitmap buffer if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    ft_glyphslot_free_bitmap( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    /* slot->internal might be NULL in out-of-memory situations */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    if ( slot->internal )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      /* free glyph loader */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
      if ( FT_DRIVER_USES_OUTLINES( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
        FT_GlyphLoader_Done( slot->internal->loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
        slot->internal->loader = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
      FT_FREE( slot->internal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
  FT_New_GlyphSlot( FT_Face        face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
                    FT_GlyphSlot  *aslot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    FT_Driver        driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
    FT_Driver_Class  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
    FT_Memory        memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    FT_GlyphSlot     slot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    if ( !face || !face->driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    driver = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    clazz  = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    memory = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    FT_TRACE4(( "FT_New_GlyphSlot: Creating new slot object\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    if ( !FT_ALLOC( slot, clazz->slot_object_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      slot->face = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
      error = ft_glyphslot_init( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
        ft_glyphslot_done( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
        FT_FREE( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
      slot->next  = face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      face->glyph = slot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      if ( aslot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
        *aslot = slot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    else if ( aslot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
      *aslot = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
    FT_TRACE4(( "FT_New_GlyphSlot: Return %d\n", error ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
  FT_Done_GlyphSlot( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
    if ( slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
      FT_Driver     driver = slot->face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      FT_Memory     memory = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      FT_GlyphSlot  prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      FT_GlyphSlot  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      /* Remove slot from its parent face's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      prev = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      cur  = slot->face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      while ( cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        if ( cur == slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
          if ( !prev )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
            slot->face->glyph = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
            prev->next = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
          ft_glyphslot_done( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
          FT_FREE( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
        prev = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
        cur  = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
  FT_Set_Transform( FT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
                    FT_Matrix*  matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
                    FT_Vector*  delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    FT_Face_Internal  internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    internal = face->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    internal->transform_flags = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    if ( !matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      internal->transform_matrix.xx = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
      internal->transform_matrix.xy = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
      internal->transform_matrix.yx = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      internal->transform_matrix.yy = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      matrix = &internal->transform_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
      internal->transform_matrix = *matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    /* set transform_flags bit flag 0 if `matrix' isn't the identity */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    if ( ( matrix->xy | matrix->yx ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
         matrix->xx != 0x10000L      ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
         matrix->yy != 0x10000L      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
      internal->transform_flags |= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    if ( !delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
      internal->transform_delta.x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      internal->transform_delta.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      delta = &internal->transform_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
      internal->transform_delta = *delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    /* set transform_flags bit flag 1 if `delta' isn't the null vector */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    if ( delta->x | delta->y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
      internal->transform_flags |= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
  static FT_Renderer
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
  ft_lookup_glyph_renderer( FT_GlyphSlot  slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
#ifdef GRID_FIT_METRICS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  ft_glyphslot_grid_fit_metrics( FT_GlyphSlot  slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
                                 FT_Bool       vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    FT_Glyph_Metrics*  metrics = &slot->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    FT_Pos             right, bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    if ( vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
      metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
      metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      right  = FT_PIX_CEIL( metrics->vertBearingX + metrics->width );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
      bottom = FT_PIX_CEIL( metrics->vertBearingY + metrics->height );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
      metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      metrics->width  = right - metrics->vertBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      metrics->height = bottom - metrics->vertBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
      metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
      right  = FT_PIX_CEIL ( metrics->horiBearingX + metrics->width );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
      bottom = FT_PIX_FLOOR( metrics->horiBearingY - metrics->height );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
      metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
      metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
      metrics->width  = right - metrics->horiBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
      metrics->height = metrics->horiBearingY - bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    metrics->horiAdvance = FT_PIX_ROUND( metrics->horiAdvance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    metrics->vertAdvance = FT_PIX_ROUND( metrics->vertAdvance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
#endif /* GRID_FIT_METRICS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
  FT_Load_Glyph( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
                 FT_UInt   glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
                 FT_Int32  load_flags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    FT_Driver     driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    FT_GlyphSlot  slot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    FT_Library    library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    FT_Bool       autohint = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    FT_Module     hinter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
    TT_Face       ttface = (TT_Face)face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
    if ( !face || !face->size || !face->glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    /* The validity test for `glyph_index' is performed by the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    /* font drivers.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    slot = face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
    ft_glyphslot_clear( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
    driver  = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    library = driver->root.library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    hinter  = library->auto_hinter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    /* resolve load flags dependencies */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
    if ( load_flags & FT_LOAD_NO_RECURSE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
      load_flags |= FT_LOAD_NO_SCALE         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
                    FT_LOAD_IGNORE_TRANSFORM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    if ( load_flags & FT_LOAD_NO_SCALE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
      load_flags |= FT_LOAD_NO_HINTING |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
                    FT_LOAD_NO_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
      load_flags &= ~FT_LOAD_RENDER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
     * Determine whether we need to auto-hint or not.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
     * The general rules are:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
     * - Do only auto-hinting if we have a hinter module, a scalable font
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
     *   format dealing with outlines, and no transforms except simple
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
     *   slants and/or rotations by integer multiples of 90 degrees.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
     * - Then, auto-hint if FT_LOAD_FORCE_AUTOHINT is set or if we don't
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
     *   have a native font hinter.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
     * - Otherwise, auto-hint for LIGHT hinting mode or if there isn't
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
     *   any hinting bytecode in the TrueType/OpenType font.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
     * - Exception: The font is `tricky' and requires the native hinter to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
     *   load properly.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
    if ( hinter                                           &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
         !( load_flags & FT_LOAD_NO_HINTING )             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
         !( load_flags & FT_LOAD_NO_AUTOHINT )            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
         FT_DRIVER_IS_SCALABLE( driver )                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
         FT_DRIVER_USES_OUTLINES( driver )                &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
         !FT_IS_TRICKY( face )                            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
         ( ( face->internal->transform_matrix.yx == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
             face->internal->transform_matrix.xx != 0 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
           ( face->internal->transform_matrix.xx == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
             face->internal->transform_matrix.yx != 0 ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
      if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
           !FT_DRIVER_HAS_HINTER( driver )         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        autohint = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
        FT_Render_Mode  mode = FT_LOAD_TARGET_MODE( load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
        /* the check for `num_locations' assures that we actually    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
        /* test for instructions in a TTF and not in a CFF-based OTF */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
        if ( mode == FT_RENDER_MODE_LIGHT                       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
             face->internal->ignore_unpatented_hinter           ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
             ( FT_IS_SFNT( face )                             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
               ttface->num_locations                          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
               ttface->max_profile.maxSizeOfInstructions == 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
          autohint = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    if ( autohint )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
      FT_AutoHinter_Service  hinting;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
      /* try to load embedded bitmaps first if available            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
      /*                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      /* XXX: This is really a temporary hack that should disappear */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      /*      promptly with FreeType 2.1!                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      /*                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
      if ( FT_HAS_FIXED_SIZES( face )             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
          ( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
        error = driver->clazz->load_glyph( slot, face->size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
                                           glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
                                           load_flags | FT_LOAD_SBITS_ONLY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
        if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
          goto Load_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
        FT_Face_Internal  internal        = face->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
        FT_Int            transform_flags = internal->transform_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
        /* since the auto-hinter calls FT_Load_Glyph by itself, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
        /* make sure that glyphs aren't transformed             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
        internal->transform_flags = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
        /* load auto-hinted outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
        hinting = (FT_AutoHinter_Service)hinter->clazz->module_interface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
        error   = hinting->load_glyph( (FT_AutoHinter)hinter,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
                                       slot, face->size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
                                       glyph_index, load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
        internal->transform_flags = transform_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
      error = driver->clazz->load_glyph( slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
                                         face->size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
                                         glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
                                         load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
      if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
        /* check that the loaded outline is correct */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
        error = FT_Outline_Check( &slot->outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
#ifdef GRID_FIT_METRICS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
        if ( !( load_flags & FT_LOAD_NO_HINTING ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
          ft_glyphslot_grid_fit_metrics( slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
              FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
  Load_Ok:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    /* compute the advance */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
      slot->advance.x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
      slot->advance.y = slot->metrics.vertAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
      slot->advance.x = slot->metrics.horiAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
      slot->advance.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
    /* compute the linear advance in 16.16 pixels */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
         ( FT_IS_SCALABLE( face ) )                  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
      FT_Size_Metrics*  metrics = &face->size->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
      /* it's tricky! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
      slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
                                           metrics->x_scale, 64 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
      slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
                                           metrics->y_scale, 64 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
      FT_Face_Internal  internal = face->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      /* now, transform the glyph image if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
      if ( internal->transform_flags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
        /* get renderer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
        FT_Renderer  renderer = ft_lookup_glyph_renderer( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
        if ( renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
          error = renderer->clazz->transform_glyph(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
                                     renderer, slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
                                     &internal->transform_matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
                                     &internal->transform_delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
        else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
          /* apply `standard' transformation if no renderer is available */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
          if ( &internal->transform_matrix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
            FT_Outline_Transform( &slot->outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
                                  &internal->transform_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
          if ( &internal->transform_delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
            FT_Outline_Translate( &slot->outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
                                  internal->transform_delta.x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
                                  internal->transform_delta.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
        /* transform advance */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
        FT_Vector_Transform( &slot->advance, &internal->transform_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    FT_TRACE5(( "  x advance: %d\n" , slot->advance.x ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
    FT_TRACE5(( "  y advance: %d\n" , slot->advance.y ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
    FT_TRACE5(( "  linear x advance: %d\n" , slot->linearHoriAdvance ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
    FT_TRACE5(( "  linear y advance: %d\n" , slot->linearVertAdvance ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
    /* do we need to render the image now? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
    if ( !error                                    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
         slot->format != FT_GLYPH_FORMAT_BITMAP    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
         slot->format != FT_GLYPH_FORMAT_COMPOSITE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
         load_flags & FT_LOAD_RENDER )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
      FT_Render_Mode  mode = FT_LOAD_TARGET_MODE( load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
      if ( mode == FT_RENDER_MODE_NORMAL      &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
           (load_flags & FT_LOAD_MONOCHROME ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
        mode = FT_RENDER_MODE_MONO;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
      error = FT_Render_Glyph( slot, mode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
  FT_Load_Char( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
                FT_ULong  char_code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
                FT_Int32  load_flags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    FT_UInt  glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    glyph_index = (FT_UInt)char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
    if ( face->charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
      glyph_index = FT_Get_Char_Index( face, char_code );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    return FT_Load_Glyph( face, glyph_index, load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
  /* destructor for sizes list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
  destroy_size( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
                FT_Size    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
                FT_Driver  driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
    /* finalize client-specific data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
    if ( size->generic.finalizer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
      size->generic.finalizer( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    /* finalize format-specific stuff */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
    if ( driver->clazz->done_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
      driver->clazz->done_size( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
    FT_FREE( size->internal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
    FT_FREE( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
  ft_cmap_done_internal( FT_CMap  cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
  destroy_charmaps( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
                    FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
    FT_Int  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    for ( n = 0; n < face->num_charmaps; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
      FT_CMap  cmap = FT_CMAP( face->charmaps[n] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
      ft_cmap_done_internal( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
      face->charmaps[n] = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    FT_FREE( face->charmaps );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    face->num_charmaps = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
  /* destructor for faces list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
  destroy_face( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
                FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
                FT_Driver  driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
    FT_Driver_Class  clazz = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
    /* discard auto-hinting data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
    if ( face->autohint.finalizer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
      face->autohint.finalizer( face->autohint.data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
    /* Discard glyph slots for this face.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    /* Beware!  FT_Done_GlyphSlot() changes the field `face->glyph' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
    while ( face->glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
      FT_Done_GlyphSlot( face->glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
    /* discard all sizes for this face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
    FT_List_Finalize( &face->sizes_list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
                      (FT_List_Destructor)destroy_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
                      memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
                      driver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
    face->size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    /* now discard client data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
    if ( face->generic.finalizer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      face->generic.finalizer( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
    /* discard charmaps */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
    destroy_charmaps( face, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
    /* finalize format-specific stuff */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
    if ( clazz->done_face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
      clazz->done_face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
    /* close the stream for this face if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
    FT_Stream_Free(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
      face->stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
      ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
    face->stream = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
    /* get rid of it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
    if ( face->internal )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
      FT_FREE( face->internal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
    FT_FREE( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
  Destroy_Driver( FT_Driver  driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    FT_List_Finalize( &driver->faces_list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
                      (FT_List_Destructor)destroy_face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
                      driver->root.memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
                      driver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
    /* check whether we need to drop the driver's glyph loader */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
    if ( FT_DRIVER_USES_OUTLINES( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
      FT_GlyphLoader_Done( driver->glyph_loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
  /*    find_unicode_charmap                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
  /*    This function finds a Unicode charmap, if there is one.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
  /*    And if there is more than one, it tries to favour the more         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
  /*    extensive one, i.e., one that supports UCS-4 against those which   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
  /*    are limited to the BMP (said UCS-2 encoding.)                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
  /*    This function is called from open_face() (just below), and also    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
  /*    from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ).                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
  find_unicode_charmap( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
    FT_CharMap*  first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
    FT_CharMap*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
    /* caller should have already checked that `face' is valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    FT_ASSERT( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
    first = face->charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    if ( !first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
      return FT_Err_Invalid_CharMap_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
     *  The original TrueType specification(s) only specified charmap
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
     *  formats that are capable of mapping 8 or 16 bit character codes to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
     *  glyph indices.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
     *  However, recent updates to the Apple and OpenType specifications
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
     *  introduced new formats that are capable of mapping 32-bit character
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
     *  codes as well.  And these are already used on some fonts, mainly to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
     *  map non-BMP Asian ideographs as defined in Unicode.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
     *  For compatibility purposes, these fonts generally come with
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
     *  *several* Unicode charmaps:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
     *   - One of them in the "old" 16-bit format, that cannot access
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
     *     all glyphs in the font.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
     *   - Another one in the "new" 32-bit format, that can access all
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
     *     the glyphs.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
     *  This function has been written to always favor a 32-bit charmap
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
     *  when found.  Otherwise, a 16-bit one is returned when found.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
    /* Since the `interesting' table, with IDs (3,10), is normally the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
    /* last one, we loop backwards.  This loses with type1 fonts with  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
    /* non-BMP characters (<.0001%), this wins with .ttf with non-BMP  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
    /* chars (.01% ?), and this is the same about 99.99% of the time!  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
    cur = first + face->num_charmaps;  /* points after the last one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    for ( ; --cur >= first; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
      if ( cur[0]->encoding == FT_ENCODING_UNICODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
        /* XXX If some new encodings to represent UCS-4 are added, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
        /*     they should be added here.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
        if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
               cur[0]->encoding_id == TT_MS_ID_UCS_4        )     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
             ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
               cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32    ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
          if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
            FT_ERROR(( "find_unicode_charmap: UCS-4 cmap is found "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
                       "at too late position (%d)\n", cur - first ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
          face->charmap = cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
          return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
    /* We do not have any UCS-4 charmap.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    /* Do the loop again and search for UCS-2 charmaps. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
    cur = first + face->num_charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    for ( ; --cur >= first; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
      if ( cur[0]->encoding == FT_ENCODING_UNICODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
        if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
          FT_ERROR(( "find_unicode_charmap: UCS-2 cmap is found "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
                     "at too late position (%d)\n", cur - first ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
        face->charmap = cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
        return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
    return FT_Err_Invalid_CharMap_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
  /*    find_variant_selector_charmap                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
  /*    This function finds the variant selector charmap, if there is one. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
  /*    There can only be one (platform=0, specific=5, format=14).         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
  static FT_CharMap
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
  find_variant_selector_charmap( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
    FT_CharMap*  first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
    FT_CharMap*  end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
    FT_CharMap*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
    /* caller should have already checked that `face' is valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
    FT_ASSERT( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
    first = face->charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
    if ( !first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
    end = first + face->num_charmaps;  /* points after the last one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
    for ( cur = first; cur < end; ++cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
      if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
           cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
           FT_Get_CMap_Format( cur[0] ) == 14                  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
        if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
          FT_ERROR(( "find_unicode_charmap: UVS cmap is found "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
                     "at too late position (%d)\n", cur - first ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
        return cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
    return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
  /*    open_face                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
  /*    This function does some work for FT_Open_Face().                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
  open_face( FT_Driver      driver,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
             FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
             FT_Long        face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
             FT_Int         num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
             FT_Parameter*  params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
             FT_Face       *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
    FT_Memory         memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
    FT_Driver_Class   clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
    FT_Face           face = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
    FT_Error          error, error2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
    FT_Face_Internal  internal = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
    clazz  = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
    memory = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    /* allocate the face object and perform basic initialization */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
    if ( FT_ALLOC( face, clazz->face_object_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
    if ( FT_NEW( internal ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
    face->internal = internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
    face->driver   = driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
    face->memory   = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
    face->stream   = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
#ifdef FT_CONFIG_OPTION_INCREMENTAL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
      int  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
      face->internal->incremental_interface = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
      for ( i = 0; i < num_params && !face->internal->incremental_interface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
            i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
        if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
          face->internal->incremental_interface =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
            (FT_Incremental_Interface)params[i].data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
    if ( clazz->init_face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
      error = clazz->init_face( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
                                face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
                                (FT_Int)face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
                                num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
                                params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
    /* select Unicode charmap by default */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
    error2 = find_unicode_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
    /* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
    /* is returned.                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
    /* no error should happen, but we want to play safe */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
    if ( error2 && error2 != FT_Err_Invalid_CharMap_Handle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
      error = error2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
    *aface = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
      destroy_charmaps( face, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
      if ( clazz->done_face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
        clazz->done_face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
      FT_FREE( internal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
      FT_FREE( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
      *aface = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
  /* there's a Mac-specific extended implementation of FT_New_Face() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
  /* in src/base/ftmac.c                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
  FT_New_Face( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
               const char*  pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
               FT_Long      face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
               FT_Face     *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
    FT_Open_Args  args;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
    if ( !pathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
    args.flags    = FT_OPEN_PATHNAME;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
    args.pathname = (char*)pathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
    args.stream   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
    return FT_Open_Face( library, &args, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
#endif  /* defined( FT_MACINTOSH ) && !defined( DARWIN_NO_CARBON ) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
  FT_New_Memory_Face( FT_Library      library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
                      const FT_Byte*  file_base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
                      FT_Long         file_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
                      FT_Long         face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
                      FT_Face        *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
    FT_Open_Args  args;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
    /* test for valid `library' and `face' delayed to FT_Open_Face() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
    if ( !file_base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
    args.flags       = FT_OPEN_MEMORY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
    args.memory_base = file_base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
    args.memory_size = file_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
    args.stream      = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
    return FT_Open_Face( library, &args, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
#ifdef FT_CONFIG_OPTION_MAC_FONTS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
  /* The behavior here is very similar to that in base/ftmac.c, but it     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
  /* is designed to work on non-mac systems, so no mac specific calls.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
  /* We look at the file and determine if it is a mac dfont file or a mac  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
  /* resource file, or a macbinary file containing a mac resource file.    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
  /* Unlike ftmac I'm not going to look at a `FOND'.  I don't really see   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
  /* the point, especially since there may be multiple `FOND' resources.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
  /* Instead I'll just look for `sfnt' and `POST' resources, ordered as    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
  /* they occur in the file.                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
  /* Note that multiple `POST' resources do not mean multiple postscript   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
  /* fonts; they all get jammed together to make what is essentially a     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
  /* pfb file.                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
  /* We aren't interested in `NFNT' or `FONT' bitmap resources.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
  /* As soon as we get an `sfnt' load it into memory and pass it off to    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
  /* FT_Open_Face.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
  /* If we have a (set of) `POST' resources, massage them into a (memory)  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
  /* pfb file and pass that to FT_Open_Face.  (As with ftmac.c I'm not     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
  /* going to try to save the kerning info.  After all that lives in the   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
  /* `FOND' which isn't in the file containing the `POST' resources so     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
  /* we don't really have access to it.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
  /* Finalizer for a memory stream; gets called by FT_Done_Face(). */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
  /* It frees the memory it uses.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
  /* From ftmac.c.                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
  memory_stream_close( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
    FT_FREE( stream->base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
    stream->size  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
    stream->base  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
    stream->close = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
  /* Create a new memory stream from a buffer and a size. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
  /* From ftmac.c.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
  new_memory_stream( FT_Library           library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
                     FT_Byte*             base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
                     FT_ULong             size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
                     FT_Stream_CloseFunc  close,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
                     FT_Stream           *astream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
    FT_Stream  stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
    if ( !base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
    *astream = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
    if ( FT_NEW( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
    FT_Stream_OpenMemory( stream, base, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
    stream->close = close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
    *astream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
  /* Create a new FT_Face given a buffer and a driver name. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
  /* from ftmac.c */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
  open_face_from_buffer( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
                         FT_Byte*     base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
                         FT_ULong     size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
                         FT_Long      face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
                         const char*  driver_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
                         FT_Face     *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
    FT_Open_Args  args;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
    FT_Stream     stream = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
    FT_Memory     memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
    error = new_memory_stream( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
                               base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
                               size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
                               memory_stream_close,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
                               &stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
      FT_FREE( base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
    args.flags = FT_OPEN_STREAM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
    args.stream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
    if ( driver_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
      args.flags = args.flags | FT_OPEN_DRIVER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
      args.driver = FT_Get_Module( library, driver_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
#ifdef FT_MACINTOSH
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
    /* At this point, face_index has served its purpose;      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
    /* whoever calls this function has already used it to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
    /* locate the correct font data.  We should not propagate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
    /* this index to FT_Open_Face() (unless it is negative).  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
    if ( face_index > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
      face_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
    error = FT_Open_Face( library, &args, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
    if ( error == FT_Err_Ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
      (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
#ifdef FT_MACINTOSH
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
      FT_Stream_Free( stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
      FT_Stream_Close( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
      FT_FREE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
  /* Look up `TYP1' or `CID ' table from sfnt table directory.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
  /* `offset' and `length' must exclude the binary header in tables. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
  /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
  /* format too.  Here, since we can't expect that the TrueType font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
  /* driver is loaded unconditially, we must parse the font by       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
  /* ourselves.  We are only interested in the name of the table and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
  /* the offset.                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
  ft_lookup_PS_in_sfnt_stream( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
                               FT_Long    face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
                               FT_ULong*  offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
                               FT_ULong*  length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
                               FT_Bool*   is_sfnt_cid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
    FT_UShort  numTables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
    FT_Long    pstable_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
    FT_ULong   tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
    int        i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
    *offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
    *length = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
    *is_sfnt_cid = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
    /* TODO: support for sfnt-wrapped PS/CID in TTC format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
    /* version check for 'typ1' (should be ignored?) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
    if ( FT_READ_ULONG( tag ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
    if ( tag != TTAG_typ1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
      return FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
    if ( FT_READ_USHORT( numTables ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
    if ( FT_STREAM_SKIP( 2 * 3 ) ) /* skip binary search header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
    pstable_index = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
    *is_sfnt_cid  = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
    for ( i = 0; i < numTables; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
      if ( FT_READ_ULONG( tag )     || FT_STREAM_SKIP( 4 )      ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
           FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
      if ( tag == TTAG_CID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
        pstable_index++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
        *offset += 22;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
        *length -= 22;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
        *is_sfnt_cid = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
        if ( face_index < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
          return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
      else if ( tag == TTAG_TYP1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
        pstable_index++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
        *offset += 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
        *length -= 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
        *is_sfnt_cid = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
        if ( face_index < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
          return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
      if ( face_index >= 0 && pstable_index == face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
        return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
    return FT_Err_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
  open_face_PS_from_sfnt_stream( FT_Library     library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
                                 FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
                                 FT_Long        face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
                                 FT_Int         num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
                                 FT_Parameter  *params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
                                 FT_Face       *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
    FT_ULong   offset, length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
    FT_Long    pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
    FT_Bool    is_sfnt_cid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
    FT_Byte*   sfnt_ps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
    FT_UNUSED( num_params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
    FT_UNUSED( params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
    pos = FT_Stream_Pos( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
    error = ft_lookup_PS_in_sfnt_stream( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
                                         face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
                                         &offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
                                         &length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
                                         &is_sfnt_cid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
    if ( FT_Stream_Seek( stream, pos + offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
    if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
    error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
    error = open_face_from_buffer( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
                                   sfnt_ps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
                                   length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
                                   face_index < 0 ? face_index : 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
                                   is_sfnt_cid ? "cid" : "type1",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
                                   aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
      FT_Error  error1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
      if ( error == FT_Err_Unknown_File_Format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
        error1 = FT_Stream_Seek( stream, pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
        if ( error1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
          return error1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
  /* The resource header says we've got resource_cnt `POST' (type1) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
  /* resources in this file.  They all need to be coalesced into    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
  /* one lump which gets passed on to the type1 driver.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
  /* Here can be only one PostScript font in a file so face_index   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
  /* must be 0 (or -1).                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
  /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
  Mac_Read_POST_Resource( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
                          FT_Stream   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
                          FT_Long    *offsets,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
                          FT_Long     resource_cnt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
                          FT_Long     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
                          FT_Face    *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
    FT_Error   error  = FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
    FT_Byte*   pfb_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
    int        i, type, flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
    FT_Long    len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
    FT_Long    pfb_len, pfb_pos, pfb_lenpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
    FT_Long    rlen, temp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
    if ( face_index == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
      face_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
    if ( face_index != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
    /* Find the length of all the POST resources, concatenated.  Assume */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
    /* worst case (each resource in its own section).                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
    pfb_len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
    for ( i = 0; i < resource_cnt; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
      error = FT_Stream_Seek( stream, offsets[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
      if ( FT_READ_LONG( temp ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
      pfb_len += temp + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
    if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
    pfb_data[0] = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
    pfb_data[1] = 1;            /* Ascii section */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
    pfb_data[2] = 0;            /* 4-byte length, fill in later */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
    pfb_data[3] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
    pfb_data[4] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
    pfb_data[5] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
    pfb_pos     = 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
    pfb_lenpos  = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
    len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
    type = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
    for ( i = 0; i < resource_cnt; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
      error = FT_Stream_Seek( stream, offsets[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
        goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
      if ( FT_READ_LONG( rlen ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
      if ( FT_READ_USHORT( flags ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
      FT_TRACE3(( "POST fragment[%d]: offsets=0x%08x, rlen=0x%08x, flags=0x%04x\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
                   i, offsets[i], rlen, flags ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
      /* postpone the check of rlen longer than buffer until FT_Stream_Read() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
      if ( ( flags >> 8 ) == 0 )        /* Comment, should not be loaded */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
      /* the flags are part of the resource, so rlen >= 2.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
      /* but some fonts declare rlen = 0 for empty fragment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
      if ( rlen > 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
        rlen -= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
        rlen = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
      if ( ( flags >> 8 ) == type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
        len += rlen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
        if ( pfb_lenpos + 3 > pfb_len + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
          goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
        pfb_data[pfb_lenpos    ] = (FT_Byte)( len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
        pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
        pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
        pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
        if ( ( flags >> 8 ) == 5 )      /* End of font mark */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
        if ( pfb_pos + 6 > pfb_len + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
          goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
        pfb_data[pfb_pos++] = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
        type = flags >> 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
        len = rlen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
        pfb_data[pfb_pos++] = (FT_Byte)type;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
        pfb_lenpos          = pfb_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
        pfb_data[pfb_pos++] = 0;        /* 4-byte length, fill in later */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
        pfb_data[pfb_pos++] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
        pfb_data[pfb_pos++] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
        pfb_data[pfb_pos++] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
      error = FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
      if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
        goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
      error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
        goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
      pfb_pos += rlen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
    if ( pfb_pos + 2 > pfb_len + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
      goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
    pfb_data[pfb_pos++] = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
    pfb_data[pfb_pos++] = 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
    if ( pfb_lenpos + 3 > pfb_len + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
      goto Exit2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
    pfb_data[pfb_lenpos    ] = (FT_Byte)( len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
    pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
    pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
    pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
    return open_face_from_buffer( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
                                  pfb_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
                                  pfb_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
                                  face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
                                  "type1",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
                                  aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
  Exit2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
    FT_FREE( pfb_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
  /* The resource header says we've got resource_cnt `sfnt'      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
  /* (TrueType/OpenType) resources in this file.  Look through   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
  /* them for the one indicated by face_index, load it into mem, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
  /* pass it on the the truetype driver and return it.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
  /*                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
  Mac_Read_sfnt_Resource( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
                          FT_Stream   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
                          FT_Long    *offsets,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
                          FT_Long     resource_cnt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
                          FT_Long     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
                          FT_Face    *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
    FT_Byte*   sfnt_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
    FT_Long    flag_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
    FT_Long    rlen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
    int        is_cff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
    FT_Long    face_index_in_resource = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
    if ( face_index == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
      face_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
    if ( face_index >= resource_cnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
    flag_offset = offsets[face_index];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
    error = FT_Stream_Seek( stream, flag_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
    if ( FT_READ_LONG( rlen ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
    if ( rlen == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
    error = open_face_PS_from_sfnt_stream( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
                                           stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
                                           face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
                                           0, NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
                                           aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
    /* rewind sfnt stream before open_face_PS_from_sfnt_stream() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
    if ( FT_Stream_Seek( stream, flag_offset + 4 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
    if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
    error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
    is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
    error = open_face_from_buffer( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
                                   sfnt_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
                                   rlen,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
                                   face_index_in_resource,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
                                   is_cff ? "cff" : "truetype",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
                                   aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
  /* Check for a valid resource fork header, or a valid dfont    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
  /* header.  In a resource fork the first 16 bytes are repeated */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
  /* at the location specified by bytes 4-7.  In a dfont bytes   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
  /* 4-7 point to 16 bytes of zeroes instead.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
  /*                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
  IsMacResource( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
                 FT_Stream   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
                 FT_Long     resource_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
                 FT_Long     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
                 FT_Face    *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
    FT_Long    map_offset, rdara_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
    FT_Long    *data_offsets;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
    FT_Long    count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
    error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
                                       &map_offset, &rdara_pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
    error = FT_Raccess_Get_DataOffsets( library, stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
                                        map_offset, rdara_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
                                        TTAG_POST,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
                                        &data_offsets, &count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
      error = Mac_Read_POST_Resource( library, stream, data_offsets, count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1761
                                      face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
      FT_FREE( data_offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
      /* POST exists in an LWFN providing a single face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
        (*aface)->num_faces = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
    error = FT_Raccess_Get_DataOffsets( library, stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
                                        map_offset, rdara_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
                                        TTAG_sfnt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
                                        &data_offsets, &count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
      FT_Long  face_index_internal = face_index % count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
      error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
                                      face_index_internal, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
      FT_FREE( data_offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
        (*aface)->num_faces = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
  /* Check for a valid macbinary header, and if we find one   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
  /* check that the (flattened) resource fork in it is valid. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
  /*                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
  IsMacBinary( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1794
               FT_Stream   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1795
               FT_Long     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
               FT_Face    *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1798
    unsigned char  header[128];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1799
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1800
    FT_Long        dlen, offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
    if ( NULL == stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
      return FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
    error = FT_Stream_Seek( stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
    error = FT_Stream_Read( stream, (FT_Byte*)header, 128 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
    if (            header[ 0] !=  0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
                    header[74] !=  0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
                    header[82] !=  0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
                    header[ 1] ==  0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
                    header[ 1] >  33 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
                    header[63] !=  0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
         header[2 + header[1]] !=  0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
      return FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
    dlen = ( header[0x53] << 24 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
           ( header[0x54] << 16 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
           ( header[0x55] <<  8 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
             header[0x56];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
    rlen = ( header[0x57] << 24 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
           ( header[0x58] << 16 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
           ( header[0x59] <<  8 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
             header[0x5a];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
    offset = 128 + ( ( dlen + 127 ) & ~127 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
    return IsMacResource( library, stream, offset, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
  load_face_in_embedded_rfork( FT_Library           library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
                               FT_Stream            stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
                               FT_Long              face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
                               FT_Face             *aface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
                               const FT_Open_Args  *args )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
#define FT_COMPONENT  trace_raccess
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
    FT_Error   error  = FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1855
    int        i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
    char *     file_names[FT_RACCESS_N_RULES];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
    FT_Long    offsets[FT_RACCESS_N_RULES];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
    FT_Error   errors[FT_RACCESS_N_RULES];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
    FT_Bool    is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
    FT_Open_Args  args2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
    FT_Stream     stream2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
    FT_Raccess_Guess( library, stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
                      args->pathname, file_names, offsets, errors );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
    for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
      is_darwin_vfs = raccess_rule_by_darwin_vfs( i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
      if ( is_darwin_vfs && vfs_rfork_has_no_font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
        FT_TRACE3(( "Skip rule %d: darwin vfs resource fork"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
                    " is already checked and"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
                    " no font is found\n", i ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
      if ( errors[i] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
        FT_TRACE3(( "Error[%d] has occurred in rule %d\n", errors[i], i ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
      args2.flags    = FT_OPEN_PATHNAME;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
      args2.pathname = file_names[i] ? file_names[i] : args->pathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
      FT_TRACE3(( "Try rule %d: %s (offset=%d) ...",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
                  i, args2.pathname, offsets[i] ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
      error = FT_Stream_New( library, &args2, &stream2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
      if ( is_darwin_vfs && error == FT_Err_Cannot_Open_Stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
        vfs_rfork_has_no_font = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1898
        FT_TRACE3(( "failed\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1899
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
      error = IsMacResource( library, stream2, offsets[i],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
                             face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
      FT_Stream_Free( stream2, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
      FT_TRACE3(( "%s\n", error ? "failed": "successful" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
      else if ( is_darwin_vfs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
          vfs_rfork_has_no_font = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
    for (i = 0; i < FT_RACCESS_N_RULES; i++)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
      if ( file_names[i] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
        FT_FREE( file_names[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
    /* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
      error = FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
#define FT_COMPONENT  trace_objs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
  /* Check for some macintosh formats without Carbon framework.    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
  /* Is this a macbinary file?  If so look at the resource fork.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
  /* Is this a mac dfont file?                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
  /* Is this an old style resource fork? (in data)                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
  /* Else call load_face_in_embedded_rfork to try extra rules      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
  /* (defined in `ftrfork.c').                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
  /*                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
  load_mac_face( FT_Library           library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
                 FT_Stream            stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
                 FT_Long              face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
                 FT_Face             *aface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
                 const FT_Open_Args  *args )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
    FT_Error error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
    FT_UNUSED( args );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
    error = IsMacBinary( library, stream, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
    if ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
#define FT_COMPONENT  trace_raccess
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
      FT_TRACE3(( "Try as dfont: %s ...", args->pathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
      error = IsMacResource( library, stream, 0, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
      FT_TRACE3(( "%s\n", error ? "failed" : "successful" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
#define FT_COMPONENT  trace_objs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
    if ( ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format      ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
           FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
         ( args->flags & FT_OPEN_PATHNAME )                            )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
      error = load_face_in_embedded_rfork( library, stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
                                           face_index, aface, args );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
#endif  /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
  FT_Open_Face( FT_Library           library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
                const FT_Open_Args*  args,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
                FT_Long              face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
                FT_Face             *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
    FT_Driver    driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
    FT_Stream    stream = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
    FT_Face      face   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
    FT_ListNode  node   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
    FT_Bool      external_stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
    FT_Module*   cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
    FT_Module*   limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
    /* test for valid `library' delayed to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
    /* FT_Stream_New()                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
    if ( ( !aface && face_index >= 0 ) || !args )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
    external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
                               args->stream                     );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
    /* create input stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
    error = FT_Stream_New( library, args, &stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
      goto Fail3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
    /* If the font driver is specified in the `args' structure, use */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
    /* it.  Otherwise, we scan the list of registered drivers.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
    if ( ( args->flags & FT_OPEN_DRIVER ) && args->driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
      driver = FT_DRIVER( args->driver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
      /* not all modules are drivers, so check... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
      if ( FT_MODULE_IS_DRIVER( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
        FT_Int         num_params = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
        FT_Parameter*  params     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
        if ( args->flags & FT_OPEN_PARAMS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
          num_params = args->num_params;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
          params     = args->params;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
        error = open_face( driver, stream, face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
                           num_params, params, &face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
        if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
          goto Success;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
        error = FT_Err_Invalid_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
      FT_Stream_Free( stream, external_stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
      /* check each font driver for an appropriate format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
      cur   = library->modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
      limit = cur + library->num_modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
      for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
        /* not all modules are font drivers, so check... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
        if ( FT_MODULE_IS_DRIVER( cur[0] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
          FT_Int         num_params = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
          FT_Parameter*  params     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2061
          driver = FT_DRIVER( cur[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
          if ( args->flags & FT_OPEN_PARAMS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2065
            num_params = args->num_params;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2066
            params     = args->params;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2068
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2069
          error = open_face( driver, stream, face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2070
                             num_params, params, &face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2071
          if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2072
            goto Success;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2073
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2074
#ifdef FT_CONFIG_OPTION_MAC_FONTS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2075
          if ( ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2076
               FT_ERROR_BASE( error ) == FT_Err_Table_Missing           )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2077
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2078
            /* TrueType but essential tables are missing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2079
            if ( FT_Stream_Seek( stream, 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2080
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2081
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2082
            error = open_face_PS_from_sfnt_stream( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2083
                                                   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2084
                                                   face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2085
                                                   num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2086
                                                   params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2087
                                                   aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2088
            if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2089
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
              FT_Stream_Free( stream, external_stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
              return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2092
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2093
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
          if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
            goto Fail3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2099
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2101
  Fail3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
    /* If we are on the mac, and we get an FT_Err_Invalid_Stream_Operation */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2103
    /* it may be because we have an empty data fork, so we need to check   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2104
    /* the resource fork.                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2105
    if ( FT_ERROR_BASE( error ) != FT_Err_Cannot_Open_Stream       &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
         FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format      &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2107
         FT_ERROR_BASE( error ) != FT_Err_Invalid_Stream_Operation )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2108
      goto Fail2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2110
#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2111
    error = load_mac_face( library, stream, face_index, aface, args );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2112
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2113
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2114
      /* We don't want to go to Success here.  We've already done that. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2115
      /* On the other hand, if we succeeded we still need to close this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2116
      /* stream (we opened a different stream which extracted the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2117
      /* interesting information out of this stream here.  That stream  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2118
      /* will still be open and the face will point to it).             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2119
      FT_Stream_Free( stream, external_stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2120
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2121
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2123
    if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2124
      goto Fail2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2125
#endif  /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2127
      /* no driver is able to handle this format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2128
      error = FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
  Fail2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2131
      FT_Stream_Free( stream, external_stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2132
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2135
  Success:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
    FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2138
    /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
    if ( external_stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
      face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
    /* add the face object to its driver's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
    if ( FT_NEW( node ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2144
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
    node->data = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
    /* don't assume driver is the same as face->driver, so use */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
    /* face->driver instead.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
    FT_List_Add( &face->driver->faces_list, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2151
    /* now allocate a glyph slot object for the face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
    FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2154
    if ( face_index >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
      error = FT_New_GlyphSlot( face, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2158
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2160
      /* finally, allocate a size object for the face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2162
        FT_Size  size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2165
        FT_TRACE4(( "FT_Open_Face: Creating size object\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
        error = FT_New_Size( face, &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2168
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2169
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2171
        face->size = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2172
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2173
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2175
    /* some checks */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2177
    if ( FT_IS_SCALABLE( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2178
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2179
      if ( face->height < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2180
        face->height = (FT_Short)-face->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
      if ( !FT_HAS_VERTICAL( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
        face->max_advance_height = (FT_Short)face->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
    if ( FT_HAS_FIXED_SIZES( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2188
      FT_Int  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
      for ( i = 0; i < face->num_fixed_sizes; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
        FT_Bitmap_Size*  bsize = face->available_sizes + i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2196
        if ( bsize->height < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2197
          bsize->height = (FT_Short)-bsize->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2198
        if ( bsize->x_ppem < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2199
          bsize->x_ppem = (FT_Short)-bsize->x_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2200
        if ( bsize->y_ppem < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2201
          bsize->y_ppem = -bsize->y_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2202
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2203
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
    /* initialize internal face data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
      FT_Face_Internal  internal = face->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2210
      internal->transform_matrix.xx = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2211
      internal->transform_matrix.xy = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
      internal->transform_matrix.yx = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
      internal->transform_matrix.yy = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
      internal->transform_delta.x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2216
      internal->transform_delta.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2218
      internal->refcount = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
    if ( aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2222
      *aface = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2223
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
      FT_Done_Face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2229
    FT_Done_Face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2231
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
    FT_TRACE4(( "FT_Open_Face: Return %d\n", error ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2234
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2238
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2240
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2241
  FT_Attach_File( FT_Face      face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2242
                  const char*  filepathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2243
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2244
    FT_Open_Args  open;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2247
    /* test for valid `face' delayed to FT_Attach_Stream() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2249
    if ( !filepathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2250
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2252
    open.stream   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2253
    open.flags    = FT_OPEN_PATHNAME;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2254
    open.pathname = (char*)filepathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2256
    return FT_Attach_Stream( face, &open );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2257
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2260
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2262
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2263
  FT_Attach_Stream( FT_Face        face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2264
                    FT_Open_Args*  parameters )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2265
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2266
    FT_Stream  stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2267
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2268
    FT_Driver  driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2270
    FT_Driver_Class  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2273
    /* test for valid `parameters' delayed to FT_Stream_New() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2275
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2276
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2278
    driver = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2279
    if ( !driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2280
      return FT_Err_Invalid_Driver_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2282
    error = FT_Stream_New( driver->root.library, parameters, &stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2283
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2284
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2286
    /* we implement FT_Attach_Stream in each driver through the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2287
    /* `attach_file' interface                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2289
    error = FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2290
    clazz = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2291
    if ( clazz->attach_file )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2292
      error = clazz->attach_file( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2294
    /* close the attached stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2295
    FT_Stream_Free( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2296
                    (FT_Bool)( parameters->stream &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2297
                               ( parameters->flags & FT_OPEN_STREAM ) ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2299
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2300
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2301
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2304
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2306
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2307
  FT_Reference_Face( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2308
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2309
    face->internal->refcount++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2311
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2312
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2315
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2317
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2318
  FT_Done_Face( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2319
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2320
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2321
    FT_Driver    driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2322
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2323
    FT_ListNode  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2326
    error = FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2327
    if ( face && face->driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2328
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2329
      face->internal->refcount--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2330
      if ( face->internal->refcount > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2331
        error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2332
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2333
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2334
        driver = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2335
        memory = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2337
        /* find face in driver's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2338
        node = FT_List_Find( &driver->faces_list, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2339
        if ( node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2340
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2341
          /* remove face object from the driver's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2342
          FT_List_Remove( &driver->faces_list, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2343
          FT_FREE( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2345
          /* now destroy the object proper */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2346
          destroy_face( memory, face, driver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2347
          error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2348
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2349
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2350
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2352
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2353
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2356
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2358
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2359
  FT_New_Size( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2360
               FT_Size  *asize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2361
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2362
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2363
    FT_Memory        memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2364
    FT_Driver        driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2365
    FT_Driver_Class  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2367
    FT_Size          size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2368
    FT_ListNode      node = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2371
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2372
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2374
    if ( !asize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2375
      return FT_Err_Invalid_Size_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2377
    if ( !face->driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2378
      return FT_Err_Invalid_Driver_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2380
    *asize = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2382
    driver = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2383
    clazz  = driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2384
    memory = face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2386
    /* Allocate new size object and perform basic initialisation */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2387
    if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2388
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2390
    size->face = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2392
    /* for now, do not use any internal fields in size objects */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2393
    size->internal = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2395
    if ( clazz->init_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2396
      error = clazz->init_size( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2398
    /* in case of success, add to the face's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2399
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2400
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2401
      *asize     = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2402
      node->data = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2403
      FT_List_Add( &face->sizes_list, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2404
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2406
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2407
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2408
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2409
      FT_FREE( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2410
      FT_FREE( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2411
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2413
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2414
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2416
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2417
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2419
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2420
  FT_Done_Size( FT_Size  size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2421
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2422
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2423
    FT_Driver    driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2424
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2425
    FT_Face      face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2426
    FT_ListNode  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2429
    if ( !size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2430
      return FT_Err_Invalid_Size_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2432
    face = size->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2433
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2434
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2436
    driver = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2437
    if ( !driver )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2438
      return FT_Err_Invalid_Driver_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2440
    memory = driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2442
    error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2443
    node  = FT_List_Find( &face->sizes_list, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2444
    if ( node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2445
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2446
      FT_List_Remove( &face->sizes_list, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2447
      FT_FREE( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2449
      if ( face->size == size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2450
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2451
        face->size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2452
        if ( face->sizes_list.head )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2453
          face->size = (FT_Size)(face->sizes_list.head->data);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2454
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2456
      destroy_size( memory, size, driver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2457
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2458
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2459
      error = FT_Err_Invalid_Size_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2461
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2462
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2465
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2467
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2468
  FT_Match_Size( FT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2469
                 FT_Size_Request  req,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2470
                 FT_Bool          ignore_width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2471
                 FT_ULong*        size_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2472
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2473
    FT_Int   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2474
    FT_Long  w, h;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2477
    if ( !FT_HAS_FIXED_SIZES( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2478
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2480
    /* FT_Bitmap_Size doesn't provide enough info... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2481
    if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2482
      return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2484
    w = FT_REQUEST_WIDTH ( req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2485
    h = FT_REQUEST_HEIGHT( req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2487
    if ( req->width && !req->height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2488
      h = w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2489
    else if ( !req->width && req->height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2490
      w = h;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2492
    w = FT_PIX_ROUND( w );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2493
    h = FT_PIX_ROUND( h );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2495
    for ( i = 0; i < face->num_fixed_sizes; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2496
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2497
      FT_Bitmap_Size*  bsize = face->available_sizes + i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2500
      if ( h != FT_PIX_ROUND( bsize->y_ppem ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2501
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2502
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2503
      if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2504
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2505
        if ( size_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2506
          *size_index = (FT_ULong)i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2508
        return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2509
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2510
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2512
    return FT_Err_Invalid_Pixel_Size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2513
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2516
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2518
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2519
  ft_synthesize_vertical_metrics( FT_Glyph_Metrics*  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2520
                                  FT_Pos             advance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2521
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2522
    FT_Pos  height = metrics->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2525
    /* compensate for glyph with bbox above/below the baseline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2526
    if ( metrics->horiBearingY < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2527
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2528
      if ( height < metrics->horiBearingY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2529
        height = metrics->horiBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2530
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2531
    else if ( metrics->horiBearingY > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2532
      height -= metrics->horiBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2534
    /* the factor 1.2 is a heuristical value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2535
    if ( !advance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2536
      advance = height * 12 / 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2538
    metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2539
    metrics->vertBearingY = ( advance - height ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2540
    metrics->vertAdvance  = advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2541
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2542
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2544
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2545
  ft_recompute_scaled_metrics( FT_Face           face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2546
                               FT_Size_Metrics*  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2547
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2548
    /* Compute root ascender, descender, test height, and max_advance */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2550
#ifdef GRID_FIT_METRICS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2551
    metrics->ascender    = FT_PIX_CEIL( FT_MulFix( face->ascender,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2552
                                                   metrics->y_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2554
    metrics->descender   = FT_PIX_FLOOR( FT_MulFix( face->descender,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2555
                                                    metrics->y_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2557
    metrics->height      = FT_PIX_ROUND( FT_MulFix( face->height,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2558
                                                    metrics->y_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2560
    metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2561
                                                    metrics->x_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2562
#else /* !GRID_FIT_METRICS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2563
    metrics->ascender    = FT_MulFix( face->ascender,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2564
                                      metrics->y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2566
    metrics->descender   = FT_MulFix( face->descender,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2567
                                      metrics->y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2569
    metrics->height      = FT_MulFix( face->height,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2570
                                      metrics->y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2572
    metrics->max_advance = FT_MulFix( face->max_advance_width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2573
                                      metrics->x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2574
#endif /* !GRID_FIT_METRICS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2575
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2576
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2578
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2579
  FT_Select_Metrics( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2580
                     FT_ULong  strike_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2581
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2582
    FT_Size_Metrics*  metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2583
    FT_Bitmap_Size*   bsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2586
    metrics = &face->size->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2587
    bsize   = face->available_sizes + strike_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2589
    metrics->x_ppem = (FT_UShort)( ( bsize->x_ppem + 32 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2590
    metrics->y_ppem = (FT_UShort)( ( bsize->y_ppem + 32 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2592
    if ( FT_IS_SCALABLE( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2593
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2594
      metrics->x_scale = FT_DivFix( bsize->x_ppem,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2595
                                    face->units_per_EM );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2596
      metrics->y_scale = FT_DivFix( bsize->y_ppem,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2597
                                    face->units_per_EM );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2599
      ft_recompute_scaled_metrics( face, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2600
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2601
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2602
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2603
      metrics->x_scale     = 1L << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2604
      metrics->y_scale     = 1L << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2605
      metrics->ascender    = bsize->y_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2606
      metrics->descender   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2607
      metrics->height      = bsize->height << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2608
      metrics->max_advance = bsize->x_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2609
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2610
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2613
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2614
  FT_Request_Metrics( FT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2615
                      FT_Size_Request  req )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2616
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2617
    FT_Size_Metrics*  metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2618
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2620
    metrics = &face->size->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2622
    if ( FT_IS_SCALABLE( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2623
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2624
      FT_Long  w = 0, h = 0, scaled_w = 0, scaled_h = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2627
      switch ( req->type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2628
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2629
      case FT_SIZE_REQUEST_TYPE_NOMINAL:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2630
        w = h = face->units_per_EM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2631
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2633
      case FT_SIZE_REQUEST_TYPE_REAL_DIM:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2634
        w = h = face->ascender - face->descender;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2635
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2637
      case FT_SIZE_REQUEST_TYPE_BBOX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2638
        w = face->bbox.xMax - face->bbox.xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2639
        h = face->bbox.yMax - face->bbox.yMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2640
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2642
      case FT_SIZE_REQUEST_TYPE_CELL:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2643
        w = face->max_advance_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2644
        h = face->ascender - face->descender;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2645
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2647
      case FT_SIZE_REQUEST_TYPE_SCALES:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2648
        metrics->x_scale = (FT_Fixed)req->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2649
        metrics->y_scale = (FT_Fixed)req->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2650
        if ( !metrics->x_scale )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2651
          metrics->x_scale = metrics->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2652
        else if ( !metrics->y_scale )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2653
          metrics->y_scale = metrics->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2654
        goto Calculate_Ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2656
      case FT_SIZE_REQUEST_TYPE_MAX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2657
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2658
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2660
      /* to be on the safe side */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2661
      if ( w < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2662
        w = -w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2664
      if ( h < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2665
        h = -h;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2667
      scaled_w = FT_REQUEST_WIDTH ( req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2668
      scaled_h = FT_REQUEST_HEIGHT( req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2670
      /* determine scales */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2671
      if ( req->width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2672
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2673
        metrics->x_scale = FT_DivFix( scaled_w, w );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2674
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2675
        if ( req->height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2676
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2677
          metrics->y_scale = FT_DivFix( scaled_h, h );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2679
          if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2680
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2681
            if ( metrics->y_scale > metrics->x_scale )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2682
              metrics->y_scale = metrics->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2683
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2684
              metrics->x_scale = metrics->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2685
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2686
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2687
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2688
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2689
          metrics->y_scale = metrics->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2690
          scaled_h = FT_MulDiv( scaled_w, h, w );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2691
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2692
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2693
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2694
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2695
        metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2696
        scaled_w = FT_MulDiv( scaled_h, w, h );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2697
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2699
  Calculate_Ppem:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2700
      /* calculate the ppems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2701
      if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2702
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2703
        scaled_w = FT_MulFix( face->units_per_EM, metrics->x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2704
        scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2705
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2707
      metrics->x_ppem = (FT_UShort)( ( scaled_w + 32 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2708
      metrics->y_ppem = (FT_UShort)( ( scaled_h + 32 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2709
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2710
      ft_recompute_scaled_metrics( face, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2711
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2712
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2713
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2714
      FT_ZERO( metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2715
      metrics->x_scale = 1L << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2716
      metrics->y_scale = 1L << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2717
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2718
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2721
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2723
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2724
  FT_Select_Size( FT_Face  face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2725
                  FT_Int   strike_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2726
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2727
    FT_Driver_Class  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2730
    if ( !face || !FT_HAS_FIXED_SIZES( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2731
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2733
    if ( strike_index < 0 || strike_index >= face->num_fixed_sizes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2734
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2736
    clazz = face->driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2738
    if ( clazz->select_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2739
      return clazz->select_size( face->size, (FT_ULong)strike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2741
    FT_Select_Metrics( face, (FT_ULong)strike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2743
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2744
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2747
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2749
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2750
  FT_Request_Size( FT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2751
                   FT_Size_Request  req )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2752
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2753
    FT_Driver_Class  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2754
    FT_ULong         strike_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2756
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2757
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2758
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2760
    if ( !req || req->width < 0 || req->height < 0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2761
         req->type >= FT_SIZE_REQUEST_TYPE_MAX )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2762
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2764
    clazz = face->driver->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2765
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2766
    if ( clazz->request_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2767
      return clazz->request_size( face->size, req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2769
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2770
     * The reason that a driver doesn't have `request_size' defined is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2771
     * either that the scaling here suffices or that the supported formats
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2772
     * are bitmap-only and size matching is not implemented.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2773
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2774
     * In the latter case, a simple size matching is done.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2775
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2776
    if ( !FT_IS_SCALABLE( face ) && FT_HAS_FIXED_SIZES( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2777
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2778
      FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2779
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2780
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2781
      error = FT_Match_Size( face, req, 0, &strike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2782
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2783
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2785
      FT_TRACE3(( "FT_Request_Size: bitmap strike %lu matched\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2786
                  strike_index ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2788
      return FT_Select_Size( face, (FT_Int)strike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2789
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2791
    FT_Request_Metrics( face, req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2792
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2793
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2794
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2797
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2798
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2799
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2800
  FT_Set_Char_Size( FT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2801
                    FT_F26Dot6  char_width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2802
                    FT_F26Dot6  char_height,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2803
                    FT_UInt     horz_resolution,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2804
                    FT_UInt     vert_resolution )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2805
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2806
    FT_Size_RequestRec  req;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2808
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2809
    if ( !char_width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2810
      char_width = char_height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2811
    else if ( !char_height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2812
      char_height = char_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2814
    if ( !horz_resolution )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2815
      horz_resolution = vert_resolution;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2816
    else if ( !vert_resolution )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2817
      vert_resolution = horz_resolution;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2819
    if ( char_width  < 1 * 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2820
      char_width  = 1 * 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2821
    if ( char_height < 1 * 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2822
      char_height = 1 * 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2823
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2824
    if ( !horz_resolution )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2825
      horz_resolution = vert_resolution = 72;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2826
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2827
    req.type           = FT_SIZE_REQUEST_TYPE_NOMINAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2828
    req.width          = char_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2829
    req.height         = char_height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2830
    req.horiResolution = horz_resolution;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2831
    req.vertResolution = vert_resolution;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2832
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2833
    return FT_Request_Size( face, &req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2834
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2837
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2839
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2840
  FT_Set_Pixel_Sizes( FT_Face  face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2841
                      FT_UInt  pixel_width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2842
                      FT_UInt  pixel_height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2843
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2844
    FT_Size_RequestRec  req;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2847
    if ( pixel_width == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2848
      pixel_width = pixel_height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2849
    else if ( pixel_height == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2850
      pixel_height = pixel_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2851
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2852
    if ( pixel_width  < 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2853
      pixel_width  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2854
    if ( pixel_height < 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2855
      pixel_height = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2857
    /* use `>=' to avoid potential compiler warning on 16bit platforms */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2858
    if ( pixel_width  >= 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2859
      pixel_width  = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2860
    if ( pixel_height >= 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2861
      pixel_height = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2863
    req.type           = FT_SIZE_REQUEST_TYPE_NOMINAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2864
    req.width          = pixel_width << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2865
    req.height         = pixel_height << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2866
    req.horiResolution = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2867
    req.vertResolution = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2869
    return FT_Request_Size( face, &req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2870
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2871
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2873
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2875
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2876
  FT_Get_Kerning( FT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2877
                  FT_UInt     left_glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2878
                  FT_UInt     right_glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2879
                  FT_UInt     kern_mode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2880
                  FT_Vector  *akerning )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2881
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2882
    FT_Error   error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2883
    FT_Driver  driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2886
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2887
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2889
    if ( !akerning )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2890
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2892
    driver = face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2894
    akerning->x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2895
    akerning->y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2897
    if ( driver->clazz->get_kerning )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2898
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2899
      error = driver->clazz->get_kerning( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2900
                                          left_glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2901
                                          right_glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2902
                                          akerning );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2903
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2904
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2905
        if ( kern_mode != FT_KERNING_UNSCALED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2906
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2907
          akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2908
          akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2909
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2910
          if ( kern_mode != FT_KERNING_UNFITTED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2911
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2912
            /* we scale down kerning values for small ppem values */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2913
            /* to avoid that rounding makes them too big.         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2914
            /* `25' has been determined heuristically.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2915
            if ( face->size->metrics.x_ppem < 25 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2916
              akerning->x = FT_MulDiv( akerning->x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2917
                                       face->size->metrics.x_ppem, 25 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2918
            if ( face->size->metrics.y_ppem < 25 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2919
              akerning->y = FT_MulDiv( akerning->y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2920
                                       face->size->metrics.y_ppem, 25 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2922
            akerning->x = FT_PIX_ROUND( akerning->x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2923
            akerning->y = FT_PIX_ROUND( akerning->y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2924
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2925
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2926
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2927
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2928
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2929
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2930
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2932
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2933
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2935
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2936
  FT_Get_Track_Kerning( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2937
                        FT_Fixed   point_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2938
                        FT_Int     degree,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2939
                        FT_Fixed*  akerning )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2940
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2941
    FT_Service_Kerning  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2942
    FT_Error            error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2943
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2944
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2945
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2946
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2947
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2948
    if ( !akerning )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2949
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2951
    FT_FACE_FIND_SERVICE( face, service, KERNING );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2952
    if ( !service )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2953
      return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2954
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2955
    error = service->get_track( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2956
                                point_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2957
                                degree,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2958
                                akerning );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2960
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2961
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2964
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2965
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2966
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2967
  FT_Select_Charmap( FT_Face      face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2968
                     FT_Encoding  encoding )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2969
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2970
    FT_CharMap*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2971
    FT_CharMap*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2973
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2974
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2975
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2976
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2977
    if ( encoding == FT_ENCODING_NONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2978
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2980
    /* FT_ENCODING_UNICODE is special.  We try to find the `best' Unicode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2981
    /* charmap available, i.e., one with UCS-4 characters, if possible.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2982
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2983
    /* This is done by find_unicode_charmap() above, to share code.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2984
    if ( encoding == FT_ENCODING_UNICODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2985
      return find_unicode_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2986
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2987
    cur = face->charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2988
    if ( !cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2989
      return FT_Err_Invalid_CharMap_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2990
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2991
    limit = cur + face->num_charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2993
    for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2994
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2995
      if ( cur[0]->encoding == encoding )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2996
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2997
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2998
        if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2999
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3000
          FT_ERROR(( "FT_Select_Charmap: requested charmap is found (%d), "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3001
                     "but in too late position to cache\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3002
                     cur - face->charmaps ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3003
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3004
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3005
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3006
        face->charmap = cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3007
        return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3008
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3009
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3011
    return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3012
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3014
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3015
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3017
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3018
  FT_Set_Charmap( FT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3019
                  FT_CharMap  charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3020
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3021
    FT_CharMap*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3022
    FT_CharMap*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3023
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3025
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3026
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3028
    cur = face->charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3029
    if ( !cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3030
      return FT_Err_Invalid_CharMap_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3031
    if ( FT_Get_CMap_Format( charmap ) == 14 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3032
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3033
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3034
    limit = cur + face->num_charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3035
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3036
    for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3037
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3038
      if ( cur[0] == charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3039
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3040
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3041
        if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3042
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3043
          FT_ERROR(( "FT_Set_Charmap: requested charmap is found (%d), "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3044
                     "but in too late position to cache\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3045
                     cur - face->charmaps ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3046
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3047
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3048
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3049
        face->charmap = cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3050
        return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3051
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3052
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3053
    return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3054
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3056
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3057
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3058
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3059
  FT_EXPORT_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3060
  FT_Get_Charmap_Index( FT_CharMap  charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3061
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3062
    FT_Int  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3063
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3064
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3065
    if ( !charmap || !charmap->face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3066
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3067
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3068
    for ( i = 0; i < charmap->face->num_charmaps; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3069
      if ( charmap->face->charmaps[i] == charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3070
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3072
    FT_ASSERT( i < charmap->face->num_charmaps );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3073
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3074
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3075
    if ( i > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3076
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3077
      FT_ERROR(( "FT_Get_Charmap_Index: requested charmap is found (%d), "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3078
                 "but in too late position to cache\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3079
                 i ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3080
      return -i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3081
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3082
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3083
    return i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3084
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3085
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3086
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3087
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3088
  ft_cmap_done_internal( FT_CMap  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3089
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3090
    FT_CMap_Class  clazz  = cmap->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3091
    FT_Face        face   = cmap->charmap.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3092
    FT_Memory      memory = FT_FACE_MEMORY(face);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3093
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3095
    if ( clazz->done )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3096
      clazz->done( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3097
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3098
    FT_FREE( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3099
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3102
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3103
  FT_CMap_Done( FT_CMap  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3104
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3105
    if ( cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3106
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3107
      FT_Face    face   = cmap->charmap.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3108
      FT_Memory  memory = FT_FACE_MEMORY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3109
      FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3110
      FT_Int     i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3113
      for ( i = 0; i < face->num_charmaps; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3114
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3115
        if ( (FT_CMap)face->charmaps[i] == cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3116
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3117
          FT_CharMap  last_charmap = face->charmaps[face->num_charmaps - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3120
          if ( FT_RENEW_ARRAY( face->charmaps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3121
                               face->num_charmaps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3122
                               face->num_charmaps - 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3123
            return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3125
          /* remove it from our list of charmaps */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3126
          for ( j = i + 1; j < face->num_charmaps; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3127
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3128
            if ( j == face->num_charmaps - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3129
              face->charmaps[j - 1] = last_charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3130
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3131
              face->charmaps[j - 1] = face->charmaps[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3132
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3134
          face->num_charmaps--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3136
          if ( (FT_CMap)face->charmap == cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3137
            face->charmap = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3139
          ft_cmap_done_internal( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3141
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3142
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3143
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3144
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3145
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3148
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3149
  FT_CMap_New( FT_CMap_Class  clazz,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3150
               FT_Pointer     init_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3151
               FT_CharMap     charmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3152
               FT_CMap       *acmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3153
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3154
    FT_Error   error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3155
    FT_Face    face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3156
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3157
    FT_CMap    cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3160
    if ( clazz == NULL || charmap == NULL || charmap->face == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3161
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3163
    face   = charmap->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3164
    memory = FT_FACE_MEMORY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3166
    if ( !FT_ALLOC( cmap, clazz->size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3167
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3168
      cmap->charmap = *charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3169
      cmap->clazz   = clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3171
      if ( clazz->init )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3172
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3173
        error = clazz->init( cmap, init_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3174
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3175
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3176
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3178
      /* add it to our list of charmaps */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3179
      if ( FT_RENEW_ARRAY( face->charmaps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3180
                           face->num_charmaps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3181
                           face->num_charmaps + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3182
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3184
      face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3185
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3187
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3188
    if ( acmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3189
      *acmap = cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3191
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3193
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3194
    ft_cmap_done_internal( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3195
    cmap = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3196
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3197
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3200
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3202
  FT_EXPORT_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3203
  FT_Get_Char_Index( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3204
                     FT_ULong  charcode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3205
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3206
    FT_UInt  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3209
    if ( face && face->charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3210
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3211
      FT_CMap  cmap = FT_CMAP( face->charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3214
      if ( charcode > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3215
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3216
        FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3217
        FT_TRACE1(( " 0x%x is truncated\n", charcode ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3218
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3219
      result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3220
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3221
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3222
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3225
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3227
  FT_EXPORT_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3228
  FT_Get_First_Char( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3229
                     FT_UInt  *agindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3230
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3231
    FT_ULong  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3232
    FT_UInt   gindex = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3235
    if ( face && face->charmap && face->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3236
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3237
      gindex = FT_Get_Char_Index( face, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3238
      if ( gindex == 0 || gindex >= (FT_UInt)face->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3239
        result = FT_Get_Next_Char( face, 0, &gindex );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3240
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3242
    if ( agindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3243
      *agindex = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3245
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3246
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3249
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3251
  FT_EXPORT_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3252
  FT_Get_Next_Char( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3253
                    FT_ULong  charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3254
                    FT_UInt  *agindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3255
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3256
    FT_ULong  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3257
    FT_UInt   gindex = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3260
    if ( face && face->charmap && face->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3261
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3262
      FT_UInt32  code = (FT_UInt32)charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3263
      FT_CMap    cmap = FT_CMAP( face->charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3266
      do {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3267
        gindex = cmap->clazz->char_next( cmap, &code );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3268
      } while ( gindex >= (FT_UInt)face->num_glyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3270
      result = ( gindex == 0 ) ? 0 : code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3271
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3273
    if ( agindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3274
      *agindex = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3276
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3277
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3280
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3282
  FT_EXPORT_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3283
  FT_Face_GetCharVariantIndex( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3284
                               FT_ULong  charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3285
                               FT_ULong  variantSelector )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3286
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3287
    FT_UInt  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3290
    if ( face && face->charmap &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3291
        face->charmap->encoding == FT_ENCODING_UNICODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3292
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3293
      FT_CharMap  charmap = find_variant_selector_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3294
      FT_CMap     ucmap = FT_CMAP( face->charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3297
      if ( charmap != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3298
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3299
        FT_CMap  vcmap = FT_CMAP( charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3302
        if ( charcode > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3303
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3304
          FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3305
          FT_TRACE1(( " 0x%x is truncated\n", charcode ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3306
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3307
        if ( variantSelector > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3308
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3309
          FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3310
          FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3311
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3313
        result = vcmap->clazz->char_var_index( vcmap, ucmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3314
                                               (FT_UInt32)charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3315
                                               (FT_UInt32)variantSelector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3316
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3317
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3319
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3320
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3323
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3325
  FT_EXPORT_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3326
  FT_Face_GetCharVariantIsDefault( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3327
                                   FT_ULong  charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3328
                                   FT_ULong  variantSelector )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3329
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3330
    FT_Int  result = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3333
    if ( face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3334
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3335
      FT_CharMap  charmap = find_variant_selector_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3338
      if ( charmap != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3339
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3340
        FT_CMap  vcmap = FT_CMAP( charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3343
        if ( charcode > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3344
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3345
          FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3346
          FT_TRACE1(( " 0x%x is truncated\n", charcode ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3347
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3348
        if ( variantSelector > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3349
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3350
          FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3351
          FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3352
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3354
        result = vcmap->clazz->char_var_default( vcmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3355
                                                 (FT_UInt32)charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3356
                                                 (FT_UInt32)variantSelector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3357
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3358
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3360
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3361
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3364
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3366
  FT_EXPORT_DEF( FT_UInt32* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3367
  FT_Face_GetVariantSelectors( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3368
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3369
    FT_UInt32  *result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3372
    if ( face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3373
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3374
      FT_CharMap  charmap = find_variant_selector_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3377
      if ( charmap != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3378
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3379
        FT_CMap    vcmap  = FT_CMAP( charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3380
        FT_Memory  memory = FT_FACE_MEMORY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3383
        result = vcmap->clazz->variant_list( vcmap, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3384
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3385
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3387
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3388
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3391
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3393
  FT_EXPORT_DEF( FT_UInt32* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3394
  FT_Face_GetVariantsOfChar( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3395
                             FT_ULong  charcode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3396
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3397
    FT_UInt32  *result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3400
    if ( face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3401
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3402
      FT_CharMap  charmap = find_variant_selector_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3405
      if ( charmap != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3406
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3407
        FT_CMap    vcmap  = FT_CMAP( charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3408
        FT_Memory  memory = FT_FACE_MEMORY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3411
        if ( charcode > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3412
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3413
          FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3414
          FT_TRACE1(( " 0x%x is truncated\n", charcode ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3415
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3416
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3417
        result = vcmap->clazz->charvariant_list( vcmap, memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3418
                                                 (FT_UInt32)charcode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3419
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3420
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3421
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3422
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3425
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3427
  FT_EXPORT_DEF( FT_UInt32* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3428
  FT_Face_GetCharsOfVariant( FT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3429
                             FT_ULong  variantSelector )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3430
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3431
    FT_UInt32  *result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3434
    if ( face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3435
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3436
      FT_CharMap  charmap = find_variant_selector_charmap( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3439
      if ( charmap != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3440
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3441
        FT_CMap    vcmap  = FT_CMAP( charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3442
        FT_Memory  memory = FT_FACE_MEMORY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3445
        if ( variantSelector > 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3446
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3447
          FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3448
          FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3449
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3451
        result = vcmap->clazz->variantchar_list( vcmap, memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3452
                                                 (FT_UInt32)variantSelector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3453
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3454
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3456
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3457
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3460
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3462
  FT_EXPORT_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3463
  FT_Get_Name_Index( FT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3464
                     FT_String*  glyph_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3465
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3466
    FT_UInt  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3468
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3469
    if ( face && FT_HAS_GLYPH_NAMES( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3470
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3471
      FT_Service_GlyphDict  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3474
      FT_FACE_LOOKUP_SERVICE( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3475
                              service,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3476
                              GLYPH_DICT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3478
      if ( service && service->name_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3479
        result = service->name_index( face, glyph_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3480
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3482
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3483
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3486
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3488
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3489
  FT_Get_Glyph_Name( FT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3490
                     FT_UInt     glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3491
                     FT_Pointer  buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3492
                     FT_UInt     buffer_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3493
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3494
    FT_Error  error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3497
    /* clean up buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3498
    if ( buffer && buffer_max > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3499
      ((FT_Byte*)buffer)[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3501
    if ( face                                     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3502
         (FT_Long)glyph_index <= face->num_glyphs &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3503
         FT_HAS_GLYPH_NAMES( face )               )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3504
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3505
      FT_Service_GlyphDict  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3508
      FT_FACE_LOOKUP_SERVICE( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3509
                              service,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3510
                              GLYPH_DICT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3512
      if ( service && service->get_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3513
        error = service->get_name( face, glyph_index, buffer, buffer_max );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3514
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3516
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3517
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3520
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3522
  FT_EXPORT_DEF( const char* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3523
  FT_Get_Postscript_Name( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3524
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3525
    const char*  result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3528
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3529
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3531
    if ( !result )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3532
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3533
      FT_Service_PsFontName  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3536
      FT_FACE_LOOKUP_SERVICE( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3537
                              service,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3538
                              POSTSCRIPT_FONT_NAME );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3540
      if ( service && service->get_ps_font_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3541
        result = service->get_ps_font_name( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3542
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3544
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3545
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3546
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3549
  /* documentation is in tttables.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3551
  FT_EXPORT_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3552
  FT_Get_Sfnt_Table( FT_Face      face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3553
                     FT_Sfnt_Tag  tag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3554
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3555
    void*                  table = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3556
    FT_Service_SFNT_Table  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3557
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3559
    if ( face && FT_IS_SFNT( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3560
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3561
      FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3562
      if ( service != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3563
        table = service->get_table( face, tag );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3564
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3566
    return table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3567
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3570
  /* documentation is in tttables.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3572
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3573
  FT_Load_Sfnt_Table( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3574
                      FT_ULong   tag,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3575
                      FT_Long    offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3576
                      FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3577
                      FT_ULong*  length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3578
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3579
    FT_Service_SFNT_Table  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3580
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3582
    if ( !face || !FT_IS_SFNT( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3583
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3585
    FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3586
    if ( service == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3587
      return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3589
    return service->load_table( face, tag, offset, buffer, length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3590
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3593
  /* documentation is in tttables.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3594
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3595
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3596
  FT_Sfnt_Table_Info( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3597
                      FT_UInt    table_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3598
                      FT_ULong  *tag,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3599
                      FT_ULong  *length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3600
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3601
    FT_Service_SFNT_Table  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3602
    FT_ULong               offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3603
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3605
    if ( !face || !FT_IS_SFNT( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3606
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3607
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3608
    FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3609
    if ( service == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3610
      return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3612
    return service->table_info( face, table_index, tag, &offset, length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3613
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3616
  /* documentation is in tttables.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3618
  FT_EXPORT_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3619
  FT_Get_CMap_Language_ID( FT_CharMap  charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3620
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3621
    FT_Service_TTCMaps  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3622
    FT_Face             face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3623
    TT_CMapInfo         cmap_info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3626
    if ( !charmap || !charmap->face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3627
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3629
    face = charmap->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3630
    FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3631
    if ( service == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3632
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3633
    if ( service->get_cmap_info( charmap, &cmap_info ))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3634
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3635
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3636
    return cmap_info.language;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3637
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3640
  /* documentation is in tttables.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3642
  FT_EXPORT_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3643
  FT_Get_CMap_Format( FT_CharMap  charmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3644
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3645
    FT_Service_TTCMaps  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3646
    FT_Face             face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3647
    TT_CMapInfo         cmap_info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3649
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3650
    if ( !charmap || !charmap->face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3651
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3653
    face = charmap->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3654
    FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3655
    if ( service == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3656
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3657
    if ( service->get_cmap_info( charmap, &cmap_info ))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3658
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3660
    return cmap_info.format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3661
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3664
  /* documentation is in ftsizes.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3666
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3667
  FT_Activate_Size( FT_Size  size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3668
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3669
    FT_Face  face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3670
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3671
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3672
    if ( size == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3673
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3674
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3675
    face = size->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3676
    if ( face == NULL || face->driver == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3677
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3679
    /* we don't need anything more complex than that; all size objects */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3680
    /* are already listed by the face                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3681
    face->size = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3683
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3684
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3686
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3687
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3688
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3689
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3690
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3691
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3692
  /****                        R E N D E R E R S                        ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3693
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3694
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3695
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3696
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3697
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3699
  /* lookup a renderer by glyph format in the library's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3700
  FT_BASE_DEF( FT_Renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3701
  FT_Lookup_Renderer( FT_Library       library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3702
                      FT_Glyph_Format  format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3703
                      FT_ListNode*     node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3704
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3705
    FT_ListNode  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3706
    FT_Renderer  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3709
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3710
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3711
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3712
    cur = library->renderers.head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3714
    if ( node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3715
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3716
      if ( *node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3717
        cur = (*node)->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3718
      *node = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3719
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3721
    while ( cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3722
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3723
      FT_Renderer  renderer = FT_RENDERER( cur->data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3724
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3726
      if ( renderer->glyph_format == format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3727
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3728
        if ( node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3729
          *node = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3730
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3731
        result = renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3732
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3733
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3734
      cur = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3735
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3737
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3738
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3739
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3742
  static FT_Renderer
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3743
  ft_lookup_glyph_renderer( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3744
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3745
    FT_Face      face    = slot->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3746
    FT_Library   library = FT_FACE_LIBRARY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3747
    FT_Renderer  result  = library->cur_renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3750
    if ( !result || result->glyph_format != slot->format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3751
      result = FT_Lookup_Renderer( library, slot->format, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3753
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3754
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3756
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3757
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3758
  ft_set_current_renderer( FT_Library  library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3759
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3760
    FT_Renderer  renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3761
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3763
    renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3764
    library->cur_renderer = renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3765
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3766
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3767
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3768
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3769
  ft_add_renderer( FT_Module  module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3770
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3771
    FT_Library   library = module->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3772
    FT_Memory    memory  = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3773
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3774
    FT_ListNode  node    = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3775
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3777
    if ( FT_NEW( node ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3778
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3779
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3780
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3781
      FT_Renderer         render = FT_RENDERER( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3782
      FT_Renderer_Class*  clazz  = (FT_Renderer_Class*)module->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3785
      render->clazz        = clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3786
      render->glyph_format = clazz->glyph_format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3788
      /* allocate raster object if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3789
      if ( clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3790
           clazz->raster_class->raster_new                )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3791
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3792
        error = clazz->raster_class->raster_new( memory, &render->raster );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3793
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3794
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3796
        render->raster_render = clazz->raster_class->raster_render;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3797
        render->render        = clazz->render_glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3798
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3800
      /* add to list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3801
      node->data = module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3802
      FT_List_Add( &library->renderers, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3804
      ft_set_current_renderer( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3805
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3807
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3808
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3809
      FT_FREE( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3811
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3812
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3813
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3816
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3817
  ft_remove_renderer( FT_Module  module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3818
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3819
    FT_Library   library = module->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3820
    FT_Memory    memory  = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3821
    FT_ListNode  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3822
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3823
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3824
    node = FT_List_Find( &library->renderers, module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3825
    if ( node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3826
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3827
      FT_Renderer  render = FT_RENDERER( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3829
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3830
      /* release raster object, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3831
      if ( render->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3832
           render->raster                                         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3833
        render->clazz->raster_class->raster_done( render->raster );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3835
      /* remove from list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3836
      FT_List_Remove( &library->renderers, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3837
      FT_FREE( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3839
      ft_set_current_renderer( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3840
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3841
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3843
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3844
  /* documentation is in ftrender.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3846
  FT_EXPORT_DEF( FT_Renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3847
  FT_Get_Renderer( FT_Library       library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3848
                   FT_Glyph_Format  format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3849
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3850
    /* test for valid `library' delayed to FT_Lookup_Renderer() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3851
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3852
    return FT_Lookup_Renderer( library, format, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3853
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3854
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3856
  /* documentation is in ftrender.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3857
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3858
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3859
  FT_Set_Renderer( FT_Library     library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3860
                   FT_Renderer    renderer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3861
                   FT_UInt        num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3862
                   FT_Parameter*  parameters )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3863
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3864
    FT_ListNode  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3865
    FT_Error     error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3866
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3868
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3869
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3870
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3871
    if ( !renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3872
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3874
    node = FT_List_Find( &library->renderers, renderer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3875
    if ( !node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3876
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3877
      error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3878
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3879
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3881
    FT_List_Up( &library->renderers, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3883
    if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3884
      library->cur_renderer = renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3886
    if ( num_params > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3887
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3888
      FT_Renderer_SetModeFunc  set_mode = renderer->clazz->set_mode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3889
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3890
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3891
      for ( ; num_params > 0; num_params-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3892
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3893
        error = set_mode( renderer, parameters->tag, parameters->data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3894
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3895
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3896
        parameters++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3897
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3898
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3900
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3901
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3902
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3903
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3904
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3905
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3906
  FT_Render_Glyph_Internal( FT_Library      library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3907
                            FT_GlyphSlot    slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3908
                            FT_Render_Mode  render_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3909
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3910
    FT_Error     error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3911
    FT_Renderer  renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3912
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3914
    /* if it is already a bitmap, no need to do anything */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3915
    switch ( slot->format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3916
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3917
    case FT_GLYPH_FORMAT_BITMAP:   /* already a bitmap, don't do anything */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3918
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3919
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3920
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3921
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3922
        FT_ListNode  node   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3923
        FT_Bool      update = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3924
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3926
        /* small shortcut for the very common case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3927
        if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3928
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3929
          renderer = library->cur_renderer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3930
          node     = library->renderers.head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3931
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3932
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3933
          renderer = FT_Lookup_Renderer( library, slot->format, &node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3935
        error = FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3936
        while ( renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3937
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3938
          error = renderer->render( renderer, slot, render_mode, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3939
          if ( !error                                               ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3940
               FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3941
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3942
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3943
          /* FT_Err_Cannot_Render_Glyph is returned if the render mode   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3944
          /* is unsupported by the current renderer for this glyph image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3945
          /* format.                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3947
          /* now, look for another renderer that supports the same */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3948
          /* format.                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3949
          renderer = FT_Lookup_Renderer( library, slot->format, &node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3950
          update   = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3951
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3952
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3953
        /* if we changed the current renderer for the glyph image format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3954
        /* we need to select it as the next current one                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3955
        if ( !error && update && renderer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3956
          FT_Set_Renderer( library, renderer, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3957
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3958
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3960
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3961
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3964
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3965
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3966
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3967
  FT_Render_Glyph( FT_GlyphSlot    slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3968
                   FT_Render_Mode  render_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3969
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3970
    FT_Library  library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3971
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3973
    if ( !slot || !slot->face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3974
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3975
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3976
    library = FT_FACE_LIBRARY( slot->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3978
    return FT_Render_Glyph_Internal( library, slot, render_mode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3979
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3980
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3981
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3982
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3983
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3984
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3985
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3986
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3987
  /****                         M O D U L E S                           ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3988
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3989
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3990
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3991
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3992
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3993
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3994
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3995
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3996
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3997
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3998
  /*    Destroy_Module                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3999
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4000
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4001
  /*    Destroys a given module object.  For drivers, this also destroys   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4002
  /*    all child faces.                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4003
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4004
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4005
  /*     module :: A handle to the target driver object.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4006
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4007
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4008
  /*     The driver _must_ be LOCKED!                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4009
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4010
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4011
  Destroy_Module( FT_Module  module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4012
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4013
    FT_Memory         memory  = module->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4014
    FT_Module_Class*  clazz   = module->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4015
    FT_Library        library = module->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4018
    /* finalize client-data - before anything else */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4019
    if ( module->generic.finalizer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4020
      module->generic.finalizer( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4021
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4022
    if ( library && library->auto_hinter == module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4023
      library->auto_hinter = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4025
    /* if the module is a renderer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4026
    if ( FT_MODULE_IS_RENDERER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4027
      ft_remove_renderer( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4028
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4029
    /* if the module is a font driver, add some steps */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4030
    if ( FT_MODULE_IS_DRIVER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4031
      Destroy_Driver( FT_DRIVER( module ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4032
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4033
    /* finalize the module object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4034
    if ( clazz->module_done )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4035
      clazz->module_done( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4036
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4037
    /* discard it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4038
    FT_FREE( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4039
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4040
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4041
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4042
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4044
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4045
  FT_Add_Module( FT_Library              library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4046
                 const FT_Module_Class*  clazz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4047
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4048
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4049
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4050
    FT_Module  module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4051
    FT_UInt    nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4053
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4054
#define FREETYPE_VER_FIXED  ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4055
                                FREETYPE_MINOR                  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4056
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4057
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4058
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4059
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4060
    if ( !clazz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4061
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4062
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4063
    /* check freetype version */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4064
    if ( clazz->module_requires > FREETYPE_VER_FIXED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4065
      return FT_Err_Invalid_Version;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4066
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4067
    /* look for a module with the same name in the library's table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4068
    for ( nn = 0; nn < library->num_modules; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4069
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4070
      module = library->modules[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4071
      if ( ft_strcmp( module->clazz->module_name, clazz->module_name ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4072
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4073
        /* this installed module has the same name, compare their versions */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4074
        if ( clazz->module_version <= module->clazz->module_version )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4075
          return FT_Err_Lower_Module_Version;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4076
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4077
        /* remove the module from our list, then exit the loop to replace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4078
        /* it by our new version..                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4079
        FT_Remove_Module( library, module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4080
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4081
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4082
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4084
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4085
    error  = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4086
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4087
    if ( library->num_modules >= FT_MAX_MODULES )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4088
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4089
      error = FT_Err_Too_Many_Drivers;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4090
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4091
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4092
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4093
    /* allocate module object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4094
    if ( FT_ALLOC( module, clazz->module_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4095
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4096
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4097
    /* base initialization */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4098
    module->library = library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4099
    module->memory  = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4100
    module->clazz   = (FT_Module_Class*)clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4102
    /* check whether the module is a renderer - this must be performed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4103
    /* before the normal module initialization                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4104
    if ( FT_MODULE_IS_RENDERER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4105
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4106
      /* add to the renderers list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4107
      error = ft_add_renderer( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4108
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4109
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4110
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4112
    /* is the module a auto-hinter? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4113
    if ( FT_MODULE_IS_HINTER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4114
      library->auto_hinter = module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4115
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4116
    /* if the module is a font driver */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4117
    if ( FT_MODULE_IS_DRIVER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4118
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4119
      /* allocate glyph loader if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4120
      FT_Driver  driver = FT_DRIVER( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4123
      driver->clazz = (FT_Driver_Class)module->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4124
      if ( FT_DRIVER_USES_OUTLINES( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4125
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4126
        error = FT_GlyphLoader_New( memory, &driver->glyph_loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4127
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4128
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4129
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4130
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4132
    if ( clazz->module_init )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4133
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4134
      error = clazz->module_init( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4135
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4136
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4137
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4139
    /* add module to the library's table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4140
    library->modules[library->num_modules++] = module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4142
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4143
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4145
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4146
    if ( FT_MODULE_IS_DRIVER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4147
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4148
      FT_Driver  driver = FT_DRIVER( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4151
      if ( FT_DRIVER_USES_OUTLINES( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4152
        FT_GlyphLoader_Done( driver->glyph_loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4153
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4155
    if ( FT_MODULE_IS_RENDERER( module ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4156
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4157
      FT_Renderer  renderer = FT_RENDERER( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4160
      if ( renderer->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4161
           renderer->raster                                         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4162
        renderer->clazz->raster_class->raster_done( renderer->raster );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4163
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4165
    FT_FREE( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4166
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4167
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4170
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4172
  FT_EXPORT_DEF( FT_Module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4173
  FT_Get_Module( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4174
                 const char*  module_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4175
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4176
    FT_Module   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4177
    FT_Module*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4178
    FT_Module*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4181
    if ( !library || !module_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4182
      return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4184
    cur   = library->modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4185
    limit = cur + library->num_modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4187
    for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4188
      if ( ft_strcmp( cur[0]->clazz->module_name, module_name ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4189
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4190
        result = cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4191
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4192
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4194
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4195
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4198
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4200
  FT_BASE_DEF( const void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4201
  FT_Get_Module_Interface( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4202
                           const char*  mod_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4203
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4204
    FT_Module  module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4206
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4207
    /* test for valid `library' delayed to FT_Get_Module() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4209
    module = FT_Get_Module( library, mod_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4211
    return module ? module->clazz->module_interface : 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4212
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4215
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4216
  ft_module_get_service( FT_Module    module,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4217
                         const char*  service_id )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4218
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4219
    FT_Pointer  result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4221
    if ( module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4222
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4223
      FT_ASSERT( module->clazz && module->clazz->get_interface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4225
     /* first, look for the service in the module
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4226
      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4227
      if ( module->clazz->get_interface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4228
        result = module->clazz->get_interface( module, service_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4230
      if ( result == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4231
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4232
       /* we didn't find it, look in all other modules then
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4233
        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4234
        FT_Library  library = module->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4235
        FT_Module*  cur     = library->modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4236
        FT_Module*  limit   = cur + library->num_modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4238
        for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4239
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4240
          if ( cur[0] != module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4241
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4242
            FT_ASSERT( cur[0]->clazz );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4244
            if ( cur[0]->clazz->get_interface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4245
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4246
              result = cur[0]->clazz->get_interface( cur[0], service_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4247
              if ( result != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4248
                break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4249
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4250
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4251
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4252
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4253
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4255
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4256
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4259
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4261
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4262
  FT_Remove_Module( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4263
                    FT_Module   module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4264
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4265
    /* try to find the module from the table, then remove it from there */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4267
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4268
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4270
    if ( module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4271
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4272
      FT_Module*  cur   = library->modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4273
      FT_Module*  limit = cur + library->num_modules;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4276
      for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4277
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4278
        if ( cur[0] == module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4279
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4280
          /* remove it from the table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4281
          library->num_modules--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4282
          limit--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4283
          while ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4284
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4285
            cur[0] = cur[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4286
            cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4287
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4288
          limit[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4290
          /* destroy the module */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4291
          Destroy_Module( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4293
          return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4294
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4295
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4296
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4297
    return FT_Err_Invalid_Driver_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4298
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4301
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4302
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4303
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4304
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4305
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4306
  /****                         L I B R A R Y                           ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4307
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4308
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4309
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4310
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4311
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4314
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4316
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4317
  FT_Reference_Library( FT_Library  library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4318
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4319
    library->refcount++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4321
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4322
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4325
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4327
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4328
  FT_New_Library( FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4329
                  FT_Library  *alibrary )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4330
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4331
    FT_Library  library = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4332
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4335
    if ( !memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4336
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4338
#ifdef FT_DEBUG_LEVEL_ERROR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4339
    /* init debugging support */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4340
    ft_debug_init();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4341
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4343
    /* first of all, allocate the library object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4344
    if ( FT_NEW( library ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4345
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4347
    library->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4349
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4350
    /* initialize position independent code containers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4351
    error = ft_pic_container_init( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4352
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4353
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4354
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4356
    /* allocate the render pool */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4357
    library->raster_pool_size = FT_RENDER_POOL_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4358
#if FT_RENDER_POOL_SIZE > 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4359
    if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4360
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4361
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4363
    library->version_major = FREETYPE_MAJOR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4364
    library->version_minor = FREETYPE_MINOR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4365
    library->version_patch = FREETYPE_PATCH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4367
    library->refcount = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4369
    /* That's ok now */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4370
    *alibrary = library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4372
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4374
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4375
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4376
    ft_pic_container_destroy( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4377
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4378
    FT_FREE( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4379
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4380
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4383
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4385
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4386
  FT_Library_Version( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4387
                      FT_Int      *amajor,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4388
                      FT_Int      *aminor,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4389
                      FT_Int      *apatch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4390
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4391
    FT_Int  major = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4392
    FT_Int  minor = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4393
    FT_Int  patch = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4396
    if ( library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4397
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4398
      major = library->version_major;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4399
      minor = library->version_minor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4400
      patch = library->version_patch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4401
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4403
    if ( amajor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4404
      *amajor = major;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4406
    if ( aminor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4407
      *aminor = minor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4409
    if ( apatch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4410
      *apatch = patch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4411
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4414
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4416
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4417
  FT_Done_Library( FT_Library  library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4418
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4419
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4422
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4423
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4425
    library->refcount--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4426
    if ( library->refcount > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4427
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4429
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4431
    /* Discard client-data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4432
    if ( library->generic.finalizer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4433
      library->generic.finalizer( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4435
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4436
     * Close all faces in the library.  If we don't do this, we can have
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4437
     * some subtle memory leaks.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4438
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4439
     * Example:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4440
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4441
     *  - the cff font driver uses the pshinter module in cff_size_done
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4442
     *  - if the pshinter module is destroyed before the cff font driver,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4443
     *    opened FT_Face objects managed by the driver are not properly
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4444
     *    destroyed, resulting in a memory leak
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4445
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4446
     * Some faces are dependent on other faces, like Type42 faces that
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4447
     * depend on TrueType faces synthesized internally.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4448
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4449
     * The order of drivers should be specified in driver_name[].
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4450
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4451
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4452
      FT_UInt      m, n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4453
      const char*  driver_name[] = { "type42", NULL };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4456
      for ( m = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4457
            m < sizeof ( driver_name ) / sizeof ( driver_name[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4458
            m++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4459
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4460
        for ( n = 0; n < library->num_modules; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4461
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4462
          FT_Module    module      = library->modules[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4463
          const char*  module_name = module->clazz->module_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4464
          FT_List      faces;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4467
          if ( driver_name[m]                                &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4468
               ft_strcmp( module_name, driver_name[m] ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4469
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4471
          if ( ( module->clazz->module_flags & FT_MODULE_FONT_DRIVER ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4472
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4474
          FT_TRACE7(( "FT_Done_Library: close faces for %s\n", module_name ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4476
          faces = &FT_DRIVER( module )->faces_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4477
          while ( faces->head )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4478
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4479
            FT_Done_Face( FT_FACE( faces->head->data ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4480
            if ( faces->head )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4481
              FT_TRACE0(( "FT_Done_Library: failed to free some faces\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4482
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4483
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4484
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4485
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4487
    /* Close all other modules in the library */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4488
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4489
    /* XXX Modules are removed in the reversed order so that  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4490
    /* type42 module is removed before truetype module.  This */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4491
    /* avoids double free in some occasions.  It is a hack.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4492
    while ( library->num_modules > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4493
      FT_Remove_Module( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4494
                        library->modules[library->num_modules - 1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4495
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4496
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4497
      FT_UInt  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4500
      for ( n = 0; n < library->num_modules; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4501
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4502
        FT_Module  module = library->modules[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4505
        if ( module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4506
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4507
          Destroy_Module( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4508
          library->modules[n] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4509
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4510
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4511
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4512
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4514
    /* Destroy raster objects */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4515
    FT_FREE( library->raster_pool );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4516
    library->raster_pool_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4518
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4519
    /* Destroy pic container contents */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4520
    ft_pic_container_destroy( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4521
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4523
    FT_FREE( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4525
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4526
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4527
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4530
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4532
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4533
  FT_Set_Debug_Hook( FT_Library         library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4534
                     FT_UInt            hook_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4535
                     FT_DebugHook_Func  debug_hook )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4536
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4537
    if ( library && debug_hook &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4538
         hook_index <
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4539
           ( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4540
      library->debug_hooks[hook_index] = debug_hook;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4541
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4542
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4544
  /* documentation is in ftmodapi.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4546
  FT_EXPORT_DEF( FT_TrueTypeEngineType )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4547
  FT_Get_TrueType_Engine_Type( FT_Library  library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4548
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4549
    FT_TrueTypeEngineType  result = FT_TRUETYPE_ENGINE_TYPE_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4552
    if ( library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4553
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4554
      FT_Module  module = FT_Get_Module( library, "truetype" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4557
      if ( module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4558
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4559
        FT_Service_TrueTypeEngine  service;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4562
        service = (FT_Service_TrueTypeEngine)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4563
                    ft_module_get_service( module,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4564
                                           FT_SERVICE_ID_TRUETYPE_ENGINE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4565
        if ( service )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4566
          result = service->engine_type;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4567
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4568
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4570
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4571
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4574
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4576
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4577
  ft_stub_set_char_sizes( FT_Size     size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4578
                          FT_F26Dot6  width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4579
                          FT_F26Dot6  height,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4580
                          FT_UInt     horz_res,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4581
                          FT_UInt     vert_res )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4582
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4583
    FT_Size_RequestRec  req;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4584
    FT_Driver           driver = size->face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4586
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4587
    if ( driver->clazz->request_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4588
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4589
      req.type   = FT_SIZE_REQUEST_TYPE_NOMINAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4590
      req.width  = width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4591
      req.height = height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4593
      if ( horz_res == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4594
        horz_res = vert_res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4595
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4596
      if ( vert_res == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4597
        vert_res = horz_res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4599
      if ( horz_res == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4600
        horz_res = vert_res = 72;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4602
      req.horiResolution = horz_res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4603
      req.vertResolution = vert_res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4605
      return driver->clazz->request_size( size, &req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4606
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4607
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4608
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4609
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4612
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4613
  ft_stub_set_pixel_sizes( FT_Size  size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4614
                           FT_UInt  width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4615
                           FT_UInt  height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4616
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4617
    FT_Size_RequestRec  req;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4618
    FT_Driver           driver = size->face->driver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4621
    if ( driver->clazz->request_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4622
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4623
      req.type           = FT_SIZE_REQUEST_TYPE_NOMINAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4624
      req.width          = width  << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4625
      req.height         = height << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4626
      req.horiResolution = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4627
      req.vertResolution = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4629
      return driver->clazz->request_size( size, &req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4630
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4631
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4632
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4633
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4635
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4638
  /* documentation is in freetype.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4640
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4641
  FT_Get_SubGlyph_Info( FT_GlyphSlot  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4642
                        FT_UInt       sub_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4643
                        FT_Int       *p_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4644
                        FT_UInt      *p_flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4645
                        FT_Int       *p_arg1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4646
                        FT_Int       *p_arg2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4647
                        FT_Matrix    *p_transform )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4648
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4649
    FT_Error  error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4651
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4652
    if ( glyph                                      &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4653
         glyph->subglyphs                           &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4654
         glyph->format == FT_GLYPH_FORMAT_COMPOSITE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4655
         sub_index < glyph->num_subglyphs           )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4656
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4657
      FT_SubGlyph  subg = glyph->subglyphs + sub_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4658
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4660
      *p_index     = subg->index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4661
      *p_flags     = subg->flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4662
      *p_arg1      = subg->arg1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4663
      *p_arg2      = subg->arg2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4664
      *p_transform = subg->transform;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4665
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4667
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4668
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4670
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  4671
/* END */