ttobjs.c
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:33k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /*  ttobjs.c                                                               */
  4. /*                                                                         */
  5. /*    Objects manager (body).                                              */
  6. /*                                                                         */
  7. /*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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. /***************************************************************************/
  17. #include <ft2build.h>
  18. #include FT_INTERNAL_DEBUG_H
  19. #include FT_INTERNAL_CALC_H
  20. #include FT_INTERNAL_STREAM_H
  21. #include FT_TRUETYPE_IDS_H
  22. #include FT_TRUETYPE_TAGS_H
  23. #include FT_INTERNAL_SFNT_H
  24. #include "ttgload.h"
  25. #include "ttpload.h"
  26. #include "tterrors.h"
  27. #ifdef TT_USE_BYTECODE_INTERPRETER
  28. #include "ttinterp.h"
  29. #endif
  30. #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  31. #include FT_TRUETYPE_UNPATENTED_H
  32. #endif
  33. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  34. #include "ttgxvar.h"
  35. #endif
  36.   /*************************************************************************/
  37.   /*                                                                       */
  38.   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
  39.   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
  40.   /* messages during execution.                                            */
  41.   /*                                                                       */
  42. #undef  FT_COMPONENT
  43. #define FT_COMPONENT  trace_ttobjs
  44. #ifdef TT_USE_BYTECODE_INTERPRETER
  45.   /*************************************************************************/
  46.   /*                                                                       */
  47.   /*                       GLYPH ZONE FUNCTIONS                            */
  48.   /*                                                                       */
  49.   /*************************************************************************/
  50.   /*************************************************************************/
  51.   /*                                                                       */
  52.   /* <Function>                                                            */
  53.   /*    tt_glyphzone_done                                                  */
  54.   /*                                                                       */
  55.   /* <Description>                                                         */
  56.   /*    Deallocate a glyph zone.                                           */
  57.   /*                                                                       */
  58.   /* <Input>                                                               */
  59.   /*    zone :: A pointer to the target glyph zone.                        */
  60.   /*                                                                       */
  61.   FT_LOCAL_DEF( void )
  62.   tt_glyphzone_done( TT_GlyphZone  zone )
  63.   {
  64.     FT_Memory  memory = zone->memory;
  65.     if ( memory )
  66.     {
  67.       FT_FREE( zone->contours );
  68.       FT_FREE( zone->tags );
  69.       FT_FREE( zone->cur );
  70.       FT_FREE( zone->org );
  71.       FT_FREE( zone->orus );
  72.       zone->max_points   = zone->n_points   = 0;
  73.       zone->max_contours = zone->n_contours = 0;
  74.       zone->memory       = NULL;
  75.     }
  76.   }
  77.   /*************************************************************************/
  78.   /*                                                                       */
  79.   /* <Function>                                                            */
  80.   /*    tt_glyphzone_new                                                   */
  81.   /*                                                                       */
  82.   /* <Description>                                                         */
  83.   /*    Allocate a new glyph zone.                                         */
  84.   /*                                                                       */
  85.   /* <Input>                                                               */
  86.   /*    memory      :: A handle to the current memory object.              */
  87.   /*                                                                       */
  88.   /*    maxPoints   :: The capacity of glyph zone in points.               */
  89.   /*                                                                       */
  90.   /*    maxContours :: The capacity of glyph zone in contours.             */
  91.   /*                                                                       */
  92.   /* <Output>                                                              */
  93.   /*    zone        :: A pointer to the target glyph zone record.          */
  94.   /*                                                                       */
  95.   /* <Return>                                                              */
  96.   /*    FreeType error code.  0 means success.                             */
  97.   /*                                                                       */
  98.   FT_LOCAL_DEF( FT_Error )
  99.   tt_glyphzone_new( FT_Memory     memory,
  100.                     FT_UShort     maxPoints,
  101.                     FT_Short      maxContours,
  102.                     TT_GlyphZone  zone )
  103.   {
  104.     FT_Error  error;
  105.     FT_MEM_ZERO( zone, sizeof ( *zone ) );
  106.     zone->memory = memory;
  107.     if ( FT_NEW_ARRAY( zone->org,      maxPoints   ) ||
  108.          FT_NEW_ARRAY( zone->cur,      maxPoints   ) ||
  109.          FT_NEW_ARRAY( zone->orus,     maxPoints   ) ||
  110.          FT_NEW_ARRAY( zone->tags,     maxPoints   ) ||
  111.          FT_NEW_ARRAY( zone->contours, maxContours ) )
  112.     {
  113.       tt_glyphzone_done( zone );
  114.     }
  115.     else
  116.     {
  117.       zone->max_points   = maxPoints;
  118.       zone->max_contours = maxContours;
  119.     }
  120.     return error;
  121.   }
  122. #endif /* TT_USE_BYTECODE_INTERPRETER */
  123.   /*************************************************************************/
  124.   /*                                                                       */
  125.   /* <Function>                                                            */
  126.   /*    tt_face_init                                                       */
  127.   /*                                                                       */
  128.   /* <Description>                                                         */
  129.   /*    Initialize a given TrueType face object.                           */
  130.   /*                                                                       */
  131.   /* <Input>                                                               */
  132.   /*    stream     :: The source font stream.                              */
  133.   /*                                                                       */
  134.   /*    face_index :: The index of the font face in the resource.          */
  135.   /*                                                                       */
  136.   /*    num_params :: Number of additional generic parameters.  Ignored.   */
  137.   /*                                                                       */
  138.   /*    params     :: Additional generic parameters.  Ignored.             */
  139.   /*                                                                       */
  140.   /* <InOut>                                                               */
  141.   /*    face       :: The newly built face object.                         */
  142.   /*                                                                       */
  143.   /* <Return>                                                              */
  144.   /*    FreeType error code.  0 means success.                             */
  145.   /*                                                                       */
  146.   FT_LOCAL_DEF( FT_Error )
  147.   tt_face_init( FT_Stream      stream,
  148.                 FT_Face        ttface,      /* TT_Face */
  149.                 FT_Int         face_index,
  150.                 FT_Int         num_params,
  151.                 FT_Parameter*  params )
  152.   {
  153.     FT_Error      error;
  154.     FT_Library    library;
  155.     SFNT_Service  sfnt;
  156.     TT_Face       face = (TT_Face)ttface;
  157.     library = face->root.driver->root.library;
  158.     sfnt    = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
  159.     if ( !sfnt )
  160.       goto Bad_Format;
  161.     /* create input stream from resource */
  162.     if ( FT_STREAM_SEEK( 0 ) )
  163.       goto Exit;
  164.     /* check that we have a valid TrueType file */
  165.     error = sfnt->init_face( stream, face, face_index, num_params, params );
  166.     if ( error )
  167.       goto Exit;
  168.     /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
  169.     /* The 0x00020000 tag is completely undocumented; some fonts from   */
  170.     /* Arphic made for Chinese Windows 3.1 have this.                   */
  171.     if ( face->format_tag != 0x00010000L &&    /* MS fonts  */
  172.          face->format_tag != 0x00020000L &&    /* CJK fonts for Win 3.1 */
  173.          face->format_tag != TTAG_true   )     /* Mac fonts */
  174.     {
  175.       FT_TRACE2(( "[not a valid TTF font]n" ));
  176.       goto Bad_Format;
  177.     }
  178. #ifdef TT_USE_BYTECODE_INTERPRETER
  179.     face->root.face_flags |= FT_FACE_FLAG_HINTER;
  180. #endif
  181.     /* If we are performing a simple font format check, exit immediately. */
  182.     if ( face_index < 0 )
  183.       return TT_Err_Ok;
  184.     /* Load font directory */
  185.     error = sfnt->load_face( stream, face, face_index, num_params, params );
  186.     if ( error )
  187.       goto Exit;
  188.     error = tt_face_load_hdmx( face, stream );
  189.     if ( error )
  190.       goto Exit;
  191.     if ( face->root.face_flags & FT_FACE_FLAG_SCALABLE )
  192.     {
  193. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  194.       if ( !face->root.internal->incremental_interface )
  195.         error = tt_face_load_loca( face, stream );
  196.       if ( !error )
  197.         error = tt_face_load_cvt( face, stream )  ||
  198.                 tt_face_load_fpgm( face, stream ) ||
  199.                 tt_face_load_prep( face, stream );
  200. #else
  201.       if ( !error )
  202.         error = tt_face_load_loca( face, stream ) ||
  203.                 tt_face_load_cvt( face, stream )  ||
  204.                 tt_face_load_fpgm( face, stream ) ||
  205.                 tt_face_load_prep( face, stream );
  206. #endif
  207.     }
  208. #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING    ) && 
  209.     !defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
  210.     {
  211.       FT_Bool  unpatented_hinting;
  212.       int      i;
  213.       /* Determine whether unpatented hinting is to be used for this face. */
  214.       unpatented_hinting = FT_BOOL
  215.         ( library->debug_hooks[FT_DEBUG_HOOK_UNPATENTED_HINTING] != NULL );
  216.       for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
  217.         if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
  218.           unpatented_hinting = TRUE;
  219.       /* Compare the face with a list of well-known `tricky' fonts. */
  220.       /* This list shall be expanded as we find more of them.       */
  221.       if ( !unpatented_hinting )
  222.       {
  223.         static const char* const  trick_names[] =
  224.         {
  225.           "DFKaiSho-SB",     /* dfkaisb.ttf */
  226.           "DFKai-SB",        /* kaiu.ttf */
  227.           "HuaTianSongTi?",  /* htst3.ttf */
  228.           "MingLiU",         /* mingliu.ttf & mingliu.ttc */
  229.           "PMingLiU",        /* mingliu.ttc */
  230.           "MingLi43",        /* mingli.ttf */
  231.           NULL
  232.         };
  233.         int  nn;
  234.         /* Note that we only check the face name at the moment; it might */
  235.         /* be worth to do more checks for a few special cases.           */
  236.         for ( nn = 0; trick_names[nn] != NULL; nn++ )
  237.         {
  238.           if ( ttface->family_name                               &&
  239.                ft_strstr( ttface->family_name, trick_names[nn] ) )
  240.           {
  241.             unpatented_hinting = 1;
  242.             break;
  243.           }
  244.         }
  245.       }
  246.       ttface->internal->ignore_unpatented_hinter =
  247.         FT_BOOL( !unpatented_hinting );
  248.     }
  249. #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING &&
  250.           !TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  251.     /* initialize standard glyph loading routines */
  252.     TT_Init_Glyph_Loading( face );
  253.   Exit:
  254.     return error;
  255.   Bad_Format:
  256.     error = TT_Err_Unknown_File_Format;
  257.     goto Exit;
  258.   }
  259.   /*************************************************************************/
  260.   /*                                                                       */
  261.   /* <Function>                                                            */
  262.   /*    tt_face_done                                                       */
  263.   /*                                                                       */
  264.   /* <Description>                                                         */
  265.   /*    Finalize a given face object.                                      */
  266.   /*                                                                       */
  267.   /* <Input>                                                               */
  268.   /*    face :: A pointer to the face object to destroy.                   */
  269.   /*                                                                       */
  270.   FT_LOCAL_DEF( void )
  271.   tt_face_done( FT_Face  ttface )           /* TT_Face */
  272.   {
  273.     TT_Face       face   = (TT_Face)ttface;
  274.     FT_Memory     memory = face->root.memory;
  275.     FT_Stream     stream = face->root.stream;
  276.     SFNT_Service  sfnt   = (SFNT_Service)face->sfnt;
  277.     /* for `extended TrueType formats' (i.e. compressed versions) */
  278.     if ( face->extra.finalizer )
  279.       face->extra.finalizer( face->extra.data );
  280.     if ( sfnt )
  281.       sfnt->done_face( face );
  282.     /* freeing the locations table */
  283.     tt_face_done_loca( face );
  284.     tt_face_free_hdmx( face );
  285.     /* freeing the CVT */
  286.     FT_FREE( face->cvt );
  287.     face->cvt_size = 0;
  288.     /* freeing the programs */
  289.     FT_FRAME_RELEASE( face->font_program );
  290.     FT_FRAME_RELEASE( face->cvt_program );
  291.     face->font_program_size = 0;
  292.     face->cvt_program_size  = 0;
  293. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  294.     tt_done_blend( memory, face->blend );
  295.     face->blend = NULL;
  296. #endif
  297.   }
  298.   /*************************************************************************/
  299.   /*                                                                       */
  300.   /*                           SIZE  FUNCTIONS                             */
  301.   /*                                                                       */
  302.   /*************************************************************************/
  303. #ifdef TT_USE_BYTECODE_INTERPRETER
  304.   /*************************************************************************/
  305.   /*                                                                       */
  306.   /* <Function>                                                            */
  307.   /*    tt_size_run_fpgm                                                   */
  308.   /*                                                                       */
  309.   /* <Description>                                                         */
  310.   /*    Run the font program.                                              */
  311.   /*                                                                       */
  312.   /* <Input>                                                               */
  313.   /*    size :: A handle to the size object.                               */
  314.   /*                                                                       */
  315.   /* <Return>                                                              */
  316.   /*    FreeType error code.  0 means success.                             */
  317.   /*                                                                       */
  318.   FT_LOCAL_DEF( FT_Error )
  319.   tt_size_run_fpgm( TT_Size  size )
  320.   {
  321.     TT_Face         face = (TT_Face)size->root.face;
  322.     TT_ExecContext  exec;
  323.     FT_Error        error;
  324.     /* debugging instances have their own context */
  325.     if ( size->debug )
  326.       exec = size->context;
  327.     else
  328.       exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
  329.     if ( !exec )
  330.       return TT_Err_Could_Not_Find_Context;
  331.     TT_Load_Context( exec, face, size );
  332.     exec->callTop   = 0;
  333.     exec->top       = 0;
  334.     exec->period    = 64;
  335.     exec->phase     = 0;
  336.     exec->threshold = 0;
  337.     exec->instruction_trap = FALSE;
  338.     exec->F_dot_P = 0x10000L;
  339.     {
  340.       FT_Size_Metrics*  metrics    = &exec->metrics;
  341.       TT_Size_Metrics*  tt_metrics = &exec->tt_metrics;
  342.       metrics->x_ppem   = 0;
  343.       metrics->y_ppem   = 0;
  344.       metrics->x_scale  = 0;
  345.       metrics->y_scale  = 0;
  346.       tt_metrics->ppem  = 0;
  347.       tt_metrics->scale = 0;
  348.       tt_metrics->ratio = 0x10000L;
  349.     }
  350.     /* allow font program execution */
  351.     TT_Set_CodeRange( exec,
  352.                       tt_coderange_font,
  353.                       face->font_program,
  354.                       face->font_program_size );
  355.     /* disable CVT and glyph programs coderange */
  356.     TT_Clear_CodeRange( exec, tt_coderange_cvt );
  357.     TT_Clear_CodeRange( exec, tt_coderange_glyph );
  358.     if ( face->font_program_size > 0 )
  359.     {
  360.       error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
  361.       if ( !error )
  362.         error = face->interpreter( exec );
  363.     }
  364.     else
  365.       error = TT_Err_Ok;
  366.     if ( !error )
  367.       TT_Save_Context( exec, size );
  368.     return error;
  369.   }
  370.   /*************************************************************************/
  371.   /*                                                                       */
  372.   /* <Function>                                                            */
  373.   /*    tt_size_run_prep                                                   */
  374.   /*                                                                       */
  375.   /* <Description>                                                         */
  376.   /*    Run the control value program.                                     */
  377.   /*                                                                       */
  378.   /* <Input>                                                               */
  379.   /*    size :: A handle to the size object.                               */
  380.   /*                                                                       */
  381.   /* <Return>                                                              */
  382.   /*    FreeType error code.  0 means success.                             */
  383.   /*                                                                       */
  384.   FT_LOCAL_DEF( FT_Error )
  385.   tt_size_run_prep( TT_Size  size )
  386.   {
  387.     TT_Face         face = (TT_Face)size->root.face;
  388.     TT_ExecContext  exec;
  389.     FT_Error        error;
  390.     /* debugging instances have their own context */
  391.     if ( size->debug )
  392.       exec = size->context;
  393.     else
  394.       exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
  395.     if ( !exec )
  396.       return TT_Err_Could_Not_Find_Context;
  397.     TT_Load_Context( exec, face, size );
  398.     exec->callTop = 0;
  399.     exec->top     = 0;
  400.     exec->instruction_trap = FALSE;
  401.     TT_Set_CodeRange( exec,
  402.                       tt_coderange_cvt,
  403.                       face->cvt_program,
  404.                       face->cvt_program_size );
  405.     TT_Clear_CodeRange( exec, tt_coderange_glyph );
  406.     if ( face->cvt_program_size > 0 )
  407.     {
  408.       error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
  409.       if ( !error && !size->debug )
  410.         error = face->interpreter( exec );
  411.     }
  412.     else
  413.       error = TT_Err_Ok;
  414.     /* save as default graphics state */
  415.     size->GS = exec->GS;
  416.     TT_Save_Context( exec, size );
  417.     return error;
  418.   }
  419. #endif /* TT_USE_BYTECODE_INTERPRETER */
  420. #ifdef TT_USE_BYTECODE_INTERPRETER
  421.   static void
  422.   tt_size_done_bytecode( FT_Size  ftsize )
  423.   {
  424.     TT_Size    size   = (TT_Size)ftsize;
  425.     TT_Face    face   = (TT_Face)ftsize->face;
  426.     FT_Memory  memory = face->root.memory;
  427.     if ( size->debug )
  428.     {
  429.       /* the debug context must be deleted by the debugger itself */
  430.       size->context = NULL;
  431.       size->debug   = FALSE;
  432.     }
  433.     FT_FREE( size->cvt );
  434.     size->cvt_size = 0;
  435.     /* free storage area */
  436.     FT_FREE( size->storage );
  437.     size->storage_size = 0;
  438.     /* twilight zone */
  439.     tt_glyphzone_done( &size->twilight );
  440.     FT_FREE( size->function_defs );
  441.     FT_FREE( size->instruction_defs );
  442.     size->num_function_defs    = 0;
  443.     size->max_function_defs    = 0;
  444.     size->num_instruction_defs = 0;
  445.     size->max_instruction_defs = 0;
  446.     size->max_func = 0;
  447.     size->max_ins  = 0;
  448.     size->bytecode_ready = 0;
  449.     size->cvt_ready      = 0;
  450.   }
  451.   /* Initialize bytecode-related fields in the size object.       */
  452.   /* We do this only if bytecode interpretation is really needed. */
  453.   static FT_Error
  454.   tt_size_init_bytecode( FT_Size  ftsize )
  455.   {
  456.     FT_Error   error;
  457.     TT_Size    size = (TT_Size)ftsize;
  458.     TT_Face    face = (TT_Face)ftsize->face;
  459.     FT_Memory  memory = face->root.memory;
  460.     FT_Int     i;
  461.     FT_UShort       n_twilight;
  462.     TT_MaxProfile*  maxp = &face->max_profile;
  463.     size->bytecode_ready = 1;
  464.     size->cvt_ready      = 0;
  465.     size->max_function_defs    = maxp->maxFunctionDefs;
  466.     size->max_instruction_defs = maxp->maxInstructionDefs;
  467.     size->num_function_defs    = 0;
  468.     size->num_instruction_defs = 0;
  469.     size->max_func = 0;
  470.     size->max_ins  = 0;
  471.     size->cvt_size     = face->cvt_size;
  472.     size->storage_size = maxp->maxStorage;
  473.     /* Set default metrics */
  474.     {
  475.       FT_Size_Metrics*  metrics  = &size->metrics;
  476.       TT_Size_Metrics*  metrics2 = &size->ttmetrics;
  477.       metrics->x_ppem = 0;
  478.       metrics->y_ppem = 0;
  479.       metrics2->rotated   = FALSE;
  480.       metrics2->stretched = FALSE;
  481.       /* set default compensation (all 0) */
  482.       for ( i = 0; i < 4; i++ )
  483.         metrics2->compensations[i] = 0;
  484.     }
  485.     /* allocate function defs, instruction defs, cvt, and storage area */
  486.     if ( FT_NEW_ARRAY( size->function_defs,    size->max_function_defs    ) ||
  487.          FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
  488.          FT_NEW_ARRAY( size->cvt,              size->cvt_size             ) ||
  489.          FT_NEW_ARRAY( size->storage,          size->storage_size         ) )
  490.       goto Exit;
  491.     /* reserve twilight zone */
  492.     n_twilight = maxp->maxTwilightPoints;
  493.     /* there are 4 phantom points (do we need this?) */
  494.     n_twilight += 4;
  495.     error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
  496.     if ( error )
  497.       goto Exit;
  498.     size->twilight.n_points = n_twilight;
  499.     size->GS = tt_default_graphics_state;
  500.     /* set `face->interpreter' according to the debug hook present */
  501.     {
  502.       FT_Library  library = face->root.driver->root.library;
  503.       face->interpreter = (TT_Interpreter)
  504.                             library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
  505.       if ( !face->interpreter )
  506.         face->interpreter = (TT_Interpreter)TT_RunIns;
  507.     }
  508.     /* Fine, now run the font program! */
  509.     error = tt_size_run_fpgm( size );
  510.   Exit:
  511.     if ( error )
  512.       tt_size_done_bytecode( ftsize );
  513.     return error;
  514.   }
  515.   FT_LOCAL_DEF( FT_Error )
  516.   tt_size_ready_bytecode( TT_Size  size )
  517.   {
  518.     FT_Error  error = TT_Err_Ok;
  519.     if ( !size->bytecode_ready )
  520.     {
  521.       error = tt_size_init_bytecode( (FT_Size)size );
  522.       if ( error )
  523.         goto Exit;
  524.     }
  525.     /* rescale CVT when needed */
  526.     if ( !size->cvt_ready )
  527.     {
  528.       FT_UInt  i;
  529.       TT_Face  face = (TT_Face) size->root.face;
  530.       /* Scale the cvt values to the new ppem.          */
  531.       /* We use by default the y ppem to scale the CVT. */
  532.       for ( i = 0; i < size->cvt_size; i++ )
  533.         size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  534.       /* all twilight points are originally zero */
  535.       for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
  536.       {
  537.         size->twilight.org[i].x = 0;
  538.         size->twilight.org[i].y = 0;
  539.         size->twilight.cur[i].x = 0;
  540.         size->twilight.cur[i].y = 0;
  541.       }
  542.       /* clear storage area */
  543.       for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
  544.         size->storage[i] = 0;
  545.       size->GS = tt_default_graphics_state;
  546.       error = tt_size_run_prep( size );
  547.       if ( !error )
  548.           size->cvt_ready = 1;
  549.     }
  550.   Exit:
  551.     return error;
  552.   }
  553. #endif /* TT_USE_BYTECODE_INTERPRETER */
  554.   /*************************************************************************/
  555.   /*                                                                       */
  556.   /* <Function>                                                            */
  557.   /*    tt_size_init                                                       */
  558.   /*                                                                       */
  559.   /* <Description>                                                         */
  560.   /*    Initialize a new TrueType size object.                             */
  561.   /*                                                                       */
  562.   /* <InOut>                                                               */
  563.   /*    size :: A handle to the size object.                               */
  564.   /*                                                                       */
  565.   /* <Return>                                                              */
  566.   /*    FreeType error code.  0 means success.                             */
  567.   /*                                                                       */
  568.   FT_LOCAL_DEF( FT_Error )
  569.   tt_size_init( FT_Size  ttsize )           /* TT_Size */
  570.   {
  571.     TT_Size   size  = (TT_Size)ttsize;
  572.     FT_Error  error = TT_Err_Ok;
  573. #ifdef TT_USE_BYTECODE_INTERPRETER
  574.     size->bytecode_ready = 0;
  575.     size->cvt_ready      = 0;
  576. #endif
  577.     size->ttmetrics.valid = FALSE;
  578.     size->strike_index    = 0xFFFFFFFFUL;
  579.     return error;
  580.   }
  581.   /*************************************************************************/
  582.   /*                                                                       */
  583.   /* <Function>                                                            */
  584.   /*    tt_size_done                                                       */
  585.   /*                                                                       */
  586.   /* <Description>                                                         */
  587.   /*    The TrueType size object finalizer.                                */
  588.   /*                                                                       */
  589.   /* <Input>                                                               */
  590.   /*    size :: A handle to the target size object.                        */
  591.   /*                                                                       */
  592.   FT_LOCAL_DEF( void )
  593.   tt_size_done( FT_Size  ttsize )           /* TT_Size */
  594.   {
  595.     TT_Size  size = (TT_Size)ttsize;
  596. #ifdef TT_USE_BYTECODE_INTERPRETER
  597.     if ( size->bytecode_ready )
  598.       tt_size_done_bytecode( ttsize );
  599. #endif
  600.     size->ttmetrics.valid = FALSE;
  601.   }
  602.   /*************************************************************************/
  603.   /*                                                                       */
  604.   /* <Function>                                                            */
  605.   /*    tt_size_reset                                                      */
  606.   /*                                                                       */
  607.   /* <Description>                                                         */
  608.   /*    Reset a TrueType size when resolutions and character dimensions    */
  609.   /*    have been changed.                                                 */
  610.   /*                                                                       */
  611.   /* <Input>                                                               */
  612.   /*    size :: A handle to the target size object.                        */
  613.   /*                                                                       */
  614.   FT_LOCAL_DEF( FT_Error )
  615.   tt_size_reset( TT_Size  size )
  616.   {
  617.     TT_Face           face;
  618.     FT_Error          error = TT_Err_Ok;
  619.     FT_Size_Metrics*  metrics;
  620.     size->ttmetrics.valid = FALSE;
  621.     face = (TT_Face)size->root.face;
  622.     metrics = &size->metrics;
  623.     /* copy the result from base layer */
  624.     *metrics = size->root.metrics;
  625.     if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
  626.       return TT_Err_Invalid_PPem;
  627.     /* This bit flag, if set, indicates that the ppems must be       */
  628.     /* rounded to integers.  Nearly all TrueType fonts have this bit */
  629.     /* set, as hinting won't work really well otherwise.             */
  630.     /*                                                               */
  631.     if ( face->header.Flags & 8 )
  632.     {
  633.       metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
  634.                                     face->root.units_per_EM );
  635.       metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
  636.                                     face->root.units_per_EM );
  637.       metrics->ascender =
  638.         FT_PIX_ROUND( FT_MulFix( face->root.ascender, metrics->y_scale ) );
  639.       metrics->descender =
  640.         FT_PIX_ROUND( FT_MulFix( face->root.descender, metrics->y_scale ) );
  641.       metrics->height =
  642.         FT_PIX_ROUND( FT_MulFix( face->root.height, metrics->y_scale ) );
  643.       metrics->max_advance =
  644.         FT_PIX_ROUND( FT_MulFix( face->root.max_advance_width,
  645.                                  metrics->x_scale ) );
  646.     }
  647.     /* compute new transformation */
  648.     if ( metrics->x_ppem >= metrics->y_ppem )
  649.     {
  650.       size->ttmetrics.scale   = metrics->x_scale;
  651.       size->ttmetrics.ppem    = metrics->x_ppem;
  652.       size->ttmetrics.x_ratio = 0x10000L;
  653.       size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
  654.                                            0x10000L,
  655.                                            metrics->x_ppem );
  656.     }
  657.     else
  658.     {
  659.       size->ttmetrics.scale   = metrics->y_scale;
  660.       size->ttmetrics.ppem    = metrics->y_ppem;
  661.       size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
  662.                                            0x10000L,
  663.                                            metrics->y_ppem );
  664.       size->ttmetrics.y_ratio = 0x10000L;
  665.     }
  666. #ifdef TT_USE_BYTECODE_INTERPRETER
  667.     size->cvt_ready = 0;
  668. #endif /* TT_USE_BYTECODE_INTERPRETER */
  669.     if ( !error )
  670.       size->ttmetrics.valid = TRUE;
  671.     return error;
  672.   }
  673.   /*************************************************************************/
  674.   /*                                                                       */
  675.   /* <Function>                                                            */
  676.   /*    tt_driver_init                                                     */
  677.   /*                                                                       */
  678.   /* <Description>                                                         */
  679.   /*    Initialize a given TrueType driver object.                         */
  680.   /*                                                                       */
  681.   /* <Input>                                                               */
  682.   /*    driver :: A handle to the target driver object.                    */
  683.   /*                                                                       */
  684.   /* <Return>                                                              */
  685.   /*    FreeType error code.  0 means success.                             */
  686.   /*                                                                       */
  687.   FT_LOCAL_DEF( FT_Error )
  688.   tt_driver_init( FT_Module  ttdriver )     /* TT_Driver */
  689.   {
  690. #ifdef TT_USE_BYTECODE_INTERPRETER
  691.     TT_Driver  driver = (TT_Driver)ttdriver;
  692.     if ( !TT_New_Context( driver ) )
  693.       return TT_Err_Could_Not_Find_Context;
  694. #else
  695.     FT_UNUSED( ttdriver );
  696. #endif
  697.     return TT_Err_Ok;
  698.   }
  699.   /*************************************************************************/
  700.   /*                                                                       */
  701.   /* <Function>                                                            */
  702.   /*    tt_driver_done                                                     */
  703.   /*                                                                       */
  704.   /* <Description>                                                         */
  705.   /*    Finalize a given TrueType driver.                                  */
  706.   /*                                                                       */
  707.   /* <Input>                                                               */
  708.   /*    driver :: A handle to the target TrueType driver.                  */
  709.   /*                                                                       */
  710.   FT_LOCAL_DEF( void )
  711.   tt_driver_done( FT_Module  ttdriver )     /* TT_Driver */
  712.   {
  713. #ifdef TT_USE_BYTECODE_INTERPRETER
  714.     TT_Driver  driver = (TT_Driver)ttdriver;
  715.     /* destroy the execution context */
  716.     if ( driver->context )
  717.     {
  718.       TT_Done_Context( driver->context );
  719.       driver->context = NULL;
  720.     }
  721. #else
  722.     FT_UNUSED( ttdriver );
  723. #endif
  724.   }
  725.   /*************************************************************************/
  726.   /*                                                                       */
  727.   /* <Function>                                                            */
  728.   /*    tt_slot_init                                                       */
  729.   /*                                                                       */
  730.   /* <Description>                                                         */
  731.   /*    Initialize a new slot object.                                      */
  732.   /*                                                                       */
  733.   /* <InOut>                                                               */
  734.   /*    slot :: A handle to the slot object.                               */
  735.   /*                                                                       */
  736.   /* <Return>                                                              */
  737.   /*    FreeType error code.  0 means success.                             */
  738.   /*                                                                       */
  739.   FT_LOCAL_DEF( FT_Error )
  740.   tt_slot_init( FT_GlyphSlot  slot )
  741.   {
  742.     return FT_GlyphLoader_CreateExtra( slot->internal->loader );
  743.   }
  744. /* END */