misc/libfreetype/src/cache/ftcmanag.c
author Xeli
Sat, 12 Nov 2011 14:50:35 +0100
branchhedgeroid
changeset 6232 cf4b0f43d64d
parent 5172 88f2e05288ba
permissions -rw-r--r--
removed sdl_net which was 'borrowed' (?:P) from peyla's port we'll now be using the official port
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
/*  ftcmanag.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
/*    FreeType Cache Manager (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 2000-2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 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_CACHE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include "ftcmanag.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_SIZES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include "ftccback.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "ftcerror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#error "cache system does not support PIC yet"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#endif 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#define FT_COMPONENT  trace_cache
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#define FTC_LRU_GET_MANAGER( lru )  ( (FTC_Manager)(lru)->user_data )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  ftc_scaler_lookup_size( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
                          FTC_Scaler   scaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                          FT_Size     *asize )
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
    FT_Face   face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_Size   size = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
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
    error = FTC_Manager_LookupFace( manager, scaler->face_id, &face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
      goto Exit;
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
    error = FT_New_Size( face, &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
      goto Exit;
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
    FT_Activate_Size( size );
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
    if ( scaler->pixel )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
      error = FT_Set_Pixel_Sizes( face, scaler->width, scaler->height );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
      error = FT_Set_Char_Size( face, scaler->width, scaler->height,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
                                scaler->x_res, scaler->y_res );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
      FT_Done_Size( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
      size = NULL;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    *asize = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  typedef struct  FTC_SizeNodeRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    FTC_MruNodeRec  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    FT_Size         size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    FTC_ScalerRec   scaler;
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
  } FTC_SizeNodeRec, *FTC_SizeNode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
#define FTC_SIZE_NODE( x ) ( (FTC_SizeNode)( x ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  ftc_size_node_done( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
                      FT_Pointer   data )
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
    FTC_SizeNode  node = (FTC_SizeNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    FT_Size       size = node->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    FT_UNUSED( data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
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
    if ( size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      FT_Done_Size( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
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
  FT_CALLBACK_DEF( FT_Bool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  ftc_size_node_compare( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
                         FT_Pointer   ftcscaler )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    FTC_SizeNode  node    = (FTC_SizeNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    FTC_Scaler    scaler  = (FTC_Scaler)ftcscaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    FTC_Scaler    scaler0 = &node->scaler;
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
    if ( FTC_SCALER_COMPARE( scaler0, scaler ) )
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
      FT_Activate_Size( node->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      return 1;
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
    return 0;
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  ftc_size_node_init( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
                      FT_Pointer   ftcscaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
                      FT_Pointer   ftcmanager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    FTC_SizeNode  node    = (FTC_SizeNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    FTC_Scaler    scaler  = (FTC_Scaler)ftcscaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    FTC_Manager   manager = (FTC_Manager)ftcmanager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    node->scaler = scaler[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    return ftc_scaler_lookup_size( manager, scaler, &node->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
  }
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
  ftc_size_node_reset( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
                       FT_Pointer   ftcscaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
                       FT_Pointer   ftcmanager )
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
    FTC_SizeNode  node    = (FTC_SizeNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    FTC_Scaler    scaler  = (FTC_Scaler)ftcscaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    FTC_Manager   manager = (FTC_Manager)ftcmanager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
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
    FT_Done_Size( node->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    node->scaler = scaler[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    return ftc_scaler_lookup_size( manager, scaler, &node->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  FT_CALLBACK_TABLE_DEF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  const FTC_MruListClassRec  ftc_size_list_class =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    sizeof ( FTC_SizeNodeRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    ftc_size_node_compare,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    ftc_size_node_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    ftc_size_node_reset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    ftc_size_node_done
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  };
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  /* helper function used by ftc_face_node_done */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  ftc_size_node_compare_faceid( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
                                FT_Pointer   ftcface_id )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    FTC_SizeNode  node    = (FTC_SizeNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    FTC_FaceID    face_id = (FTC_FaceID)ftcface_id;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    return FT_BOOL( node->scaler.face_id == face_id );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
  /* documentation is in ftcache.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  FTC_Manager_LookupSize( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
                          FTC_Scaler   scaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
                          FT_Size     *asize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    FTC_MruNode  mrunode;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    if ( asize == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
      return FTC_Err_Invalid_Argument;
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
    *asize = NULL;
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
    if ( !manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      return FTC_Err_Invalid_Cache_Handle;
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
#ifdef FTC_INLINE
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
    FTC_MRULIST_LOOKUP_CMP( &manager->sizes, scaler, ftc_size_node_compare,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
                            mrunode, error );
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
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    error = FTC_MruList_Lookup( &manager->sizes, scaler, &mrunode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
#endif
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
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      *asize = FTC_SIZE_NODE( mrunode )->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
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
  /*****                    FACE MRU IMPLEMENTATION                    *****/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
  typedef struct  FTC_FaceNodeRec_
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
    FTC_MruNodeRec  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
    FTC_FaceID      face_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    FT_Face         face;
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
  } FTC_FaceNodeRec, *FTC_FaceNode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
