1 /**************************************************************************** 2 * 3 * cidriver.c 4 * 5 * CID driver interface (body). 6 * 7 * Copyright 1996-2018 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 #include FT_INTERNAL_POSTSCRIPT_PROPS_H 24 25 #include "ciderrs.h" 26 27 #include FT_SERVICE_POSTSCRIPT_NAME_H 28 #include FT_SERVICE_FONT_FORMAT_H 29 #include FT_SERVICE_POSTSCRIPT_INFO_H 30 #include FT_SERVICE_CID_H 31 #include FT_SERVICE_PROPERTIES_H 32 #include FT_DRIVER_H 33 34 #include FT_INTERNAL_POSTSCRIPT_AUX_H 35 36 37 /************************************************************************** 38 * 39 * The macro FT_COMPONENT is used in trace mode. It is an implicit 40 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log 41 * messages during execution. 42 */ 43 #undef FT_COMPONENT 44 #define FT_COMPONENT trace_ciddriver 45 46 47 /* 48 * POSTSCRIPT NAME SERVICE 49 * 50 */ 51 52 static const char* cid_get_postscript_name(CID_Face face)53 cid_get_postscript_name( CID_Face face ) 54 { 55 const char* result = face->cid.cid_font_name; 56 57 58 if ( result && result[0] == '/' ) 59 result++; 60 61 return result; 62 } 63 64 65 static const FT_Service_PsFontNameRec cid_service_ps_name = 66 { 67 (FT_PsName_GetFunc)cid_get_postscript_name /* get_ps_font_name */ 68 }; 69 70 71 /* 72 * POSTSCRIPT INFO SERVICE 73 * 74 */ 75 76 static FT_Error cid_ps_get_font_info(FT_Face face,PS_FontInfoRec * afont_info)77 cid_ps_get_font_info( FT_Face face, 78 PS_FontInfoRec* afont_info ) 79 { 80 *afont_info = ((CID_Face)face)->cid.font_info; 81 82 return FT_Err_Ok; 83 } 84 85 static FT_Error cid_ps_get_font_extra(FT_Face face,PS_FontExtraRec * afont_extra)86 cid_ps_get_font_extra( FT_Face face, 87 PS_FontExtraRec* afont_extra ) 88 { 89 *afont_extra = ((CID_Face)face)->font_extra; 90 91 return FT_Err_Ok; 92 } 93 94 static const FT_Service_PsInfoRec cid_service_ps_info = 95 { 96 (PS_GetFontInfoFunc) cid_ps_get_font_info, /* ps_get_font_info */ 97 (PS_GetFontExtraFunc) cid_ps_get_font_extra, /* ps_get_font_extra */ 98 /* unsupported with CID fonts */ 99 (PS_HasGlyphNamesFunc) NULL, /* ps_has_glyph_names */ 100 /* unsupported */ 101 (PS_GetFontPrivateFunc)NULL, /* ps_get_font_private */ 102 /* not implemented */ 103 (PS_GetFontValueFunc) NULL /* ps_get_font_value */ 104 }; 105 106 107 /* 108 * CID INFO SERVICE 109 * 110 */ 111 static FT_Error cid_get_ros(CID_Face face,const char ** registry,const char ** ordering,FT_Int * supplement)112 cid_get_ros( CID_Face face, 113 const char* *registry, 114 const char* *ordering, 115 FT_Int *supplement ) 116 { 117 CID_FaceInfo cid = &face->cid; 118 119 120 if ( registry ) 121 *registry = cid->registry; 122 123 if ( ordering ) 124 *ordering = cid->ordering; 125 126 if ( supplement ) 127 *supplement = cid->supplement; 128 129 return FT_Err_Ok; 130 } 131 132 133 static FT_Error cid_get_is_cid(CID_Face face,FT_Bool * is_cid)134 cid_get_is_cid( CID_Face face, 135 FT_Bool *is_cid ) 136 { 137 FT_Error error = FT_Err_Ok; 138 FT_UNUSED( face ); 139 140 141 if ( is_cid ) 142 *is_cid = 1; /* cid driver is only used for CID keyed fonts */ 143 144 return error; 145 } 146 147 148 static FT_Error cid_get_cid_from_glyph_index(CID_Face face,FT_UInt glyph_index,FT_UInt * cid)149 cid_get_cid_from_glyph_index( CID_Face face, 150 FT_UInt glyph_index, 151 FT_UInt *cid ) 152 { 153 FT_Error error = FT_Err_Ok; 154 FT_UNUSED( face ); 155 156 157 if ( cid ) 158 *cid = glyph_index; /* identity mapping */ 159 160 return error; 161 } 162 163 164 static const FT_Service_CIDRec cid_service_cid_info = 165 { 166 (FT_CID_GetRegistryOrderingSupplementFunc) 167 cid_get_ros, /* get_ros */ 168 (FT_CID_GetIsInternallyCIDKeyedFunc) 169 cid_get_is_cid, /* get_is_cid */ 170 (FT_CID_GetCIDFromGlyphIndexFunc) 171 cid_get_cid_from_glyph_index /* get_cid_from_glyph_index */ 172 }; 173 174 175 /* 176 * PROPERTY SERVICE 177 * 178 */ 179 180 FT_DEFINE_SERVICE_PROPERTIESREC( 181 cid_service_properties, 182 183 (FT_Properties_SetFunc)ps_property_set, /* set_property */ 184 (FT_Properties_GetFunc)ps_property_get ) /* get_property */ 185 186 187 /* 188 * SERVICE LIST 189 * 190 */ 191 192 static const FT_ServiceDescRec cid_services[] = 193 { 194 { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CID }, 195 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cid_service_ps_name }, 196 { FT_SERVICE_ID_POSTSCRIPT_INFO, &cid_service_ps_info }, 197 { FT_SERVICE_ID_CID, &cid_service_cid_info }, 198 { FT_SERVICE_ID_PROPERTIES, &cid_service_properties }, 199 { NULL, NULL } 200 }; 201 202 203 FT_CALLBACK_DEF( FT_Module_Interface ) cid_get_interface(FT_Module module,const char * cid_interface)204 cid_get_interface( FT_Module module, 205 const char* cid_interface ) 206 { 207 FT_UNUSED( module ); 208 209 return ft_service_list_lookup( cid_services, cid_interface ); 210 } 211 212 213 214 FT_CALLBACK_TABLE_DEF 215 const FT_Driver_ClassRec t1cid_driver_class = 216 { 217 { 218 FT_MODULE_FONT_DRIVER | 219 FT_MODULE_DRIVER_SCALABLE | 220 FT_MODULE_DRIVER_HAS_HINTER, 221 sizeof ( PS_DriverRec ), 222 223 "t1cid", /* module name */ 224 0x10000L, /* version 1.0 of driver */ 225 0x20000L, /* requires FreeType 2.0 */ 226 227 NULL, /* module-specific interface */ 228 229 cid_driver_init, /* FT_Module_Constructor module_init */ 230 cid_driver_done, /* FT_Module_Destructor module_done */ 231 cid_get_interface /* FT_Module_Requester get_interface */ 232 }, 233 234 sizeof ( CID_FaceRec ), 235 sizeof ( CID_SizeRec ), 236 sizeof ( CID_GlyphSlotRec ), 237 238 cid_face_init, /* FT_Face_InitFunc init_face */ 239 cid_face_done, /* FT_Face_DoneFunc done_face */ 240 cid_size_init, /* FT_Size_InitFunc init_size */ 241 cid_size_done, /* FT_Size_DoneFunc done_size */ 242 cid_slot_init, /* FT_Slot_InitFunc init_slot */ 243 cid_slot_done, /* FT_Slot_DoneFunc done_slot */ 244 245 cid_slot_load_glyph, /* FT_Slot_LoadFunc load_glyph */ 246 247 NULL, /* FT_Face_GetKerningFunc get_kerning */ 248 NULL, /* FT_Face_AttachFunc attach_file */ 249 NULL, /* FT_Face_GetAdvancesFunc get_advances */ 250 251 cid_size_request, /* FT_Size_RequestFunc request_size */ 252 NULL /* FT_Size_SelectFunc select_size */ 253 }; 254 255 256 /* END */ 257