misc/libfreetype/src/sfnt/ttmtx.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
/*  ttmtx.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
/*    Load the metrics tables common to TTF and OTF fonts (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 2006-2009, 2011 by                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include "ttmtx.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "sferrors.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
  /*************************************************************************/
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
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* messages during execution.                                            */
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_ttmtx
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
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
   *  Unfortunately, we can't enable our memory optimizations if
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
   *  FT_CONFIG_OPTION_OLD_INTERNALS is defined.  This is because at least
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
   *  one rogue client (libXfont in the X.Org XServer) is directly accessing
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
   *  the metrics.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /*    tt_face_load_hmtx                                                  */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /*    Load the `hmtx' or `vmtx' table into a face object.                */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /*    face     :: A handle to the target face object.                    */
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
  /*    stream   :: The input stream.                                      */
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
  /*    vertical :: A boolean flag.  If set, load `vmtx'.                  */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  tt_face_load_hmtx( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
                     FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
                     FT_Bool    vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    FT_ULong   tag, table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    FT_ULong*  ptable_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    FT_ULong*  ptable_size;
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
    if ( vertical )
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
      tag           = TTAG_vmtx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      ptable_offset = &face->vert_metrics_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
      ptable_size   = &face->vert_metrics_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    else
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
      tag           = TTAG_hmtx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      ptable_offset = &face->horz_metrics_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      ptable_size   = &face->horz_metrics_size;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    error = face->goto_table( face, tag, stream, &table_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      goto Fail;
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
    *ptable_size   = table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    *ptable_offset = FT_STREAM_POS();
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  }
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
#else /* !FT_CONFIG_OPTION_OLD_INTERNALS */
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_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  tt_face_load_hmtx( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
                     FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
                     FT_Bool    vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    FT_Memory  memory = stream->memory;
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
    FT_ULong   table_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    FT_Long    num_shorts, num_longs, num_shorts_checked;
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
    TT_LongMetrics*    longs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    TT_ShortMetrics**  shorts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    FT_Byte*           p;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    if ( vertical )
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
      void*   lm = &face->vertical.long_metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      void**  sm = &face->vertical.short_metrics;
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
      error = face->goto_table( face, TTAG_vmtx, stream, &table_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
        goto Fail;
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
      num_longs = face->vertical.number_Of_VMetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
      if ( (FT_ULong)num_longs > table_len / 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
        num_longs = (FT_Long)( table_len / 4 );
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
      face->vertical.number_Of_VMetrics = 0;
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
      longs  = (TT_LongMetrics*)lm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      shorts = (TT_ShortMetrics**)sm;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      void*   lm = &face->horizontal.long_metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
      void**  sm = &face->horizontal.short_metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
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
      error = face->goto_table( face, TTAG_hmtx, stream, &table_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        goto Fail;
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
      num_longs = face->horizontal.number_Of_HMetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
      if ( (FT_ULong)num_longs > table_len / 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
        num_longs = (FT_Long)( table_len / 4 );
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
      face->horizontal.number_Of_HMetrics = 0;
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
      longs  = (TT_LongMetrics*)lm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      shorts = (TT_ShortMetrics**)sm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    }
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
    /* never trust derived values */
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
    num_shorts         = face->max_profile.numGlyphs - num_longs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    num_shorts_checked = ( table_len - num_longs * 4L ) / 2;
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
    if ( num_shorts < 0 )
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
      FT_TRACE0(( "tt_face_load_hmtx:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
                  " %cmtx has more metrics than glyphs.\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
                  vertical ? 'v' : 'h' ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      /* Adobe simply ignores this problem.  So we shall do the same. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      error = vertical ? SFNT_Err_Invalid_Vert_Metrics
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
                       : SFNT_Err_Invalid_Horiz_Metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      num_shorts = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
#endif
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
    if ( FT_QNEW_ARRAY( *longs,  num_longs  ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
         FT_QNEW_ARRAY( *shorts, num_shorts ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    if ( FT_FRAME_ENTER( table_len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
      goto Fail;
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
    p = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
      TT_LongMetrics  cur   = *longs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
      TT_LongMetrics  limit = cur + num_longs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
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
      for ( ; cur < limit; cur++ )
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
        cur->advance = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        cur->bearing = FT_NEXT_SHORT( p );
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
    }
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
    /* do we have an inconsistent number of metric values? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      TT_ShortMetrics*  cur   = *shorts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      TT_ShortMetrics*  limit = cur +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
                                FT_MIN( num_shorts, num_shorts_checked );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        *cur = FT_NEXT_SHORT( p );
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
      /* We fill up the missing left side bearings with the     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      /* last valid value.  Since this will occur for buggy CJK */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      /* fonts usually only, nothing serious will happen.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      if ( num_shorts > num_shorts_checked && num_shorts_checked > 0 )
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
        FT_Short  val = (*shorts)[num_shorts_checked - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
        limit = *shorts + num_shorts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
        for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
          *cur = val;
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
    }
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
    FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    if ( vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      face->vertical.number_Of_VMetrics = (FT_UShort)num_longs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
      face->horizontal.number_Of_HMetrics = (FT_UShort)num_longs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
#endif /* !FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  /*    tt_face_load_hhea                                                  */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  /*    Load the `hhea' or 'vhea' table into a face object.                */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  /*    face     :: A handle to the target face object.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  /*    stream   :: The input stream.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
  /*    vertical :: A boolean flag.  If set, load `vhea'.                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
  /*    FreeType error code.  0 means success.                             */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  tt_face_load_hhea( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
                     FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
                     FT_Bool    vertical )
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_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    TT_HoriHeader*  header;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    const FT_Frame_Field  metrics_header_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
#define FT_STRUCTURE  TT_HoriHeader
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
      FT_FRAME_START( 36 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
        FT_FRAME_ULONG ( Version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
        FT_FRAME_SHORT ( Ascender ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
        FT_FRAME_SHORT ( Descender ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
        FT_FRAME_SHORT ( Line_Gap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
        FT_FRAME_USHORT( advance_Width_Max ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
        FT_FRAME_SHORT ( min_Left_Side_Bearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        FT_FRAME_SHORT ( min_Right_Side_Bearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        FT_FRAME_SHORT ( xMax_Extent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
        FT_FRAME_SHORT ( caret_Slope_Rise ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
        FT_FRAME_SHORT ( caret_Slope_Run ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
        FT_FRAME_SHORT ( caret_Offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
        FT_FRAME_SHORT ( Reserved[0] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
        FT_FRAME_SHORT ( Reserved[1] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
        FT_FRAME_SHORT ( Reserved[2] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
        FT_FRAME_SHORT ( Reserved[3] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
        FT_FRAME_SHORT ( metric_Data_Format ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
        FT_FRAME_USHORT( number_Of_HMetrics ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
      FT_FRAME_END
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    if ( vertical )
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
      void  *v = &face->vertical;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      error = face->goto_table( face, TTAG_vhea, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      header = (TT_HoriHeader*)v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    else
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
      error = face->goto_table( face, TTAG_hhea, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
        goto Fail;
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
      header = &face->horizontal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    if ( FT_STREAM_READ_FIELDS( metrics_header_fields, header ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    FT_TRACE3(( "Ascender:          %5d\n", header->Ascender ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    FT_TRACE3(( "Descender:         %5d\n", header->Descender ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    FT_TRACE3(( "number_Of_Metrics: %5u\n", header->number_Of_HMetrics ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    header->long_metrics  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    header->short_metrics = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
  /*    tt_face_get_metrics                                                */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
  /*    Returns the horizontal or vertical metrics in font units for a     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  /*    given glyph.  The metrics are the left side bearing (resp. top     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  /*    side bearing) and advance width (resp. advance height).            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
  /*    header  :: A pointer to either the horizontal or vertical metrics  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
  /*               structure.                                              */
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
  /*    idx     :: The glyph index.                                        */
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
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  /*    bearing :: The bearing, either left side or top side.              */
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
  /*    advance :: The advance width resp. advance height.                 */
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
#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
  tt_face_get_metrics( TT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
                       FT_Bool     vertical,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
                       FT_UInt     gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
                       FT_Short   *abearing,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
                       FT_UShort  *aadvance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
    FT_Stream       stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
    TT_HoriHeader*  header;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
    FT_ULong        table_pos, table_size, table_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    FT_UShort       k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    if ( vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      void*  v = &face->vertical;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      header     = (TT_HoriHeader*)v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      table_pos  = face->vert_metrics_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      table_size = face->vert_metrics_size;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      header     = &face->horizontal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
      table_pos  = face->horz_metrics_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      table_size = face->horz_metrics_size;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    table_end = table_pos + table_size;
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
    k = header->number_Of_HMetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
    if ( k > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      if ( gindex < (FT_UInt)k )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        table_pos += 4 * gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
        if ( table_pos + 4 > table_end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
          goto NoData;
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
        if ( FT_STREAM_SEEK( table_pos ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
             FT_READ_USHORT( *aadvance ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
             FT_READ_SHORT( *abearing )  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
          goto NoData;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
        table_pos += 4 * ( k - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
        if ( table_pos + 4 > table_end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
          goto NoData;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
        if ( FT_STREAM_SEEK( table_pos ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
             FT_READ_USHORT( *aadvance ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
          goto NoData;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
        table_pos += 4 + 2 * ( gindex - k );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
        if ( table_pos + 2 > table_end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
          *abearing = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
          if ( !FT_STREAM_SEEK( table_pos ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
            (void)FT_READ_SHORT( *abearing );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    else
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
    NoData:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      *abearing = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      *aadvance = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
#else /* !FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
  tt_face_get_metrics( TT_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
                       FT_Bool     vertical,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
                       FT_UInt     gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
                       FT_Short*   abearing,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
                       FT_UShort*  aadvance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    void*           v = &face->vertical;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
    void*           h = &face->horizontal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    TT_HoriHeader*  header = vertical ? (TT_HoriHeader*)v
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
                                      : (TT_HoriHeader*)h;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    TT_LongMetrics  longs_m;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
    FT_UShort       k = header->number_Of_HMetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
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
    if ( k == 0                                         ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
         !header->long_metrics                          ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
         gindex >= (FT_UInt)face->max_profile.numGlyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      *abearing = *aadvance = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
    if ( gindex < (FT_UInt)k )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
      longs_m   = (TT_LongMetrics)header->long_metrics + gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      *abearing = longs_m->bearing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
      *aadvance = longs_m->advance;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
      *abearing = ((TT_ShortMetrics*)header->short_metrics)[gindex - k];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
      *aadvance = ((TT_LongMetrics)header->long_metrics)[k - 1].advance;
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
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
  }
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
#endif /* !FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
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
/* END */