1 /**************************************************************************** 2 * 3 * t42drivr.c 4 * 5 * High-level Type 42 driver interface (body). 6 * 7 * Copyright (C) 2002-2023 by 8 * Roberto Alameda. 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 /************************************************************************** 20 * 21 * This driver implements Type42 fonts as described in the 22 * Technical Note #5012 from Adobe, with these limitations: 23 * 24 * 1) CID Fonts are not currently supported. 25 * 2) Incremental fonts making use of the GlyphDirectory keyword 26 * will be loaded, but the rendering will be using the TrueType 27 * tables. 28 * 3) As for Type1 fonts, CDevProc is not supported. 29 * 4) The Metrics dictionary is not supported. 30 * 5) AFM metrics are not supported. 31 * 32 * In other words, this driver supports Type42 fonts derived from 33 * TrueType fonts in a non-CID manner, as done by usual conversion 34 * programs. 35 * 36 */ 37 38 39 #include "t42drivr.h" 40 #include "t42objs.h" 41 #include "t42error.h" 42 #include <freetype/internal/ftdebug.h> 43 44 #include <freetype/internal/services/svfntfmt.h> 45 #include <freetype/internal/services/svgldict.h> 46 #include <freetype/internal/services/svpostnm.h> 47 #include <freetype/internal/services/svpsinfo.h> 48 49 #undef FT_COMPONENT 50 #define FT_COMPONENT t42 51 52 53 /* 54 * 55 * GLYPH DICT SERVICE 56 * 57 */ 58 59 FT_CALLBACK_DEF( FT_Error ) t42_get_glyph_name(FT_Face face,FT_UInt glyph_index,FT_Pointer buffer,FT_UInt buffer_max)60 t42_get_glyph_name( FT_Face face, /* T42_Face */ 61 FT_UInt glyph_index, 62 FT_Pointer buffer, 63 FT_UInt buffer_max ) 64 { 65 T42_Face t42face = (T42_Face)face; 66 67 68 FT_STRCPYN( buffer, 69 t42face->type1.glyph_names[glyph_index], 70 buffer_max ); 71 72 return FT_Err_Ok; 73 } 74 75 76 FT_CALLBACK_DEF( FT_UInt ) t42_get_name_index(FT_Face face,const FT_String * glyph_name)77 t42_get_name_index( FT_Face face, /* T42_Face */ 78 const FT_String* glyph_name ) 79 { 80 T42_Face t42face = (T42_Face)face; 81 FT_Int i; 82 83 84 for ( i = 0; i < t42face->type1.num_glyphs; i++ ) 85 { 86 FT_String* gname = t42face->type1.glyph_names[i]; 87 88 89 if ( glyph_name[0] == gname[0] && !ft_strcmp( glyph_name, gname ) ) 90 return (FT_UInt)ft_strtol( 91 (const char *)t42face->type1.charstrings[i], 92 NULL, 93 10 ); 94 } 95 96 return 0; 97 } 98 99 100 static const FT_Service_GlyphDictRec t42_service_glyph_dict = 101 { 102 (FT_GlyphDict_GetNameFunc) t42_get_glyph_name, /* get_name */ 103 (FT_GlyphDict_NameIndexFunc)t42_get_name_index /* name_index */ 104 }; 105 106 107 /* 108 * 109 * POSTSCRIPT NAME SERVICE 110 * 111 */ 112 113 FT_CALLBACK_DEF( const char* ) t42_get_ps_font_name(FT_Face face)114 t42_get_ps_font_name( FT_Face face ) /* T42_Face */ 115 { 116 T42_Face t42face = (T42_Face)face; 117 118 119 return (const char*)t42face->type1.font_name; 120 } 121 122 123 static const FT_Service_PsFontNameRec t42_service_ps_font_name = 124 { 125 (FT_PsName_GetFunc)t42_get_ps_font_name /* get_ps_font_name */ 126 }; 127 128 129 /* 130 * 131 * POSTSCRIPT INFO SERVICE 132 * 133 */ 134 135 FT_CALLBACK_DEF( FT_Error ) t42_ps_get_font_info(FT_Face face,PS_FontInfoRec * afont_info)136 t42_ps_get_font_info( FT_Face face, 137 PS_FontInfoRec* afont_info ) 138 { 139 *afont_info = ((T42_Face)face)->type1.font_info; 140 141 return FT_Err_Ok; 142 } 143 144 145 FT_CALLBACK_DEF( FT_Error ) t42_ps_get_font_extra(FT_Face face,PS_FontExtraRec * afont_extra)146 t42_ps_get_font_extra( FT_Face face, 147 PS_FontExtraRec* afont_extra ) 148 { 149 *afont_extra = ((T42_Face)face)->type1.font_extra; 150 151 return FT_Err_Ok; 152 } 153 154 155 FT_CALLBACK_DEF( FT_Int ) t42_ps_has_glyph_names(FT_Face face)156 t42_ps_has_glyph_names( FT_Face face ) 157 { 158 FT_UNUSED( face ); 159 160 return 1; 161 } 162 163 164 static const FT_Service_PsInfoRec t42_service_ps_info = 165 { 166 (PS_GetFontInfoFunc) t42_ps_get_font_info, /* ps_get_font_info */ 167 (PS_GetFontExtraFunc) t42_ps_get_font_extra, /* ps_get_font_extra */ 168 (PS_HasGlyphNamesFunc) t42_ps_has_glyph_names, /* ps_has_glyph_names */ 169 /* Type42 fonts don't have a Private dict */ 170 (PS_GetFontPrivateFunc)NULL, /* ps_get_font_private */ 171 /* not implemented */ 172 (PS_GetFontValueFunc) NULL /* ps_get_font_value */ 173 }; 174 175 176 /* 177 * 178 * SERVICE LIST 179 * 180 */ 181 182 static const FT_ServiceDescRec t42_services[] = 183 { 184 { FT_SERVICE_ID_GLYPH_DICT, &t42_service_glyph_dict }, 185 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &t42_service_ps_font_name }, 186 { FT_SERVICE_ID_POSTSCRIPT_INFO, &t42_service_ps_info }, 187 { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_TYPE_42 }, 188 { NULL, NULL } 189 }; 190 191 192 FT_CALLBACK_DEF( FT_Module_Interface ) T42_Get_Interface(FT_Module module,const FT_String * t42_interface)193 T42_Get_Interface( FT_Module module, 194 const FT_String* t42_interface ) 195 { 196 FT_UNUSED( module ); 197 198 return ft_service_list_lookup( t42_services, t42_interface ); 199 } 200 201 202 const FT_Driver_ClassRec t42_driver_class = 203 { 204 { 205 FT_MODULE_FONT_DRIVER | 206 FT_MODULE_DRIVER_SCALABLE | 207 #ifdef TT_USE_BYTECODE_INTERPRETER 208 FT_MODULE_DRIVER_HAS_HINTER, 209 #else 210 0, 211 #endif 212 213 sizeof ( T42_DriverRec ), 214 215 "type42", 216 0x10000L, 217 0x20000L, 218 219 NULL, /* module-specific interface */ 220 221 T42_Driver_Init, /* FT_Module_Constructor module_init */ 222 T42_Driver_Done, /* FT_Module_Destructor module_done */ 223 T42_Get_Interface, /* FT_Module_Requester get_interface */ 224 }, 225 226 sizeof ( T42_FaceRec ), 227 sizeof ( T42_SizeRec ), 228 sizeof ( T42_GlyphSlotRec ), 229 230 T42_Face_Init, /* FT_Face_InitFunc init_face */ 231 T42_Face_Done, /* FT_Face_DoneFunc done_face */ 232 T42_Size_Init, /* FT_Size_InitFunc init_size */ 233 T42_Size_Done, /* FT_Size_DoneFunc done_size */ 234 T42_GlyphSlot_Init, /* FT_Slot_InitFunc init_slot */ 235 T42_GlyphSlot_Done, /* FT_Slot_DoneFunc done_slot */ 236 237 T42_GlyphSlot_Load, /* FT_Slot_LoadFunc load_glyph */ 238 239 NULL, /* FT_Face_GetKerningFunc get_kerning */ 240 NULL, /* FT_Face_AttachFunc attach_file */ 241 NULL, /* FT_Face_GetAdvancesFunc get_advances */ 242 243 T42_Size_Request, /* FT_Size_RequestFunc request_size */ 244 T42_Size_Select /* FT_Size_SelectFunc select_size */ 245 }; 246 247 248 /* END */ 249