T168_111\appl\Text\Freetype文件:第1~8个文件

ALLOC.C   、、、、、、、、、、、、、、、、、、、、、、、

/*******************************************************************************
*
* malloc.c 
*
* Copyright 1995-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*  $Id: malloc.c,v 1.3 1999/02/08 15:51:22 simomura Exp $
*
*    NC30 Version 0.00.00
*
*     : Version 0.00.00
*                
*        
*
*******************************************************************************/

#include <stdlib.h>
#include <string.h>
#include "FT_CONF.H"

#define _FAR 
#define Malloc        dlmalloc
#define Realloc        dlrealloc
#define Free        dlfree
#define Calloc        dlcalloc
#define _msize        mmsize


//#define NULL 0          
#define size_t int 

//extern void *memset(void *, int, size_t);
//extern void *memcpy(void *, const void *, size_t);


char _FAR *_mbase;                      /*                   */
char _FAR *_mnext;                      /*                   */

unsigned long  _msize=POOL_SIZE;          /*                   */

//MEMT  _pool = { NULL, NULL };  /*                */
//MEMT  _memt = { NULL, NULL };  /*                 */
MEMT  _pool;
MEMT  _memt;

#define _MEMTSIZE sizeof( struct _MEMT )

char _FAR *getmem( unsigned int );
int  rlsmem( char _FAR *cp, unsigned nbytes );

/*******************************************************************************
*
* free 
*
* Copyright 1988-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*        free --          
*
*        #include <stdlib.h>
*           ret = free( cp );
*
*           int  ret;             
*           void _FAR *cp;                          
*
*        ret ==  0                  
*               == -1           "cp"                 
*
*             malloc calloc                       
*                char *                malloc calloc   
*                             
*
*******************************************************************************/
void Free( void _FAR *cp )    /*                   */
{
    struct _MEMT _FAR *p;               /*                   */

    if( NULL == cp )
    return;
    p = ( struct _MEMT _FAR * )cp - 1;   /*                  */
#if 0
    return ( rlsmem( ( char _FAR * )p, p->size * _MEMTSIZE ) );
#else
    rlsmem( ( char _FAR * )p, p->size * _MEMTSIZE );
#endif
                                        /*                   */
}


/*******************************************************************************
*
* malloc -- Version 3.10.00
*
* Copyright 1988-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*        malloc --           
*
*        #include <stdlib.h>
*           p = malloc( nbytes );
*
*           char _FAR *p;                       
*           unsigned nbytes;                      
*
*                                     
*                     
*
*                                 
*
*******************************************************************************/
void _FAR *Malloc( size_t nbytes ) /*                   */
{
    unsigned nunits;                    /*                   */
    struct _MEMT _FAR *p;               /*                   */

    if ( nbytes == 0 )
    return ( NULL );         /*   "nbytes"           */
    nunits = ( nbytes + _MEMTSIZE * 2 - 1 ) / _MEMTSIZE;
                                        /*                   */
    if ( ( p = ( struct _MEMT _FAR * )getmem( nunits * _MEMTSIZE ) ) == NULL )
        return ( NULL );                /*                   */
    p->size = nunits;                   /*                   */
    return ( ( char _FAR * )( p + 1 ) );     /*                   */
}


/*******************************************************************************
*
* realloc 
*
* Copyright 1988-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*        realloc --                
*
*        #include <stdlib.h>
*           np = realloc( cp, nbytes );
*
*           char _FAR *np;                          
*           char _FAR *cp;                          
*           unsigned nbytes;                       
*
*                                      
*                                        
*                     
*
*          malloc calloc                     
*             "cp"                    "nbytes" 
*                         
*
*******************************************************************************/
void _FAR *Realloc( void _FAR *cp, size_t nbytes )/*                   */
{
    char _FAR *np;                      /*                   */
    unsigned size;                      /*                   */
    struct _MEMT _FAR *p;               /*                   */

    if ( ( np = Malloc( nbytes ) ) != NULL ) {
                                        /*                   */
        if ( cp != NULL ){
            p = ( struct _MEMT _FAR * )cp - 1;   /*                */
            size = p->size * _MEMTSIZE - _MEMTSIZE;
                                        /*                   */
           if ( size > nbytes )         /*                   */
                size = nbytes;          /*                   */
            memcpy( np, cp, size );     /*                   */
            Free( cp );                 /*                   */
        }
    }
    return( np );                       /*                   */
}


/*******************************************************************************
*
* getmem 
*
* Copyright 1988-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*        getmem --           
*
*        p = getmem( nbytes );
*
*           char _FAR *p;                         
*           unsigned nbytes;             
*
*                                     
*                     
*
*                                    nbytes 
*                                          
*                                  
*
*******************************************************************************/
char _FAR *getmem( unsigned nbytes )    /*                   */
{

    unsigned long lbytes;               /*                   */
    unsigned long lunits;               /*                   */
    struct _MEMT _FAR *p;               /*                   */
    struct _MEMT _FAR *q;               /*                   */

    lbytes = ( unsigned long )(nbytes);
    if ( lbytes <= 0L )
    return ( NULL );        /*                   */
    lunits = ( lbytes + _MEMTSIZE - 1 ) / _MEMTSIZE;
                                        /*                   */
    q = &_memt;                         /*                   */
     for ( p = q->top; p != NULL; q = p, p = p->top ) {
                                        /*                   */
        if ( lunits <= p->size ) {      /*                   */
            if ( p->size != lunits ) {  /*                   */
                p->size -= lunits;      /*                   */
                p += p->size;           /*                   */
            }
            else q->top = p->top;       /*                   */
            _memt.size -= lunits;       /*                   */
            return ( ( char _FAR * )p );  /*                  */
        }
    }
    if ( lunits * _MEMTSIZE >_msize )  /*                   */
        return ( NULL );                /*                   */
    p = ( struct _MEMT _FAR * )_mnext;  /*                   */
    _mnext += lbytes;                   /*                   */
    _msize -= lbytes;                   /*                   */
    if ( ! _pool.size ) {         /*                   */
        _pool.top = p;                  /*                   */
        _pool.size = lunits;            /*                   */
    }
    else {                              /*                   */
        q = _pool.top + _pool.size;     /*                   */
        if ( p == q )                   /*                   */
            _pool.size += lunits;       /*                   */
    }
    return ( ( char _FAR * )p );         /*                  */
}


/*******************************************************************************
*
* rlsmem 
*
* Copyright 1988-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*        rlsmem --          
*
*        ret = rlsmem( cp, nbytes );
*
*           int      ret;         
*           char     _FAR *cp;                        
*           unsigned nbytes;                
*
*        ret ==  0                  
*               == -1           "cp"                 
*
*                         
*                                     
*                                           
*                                          
*                                            
*                                            
*
*******************************************************************************/
int  rlsmem( char _FAR *cp, unsigned nbytes )   /*        */
{
    long lbytes;                        /*                   */
    long lunits;                        /*                   */
    struct _MEMT _FAR *p;     /*                   */
    struct _MEMT _FAR *pu;     /*                   */
    struct _MEMT _FAR *q;     /*                   */
    struct _MEMT _FAR *qu;     /*                   */
    struct _MEMT _FAR *n;     /*                   */
    struct _MEMT _FAR *nu;     /*                   */

    lbytes = nbytes;
    if ( lbytes <= 0 ) return ( -1 );   /*                   */
    n = ( struct _MEMT _FAR * )cp;      /*                   */
    lunits = ( lbytes + _MEMTSIZE - 1 ) / _MEMTSIZE;
                                        /*                   */
    nu = n + lunits;                    /*                   */
    _memt.size += lunits;               /*                   */
    q = &_memt;                         /*                   */
    for ( p = q->top; p != NULL; q = p, qu = pu, p = p->top ) {
                                        /*                   */
        pu = p + p->size;               /*                   */
        if ( p  > nu ) {                /*                   */
            n->top = p;                 /*                   */
            n->size = lunits;           /*                   */
            q->top = n;                 /*                   */
            return ( 0 );               /*                   */
        }
        if ( p == nu ) {                /*                   */
            n->top = p->top;            /*                   */
            n->size = lunits + p->size; /*                   */
            q->top = n;                 /*                   */
            return ( 0 );               /*                   */
        }
        if ( n < pu ) {                 /*                   */
            _memt.size -= lunits;       /*                   */
            return ( -1 );              /*                   */
        }
        if ( n == pu ) {                /*                   */
            if ( p->top != NULL ) {     /*                   */
                if ( nu > p->top ) {    /*                   */
                    _memt.size -= lunits;
                                        /*                   */
                    return ( -1 );      /*                   */
                }
            }
            p->size += lunits;          /*                   */
            if ( p->top != NULL ) {     /*                   */
                if ( nu == p->top ) {   /*                   */
                    p->size += nu->size;
                                        /*                   */
                    p->top = nu->top;   /*                   */
                }
            }
            return ( 0 );               /*                   */
        }
    }
    q->top = n;                         /*           "_MEMT"     */
    n->top = NULL;                      /*                   */
    n->size = lunits;                   /*                   */
    return ( 0 );                       /*                   */
}


/*******************************************************************************
*
* calloc 
*
* Copyright 1988-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*        calloc --               
*
*        #include <stdlib.h>
*           p = calloc( n, size );
*
*           char _FAR *p;                       
*           unsigned n;             
*           unsigned size;                      
*
*                                     
*                     
*
*                                
*                                
*
*******************************************************************************/
void _FAR *Calloc( size_t n, size_t size )    /*                   */
{
    char _FAR *cp;                      /*                   */

    if ( cp = Malloc( n * size ) )      /*                   */
        memset( cp, ( int )'\0', n * size );
                                        /*                   */
    return ( cp );                      /*                   */
}

/*******************************************************************************
*
* malloc.c 
*
* Copyright 1995-1998 MITSUBISHI ELECTRIC CORPORATION
* AND MITSUBISHI ELECTRIC SEMICONDUCTOR SYSTEMS CORPORATION
* All Rights Reserved.
*
*******************************************************************************/
 

FREETYPE.C    、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

#include "Common.h"

#if defined(FREETYPE_TTF )

/* This file is part of the FreeType project */

/* Single file library component for the ANSI target */
#define TT_MAKE_OPTION_SINGLE_OBJECT
// POOL_SIZE is a buffer for TTF.
//#define POOL_SIZE 0x60000

/* first include common core components */

#include "alloc.c"
#include "ttextout.c"

#define error error_
//redefine file related functions to TSC's
#define fseek(X, Y) lpTTFSetDataPoint(Y)
//#define fopen Fopen
#define fclose(X) (X)
//#define fread Fread
#define ftell(X) lpTTFGetDataPoint()

#include "ttapi.c"
#include "ttcache.c"
#include "ttcalc.c"
#include "ttcmap.c"
#include "ttgload.c"
#include "ttinterp.c"
#include "ttload.c"
#include "ttobjs.c"
#include "ttraster.c"

// then system-specific (or ANSI) components 

#include "ttfile.c"
#include "ttmemory.c"
#include "ttmutex.c"

/* the extensions are compiled separately, but we need to */
/* include the file ttextend.c if we want to support them */

#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
#include "ttextend.c"
#endif

#endif
/* END */
 

FREETYPE.H  、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/*******************************************************************
 *
 *  freetype.h
 *
 *    High-level interface specification.
 *
 *  Copyright 1996-1999 by
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 *  This file is part of the FreeType project and may only be used,
 *  modified, and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 *  Note:
 *
 *    This is the only file that should be included by client
 *    application sources.  All other types and functions defined
 *    in the `tt*.h' files are library internals and should not be
 *    included.
 *
 ******************************************************************/

#ifndef FREETYPE_H
#define FREETYPE_H


#define TT_FREETYPE_MAJOR  1
#define TT_FREETYPE_MINOR  3


#include "fterrid.h"
#include "ftnameid.h"

/* To make freetype.h independent from configuration files we check */
/* whether EXPORT_DEF has been defined already.                     */

#ifndef EXPORT_DEF
#define EXPORT_DEF  extern
#endif

/* The same for TT_Text.  If you define the HAVE_TT_TEXT macro, you */
/* have to provide a typedef declaration for TT_Text before         */
/* including this file.                                             */

#ifndef HAVE_TT_TEXT
#define HAVE_TT_TEXT
  typedef char  TT_Text;              /* The data type to represent */
                                      /* file name string elements. */
#endif