#define FTC_FACE_NODE( x ) ( ( FTC_FaceNode )( x ) )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  ftc_face_node_init( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
                      FT_Pointer   ftcface_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
                      FT_Pointer   ftcmanager )
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
    FTC_FaceNode  node    = (FTC_FaceNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    FTC_FaceID    face_id = (FTC_FaceID)ftcface_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    FTC_Manager   manager = (FTC_Manager)ftcmanager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
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
    node->face_id = face_id;
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
    error = manager->request_face( face_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
                                   manager->library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
                                   manager->request_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
                                   &node->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    if ( !error )
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
      /* destroy initial size object; it will be re-created later */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
      if ( node->face->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
        FT_Done_Size( node->face->size );
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
  ftc_face_node_done( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
                      FT_Pointer   ftcmanager )
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
    FTC_FaceNode  node    = (FTC_FaceNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    FTC_Manager   manager = (FTC_Manager)ftcmanager;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    /* we must begin by removing all scalers for the target face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    /* from the manager's list                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    FTC_MruList_RemoveSelection( &manager->sizes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
                                 ftc_size_node_compare_faceid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
                                 node->face_id );
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
    /* all right, we can discard the face now */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    FT_Done_Face( node->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    node->face    = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    node->face_id = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
  FT_CALLBACK_DEF( FT_Bool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
  ftc_face_node_compare( FTC_MruNode  ftcnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
                         FT_Pointer   ftcface_id )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    FTC_FaceNode  node    = (FTC_FaceNode)ftcnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    FTC_FaceID    face_id = (FTC_FaceID)ftcface_id;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    return FT_BOOL( node->face_id == face_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
  FT_CALLBACK_TABLE_DEF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
  const FTC_MruListClassRec  ftc_face_list_class =
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
    sizeof ( FTC_FaceNodeRec),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    ftc_face_node_compare,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    ftc_face_node_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    0,                          /* FTC_MruNode_ResetFunc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    ftc_face_node_done
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
  };
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
  /* documentation is in ftcache.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
  FTC_Manager_LookupFace( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
                          FTC_FaceID   face_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
                          FT_Face     *aface )
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
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    FTC_MruNode  mrunode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
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
    if ( aface == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      return FTC_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    *aface = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    if ( !manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
      return FTC_Err_Invalid_Cache_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    /* we break encapsulation for the sake of speed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
#ifdef FTC_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    FTC_MRULIST_LOOKUP_CMP( &manager->faces, face_id, ftc_face_node_compare,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
                            mrunode, error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    error = FTC_MruList_Lookup( &manager->faces, face_id, &mrunode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      *aface = FTC_FACE_NODE( mrunode )->face;
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
  /*****                    CACHE MANAGER ROUTINES                     *****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
  /* documentation is in ftcache.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
  FTC_Manager_New( FT_Library          library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
                   FT_UInt             max_faces,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
                   FT_UInt             max_sizes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
                   FT_ULong            max_bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
                   FTC_Face_Requester  requester,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
                   FT_Pointer          req_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
                   FTC_Manager        *amanager )
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
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    FTC_Manager  manager = 0;
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
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      return FTC_Err_Invalid_Library_Handle;
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
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    if ( FT_NEW( manager ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    if ( max_faces == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      max_faces = FTC_MAX_FACES_DEFAULT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    if ( max_sizes == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
      max_sizes = FTC_MAX_SIZES_DEFAULT;
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 ( max_bytes == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      max_bytes = FTC_MAX_BYTES_DEFAULT;
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
    manager->library      = library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    manager->memory       = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    manager->max_weight   = max_bytes;
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
    manager->request_face = requester;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    manager->request_data = req_data;
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
    FTC_MruList_Init( &manager->faces,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
                      &ftc_face_list_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
                      max_faces,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
                      manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
                      memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    FTC_MruList_Init( &manager->sizes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
                      &ftc_size_list_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
                      max_sizes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
                      manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
                      memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    *amanager = manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
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
  /* documentation is in ftcache.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
  FTC_Manager_Done( FTC_Manager  manager )
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
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    FT_UInt    idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
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
    if ( !manager || !manager->library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      return;
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
    memory = manager->memory;
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
    /* now discard all caches */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    for (idx = manager->num_caches; idx-- > 0; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      FTC_Cache  cache = manager->caches[idx];
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
      if ( cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        cache->clazz.cache_done( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        FT_FREE( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        manager->caches[idx] = NULL;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    manager->num_caches = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    /* discard faces and sizes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
    FTC_MruList_Done( &manager->sizes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
    FTC_MruList_Done( &manager->faces );
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
    manager->library = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    manager->memory  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    FT_FREE( manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
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
  /* documentation is in ftcache.h */
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
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
  FTC_Manager_Reset( FTC_Manager  manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
    if ( manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      FTC_MruList_Reset( &manager->sizes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
      FTC_MruList_Reset( &manager->faces );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    /* XXX: FIXME: flush the caches? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
  }
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
#ifdef FT_DEBUG_ERROR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
  FTC_Manager_Check( FTC_Manager  manager )
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
    FTC_Node  node, first;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    first = manager->nodes_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    /* check node weights */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    if ( first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      FT_ULong  weight = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
      node = first;
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
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
        FTC_Cache  cache = manager->caches[node->cache_index];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
        if ( (FT_UInt)node->cache_index >= manager->num_caches )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
          FT_TRACE0(( "FTC_Manager_Check: invalid node (cache index = %ld\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
                      node->cache_index ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
          weight += cache->clazz.node_weight( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
        node = FTC_NODE__NEXT( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
      } while ( node != first );
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
      if ( weight != manager->cur_weight )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
        FT_TRACE0(( "FTC_Manager_Check: invalid weight %ld instead of %ld\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
                    manager->cur_weight, weight ));
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
    /* check circular list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    if ( first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
      FT_UFast  count = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      node = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
        count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
        node = FTC_NODE__NEXT( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      } while ( node != first );
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 ( count != manager->num_nodes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
        FT_TRACE0(( "FTC_Manager_Check:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
                    " invalid cache node count %d instead of %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
                    manager->num_nodes, count ));
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
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
#endif /* FT_DEBUG_ERROR */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
  /* `Compress' the manager's data, i.e., get rid of old cache nodes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
  /* that are not referenced anymore in order to limit the total     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
  /* memory used by the cache.                                       */
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
  /* documentation is in ftcmanag.h */
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
  FTC_Manager_Compress( FTC_Manager  manager )
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
    FTC_Node   node, first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
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
    if ( !manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
      return;
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
    first = manager->nodes_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
#ifdef FT_DEBUG_ERROR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    FTC_Manager_Check( manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    FT_TRACE0(( "compressing, weight = %ld, max = %ld, nodes = %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
                manager->cur_weight, manager->max_weight,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
                manager->num_nodes ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
#endif
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
    if ( manager->cur_weight < manager->max_weight || first == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    /* go to last node -- it's a circular list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
    node = FTC_NODE__PREV( first );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    do
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
      FTC_Node  prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      prev = ( node == first ) ? NULL : FTC_NODE__PREV( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
      if ( node->ref_count <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
        ftc_node_destroy( node, manager );
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
      node = prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    } while ( node && manager->cur_weight > manager->max_weight );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
  /* documentation is in ftcmanag.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
  FTC_Manager_RegisterCache( FTC_Manager      manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
                             FTC_CacheClass   clazz,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
                             FTC_Cache       *acache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
    FT_Error   error = FTC_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    FTC_Cache  cache = NULL;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
    if ( manager && clazz && acache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
      FT_Memory  memory = manager->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
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
      if ( manager->num_caches >= FTC_MAX_CACHES )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
        error = FTC_Err_Too_Many_Caches;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
        FT_ERROR(( "FTC_Manager_RegisterCache:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
                   " too many registered caches\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      if ( !FT_ALLOC( cache, clazz->cache_size ) )
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
        cache->manager   = manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
        cache->memory    = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
        cache->clazz     = clazz[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
        cache->org_class = clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
        /* THIS IS VERY IMPORTANT!  IT WILL WRETCH THE MANAGER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
        /* IF IT IS NOT SET CORRECTLY                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
        cache->index = manager->num_caches;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
        error = clazz->cache_init( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
          clazz->cache_done( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
          FT_FREE( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
        manager->caches[manager->num_caches++] = cache;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
    if ( acache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
      *acache = cache;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
  FT_LOCAL_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
  FTC_Manager_FlushN( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
                      FT_UInt      count )
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
    FTC_Node  first = manager->nodes_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
    FTC_Node  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    FT_UInt   result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    /* try to remove `count' nodes from the list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    if ( first == NULL )  /* empty list! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    /* go to last node - it's a circular list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    node = FTC_NODE__PREV(first);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    for ( result = 0; result < count; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
      FTC_Node  prev = FTC_NODE__PREV( node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
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
      /* don't touch locked nodes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
      if ( node->ref_count <= 0 )
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
        ftc_node_destroy( node, manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        result++;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
      if ( node == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
      node = prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
    return  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
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
  /* documentation is in ftcache.h */
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_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  FTC_Manager_RemoveFaceID( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
                            FTC_FaceID   face_id )
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
    FT_UInt  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
    /* this will remove all FTC_SizeNode that correspond to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
     * the face_id as well
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    FTC_MruList_RemoveSelection( &manager->faces,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
                                 ftc_face_node_compare,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
                                 face_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    for ( nn = 0; nn < manager->num_caches; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
      FTC_Cache_RemoveFaceID( manager->caches[nn], face_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
  }
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
  /* documentation is in ftcache.h */
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
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
  FTC_Node_Unref( FTC_Node     node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
                  FTC_Manager  manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    if ( node && (FT_UInt)node->cache_index < manager->num_caches )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
      node->ref_count--;
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
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
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
  FTC_Manager_Lookup_Face( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
                           FTC_FaceID   face_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
                           FT_Face     *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    return FTC_Manager_LookupFace( manager, face_id, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
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
  FT_EXPORT( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
  FTC_Manager_Lookup_Size( FTC_Manager  manager,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
                           FTC_Font     font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
                           FT_Face     *aface,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
                           FT_Size     *asize )
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
    FTC_ScalerRec  scaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
    FT_Size        size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    FT_Face        face;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
    scaler.face_id = font->face_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
    scaler.width   = font->pix_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    scaler.height  = font->pix_height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
    scaler.pixel   = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    scaler.x_res   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    scaler.y_res   = 0;
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
    error = FTC_Manager_LookupSize( manager, &scaler, &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
    if ( error )
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
      face = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
      size = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
      face = size->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    if ( aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
      *aface = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    if ( asize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
      *asize = size;
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
/* END */