misc/libfreetype/src/cid/cidriver.c
changeset 5172 88f2e05288ba
equal deleted inserted replaced
5171:f9283dc4860d 5172:88f2e05288ba
       
     1 /***************************************************************************/
       
     2 /*                                                                         */
       
     3 /*  cidriver.c                                                             */
       
     4 /*                                                                         */
       
     5 /*    CID driver interface (body).                                         */
       
     6 /*                                                                         */
       
     7 /*  Copyright 1996-2001, 2002, 2003, 2004, 2006, 2008, 2009 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 
       
    18 
       
    19 #include <ft2build.h>
       
    20 #include "cidriver.h"
       
    21 #include "cidgload.h"
       
    22 #include FT_INTERNAL_DEBUG_H
       
    23 
       
    24 #include "ciderrs.h"
       
    25 
       
    26 #include FT_SERVICE_POSTSCRIPT_NAME_H
       
    27 #include FT_SERVICE_XFREE86_NAME_H
       
    28 #include FT_SERVICE_POSTSCRIPT_INFO_H
       
    29 #include FT_SERVICE_CID_H
       
    30 
       
    31 
       
    32   /*************************************************************************/
       
    33   /*                                                                       */
       
    34   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
       
    35   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
       
    36   /* messages during execution.                                            */
       
    37   /*                                                                       */
       
    38 #undef  FT_COMPONENT
       
    39 #define FT_COMPONENT  trace_ciddriver
       
    40 
       
    41 
       
    42   /*
       
    43    *  POSTSCRIPT NAME SERVICE
       
    44    *
       
    45    */
       
    46 
       
    47   static const char*
       
    48   cid_get_postscript_name( CID_Face  face )
       
    49   {
       
    50     const char*  result = face->cid.cid_font_name;
       
    51 
       
    52 
       
    53     if ( result && result[0] == '/' )
       
    54       result++;
       
    55 
       
    56     return result;
       
    57   }
       
    58 
       
    59 
       
    60   static const FT_Service_PsFontNameRec  cid_service_ps_name =
       
    61   {
       
    62     (FT_PsName_GetFunc) cid_get_postscript_name
       
    63   };
       
    64 
       
    65 
       
    66   /*
       
    67    *  POSTSCRIPT INFO SERVICE
       
    68    *
       
    69    */
       
    70 
       
    71   static FT_Error
       
    72   cid_ps_get_font_info( FT_Face          face,
       
    73                         PS_FontInfoRec*  afont_info )
       
    74   {
       
    75     *afont_info = ((CID_Face)face)->cid.font_info;
       
    76 
       
    77     return CID_Err_Ok;
       
    78   }
       
    79 
       
    80   static FT_Error
       
    81   cid_ps_get_font_extra( FT_Face          face,
       
    82                         PS_FontExtraRec*  afont_extra )
       
    83   {
       
    84     *afont_extra = ((CID_Face)face)->font_extra;
       
    85 
       
    86     return CID_Err_Ok;
       
    87   }
       
    88 
       
    89   static const FT_Service_PsInfoRec  cid_service_ps_info =
       
    90   {
       
    91     (PS_GetFontInfoFunc)   cid_ps_get_font_info,
       
    92     (PS_GetFontExtraFunc)  cid_ps_get_font_extra,
       
    93     (PS_HasGlyphNamesFunc) NULL,        /* unsupported with CID fonts */
       
    94     (PS_GetFontPrivateFunc)NULL         /* unsupported                */
       
    95   };
       
    96 
       
    97 
       
    98   /*
       
    99    *  CID INFO SERVICE
       
   100    *
       
   101    */
       
   102   static FT_Error
       
   103   cid_get_ros( CID_Face      face,
       
   104                const char*  *registry,
       
   105                const char*  *ordering,
       
   106                FT_Int       *supplement )
       
   107   {
       
   108     CID_FaceInfo  cid = &face->cid;
       
   109 
       
   110 
       
   111     if ( registry )
       
   112       *registry = cid->registry;
       
   113       
       
   114     if ( ordering )
       
   115       *ordering = cid->ordering;
       
   116 
       
   117     if ( supplement )
       
   118       *supplement = cid->supplement;
       
   119       
       
   120     return CID_Err_Ok;
       
   121   }
       
   122 
       
   123 
       
   124   static FT_Error
       
   125   cid_get_is_cid( CID_Face  face,
       
   126                   FT_Bool  *is_cid )
       
   127   {
       
   128     FT_Error  error = CID_Err_Ok;
       
   129     FT_UNUSED( face );
       
   130 
       
   131 
       
   132     if ( is_cid )
       
   133       *is_cid = 1; /* cid driver is only used for CID keyed fonts */
       
   134 
       
   135     return error;
       
   136   }
       
   137 
       
   138 
       
   139   static FT_Error
       
   140   cid_get_cid_from_glyph_index( CID_Face  face,
       
   141                                 FT_UInt   glyph_index,
       
   142                                 FT_UInt  *cid )
       
   143   {
       
   144     FT_Error  error = CID_Err_Ok;
       
   145     FT_UNUSED( face );
       
   146 
       
   147 
       
   148     if ( cid )
       
   149       *cid = glyph_index; /* identity mapping */
       
   150 
       
   151     return error;
       
   152   }
       
   153 
       
   154 
       
   155   static const FT_Service_CIDRec  cid_service_cid_info =
       
   156   {
       
   157      (FT_CID_GetRegistryOrderingSupplementFunc)cid_get_ros,
       
   158      (FT_CID_GetIsInternallyCIDKeyedFunc)      cid_get_is_cid,
       
   159      (FT_CID_GetCIDFromGlyphIndexFunc)         cid_get_cid_from_glyph_index
       
   160   };
       
   161 
       
   162 
       
   163   /*
       
   164    *  SERVICE LIST
       
   165    *
       
   166    */
       
   167 
       
   168   static const FT_ServiceDescRec  cid_services[] =
       
   169   {
       
   170     { FT_SERVICE_ID_XF86_NAME,            FT_XF86_FORMAT_CID },
       
   171     { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cid_service_ps_name },
       
   172     { FT_SERVICE_ID_POSTSCRIPT_INFO,      &cid_service_ps_info },
       
   173     { FT_SERVICE_ID_CID,                  &cid_service_cid_info },
       
   174     { NULL, NULL }
       
   175   };
       
   176 
       
   177 
       
   178   FT_CALLBACK_DEF( FT_Module_Interface )
       
   179   cid_get_interface( FT_Module    module,
       
   180                      const char*  cid_interface )
       
   181   {
       
   182     FT_UNUSED( module );
       
   183 
       
   184     return ft_service_list_lookup( cid_services, cid_interface );
       
   185   }
       
   186 
       
   187 
       
   188 
       
   189   FT_CALLBACK_TABLE_DEF
       
   190   const FT_Driver_ClassRec  t1cid_driver_class =
       
   191   {
       
   192     /* first of all, the FT_Module_Class fields */
       
   193     {
       
   194       FT_MODULE_FONT_DRIVER       |
       
   195       FT_MODULE_DRIVER_SCALABLE   |
       
   196       FT_MODULE_DRIVER_HAS_HINTER,
       
   197 
       
   198       sizeof( FT_DriverRec ),
       
   199       "t1cid",   /* module name           */
       
   200       0x10000L,  /* version 1.0 of driver */
       
   201       0x20000L,  /* requires FreeType 2.0 */
       
   202 
       
   203       0,
       
   204 
       
   205       cid_driver_init,
       
   206       cid_driver_done,
       
   207       cid_get_interface
       
   208     },
       
   209 
       
   210     /* then the other font drivers fields */
       
   211     sizeof( CID_FaceRec ),
       
   212     sizeof( CID_SizeRec ),
       
   213     sizeof( CID_GlyphSlotRec ),
       
   214 
       
   215     cid_face_init,
       
   216     cid_face_done,
       
   217 
       
   218     cid_size_init,
       
   219     cid_size_done,
       
   220     cid_slot_init,
       
   221     cid_slot_done,
       
   222 
       
   223 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
       
   224     ft_stub_set_char_sizes,
       
   225     ft_stub_set_pixel_sizes,
       
   226 #endif
       
   227 
       
   228     cid_slot_load_glyph,
       
   229 
       
   230     0,                      /* FT_Face_GetKerningFunc  */
       
   231     0,                      /* FT_Face_AttachFunc      */
       
   232 
       
   233     0,                      /* FT_Face_GetAdvancesFunc */
       
   234 
       
   235     cid_size_request,
       
   236     0                       /* FT_Size_SelectFunc      */
       
   237   };
       
   238 
       
   239 
       
   240 /* END */