#ifdef __cplusplus
  extern "C" {
#endif


  /*******************************************************************/
  /*                                                                 */
  /*  FreeType types definitions.                                    */
  /*                                                                 */
  /*  All these begin with a 'TT_' prefix.                           */
  /*                                                                 */
  /*******************************************************************/

  typedef int             TT_Bool;

  typedef signed long     TT_Fixed;   /* signed fixed 16.16 float */

  typedef signed short    TT_FWord;   /* distance in FUnits */
  typedef unsigned short  TT_UFWord;  /* unsigned distance  */

  typedef char            TT_String;
  typedef signed char     TT_Char;
  typedef unsigned char   TT_Byte;
  typedef signed short    TT_Short;
  typedef unsigned short  TT_UShort;
  typedef int             TT_Int;
  typedef unsigned int    TT_UInt;
  typedef signed long     TT_Long;
  typedef unsigned long   TT_ULong;

  typedef signed short    TT_F2Dot14; /* Signed fixed float 2.14 used for */
                                      /* unit vectors, with layout        */
                                      /*                                  */
                                      /*   s : 1  -- sign bit             */
                                      /*   m : 1  -- integer bit          */
                                      /*   f : 14 -- unsigned fractional  */
                                      /*                                  */
                                      /* `s:m' is the 2-bit signed int    */
                                      /* value to which the positive      */
                                      /* fractional part should be added. */

  typedef signed long     TT_F26Dot6; /* 26.6 fixed float, used for       */
                                      /* glyph points pixel coordinates.  */

  typedef signed long     TT_Pos;     /* Point position, expressed either */
                                      /* in fractional pixels or notional */
                                      /* units, depending on context.     */
                                      /* For example, glyph coordinates   */
                                      /* returned by TT_Load_Glyph() are  */
                                      /* expressed in font units if       */
                                      /* scaling wasn't requested, and    */
                                      /* in 26.6 fractional pixels if it  */
                                      /* was.                             */


  struct  TT_UnitVector_      /* guess what...  */
  {
    TT_F2Dot14  x;
    TT_F2Dot14  y;
  };

  typedef struct TT_UnitVector_  TT_UnitVector;


  struct  TT_Vector_          /* simple vector type */
  {
    TT_F26Dot6  x;
    TT_F26Dot6  y;
  };

  typedef struct TT_Vector_  TT_Vector;


  /* A simple 2x2 matrix used for transformations. */
  /* You should use 16.16 fixed floats.            */
  /*                                               */
  /*   x' = xx*x + xy*y                            */
  /*   y' = yx*x + yy*y                            */
  /*                                               */

  struct  TT_Matrix_
  {
    TT_Fixed  xx, xy;
    TT_Fixed  yx, yy;
  };

  typedef struct TT_Matrix_  TT_Matrix;


  /* A structure used to describe the source glyph to the renderer. */

  struct  TT_Outline_
  {
    TT_Short         n_contours;   /* number of contours in glyph   */
    TT_UShort        n_points;     /* number of points in the glyph */

    TT_Vector*       points;       /* the outline's points   */
    TT_Byte*         flags;        /* the points flags       */
    TT_UShort*       contours;     /* the contour end points */

    /* The following flag indicates that the outline owns the arrays it  */
    /* refers to.  Typically, this is true of outlines created from the  */
    /* TT_New_Outline() API, while it isn't for those returned by        */
    /* TT_Get_Glyph_Outline().                                           */

    TT_Bool          owner;      /* The outline owns the coordinates, */
                                 /* flags and contours array it uses. */

    /* The following flags are set automatically by                      */
    /* TT_Get_Glyph_Outline().  Their meaning is the following:          */
    /*                                                                   */
    /*  high_precision   If true, the scan-line converter will use a     */
    /*                   higher precision to render bitmaps (i.e., a     */
    /*                   1/1024 pixel precision).  This is important for */
    /*                   small ppem sizes.                               */
    /*                                                                   */
    /*  second_pass      If true, the scan-line converter performs a     */
    /*                   second sweep phase dedicated to find vertical   */
    /*                   drop-outs.  If false, only horizontal drop-outs */
    /*                   will be checked during the first vertical       */
    /*                   sweep (yes, this is a bit confusing but it is   */
    /*                   really the way it should work).  This is        */
    /*                   important for small ppems too.                  */
    /*                                                                   */
    /*  dropout_mode     Specifies the TrueType drop-out mode to use for */
    /*                   continuity checking.  Valid values are 0 (no    */
    /*                   check), 1, 2, 4, and 5.                         */
    /*                                                                   */
    /*  Most of the engine's users will safely ignore these fields...    */

    TT_Bool          high_precision;  /* high precision rendering */
    TT_Bool          second_pass;     /* two sweeps rendering     */
    TT_Char          dropout_mode;    /* dropout mode             */
  };

  typedef struct TT_Outline_  TT_Outline;


  /* A structure used to describe a simple bounding box. */

  struct TT_BBox_
  {
    TT_Pos  xMin;
    TT_Pos  yMin;
    TT_Pos  xMax;
    TT_Pos  yMax;
  };

  typedef struct TT_BBox_  TT_BBox;


  /* A structure used to return glyph metrics.                          */
  /*                                                                    */
  /* The `bearingX' isn't called `left-side bearing' anymore because    */
  /* it has different meanings depending on the glyph's orientation.    */
  /*                                                                    */
  /* The same is true for `bearingY', which is the top-side bearing     */
  /* defined by the TT_Spec, i.e., the distance from the baseline to    */
  /* the top of the glyph's bbox.  According to our current convention, */
  /* this is always the same as `bbox.yMax' but we make it appear for   */
  /* consistency in its proper field.                                   */
  /*                                                                    */
  /* The `advance' field is the advance width for horizontal layout,    */
  /* and advance height for vertical layouts.                           */

  struct  TT_Glyph_Metrics_
  {
    TT_BBox  bbox;      /* glyph bounding box */

    TT_Pos   bearingX;  /* left-side bearing                    */
    TT_Pos   bearingY;  /* top-side bearing, per se the TT spec */

    TT_Pos   advance;   /* advance width (or height) */
  };

  typedef struct TT_Glyph_Metrics_  TT_Glyph_Metrics;


  /* A structure used to return horizontal _and_ vertical glyph         */
  /* metrics.                                                           */
  /*                                                                    */
  /* A glyph can be used either in a horizontal or vertical layout.     */
  /* Its glyph metrics vary with orientation.  The TT_Big_Glyph_Metrics */
  /* structure is used to return _all_ metrics in one call.             */

  struct TT_Big_Glyph_Metrics_
  {
    TT_BBox  bbox;          /* glyph bounding box */

    TT_Pos   horiBearingX;  /* left side bearing in horizontal layouts */
    TT_Pos   horiBearingY;  /* top side bearing in horizontal layouts  */

    TT_Pos   vertBearingX;  /* left side bearing in vertical layouts */
    TT_Pos   vertBearingY;  /* top side bearing in vertical layouts  */

    TT_Pos   horiAdvance;   /* advance width for horizontal layout */
    TT_Pos   vertAdvance;   /* advance height for vertical layout  */

    /* The following fields represent unhinted scaled metrics values. */
    /* They can be useful for applications needing to do some device  */
    /* independent placement of glyphs.                               */
    /*                                                                */
    /* Applying these metrics to hinted glyphs will most surely ruin  */
    /* the grid fitting performed by the bytecode interpreter.  These */
    /* values are better used to compute accumulated positioning      */
    /* distances.                                                     */

    TT_Pos   linearHoriBearingX;  /* linearly scaled horizontal lsb     */
    TT_Pos   linearHoriAdvance;   /* linearly scaled horizontal advance */

    TT_Pos   linearVertBearingY;  /* linearly scaled vertical tsb     */
    TT_Pos   linearVertAdvance;   /* linearly scaled vertical advance */
  };

  typedef struct TT_Big_Glyph_Metrics_  TT_Big_Glyph_Metrics;


  /* A structure used to return instance metrics. */

  struct  TT_Instance_Metrics_
  {
    TT_F26Dot6  pointSize;     /* char. size in points (1pt = 1/72 inch) */

    TT_UShort   x_ppem;        /* horizontal pixels per EM square */
    TT_UShort   y_ppem;        /* vertical pixels per EM square   */

    TT_Fixed    x_scale;     /* 16.16 to convert from EM units to 26.6 pix */
    TT_Fixed    y_scale;     /* 16.16 to convert from EM units to 26.6 pix */

    TT_UShort   x_resolution;  /* device horizontal resolution in dpi */
    TT_UShort   y_resolution;  /* device vertical resolution in dpi   */
  };

  typedef struct TT_Instance_Metrics_  TT_Instance_Metrics;


  /* Flow constants:                                             */
  /*                                                             */
  /* The flow of a bitmap refers to the way lines are oriented   */
  /* within the bitmap data, i.e., the orientation of the Y      */
  /* coordinate axis.                                            */
  /*                                                             */
  /* For example, if the first bytes of the bitmap pertain to    */
  /* its top-most line, then the flow is `down'.  If these bytes */
  /* pertain to its lowest line, the the flow is `up'.           */

#define TT_Flow_Down  -1  /* bitmap is oriented from top to bottom */
#define TT_Flow_Up     1  /* bitmap is oriented from bottom to top */
#define TT_Flow_Error  0  /* an error occurred during rendering    */


  /* A structure used to describe the target bitmap or pixmap to the   */
  /* renderer.  Note that there is nothing in this structure that      */
  /* gives the nature of the buffer.                                   */
  /*                                                                   */
  /* IMPORTANT NOTE:                                                   */
  /*                                                                   */
  /*   In the case of a pixmap, the `width' and `cols' fields must     */
  /*   have the _same_ values, and _must_ be padded to 32-bits, i.e.,  */
  /*   be a multiple of 4.  Clipping problems will arise otherwise,    */
  /*   if not even page faults!                                        */
  /*                                                                   */
  /*   The typical settings are:                                       */
  /*                                                                   */
  /*   - for a WxH bitmap:                                             */
  /*                                                                   */
  /*       rows  = H                                                   */
  /*       cols  = (W+7) / 8                                           */
  /*       width = W                                                   */
  /*       flow  = your_choice                                         */
  /*                                                                   */
  /*   - for a WxH pixmap:                                             */
  /*                                                                   */
  /*       rows  = H                                                   */
  /*       cols  = (W+3) & ~3                                          */
  /*       width = cols                                                */
  /*       flow  = your_choice                                         */

  struct  TT_Raster_Map_
  {
    int    rows;    /* number of rows                    */
    int    cols;    /* number of columns (bytes) per row */
    int    width;   /* number of pixels per line         */
    int    flow;    /* bitmap orientation                */

    void*  bitmap;  /* bit/pixmap buffer                 */
    long   size;    /* bit/pixmap size in bytes          */
  };

  typedef struct TT_Raster_Map_  TT_Raster_Map;


  /* ------ The font header TrueType table structure ------ */

  struct  TT_Header_
  {
    TT_Fixed   Table_Version;
    TT_Fixed   Font_Revision;

    TT_Long    CheckSum_Adjust;
    TT_Long    Magic_Number;

    TT_UShort  Flags;
    TT_UShort  Units_Per_EM;

    TT_Long    Created [2];
    TT_Long    Modified[2];

    TT_FWord   xMin;
    TT_FWord   yMin;
    TT_FWord   xMax;
    TT_FWord   yMax;

    TT_UShort  Mac_Style;
    TT_UShort  Lowest_Rec_PPEM;

    TT_Short   Font_Direction;
    TT_Short   Index_To_Loc_Format;
    TT_Short   Glyph_Data_Format;
  };

  typedef struct TT_Header_  TT_Header;


  /* ------ The horizontal header TrueType table structure ------ */

  /*******************************************************/
  /*  This structure is the one defined by the TrueType  */
  /*  specification, plus two fields used to link the    */
  /*  font-units metrics to the header.                  */

  struct  TT_Horizontal_Header_
  {
    TT_Fixed   Version;
    TT_FWord   Ascender;
    TT_FWord   Descender;
    TT_FWord   Line_Gap;

    TT_UFWord  advance_Width_Max;      /* advance width maximum */

    TT_FWord   min_Left_Side_Bearing;  /* minimum left-sb       */
    TT_FWord   min_Right_Side_Bearing; /* minimum right-sb      */
    TT_FWord   xMax_Extent;            /* xmax extents          */
    TT_FWord   caret_Slope_Rise;
    TT_FWord   caret_Slope_Run;

    TT_Short   Reserved0,
               Reserved1,
               Reserved2,
               Reserved3,
               Reserved4;

    TT_Short   metric_Data_Format;
    TT_UShort  number_Of_HMetrics;

    /* The following fields are not defined by the TrueType specification */
    /* but they're used to connect the metrics header to the relevant     */
    /* `HMTX' or `VMTX' table.                                            */

    void*      long_metrics;
    void*      short_metrics;
  };

  typedef struct TT_Horizontal_Header_  TT_Horizontal_Header;


  /*******************************************************/
  /*  This structure is the one defined by the TrueType  */
  /*  specification.  Note that it has exactly the same  */
  /*  layout as the horizontal header (both are loaded   */
  /*  by the same function).                             */

  struct  TT_Vertical_Header_
  {
    TT_Fixed   Version;
    TT_FWord   Ascender;
    TT_FWord   Descender;
    TT_FWord   Line_Gap;

    TT_UFWord  advance_Height_Max;      /* advance height maximum */

    TT_FWord   min_Top_Side_Bearing;    /* minimum left-sb or top-sb       */
    TT_FWord   min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb   */
    TT_FWord   yMax_Extent;             /* xmax or ymax extents            */
    TT_FWord   caret_Slope_Rise;
    TT_FWord   caret_Slope_Run;
    TT_FWord   caret_Offset;

    TT_Short   Reserved1,
               Reserved2,
               Reserved3,
               Reserved4;

    TT_Short   metric_Data_Format;
    TT_UShort  number_Of_VMetrics;

    /* The following fields are not defined by the TrueType specification */
    /* but they're used to connect the metrics header to the relevant     */
    /* `HMTX' or `VMTX' table.                                            */

    void*      long_metrics;
    void*      short_metrics;
  };

  typedef struct TT_Vertical_Header_  TT_Vertical_Header;


  /* ------ The OS/2 table ------ */

  /************************************************************************/
  /* Note that since FreeType 1.3, we support Mac fonts which do not have */
  /* an OS/2 table.  In this case the `version' field will be set to      */
  /* 0xFFFF by the table loader; all other fields should be 0.            */

  struct  TT_OS2_
  {
    TT_UShort  version;                /* 0x0001 */
    TT_FWord   xAvgCharWidth;
    TT_UShort  usWeightClass;
    TT_UShort  usWidthClass;
    TT_Short   fsType;
    TT_FWord   ySubscriptXSize;
    TT_FWord   ySubscriptYSize;
    TT_FWord   ySubscriptXOffset;
    TT_FWord   ySubscriptYOffset;
    TT_FWord   ySuperscriptXSize;
    TT_FWord   ySuperscriptYSize;
    TT_FWord   ySuperscriptXOffset;
    TT_FWord   ySuperscriptYOffset;
    TT_FWord   yStrikeoutSize;
    TT_FWord   yStrikeoutPosition;
    TT_Short   sFamilyClass;

    TT_Byte    panose[10];

    TT_ULong   ulUnicodeRange1;        /* Bits 0-31   */
    TT_ULong   ulUnicodeRange2;        /* Bits 32-63  */
    TT_ULong   ulUnicodeRange3;        /* Bits 64-95  */
    TT_ULong   ulUnicodeRange4;        /* Bits 96-127 */

    TT_Char    achVendID[4];

    TT_UShort  fsSelection;
    TT_UShort  usFirstCharIndex;
    TT_UShort  usLastCharIndex;
    TT_Short   sTypoAscender;
    TT_Short   sTypoDescender;
    TT_Short   sTypoLineGap;
    TT_UShort  usWinAscent;
    TT_UShort  usWinDescent;

    /* only version 1 tables: */

    TT_ULong   ulCodePageRange1;       /* Bits 0-31   */
    TT_ULong   ulCodePageRange2;       /* Bits 32-63  */
  };

  typedef struct TT_OS2_  TT_OS2;


  /* ------ The PostScript table ------ */

  struct  TT_Postscript_
  {
    TT_Fixed  FormatType;
    TT_Fixed  italicAngle;
    TT_FWord  underlinePosition;
    TT_FWord  underlineThickness;
    TT_ULong  isFixedPitch;
    TT_ULong  minMemType42;
    TT_ULong  maxMemType42;
    TT_ULong  minMemType1;
    TT_ULong  maxMemType1;

    /* Glyph names follow in the file, but we don't         */
    /* load them by default.  See the ftxpost.c extension.  */
  };

  typedef struct TT_Postscript_  TT_Postscript;


  /* ------ The horizontal device metrics table (`hdmx') ------ */

  struct  TT_Hdmx_Record_
  {
    TT_Byte   ppem;
    TT_Byte   max_width;
    TT_Byte*  widths;
  };

  typedef struct TT_Hdmx_Record_  TT_Hdmx_Record;


  struct  TT_Hdmx_
  {
    TT_UShort        version;
    TT_Short         num_records;
    TT_Hdmx_Record*  records;
  };

  typedef struct TT_Hdmx_  TT_Hdmx;


  /* A structure used to describe face properties. */

  struct  TT_Face_Properties_
  {
    TT_UShort  num_Glyphs;      /* number of glyphs in face              */
    TT_UShort  max_Points;      /* maximum number of points in a glyph   */
    TT_UShort  max_Contours;    /* maximum number of contours in a glyph */

    TT_UShort  num_CharMaps;    /* number of charmaps in the face     */
    TT_UShort  num_Names;       /* number of name records in the face */

    TT_ULong   num_Faces;  /* 1 for normal TrueType files, and the  */
                           /* number of embedded faces for TrueType */
                           /* collections                           */

    TT_Header*             header;        /* TrueType header table          */
    TT_Horizontal_Header*  horizontal;    /* TrueType horizontal header     */
    TT_OS2*                os2;           /* TrueType OS/2 table            */
    TT_Postscript*         postscript;    /* TrueType Postscript table      */
    TT_Hdmx*               hdmx;          /* TrueType hor. dev. metr. table */
    TT_Vertical_Header*    vertical;      /* TT Vertical header, if present */
  };

  typedef struct TT_Face_Properties_  TT_Face_Properties;


  /* Here are the definitions of the handle types used for FreeType's */
  /* most common objects accessed by the client application.  We use  */
  /* a simple trick:                                                  */
  /*                                                                  */
  /*   Each handle type is a structure that only contains one         */
  /*   pointer.  The advantage of structures is that they are         */
  /*   mutually exclusive types.  We could have defined the           */
  /*   following types:                                               */
  /*                                                                  */
  /*     typedef void*  TT_Stream;                                    */
  /*     typedef void*  TT_Face;                                      */
  /*     typedef void*  TT_Instance;                                  */
  /*     typedef void*  TT_Glyph;                                     */
  /*     typedef void*  TT_CharMap;                                   */
  /*                                                                  */
  /*   but these would have allowed lines like:                       */
  /*                                                                  */
  /*      stream = instance;                                          */
  /*                                                                  */
  /*   in the client code this would be a severe bug, unnoticed       */
  /*   by the compiler!                                               */
  /*                                                                  */
  /*   Thus, we enforce type checking with a simple language          */
  /*   trick...                                                       */
  /*                                                                  */
  /*   NOTE:  Some macros are defined in tttypes.h to perform         */
  /*          automatic type conversions for library hackers...       */

  struct TT_Engine_   { void*  z; };
  struct TT_Stream_   { void*  z; };
  struct TT_Face_     { void*  z; };
  struct TT_Instance_ { void*  z; };
  struct TT_Glyph_    { void*  z; };
  struct TT_CharMap_  { void*  z; };

  typedef struct TT_Engine_    TT_Engine;    /* engine instance           */
  typedef struct TT_Stream_    TT_Stream;    /* stream handle type        */
  typedef struct TT_Face_      TT_Face;      /* face handle type          */
  typedef struct TT_Instance_  TT_Instance;  /* instance handle type      */
  typedef struct TT_Glyph_     TT_Glyph;     /* glyph handle type         */
  typedef struct TT_CharMap_   TT_CharMap;   /* character map handle type */


  /* Almost all functions return an error code of this type. */

  typedef long  TT_Error;


  /*******************************************************************/
  /*                                                                 */
  /*  FreeType API                                                   */
  /*                                                                 */
  /*  All these begin with a `TT_' prefix.                           */
  /*                                                                 */
  /*  Most of them are implemented in the `ttapi.c' source file.     */
  /*                                                                 */
  /*******************************************************************/

  /* Get version information. */

  EXPORT_DEF
  TT_Error  TT_FreeType_Version( int  *major,
                                 int  *minor );


  /* Initialize the engine. */

  EXPORT_DEF
  TT_Error  TT_Init_FreeType( TT_Engine*  engine );


  /* Finalize the engine, and release all allocated objects. */

  EXPORT_DEF
  TT_Error  TT_Done_FreeType( TT_Engine  engine );


  /* Set the gray level palette.  This is an array of 5 bytes used */
  /* to produce the font smoothed pixmaps.  By convention:         */
  /*                                                               */
  /*  palette[0] = background (white)                              */
  /*  palette[1] = light                                           */
  /*  palette[2] = medium                                          */
  /*  palette[3] = dark                                            */
  /*  palette[4] = foreground (black)                              */
  /*                                                               */

  EXPORT_DEF
  TT_Error  TT_Set_Raster_Gray_Palette( TT_Engine  engine,
                                        TT_Byte*   palette );


  /* ----------------------- face management ----------------------- */

  /* Open a new TrueType font file, and returns a handle for  */
  /* it in variable '*face'.                                  */
  /*                                                          */
  /* Note: The file can be either a TrueType file (*.ttf) or  */
  /*       a TrueType collection (*.ttc, in this case, only   */
  /*       the first face is opened).  The number of faces in */
  /*       the same collection can be obtained in the face's  */
  /*       properties, using TT_Get_Face_Properties() and the */
  /*       `max_Faces' field.                                 */

  EXPORT_DEF
  TT_Error  TT_Open_Face( TT_Engine       engine,
                          const TT_Text*  fontPathName,
                          TT_Face*        face );


  /* Open a TrueType font file located inside a collection. */
  /* The font is assigned by its index in `fontIndex'.      */

  EXPORT_DEF
  TT_Error  TT_Open_Collection( TT_Engine       engine,
                                const TT_Text*  collectionPathName,
                                TT_ULong        fontIndex,
                                TT_Face*        face );


  /* Return face properties in the `properties' structure.          */
  /*                                                                */
  /* Note that since version 1.3, we support font files with no     */
  /* OS/2 table (mainly old Mac fonts).  In this case, the OS/2     */
  /* `version' field will be set to 0xFFFF, and all other fields    */
  /* will be zeroed.                                                */

  EXPORT_DEF
  TT_Error  TT_Get_Face_Properties( TT_Face              face,
                                    TT_Face_Properties*  properties );


  /* Set a face object's generic pointer */

  EXPORT_DEF
  TT_Error  TT_Set_Face_Pointer( TT_Face  face,
                                 void*    data );


  /* Get a face object's generic pointer */

  EXPORT_DEF
  void*  TT_Get_Face_Pointer( TT_Face  face );


  /* Close a face's file handle to save system resources.  The file */
  /* will be re-opened automatically on the next disk access.       */

  EXPORT_DEF
  TT_Error  TT_Flush_Face( TT_Face  face );

  /* Get a face's glyph metrics expressed in font units.  Returns any    */
  /* number of arrays.  Set the fields to NULL if you are not interested */
  /* by a given array.                                                   */

  EXPORT_DEF
  TT_Error  TT_Get_Face_Metrics( TT_Face     face,
                                 TT_UShort   firstGlyph,
                                 TT_UShort   lastGlyph,
                                 TT_Short*   leftBearings,
                                 TT_UShort*  widths,
                                 TT_Short*   topBearings,
                                 TT_UShort*  heights );


  /* Close a given font object, destroying all associated */
  /* instances.                                           */

  EXPORT_DEF
  TT_Error  TT_Close_Face( TT_Face  face );


  /* Get font or table data. */

  EXPORT_DEF
  TT_Error  TT_Get_Font_Data( TT_Face   face,
                              TT_ULong  tag,
                              TT_Long   offset,
                              void*     buffer,
                              TT_Long*  length );


/* A simple macro to build table tags from ASCII chars */

#define MAKE_TT_TAG( _x1, _x2, _x3, _x4 ) \
          (((TT_ULong)_x1 << 24) |        \
           ((TT_ULong)_x2 << 16) |        \
           ((TT_ULong)_x3 << 8)  |        \
            (TT_ULong)_x4)

  /* ----------------------- instance management -------------------- */

  /* Open a new font instance and returns an instance handle */
  /* for it in `*instance'.                                  */

  EXPORT_DEF
  TT_Error  TT_New_Instance( TT_Face       face,
                             TT_Instance*  instance );


  /* Set device resolution for a given instance.  The values are      */
  /* given in dpi (Dots Per Inch).  Default is 96 in both directions. */

  EXPORT_DEF
  TT_Error  TT_Set_Instance_Resolutions( TT_Instance  instance,
                                         TT_UShort    xResolution,
                                         TT_UShort    yResolution );


  /* Set the pointsize for a given instance.  Default is 10pt. */

  EXPORT_DEF
  TT_Error  TT_Set_Instance_CharSize( TT_Instance  instance,
                                      TT_F26Dot6   charSize );

  EXPORT_DEF
  TT_Error  TT_Set_Instance_CharSizes( TT_Instance  instance,
                                       TT_F26Dot6   charWidth,
                                       TT_F26Dot6   charHeight );

#define TT_Set_Instance_PointSize( ins, ptsize )   \
            TT_Set_Instance_CharSize( ins, ptsize*64L )

  EXPORT_DEF
  TT_Error  TT_Set_Instance_PixelSizes( TT_Instance  instance,
                                        TT_UShort    pixelWidth,
                                        TT_UShort    pixelHeight,
                                        TT_F26Dot6   pointSize );


  /* This function has been deprecated!  Do not use it, as it      */
  /* doesn't work reliably.  You can perfectly control hinting     */
  /* yourself when loading glyphs, then apply transforms as usual. */

  EXPORT_DEF
  TT_Error  TT_Set_Instance_Transform_Flags( TT_Instance  instance,
                                             TT_Bool      rotated,
                                             TT_Bool      stretched );


  /* Return instance metrics in `metrics'. */

  EXPORT_DEF
  TT_Error  TT_Get_Instance_Metrics( TT_Instance           instance,
                                     TT_Instance_Metrics*  metrics );


  /* Set an instance's generic pointer. */

  EXPORT_DEF
  TT_Error  TT_Set_Instance_Pointer( TT_Instance  instance,
                                     void*        data );


  /* Get an instance's generic pointer. */

  EXPORT_DEF
  void*     TT_Get_Instance_Pointer( TT_Instance  instance );


  /* Close a given instance object, destroying all associated data. */

  EXPORT_DEF
  TT_Error  TT_Done_Instance( TT_Instance  instance );

  /* ----------------------- glyph management ----------------------- */

  /* Create a new glyph object related to the given `face'. */

  EXPORT_DEF
  TT_Error  TT_New_Glyph( TT_Face    face,
                          TT_Glyph*  glyph );


  /* Discard (and destroy) a given glyph object. */

  EXPORT_DEF
  TT_Error  TT_Done_Glyph( TT_Glyph  glyph );


#define TTLOAD_SCALE_GLYPH                    1
#define TTLOAD_HINT_GLYPH                     2
#define TTLOAD_PEDANTIC                     128
#define TTLOAD_IGNORE_GLOBAL_ADVANCE_WIDTH  256

#define TTLOAD_DEFAULT  (TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH)


  /* Load and process (scale/transform and hint) a glyph from the */
  /* given `instance'.  The glyph and instance handles must be    */
  /* related to the same face object.  The glyph index can be     */
  /* computed with a call to TT_Char_Index().                     */
  /*                                                              */
  /* The 'load_flags' argument is a combination of the macros     */
  /* TTLOAD_SCALE_GLYPH and TTLOAD_HINT_GLYPH.  Hinting will be   */
  /* applied only if the scaling is selected.                     */
  /*                                                              */
  /* If scaling is off (i.e., load_flags = 0), the returned       */
  /* outlines are in EM square coordinates (also called FUnits),  */
  /* extracted directly from the font with no hinting.  Other     */
  /* glyph metrics are also in FUnits.                            */
  /*                                                              */
  /* If scaling is on, the returned outlines are in fractional    */
  /* pixel units (i.e. TT_F26Dot6 = 26.6 fixed floats).           */
  /*                                                              */
  /* NOTE: The glyph index must be in the range 0..num_glyphs-1,  */
  /*       where `num_glyphs' is the total number of glyphs in    */
  /*       the font file (given in the face properties).          */

  EXPORT_DEF
  TT_Error  TT_Load_Glyph( TT_Instance  instance,
                           TT_Glyph     glyph,
                           TT_UShort    glyphIndex,
                           TT_UShort    loadFlags );


  /* Return glyph outline pointers in `outline'.  Note that the returned */
  /* pointers are owned by the glyph object, and will be destroyed with  */
  /* it.  The client application should _not_ change the pointers.       */

  EXPORT_DEF
  TT_Error  TT_Get_Glyph_Outline( TT_Glyph     glyph,
                                  TT_Outline*  outline );


  /* Copy the glyph metrics into `metrics'. */

  EXPORT_DEF
  TT_Error  TT_Get_Glyph_Metrics( TT_Glyph           glyph,
                                  TT_Glyph_Metrics*  metrics );


  /* Copy the glyph's big metrics into `metrics'. */
  /* Necessary to obtain vertical metrics.        */

  EXPORT_DEF
  TT_Error  TT_Get_Glyph_Big_Metrics( TT_Glyph               glyph,
                                      TT_Big_Glyph_Metrics*  metrics );


  /* Render the glyph into a bitmap, with given position offsets.     */
  /*                                                                  */
  /* Note: Only use integer pixel offsets to preserve the fine        */
  /*       hinting of the glyph and the `correct' anti-aliasing       */
  /*       (where vertical and horizontal stems aren't grayed).  This */
  /*       means that `xOffset' and `yOffset' must be multiples       */
  /*       of 64!                                                     */

  EXPORT_DEF
  TT_Error  TT_Get_Glyph_Bitmap( TT_Glyph        glyph,
                                 TT_Raster_Map*  map,
                                 TT_F26Dot6      xOffset,
                                 TT_F26Dot6      yOffset );


  /* Render the glyph into a pixmap, with given position offsets.     */
  /*                                                                  */
  /* Note: Only use integer pixel offsets to preserve the fine        */
  /*       hinting of the glyph and the `correct' anti-aliasing       */
  /*       (where vertical and horizontal stems aren't grayed).  This */
  /*       means that `xOffset' and `yOffset' must be multiples       */
  /*       of 64!                                                     */

  EXPORT_DEF
  TT_Error  TT_Get_Glyph_Pixmap( TT_Glyph        glyph,
                                 TT_Raster_Map*  map,
                                 TT_F26Dot6      xOffset,
                                 TT_F26Dot6      yOffset );

  /* ----------------------- outline support ------------------------ */

  /* Allocate a new outline.  Reserve space for `numPoints' and */
  /* `numContours'.                                             */

  EXPORT_DEF
  TT_Error  TT_New_Outline( TT_UShort    numPoints,
                            TT_Short     numContours,
                            TT_Outline*  outline );


  /* Release an outline. */

  EXPORT_DEF
  TT_Error  TT_Done_Outline( TT_Outline*  outline );


  /* Copy an outline into another one. */

  EXPORT_DEF
  TT_Error  TT_Copy_Outline( TT_Outline*  source,
                             TT_Outline*  target );


  /* Render an outline into a bitmap. */

  EXPORT_DEF
  TT_Error  TT_Get_Outline_Bitmap( TT_Engine       engine,
                                   TT_Outline*     outline,
                                   TT_Raster_Map*  map );


  /* Render an outline into a pixmap. */

  EXPORT_DEF
  TT_Error  TT_Get_Outline_Pixmap( TT_Engine       engine,
                                   TT_Outline*     outline,
                                   TT_Raster_Map*  map );


  /* Return an outline's bounding box -- this function is slow as it */
  /* performs a complete scan-line process, without drawing, to get  */
  /* the most accurate values.                                       */

  EXPORT_DEF
  TT_Error  TT_Get_Outline_BBox( TT_Outline*  outline,
                                 TT_BBox*     bbox );


  /* Apply a transformation to a glyph outline. */

  EXPORT_DEF
  void  TT_Transform_Outline( TT_Outline*  outline,
                              TT_Matrix*   matrix );


  /* Apply a translation to a glyph outline. */

  EXPORT_DEF
  void  TT_Translate_Outline( TT_Outline*  outline,
                              TT_F26Dot6   xOffset,
                              TT_F26Dot6   yOffset );


  /* Apply a transformation to a vector. */

  EXPORT_DEF
  void  TT_Transform_Vector( TT_F26Dot6*  x,
                             TT_F26Dot6*  y,
                             TT_Matrix*   matrix );


  /* Compute A*B/C with 64 bits intermediate precision. */

  EXPORT_DEF
  TT_Long  TT_MulDiv( TT_Long  A,
                      TT_Long  B,
                      TT_Long  C );


  /* Compute A*B/0x10000 with 64 bits intermediate precision. */
  /* Useful to multiply by a 16.16 fixed float value.         */

  EXPORT_DEF
  TT_Long  TT_MulFix( TT_Long  A,
                      TT_Long  B );


  /* ----------------- character mapping support --------------- */

  /* Return the number of character mappings found in this file. */
  /* Returns -1 in case of failure (invalid face handle).        */
  /*                                                             */
  /* DON'T USE THIS FUNCTION!  IT HAS BEEN DEPRECATED!           */
  /*                                                             */
  /* It is retained for backwards compatibility only and will    */
  /* fail on 16bit systems.                                      */
  /*                                                             */
  /* You can now get the charmap count in the `num_CharMaps'     */
  /* field of a face's properties.                               */
  /*                                                             */

  EXPORT_DEF
  int  TT_Get_CharMap_Count( TT_Face  face );


  /* Return the ID of charmap number `charmapIndex' of a given face */
  /* used to enumerate the charmaps present in a TrueType file.     */

  EXPORT_DEF
  TT_Error  TT_Get_CharMap_ID( TT_Face     face,
                               TT_UShort   charmapIndex,
                               TT_UShort*  platformID,
                               TT_UShort*  encodingID );


  /* Look up the character maps found in `face' and return a handle */
  /* for the one matching `platformID' and `platformEncodingID'     */
  /* (see the TrueType specs relating to the `cmap' table for       */
  /* information on these ID numbers).  Returns an error code.      */
  /* In case of failure, the handle is set to NULL and is invalid.  */

  EXPORT_DEF
  TT_Error  TT_Get_CharMap( TT_Face      face,
                            TT_UShort    charmapIndex,
                            TT_CharMap*  charMap );


  /* Translate a character code through a given character map   */
  /* and return the corresponding glyph index to be used in     */
  /* a TT_Load_Glyph() call.  This function returns 0 in case   */
  /* of failure.                                                */

  EXPORT_DEF
  TT_UShort  TT_Char_Index( TT_CharMap  charMap,
                            TT_UShort   charCode );

  /* --------------------- names table support ------------------- */

  /* Return the number of name strings found in the name table.  */
  /* Returns -1 in case of failure (invalid face handle).        */
  /*                                                             */
  /* DON'T USE THIS FUNCTION!  IT HAS BEEN DEPRECATED!           */
  /*                                                             */
  /* It is retained for backwards compatibility only and will    */
  /* fail on 16bit systems.                                      */
  /*                                                             */
  /* You can now get the number of name strings in a face with   */
  /* the `num_Names' field of its properties.                    */

  EXPORT_DEF
  int  TT_Get_Name_Count( TT_Face  face );


  /* Return the ID of the name number `nameIndex' of a given face */
  /* used to enumerate the charmaps present in a TrueType file.   */

  EXPORT_DEF
  TT_Error  TT_Get_Name_ID( TT_Face     face,
                            TT_UShort   nameIndex,
                            TT_UShort*  platformID,
                            TT_UShort*  encodingID,
                            TT_UShort*  languageID,
                            TT_UShort*  nameID );


  /* Return the address and length of the name number `nameIndex' */
  /* of a given face in the variables `stringPtr' resp. `length'. */
  /* The string is part of the face object and shouldn't be       */
  /* written to or released.                                      */
  /*                                                              */
  /* Note that for an invalid platform ID a null pointer will be  */
  /* returned.                                                    */

  EXPORT_DEF
  TT_Error  TT_Get_Name_String( TT_Face      face,
                                TT_UShort    nameIndex,
                                TT_String**  stringPtr,
                                TT_UShort*   length );


#ifdef __cplusplus
  }
