home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / ft-beta.zip / freetype / lib / extend / ttextend.c < prev    next >
C/C++ Source or Header  |  1997-10-06  |  5KB  |  158 lines

  1. /*******************************************************************
  2.  *
  3.  *  ttextend.c                                                   1.0
  4.  *
  5.  *    Extensions Default Body 
  6.  *
  7.  *  Copyright 1996, 1997 by
  8.  *  David Turner, Robert Wilhelm, and Werner Lemberg.
  9.  *
  10.  *  This file is part of the FreeType project, and may only be used
  11.  *  modified and distributed under the terms of the FreeType project
  12.  *  license, LICENSE.TXT. By continuing to use, modify or distribute
  13.  *  this file you indicate that you have read the license and
  14.  *  understand and accept it fully.
  15.  *
  16.  *  It is now possible to 'extend' the FreeType engine, in order
  17.  *  to be able to access additionnal tables, without having to
  18.  *  to change the core library's code.
  19.  *
  20.  *  Only extensions of the face object class are supported.
  21.  *  Each face object has now a typeless pointer called 'extension'
  22.  *  that can be used as an anchor to the data specific to a given
  23.  *  library extension.
  24.  *
  25.  *  The extension component can also allocate memory on engine
  26.  *  initialisation, which calls the TTExtension_Init function.
  27.  *
  28.  *  NOTE :
  29.  *
  30.  *  The ttextend.h and ttextend.c are used to extend the core           
  31.  *  library. They do not affect the high-level API.  
  32.  *
  33.  *  It is possible to extend the high-level API by modifying the
  34.  *  files 'apiext.h' and 'apiext.c' found in this same directory
  35.  *  read their source for more information on how to do that.
  36.  *
  37.  *  ===============================================================
  38.  *
  39.  *  This is the first default extension that came to my mind,
  40.  *  it provides support for the kerning tables. Read 'ftxapi.h'
  41.  *  to see how the user application can access them.
  42.  *
  43.  *                                                    - DavidT
  44.  *
  45.  ******************************************************************/
  46.  
  47. #include "freetype.h"
  48. #include "ttextend.h"
  49. #include "tterror.h"
  50. #include "ttmemory.h"
  51.  
  52. /*******************************************************************
  53.  *
  54.  *  Function    :  TTExtension_Init
  55.  *
  56.  *  Description :  Initialize the extensions component.
  57.  *                 Called by the engine initializer FreeType_Init
  58.  *
  59.  ******************************************************************/
  60.  
  61.   TT_Error  TTExtension_Init()
  62.   {
  63.     /* No supplemental memory required to support these extensions */
  64.     return TT_Err_Ok;
  65.   }
  66.  
  67.  
  68. /*******************************************************************
  69.  *
  70.  *  Function    :  TTExtension_Done
  71.  *
  72.  *  Description :  Finalizes the extensions component.
  73.  *                 Called by the engine finalizer FreeType_Done
  74.  *
  75.  ******************************************************************/
  76.  
  77.   TT_Error  TTExtension_Done()
  78.   {
  79.     /* No memory was required to support these extensions */
  80.     return TT_Err_Ok;
  81.   }
  82.  
  83. /*******************************************************************
  84.  *
  85.  *  Function    :  Extension_Destroy
  86.  *
  87.  *  Description :  Destroy a previously allocated extensions
  88.  *
  89.  *  NOTE : This is the last function called by the face destructor.
  90.  *         as a consequence, you should consider all the fields in
  91.  *         the face object invalid. You're not allowed to access
  92.  *         them with the exception of the face->extension field
  93.  *         here anyway.
  94.  *
  95.  *         The error code is currently ignored by the destructor
  96.  *
  97.  ******************************************************************/
  98.  
  99.   TT_Error  Extension_Destroy( PFace  face )
  100.   {
  101.     TExtension*  ext;
  102.  
  103.     /* by convention, exit when facing null pointers */
  104.     if ( !face )
  105.       return TT_Err_Ok;
  106.  
  107.     ext = (TExtension*)face->extension;
  108.     if ( !ext )
  109.       return TT_Err_Ok;
  110.  
  111.     /* ----------------- kerning support --------------------*/
  112.  
  113.     Kerning_Destroy( &ext->kerning );
  114.  
  115.     /* --------- other optional extensions ----------------- */
  116.  
  117.     /* ----------------------------------------------------- */
  118.  
  119.     /* then, destroy the extension block itself */
  120.  
  121.     FREE( face->extension );
  122.     return TT_Err_Ok;
  123.   }
  124.  
  125. /*******************************************************************
  126.  *
  127.  *  Function    :  Extension_Create
  128.  *
  129.  *  Description :  Create
  130.  *
  131.  ******************************************************************/
  132.  
  133.   TT_Error  Extension_Create( PFace  face )
  134.   {
  135.     TT_Error     error;
  136.     TExtension*  ext;
  137.  
  138.     /* First of all, create the extension block */
  139.  
  140.     if ( ALLOC( face->extension, sizeof(TExtension) ) )
  141.       return error;
  142.  
  143.     ext = (TExtension*)face->extension;
  144.  
  145.     /* ----------------- kerning support --------------------*/
  146.  
  147.     error = Kerning_Create( face, &ext->kerning );
  148.     if (error)
  149.       return error;
  150.  
  151.     /* --------- other optional extensions ----------------- */
  152.  
  153.     /* ----------------------------------------------------- */
  154.  
  155.     return error;
  156.   }
  157.  
  158.