misc/libfreetype/src/cache/ftcimage.c
author belphegorr <szabibibi@gmail.com>
Mon, 23 Jul 2012 19:15:59 +0300
changeset 7263 644eabbc9218
parent 5172 88f2e05288ba
permissions -rw-r--r--
Added a new function: AddNewEvent, which only adds an event to the list if it doesn't already exist. Kept the old one as it might me useful to be able to add an event more than once.
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
/*  ftcimage.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 Image cache (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, 2003, 2004, 2006, 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 "ftcimage.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_MEMORY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "ftccback.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "ftcerror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /* finalize a given glyph image node */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  ftc_inode_free( FTC_Node   ftcinode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
                  FTC_Cache  cache )
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
    FTC_INode  inode = (FTC_INode)ftcinode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
    FT_Memory  memory = cache->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
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
    if ( inode->glyph )
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
      FT_Done_Glyph( inode->glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
      inode->glyph = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    FTC_GNode_Done( FTC_GNODE( inode ), cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    FT_FREE( inode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  FTC_INode_Free( FTC_INode  inode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
                  FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    ftc_inode_free( FTC_NODE( inode ), cache );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /* initialize a new glyph image node */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  FTC_INode_New( FTC_INode   *pinode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
                 FTC_GQuery   gquery,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
                 FTC_Cache    cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    FT_Memory  memory = cache->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    FTC_INode  inode  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    if ( !FT_NEW( inode ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
      FTC_GNode         gnode  = FTC_GNODE( inode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
      FTC_Family        family = gquery->family;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
      FT_UInt           gindex = gquery->gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      FTC_IFamilyClass  clazz  = FTC_CACHE__IFAMILY_CLASS( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
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
      /* initialize its inner fields */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
      FTC_GNode_Init( gnode, gindex, family );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
      /* we will now load the glyph image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      error = clazz->family_load_glyph( family, gindex, cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
                                        &inode->glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      if ( error )
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_INode_Free( inode, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
        inode = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    }
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
    *pinode = inode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  ftc_inode_new( FTC_Node   *ftcpinode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
                 FT_Pointer  ftcgquery,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
                 FTC_Cache   cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    FTC_INode  *pinode = (FTC_INode*)ftcpinode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    FTC_GQuery  gquery = (FTC_GQuery)ftcgquery;
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
    return FTC_INode_New( pinode, gquery, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  FT_LOCAL_DEF( FT_Offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  ftc_inode_weight( FTC_Node   ftcinode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
                    FTC_Cache  ftccache )
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
    FTC_INode  inode = (FTC_INode)ftcinode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    FT_Offset  size  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    FT_Glyph   glyph = inode->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    FT_UNUSED( ftccache );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    switch ( glyph->format )
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
    case FT_GLYPH_FORMAT_BITMAP:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        FT_BitmapGlyph  bitg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
        bitg = (FT_BitmapGlyph)glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
        size = bitg->bitmap.rows * ft_labs( bitg->bitmap.pitch ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
               sizeof ( *bitg );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      break;
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
    case FT_GLYPH_FORMAT_OUTLINE:
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
        FT_OutlineGlyph  outg;
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
        outg = (FT_OutlineGlyph)glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
        size = outg->outline.n_points *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
                 ( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
               outg->outline.n_contours * sizeof ( FT_Short ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
               sizeof ( *outg );
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
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    default:
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    size += sizeof ( *inode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    return size;
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
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
#if 0
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_LOCAL_DEF( FT_Offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  FTC_INode_Weight( FTC_INode  inode )
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
    return ftc_inode_weight( FTC_NODE( inode ), NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
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
/* END */