#endif

#endif /* FREETYPE_H */


/* END */
 

FT_CONF.H   、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/* This file is part of the FreeType project */

/* ft_conf.h for the ANSI Build */


/* we need the following because there are some typedefs in this file */

#ifndef FT_CONF_H
#define FT_CONF_H

#define POOL_SIZE 0x20000   //freerype

typedef struct _MEMT {
        struct _MEMT     *top;         /*                   */
        unsigned long      size;        /*                   */
}MEMT;

/* Define to empty if the keyword does not work.  */
/* #undef const */

/* Define if you have a working `mmap' system call.  */
#undef HAVE_MMAP

/* Define if you have the <stdlib.h> header file.  */
#define HAVE_STDLIB_H

/* Define if you have the getpagesize function.  */
#undef HAVE_GETPAGESIZE

/* Define if you have the memcpy function.  */
#define HAVE_MEMCPY

/* Define if you have the memmove function.  */
#define HAVE_MEMMOVE

/* Define if you have the valloc function.  */
#undef HAVE_VALLOC

/* Define if you have the <fcntl.h> header file. Unix-specific  */
#undef  HAVE_FCNTL_H

/* command.com can't pipe stderr into a file; any message would be */
/* written into the graphics screen.                               */
#define HAVE_PRINT_FUNCTION 1

#define Print( format, ap )  vfprintf( stdout, (format), (ap) )


/* The number of bytes in a int. We use the ANSI header file limits.h */
/* for determining it since there is no easy way to guess.            */
/*                                                                    */
#include <limits.h>
#if   UINT_MAX == 0xFFFF
#define SIZEOF_INT  2
#elif UINT_MAX == 0xFFFFFFFF
#define SIZEOF_INT  4
#else
#error "Unsupported number of bytes in `int' type!"
#endif

/* We now try to guess the size of longs in the same way */
/*                                                       */
#if   ULONG_MAX == 0xFFFFFFFF
#define SIZEOF_LONG 4
#elif ULONG_MAX == 0xFFFFFFFFFFFFFFFF
#define SIZEOF_LONG 8
#else
#error "Unsupported number of bytes in `long' type!"
#endif


/**********************************************************************/
/*                                                                    */
/*  The following configuration macros can be tweaked manually by     */
/*  a developer to turn on or off certain features or options in the  */
/*  TrueType engine. This may be useful to tune it for specific       */
/*  purposes..                                                        */
/*                                                                    */
/**********************************************************************/


/*************************************************************************/
/* Define this if the underlying operating system uses a different       */
/* character width than 8bit for file names.  You must then also supply  */
/* a typedef declaration for defining 'TT_Text'.  Default is off.        */

/* #define HAVE_TT_TEXT */


/*************************************************************************/
/* Define this if you want to generate code to support engine extensions */
/* Default is on, but if you're satisfied by the basic services provided */
/* by the engine and need no extensions, undefine this configuration     */
/* macro to save a few more bytes.                                       */

#define  TT_CONFIG_OPTION_EXTEND_ENGINE


/*************************************************************************/
/* Define this if you want to generate code to support gray-scaling,     */
/* a.k.a. font-smoothing or anti-aliasing. Default is on, but you can    */
/* disable it if you don't need it.                                      */

#define  TT_CONFIG_OPTION_GRAY_SCALING


/*************************************************************************/
/* Define this if you want to completely disable the use of the bytecode */
/* interpreter.  Doing so will produce a much smaller library, but the   */
/* quality of the rendered glyphs will enormously suffer from this.      */
/*                                                                       */
/* This switch was introduced due to the Apple patents issue which       */
/* emerged recently on the FreeType lists.  We still do not have Apple's */
/* opinion on the subject and will change this as soon as we have.       */

#undef   TT_CONFIG_OPTION_NO_INTERPRETER


/*************************************************************************/
/* Define this if you want to use a big 'switch' statement within the    */
/* bytecode interpreter. Because some non-optimizing compilers are not   */
/* able to produce jump tables from such statements, undefining this     */
/* configuration macro will generate the appropriate C jump table in     */
/* ttinterp.c. If you use an optimizing compiler, you should leave it    */
/* defined for better performance and code compactness..                 */

#define  TT_CONFIG_OPTION_INTERPRETER_SWITCH


/*************************************************************************/
/* Define this if you want to build a 'static' version of the TrueType   */
/* bytecode interpreter. This will produce much bigger code, which       */
/* _may_ be faster on some architectures..                               */
/*                                                                       */
/* Do NOT DEFINE THIS is you build a thread-safe version of the engine   */
/*                                                                       */
#undef TT_CONFIG_OPTION_STATIC_INTERPRETER


/*************************************************************************/
/* Define this if you want to build a 'static' version of the scan-line  */
/* converter (the component which in charge of converting outlines into  */
/* bitmaps). This will produce a bigger object file for "ttraster.c",    */
/* which _may_ be faster on some architectures..                         */
/*                                                                       */
/* Do NOT DEFINE THIS is you build a thread-safe version of the engine   */
/*                                                                       */
#define TT_CONFIG_OPTION_STATIC_RASTER


/*************************************************************************/
/* Define TT_CONFIG_THREAD_SAFE if you want to build a thread-safe       */
/* version of the library.                                               */

#undef  TT_CONFIG_OPTION_THREAD_SAFE


/**********************************************************************/
/*                                                                    */
/*  The following macros are used to define the debug level, as well  */
/*  as individual tracing levels for each component. There are        */
/*  currently three modes of operation :                              */
/*                                                                    */
/*  - trace mode (define DEBUG_LEVEL_TRACE)                           */
/*                                                                    */
/*      The engine prints all error messages, as well as tracing      */
/*      ones, filtered by each component's level                      */
/*                                                                    */
/*  - debug mode (define DEBUG_LEVEL_ERROR)                           */
/*                                                                    */
/*      Disable tracing, but keeps error output and assertion         */
/*      checks.                                                       */
/*                                                                    */
/*  - release mode (don't define anything)                            */
/*                                                                    */
/*      Don't include error-checking or tracing code in the           */
/*      engine's code. Ideal for releases.                            */
/*                                                                    */
/* NOTE :                                                             */
/*                                                                    */
/*   Each component's tracing level is defined in its own source.     */
/*                                                                    */
/**********************************************************************/

/* Define if you want to use the tracing debug mode */
#undef  DEBUG_LEVEL_TRACE

/* Define if you want to use the error debug mode - ignored if */
/* DEBUG_LEVEL_TRACE is defined                                */
#undef  DEBUG_LEVEL_ERROR


/**************************************************************************/
/* Definition of various integer sizes. These types are used by ttcalc    */
/* and ttinterp (for the 64-bit integers) only..                          */

#if SIZEOF_INT == 4

  typedef signed int      TT_Int32;
  typedef unsigned int    TT_Word32;

#elif SIZEOF_LONG == 4

  typedef signed long     TT_Int32;
  typedef unsigned long   TT_Word32;

