t1driver.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  t1driver.c                                                             */
00004 /*                                                                         */
00005 /*    Type 1 driver interface (body).                                      */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007, 2009 by             */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #include <ft2build.h>
00020 #include "t1driver.h"
00021 #include "t1gload.h"
00022 #include "t1load.h"
00023 
00024 #include "t1errors.h"
00025 
00026 #ifndef T1_CONFIG_OPTION_NO_AFM
00027 #include "t1afm.h"
00028 #endif
00029 
00030 #include FT_INTERNAL_DEBUG_H
00031 #include FT_INTERNAL_STREAM_H
00032 
00033 #include FT_SERVICE_MULTIPLE_MASTERS_H
00034 #include FT_SERVICE_GLYPH_DICT_H
00035 #include FT_SERVICE_XFREE86_NAME_H
00036 #include FT_SERVICE_POSTSCRIPT_NAME_H
00037 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
00038 #include FT_SERVICE_POSTSCRIPT_INFO_H
00039 #include FT_SERVICE_KERNING_H
00040 
00041 
00042   /*************************************************************************/
00043   /*                                                                       */
00044   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00045   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00046   /* messages during execution.                                            */
00047   /*                                                                       */
00048 #undef  FT_COMPONENT
00049 #define FT_COMPONENT  trace_t1driver
00050 
00051  /*
00052   *  GLYPH DICT SERVICE
00053   *
00054   */
00055 
00056   static FT_Error
00057   t1_get_glyph_name( T1_Face     face,
00058                      FT_UInt     glyph_index,
00059                      FT_Pointer  buffer,
00060                      FT_UInt     buffer_max )
00061   {
00062     FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max );
00063 
00064     return T1_Err_Ok;
00065   }
00066 
00067 
00068   static FT_UInt
00069   t1_get_name_index( T1_Face     face,
00070                      FT_String*  glyph_name )
00071   {
00072     FT_Int      i;
00073     FT_String*  gname;
00074 
00075 
00076     for ( i = 0; i < face->type1.num_glyphs; i++ )
00077     {
00078       gname = face->type1.glyph_names[i];
00079 
00080       if ( !ft_strcmp( glyph_name, gname ) )
00081         return (FT_UInt)i;
00082     }
00083 
00084     return 0;
00085   }
00086 
00087 
00088   static const FT_Service_GlyphDictRec  t1_service_glyph_dict =
00089   {
00090     (FT_GlyphDict_GetNameFunc)  t1_get_glyph_name,
00091     (FT_GlyphDict_NameIndexFunc)t1_get_name_index
00092   };
00093 
00094 
00095   /*
00096    *  POSTSCRIPT NAME SERVICE
00097    *
00098    */
00099 
00100   static const char*
00101   t1_get_ps_name( T1_Face  face )
00102   {
00103     return (const char*) face->type1.font_name;
00104   }
00105 
00106 
00107   static const FT_Service_PsFontNameRec  t1_service_ps_name =
00108   {
00109     (FT_PsName_GetFunc)t1_get_ps_name
00110   };
00111 
00112 
00113   /*
00114    *  MULTIPLE MASTERS SERVICE
00115    *
00116    */
00117 
00118 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
00119   static const FT_Service_MultiMastersRec  t1_service_multi_masters =
00120   {
00121     (FT_Get_MM_Func)        T1_Get_Multi_Master,
00122     (FT_Set_MM_Design_Func) T1_Set_MM_Design,
00123     (FT_Set_MM_Blend_Func)  T1_Set_MM_Blend,
00124     (FT_Get_MM_Var_Func)    T1_Get_MM_Var,
00125     (FT_Set_Var_Design_Func)T1_Set_Var_Design
00126   };
00127 #endif
00128 
00129 
00130   /*
00131    *  POSTSCRIPT INFO SERVICE
00132    *
00133    */
00134 
00135   static FT_Error
00136   t1_ps_get_font_info( FT_Face          face,
00137                        PS_FontInfoRec*  afont_info )
00138   {
00139     *afont_info = ((T1_Face)face)->type1.font_info;
00140 
00141     return T1_Err_Ok;
00142   }
00143 
00144 
00145   static FT_Error
00146   t1_ps_get_font_extra( FT_Face           face,
00147                         PS_FontExtraRec*  afont_extra )
00148   {
00149     *afont_extra = ((T1_Face)face)->type1.font_extra;
00150 
00151     return T1_Err_Ok;
00152   }
00153 
00154 
00155   static FT_Int
00156   t1_ps_has_glyph_names( FT_Face  face )
00157   {
00158     FT_UNUSED( face );
00159 
00160     return 1;
00161   }
00162 
00163 
00164   static FT_Error
00165   t1_ps_get_font_private( FT_Face         face,
00166                           PS_PrivateRec*  afont_private )
00167   {
00168     *afont_private = ((T1_Face)face)->type1.private_dict;
00169 
00170     return T1_Err_Ok;
00171   }
00172 
00173 
00174   static const FT_Service_PsInfoRec  t1_service_ps_info =
00175   {
00176     (PS_GetFontInfoFunc)   t1_ps_get_font_info,
00177     (PS_GetFontExtraFunc)  t1_ps_get_font_extra,
00178     (PS_HasGlyphNamesFunc) t1_ps_has_glyph_names,
00179     (PS_GetFontPrivateFunc)t1_ps_get_font_private,
00180   };
00181 
00182 
00183 #ifndef T1_CONFIG_OPTION_NO_AFM
00184   static const FT_Service_KerningRec  t1_service_kerning =
00185   {
00186     T1_Get_Track_Kerning,
00187   };
00188 #endif
00189 
00190 
00191   /*
00192    *  SERVICE LIST
00193    *
00194    */
00195 
00196   static const FT_ServiceDescRec  t1_services[] =
00197   {
00198     { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &t1_service_ps_name },
00199     { FT_SERVICE_ID_GLYPH_DICT,           &t1_service_glyph_dict },
00200     { FT_SERVICE_ID_XF86_NAME,            FT_XF86_FORMAT_TYPE_1 },
00201     { FT_SERVICE_ID_POSTSCRIPT_INFO,      &t1_service_ps_info },
00202 
00203 #ifndef T1_CONFIG_OPTION_NO_AFM
00204     { FT_SERVICE_ID_KERNING,              &t1_service_kerning },
00205 #endif
00206 
00207 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
00208     { FT_SERVICE_ID_MULTI_MASTERS,        &t1_service_multi_masters },
00209 #endif
00210     { NULL, NULL }
00211   };
00212 
00213 
00214   static FT_Module_Interface
00215   Get_Interface( FT_Driver         driver,
00216                  const FT_String*  t1_interface )
00217   {
00218     FT_UNUSED( driver );
00219 
00220     return ft_service_list_lookup( t1_services, t1_interface );
00221   }
00222 
00223 
00224 #ifndef T1_CONFIG_OPTION_NO_AFM
00225 
00226   /*************************************************************************/
00227   /*                                                                       */
00228   /* <Function>                                                            */
00229   /*    Get_Kerning                                                        */
00230   /*                                                                       */
00231   /* <Description>                                                         */
00232   /*    A driver method used to return the kerning vector between two      */
00233   /*    glyphs of the same face.                                           */
00234   /*                                                                       */
00235   /* <Input>                                                               */
00236   /*    face        :: A handle to the source face object.                 */
00237   /*                                                                       */
00238   /*    left_glyph  :: The index of the left glyph in the kern pair.       */
00239   /*                                                                       */
00240   /*    right_glyph :: The index of the right glyph in the kern pair.      */
00241   /*                                                                       */
00242   /* <Output>                                                              */
00243   /*    kerning     :: The kerning vector.  This is in font units for      */
00244   /*                   scalable formats, and in pixels for fixed-sizes     */
00245   /*                   formats.                                            */
00246   /*                                                                       */
00247   /* <Return>                                                              */
00248   /*    FreeType error code.  0 means success.                             */
00249   /*                                                                       */
00250   /* <Note>                                                                */
00251   /*    Only horizontal layouts (left-to-right & right-to-left) are        */
00252   /*    supported by this function.  Other layouts, or more sophisticated  */
00253   /*    kernings are out of scope of this method (the basic driver         */
00254   /*    interface is meant to be simple).                                  */
00255   /*                                                                       */
00256   /*    They can be implemented by format-specific interfaces.             */
00257   /*                                                                       */
00258   static FT_Error
00259   Get_Kerning( T1_Face     face,
00260                FT_UInt     left_glyph,
00261                FT_UInt     right_glyph,
00262                FT_Vector*  kerning )
00263   {
00264     kerning->x = 0;
00265     kerning->y = 0;
00266 
00267     if ( face->afm_data )
00268       T1_Get_Kerning( (AFM_FontInfo)face->afm_data,
00269                       left_glyph,
00270                       right_glyph,
00271                       kerning );
00272 
00273     return T1_Err_Ok;
00274   }
00275 
00276 
00277 #endif /* T1_CONFIG_OPTION_NO_AFM */
00278 
00279 
00280   FT_CALLBACK_TABLE_DEF
00281   const FT_Driver_ClassRec  t1_driver_class =
00282   {
00283     {
00284       FT_MODULE_FONT_DRIVER       |
00285       FT_MODULE_DRIVER_SCALABLE   |
00286       FT_MODULE_DRIVER_HAS_HINTER,
00287 
00288       sizeof( FT_DriverRec ),
00289 
00290       "type1",
00291       0x10000L,
00292       0x20000L,
00293 
00294       0,   /* format interface */
00295 
00296       (FT_Module_Constructor)T1_Driver_Init,
00297       (FT_Module_Destructor) T1_Driver_Done,
00298       (FT_Module_Requester)  Get_Interface,
00299     },
00300 
00301     sizeof( T1_FaceRec ),
00302     sizeof( T1_SizeRec ),
00303     sizeof( T1_GlyphSlotRec ),
00304 
00305     (FT_Face_InitFunc)        T1_Face_Init,
00306     (FT_Face_DoneFunc)        T1_Face_Done,
00307     (FT_Size_InitFunc)        T1_Size_Init,
00308     (FT_Size_DoneFunc)        T1_Size_Done,
00309     (FT_Slot_InitFunc)        T1_GlyphSlot_Init,
00310     (FT_Slot_DoneFunc)        T1_GlyphSlot_Done,
00311 
00312 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
00313     ft_stub_set_char_sizes,
00314     ft_stub_set_pixel_sizes,
00315 #endif
00316     (FT_Slot_LoadFunc)        T1_Load_Glyph,
00317 
00318 #ifdef T1_CONFIG_OPTION_NO_AFM
00319     (FT_Face_GetKerningFunc)  0,
00320     (FT_Face_AttachFunc)      0,
00321 #else
00322     (FT_Face_GetKerningFunc)  Get_Kerning,
00323     (FT_Face_AttachFunc)      T1_Read_Metrics,
00324 #endif
00325     (FT_Face_GetAdvancesFunc) T1_Get_Advances,
00326     (FT_Size_RequestFunc)     T1_Size_Request,
00327     (FT_Size_SelectFunc)      0
00328   };
00329 
00330 
00331 /* END */

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