misc/libfreetype/src/base/ftadvanc.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
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
/*  ftadvanc.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
/*    Quick computation of advance widths (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 2008, 2009 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_ADVANCES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  _ft_face_scale_advances( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
                           FT_Fixed*  advances,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
                           FT_UInt    count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
                           FT_Int32   flags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
    FT_Fixed  scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
    FT_UInt   nn;
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
    if ( flags & FT_LOAD_NO_SCALE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
      return FT_Err_Ok;
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 ( face->size == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
      return FT_Err_Invalid_Size_Handle;
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
    if ( flags & FT_LOAD_VERTICAL_LAYOUT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
      scale = face->size->metrics.y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
      scale = face->size->metrics.x_scale;
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
    /* this must be the same scaling as to get linear{Hori,Vert}Advance */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    /* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c)        */
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
    for ( nn = 0; nn < count; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
      advances[nn] = FT_MulDiv( advances[nn], scale, 64 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
   /* at the moment, we can perform fast advance retrieval only in */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
   /* the following cases:                                         */
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
   /*  - unscaled load                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
   /*  - unhinted load                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
   /*  - light-hinted load                                         */
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
#define LOAD_ADVANCE_FAST_CHECK( flags )                            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
          ( flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING )    || \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
            FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_LIGHT )
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
  /* documentation is in ftadvanc.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  FT_Get_Advance( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                  FT_UInt    gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
                  FT_Int32   flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
                  FT_Fixed  *padvance )
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
    FT_Face_GetAdvancesFunc  func;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      return FT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    if ( gindex >= (FT_UInt)face->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      return FT_Err_Invalid_Glyph_Index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    func = face->driver->clazz->get_advances;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) )
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
      FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      error = func( face, gindex, 1, flags, padvance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
        return _ft_face_scale_advances( face, padvance, 1, flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    return FT_Get_Advances( face, gindex, 1, flags, padvance );
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
  /* documentation is in ftadvanc.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  FT_Get_Advances( FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
                   FT_UInt    start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
                   FT_UInt    count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
                   FT_Int32   flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
                   FT_Fixed  *padvances )
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
    FT_Face_GetAdvancesFunc  func;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    FT_UInt                  num, end, nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    FT_Error                 error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      return FT_Err_Invalid_Face_Handle;
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
    num = (FT_UInt)face->num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    end = start + count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    if ( start >= num || end < start || end > num )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      return FT_Err_Invalid_Glyph_Index;
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
    if ( count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    func = face->driver->clazz->get_advances;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) )
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
      error = func( face, start, count, flags, padvances );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
        goto Exit;
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
      if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      return FT_Err_Unimplemented_Feature;
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
    flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    for ( nn = 0; nn < count; nn++ )
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
      error = FT_Load_Glyph( face, start + nn, flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
        break;
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
      padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
                      ? face->glyph->advance.y
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
                      : face->glyph->advance.x;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    return _ft_face_scale_advances( face, padvances, count, flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  }
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 */