#else
#error "no 32bit type found"
#endif

#if SIZEOF_LONG == 8

/* LONG64 must be defined when a 64-bit type is available */
/* INT64 must then be defined to this type..              */
#define LONG64
#define INT64   long

#else

/* GCC provides the non-ANSI 'long long' 64-bit type.  You can activate    */
/* by defining the TT_USE_LONG_LONG macro in 'ft_conf.h'.  Note that this  */
/* will produce many -ansi warnings during library compilation.            */
#ifdef TT_USE_LONG_LONG

#define LONG64
#define INT64   long long

#endif /* TT_USE_LONG_LONG */
#endif

#endif /* FT_CONF_H */


/* END */
 

FTERRID.H  、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/*******************************************************************
 *
 *  fterrid.h
 *
 *    TrueType Error ID definitions
 *
 *  Copyright 1996-1999 by
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 *  This file is part of the FreeType project, and may only be used
 *  modified and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 ******************************************************************/

#ifndef FREETYPE_H
#error "Don't include this file! Use freetype.h instead."
#endif

#ifndef FTERRID_H
#define FTERRID_H

  /************************ error codes declaration **************/

  /* The error codes are grouped in 'classes' used to indicate the */
  /* 'level' at which the error happened.                          */
  /* The class is given by an error code's high byte.              */


  /* ------------- Success is always 0 -------- */

#define TT_Err_Ok                       0


  /* -------- High-level API error codes ------ */

#define TT_Err_Invalid_Face_Handle      0x001
#define TT_Err_Invalid_Instance_Handle  0x002
#define TT_Err_Invalid_Glyph_Handle     0x003
#define TT_Err_Invalid_CharMap_Handle   0x004
#define TT_Err_Invalid_Result_Address   0x005
#define TT_Err_Invalid_Glyph_Index      0x006
#define TT_Err_Invalid_Argument         0x007
#define TT_Err_Could_Not_Open_File      0x008
#define TT_Err_File_Is_Not_Collection   0x009

#define TT_Err_Table_Missing            0x00A
#define TT_Err_Invalid_Horiz_Metrics    0x00B
#define TT_Err_Invalid_CharMap_Format   0x00C
#define TT_Err_Invalid_PPem             0x00D
#define TT_Err_Invalid_Vert_Metrics     0x00E

#define TT_Err_Invalid_File_Format      0x010

#define TT_Err_Invalid_Engine           0x020
#define TT_Err_Too_Many_Extensions      0x021
#define TT_Err_Extensions_Unsupported   0x022
#define TT_Err_Invalid_Extension_Id     0x023

#define TT_Err_No_Vertical_Data         0x030

#define TT_Err_Max_Profile_Missing      0x080
#define TT_Err_Header_Table_Missing     0x081
#define TT_Err_Horiz_Header_Missing     0x082
#define TT_Err_Locations_Missing        0x083
#define TT_Err_Name_Table_Missing       0x084
#define TT_Err_CMap_Table_Missing       0x085
#define TT_Err_Hmtx_Table_Missing       0x086
#define TT_Err_OS2_Table_Missing        0x087
#define TT_Err_Post_Table_Missing       0x088
#define TT_Err_Glyf_Table_Missing       0x089


  /* -------- Memory component error codes ---- */

  /* this error indicates that an operation cannot */
  /* be performed due to memory exhaustion.        */

#define TT_Err_Out_Of_Memory            0x100


  /* -------- File component error codes ------ */

  /* these error codes indicate that the file could */
  /* not be accessed properly.  Usually, this means */
  /* a broken font file!                            */

#define TT_Err_Invalid_File_Offset      0x200
#define TT_Err_Invalid_File_Read        0x201
#define TT_Err_Invalid_Frame_Access     0x202


  /* -------- Glyph loader error codes -------- */

  /* Produced only by the glyph loader, these error */
  /* codes indicate a broken glyph in a font file.  */

#define TT_Err_Too_Many_Points          0x300
#define TT_Err_Too_Many_Contours        0x301
#define TT_Err_Invalid_Composite        0x302
#define TT_Err_Too_Many_Ins             0x303


  /* --- bytecode interpreter error codes ----- */

  /* These error codes are produced by the TrueType */
  /* bytecode interpreter.  They usually indicate a */
  /* broken font file, a broken glyph within a font */
  /* file, or a bug in the interpreter!             */

#define TT_Err_Invalid_Opcode           0x400
#define TT_Err_Too_Few_Arguments        0x401
#define TT_Err_Stack_Overflow           0x402
#define TT_Err_Code_Overflow            0x403
#define TT_Err_Bad_Argument             0x404
#define TT_Err_Divide_By_Zero           0x405
#define TT_Err_Storage_Overflow         0x406
#define TT_Err_Cvt_Overflow             0x407
#define TT_Err_Invalid_Reference        0x408
#define TT_Err_Invalid_Distance         0x409
#define TT_Err_Interpolate_Twilight     0x40A
#define TT_Err_Debug_OpCode             0x40B
#define TT_Err_ENDF_In_Exec_Stream      0x40C
#define TT_Err_Out_Of_CodeRanges        0x40D
#define TT_Err_Nested_DEFS              0x40E
#define TT_Err_Invalid_CodeRange        0x40F
#define TT_Err_Invalid_Displacement     0x410
#define TT_Err_Execution_Too_Long       0x411


  /* ------ internal failure error codes ----- */

  /* These error codes are produced when an incoherent */
  /* library state has been detected.  These reflect a */
  /* severe bug in the engine! (Or a major overwrite   */
  /* of your application into the library's data.)     */

#define TT_Err_Nested_Frame_Access      0x500
#define TT_Err_Invalid_Cache_List       0x501
#define TT_Err_Could_Not_Find_Context   0x502
#define TT_Err_Unlisted_Object          0x503


  /* ---- scan-line converter error codes ----- */

  /* These error codes are produced by the raster component.  */
  /* They indicate that an outline structure was incoherently */
  /* setup, or that you're trying to render an horribly       */
  /* complex glyph!                                           */

#define TT_Err_Raster_Pool_Overflow     0x600
#define TT_Err_Raster_Negative_Height   0x601
#define TT_Err_Raster_Invalid_Value     0x602
#define TT_Err_Raster_Not_Initialized   0x603

#endif /* FTERRID_H */


/* END */
 

ftnameid.h  、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/*******************************************************************
 *
 *  ftnameid.h
 *
 *    TrueType Name ID definitions
 *
 *  Copyright 1996-1999 by
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 *  This file is part of the FreeType project, and may only be used
 *  modified and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 ******************************************************************/

#ifndef FREETYPE_H
#error "Don't include this file! Use freetype.h instead."
#endif

#ifndef FTNAMEID_H
#define FTNAMEID_H

/*
 * possible values for the 'Platform' identifier code in the name
 * records of the TTF "name" table
 */

#define TT_PLATFORM_APPLE_UNICODE       0
#define TT_PLATFORM_MACINTOSH           1
#define TT_PLATFORM_ISO                 2
#define TT_PLATFORM_MICROSOFT           3


/*
 * possible values of the platform specific encoding identifier field in
 * the name records of the TTF "name" table when the 'Platform' identifier
 * code is TT_PLATFORM_APPLE_UNICODE
 */

#define TT_APPLE_ID_DEFAULT             0
#define TT_APPLE_ID_UNICODE_1_1         1
#define TT_APPLE_ID_ISO_10646           2
#define TT_APPLE_ID_UNICODE_2_0         3


/*
 * possible values of the platform specific encoding identifier field in
 * the name records of the TTF "name" table when the 'Platform' identifier
 * code is TT_PLATFORM_MACINTOSH
 */

#define TT_MAC_ID_ROMAN                 0
#define TT_MAC_ID_JAPANESE              1
#define TT_MAC_ID_TRADITIONAL_CHINESE   2
#define TT_MAC_ID_KOREAN                3
#define TT_MAC_ID_ARABIC                4
#define TT_MAC_ID_HEBREW                5
#define TT_MAC_ID_GREEK                 6
#define TT_MAC_ID_RUSSIAN               7
#define TT_MAC_ID_RSYMBOL               8
#define TT_MAC_ID_DEVANAGARI            9
#define TT_MAC_ID_GURMUKHI              10
#define TT_MAC_ID_GUJARATI              11
#define TT_MAC_ID_ORIYA                 12
#define TT_MAC_ID_BENGALI               13
#define TT_MAC_ID_TAMIL                 14
#define TT_MAC_ID_TELUGU                15
#define TT_MAC_ID_KANNADA               16
#define TT_MAC_ID_MALAYALAM             17
#define TT_MAC_ID_SINHALESE             18
#define TT_MAC_ID_BURMESE               19
#define TT_MAC_ID_KHMER                 20
#define TT_MAC_ID_THAI                  21
#define TT_MAC_ID_LAOTIAN               22
#define TT_MAC_ID_GEORGIAN              23
#define TT_MAC_ID_ARMENIAN              24
#define TT_MAC_ID_MALDIVIAN             25
#define TT_MAC_ID_SIMPLIFIED_CHINESE    25
#define TT_MAC_ID_TIBETAN               26
#define TT_MAC_ID_MONGOLIAN             27
#define TT_MAC_ID_GEEZ                  28
#define TT_MAC_ID_SLAVIC                29
#define TT_MAC_ID_VIETNAMESE            30
#define TT_MAC_ID_SINDHI                31
#define TT_MAC_ID_UNINTERP              32


/*
 * possible values of the platform specific encoding identifier field in
 * the name records of the TTF "name" table when the 'Platform' identifier
 * code is TT_PLATFORM_ISO
 */

#define TT_ISO_ID_7BIT_ASCII    0
#define TT_ISO_ID_10646         1
#define TT_ISO_ID_8859_1        2


/*
 * possible values of the platform specific encoding identifier field in
 * the name records of the TTF "name" table when the 'Platform' identifier
 * code is TT_PLATFORM_MICROSOFT
 */

#define TT_MS_ID_SYMBOL_CS      0
#define TT_MS_ID_UNICODE_CS     1
#define TT_MS_ID_SJIS           2
#define TT_MS_ID_GB2312         3
#define TT_MS_ID_BIG_5          4
#define TT_MS_ID_WANSUNG        5
#define TT_MS_ID_JOHAB          6

/*
 * possible values of the language identifier field in the name records of
 * the TTF "name" table when the 'Platform' identifier code is
 * TT_PLATFORM_MACINTOSH
 *
 * the canonical source for the Apple assigned Language ID's is at
 * http://fonts.apple.com/TTRefMan/RM06/Chap6name.html
 */

#define TT_MAC_LANGID_ENGLISH                           0
#define TT_MAC_LANGID_FRENCH                            1
#define TT_MAC_LANGID_GERMAN                            2
#define TT_MAC_LANGID_ITALIAN                           3
#define TT_MAC_LANGID_DUTCH                             4
#define TT_MAC_LANGID_SWEDISH                           5
#define TT_MAC_LANGID_SPANISH                           6
#define TT_MAC_LANGID_DANISH                            7
#define TT_MAC_LANGID_PORTUGUESE                        8
#define TT_MAC_LANGID_NORWEGIAN                         9
#define TT_MAC_LANGID_HEBREW                            10
#define TT_MAC_LANGID_JAPANESE                          11
#define TT_MAC_LANGID_ARABIC                            12
#define TT_MAC_LANGID_FINNISH                           13
#define TT_MAC_LANGID_GREEK                             14
#define TT_MAC_LANGID_ICELANDIC                         15
#define TT_MAC_LANGID_MALTESE                           16
#define TT_MAC_LANGID_TURKISH                           17
#define TT_MAC_LANGID_CROATIAN                          18
#define TT_MAC_LANGID_CHINESE_TRADITIONAL               19
#define TT_MAC_LANGID_URDU                              20
#define TT_MAC_LANGID_HINDI                             21
#define TT_MAC_LANGID_THAI                              22
#define TT_MAC_LANGID_KOREAN                            23
#define TT_MAC_LANGID_LITHUANIAN                        24
#define TT_MAC_LANGID_POLISH                            25
#define TT_MAC_LANGID_HUNGARIAN                         26
#define TT_MAC_LANGID_ESTONIAN                          27
#define TT_MAC_LANGID_LETTISH                           28
#define TT_MAC_LANGID_SAAMISK                           29
#define TT_MAC_LANGID_FAEROESE                          30
#define TT_MAC_LANGID_FARSI                             31
#define TT_MAC_LANGID_RUSSIAN                           32
#define TT_MAC_LANGID_CHINESE_SIMPLIFIED                33
#define TT_MAC_LANGID_FLEMISH                           34
#define TT_MAC_LANGID_IRISH                             35
#define TT_MAC_LANGID_ALBANIAN                          36
#define TT_MAC_LANGID_ROMANIAN                          37
#define TT_MAC_LANGID_CZECH                             38
#define TT_MAC_LANGID_SLOVAK                            39
#define TT_MAC_LANGID_SLOVENIAN                         40
#define TT_MAC_LANGID_YIDDISH                           41
#define TT_MAC_LANGID_SERBIAN                           42
#define TT_MAC_LANGID_MACEDONIAN                        43
#define TT_MAC_LANGID_BULGARIAN                         44
#define TT_MAC_LANGID_UKRAINIAN                         45
#define TT_MAC_LANGID_BYELORUSSIAN                      46
#define TT_MAC_LANGID_UZBEK                             47
#define TT_MAC_LANGID_KAZAKH                            48
#define TT_MAC_LANGID_AZERBAIJANI                       49
#define TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT         50
#define TT_MAC_LANGID_ARMENIAN                          51
#define TT_MAC_LANGID_GEORGIAN                          52
#define TT_MAC_LANGID_MOLDAVIAN                         53
#define TT_MAC_LANGID_KIRGHIZ                           54
#define TT_MAC_LANGID_TAJIKI                            55
#define TT_MAC_LANGID_TURKMEN                           56
#define TT_MAC_LANGID_MONGOLIAN                         57
#define TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT         58
#define TT_MAC_LANGID_PASHTO                            59
#define TT_MAC_LANGID_KURDISH                           60
#define TT_MAC_LANGID_KASHMIRI                          61
#define TT_MAC_LANGID_SINDHI                            62
#define TT_MAC_LANGID_TIBETAN                           63
#define TT_MAC_LANGID_NEPALI                            64
#define TT_MAC_LANGID_SANSKRIT                          65
#define TT_MAC_LANGID_MARATHI                           66
#define TT_MAC_LANGID_BENGALI                           67
#define TT_MAC_LANGID_ASSAMESE                          68
#define TT_MAC_LANGID_GUJARATI                          69
#define TT_MAC_LANGID_PUNJABI                           70
#define TT_MAC_LANGID_ORIYA                             71
#define TT_MAC_LANGID_MALAYALAM                         72
#define TT_MAC_LANGID_KANNADA                           73
#define TT_MAC_LANGID_TAMIL                             74
#define TT_MAC_LANGID_TELUGU                            75
#define TT_MAC_LANGID_SINHALESE                         76
#define TT_MAC_LANGID_BURMESE                           77
#define TT_MAC_LANGID_KHMER                             78
#define TT_MAC_LANGID_LAO                               79
#define TT_MAC_LANGID_VIETNAMESE                        80
#define TT_MAC_LANGID_INDONESIAN                        81
#define TT_MAC_LANGID_TAGALOG                           82
#define TT_MAC_LANGID_MALAY_ROMAN_SCRIPT                83
#define TT_MAC_LANGID_MALAY_ARABIC_SCRIPT               84
#define TT_MAC_LANGID_AMHARIC                           85
#define TT_MAC_LANGID_TIGRINYA                          86
#define TT_MAC_LANGID_GALLA                             87
#define TT_MAC_LANGID_SOMALI                            88
#define TT_MAC_LANGID_SWAHILI                           89
#define TT_MAC_LANGID_RUANDA                            90
#define TT_MAC_LANGID_RUNDI                             91
#define TT_MAC_LANGID_CHEWA                             92
#define TT_MAC_LANGID_MALAGASY                          93
#define TT_MAC_LANGID_ESPERANTO                         94
#define TT_MAC_LANGID_WELSH                             128
#define TT_MAC_LANGID_BASQUE                            129
#define TT_MAC_LANGID_CATALAN                           130
#define TT_MAC_LANGID_LATIN                             131
#define TT_MAC_LANGID_QUECHUA                           132
#define TT_MAC_LANGID_GUARANI                           133
#define TT_MAC_LANGID_AYMARA                            134
#define TT_MAC_LANGID_TATAR                             135
#define TT_MAC_LANGID_UIGHUR                            136
#define TT_MAC_LANGID_DZONGKHA                          137
#define TT_MAC_LANGID_JAVANESE                          138
#define TT_MAC_LANGID_SUNDANESE                         139
#define TT_MAC_LANGID_SCOTTISH_GAELIC                   140
#define TT_MAC_LANGID_IRISH_GAELIC                      141
#define TT_MAC_LANGID_BRETON                            142
#define TT_MAC_LANGID_INUKTITUT                         143


/*
 * possible values of the language identifier field in the name records of
 * the TTF "name" table when the 'Platform' identifier code is
 * TT_PLATFORM_MICROSOFT
 *
 * the canonical source for the MS assigned LCID's is at
 * http://www.microsoft.com/typography/OTSPEC/lcid-cp.txt
 */

