ReactOS Fundraising Campaign 2012
 
€ 4,060 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ttobjs.c
Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ttobjs.c                                                               */
00004 /*                                                                         */
00005 /*    Objects manager (body).                                              */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
00008 /*            2010 by                                                      */
00009 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00010 /*                                                                         */
00011 /*  This file is part of the FreeType project, and may only be used,       */
00012 /*  modified, and distributed under the terms of the FreeType project      */
00013 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00014 /*  this file you indicate that you have read the license and              */
00015 /*  understand and accept it fully.                                        */
00016 /*                                                                         */
00017 /***************************************************************************/
00018 
00019 
00020 #include <ft2build.h>
00021 #include FT_INTERNAL_DEBUG_H
00022 #include FT_INTERNAL_STREAM_H
00023 #include FT_TRUETYPE_TAGS_H
00024 #include FT_INTERNAL_SFNT_H
00025 
00026 #include "ttgload.h"
00027 #include "ttpload.h"
00028 
00029 #include "tterrors.h"
00030 
00031 #ifdef TT_USE_BYTECODE_INTERPRETER
00032 #include "ttinterp.h"
00033 #endif
00034 
00035 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
00036 #include FT_TRUETYPE_UNPATENTED_H
00037 #endif
00038 
00039 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
00040 #include "ttgxvar.h"
00041 #endif
00042 
00043   /*************************************************************************/
00044   /*                                                                       */
00045   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00046   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00047   /* messages during execution.                                            */
00048   /*                                                                       */
00049 #undef  FT_COMPONENT
00050 #define FT_COMPONENT  trace_ttobjs
00051 
00052 
00053 #ifdef TT_USE_BYTECODE_INTERPRETER
00054 
00055   /*************************************************************************/
00056   /*                                                                       */
00057   /*                       GLYPH ZONE FUNCTIONS                            */
00058   /*                                                                       */
00059   /*************************************************************************/
00060 
00061 
00062   /*************************************************************************/
00063   /*                                                                       */
00064   /* <Function>                                                            */
00065   /*    tt_glyphzone_done                                                  */
00066   /*                                                                       */
00067   /* <Description>                                                         */
00068   /*    Deallocate a glyph zone.                                           */
00069   /*                                                                       */
00070   /* <Input>                                                               */
00071   /*    zone :: A pointer to the target glyph zone.                        */
00072   /*                                                                       */
00073   FT_LOCAL_DEF( void )
00074   tt_glyphzone_done( TT_GlyphZone  zone )
00075   {
00076     FT_Memory  memory = zone->memory;
00077 
00078 
00079     if ( memory )
00080     {
00081       FT_FREE( zone->contours );
00082       FT_FREE( zone->tags );
00083       FT_FREE( zone->cur );
00084       FT_FREE( zone->org );
00085       FT_FREE( zone->orus );
00086 
00087       zone->max_points   = zone->n_points   = 0;
00088       zone->max_contours = zone->n_contours = 0;
00089       zone->memory       = NULL;
00090     }
00091   }
00092 
00093 
00094   /*************************************************************************/
00095   /*                                                                       */
00096   /* <Function>                                                            */
00097   /*    tt_glyphzone_new                                                   */
00098   /*                                                                       */
00099   /* <Description>                                                         */
00100   /*    Allocate a new glyph zone.                                         */
00101   /*                                                                       */
00102   /* <Input>                                                               */
00103   /*    memory      :: A handle to the current memory object.              */
00104   /*                                                                       */
00105   /*    maxPoints   :: The capacity of glyph zone in points.               */
00106   /*                                                                       */
00107   /*    maxContours :: The capacity of glyph zone in contours.             */
00108   /*                                                                       */
00109   /* <Output>                                                              */
00110   /*    zone        :: A pointer to the target glyph zone record.          */
00111   /*                                                                       */
00112   /* <Return>                                                              */
00113   /*    FreeType error code.  0 means success.                             */
00114   /*                                                                       */
00115   FT_LOCAL_DEF( FT_Error )
00116   tt_glyphzone_new( FT_Memory     memory,
00117                     FT_UShort     maxPoints,
00118                     FT_Short      maxContours,
00119                     TT_GlyphZone  zone )
00120   {
00121     FT_Error  error;
00122 
00123 
00124     FT_MEM_ZERO( zone, sizeof ( *zone ) );
00125     zone->memory = memory;
00126 
00127     if ( FT_NEW_ARRAY( zone->org,      maxPoints   ) ||
00128          FT_NEW_ARRAY( zone->cur,      maxPoints   ) ||
00129          FT_NEW_ARRAY( zone->orus,     maxPoints   ) ||
00130          FT_NEW_ARRAY( zone->tags,     maxPoints   ) ||
00131          FT_NEW_ARRAY( zone->contours, maxContours ) )
00132     {
00133       tt_glyphzone_done( zone );
00134     }
00135     else
00136     {
00137       zone->max_points   = maxPoints;
00138       zone->max_contours = maxContours;
00139     }
00140 
00141     return error;
00142   }
00143 #endif /* TT_USE_BYTECODE_INTERPRETER */
00144 
00145 
00146   /* Compare the face with a list of well-known `tricky' fonts. */
00147   /* This list shall be expanded as we find more of them.       */
00148 
00149   static FT_Bool
00150   tt_check_trickyness_family( FT_String*  name )
00151   {
00152 
00153 #define TRICK_NAMES_MAX_CHARACTERS  16
00154 #define TRICK_NAMES_COUNT            8
00155 
00156     static const char trick_names[TRICK_NAMES_COUNT]
00157                                  [TRICK_NAMES_MAX_CHARACTERS + 1] =
00158     {
00159       "DFKaiSho-SB",     /* dfkaisb.ttf */
00160       "DFKaiShu",
00161       "DFKai-SB",        /* kaiu.ttf */
00162       "HuaTianKaiTi?",   /* htkt2.ttf */
00163       "HuaTianSongTi?",  /* htst3.ttf */
00164       "MingLiU",         /* mingliu.ttf & mingliu.ttc */
00165       "PMingLiU",        /* mingliu.ttc */
00166       "MingLi43",        /* mingli.ttf */
00167     };
00168 
00169     int  nn;
00170 
00171 
00172     for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ )
00173       if ( ft_strstr( name, trick_names[nn] ) )
00174         return TRUE;
00175 
00176     return FALSE;
00177   }
00178 
00179 
00180   /* XXX: This function should be in the `sfnt' module. */
00181 
00182   /* Some PDF generators clear the checksums in the TrueType header table. */
00183   /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF     */
00184   /* Printer clears the entries for subsetted subtables.  We thus have to  */
00185   /* recalculate the checksums  where necessary.                           */
00186 
00187   static FT_UInt32
00188   tt_synth_sfnt_checksum( FT_Stream  stream,
00189                           FT_ULong   length )
00190   {
00191     FT_Error   error;
00192     FT_UInt32  checksum = 0;
00193     int        i;
00194 
00195 
00196     if ( FT_FRAME_ENTER( length ) )
00197       return 0;
00198 
00199     for ( ; length > 3; length -= 4 )
00200       checksum += (FT_UInt32)FT_GET_ULONG();
00201 
00202     for ( i = 3; length > 0; length --, i-- )
00203       checksum += (FT_UInt32)( FT_GET_BYTE() << ( i * 8 ) );
00204 
00205     FT_FRAME_EXIT();
00206 
00207     return checksum;
00208   }
00209 
00210 
00211   /* XXX: This function should be in the `sfnt' module. */
00212 
00213   static FT_ULong
00214   tt_get_sfnt_checksum( TT_Face    face,
00215                         FT_UShort  i )
00216   {
00217     if ( face->dir_tables[i].CheckSum )
00218       return face->dir_tables[i].CheckSum;
00219 
00220     else if ( !face->goto_table )
00221       return 0;
00222 
00223     else if ( !face->goto_table( face,
00224                                  face->dir_tables[i].Tag,
00225                                  face->root.stream,
00226                                  NULL ) )
00227       return 0;
00228 
00229     return (FT_ULong)tt_synth_sfnt_checksum( face->root.stream,
00230                                              face->dir_tables[i].Length );
00231   }
00232 
00233 
00234   typedef struct tt_sfnt_id_rec_
00235   {
00236     FT_ULong  CheckSum;
00237     FT_ULong  Length;
00238 
00239   } tt_sfnt_id_rec;
00240 
00241 
00242   static FT_Bool
00243   tt_check_trickyness_sfnt_ids( TT_Face  face )
00244   {
00245 #define TRICK_SFNT_IDS_PER_FACE   3
00246 #define TRICK_SFNT_IDS_NUM_FACES  5
00247 
00248     static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES]
00249                                        [TRICK_SFNT_IDS_PER_FACE] = {
00250 
00251 #define TRICK_SFNT_ID_cvt   0
00252 #define TRICK_SFNT_ID_fpgm  1
00253 #define TRICK_SFNT_ID_prep  2
00254 
00255       { /* MingLiU 1995 */
00256         { 0x05bcf058, 0x000002e4 }, /* cvt  */
00257         { 0x28233bf1, 0x000087c4 }, /* fpgm */
00258         { 0xa344a1ea, 0x000001e1 }  /* prep */
00259       },
00260       { /* MingLiU 1996- */
00261         { 0x05bcf058, 0x000002e4 }, /* cvt  */
00262         { 0x28233bf1, 0x000087c4 }, /* fpgm */
00263         { 0xa344a1eb, 0x000001e1 }  /* prep */
00264       },
00265       { /* DFKaiShu */
00266         { 0x11e5ead4, 0x00000350 }, /* cvt  */
00267         { 0x5a30ca3b, 0x00009063 }, /* fpgm */
00268         { 0x13a42602, 0x0000007e }  /* prep */
00269       },
00270       { /* HuaTianKaiTi */
00271         { 0xfffbfffc, 0x00000008 }, /* cvt  */
00272         { 0x9c9e48b8, 0x0000bea2 }, /* fpgm */
00273         { 0x70020112, 0x00000008 }  /* prep */
00274       },
00275       { /* HuaTianSongTi */
00276         { 0xfffbfffc, 0x00000008 }, /* cvt  */
00277         { 0x0a5a0483, 0x00017c39 }, /* fpgm */
00278         { 0x70020112, 0x00000008 }  /* prep */
00279       }
00280     };
00281 
00282     FT_ULong  checksum;
00283     int       num_matched_ids[TRICK_SFNT_IDS_NUM_FACES];
00284     int       i, j, k;
00285 
00286 
00287     FT_MEM_SET( num_matched_ids, 0,
00288                 sizeof( int ) * TRICK_SFNT_IDS_NUM_FACES );
00289 
00290     for ( i = 0; i < face->num_tables; i++ )
00291     {
00292       checksum = 0;
00293 
00294       switch( face->dir_tables[i].Tag )
00295       {
00296       case TTAG_cvt:
00297         k = TRICK_SFNT_ID_cvt;
00298         break;
00299 
00300       case TTAG_fpgm:
00301         k = TRICK_SFNT_ID_fpgm;
00302         break;
00303 
00304       case TTAG_prep:
00305         k = TRICK_SFNT_ID_prep;
00306         break;
00307 
00308       default:
00309         continue;
00310       }
00311 
00312       for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
00313         if ( face->dir_tables[i].Length == sfnt_id[j][k].Length )
00314         {
00315           if ( !checksum )
00316             checksum = tt_get_sfnt_checksum( face, i );
00317 
00318           if ( sfnt_id[j][k].CheckSum == checksum )
00319             num_matched_ids[j]++;
00320 
00321           if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
00322             return TRUE;
00323         }
00324     }
00325 
00326     return FALSE;
00327   }
00328 
00329 
00330   static FT_Bool
00331   tt_check_trickyness( FT_Face  face )
00332   {
00333     if ( !face )
00334       return FALSE;
00335 
00336     /* First, check the face name. */
00337     if ( face->family_name )
00338     {
00339       if ( tt_check_trickyness_family( face->family_name ) )
00340         return TRUE;
00341       else
00342         return FALSE;
00343     }
00344 
00345     /* Type42 fonts may lack `name' tables, we thus try to identify */
00346     /* tricky fonts by checking the checksums of Type42-persistent  */
00347     /* sfnt tables (`cvt', `fpgm', and `prep').                     */
00348     if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) )
00349       return TRUE;
00350 
00351     return FALSE;
00352   }
00353 
00354 
00355   /*************************************************************************/
00356   /*                                                                       */
00357   /* <Function>                                                            */
00358   /*    tt_face_init                                                       */
00359   /*                                                                       */
00360   /* <Description>                                                         */
00361   /*    Initialize a given TrueType face object.                           */
00362   /*                                                                       */
00363   /* <Input>                                                               */
00364   /*    stream     :: The source font stream.                              */
00365   /*                                                                       */
00366   /*    face_index :: The index of the font face in the resource.          */
00367   /*                                                                       */
00368   /*    num_params :: Number of additional generic parameters.  Ignored.   */
00369   /*                                                                       */
00370   /*    params     :: Additional generic parameters.  Ignored.             */
00371   /*                                                                       */
00372   /* <InOut>                                                               */
00373   /*    face       :: The newly built face object.                         */
00374   /*                                                                       */
00375   /* <Return>                                                              */
00376   /*    FreeType error code.  0 means success.                             */
00377   /*                                                                       */
00378   FT_LOCAL_DEF( FT_Error )
00379   tt_face_init( FT_Stream      stream,
00380                 FT_Face        ttface,      /* TT_Face */
00381                 FT_Int         face_index,
00382                 FT_Int         num_params,
00383                 FT_Parameter*  params )
00384   {
00385     FT_Error      error;
00386     FT_Library    library;
00387     SFNT_Service  sfnt;
00388     TT_Face       face = (TT_Face)ttface;
00389 
00390 
00391     library = ttface->driver->root.library;
00392     sfnt    = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
00393     if ( !sfnt )
00394       goto Bad_Format;
00395 
00396     /* create input stream from resource */
00397     if ( FT_STREAM_SEEK( 0 ) )
00398       goto Exit;
00399 
00400     /* check that we have a valid TrueType file */
00401     error = sfnt->init_face( stream, face, face_index, num_params, params );
00402     if ( error )
00403       goto Exit;
00404 
00405     /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
00406     /* The 0x00020000 tag is completely undocumented; some fonts from   */
00407     /* Arphic made for Chinese Windows 3.1 have this.                   */
00408     if ( face->format_tag != 0x00010000L &&    /* MS fonts  */
00409          face->format_tag != 0x00020000L &&    /* CJK fonts for Win 3.1 */
00410          face->format_tag != TTAG_true   )     /* Mac fonts */
00411     {
00412       FT_TRACE2(( "[not a valid TTF font]\n" ));
00413       goto Bad_Format;
00414     }
00415 
00416 #ifdef TT_USE_BYTECODE_INTERPRETER
00417     ttface->face_flags |= FT_FACE_FLAG_HINTER;
00418 #endif
00419 
00420     /* If we are performing a simple font format check, exit immediately. */
00421     if ( face_index < 0 )
00422       return TT_Err_Ok;
00423 
00424     /* Load font directory */
00425     error = sfnt->load_face( stream, face, face_index, num_params, params );
00426     if ( error )
00427       goto Exit;
00428 
00429     if ( tt_check_trickyness( ttface ) )
00430       ttface->face_flags |= FT_FACE_FLAG_TRICKY;
00431 
00432     error = tt_face_load_hdmx( face, stream );
00433     if ( error )
00434       goto Exit;
00435 
00436     if ( FT_IS_SCALABLE( ttface ) )
00437     {
00438 
00439 #ifdef FT_CONFIG_OPTION_INCREMENTAL
00440 
00441       if ( !ttface->internal->incremental_interface )
00442         error = tt_face_load_loca( face, stream );
00443       if ( !error )
00444         error = tt_face_load_cvt( face, stream );
00445       if ( !error )
00446         error = tt_face_load_fpgm( face, stream );
00447       if ( !error )
00448         error = tt_face_load_prep( face, stream );
00449 
00450 #else
00451 
00452       if ( !error )
00453         error = tt_face_load_loca( face, stream );
00454       if ( !error )
00455         error = tt_face_load_cvt( face, stream );
00456       if ( !error )
00457         error = tt_face_load_fpgm( face, stream );
00458       if ( !error )
00459         error = tt_face_load_prep( face, stream );
00460 
00461 #endif
00462 
00463     }
00464 
00465 #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING    ) && \
00466     !defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
00467 
00468     {
00469       FT_Bool  unpatented_hinting;
00470       int      i;
00471 
00472 
00473       /* Determine whether unpatented hinting is to be used for this face. */
00474       unpatented_hinting = FT_BOOL
00475         ( library->debug_hooks[FT_DEBUG_HOOK_UNPATENTED_HINTING] != NULL );
00476 
00477       for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
00478         if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
00479           unpatented_hinting = TRUE;
00480 
00481       if ( !unpatented_hinting )
00482         ttface->internal->ignore_unpatented_hinter = TRUE;
00483     }
00484 
00485 #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING &&
00486           !TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
00487 
00488     /* initialize standard glyph loading routines */
00489     TT_Init_Glyph_Loading( face );
00490 
00491   Exit:
00492     return error;
00493 
00494   Bad_Format:
00495     error = TT_Err_Unknown_File_Format;
00496     goto Exit;
00497   }
00498 
00499 
00500   /*************************************************************************/
00501   /*                                                                       */
00502   /* <Function>                                                            */
00503   /*    tt_face_done                                                       */
00504   /*                                                                       */
00505   /* <Description>                                                         */
00506   /*    Finalize a given face object.                                      */
00507   /*                                                                       */
00508   /* <Input>                                                               */
00509   /*    face :: A pointer to the face object to destroy.                   */
00510   /*                                                                       */
00511   FT_LOCAL_DEF( void )
00512   tt_face_done( FT_Face  ttface )           /* TT_Face */
00513   {
00514     TT_Face       face = (TT_Face)ttface;
00515     FT_Memory     memory;
00516     FT_Stream     stream;
00517     SFNT_Service  sfnt;
00518 
00519 
00520     if ( !face )
00521       return;
00522 
00523     memory = ttface->memory;
00524     stream = ttface->stream;
00525     sfnt   = (SFNT_Service)face->sfnt;
00526 
00527     /* for `extended TrueType formats' (i.e. compressed versions) */
00528     if ( face->extra.finalizer )
00529       face->extra.finalizer( face->extra.data );
00530 
00531     if ( sfnt )
00532       sfnt->done_face( face );
00533 
00534     /* freeing the locations table */
00535     tt_face_done_loca( face );
00536 
00537     tt_face_free_hdmx( face );
00538 
00539     /* freeing the CVT */
00540     FT_FREE( face->cvt );
00541     face->cvt_size = 0;
00542 
00543     /* freeing the programs */
00544     FT_FRAME_RELEASE( face->font_program );
00545     FT_FRAME_RELEASE( face->cvt_program );
00546     face->font_program_size = 0;
00547     face->cvt_program_size  = 0;
00548 
00549 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
00550     tt_done_blend( memory, face->blend );
00551     face->blend = NULL;
00552 #endif
00553   }
00554 
00555 
00556   /*************************************************************************/
00557   /*                                                                       */
00558   /*                           SIZE  FUNCTIONS                             */
00559   /*                                                                       */
00560   /*************************************************************************/
00561 
00562 #ifdef TT_USE_BYTECODE_INTERPRETER
00563 
00564   /*************************************************************************/
00565   /*                                                                       */
00566   /* <Function>                                                            */
00567   /*    tt_size_run_fpgm                                                   */
00568   /*                                                                       */
00569   /* <Description>                                                         */
00570   /*    Run the font program.                                              */
00571   /*                                                                       */
00572   /* <Input>                                                               */
00573   /*    size :: A handle to the size object.                               */
00574   /*                                                                       */
00575   /* <Return>                                                              */
00576   /*    FreeType error code.  0 means success.                             */
00577   /*                                                                       */
00578   FT_LOCAL_DEF( FT_Error )
00579   tt_size_run_fpgm( TT_Size  size )
00580   {
00581     TT_Face         face = (TT_Face)size->root.face;
00582     TT_ExecContext  exec;
00583     FT_Error        error;
00584 
00585 
00586     /* debugging instances have their own context */
00587     if ( size->debug )
00588       exec = size->context;
00589     else
00590       exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
00591 
00592     if ( !exec )
00593       return TT_Err_Could_Not_Find_Context;
00594 
00595     TT_Load_Context( exec, face, size );
00596 
00597     exec->callTop   = 0;
00598     exec->top       = 0;
00599 
00600     exec->period    = 64;
00601     exec->phase     = 0;
00602     exec->threshold = 0;
00603 
00604     exec->instruction_trap = FALSE;
00605     exec->F_dot_P = 0x10000L;
00606 
00607     {
00608       FT_Size_Metrics*  metrics    = &exec->metrics;
00609       TT_Size_Metrics*  tt_metrics = &exec->tt_metrics;
00610 
00611 
00612       metrics->x_ppem   = 0;
00613       metrics->y_ppem   = 0;
00614       metrics->x_scale  = 0;
00615       metrics->y_scale  = 0;
00616 
00617       tt_metrics->ppem  = 0;
00618       tt_metrics->scale = 0;
00619       tt_metrics->ratio = 0x10000L;
00620     }
00621 
00622     /* allow font program execution */
00623     TT_Set_CodeRange( exec,
00624                       tt_coderange_font,
00625                       face->font_program,
00626                       face->font_program_size );
00627 
00628     /* disable CVT and glyph programs coderange */
00629     TT_Clear_CodeRange( exec, tt_coderange_cvt );
00630     TT_Clear_CodeRange( exec, tt_coderange_glyph );
00631 
00632     if ( face->font_program_size > 0 )
00633     {
00634       error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
00635 
00636       if ( !error )
00637       {
00638         FT_TRACE4(( "Executing `fpgm' table.\n" ));
00639 
00640         error = face->interpreter( exec );
00641       }
00642     }
00643     else
00644       error = TT_Err_Ok;
00645 
00646     if ( !error )
00647       TT_Save_Context( exec, size );
00648 
00649     return error;
00650   }
00651 
00652 
00653   /*************************************************************************/
00654   /*                                                                       */
00655   /* <Function>                                                            */
00656   /*    tt_size_run_prep                                                   */
00657   /*                                                                       */
00658   /* <Description>                                                         */
00659   /*    Run the control value program.                                     */
00660   /*                                                                       */
00661   /* <Input>                                                               */
00662   /*    size :: A handle to the size object.                               */
00663   /*                                                                       */
00664   /* <Return>                                                              */
00665   /*    FreeType error code.  0 means success.                             */
00666   /*                                                                       */
00667   FT_LOCAL_DEF( FT_Error )
00668   tt_size_run_prep( TT_Size  size )
00669   {
00670     TT_Face         face = (TT_Face)size->root.face;
00671     TT_ExecContext  exec;
00672     FT_Error        error;
00673 
00674 
00675     /* debugging instances have their own context */
00676     if ( size->debug )
00677       exec = size->context;
00678     else
00679       exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
00680 
00681     if ( !exec )
00682       return TT_Err_Could_Not_Find_Context;
00683 
00684     TT_Load_Context( exec, face, size );
00685 
00686     exec->callTop = 0;
00687     exec->top     = 0;
00688 
00689     exec->instruction_trap = FALSE;
00690 
00691     TT_Set_CodeRange( exec,
00692                       tt_coderange_cvt,
00693                       face->cvt_program,
00694                       face->cvt_program_size );
00695 
00696     TT_Clear_CodeRange( exec, tt_coderange_glyph );
00697 
00698     if ( face->cvt_program_size > 0 )
00699     {
00700       error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
00701 
00702       if ( !error && !size->debug )
00703       {
00704         FT_TRACE4(( "Executing `prep' table.\n" ));
00705 
00706         error = face->interpreter( exec );
00707       }
00708     }
00709     else
00710       error = TT_Err_Ok;
00711 
00712     /* save as default graphics state */
00713     size->GS = exec->GS;
00714 
00715     TT_Save_Context( exec, size );
00716 
00717     return error;
00718   }
00719 
00720 #endif /* TT_USE_BYTECODE_INTERPRETER */
00721 
00722 
00723 #ifdef TT_USE_BYTECODE_INTERPRETER
00724 
00725   static void
00726   tt_size_done_bytecode( FT_Size  ftsize )
00727   {
00728     TT_Size    size   = (TT_Size)ftsize;
00729     TT_Face    face   = (TT_Face)ftsize->face;
00730     FT_Memory  memory = face->root.memory;
00731 
00732 
00733     if ( size->debug )
00734     {
00735       /* the debug context must be deleted by the debugger itself */
00736       size->context = NULL;
00737       size->debug   = FALSE;
00738     }
00739 
00740     FT_FREE( size->cvt );
00741     size->cvt_size = 0;
00742 
00743     /* free storage area */
00744     FT_FREE( size->storage );
00745     size->storage_size = 0;
00746 
00747     /* twilight zone */
00748     tt_glyphzone_done( &size->twilight );
00749 
00750     FT_FREE( size->function_defs );
00751     FT_FREE( size->instruction_defs );
00752 
00753     size->num_function_defs    = 0;
00754     size->max_function_defs    = 0;
00755     size->num_instruction_defs = 0;
00756     size->max_instruction_defs = 0;
00757 
00758     size->max_func = 0;
00759     size->max_ins  = 0;
00760 
00761     size->bytecode_ready = 0;
00762     size->cvt_ready      = 0;
00763   }
00764 
00765 
00766   /* Initialize bytecode-related fields in the size object.       */
00767   /* We do this only if bytecode interpretation is really needed. */
00768   static FT_Error
00769   tt_size_init_bytecode( FT_Size  ftsize )
00770   {
00771     FT_Error   error;
00772     TT_Size    size = (TT_Size)ftsize;
00773     TT_Face    face = (TT_Face)ftsize->face;
00774     FT_Memory  memory = face->root.memory;
00775     FT_Int     i;
00776 
00777     FT_UShort       n_twilight;
00778     TT_MaxProfile*  maxp = &face->max_profile;
00779 
00780 
00781     size->bytecode_ready = 1;
00782     size->cvt_ready      = 0;
00783 
00784     size->max_function_defs    = maxp->maxFunctionDefs;
00785     size->max_instruction_defs = maxp->maxInstructionDefs;
00786 
00787     size->num_function_defs    = 0;
00788     size->num_instruction_defs = 0;
00789 
00790     size->max_func = 0;
00791     size->max_ins  = 0;
00792 
00793     size->cvt_size     = face->cvt_size;
00794     size->storage_size = maxp->maxStorage;
00795 
00796     /* Set default metrics */
00797     {
00798       TT_Size_Metrics*  metrics = &size->ttmetrics;
00799 
00800 
00801       metrics->rotated   = FALSE;
00802       metrics->stretched = FALSE;
00803 
00804       /* set default compensation (all 0) */
00805       for ( i = 0; i < 4; i++ )
00806         metrics->compensations[i] = 0;
00807     }
00808 
00809     /* allocate function defs, instruction defs, cvt, and storage area */
00810     if ( FT_NEW_ARRAY( size->function_defs,    size->max_function_defs    ) ||
00811          FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
00812          FT_NEW_ARRAY( size->cvt,              size->cvt_size             ) ||
00813          FT_NEW_ARRAY( size->storage,          size->storage_size         ) )
00814       goto Exit;
00815 
00816     /* reserve twilight zone */
00817     n_twilight = maxp->maxTwilightPoints;
00818 
00819     /* there are 4 phantom points (do we need this?) */
00820     n_twilight += 4;
00821 
00822     error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
00823     if ( error )
00824       goto Exit;
00825 
00826     size->twilight.n_points = n_twilight;
00827 
00828     size->GS = tt_default_graphics_state;
00829 
00830     /* set `face->interpreter' according to the debug hook present */
00831     {
00832       FT_Library  library = face->root.driver->root.library;
00833 
00834 
00835       face->interpreter = (TT_Interpreter)
00836                             library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
00837       if ( !face->interpreter )
00838         face->interpreter = (TT_Interpreter)TT_RunIns;
00839     }
00840 
00841     /* Fine, now run the font program! */
00842     error = tt_size_run_fpgm( size );
00843 
00844   Exit:
00845     if ( error )
00846       tt_size_done_bytecode( ftsize );
00847 
00848     return error;
00849   }
00850 
00851 
00852   FT_LOCAL_DEF( FT_Error )
00853   tt_size_ready_bytecode( TT_Size  size )
00854   {
00855     FT_Error  error = TT_Err_Ok;
00856 
00857 
00858     if ( !size->bytecode_ready )
00859     {
00860       error = tt_size_init_bytecode( (FT_Size)size );
00861       if ( error )
00862         goto Exit;
00863     }
00864 
00865     /* rescale CVT when needed */
00866     if ( !size->cvt_ready )
00867     {
00868       FT_UInt  i;
00869       TT_Face  face = (TT_Face)size->root.face;
00870 
00871 
00872       /* Scale the cvt values to the new ppem.          */
00873       /* We use by default the y ppem to scale the CVT. */
00874       for ( i = 0; i < size->cvt_size; i++ )
00875         size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
00876 
00877       /* all twilight points are originally zero */
00878       for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
00879       {
00880         size->twilight.org[i].x = 0;
00881         size->twilight.org[i].y = 0;
00882         size->twilight.cur[i].x = 0;
00883         size->twilight.cur[i].y = 0;
00884       }
00885 
00886       /* clear storage area */
00887       for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
00888         size->storage[i] = 0;
00889 
00890       size->GS = tt_default_graphics_state;
00891 
00892       error = tt_size_run_prep( size );
00893       if ( !error )
00894         size->cvt_ready = 1;
00895     }
00896 
00897   Exit:
00898     return error;
00899   }
00900 
00901 #endif /* TT_USE_BYTECODE_INTERPRETER */
00902 
00903 
00904   /*************************************************************************/
00905   /*                                                                       */
00906   /* <Function>                                                            */
00907   /*    tt_size_init                                                       */
00908   /*                                                                       */
00909   /* <Description>                                                         */
00910   /*    Initialize a new TrueType size object.                             */
00911   /*                                                                       */
00912   /* <InOut>                                                               */
00913   /*    size :: A handle to the size object.                               */
00914   /*                                                                       */
00915   /* <Return>                                                              */
00916   /*    FreeType error code.  0 means success.                             */
00917   /*                                                                       */
00918   FT_LOCAL_DEF( FT_Error )
00919   tt_size_init( FT_Size  ttsize )           /* TT_Size */
00920   {
00921     TT_Size   size  = (TT_Size)ttsize;
00922     FT_Error  error = TT_Err_Ok;
00923 
00924 #ifdef TT_USE_BYTECODE_INTERPRETER
00925     size->bytecode_ready = 0;
00926     size->cvt_ready      = 0;
00927 #endif
00928 
00929     size->ttmetrics.valid = FALSE;
00930     size->strike_index    = 0xFFFFFFFFUL;
00931 
00932     return error;
00933   }
00934 
00935 
00936   /*************************************************************************/
00937   /*                                                                       */
00938   /* <Function>                                                            */
00939   /*    tt_size_done                                                       */
00940   /*                                                                       */
00941   /* <Description>                                                         */
00942   /*    The TrueType size object finalizer.                                */
00943   /*                                                                       */
00944   /* <Input>                                                               */
00945   /*    size :: A handle to the target size object.                        */
00946   /*                                                                       */
00947   FT_LOCAL_DEF( void )
00948   tt_size_done( FT_Size  ttsize )           /* TT_Size */
00949   {
00950     TT_Size  size = (TT_Size)ttsize;
00951 
00952 
00953 #ifdef TT_USE_BYTECODE_INTERPRETER
00954     if ( size->bytecode_ready )
00955       tt_size_done_bytecode( ttsize );
00956 #endif
00957 
00958     size->ttmetrics.valid = FALSE;
00959   }
00960 
00961 
00962   /*************************************************************************/
00963   /*                                                                       */
00964   /* <Function>                                                            */
00965   /*    tt_size_reset                                                      */
00966   /*                                                                       */
00967   /* <Description>                                                         */
00968   /*    Reset a TrueType size when resolutions and character dimensions    */
00969   /*    have been changed.                                                 */
00970   /*                                                                       */
00971   /* <Input>                                                               */
00972   /*    size :: A handle to the target size object.                        */
00973   /*                                                                       */
00974   FT_LOCAL_DEF( FT_Error )
00975   tt_size_reset( TT_Size  size )
00976   {
00977     TT_Face           face;
00978     FT_Error          error = TT_Err_Ok;
00979     FT_Size_Metrics*  metrics;
00980 
00981 
00982     size->ttmetrics.valid = FALSE;
00983 
00984     face = (TT_Face)size->root.face;
00985 
00986     metrics = &size->metrics;
00987 
00988     /* copy the result from base layer */
00989     *metrics = size->root.metrics;
00990 
00991     if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
00992       return TT_Err_Invalid_PPem;
00993 
00994     /* This bit flag, if set, indicates that the ppems must be       */
00995     /* rounded to integers.  Nearly all TrueType fonts have this bit */
00996     /* set, as hinting won't work really well otherwise.             */
00997     /*                                                               */
00998     if ( face->header.Flags & 8 )
00999     {
01000       metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
01001                                     face->root.units_per_EM );
01002       metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
01003                                     face->root.units_per_EM );
01004 
01005       metrics->ascender =
01006         FT_PIX_ROUND( FT_MulFix( face->root.ascender, metrics->y_scale ) );
01007       metrics->descender =
01008         FT_PIX_ROUND( FT_MulFix( face->root.descender, metrics->y_scale ) );
01009       metrics->height =
01010         FT_PIX_ROUND( FT_MulFix( face->root.height, metrics->y_scale ) );
01011       metrics->max_advance =
01012         FT_PIX_ROUND( FT_MulFix( face->root.max_advance_width,
01013                                  metrics->x_scale ) );
01014     }
01015 
01016     /* compute new transformation */
01017     if ( metrics->x_ppem >= metrics->y_ppem )
01018     {
01019       size->ttmetrics.scale   = metrics->x_scale;
01020       size->ttmetrics.ppem    = metrics->x_ppem;
01021       size->ttmetrics.x_ratio = 0x10000L;
01022       size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
01023                                            0x10000L,
01024                                            metrics->x_ppem );
01025     }
01026     else
01027     {
01028       size->ttmetrics.scale   = metrics->y_scale;
01029       size->ttmetrics.ppem    = metrics->y_ppem;
01030       size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
01031                                            0x10000L,
01032                                            metrics->y_ppem );
01033       size->ttmetrics.y_ratio = 0x10000L;
01034     }
01035 
01036 #ifdef TT_USE_BYTECODE_INTERPRETER
01037     size->cvt_ready = 0;
01038 #endif /* TT_USE_BYTECODE_INTERPRETER */
01039 
01040     if ( !error )
01041       size->ttmetrics.valid = TRUE;
01042 
01043     return error;
01044   }
01045 
01046 
01047   /*************************************************************************/
01048   /*                                                                       */
01049   /* <Function>                                                            */
01050   /*    tt_driver_init                                                     */
01051   /*                                                                       */
01052   /* <Description>                                                         */
01053   /*    Initialize a given TrueType driver object.                         */
01054   /*                                                                       */
01055   /* <Input>                                                               */
01056   /*    driver :: A handle to the target driver object.                    */
01057   /*                                                                       */
01058   /* <Return>                                                              */
01059   /*    FreeType error code.  0 means success.                             */
01060   /*                                                                       */
01061   FT_LOCAL_DEF( FT_Error )
01062   tt_driver_init( FT_Module  ttdriver )     /* TT_Driver */
01063   {
01064 
01065 #ifdef TT_USE_BYTECODE_INTERPRETER
01066 
01067     TT_Driver  driver = (TT_Driver)ttdriver;
01068 
01069 
01070     if ( !TT_New_Context( driver ) )
01071       return TT_Err_Could_Not_Find_Context;
01072 
01073 #else
01074 
01075     FT_UNUSED( ttdriver );
01076 
01077 #endif
01078 
01079     return TT_Err_Ok;
01080   }
01081 
01082 
01083   /*************************************************************************/
01084   /*                                                                       */
01085   /* <Function>                                                            */
01086   /*    tt_driver_done                                                     */
01087   /*                                                                       */
01088   /* <Description>                                                         */
01089   /*    Finalize a given TrueType driver.                                  */
01090   /*                                                                       */
01091   /* <Input>                                                               */
01092   /*    driver :: A handle to the target TrueType driver.                  */
01093   /*                                                                       */
01094   FT_LOCAL_DEF( void )
01095   tt_driver_done( FT_Module  ttdriver )     /* TT_Driver */
01096   {
01097 #ifdef TT_USE_BYTECODE_INTERPRETER
01098     TT_Driver  driver = (TT_Driver)ttdriver;
01099 
01100 
01101     /* destroy the execution context */
01102     if ( driver->context )
01103     {
01104       TT_Done_Context( driver->context );
01105       driver->context = NULL;
01106     }
01107 #else
01108     FT_UNUSED( ttdriver );
01109 #endif
01110 
01111   }
01112 
01113 
01114   /*************************************************************************/
01115   /*                                                                       */
01116   /* <Function>                                                            */
01117   /*    tt_slot_init                                                       */
01118   /*                                                                       */
01119   /* <Description>                                                         */
01120   /*    Initialize a new slot object.                                      */
01121   /*                                                                       */
01122   /* <InOut>                                                               */
01123   /*    slot :: A handle to the slot object.                               */
01124   /*                                                                       */
01125   /* <Return>                                                              */
01126   /*    FreeType error code.  0 means success.                             */
01127   /*                                                                       */
01128   FT_LOCAL_DEF( FT_Error )
01129   tt_slot_init( FT_GlyphSlot  slot )
01130   {
01131     return FT_GlyphLoader_CreateExtra( slot->internal->loader );
01132   }
01133 
01134 
01135 /* END */

Generated on Tue May 22 2012 04:38:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.