misc/libfreetype/src/truetype/ttobjs.c
author nemo
Thu, 16 May 2013 14:02:33 -0400
changeset 9004 901ee9a8a3b4
parent 5172 88f2e05288ba
permissions -rw-r--r--
Yeah, this isn't safe either. Caused bug #629 - removing.
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
/*  ttobjs.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
/*    Objects manager (body).                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2011                                                    */
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 FT_INTERNAL_SFNT_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 "ttgload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include "ttpload.h"
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
#include "tterrors.h"
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
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#include "ttinterp.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#endif
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
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#include FT_TRUETYPE_UNPATENTED_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#endif
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
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#include "ttgxvar.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#endif
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /* 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
    45
  /* 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
    46
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
#define FT_COMPONENT  trace_ttobjs
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
#ifdef TT_USE_BYTECODE_INTERPRETER
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
  /*                       GLYPH ZONE FUNCTIONS                            */
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
  /*************************************************************************/
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
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /*    tt_glyphzone_done                                                  */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /*    Deallocate a glyph zone.                                           */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  /*    zone :: A pointer to the target glyph zone.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  tt_glyphzone_done( TT_GlyphZone  zone )
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_Memory  memory = zone->memory;
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 ( memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
      FT_FREE( zone->contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      FT_FREE( zone->tags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      FT_FREE( zone->cur );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
      FT_FREE( zone->org );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      FT_FREE( zone->orus );
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
      zone->max_points   = zone->n_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
      zone->max_contours = zone->n_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
      zone->memory       = NULL;
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
  }
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  /*    tt_glyphzone_new                                                   */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  /*    Allocate a new glyph zone.                                         */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  /*    memory      :: A handle to the current memory object.              */
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
  /*    maxPoints   :: The capacity of glyph zone in points.               */
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
  /*    maxContours :: The capacity of glyph zone in contours.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  /*    zone        :: A pointer to the target glyph zone record.          */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  /*    FreeType error code.  0 means success.                             */
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_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  tt_glyphzone_new( FT_Memory     memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
                    FT_UShort     maxPoints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
                    FT_Short      maxContours,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
                    TT_GlyphZone  zone )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    FT_MEM_ZERO( zone, sizeof ( *zone ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    zone->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    if ( FT_NEW_ARRAY( zone->org,      maxPoints   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
         FT_NEW_ARRAY( zone->cur,      maxPoints   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
         FT_NEW_ARRAY( zone->orus,     maxPoints   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
         FT_NEW_ARRAY( zone->tags,     maxPoints   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
         FT_NEW_ARRAY( zone->contours, maxContours ) )
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
      tt_glyphzone_done( zone );
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      zone->max_points   = maxPoints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
      zone->max_contours = maxContours;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    return error;
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
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  /* Compare the face with a list of well-known `tricky' fonts. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  /* This list shall be expanded as we find more of them.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  tt_check_trickyness_family( FT_String*  name )
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
#define TRICK_NAMES_MAX_CHARACTERS  16
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
#define TRICK_NAMES_COUNT            8
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
    static const char trick_names[TRICK_NAMES_COUNT]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
                                 [TRICK_NAMES_MAX_CHARACTERS + 1] =
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
      "DFKaiSho-SB",     /* dfkaisb.ttf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
      "DFKaiShu",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
      "DFKai-SB",        /* kaiu.ttf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      "HuaTianKaiTi?",   /* htkt2.ttf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      "HuaTianSongTi?",  /* htst3.ttf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      "MingLiU",         /* mingliu.ttf & mingliu.ttc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      "PMingLiU",        /* mingliu.ttc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      "MingLi43",        /* mingli.ttf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    };
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
    int  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      if ( ft_strstr( name, trick_names[nn] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
        return TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    return FALSE;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
  /* XXX: This function should be in the `sfnt' module. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  /* Some PDF generators clear the checksums in the TrueType header table. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
  /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
  /* Printer clears the entries for subsetted subtables.  We thus have to  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  /* recalculate the checksums  where necessary.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  static FT_UInt32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  tt_synth_sfnt_checksum( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
                          FT_ULong   length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    FT_UInt32  checksum = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    int        i;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    if ( FT_FRAME_ENTER( length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
      return 0;
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
    for ( ; length > 3; length -= 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      checksum += (FT_UInt32)FT_GET_ULONG();
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
    for ( i = 3; length > 0; length --, i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      checksum += (FT_UInt32)( FT_GET_BYTE() << ( i * 8 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    FT_FRAME_EXIT();
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
    return checksum;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /* XXX: This function should be in the `sfnt' module. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
  static FT_ULong
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
  tt_get_sfnt_checksum( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
                        FT_UShort  i )
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
    if ( face->dir_tables[i].CheckSum )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      return face->dir_tables[i].CheckSum;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    else if ( !face->goto_table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      return 0;
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
    else if ( !face->goto_table( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
                                 face->dir_tables[i].Tag,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
                                 face->root.stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
                                 NULL ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    return (FT_ULong)tt_synth_sfnt_checksum( face->root.stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
                                             face->dir_tables[i].Length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  typedef struct tt_sfnt_id_rec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    FT_ULong  CheckSum;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    FT_ULong  Length;
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
  } tt_sfnt_id_rec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
  tt_check_trickyness_sfnt_ids( TT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
#define TRICK_SFNT_IDS_PER_FACE   3
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
#define TRICK_SFNT_IDS_NUM_FACES  5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
                                       [TRICK_SFNT_IDS_PER_FACE] = {
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
#define TRICK_SFNT_ID_cvt   0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
#define TRICK_SFNT_ID_fpgm  1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
#define TRICK_SFNT_ID_prep  2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      { /* MingLiU 1995 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
        { 0x05bcf058, 0x000002e4 }, /* cvt  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
        { 0x28233bf1, 0x000087c4 }, /* fpgm */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        { 0xa344a1ea, 0x000001e1 }  /* prep */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
      },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
      { /* MingLiU 1996- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
        { 0x05bcf058, 0x000002e4 }, /* cvt  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
        { 0x28233bf1, 0x000087c4 }, /* fpgm */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
        { 0xa344a1eb, 0x000001e1 }  /* prep */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
      },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      { /* DFKaiShu */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
        { 0x11e5ead4, 0x00000350 }, /* cvt  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
        { 0x5a30ca3b, 0x00009063 }, /* fpgm */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
        { 0x13a42602, 0x0000007e }  /* prep */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
      },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      { /* HuaTianKaiTi */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
        { 0xfffbfffc, 0x00000008 }, /* cvt  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
        { 0x9c9e48b8, 0x0000bea2 }, /* fpgm */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
        { 0x70020112, 0x00000008 }  /* prep */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      { /* HuaTianSongTi */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        { 0xfffbfffc, 0x00000008 }, /* cvt  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        { 0x0a5a0483, 0x00017c39 }, /* fpgm */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
        { 0x70020112, 0x00000008 }  /* prep */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    FT_ULong  checksum;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    int       num_matched_ids[TRICK_SFNT_IDS_NUM_FACES];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    int       i, j, k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    FT_MEM_SET( num_matched_ids, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
                sizeof( int ) * TRICK_SFNT_IDS_NUM_FACES );
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
    for ( i = 0; i < face->num_tables; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
      checksum = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      switch( face->dir_tables[i].Tag )
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
      case TTAG_cvt:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
        k = TRICK_SFNT_ID_cvt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
        break;
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
      case TTAG_fpgm:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
        k = TRICK_SFNT_ID_fpgm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
        break;
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
      case TTAG_prep:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
        k = TRICK_SFNT_ID_prep;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
        break;
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
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
        continue;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
        if ( face->dir_tables[i].Length == sfnt_id[j][k].Length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
          if ( !checksum )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
            checksum = tt_get_sfnt_checksum( face, i );
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
          if ( sfnt_id[j][k].CheckSum == checksum )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
            num_matched_ids[j]++;
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
          if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
            return TRUE;
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
    return FALSE;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
  tt_check_trickyness( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      return FALSE;
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
    /* First, check the face name. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    if ( face->family_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      if ( tt_check_trickyness_family( face->family_name ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
        return TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
        return FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
    /* Type42 fonts may lack `name' tables, we thus try to identify */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    /* tricky fonts by checking the checksums of Type42-persistent  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    /* sfnt tables (`cvt', `fpgm', and `prep').                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
      return TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    return FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  /*    tt_face_init                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
  /*    Initialize a given TrueType face object.                           */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
  /*    stream     :: The source font stream.                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
  /*    face_index :: The index of the font face in the resource.          */
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
  /*    num_params :: Number of additional generic parameters.  Ignored.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
  /*    params     :: Additional generic parameters.  Ignored.             */
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
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
  /*    face       :: The newly built face object.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  /*    FreeType error code.  0 means success.                             */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  tt_face_init( FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
                FT_Face        ttface,      /* TT_Face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
                FT_Int         face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
                FT_Int         num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
                FT_Parameter*  params )
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
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    FT_Library    library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    SFNT_Service  sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    TT_Face       face = (TT_Face)ttface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
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
    library = ttface->driver->root.library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    sfnt    = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    if ( !sfnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      goto Bad_Format;
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
    /* create input stream from resource */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    if ( FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    /* check that we have a valid TrueType file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
    error = sfnt->init_face( stream, face, face_index, num_params, params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    /* The 0x00020000 tag is completely undocumented; some fonts from   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    /* Arphic made for Chinese Windows 3.1 have this.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    if ( face->format_tag != 0x00010000L &&    /* MS fonts  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
         face->format_tag != 0x00020000L &&    /* CJK fonts for Win 3.1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
         face->format_tag != TTAG_true   )     /* Mac fonts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      FT_TRACE2(( "[not a valid TTF font]\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
      goto Bad_Format;
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
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    ttface->face_flags |= FT_FACE_FLAG_HINTER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
    /* If we are performing a simple font format check, exit immediately. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    if ( face_index < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      return TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    /* Load font directory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    error = sfnt->load_face( stream, face, face_index, num_params, params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    if ( tt_check_trickyness( ttface ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      ttface->face_flags |= FT_FACE_FLAG_TRICKY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    error = tt_face_load_hdmx( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
    if ( FT_IS_SCALABLE( ttface ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
#ifdef FT_CONFIG_OPTION_INCREMENTAL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      if ( !ttface->internal->incremental_interface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
        error = tt_face_load_loca( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        error = tt_face_load_cvt( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        error = tt_face_load_fpgm( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
        error = tt_face_load_prep( face, stream );
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
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
        error = tt_face_load_loca( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
        error = tt_face_load_cvt( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
        error = tt_face_load_fpgm( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        error = tt_face_load_prep( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
#if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING    ) && \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    !defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
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
      FT_Bool  unpatented_hinting;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      int      i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      /* Determine whether unpatented hinting is to be used for this face. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
      unpatented_hinting = FT_BOOL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
        ( library->debug_hooks[FT_DEBUG_HOOK_UNPATENTED_HINTING] != NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
        if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
          unpatented_hinting = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      if ( !unpatented_hinting )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        ttface->internal->ignore_unpatented_hinter = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
#endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
          !TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    /* initialize standard glyph loading routines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    TT_Init_Glyph_Loading( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
  Bad_Format:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    error = TT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
  /*    tt_face_done                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
  /*    Finalize a given face object.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  /*    face :: A pointer to the face object to destroy.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
  tt_face_done( FT_Face  ttface )           /* TT_Face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    TT_Face       face = (TT_Face)ttface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    FT_Memory     memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    FT_Stream     stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
    SFNT_Service  sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    memory = ttface->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    stream = ttface->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    sfnt   = (SFNT_Service)face->sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    /* for `extended TrueType formats' (i.e. compressed versions) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
    if ( face->extra.finalizer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
      face->extra.finalizer( face->extra.data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    if ( sfnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      sfnt->done_face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
    /* freeing the locations table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    tt_face_done_loca( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    tt_face_free_hdmx( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    /* freeing the CVT */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    FT_FREE( face->cvt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    face->cvt_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    /* freeing the programs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    FT_FRAME_RELEASE( face->font_program );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    FT_FRAME_RELEASE( face->cvt_program );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    face->font_program_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    face->cvt_program_size  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
    tt_done_blend( memory, face->blend );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
    face->blend = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
  /*                           SIZE  FUNCTIONS                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
  /*    tt_size_run_fpgm                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
  /*    Run the font program.                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
  /*    size     :: A handle to the size object.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
  /*    pedantic :: Set if bytecode execution should be pedantic.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
  tt_size_run_fpgm( TT_Size  size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
                    FT_Bool  pedantic )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
    TT_Face         face = (TT_Face)size->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
    TT_ExecContext  exec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
    /* debugging instances have their own context */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    if ( size->debug )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
      exec = size->context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    if ( !exec )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      return TT_Err_Could_Not_Find_Context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
    TT_Load_Context( exec, face, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    exec->callTop = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
    exec->top     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
    exec->period    = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    exec->phase     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
    exec->threshold = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    exec->instruction_trap = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
    exec->F_dot_P          = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
    exec->pedantic_hinting = pedantic;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
      FT_Size_Metrics*  metrics    = &exec->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      TT_Size_Metrics*  tt_metrics = &exec->tt_metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
      metrics->x_ppem   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      metrics->y_ppem   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      metrics->x_scale  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      metrics->y_scale  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
      tt_metrics->ppem  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
      tt_metrics->scale = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      tt_metrics->ratio = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    /* allow font program execution */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
    TT_Set_CodeRange( exec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
                      tt_coderange_font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
                      face->font_program,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
                      face->font_program_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    /* disable CVT and glyph programs coderange */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    TT_Clear_CodeRange( exec, tt_coderange_cvt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    TT_Clear_CodeRange( exec, tt_coderange_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    if ( face->font_program_size > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
      error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
        FT_TRACE4(( "Executing `fpgm' table.\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
        error = face->interpreter( exec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      error = TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
      TT_Save_Context( exec, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
  /*    tt_size_run_prep                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
  /*    Run the control value program.                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
  /*    size     :: A handle to the size object.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
  /*    pedantic :: Set if bytecode execution should be pedantic.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
  tt_size_run_prep( TT_Size  size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
                    FT_Bool  pedantic )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
    TT_Face         face = (TT_Face)size->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    TT_ExecContext  exec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    /* debugging instances have their own context */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    if ( size->debug )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
      exec = size->context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
      exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    if ( !exec )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      return TT_Err_Could_Not_Find_Context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
    TT_Load_Context( exec, face, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
    exec->callTop = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
    exec->top     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
    exec->instruction_trap = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    exec->pedantic_hinting = pedantic;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    TT_Set_CodeRange( exec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
                      tt_coderange_cvt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
                      face->cvt_program,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
                      face->cvt_program_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    TT_Clear_CodeRange( exec, tt_coderange_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    if ( face->cvt_program_size > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
      error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      if ( !error && !size->debug )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
        FT_TRACE4(( "Executing `prep' table.\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
        error = face->interpreter( exec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
      error = TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    /* save as default graphics state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
    size->GS = exec->GS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
    TT_Save_Context( exec, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
  tt_size_done_bytecode( FT_Size  ftsize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    TT_Size    size   = (TT_Size)ftsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    TT_Face    face   = (TT_Face)ftsize->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    FT_Memory  memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    if ( size->debug )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
      /* the debug context must be deleted by the debugger itself */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
      size->context = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      size->debug   = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
    FT_FREE( size->cvt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
    size->cvt_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
    /* free storage area */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
    FT_FREE( size->storage );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
    size->storage_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
    /* twilight zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
    tt_glyphzone_done( &size->twilight );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
    FT_FREE( size->function_defs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
    FT_FREE( size->instruction_defs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
    size->num_function_defs    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
    size->max_function_defs    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
    size->num_instruction_defs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
    size->max_instruction_defs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    size->max_func = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    size->max_ins  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
    size->bytecode_ready = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
    size->cvt_ready      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
  /* Initialize bytecode-related fields in the size object.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
  /* We do this only if bytecode interpretation is really needed. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
  tt_size_init_bytecode( FT_Size  ftsize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
                         FT_Bool  pedantic )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    TT_Size    size = (TT_Size)ftsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
    TT_Face    face = (TT_Face)ftsize->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
    FT_Memory  memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
    FT_Int     i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    FT_UShort       n_twilight;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    TT_MaxProfile*  maxp = &face->max_profile;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    size->bytecode_ready = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
    size->cvt_ready      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    size->max_function_defs    = maxp->maxFunctionDefs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
    size->max_instruction_defs = maxp->maxInstructionDefs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
    size->num_function_defs    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    size->num_instruction_defs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
    size->max_func = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
    size->max_ins  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    size->cvt_size     = face->cvt_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
    size->storage_size = maxp->maxStorage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
    /* Set default metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      TT_Size_Metrics*  metrics = &size->ttmetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
      metrics->rotated   = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
      metrics->stretched = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
      /* set default compensation (all 0) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
      for ( i = 0; i < 4; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
        metrics->compensations[i] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
    /* allocate function defs, instruction defs, cvt, and storage area */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
    if ( FT_NEW_ARRAY( size->function_defs,    size->max_function_defs    ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
         FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
         FT_NEW_ARRAY( size->cvt,              size->cvt_size             ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
         FT_NEW_ARRAY( size->storage,          size->storage_size         ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    /* reserve twilight zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
    n_twilight = maxp->maxTwilightPoints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
    /* there are 4 phantom points (do we need this?) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
    n_twilight += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
    error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
    size->twilight.n_points = n_twilight;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
    size->GS = tt_default_graphics_state;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
    /* set `face->interpreter' according to the debug hook present */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
      FT_Library  library = face->root.driver->root.library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
      face->interpreter = (TT_Interpreter)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
                            library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
      if ( !face->interpreter )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
        face->interpreter = (TT_Interpreter)TT_RunIns;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
    /* Fine, now run the font program! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
    error = tt_size_run_fpgm( size, pedantic );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
      tt_size_done_bytecode( ftsize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
  tt_size_ready_bytecode( TT_Size  size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
                          FT_Bool  pedantic )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
    FT_Error  error = TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
    if ( !size->bytecode_ready )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
      error = tt_size_init_bytecode( (FT_Size)size, pedantic );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
    /* rescale CVT when needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
    if ( !size->cvt_ready )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
      FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
      TT_Face  face = (TT_Face)size->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
      /* Scale the cvt values to the new ppem.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      /* We use by default the y ppem to scale the CVT. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
      for ( i = 0; i < size->cvt_size; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
        size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
      /* all twilight points are originally zero */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
      for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
        size->twilight.org[i].x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
        size->twilight.org[i].y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
        size->twilight.cur[i].x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
        size->twilight.cur[i].y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
      /* clear storage area */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
      for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
        size->storage[i] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
      size->GS = tt_default_graphics_state;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
      error = tt_size_run_prep( size, pedantic );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
        size->cvt_ready = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
  /*    tt_size_init                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
  /*    Initialize a new TrueType size object.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
  /*    size :: A handle to the size object.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
  tt_size_init( FT_Size  ttsize )           /* TT_Size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
    TT_Size   size  = (TT_Size)ttsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    FT_Error  error = TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    size->bytecode_ready = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
    size->cvt_ready      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
    size->ttmetrics.valid = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
    size->strike_index    = 0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
  /*    tt_size_done                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
  /*    The TrueType size object finalizer.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
  /*    size :: A handle to the target size object.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
  tt_size_done( FT_Size  ttsize )           /* TT_Size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
    TT_Size  size = (TT_Size)ttsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
    if ( size->bytecode_ready )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
      tt_size_done_bytecode( ttsize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
    size->ttmetrics.valid = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
  /*    tt_size_reset                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
  /*    Reset a TrueType size when resolutions and character dimensions    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
  /*    have been changed.                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
  /*    size :: A handle to the target size object.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
  tt_size_reset( TT_Size  size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
    TT_Face           face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    FT_Error          error = TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    FT_Size_Metrics*  metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
    size->ttmetrics.valid = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
    face = (TT_Face)size->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    metrics = &size->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
    /* copy the result from base layer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
    *metrics = size->root.metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
    if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
      return TT_Err_Invalid_PPem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    /* This bit flag, if set, indicates that the ppems must be       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
    /* rounded to integers.  Nearly all TrueType fonts have this bit */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
    /* set, as hinting won't work really well otherwise.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
    /*                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
    if ( face->header.Flags & 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
      metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
                                    face->root.units_per_EM );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
      metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
                                    face->root.units_per_EM );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
      metrics->ascender =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
        FT_PIX_ROUND( FT_MulFix( face->root.ascender, metrics->y_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
      metrics->descender =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
        FT_PIX_ROUND( FT_MulFix( face->root.descender, metrics->y_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
      metrics->height =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
        FT_PIX_ROUND( FT_MulFix( face->root.height, metrics->y_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
      metrics->max_advance =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
        FT_PIX_ROUND( FT_MulFix( face->root.max_advance_width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
                                 metrics->x_scale ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
    /* compute new transformation */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
    if ( metrics->x_ppem >= metrics->y_ppem )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
      size->ttmetrics.scale   = metrics->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
      size->ttmetrics.ppem    = metrics->x_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
      size->ttmetrics.x_ratio = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
      size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
                                           0x10000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
                                           metrics->x_ppem );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
      size->ttmetrics.scale   = metrics->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
      size->ttmetrics.ppem    = metrics->y_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
      size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
                                           0x10000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
                                           metrics->y_ppem );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
      size->ttmetrics.y_ratio = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    size->cvt_ready = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
#endif /* TT_USE_BYTECODE_INTERPRETER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
      size->ttmetrics.valid = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
  /*    tt_driver_init                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
  /*    Initialize a given TrueType driver object.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
  /*    driver :: A handle to the target driver object.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
  tt_driver_init( FT_Module  ttdriver )     /* TT_Driver */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
    TT_Driver  driver = (TT_Driver)ttdriver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
    if ( !TT_New_Context( driver ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
      return TT_Err_Could_Not_Find_Context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
    FT_UNUSED( ttdriver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
    return TT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
  /*    tt_driver_done                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
  /*    Finalize a given TrueType driver.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
  /*    driver :: A handle to the target TrueType driver.                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
  tt_driver_done( FT_Module  ttdriver )     /* TT_Driver */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
#ifdef TT_USE_BYTECODE_INTERPRETER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
    TT_Driver  driver = (TT_Driver)ttdriver;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
    /* destroy the execution context */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
    if ( driver->context )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
      TT_Done_Context( driver->context );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
      driver->context = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
    FT_UNUSED( ttdriver );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
  /*    tt_slot_init                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
  /*    Initialize a new slot object.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
  /*    slot :: A handle to the slot object.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
  tt_slot_init( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
    return FT_GlyphLoader_CreateExtra( slot->internal->loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
/* END */