#define TT_MS_LANGID_ARABIC_SAUDI_ARABIA                0x0401
#define TT_MS_LANGID_ARABIC_IRAQ                        0x0801
#define TT_MS_LANGID_ARABIC_EGYPT                       0x0c01
#define TT_MS_LANGID_ARABIC_LIBYA                       0x1001
#define TT_MS_LANGID_ARABIC_ALGERIA                     0x1401
#define TT_MS_LANGID_ARABIC_MOROCCO                     0x1801
#define TT_MS_LANGID_ARABIC_TUNISIA                     0x1c01
#define TT_MS_LANGID_ARABIC_OMAN                        0x2001
#define TT_MS_LANGID_ARABIC_YEMEN                       0x2401
#define TT_MS_LANGID_ARABIC_SYRIA                       0x2801
#define TT_MS_LANGID_ARABIC_JORDAN                      0x2c01
#define TT_MS_LANGID_ARABIC_LEBANON                     0x3001
#define TT_MS_LANGID_ARABIC_KUWAIT                      0x3401
#define TT_MS_LANGID_ARABIC_UAE                         0x3801
#define TT_MS_LANGID_ARABIC_BAHRAIN                     0x3c01
#define TT_MS_LANGID_ARABIC_QATAR                       0x4001
#define TT_MS_LANGID_BULGARIAN_BULGARIA                 0x0402
#define TT_MS_LANGID_CATALAN_SPAIN                      0x0403
#define TT_MS_LANGID_CHINESE_TAIWAN                     0x0404
#define TT_MS_LANGID_CHINESE_PRC                        0x0804
#define TT_MS_LANGID_CHINESE_HONG_KONG                  0x0c04
#define TT_MS_LANGID_CHINESE_SINGAPORE                  0x1004
#define TT_MS_LANGID_CHINESE_MACAU                      0x1404
#define TT_MS_LANGID_CZECH_CZECH_REPUBLIC               0x0405
#define TT_MS_LANGID_DANISH_DENMARK                     0x0406
#define TT_MS_LANGID_GERMAN_GERMANY                     0x0407
#define TT_MS_LANGID_GERMAN_SWITZERLAND                 0x0807
#define TT_MS_LANGID_GERMAN_AUSTRIA                     0x0c07
#define TT_MS_LANGID_GERMAN_LUXEMBOURG                  0x1007
#define TT_MS_LANGID_GERMAN_LIECHTENSTEI                0x1407
#define TT_MS_LANGID_GREEK_GREECE                       0x0408
#define TT_MS_LANGID_ENGLISH_UNITED_STATES              0x0409
#define TT_MS_LANGID_ENGLISH_UNITED_KINGDOM             0x0809
#define TT_MS_LANGID_ENGLISH_AUSTRALIA                  0x0c09
#define TT_MS_LANGID_ENGLISH_CANADA                     0x1009
#define TT_MS_LANGID_ENGLISH_NEW_ZEALAND                0x1409
#define TT_MS_LANGID_ENGLISH_IRELAND                    0x1809
#define TT_MS_LANGID_ENGLISH_SOUTH_AFRICA               0x1c09
#define TT_MS_LANGID_ENGLISH_JAMAICA                    0x2009
#define TT_MS_LANGID_ENGLISH_CARIBBEAN                  0x2409
#define TT_MS_LANGID_ENGLISH_BELIZE                     0x2809
#define TT_MS_LANGID_ENGLISH_TRINIDAD                   0x2c09
#define TT_MS_LANGID_ENGLISH_ZIMBABWE                   0x3009
#define TT_MS_LANGID_ENGLISH_PHILIPPINES                0x3409
#define TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT     0x040a
#define TT_MS_LANGID_SPANISH_MEXICO                     0x080a
#define TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT   0x0c0a
#define TT_MS_LANGID_SPANISH_GUATEMALA                  0x100a
#define TT_MS_LANGID_SPANISH_COSTA_RICA                 0x140a
#define TT_MS_LANGID_SPANISH_PANAMA                     0x180a
#define TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC         0x1c0a
#define TT_MS_LANGID_SPANISH_VENEZUELA                  0x200a
#define TT_MS_LANGID_SPANISH_COLOMBIA                   0x240a
#define TT_MS_LANGID_SPANISH_PERU                       0x280a
#define TT_MS_LANGID_SPANISH_ARGENTINA                  0x2c0a
#define TT_MS_LANGID_SPANISH_ECUADOR                    0x300a
#define TT_MS_LANGID_SPANISH_CHILE                      0x340a
#define TT_MS_LANGID_SPANISH_URUGUAY                    0x380a
#define TT_MS_LANGID_SPANISH_PARAGUAY                   0x3c0a
#define TT_MS_LANGID_SPANISH_BOLIVIA                    0x400a
#define TT_MS_LANGID_SPANISH_EL_SALVADOR                0x440a
#define TT_MS_LANGID_SPANISH_HONDURAS                   0x480a
#define TT_MS_LANGID_SPANISH_NICARAGUA                  0x4c0a
#define TT_MS_LANGID_SPANISH_PUERTO_RICO                0x500a
#define TT_MS_LANGID_FINNISH_FINLAND                    0x040b
#define TT_MS_LANGID_FRENCH_FRANCE                      0x040c
#define TT_MS_LANGID_FRENCH_BELGIUM                     0x080c
#define TT_MS_LANGID_FRENCH_CANADA                      0x0c0c
#define TT_MS_LANGID_FRENCH_SWITZERLAND                 0x100c
#define TT_MS_LANGID_FRENCH_LUXEMBOURG                  0x140c
#define TT_MS_LANGID_FRENCH_MONACO                      0x180c
#define TT_MS_LANGID_HEBREW_ISRAEL                      0x040d
#define TT_MS_LANGID_HUNGARIAN_HUNGARY                  0x040e
#define TT_MS_LANGID_ICELANDIC_ICELAND                  0x040f
#define TT_MS_LANGID_ITALIAN_ITALY                      0x0410
#define TT_MS_LANGID_ITALIAN_SWITZERLAND                0x0810
#define TT_MS_LANGID_JAPANESE_JAPAN                     0x0411
#define TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA      0x0412
#define TT_MS_LANGID_KOREAN_JOHAB_KOREA                 0x0812
#define TT_MS_LANGID_DUTCH_NETHERLANDS                  0x0413
#define TT_MS_LANGID_DUTCH_BELGIUM                      0x0813
#define TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL            0x0414
#define TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK           0x0814
#define TT_MS_LANGID_POLISH_POLAND                      0x0415
#define TT_MS_LANGID_PORTUGUESE_BRAZIL                  0x0416
#define TT_MS_LANGID_PORTUGUESE_PORTUGAL                0x0816
#define TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND         0x0417
#define TT_MS_LANGID_ROMANIAN_ROMANIA                   0x0418
#define TT_MS_LANGID_MOLDAVIAN_MOLDAVIA                 0x0818
#define TT_MS_LANGID_RUSSIAN_RUSSIA                     0x0419
#define TT_MS_LANGID_RUSSIAN_MOLDAVIA                   0x0819
#define TT_MS_LANGID_CROATIAN_CROATIA                   0x041a
#define TT_MS_LANGID_SERBIAN_SERBIA_LATIN               0x081a
#define TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC            0x0c1a
#define TT_MS_LANGID_SLOVAK_SLOVAKIA                    0x041b
#define TT_MS_LANGID_ALBANIAN_ALBANIA                   0x041c
#define TT_MS_LANGID_SWEDISH_SWEDEN                     0x041d
#define TT_MS_LANGID_SWEDISH_FINLAND                    0x081d
#define TT_MS_LANGID_THAI_THAILAND                      0x041e
#define TT_MS_LANGID_TURKISH_TURKEY                     0x041f
#define TT_MS_LANGID_URDU_PAKISTAN                      0x0420
#define TT_MS_LANGID_INDONESIAN_INDONESIA               0x0421
#define TT_MS_LANGID_UKRAINIAN_UKRAINE                  0x0422
#define TT_MS_LANGID_BELARUSIAN_BELARUS                 0x0423
#define TT_MS_LANGID_SLOVENE_SLOVENIA                   0x0424
#define TT_MS_LANGID_ESTONIAN_ESTONIA                   0x0425
#define TT_MS_LANGID_LATVIAN_LATVIA                     0x0426
#define TT_MS_LANGID_LITHUANIAN_LITHUANIA               0x0427
#define TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA       0x0827
#define TT_MS_LANGID_MAORI_NEW_ZEALAND                  0x0428
#define TT_MS_LANGID_FARSI_IRAN                         0x0429
#define TT_MS_LANGID_VIETNAMESE_VIET_NAM                0x042a
#define TT_MS_LANGID_ARMENIAN_ARMENIA                   0x042b
#define TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN             0x042c
#define TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC          0x082c
#define TT_MS_LANGID_BASQUE_SPAIN                       0x042d
#define TT_MS_LANGID_SORBIAN_GERMANY                    0x042e
#define TT_MS_LANGID_MACEDONIAN_MACEDONIA               0x042f
#define TT_MS_LANGID_SUTU_SOUTH_AFRICA                  0x0430
#define TT_MS_LANGID_TSONGA_SOUTH_AFRICA                0x0431
#define TT_MS_LANGID_TSWANA_SOUTH_AFRICA                0x0432
#define TT_MS_LANGID_VENDA_SOUTH_AFRICA                 0x0433
#define TT_MS_LANGID_XHOSA_SOUTH_AFRICA                 0x0434
#define TT_MS_LANGID_ZULU_SOUTH_AFRICA                  0x0435
#define TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA             0x0436
#define TT_MS_LANGID_GEORGIAN_GEORGIA                   0x0437
#define TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS            0x0438
#define TT_MS_LANGID_HINDI_INDIA                        0x0439
#define TT_MS_LANGID_MALTESE_MALTA                      0x043a
#define TT_MS_LANGID_SAAMI_LAPONIA                      0x043b
#define TT_MS_LANGID_IRISH_GAELIC_IRELAND               0x043c
#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM     0x083c
#define TT_MS_LANGID_MALAY_MALAYSIA                     0x043e
#define TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM            0x083e
#define TT_MS_LANGID_KAZAK_KAZAKSTAN                    0x043f
#define TT_MS_LANGID_SWAHILI_KENYA                      0x0441
#define TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN             0x0443
#define TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC          0x0843
#define TT_MS_LANGID_TATAR_TATARSTAN                    0x0444
#define TT_MS_LANGID_BENGALI_INDIA                      0x0445
#define TT_MS_LANGID_PUNJABI_INDIA                      0x0446
#define TT_MS_LANGID_GUJARATI_INDIA                     0x0447
#define TT_MS_LANGID_ORIYA_INDIA                        0x0448
#define TT_MS_LANGID_TAMIL_INDIA                        0x0449
#define TT_MS_LANGID_TELUGU_INDIA                       0x044a
#define TT_MS_LANGID_KANNADA_INDIA                      0x044b
#define TT_MS_LANGID_MALAYALAM_INDIA                    0x044c
#define TT_MS_LANGID_ASSAMESE_INDIA                     0x044d
#define TT_MS_LANGID_MARATHI_INDIA                      0x044e
#define TT_MS_LANGID_SANSKRIT_INDIA                     0x044f
#define TT_MS_LANGID_KONKANI_INDIA                      0x0457


/*
 * possible values of the 'Name' identifier field in the name records of
 * the TTF "name" table.  These values are platform independent.
 */

#define TT_NAME_ID_COPYRIGHT            0
#define TT_NAME_ID_FONT_FAMILY          1
#define TT_NAME_ID_FONT_SUBFAMILY       2
#define TT_NAME_ID_UNIQUE_ID            3
#define TT_NAME_ID_FULL_NAME            4
#define TT_NAME_ID_VERSION_STRING       5
#define TT_NAME_ID_PS_NAME              6
#define TT_NAME_ID_TRADEMARK            7
/* the following values are from the OpenType spec */
#define TT_NAME_ID_MANUFACTURER         8
#define TT_NAME_ID_DESIGNER             9
#define TT_NAME_ID_DESCRIPTION          10
#define TT_NAME_ID_VENDOR_URL           11
#define TT_NAME_ID_DESIGNER_URL         12
#define TT_NAME_ID_LICENSE              13
#define TT_NAME_ID_LICENSE_URL          14
/* number 15 is reserved */
#define TT_NAME_ID_PREFERRED_FAMILY     16
#define TT_NAME_ID_PREFERRED_SUBFAMILY  17
#define TT_NAME_ID_MAC_FULL_NAME        18


/*
 * Bit Mask values for the Unicode Ranges from the TTF "OS2 " table.
 */

/* General Scripts Area */

/* Bit  0   C0 Controls and Basic Latin */
#define TT_UCR_BASIC_LATIN                     (1L <<  0) /* U+0000-U+007F */
/* Bit  1   C1 Controls and Latin-1 Supplement */
#define TT_UCR_LATIN1_SUPPLEMENT               (1L <<  1) /* U+0080-U+00FF */
/* Bit  2   Latin Extended-A */
#define TT_UCR_LATIN_EXTENDED_A                (1L <<  2) /* U+0100-U+017F */
/* Bit  3   Latin Extended-B */
#define TT_UCR_LATIN_EXTENDED_B                (1L <<  3) /* U+0180-U+024F */
/* Bit  4   IPA Extensions */
#define TT_UCR_IPA_EXTENSIONS                  (1L <<  4) /* U+0250-U+02AF */
/* Bit  5   Spacing Modifier Letters */
#define TT_UCR_SPACING_MODIFIER                (1L <<  5) /* U+02B0-U+02FF */
/* Bit  6   Combining Diacritical Marks */
#define TT_UCR_COMBINING_DIACRITICS            (1L <<  6) /* U+0300-U+036F */
/* Bit  7   Greek */
#define TT_UCR_GREEK                           (1L <<  7) /* U+0370-U+03FF */
/* Bit 8 is reserved (was: Greek Symbols and Coptic) */
/* Bit  9   Cyrillic */
#define TT_UCR_CYRILLIC                        (1L <<  9) /* U+0400-U+04FF */
/* Bit 10   Armenian */
#define TT_UCR_ARMENIAN                        (1L << 10) /* U+0530-U+058F */
/* Bit 11   Hebrew */
#define TT_UCR_HEBREW                          (1L << 11) /* U+0590-U+05FF */
/* Bit 12 is reserved (was: Hebrew Extended) */
/* Bit 13   Arabic */
#define TT_UCR_ARABIC                          (1L << 13) /* U+0600-U+06FF */
/* Bit 14 is reserved (was: Arabic Extended) */
/* Bit 15   Devanagari */
#define TT_UCR_DEVANAGARI                      (1L << 15) /* U+0900-U+097F */
/* Bit 16   Bengali */
#define TT_UCR_BENGALI                         (1L << 16) /* U+0980-U+09FF */
/* Bit 17   Gurmukhi */
#define TT_UCR_GURMUKHI                        (1L << 17) /* U+0A00-U+0A7F */
/* Bit 18   Gujarati */
#define TT_UCR_GUJARATI                        (1L << 18) /* U+0A80-U+0AFF */
/* Bit 19   Oriya */
#define TT_UCR_ORIYA                           (1L << 19) /* U+0B00-U+0B7F */
/* Bit 20   Tamil */
#define TT_UCR_TAMIL                           (1L << 20) /* U+0B80-U+0BFF */
/* Bit 21   Telugu */
#define TT_UCR_TELUGU                          (1L << 21) /* U+0C00-U+0C7F */
/* Bit 22   Kannada */
#define TT_UCR_KANNADA                         (1L << 22) /* U+0C80-U+0CFF */
/* Bit 23   Malayalam */
#define TT_UCR_MALAYALAM                       (1L << 23) /* U+0D00-U+0D7F */
/* Bit 24   Thai */
#define TT_UCR_THAI                            (1L << 24) /* U+0E00-U+0E7F */
/* Bit 25   Lao */
#define TT_UCR_LAO                             (1L << 25) /* U+0E80-U+0EFF */
/* Bit 26   Georgian */
#define TT_UCR_GEORGIAN                        (1L << 26) /* U+10A0-U+10FF */
/* Bit 27 is reserved (was Georgian Extended) */
/* Bit 28   Hangul Jamo */
#define TT_UCR_HANGUL_JAMO                     (1L << 28) /* U+1100-U+11FF */
/* Bit 29   Latin Extended Additional */
#define TT_UCR_LATIN_EXTENDED_ADDITIONAL       (1L << 29) /* U+1E00-U+1EFF */
/* Bit 30   Greek Extended */
#define TT_UCR_GREEK_EXTENDED                  (1L << 30) /* U+1F00-U+1FFF */

/* Symbols Area */

/* Bit 31   General Punctuation */
#define TT_UCR_GENERAL_PUNCTUATION             (1L << 31) /* U+2000-U+206F */
/* Bit 32   Superscripts And Subscripts */
#define TT_UCR_SUPERSCRIPTS_SUBSCRIPTS         (1L <<  0) /* U+2070-U+209F */
/* Bit 33   Currency Symbols */
#define TT_UCR_CURRENCY_SYMBOLS                (1L <<  1) /* U+20A0-U+20CF */
/* Bit 34   Combining Diacritical Marks For Symbols */
#define TT_UCR_COMBINING_DIACRITICS_SYMB       (1L <<  2) /* U+20D0-U+20FF */
/* Bit 35   Letterlike Symbols */
#define TT_UCR_LETTERLIKE_SYMBOLS              (1L <<  3) /* U+2100-U+214F */
/* Bit 36   Number Forms */
#define TT_UCR_NUMBER_FORMS                    (1L <<  4) /* U+2150-U+218F */
/* Bit 37   Arrows */
#define TT_UCR_ARROWS                          (1L <<  5) /* U+2190-U+21FF */
/* Bit 38   Mathematical Operators */
#define TT_UCR_MATHEMATICAL_OPERATORS          (1L <<  6) /* U+2200-U+22FF */
/* Bit 39 Miscellaneous Technical */
#define TT_UCR_MISCELLANEOUS_TECHNICAL         (1L <<  7) /* U+2300-U+23FF */
/* Bit 40   Control Pictures */
#define TT_UCR_CONTROL_PICTURES                (1L <<  8) /* U+2400-U+243F */
/* Bit 41   Optical Character Recognition */
#define TT_UCR_OCR                             (1L <<  9) /* U+2440-U+245F */
/* Bit 42   Enclosed Alphanumerics */
#define TT_UCR_ENCLOSED_ALPHANUMERICS          (1L << 10) /* U+2460-U+24FF */
/* Bit 43   Box Drawing */
#define TT_UCR_BOX_DRAWING                     (1L << 11) /* U+2500-U+257F */
/* Bit 44   Block Elements */
#define TT_UCR_BLOCK_ELEMENTS                  (1L << 12) /* U+2580-U+259F */
/* Bit 45   Geometric Shapes */
#define TT_UCR_GEOMETRIC_SHAPES                (1L << 13) /* U+25A0-U+25FF */
/* Bit 46   Miscellaneous Symbols */
#define TT_UCR_MISCELLANEOUS_SYMBOLS           (1L << 14) /* U+2600-U+26FF */
/* Bit 47   Dingbats */
#define TT_UCR_DINGBATS                        (1L << 15) /* U+2700-U+27BF */

/* CJK Phonetics and Symbols Area */

/* Bit 48   CJK Symbols And Punctuation */
#define TT_UCR_CJK_SYMBOLS                     (1L << 16) /* U+3000-U+303F */
/* Bit 49   Hiragana */
#define TT_UCR_HIRAGANA                        (1L << 17) /* U+3040-U+309F */
/* Bit 50   Katakana */
#define TT_UCR_KATAKANA                        (1L << 18) /* U+30A0-U+30FF */
/* Bit 51   Bopomofo */
#define TT_UCR_BOPOMOFO                        (1L << 19) /* U+3100-U+312F */
/* Bit 52   Hangul Compatibility Jamo */
#define TT_UCR_HANGUL_COMPATIBILITY_JAMO       (1L << 20) /* U+3130-U+318F */
/* Bit 53   CJK Miscellaneous */
#define TT_UCR_CJK_MISC                        (1L << 21) /* U+3190-U+319F */
/* Bit 54   Enclosed CJK Letters And Months */
#define TT_UCR_ENCLOSED_CJK_LETTERS_MONTHS     (1L << 22) /* U+3200-U+32FF */
/* Bit 55   CJK Compatibility */
#define TT_UCR_CJK_COMPATIBILITY               (1L << 23) /* U+3300-U+33FF */

