ttdriver.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ttdriver.c                                                             */
00004 /*                                                                         */
00005 /*    TrueType font driver implementation (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_INTERNAL_SFNT_H
00024 #include FT_SERVICE_XFREE86_NAME_H
00025 
00026 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
00027 #include FT_MULTIPLE_MASTERS_H
00028 #include FT_SERVICE_MULTIPLE_MASTERS_H
00029 #endif
00030 
00031 #include FT_SERVICE_TRUETYPE_ENGINE_H
00032 #include FT_SERVICE_TRUETYPE_GLYF_H
00033 
00034 #include "ttdriver.h"
00035 #include "ttgload.h"
00036 #include "ttpload.h"
00037 
00038 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
00039 #include "ttgxvar.h"
00040 #endif
00041 
00042 #include "tterrors.h"
00043 
00044 #include "ttpic.h"
00045 
00046   /*************************************************************************/
00047   /*                                                                       */
00048   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00049   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00050   /* messages during execution.                                            */
00051   /*                                                                       */
00052 #undef  FT_COMPONENT
00053 #define FT_COMPONENT  trace_ttdriver
00054 
00055 
00056   /*************************************************************************/
00057   /*************************************************************************/
00058   /*************************************************************************/
00059   /****                                                                 ****/
00060   /****                                                                 ****/
00061   /****                          F A C E S                              ****/
00062   /****                                                                 ****/
00063   /****                                                                 ****/
00064   /*************************************************************************/
00065   /*************************************************************************/
00066   /*************************************************************************/
00067 
00068 
00069 #undef  PAIR_TAG
00070 #define PAIR_TAG( left, right )  ( ( (FT_ULong)left << 16 ) | \
00071                                      (FT_ULong)right        )
00072 
00073 
00074   /*************************************************************************/
00075   /*                                                                       */
00076   /* <Function>                                                            */
00077   /*    tt_get_kerning                                                     */
00078   /*                                                                       */
00079   /* <Description>                                                         */
00080   /*    A driver method used to return the kerning vector between two      */
00081   /*    glyphs of the same face.                                           */
00082   /*                                                                       */
00083   /* <Input>                                                               */
00084   /*    face        :: A handle to the source face object.                 */
00085   /*                                                                       */
00086   /*    left_glyph  :: The index of the left glyph in the kern pair.       */
00087   /*                                                                       */
00088   /*    right_glyph :: The index of the right glyph in the kern pair.      */
00089   /*                                                                       */
00090   /* <Output>                                                              */
00091   /*    kerning     :: The kerning vector.  This is in font units for      */
00092   /*                   scalable formats, and in pixels for fixed-sizes     */
00093   /*                   formats.                                            */
00094   /*                                                                       */
00095   /* <Return>                                                              */
00096   /*    FreeType error code.  0 means success.                             */
00097   /*                                                                       */
00098   /* <Note>                                                                */
00099   /*    Only horizontal layouts (left-to-right & right-to-left) are        */
00100   /*    supported by this function.  Other layouts, or more sophisticated  */
00101   /*    kernings, are out of scope of this method (the basic driver        */
00102   /*    interface is meant to be simple).                                  */
00103   /*                                                                       */
00104   /*    They can be implemented by format-specific interfaces.             */
00105   /*                                                                       */
00106   static FT_Error
00107   tt_get_kerning( FT_Face     ttface,          /* TT_Face */
00108                   FT_UInt     left_glyph,
00109                   FT_UInt     right_glyph,
00110                   FT_Vector*  kerning )
00111   {
00112     TT_Face       face = (TT_Face)ttface;
00113     SFNT_Service  sfnt = (SFNT_Service)face->sfnt;
00114 
00115 
00116     kerning->x = 0;
00117     kerning->y = 0;
00118 
00119     if ( sfnt )
00120       kerning->x = sfnt->get_kerning( face, left_glyph, right_glyph );
00121 
00122     return 0;
00123   }
00124 
00125 
00126 #undef PAIR_TAG
00127 
00128 
00129   static FT_Error
00130   tt_get_advances( FT_Face    ttface,
00131                    FT_UInt    start,
00132                    FT_UInt    count,
00133                    FT_Int32   flags,
00134                    FT_Fixed  *advances )
00135   {
00136     FT_UInt  nn;
00137     TT_Face  face  = (TT_Face) ttface;
00138     FT_Bool  check = FT_BOOL(
00139                        !( flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) );
00140 
00141 
00142     /* XXX: TODO: check for sbits */
00143 
00144     if ( flags & FT_LOAD_VERTICAL_LAYOUT )
00145     {
00146       for ( nn = 0; nn < count; nn++ )
00147       {
00148         FT_Short   tsb;
00149         FT_UShort  ah;
00150 
00151 
00152         TT_Get_VMetrics( face, start + nn, check, &tsb, &ah );
00153         advances[nn] = ah;
00154       }
00155     }
00156     else
00157     {
00158       for ( nn = 0; nn < count; nn++ )
00159       {
00160         FT_Short   lsb;
00161         FT_UShort  aw;
00162 
00163 
00164         TT_Get_HMetrics( face, start + nn, check, &lsb, &aw );
00165         advances[nn] = aw;
00166       }
00167     }
00168 
00169     return TT_Err_Ok;
00170   }
00171 
00172   /*************************************************************************/
00173   /*************************************************************************/
00174   /*************************************************************************/
00175   /****                                                                 ****/
00176   /****                                                                 ****/
00177   /****                           S I Z E S                             ****/
00178   /****                                                                 ****/
00179   /****                                                                 ****/
00180   /*************************************************************************/
00181   /*************************************************************************/
00182   /*************************************************************************/
00183 
00184 
00185 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
00186 
00187   static FT_Error
00188   tt_size_select( FT_Size   size,
00189                   FT_ULong  strike_index )
00190   {
00191     TT_Face   ttface = (TT_Face)size->face;
00192     TT_Size   ttsize = (TT_Size)size;
00193     FT_Error  error  = TT_Err_Ok;
00194 
00195 
00196     ttsize->strike_index = strike_index;
00197 
00198     if ( FT_IS_SCALABLE( size->face ) )
00199     {
00200       /* use the scaled metrics, even when tt_size_reset fails */
00201       FT_Select_Metrics( size->face, strike_index );
00202 
00203       tt_size_reset( ttsize );
00204     }
00205     else
00206     {
00207       SFNT_Service      sfnt    = (SFNT_Service) ttface->sfnt;
00208       FT_Size_Metrics*  metrics = &size->metrics;
00209 
00210 
00211       error = sfnt->load_strike_metrics( ttface, strike_index, metrics );
00212       if ( error )
00213         ttsize->strike_index = 0xFFFFFFFFUL;
00214     }
00215 
00216     return error;
00217   }
00218 
00219 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
00220 
00221 
00222   static FT_Error
00223   tt_size_request( FT_Size          size,
00224                    FT_Size_Request  req )
00225   {
00226     TT_Size   ttsize = (TT_Size)size;
00227     FT_Error  error  = TT_Err_Ok;
00228 
00229 
00230 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
00231 
00232     if ( FT_HAS_FIXED_SIZES( size->face ) )
00233     {
00234       TT_Face       ttface = (TT_Face)size->face;
00235       SFNT_Service  sfnt   = (SFNT_Service) ttface->sfnt;
00236       FT_ULong      strike_index;
00237 
00238 
00239       error = sfnt->set_sbit_strike( ttface, req, &strike_index );
00240 
00241       if ( error )
00242         ttsize->strike_index = 0xFFFFFFFFUL;
00243       else
00244         return tt_size_select( size, strike_index );
00245     }
00246 
00247 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
00248 
00249     FT_Request_Metrics( size->face, req );
00250 
00251     if ( FT_IS_SCALABLE( size->face ) )
00252       error = tt_size_reset( ttsize );
00253 
00254     return error;
00255   }
00256 
00257 
00258   /*************************************************************************/
00259   /*                                                                       */
00260   /* <Function>                                                            */
00261   /*    Load_Glyph                                                         */
00262   /*                                                                       */
00263   /* <Description>                                                         */
00264   /*    A driver method used to load a glyph within a given glyph slot.    */
00265   /*                                                                       */
00266   /* <Input>                                                               */
00267   /*    slot        :: A handle to the target slot object where the glyph  */
00268   /*                   will be loaded.                                     */
00269   /*                                                                       */
00270   /*    size        :: A handle to the source face size at which the glyph */
00271   /*                   must be scaled, loaded, etc.                        */
00272   /*                                                                       */
00273   /*    glyph_index :: The index of the glyph in the font file.            */
00274   /*                                                                       */
00275   /*    load_flags  :: A flag indicating what to load for this glyph.  The */
00276   /*                   FT_LOAD_XXX constants can be used to control the    */
00277   /*                   glyph loading process (e.g., whether the outline    */
00278   /*                   should be scaled, whether to load bitmaps or not,   */
00279   /*                   whether to hint the outline, etc).                  */
00280   /*                                                                       */
00281   /* <Return>                                                              */
00282   /*    FreeType error code.  0 means success.                             */
00283   /*                                                                       */
00284   static FT_Error
00285   Load_Glyph( FT_GlyphSlot  ttslot,         /* TT_GlyphSlot */
00286               FT_Size       ttsize,         /* TT_Size      */
00287               FT_UInt       glyph_index,
00288               FT_Int32      load_flags )
00289   {
00290     TT_GlyphSlot  slot = (TT_GlyphSlot)ttslot;
00291     TT_Size       size = (TT_Size)ttsize;
00292     FT_Face       face = ttslot->face;
00293     FT_Error      error;
00294 
00295 
00296     if ( !slot )
00297       return TT_Err_Invalid_Slot_Handle;
00298 
00299     if ( !size )
00300       return TT_Err_Invalid_Size_Handle;
00301 
00302     if ( !face )
00303       return TT_Err_Invalid_Argument;
00304 
00305 #ifdef FT_CONFIG_OPTION_INCREMENTAL
00306     if ( glyph_index >= (FT_UInt)face->num_glyphs &&
00307          !face->internal->incremental_interface   )
00308 #else
00309     if ( glyph_index >= (FT_UInt)face->num_glyphs )
00310 #endif
00311       return TT_Err_Invalid_Argument;
00312 
00313     if ( load_flags & FT_LOAD_NO_HINTING )
00314     {
00315       /* both FT_LOAD_NO_HINTING and FT_LOAD_NO_AUTOHINT   */
00316       /* are necessary to disable hinting for tricky fonts */          
00317 
00318       if ( FT_IS_TRICKY( face ) )
00319         load_flags &= ~FT_LOAD_NO_HINTING;
00320 
00321       if ( load_flags & FT_LOAD_NO_AUTOHINT )
00322         load_flags |= FT_LOAD_NO_HINTING;
00323     }
00324 
00325     if ( load_flags & ( FT_LOAD_NO_RECURSE | FT_LOAD_NO_SCALE ) )
00326     {
00327       load_flags |= FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE;
00328 
00329       if ( !FT_IS_TRICKY( face ) )
00330         load_flags |= FT_LOAD_NO_HINTING;
00331     }
00332 
00333     /* now load the glyph outline if necessary */
00334     error = TT_Load_Glyph( size, slot, glyph_index, load_flags );
00335 
00336     /* force drop-out mode to 2 - irrelevant now */
00337     /* slot->outline.dropout_mode = 2; */
00338 
00339     return error;
00340   }
00341 
00342 
00343   /*************************************************************************/
00344   /*************************************************************************/
00345   /*************************************************************************/
00346   /****                                                                 ****/
00347   /****                                                                 ****/
00348   /****                D R I V E R  I N T E R F A C E                   ****/
00349   /****                                                                 ****/
00350   /****                                                                 ****/
00351   /*************************************************************************/
00352   /*************************************************************************/
00353   /*************************************************************************/
00354 
00355 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
00356   FT_DEFINE_SERVICE_MULTIMASTERSREC(tt_service_gx_multi_masters,
00357     (FT_Get_MM_Func)        NULL,
00358     (FT_Set_MM_Design_Func) NULL,
00359     (FT_Set_MM_Blend_Func)  TT_Set_MM_Blend,
00360     (FT_Get_MM_Var_Func)    TT_Get_MM_Var,
00361     (FT_Set_Var_Design_Func)TT_Set_Var_Design
00362   )
00363 #endif
00364 
00365   static const FT_Service_TrueTypeEngineRec  tt_service_truetype_engine =
00366   {
00367 #ifdef TT_USE_BYTECODE_INTERPRETER
00368 
00369 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
00370     FT_TRUETYPE_ENGINE_TYPE_UNPATENTED
00371 #else
00372     FT_TRUETYPE_ENGINE_TYPE_PATENTED
00373 #endif
00374 
00375 #else /* !TT_USE_BYTECODE_INTERPRETER */
00376 
00377     FT_TRUETYPE_ENGINE_TYPE_NONE
00378 
00379 #endif /* TT_USE_BYTECODE_INTERPRETER */
00380   };
00381 
00382   FT_DEFINE_SERVICE_TTGLYFREC(tt_service_truetype_glyf,
00383     (TT_Glyf_GetLocationFunc)tt_face_get_location
00384   )
00385 
00386 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
00387   FT_DEFINE_SERVICEDESCREC4(tt_services,
00388     FT_SERVICE_ID_XF86_NAME,       FT_XF86_FORMAT_TRUETYPE,
00389     FT_SERVICE_ID_MULTI_MASTERS,   &FT_TT_SERVICE_GX_MULTI_MASTERS_GET,
00390     FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine,
00391     FT_SERVICE_ID_TT_GLYF,         &FT_TT_SERVICE_TRUETYPE_GLYF_GET
00392   )
00393 #else
00394   FT_DEFINE_SERVICEDESCREC3(tt_services,
00395     FT_SERVICE_ID_XF86_NAME,       FT_XF86_FORMAT_TRUETYPE,
00396     FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine,
00397     FT_SERVICE_ID_TT_GLYF,         &FT_TT_SERVICE_TRUETYPE_GLYF_GET
00398   )
00399 #endif
00400 
00401   FT_CALLBACK_DEF( FT_Module_Interface )
00402   tt_get_interface( FT_Module    driver,    /* TT_Driver */
00403                     const char*  tt_interface )
00404   {
00405     FT_Module_Interface  result;
00406     FT_Module            sfntd;
00407     SFNT_Service         sfnt;
00408 
00409     result = ft_service_list_lookup( FT_TT_SERVICES_GET, tt_interface );
00410     if ( result != NULL )
00411       return result;
00412 
00413     if ( !driver )
00414       return NULL;
00415 
00416     /* only return the default interface from the SFNT module */
00417     sfntd = FT_Get_Module( driver->library, "sfnt" );
00418     if ( sfntd )
00419     {
00420       sfnt = (SFNT_Service)( sfntd->clazz->module_interface );
00421       if ( sfnt )
00422         return sfnt->get_interface( driver, tt_interface );
00423     }
00424 
00425     return 0;
00426   }
00427 
00428 
00429   /* The FT_DriverInterface structure is defined in ftdriver.h. */
00430 
00431 #ifdef TT_USE_BYTECODE_INTERPRETER
00432 #define TT_HINTER_FLAG   FT_MODULE_DRIVER_HAS_HINTER
00433 #else
00434 #define TT_HINTER_FLAG   0
00435 #endif
00436 
00437 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
00438 #define TT_SIZE_SELECT    tt_size_select
00439 #else
00440 #define TT_SIZE_SELECT    0
00441 #endif
00442 
00443   FT_DEFINE_DRIVER(tt_driver_class,
00444   
00445     
00446       FT_MODULE_FONT_DRIVER        |
00447       FT_MODULE_DRIVER_SCALABLE    |
00448       TT_HINTER_FLAG,
00449 
00450       sizeof ( TT_DriverRec ),
00451 
00452       "truetype",      /* driver name                           */
00453       0x10000L,        /* driver version == 1.0                 */
00454       0x20000L,        /* driver requires FreeType 2.0 or above */
00455 
00456       (void*)0,        /* driver specific interface */
00457 
00458       tt_driver_init,
00459       tt_driver_done,
00460       tt_get_interface,
00461 
00462     sizeof ( TT_FaceRec ),
00463     sizeof ( TT_SizeRec ),
00464     sizeof ( FT_GlyphSlotRec ),
00465 
00466     tt_face_init,
00467     tt_face_done,
00468     tt_size_init,
00469     tt_size_done,
00470     tt_slot_init,
00471     0,                      /* FT_Slot_DoneFunc */
00472 
00473     ft_stub_set_char_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */
00474     ft_stub_set_pixel_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */
00475 
00476     Load_Glyph,
00477 
00478     tt_get_kerning,
00479     0,                      /* FT_Face_AttachFunc      */
00480     tt_get_advances,
00481 
00482     tt_size_request,
00483     TT_SIZE_SELECT
00484   )
00485 
00486 
00487 /* END */

Generated on Tue Jul 5 14:13:53 2011 for ROOT_528-00b_version by  doxygen 1.5.1