/* Hangul Syllables Area */

/* Bit 56   Hangul */
#define TT_UCR_HANGUL                          (1L << 24) /* U+AC00-U+D7A3 */

/* Surrogates Area */

/* Bit 57   Surrogates */
#define TT_UCR_SURROGATES                      (1L << 25) /* U+D800-U+DFFF */
/* Bit 58 is reserved for Unicode SubRanges */

/* CJK Ideographs Area */

/* Bit 59   CJK Unified Ideographs */
#define TT_UCR_CJK_UNIFIED_IDEOGRAPHS          (1L << 27) /* U+4E00-U+9FFF */

/* Private Use Area */

/* Bit 60   Private Use */
#define TT_UCR_PRIVATE_USE                     (1L << 28) /* U+E000-U+F8FF */

/* Compatibility Area and Specials */

/* Bit 61   CJK Compatibility Ideographs */
#define TT_UCR_CJK_COMPATIBILITY_IDEOGRAPHS    (1L << 29) /* U+F900-U+FAFF */
/* Bit 62   Alphabetic Presentation Forms */
#define TT_UCR_ALPHABETIC_PRESENTATION_FORMS   (1L << 30) /* U+FB00-U+FB4F */
/* Bit 63   Arabic Presentation Forms-A */
#define TT_UCR_ARABIC_PRESENTATIONS_A          (1L << 31) /* U+FB50-U+FSFF */
/* Bit 64   Combining Half Marks */
#define TT_UCR_COMBINING_HALF_MARKS            (1L <<  0) /* U+FE20-U+FE2F */
/* Bit 65   CJK Compatibility Forms */
#define TT_UCR_CJK_COMPATIBILITY_FORMS         (1L <<  1) /* U+FE30-U+FE4F */
/* Bit 66   Small Form Variants */
#define TT_UCR_SMALL_FORM_VARIANTS             (1L <<  2) /* U+FE50-U+FE6F */
/* Bit 67   Arabic Presentation Forms-B */
#define TT_UCR_ARABIC_PRESENTATIONS_B          (1L <<  3) /* U+FE70-U+FEFF */
/* Bit 68   Halfwidth And Fullwidth Forms */
#define TT_UCR_HALFWIDTH_FULLWIDTH_FORMS       (1L <<  4) /* U+FF00-U+FFEF */
/* Bit 69   Specials */
#define TT_UCR_SPECIALS                        (1L <<  5) /* U+FEFF,
                                                             U+FFF0-U+FFFF */
/* Bit 70   Tibetan */
#define TT_UCR_TIBETAN                         (1L <<  6) /* U+0F00-U+0FBF */


/* Some compilers have a very limited length of identifiers. */

//#if defined( __TURBOC__ ) &&  __TURBOC__ < 0x0410 || defined( __PACIFIC__ )
//    #define HAVE_LIMIT_ON_IDENTS
//#endif

#ifndef HAVE_LIMIT_ON_IDENTS

/*
 *  Here some alias #defines in order to be clearer.
 *
 *  These are not always #defined to stay within the 31 character limit
 *  which some compilers have.
 *
 *  Credits go to Dave Hoo <dhoo@flash.net> for pointing out that modern
 *  Borland compilers (read: from BC++ 3.1 on) can increase this limit.
 *  If you get a warning with such a compiler, use the -i40 switch.
 */
 
#define TT_UCR_ARABIC_PRESENTATION_FORMS_A      \
         TT_UCR_ARABIC_PRESENTATIONS_A
#define TT_UCR_ARABIC_PRESENTATION_FORMS_B      \
         TT_UCR_ARABIC_PRESENTATIONS_B           

#define TT_UCR_COMBINING_DIACRITICAL_MARKS      \
         TT_UCR_COMBINING_DIACRITICS
#define TT_UCR_COMBINING_DIACRITICAL_MARKS_SYMB \
         TT_UCR_COMBINING_DIACRITICS_SYMB

#endif /* ndef HAVE_LIMIT_ON_IDENTS */

#endif /* FTNAMEID_H */


/* END */
 

HEADER.H  、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/*******************************************************************
 *
 *  Function    :
 *
 *  Description :
 *
 *  Input  :
 *
 *  Output :
 *
 *  Notes  :
 *
 ******************************************************************/

/*******************************************************************
 *
 *  Function    :
 *
 *  Description :
 *
 *  Input  :  None
 *
 *  Output :  Error code.
 *
 ******************************************************************/

/*******************************************************************
 *
 *  Function    :
 *
 *  Description :
 *
 ******************************************************************/

/*******************************************************************
 *
 *  Component Name (e.g. TTRaster.C) + eventually a version number.
 *
 *  Component Short Description (e.g. Rasterizer).
 *
 *  Copyright 1996 David Turner, Robert Wilhelm and Werner Lemberg.
 *
 *  This file is part of the FreeType project, and may only be used
 *  modified and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT. By continuing to use, modify or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 ******************************************************************/
 

TTAPI.C   、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/*******************************************************************
 *
 *  ttapi.c
 *
 *    High-level interface implementation
 *
 *  Copyright 1996-1999 by
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 *  This file is part of the FreeType project, and may only be used,
 *  modified, and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 *  Notes:
 *
 *    This file is used to implement most of the functions that are
 *    defined in the file "freetype.h". However, two functions are
 *    implemented elsewhere :
 *
 *     TT_MulDiv and TT_MulFix  are in ttcalc.h/ttcalc.c
 *
 ******************************************************************/

#include "ttconfig.h"

#include "freetype.h"
#include "ttengine.h"
#include "ttcalc.h"
#include "ttmemory.h"
#include "ttcache.h"
#include "ttfile.h"
#include "ttobjs.h"
#include "ttload.h"
#include "ttgload.h"
#include "ttraster.h"
#include "ttextend.h"


/* required by the tracing mode */
#undef  TT_COMPONENT
#define TT_COMPONENT  trace_api


#ifdef TT_STATIC_RASTER
#define RAS_OPS  /* void */
#define RAS_OP   /* void */
#else
#define RAS_OPS  ((TRaster_Instance*)_engine->raster_component),
#define RAS_OP   ((TRaster_Instance*)_engine->raster_component)
#endif /* TT_STATIC_RASTER */


#define RENDER_Glyph( glyph, target ) \
          Render_Glyph( RAS_OPS  glyph, target )

#define RENDER_Gray_Glyph( glyph, target, palette ) \
          Render_Gray_Glyph( RAS_OPS  glyph, target, palette )

/*******************************************************************
 *
 *  Function    :  TT_FreeType_Version
 *
 *  Description :  Returns the major and minor version of the library.
 *
 *  Input  :  major, minor addresses
 *
 *  Output :  Error code.
 *
 *  MT-Note : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_FreeType_Version( int  *major, int  *minor )
  {
    if ( !major || !minor )
      return TT_Err_Invalid_Argument;

    *major = TT_FREETYPE_MAJOR;
    *minor = TT_FREETYPE_MINOR;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    : TT_Init_FreeType
 *
 *  Description : The library's engine initializer.  This function
 *                must be called prior to any call.
 *
 *  Input  :  engine        pointer to a FreeType engine instance
 *
 *  Output :  Error code.
 *
 *  MT-Note : This function should be called each time you want
 *            to create a TT_Engine.  It is not necessarily thread
 *            safe depending on the implementations of ttmemory,
 *            ttfile and ttmutex, so take care.  Their default
 *            implementations are safe, however.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Init_FreeType( TT_Engine*  engine )
  {
    PEngine_Instance  _engine;

    TT_Error  error;
    int       n;


    /* first of all, initialize memory sub-system */
    error = TTMemory_Init();
    if ( error )
      return error;

    /* Allocate engine instance */
    if ( ALLOC( _engine, sizeof ( TEngine_Instance ) ) )
      return error;

#undef  TT_FAIL
#define TT_FAIL( x )  ( error = x (_engine) ) != TT_Err_Ok

    /* Initalize components */
    if ( TT_FAIL( TTFile_Init  )  ||
         TT_FAIL( TTCache_Init )  ||
#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
         TT_FAIL( TTExtend_Init ) ||
#endif
         TT_FAIL( TTObjs_Init )   ||
         TT_FAIL( TTRaster_Init ) )
       goto Fail;

#undef TT_FAIL

    /* set the gray palette defaults: 0 to 4 */
    for ( n = 0; n < 5; n++ )
      _engine->raster_palette[n] = (Byte)n;  /* Conversion ok, some warn */

    /* create the engine lock */
    MUTEX_Create( _engine->lock );

    HANDLE_Set( *engine, _engine );
    return TT_Err_Ok;

  Fail:
    TT_Done_FreeType( *engine );
    HANDLE_Set( *engine, NULL );
    return error;
  }


/*******************************************************************
 *
 *  Function    : TT_Done_FreeType
 *
 *  Description : The library's engine finalizer.  This function
 *                will discard all active face and glyph objects
 *                from the heap.
 *
 *  Input  :  engine        FreeType engine instance
 *
 *  Output :  Error code.
 *
 *  MT-Note : Destroys an engine.  Not necessarily thread-safe
 *            depending on the implementations of ttmemory,
 *            ttfile and ttmutex.  The default implementations
 *            are safe, however.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Done_FreeType( TT_Engine  engine )
  {
    PEngine_Instance  _engine = HANDLE_Engine( engine );


    if ( !_engine )
      return TT_Err_Ok;

    MUTEX_Destroy( _engine->lock );

    TTRaster_Done( _engine );
    TTObjs_Done  ( _engine );
#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
    TTExtend_Done( _engine );
#endif
    TTCache_Done ( _engine );
    TTFile_Done  ( _engine );
    FREE( _engine );

    TTMemory_Done();

    return TT_Err_Ok;
  }


#ifdef TT_CONFIG_OPTION_GRAY_SCALING

/*******************************************************************
 *
 *  Function    :  TT_Set_Raster_Gray_Palette
 *
 *  Description :  Sets the gray-levels palette used for font
 *                 smoothing.
 *
 *  Input  :  engine        FreeType engine instance
 *            palette       address of palette (a 5 byte array)
 *
 *  Output :  Invalid argument if 'palette' is NULL.
 *
 *  MT-Note:  NO!  Unprotected modification of an engine's palette.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Raster_Gray_Palette( TT_Engine  engine,
                                        Byte*      palette )
  {
    int  i;


    if ( !palette )
      return TT_Err_Invalid_Argument;

    for ( i = 0; i < 5; i++ )
      HANDLE_Engine( engine )->raster_palette[i] = (Byte)palette[i];

    return TT_Err_Ok;
  }

#endif /* TT_CONFIG_OPTION_GRAY_SCALING */


/*******************************************************************
 *
 *  Function    :  TT_Open_Face
 *
 *  Description :  Creates a new face object from a given font file.
 *
 *  Input  :  engine        FreeType engine instance
 *            fontPathName  the font file's pathname
 *            face          adress of returned face handle
 *
 *  Output :  Error code.
 *
 *  Note :    The face handle is set to NULL in case of failure.
 *
 *  MT-Note : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Open_Face( TT_Engine       engine,
                          const TT_Text*  fontPathName,
                          TT_Face*        face )
  {
    PEngine_Instance  _engine = HANDLE_Engine( engine );

    TFont_Input  input;
    TT_Error     error;
    TT_Stream    stream;
    PFace        _face;


    if ( !_engine )
      return TT_Err_Invalid_Engine;

    /* open the file */
    error = TT_Open_Stream( fontPathName, &stream );
    if ( error )
      return error;

    input.stream    = stream;
    input.fontIndex = 0;
    input.engine    = _engine;

    /* Create and load the new face object - this is thread-safe */
    error = CACHE_New( _engine->objs_face_cache,
                       _face,
                       &input );

    /* Set the handle */
    HANDLE_Set( *face, _face );

    if ( error )
      goto Fail;

    return TT_Err_Ok;

  Fail:
    TT_Close_Stream( &stream );
    return error;
  }


/*******************************************************************
 *
 *  Function    :  TT_Open_Collection
 *
 *  Description :  Creates a new face object from a given font file.
 *
 *  Input  :  engine                FreeType engine instance
 *            collectionPathName    the font file's pathname
 *            fontIndex             index of font in TrueType collection
 *            face                  adress of returned face handle
 *
 *  Output :  Error code.
 *
 *  Note :    The face handle is set to NULL in case of failure.
 *
 *  MT-Note : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Open_Collection( TT_Engine       engine,
                                const TT_Text*  collectionPathName,
                                TT_ULong        fontIndex,
                                TT_Face*        face )
  {
    PEngine_Instance  _engine = HANDLE_Engine( engine );

    TFont_Input  input;
    TT_Error     error;
    TT_Stream    stream;
    PFace        _face;


    if ( !_engine )
      return TT_Err_Invalid_Engine;

    /* open the file */
    error = TT_Open_Stream( collectionPathName, &stream );
    if ( error )
      return error;

    input.stream    = stream;
    input.fontIndex = fontIndex;
    input.engine    = _engine;

    /* Create and load the new face object - this is thread-safe */
    error = CACHE_New( _engine->objs_face_cache,
                       _face,
                       &input );

    /* Set the handle */
    HANDLE_Set( *face, _face );

    if ( error )
      goto Fail;

    return TT_Err_Ok;

  Fail:
    TT_Close_Stream( &stream );

    return error;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Face_Properties
 *
 *  Description :  Returns face properties.
 *
 *  Input  :  face          the face handle
 *            properties    address of target properties record
 *
 *  Output :  Error code.
 *
 *  Note :    Currently, max_Faces is always set to 0.
 *
 *  MT-Note : YES!  Reads only permanent data.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Face_Properties( TT_Face              face,
                                    TT_Face_Properties*  properties )
  {
    PFace _face = HANDLE_Face( face );


    if ( !_face )
      return TT_Err_Invalid_Face_Handle;

    properties->num_Glyphs   = _face->numGlyphs;
    properties->max_Points   = _face->maxPoints;
    properties->max_Contours = _face->maxContours;
    properties->num_CharMaps = _face->numCMaps;
    properties->num_Names    = _face->nameTable.numNameRecords;

    if ( _face->ttcHeader.DirCount == 0 )
      properties->num_Faces = 1;
    else
      properties->num_Faces = _face->ttcHeader.DirCount;

    properties->header       = &_face->fontHeader;
    properties->horizontal   = &_face->horizontalHeader;

    if ( _face->verticalInfo )
      properties->vertical   = &_face->verticalHeader;
    else
      properties->vertical   = NULL;

    properties->os2          = &_face->os2;
    properties->postscript   = &_face->postscript;
    properties->hdmx         = &_face->hdmx;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Face_Pointer
 *
 *  Description :  Each face object has one pointer, which use is
 *                 reserved to client applications.  The TrueType
 *                 engine never accesses or uses this field.
 *
 *                 This function is used to set the pointer.
 *
 *  Input  :  face    the given face handle
 *            data    the generic pointer value
 *
 *  Output :  Error code.
 *
 *  MT-Note : NO!  But this function is reserved to "enlightened"
 *            developers, so it shouldn't be a problem.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Face_Pointer( TT_Face  face,
                                 void*    data )
  {
    PFace  faze = HANDLE_Face( face );


    if ( !faze )
      return TT_Err_Invalid_Face_Handle;
    else
      faze->generic = data;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Face_Pointer
 *
 *  Description :  Each face object has one pointer, which use is
 *                 reserved to client applications.  The TrueType
 *                 engine never access or use this field.
 *
 *                 This function is used to read the pointer.
 *
 *  Input  :  face    the given face handle
 *            data    the generic pointer value
 *
 *  Output :  Error code.
 *
 *  MT-Note : NO!  But this function is reserved to "enlightened"
 *            developers, so it shouldn't be a problem.
 *
 ******************************************************************/

  EXPORT_FUNC
  void*  TT_Get_Face_Pointer( TT_Face  face )
  {
    PFace  faze = HANDLE_Face( face );


    if ( !faze )
      return NULL;
    else
      return faze->generic;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Face_Metrics
 *
 *  Description :  This function returns the original horizontal AND
 *                 vertical metrics as found in the "hmtx" and "vmtx"
 *                 tables.  These are the glyphs' left-side-bearings
 *                 and advance widths (horizontal), as well as top
 *                 side bearings and advance heights (vertical).
 *
 *                 All are expressed in FONT UNITS, a.k.a. EM
 *                 units.
 *
 *  Input  :     face  The given face handle.
 *              first  Index of first glyph in table.
 *               last  Index of last glyph in table.
 *
 *       leftBearings  A pointer to an array of TT_Shorts where the
 *                     left side bearings for the glyphs 'first'
 *                     to 'last' will be returned.  If these metrics
 *                     don't interest you, simply set it to NULL.
 *
 *             widths  A pointer to an array of TT_UShorts
 *                     where the advance widths for the glyphs
 *                     'first' to 'last' will be returned.  If these
 *                     metrics don't interest you, simply set it
 *                     to NULL.
 *
 *        topBearings  A pointer to an array of TT_Shorts where the
 *                     top side bearings for the glyphs 'first'
 *                     to 'last' will be returned.  If these metrics
 *                     don't interest you, simply set it to NULL.
 *
 *            heights  A pointer to an array of TT_UShorts
 *                     where the advance heights for the glyphs
 *                     'first' to 'last' will be returned.  If these
 *                     metrics don't interest you, simply set it
 *                     to NULL.
 *
 *  Output :  Error code.
 *
 *  IMPORTANT NOTE :
 *
 *  As vertical metrics are optional in a TrueType font, this
 *  function will return an error ( TT_Err_No_Vertical_Data )
 *  whenever this function is called on such a face with non-NULL
 *  'topBearings' or 'heights' arguments.
 *
 *  When a font has no vertical data, the 'vertical' field in its
 *  properties structure is set to NULL.
 *
 *  MT-Note : YES!  Reads only permanent data.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Face_Metrics( TT_Face     face,
                                 TT_UShort   firstGlyph,
                                 TT_UShort   lastGlyph,
                                 TT_Short*   leftBearings,
                                 TT_UShort*  widths,
                                 TT_Short*   topBearings,
                                 TT_UShort*  heights )
  {
    PFace   _face = HANDLE_Face( face );
    UShort  num;


    if ( !_face )
      return TT_Err_Invalid_Face_Handle;

    /* Check the glyph range */
    if ( lastGlyph >= _face->numGlyphs || firstGlyph > lastGlyph )
      return TT_Err_Invalid_Argument;

    num = lastGlyph - firstGlyph;   /* number of elements-1 in each array */

    /* store the left side bearings and advance widths first */
    {
      UShort  n;
      Short   left_bearing;
      UShort  advance_width;


      for ( n = 0; n <= num; n++ )
      {
        TT_Get_Metrics( &_face->horizontalHeader,
                        firstGlyph + n, &left_bearing, &advance_width );

        if ( leftBearings )  leftBearings[n] = left_bearing;
        if ( widths )        widths[n]       = advance_width;
      }
    }

    /* check for vertical data if topBearings or heights is non-NULL */
    if ( !topBearings && !heights )
      return TT_Err_Ok;

    if ( !_face->verticalInfo )
      return TT_Err_No_Vertical_Data;

    /* store the top side bearings */
    {
      UShort  n;
      Short   top_bearing;
      UShort  advance_height;

      for ( n = 0; n <= num; n++ )
      {
        TT_Get_Metrics( (TT_Horizontal_Header*)&_face->verticalHeader,
                        firstGlyph + n, &top_bearing, &advance_height );

        if ( topBearings )  topBearings[n] = top_bearing;
        if ( heights )      heights[n]     = advance_height;
      }
    }

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Flush_Face
 *
 *  Description :  This function is used to close an active face's
 *                 file handle or descriptor.  This is useful to save
 *                 system resources, if your application uses tons
 *                 of fonts.
 *
 *  Input  :  face    the given face handle
 *
 *  Output :  Error code.
 *
 *  MT-Note : YES!  (If ttfile is.)
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Flush_Face( TT_Face  face )
  {
    PFace  faze = HANDLE_Face( face );


    if ( !faze )
      return TT_Err_Invalid_Face_Handle;
    else
      return TT_Flush_Stream( &faze->stream );
  }


/*******************************************************************
 *
 *  Function    :  TT_Close_Face
 *
 *  Description :  Closes an opened face object.  This function
 *                 will destroy all objects associated to the
 *                 face, except the glyphs.
 *
 *  Input  :  face    the given face handle
 *
 *  Output :  Error code.
 *
 *  NOTE   :  The handle is set to NULL on exit.
 *
 *  MT-Note : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Close_Face( TT_Face  face )
  {
    PFace  _face = HANDLE_Face( face );


    if ( !_face )
      return TT_Err_Invalid_Face_Handle;

    TT_Close_Stream( &_face->stream );

    /* delete the face object -- this is thread-safe */
    return CACHE_Done( _face->engine->objs_face_cache, _face );
  }


/*******************************************************************
 *
 *  Function    :  TT_New_Instance
 *
 *  Description :  Creates a new instance from a given face.
 *
 *  Input  :  face        parent face handle
 *            instance    address of instance handle
 *
 *  Output :  Error code.
 *
 *  Note   :  The handle is set to NULL in case of failure.
 *
 *  MT-Note : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_New_Instance( TT_Face       face,
                             TT_Instance*  instance )
  {
    TT_Error   error;
    PFace      _face = HANDLE_Face( face );
    PInstance  _ins;


    if ( !_face )
      return TT_Err_Invalid_Face_Handle;

    /* get a new instance from the face's cache -- this is thread-safe */
    error = CACHE_New( &_face->instances, _ins, _face );

    HANDLE_Set( *instance, _ins );

    if ( !error )
    {
      error = Instance_Init( _ins );
      if ( error )
      {
        HANDLE_Set( *instance, NULL );
        CACHE_Done( &_face->instances, _ins );
      }
    }

    return error;
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Instance_Resolutions
 *
 *  Description :  Resets an instance to a new device resolution.
 *
 *  Input  :  instance      the instance handle
 *            xResolution   new horizontal device resolution in dpi
 *            yResolution   new vertical device resolution in dpi
 *
 *  Output :  Error code.
 *
 *  Note :    There is no check for overflow; with other words,
 *            the product of glyph dimensions times the device
 *            resolutions must have reasonable values.
 *
 *  MT-Note : You should set the charsize or pixel size immediately
 *            after this call in multi-threaded programs.  This will
 *            force the instance data to be resetted.  Otherwise, you
 *            may encounter corruption when loading two glyphs from
 *            the same instance concurrently!
 *
 *            Happily, 99.99% will do just that :-)
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Instance_Resolutions( TT_Instance  instance,
                                         TT_UShort    xResolution,
                                         TT_UShort    yResolution )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
      return TT_Err_Invalid_Instance_Handle;

    ins->metrics.x_resolution = xResolution;
    ins->metrics.y_resolution = yResolution;
    ins->valid                = FALSE;

    /* In the case of a thread-safe implementation, we immediately    */
    /* call Instance_Reset in order to change the instance's variable */

    /* In the case of a non-threaded build, we simply set the 'valid' */
    /* flag to FALSE, which will force the instance's resetting at    */
    /* the next glyph loading                                         */

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Instance_CharSizes
 *
 *  Description :  Resets an instance to new point size.
 *
 *  Input  :  instance      the instance handle
 *            charWidth     the new width in 26.6 char points
 *            charHeight    the new height in 26.6 char points
 *
 *  Output :  Error code.
 *
 *  Note :    There is no check for overflow; with other words,
 *            the product of glyph dimensions times the device
 *            resolution must have reasonable values.
 *
 *  MT-Note : NO!  This should be called only when setting/resetting
 *            instances, so there is no need to protect.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Instance_CharSizes( TT_Instance  instance,
                                       TT_F26Dot6   charWidth,
                                       TT_F26Dot6   charHeight )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
      return TT_Err_Invalid_Instance_Handle;

    if ( charWidth < 1 * 64 )
      charWidth = 1 * 64;

    if ( charHeight < 1 * 64 )
      charHeight = 1 * 64;

    ins->metrics.x_scale1 = ( charWidth * ins->metrics.x_resolution ) / 72;
    ins->metrics.x_scale2 = ins->owner->fontHeader.Units_Per_EM;

    ins->metrics.y_scale1 = ( charHeight * ins->metrics.y_resolution ) / 72;
    ins->metrics.y_scale2 = ins->owner->fontHeader.Units_Per_EM;

    if ( ins->owner->fontHeader.Flags & 8 )
    {
      ins->metrics.x_scale1 = (ins->metrics.x_scale1+32) & -64;
      ins->metrics.y_scale1 = (ins->metrics.y_scale1+32) & -64;
    }

    ins->metrics.x_ppem = ins->metrics.x_scale1 / 64;
    ins->metrics.y_ppem = ins->metrics.y_scale1 / 64;

    if ( charWidth > charHeight )
      ins->metrics.pointSize = charWidth;
    else
      ins->metrics.pointSize = charHeight;

    ins->valid  = FALSE;

    return Instance_Reset( ins );
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Instance_CharSize
 *
 *  Description :  Resets an instance to new point size.
 *
 *  Input  :  instance      the instance handle
 *            charSize      the new character size in 26.6 char points
 *
 *  Output :  Error code.
 *
 *  Note :    There is no check for overflow; with other words,
 *            the product of glyph dimensions times the device
 *            resolution must have reasonable values.
 *
 *  MT-Note : NO!  This should be called only when setting/resetting
 *            instances, so there is no need to protect.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Instance_CharSize( TT_Instance  instance,
                                      TT_F26Dot6   charSize )
  {
    return TT_Set_Instance_CharSizes( instance, charSize, charSize );
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Instance_PixelSizes
 *
 *  Description :  Resets an instance to new pixel sizes
 *
 *  Input  :  instance      the instance handle
 *            pixelWidth    the new width in pixels
 *            pixelHeight   the new height in pixels
 *
 *  Output :  Error code.
 *
 *  Note :    There is no check for overflow; with other words,
 *            the product of glyph dimensions times the device
 *            resolution must have reasonable values.
 *
 *  MT-Note : NO!  This should be called only when setting/resetting
 *            instances, so there is no need to protect.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Instance_PixelSizes( TT_Instance  instance,
                                        TT_UShort    pixelWidth,
                                        TT_UShort    pixelHeight,
                                        TT_F26Dot6   pointSize )
  {
    PInstance  ins = HANDLE_Instance( instance );

    if ( !ins )
      return TT_Err_Invalid_Instance_Handle;

    if ( pixelWidth  < 1 ) pixelWidth = 1;
    if ( pixelHeight < 1 ) pixelHeight = 1;

    ins->metrics.x_ppem    = pixelWidth;
    ins->metrics.y_ppem    = pixelHeight;
    ins->metrics.pointSize = pointSize;

    ins->metrics.x_scale1 = ins->metrics.x_ppem * 64L;
    ins->metrics.x_scale2 = ins->owner->fontHeader.Units_Per_EM;
    ins->metrics.y_scale1 = ins->metrics.y_ppem * 64L;
    ins->metrics.y_scale2 = ins->owner->fontHeader.Units_Per_EM;

    ins->valid = FALSE;

    return Instance_Reset( ins );
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Instance_Transform_Flags
 *
 *  Description :  Informs the interpreter about the transformations
 *                 that will be applied to the rendered glyphs.
 *
 *  Input  :  instance      the instance handle
 *            rotated       set to TRUE if the glyph are rotated
 *            stretched     set to TRUE if the glyph are stretched
 *
 *  Output :  Error code.
 *
 *  Note :    This function is deprecated!  It's much better to
 *            control hinting manually when calling TT_Load_Glyph
 *            than relying on the font programs...
 *
 *            Never use it, unless calling for trouble ;-)
 *
 *  MT-Note : NO!  This should be called only when setting/resetting
 *            instances, so there is no need to protect.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Instance_Transform_Flags( TT_Instance  instance,
                                             TT_Bool      rotated,
                                             TT_Bool      stretched )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
      return TT_Err_Invalid_Instance_Handle;

    ins->metrics.rotated   = rotated;
    ins->metrics.stretched = stretched;
    ins->valid             = FALSE;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Instance_Metrics
 *
 *  Description :  Returns instance metrics.
 *
 *  Input  :  instance      the instance handle
 *            metrics       address of target instance metrics record
 *
 *  Output :  Error code.
 *
 *  MT-Note : YES!  Reads only semi-permanent data.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Instance_Metrics( TT_Instance           instance,
                                     TT_Instance_Metrics*  metrics )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
     return TT_Err_Invalid_Instance_Handle;

    if ( !ins->valid )
      Instance_Reset( ins );

    metrics->pointSize    = ins->metrics.pointSize;

    metrics->x_scale      = TT_MulDiv( 0x10000,
                                       ins->metrics.x_scale1,
                                       ins->metrics.x_scale2 );

    metrics->y_scale      = TT_MulDiv( 0x10000,
                                       ins->metrics.y_scale1,
                                       ins->metrics.y_scale2 );

    metrics->x_resolution = ins->metrics.x_resolution;
    metrics->y_resolution = ins->metrics.y_resolution;
    metrics->x_ppem       = ins->metrics.x_ppem;
    metrics->y_ppem       = ins->metrics.y_ppem;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Set_Instance_Pointer
 *
 *  Description :  Each instance has one pointer, which use is
 *                 reserved to client applications.  The TrueType
 *                 engine never accesses or uses this field.
 *
 *                 This function is used to set the pointer.
 *
 *  Input  :  face    the given face handle
 *            data    the generic pointer value
 *
 *  Output :  Error code.
 *
 *  MT-Note : NO!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Set_Instance_Pointer( TT_Instance  instance,
                                     void*        data )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
      return TT_Err_Invalid_Instance_Handle;
    else
      ins->generic = data;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Instance_Pointer
 *
 *  Description :  Each instance has one pointer, which use is
 *                 reserved to client applications.  The TrueType
 *                 engine never accesses or uses this field.
 *
 *                 This function is used to read the pointer.
 *
 *  Input  :  face    the given face handle
 *            data    the generic pointer value
 *
 *  Output :  Error code.
 *
 *  MT-Safe : NO!
 *
 ******************************************************************/

  EXPORT_FUNC
  void*  TT_Get_Instance_Pointer( TT_Instance  instance )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
      return NULL;
    else
      return ins->generic;
  }


/*******************************************************************
 *
 *  Function    :  TT_Done_Instance
 *
 *  Description :  Closes a given instance.
 *
 *  Input  :  instance      address of instance handle
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Done_Instance( TT_Instance  instance )
  {
    PInstance  ins = HANDLE_Instance( instance );


    if ( !ins )
      return TT_Err_Invalid_Instance_Handle;

    /* delete the instance -- this is thread-safe */
    return CACHE_Done( &ins->owner->instances, ins );
  }


/*******************************************************************
 *
 *  Function    :  TT_New_Glyph
 *
 *  Description :  Creates a new glyph object related to a given
 *                 face.
 *
 *  Input  :  face       the face handle
 *            glyph      address of target glyph handle
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_New_Glyph( TT_Face    face,
                          TT_Glyph*  glyph )
  {
    TT_Error  error;
    PFace     _face = HANDLE_Face( face );
    PGlyph    _glyph;


    if ( !_face )
      return TT_Err_Invalid_Face_Handle;

    /* get a new glyph from the face's cache -- this is thread-safe */
    error = CACHE_New( &_face->glyphs, _glyph, _face );

    HANDLE_Set( *glyph, _glyph );

    return error;
  }


/*******************************************************************
 *
 *  Function    :  TT_Done_Glyph
 *
 *  Description :  Destroys a given glyph object.
 *
 *  Input  :  glyph  the glyph handle
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Done_Glyph( TT_Glyph  glyph )
  {
    PGlyph  _glyph = HANDLE_Glyph( glyph );


    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    /* delete the engine -- this is thread-safe */
    return CACHE_Done( &_glyph->face->glyphs, _glyph );
  }


/*******************************************************************
 *
 *  Function    :  TT_Load_Glyph
 *
 *  Description :  Loads a glyph.
 *
 *  Input  :  instance      the instance handle
 *            glyph         the glyph handle
 *            glyphIndex    the glyph index
 *            loadFlags     flags controlling how to load the glyph
 *                          (none, scaled, hinted, both)
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Load_Glyph( TT_Instance  instance,
                           TT_Glyph     glyph,
                           TT_UShort    glyphIndex,
                           TT_UShort    loadFlags   )
  {
    PInstance  _ins;
    PGlyph     _glyph;
    TT_Error   error;


    _ins = HANDLE_Instance( instance );

    if ( !_ins )
      loadFlags &= ~(TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH);

    if ( (loadFlags & TTLOAD_SCALE_GLYPH) == 0 )
      _ins = 0;

    _glyph = HANDLE_Glyph( glyph );
    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    if ( _ins )
    {
      if ( _ins->owner != _glyph->face )
        return TT_Err_Invalid_Face_Handle;

      if ( !_ins->valid )
      {
        /* This code can only be called in non thread-safe builds */
        error = Instance_Reset( _ins );
        if ( error )
          return error;
      }
    }
  
    return Load_TrueType_Glyph( _ins, _glyph, glyphIndex, loadFlags );
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Glyph_Outline
 *
 *  Description :  Returns the glyph's outline data.
 *
 *  Input  :  glyph     the glyph handle
 *            outline   address where the glyph outline will be returned
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!  Reads only semi-permanent data.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Glyph_Outline( TT_Glyph     glyph,
                                  TT_Outline*  outline )
  {
    PGlyph  _glyph = HANDLE_Glyph( glyph );


    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    *outline = _glyph->outline;
    outline->owner = FALSE;

//Display_Error("n_contours    ",outline->n_contours); 
//Display_Error("n_points      ",outline->n_points); 
//Display_Error("high_precision",outline->high_precision); 
//Display_Error("second_pass   ",outline->second_pass); 
//Display_Error("dropout_mode  ",outline->dropout_mode); 


    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Glyph_Metrics
 *
 *  Description :  Extracts the glyph's horizontal metrics information.
 *
 *  Input  :  glyph       glyph object handle
 *            metrics     address where metrics will be returned
 *
 *  Output :  Error code.
 *
 *  MT-Safe : NO!  Glyph containers can't be shared.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Glyph_Metrics( TT_Glyph           glyph,
                                  TT_Glyph_Metrics*  metrics )
  {
    PGlyph  _glyph = HANDLE_Glyph( glyph );


    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    metrics->bbox     = _glyph->metrics.bbox;
    metrics->bearingX = _glyph->metrics.horiBearingX;
    metrics->bearingY = _glyph->metrics.horiBearingY;
    metrics->advance  = _glyph->metrics.horiAdvance;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Glyph_Big_Metrics
 *
 *  Description :  Extracts the glyph's big metrics information.
 *
 *  Input  :  glyph       glyph object handle
 *            metrics     address where big metrics will be returned
 *
 *  Output :  Error code.
 *
 *  MT-Safe : NO!  Glyph containers can't be shared.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Glyph_Big_Metrics( TT_Glyph               glyph,
                                      TT_Big_Glyph_Metrics*  metrics )
  {
    PGlyph  _glyph = HANDLE_Glyph( glyph );


    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    *metrics = _glyph->metrics;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Glyph_Bitmap
 *
 *  Description :  Produces a bitmap from a glyph outline.
 *
 *  Input  :  glyph      the glyph container's handle
 *            map        target pixmap description block
 *            xOffset    x offset in fractional pixels (26.6 format)
 *            yOffset    y offset in fractional pixels (26.6 format)
 *
 *  Output :  Error code.
 *
 *  Note : Only use integer pixel offsets if you want to preserve
 *         the fine hints applied to the outline.  This means that
 *         xOffset and yOffset must be multiples of 64!
 *
 *  MT-Safe : NO!  Glyph containers can't be shared.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Glyph_Bitmap( TT_Glyph        glyph,
                                 TT_Raster_Map*  map,
                                 TT_F26Dot6      xOffset,
                                 TT_F26Dot6      yOffset )
  {
    PEngine_Instance  _engine;
    TT_Engine         engine;
    TT_Error          error;
    PGlyph            _glyph = HANDLE_Glyph( glyph );

    TT_Outline  outline;


    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    _engine = _glyph->face->engine;
    HANDLE_Set( engine, _engine );

    outline = _glyph->outline;
    /* XXX : For now, use only dropout mode 2    */
    /* outline.dropout_mode = _glyph->scan_type; */
    outline.dropout_mode = 2;

    TT_Translate_Outline( &outline, xOffset, yOffset );
    error = TT_Get_Outline_Bitmap( engine, &outline, map );
    TT_Translate_Outline( &outline, -xOffset, -yOffset );

    return error;
  }


#ifdef TT_CONFIG_OPTION_GRAY_SCALING

/*******************************************************************
 *
 *  Function    :  TT_Get_Glyph_Pixmap
 *
 *  Description :  Produces a grayscaled pixmap from a glyph
 *                 outline.
 *
 *  Input  :  glyph      the glyph container's handle
 *            map        target pixmap description block
 *            xOffset    x offset in fractional pixels (26.6 format)
 *            yOffset    y offset in fractional pixels (26.6 format)
 *
 *  Output :  Error code.
 *
 *  Note : Only use integer pixel offsets to preserve the fine
 *         hinting of the glyph and the 'correct' anti-aliasing
 *         (where vertical and horizontal stems aren't grayed).
 *         This means that xOffset and yOffset must be multiples
 *         of 64!
 *
 *         You can experiment with offsets of +32 to get 'blurred'
 *         versions of the glyphs (a nice effect at large sizes that
 *         some graphic designers may appreciate :)
 *
 *  MT-Safe : NO!  Glyph containers can't be shared.
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Glyph_Pixmap( TT_Glyph        glyph,
                                 TT_Raster_Map*  map,
                                 TT_F26Dot6      xOffset,
                                 TT_F26Dot6      yOffset )
  {
    PEngine_Instance  _engine;
    TT_Engine         engine;
    TT_Error          error;
    PGlyph            _glyph = HANDLE_Glyph( glyph );

    TT_Outline  outline;


    if ( !_glyph )
      return TT_Err_Invalid_Glyph_Handle;

    _engine = _glyph->face->engine;
    HANDLE_Set(engine,_engine);

    outline = _glyph->outline;
    /* XXX : For now, use only dropout mode 2    */
    /* outline.dropout_mode = _glyph->scan_type; */
    outline.dropout_mode = 2;

    TT_Translate_Outline( &outline, xOffset, yOffset );
    error = TT_Get_Outline_Pixmap( engine, &outline, map );
    TT_Translate_Outline( &outline, -xOffset, -yOffset );

    return error;
  }

#endif /* TT_CONFIG_OPTION_GRAY_SCALING */


  static const TT_Outline  null_outline
      = { 0, 0, NULL, NULL, NULL, 0, 0, 0, 0 };


/*******************************************************************
 *
 *  Function    :  TT_New_Outline
 *
 *  Description :  Creates a new TrueType outline, reserving
 *                 array space for a given number of points and
 *                 contours.
 *
 *  Input  :  numPoints         number of points
 *            numContours       number of contours
 *            outline           address of target outline structure
 *
 *  Output :  Error code
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_New_Outline( TT_UShort    numPoints,
                            TT_Short     numContours,
                            TT_Outline*  outline )
  {
    TT_Error  error;


    if ( !outline )
      return TT_Err_Invalid_Argument;

    *outline = null_outline;

    if ( ALLOC( outline->points,   numPoints*2*sizeof ( TT_F26Dot6 ) ) ||
         ALLOC( outline->flags,    numPoints  *sizeof ( Byte )       ) ||
         ALLOC( outline->contours, numContours*sizeof ( UShort )     ) )
      goto Fail;

    outline->n_points   = numPoints;
    outline->n_contours = numContours;
    outline->owner      = TRUE;
    return TT_Err_Ok;

  Fail:
    outline->owner = TRUE;
    TT_Done_Outline( outline );
    return error;
  }


/*******************************************************************
 *
 *  Function    :  TT_Done_Outline
 *
 *  Description :  Deletes an outline created through TT_New_Outline().
 *                 Calling this function for outlines returned
 *                 by TT_Get_Glyph_Outline() yields an error.
 *
 *  Input  :  outline        address of outline
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Done_Outline( TT_Outline*  outline )
  {
    if ( outline )
    {
      if ( outline->owner )
      {
        FREE( outline->points   );
        FREE( outline->flags    );
        FREE( outline->contours );
      }
      *outline = null_outline;
      return TT_Err_Ok;
    }
    else
      return TT_Err_Invalid_Argument;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Outline_Bitmap
 *
 *  Description :  Render a TrueType outline into a bitmap.
 *                 Note that the bitmap must be created by the caller.
 *
 *  Input  :  outline        the outline to render
 *            map            the target bitmap
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Outline_Bitmap( TT_Engine       engine,
                                   TT_Outline*     outline,
                                   TT_Raster_Map*  map )
  {
    PEngine_Instance  _engine = HANDLE_Engine( engine );
    TT_Error          error;


    if ( !_engine )
      return TT_Err_Invalid_Engine;

    if ( !outline || !map )
      return TT_Err_Invalid_Argument;

    MUTEX_Lock( _engine->raster_lock );
    error = RENDER_Glyph( outline, map );
    MUTEX_Release( _engine->raster_lock );

    return error;
  }


#ifdef TT_CONFIG_OPTION_GRAY_SCALING

/*******************************************************************
 *
 *  Function    :  TT_Get_Outline_Pixmap
 *
 *  Description :  Render a TrueType outline into a pixmap.
 *                 Note that the pixmap must be created by the caller.
 *
 *  Input  :  outline       the outline to render
 *            map           the target bitmap
 *
 *  Output :  Error code
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Outline_Pixmap( TT_Engine       engine,
                                   TT_Outline*     outline,
                                   TT_Raster_Map*  map )
  {
    PEngine_Instance  _engine = HANDLE_Engine( engine );
    TT_Error          error;


    if ( !_engine )
      return TT_Err_Invalid_Engine;

    if ( !outline || !map )
      return TT_Err_Invalid_Argument;

    MUTEX_Lock( _engine->raster_lock );
    error = RENDER_Gray_Glyph( outline, map, _engine->raster_palette );
    MUTEX_Release( _engine->raster_lock );
    return error;
  }

#endif /* TT_CONFIG_OPTION_GRAY_SCALING */


/*******************************************************************
 *
 *  Function    :  TT_Copy_Outline
 *
 *  Description :  Copy an outline into another.  The source and
 *                 target outlines must have the same points and
 *                 contours numbers.
 *
 *  Input  :  source         address of source outline
 *            target         address of target outline
 *
 *  Output :  Error code
 *
 *  Note :    This function doesn't touch the target outline's 'owner'
 *            field.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Copy_Outline( TT_Outline*  source,
                             TT_Outline*  target )
  {
    if ( !source            || !target            ||
         source->n_points   != target->n_points   ||
         source->n_contours != target->n_contours )
      return TT_Err_Invalid_Argument;

    MEM_Copy( target->points, source->points,
              source->n_points * 2 * sizeof ( TT_F26Dot6 ) );

    MEM_Copy( target->flags, source->flags,
              source->n_points * sizeof ( Byte ) );

    MEM_Copy( target->contours, source->contours,
              source->n_contours * sizeof ( Short ) );

    target->high_precision = source->high_precision;
    target->second_pass    = target->second_pass;
    target->dropout_mode   = source->dropout_mode;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Transform_Outline
 *
 *  Description :  Applies a simple transformation to an outline.
 *
 *  Input  :  outline     the glyph's outline.  Can be extracted
 *                        from a glyph container through
 *                        TT_Get_Glyph_Outline().
 *
 *            matrix      simple matrix with 16.16 fixed floats
 *
 *  Output :  Error code (always TT_Err_Ok).
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  void  TT_Transform_Outline( TT_Outline*  outline,
                              TT_Matrix*   matrix )
  {
    UShort      n;
    TT_F26Dot6  x, y;
    TT_Vector*  vec;


    vec = outline->points;
    for ( n = 0; n < outline->n_points; n++ )
    {
      x = TT_MulFix( vec->x, matrix->xx ) +
          TT_MulFix( vec->y, matrix->xy );

      y = TT_MulFix( vec->x, matrix->yx ) +
          TT_MulFix( vec->y, matrix->yy );

      vec->x = x;
      vec->y = y;
      vec++;
    }
  }


/*******************************************************************
 *
 *  Function    :  TT_Transform_Vector
 *
 *  Description :  Apply a simple transform to a vector
 *
 *  Input  :  x, y        the vector.
 *
 *            matrix      simple matrix with 16.16 fixed floats
 *
 *  Output :  None.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  void  TT_Transform_Vector( TT_F26Dot6*  x,
                             TT_F26Dot6*  y,
                             TT_Matrix*   matrix )
  {
    TT_F26Dot6  xz, yz;


    xz = TT_MulFix( *x, matrix->xx ) +
         TT_MulFix( *y, matrix->xy );

    yz = TT_MulFix( *x, matrix->yx ) +
         TT_MulFix( *y, matrix->yy );

    *x = xz;
    *y = yz;
  }


/*******************************************************************
 *
 *  Function    :  TT_Translate_Outline
 *
 *  Description :  Applies a simple translation.
 *
 *  Input  :  outline   no comment :)
 *            xOffset
 *            yOffset
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  void      TT_Translate_Outline( TT_Outline*  outline,
                                  TT_F26Dot6   xOffset,
                                  TT_F26Dot6   yOffset )
  {
    UShort      n;
    TT_Vector*  vec = outline->points;


    for ( n = 0; n < outline->n_points; n++ )
    {
      vec->x += xOffset;
      vec->y += yOffset;
      vec++;
    }
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Outline_BBox
 *
 *  Description :  Returns an outline's bounding box.
 *
 *  Input  :  outline   no comment :)
 *            bbox      address where the bounding box is returned
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Outline_BBox( TT_Outline*  outline,
                                 TT_BBox*     bbox )
  {
    TT_F26Dot6  x, y;
    UShort      k;


    if ( outline && bbox )
    {
      if ( outline->n_points == 0 )
      {
        bbox->xMin = 0;
        bbox->yMin = 0;
        bbox->xMax = 0;
        bbox->yMax = 0;
      }
      else
      {
        TT_Vector*  vec = outline->points;

        bbox->xMin = bbox->xMax = vec->x;
        bbox->yMin = bbox->yMax = vec->y;
        vec++;

        for ( k = 1; k < outline->n_points; k++ )
        {
          x = vec->x;
          if ( x < bbox->xMin ) bbox->xMin = x;
          if ( x > bbox->xMax ) bbox->xMax = x;
          y = vec->y;
          if ( y < bbox->yMin ) bbox->yMin = y;
          if ( y > bbox->yMax ) bbox->yMax = y;
          vec++;
        }
      }
      return TT_Err_Ok;
    }
    else
      return TT_Err_Invalid_Argument;
  }

  /* ----------------- character mappings support ------------- */

/*******************************************************************
 *
 *  Function    :  TT_Get_CharMap_Count
 *
 *  Description :  Returns the number of charmaps in a given face.
 *
 *  Input  :  face   face object handle
 *
 *  Output :  Number of tables. -1 in case of error (bad handle).
 *
 *  Note   :  DON'T USE THIS FUNCTION! IT HAS BEEN DEPRECATED!
 *
 *            It is retained for backwards compatibility only and will
 *            fail on 16bit systems.
 *
 *  MT-Safe : YES !
 *
 ******************************************************************/

  EXPORT_FUNC
  int  TT_Get_CharMap_Count( TT_Face  face )
  {
    PFace  faze = HANDLE_Face( face );

    return ( faze ? faze->numCMaps : -1 );
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_CharMap_ID
 *
 *  Description :  Returns the ID of a given charmap.
 *
 *  Input  :  face             face object handle
 *            charmapIndex     index of charmap in directory
 *            platformID       address of returned platform ID
 *            encodingID       address of returned encoding ID
 *
 *  Output :  error code
 *
 *  MT-Safe : YES !
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_CharMap_ID( TT_Face     face,
                               TT_UShort   charmapIndex,
                               TT_UShort*  platformID,
                               TT_UShort*  encodingID )
  {
    PCMapTable  cmap;
    PFace       faze = HANDLE_Face( face );


    if ( !faze )
      return TT_Err_Invalid_Face_Handle;

    if ( charmapIndex >= faze->numCMaps )
      return TT_Err_Invalid_Argument;

    cmap = faze->cMaps + charmapIndex;

    *platformID = cmap->platformID;
    *encodingID = cmap->platformEncodingID;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_CharMap
 *
 *  Description :  Looks up a charmap.
 *
 *  Input  :  face          face object handle
 *            charmapIndex  index of charmap in directory
 *            charMap       address of returned charmap handle
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_CharMap( TT_Face      face,
                            TT_UShort    charmapIndex,
                            TT_CharMap*  charMap )
  {
    TT_Error    error;
    TT_Stream   stream;
    PCMapTable  cmap;
    PFace       faze = HANDLE_Face( face );
    
    if ( !faze )
      return TT_Err_Invalid_Face_Handle;
      
    if ( charmapIndex >= faze->numCMaps )
      return TT_Err_Invalid_Argument;
      
    cmap = faze->cMaps + charmapIndex; 
    
    /* Load table if needed */
    error = TT_Err_Ok;

    /* MT-NOTE: We're modifying the face object, so protect it. */
    MUTEX_Lock( faze->lock );

    if ( !cmap->loaded )
    {
      (void)USE_Stream( faze->stream, stream );
      if ( !error )
      {
        error = CharMap_Load( cmap, stream );
        DONE_Stream( stream );
      }

      if ( error )
        cmap = NULL;
      else
        cmap->loaded = TRUE;
    }
    MUTEX_Release( faze->lock );

    HANDLE_Set( *charMap, cmap );

    return error;
  }


/*******************************************************************
 *
 *  Function    :  TT_Char_Index
 *
 *  Description :  Returns the glyph index corresponding to
 *                 a given character code defined for the 'charmap'.
 *
 *  Input  :  charMap    charmap handle
 *            charcode   character code
 *
 *  Output :  glyph index.
 *
 *  Notes  :  Character code 0 is the unknown glyph, which should never
 *            be displayed.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_UShort  TT_Char_Index( TT_CharMap  charMap,
                            TT_UShort   charCode )
  {
    PCMapTable  cmap = HANDLE_CharMap( charMap );


    if ( !cmap )
      return 0;  /* we return 0 in case of invalid char map */

    return CharMap_Index( cmap, charCode );
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Name_Count
 *
 *  Description :  Returns the number of strings found in the
 *                 name table.
 *
 *  Input  :  face   face handle
 *
 *  Output :  number of strings.
 *
 *  Notes  :  Returns -1 on error (invalid handle).
 *
 *            DON'T USE THIS FUNCTION! IT HAS BEEN DEPRECATED!
 *
 *            It is retained for backwards compatibility only and will
 *            fail on 16bit systems.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  int  TT_Get_Name_Count( TT_Face  face )
  {
    PFace  faze = HANDLE_Face( face );


    if ( !faze )
      return -1;

    return faze->nameTable.numNameRecords;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Name_ID
 *
 *  Description :  Returns the IDs of the string number 'nameIndex'
 *                 in the name table of a given face.
 *
 *  Input  :  face        face handle
 *            nameIndex   index of string. First is 0
 *            platformID  addresses of returned IDs
 *            encodingID
 *            languageID
 *            nameID
 *
 *  Output :  Error code.
 *
 *  Notes  :  Some files have a corrupt or unusual name table, with some
 *            entries having a platformID > 3.  These can usually
 *            be ignored by a client application.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Name_ID( TT_Face     face,
                            TT_UShort   nameIndex,
                            TT_UShort*  platformID,
                            TT_UShort*  encodingID,
                            TT_UShort*  languageID,
                            TT_UShort*  nameID )
  {
    TNameRec*  namerec;
    PFace      faze = HANDLE_Face( face );


    if ( !faze )
      return TT_Err_Invalid_Face_Handle;

    if ( nameIndex >= faze->nameTable.numNameRecords )
      return TT_Err_Invalid_Argument;

    namerec = faze->nameTable.names + nameIndex;

    *platformID = namerec->platformID;
    *encodingID = namerec->encodingID;
    *languageID = namerec->languageID;
    *nameID     = namerec->nameID;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Name_String
 *
 *  Description :  Returns the address and length of a given
 *                 string found in the name table.
 *
 *  Input  :  face        face handle
 *            nameIndex   string index
 *            stringPtr   address of returned pointer to string
 *            length      address of returned string length
 *
 *  Output :  Error code.
 *
 *  Notes  :  If the string's platformID is invalid,
 *            stringPtr is NULL, and length is 0.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Name_String( TT_Face      face,
                                TT_UShort    nameIndex,
                                TT_String**  stringPtr,
                                TT_UShort*   length )
  {
    TNameRec*  namerec;
    PFace      faze = HANDLE_Face( face );


    if ( !faze )
      return TT_Err_Invalid_Face_Handle;

    if ( nameIndex >= faze->nameTable.numNameRecords )
      return TT_Err_Invalid_Argument;

    namerec = faze->nameTable.names + nameIndex;

    *stringPtr = (String*)namerec->string;
    *length    = namerec->stringLength;

    return TT_Err_Ok;
  }


/*******************************************************************
 *
 *  Function    :  TT_Get_Font_Data
 *
 *  Description :  Loads any font table into client memory.
 *
 *  Input  :  face     Face object to look for.
 *
 *            tag      Tag of table to load.  Use the value 0 if you
 *                     want to access the whole font file, else set
 *                     this parameter to a valid TrueType table tag
 *                     that you can forge with the MAKE_TT_TAG
 *                     macro.
 *
 *            offset   Starting offset in the table (or the file
 *                     if tag == 0).
 *
 *            buffer   Address of target buffer
 *
 *            length   Address of decision variable:
 *
 *                       if length == NULL:
 *                             Load the whole table.  Returns an
 *                             error if 'offset' != 0.
 *
 *                       if *length == 0 :
 *                             Exit immediately, returning the
 *                             length of the given table, or of
 *                             the font file, depending on the
 *                             value of 'tag'.
 *
 *                       if *length != 0 :
 *                             Load the next 'length' bytes of
 *                             table or font, starting at offset
 *                             'offset' (in table or font too).
 *
 *  Output :  Error code.
 *
 *  MT-Safe : YES!
 *
 ******************************************************************/

  EXPORT_FUNC
  TT_Error  TT_Get_Font_Data( TT_Face   face,
                              TT_ULong  tag,
                              TT_Long   offset,
                              void*     buffer,
                              TT_Long*  length )
  {
    PFace faze = HANDLE_Face( face );


    if ( !faze )
      return TT_Err_Invalid_Face_Handle;

    return Load_TrueType_Any( faze, tag, offset, buffer, length );
  }


  /************************ callback definition ******************/

  /* Register a new callback to the TrueType engine -- this should */
  /* only be used by higher-level libraries, not typical clients   */
  /*                                                               */
  /* This is not part of the current FreeType release, thus        */
  /* undefined...                                                  */

#if 0
  EXPORT_FUNC
  TT_Error  TT_Register_Callback( TT_Engine  engine,
                                  int        callback_id,
                                  void*      callback_ptr )
  {
    PEngine_Instance  eng = HANDLE_Engine( engine );


    if ( !eng )
      return TT_Err_Invalid_Argument;

    /* currently, we only support one callback */
    if (callback_id != TT_Callback_Glyph_Outline_Load)
      return TT_Err_Invalid_Argument;

    eng->glCallback = (TT_Glyph_Loader_Callback)callback_ptr;
    return TT_Err_Ok;
  }
#endif /* 0 */


/* END */
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值