Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* t42drivr.c */ |
| 4 | /* */ |
| 5 | /* High-level Type 42 driver interface (body). */ |
| 6 | /* */ |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 7 | /* Copyright 2002, 2003, 2004, 2006, 2007, 2009 by Roberto Alameda. */ |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 8 | /* */ |
| 9 | /* This file is part of the FreeType project, and may only be used, */ |
| 10 | /* modified, and distributed under the terms of the FreeType project */ |
| 11 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 12 | /* this file you indicate that you have read the license and */ |
| 13 | /* understand and accept it fully. */ |
| 14 | /* */ |
| 15 | /***************************************************************************/ |
| 16 | |
| 17 | |
Werner Lemberg | 0657a8a | 2002-06-19 19:43:15 +0000 | [diff] [blame] | 18 | /*************************************************************************/ |
| 19 | /* */ |
| 20 | /* This driver implements Type42 fonts as described in the */ |
| 21 | /* Technical Note #5012 from Adobe, with these limitations: */ |
| 22 | /* */ |
| 23 | /* 1) CID Fonts are not currently supported. */ |
| 24 | /* 2) Incremental fonts making use of the GlyphDirectory keyword */ |
| 25 | /* will be loaded, but the rendering will be using the TrueType */ |
| 26 | /* tables. */ |
Werner Lemberg | e3f4198 | 2003-10-16 15:48:39 +0000 | [diff] [blame] | 27 | /* 3) As for Type1 fonts, CDevProc is not supported. */ |
| 28 | /* 4) The Metrics dictionary is not supported. */ |
| 29 | /* 5) AFM metrics are not supported. */ |
Werner Lemberg | 0657a8a | 2002-06-19 19:43:15 +0000 | [diff] [blame] | 30 | /* */ |
| 31 | /* In other words, this driver supports Type42 fonts derived from */ |
| 32 | /* TrueType fonts in a non-CID manner, as done by usual conversion */ |
| 33 | /* programs. */ |
| 34 | /* */ |
| 35 | /*************************************************************************/ |
| 36 | |
| 37 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 38 | #include "t42drivr.h" |
| 39 | #include "t42objs.h" |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 40 | #include "t42error.h" |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 41 | #include FT_INTERNAL_DEBUG_H |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 42 | |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 43 | #include FT_SERVICE_XFREE86_NAME_H |
| 44 | #include FT_SERVICE_GLYPH_DICT_H |
| 45 | #include FT_SERVICE_POSTSCRIPT_NAME_H |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 46 | #include FT_SERVICE_POSTSCRIPT_INFO_H |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 47 | |
Werner Lemberg | 7cf4d37 | 2002-05-21 14:13:01 +0000 | [diff] [blame] | 48 | #undef FT_COMPONENT |
| 49 | #define FT_COMPONENT trace_t42 |
| 50 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 51 | |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 52 | /* |
| 53 | * |
| 54 | * GLYPH DICT SERVICE |
| 55 | * |
| 56 | */ |
David Turner | b72d8a8 | 2003-09-29 20:33:37 +0000 | [diff] [blame] | 57 | |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 58 | static FT_Error |
| 59 | t42_get_glyph_name( T42_Face face, |
| 60 | FT_UInt glyph_index, |
| 61 | FT_Pointer buffer, |
| 62 | FT_UInt buffer_max ) |
| 63 | { |
David Turner | c0f9c4a | 2007-02-12 14:55:03 +0000 | [diff] [blame] | 64 | FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max ); |
Werner Lemberg | 442bfb8 | 2007-02-12 21:44:10 +0000 | [diff] [blame] | 65 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 66 | return T42_Err_Ok; |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 70 | static FT_UInt |
| 71 | t42_get_name_index( T42_Face face, |
| 72 | FT_String* glyph_name ) |
| 73 | { |
| 74 | FT_Int i; |
| 75 | FT_String* gname; |
| 76 | |
| 77 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 78 | for ( i = 0; i < face->type1.num_glyphs; i++ ) |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 79 | { |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 80 | gname = face->type1.glyph_names[i]; |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 81 | |
David Turner | c0f9c4a | 2007-02-12 14:55:03 +0000 | [diff] [blame] | 82 | if ( glyph_name[0] == gname[0] && !ft_strcmp( glyph_name, gname ) ) |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 83 | return (FT_UInt)ft_atol( (const char *)face->type1.charstrings[i] ); |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | |
David Turner | 10bf05a | 2004-04-21 14:30:37 +0000 | [diff] [blame] | 90 | static const FT_Service_GlyphDictRec t42_service_glyph_dict = |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 91 | { |
Werner Lemberg | 013efd1 | 2003-09-17 05:26:33 +0000 | [diff] [blame] | 92 | (FT_GlyphDict_GetNameFunc) t42_get_glyph_name, |
| 93 | (FT_GlyphDict_NameIndexFunc)t42_get_name_index |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 97 | /* |
| 98 | * |
| 99 | * POSTSCRIPT NAME SERVICE |
| 100 | * |
| 101 | */ |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 102 | |
| 103 | static const char* |
David Turner | b72d8a8 | 2003-09-29 20:33:37 +0000 | [diff] [blame] | 104 | t42_get_ps_font_name( T42_Face face ) |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 105 | { |
| 106 | return (const char*)face->type1.font_name; |
| 107 | } |
| 108 | |
| 109 | |
David Turner | 10bf05a | 2004-04-21 14:30:37 +0000 | [diff] [blame] | 110 | static const FT_Service_PsFontNameRec t42_service_ps_font_name = |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 111 | { |
David Turner | b72d8a8 | 2003-09-29 20:33:37 +0000 | [diff] [blame] | 112 | (FT_PsName_GetFunc)t42_get_ps_font_name |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 116 | /* |
| 117 | * |
| 118 | * POSTSCRIPT INFO SERVICE |
| 119 | * |
| 120 | */ |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 121 | |
| 122 | static FT_Error |
| 123 | t42_ps_get_font_info( FT_Face face, |
| 124 | PS_FontInfoRec* afont_info ) |
| 125 | { |
| 126 | *afont_info = ((T42_Face)face)->type1.font_info; |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 127 | |
Werner Lemberg | 3605e47 | 2004-11-12 07:02:45 +0000 | [diff] [blame] | 128 | return T42_Err_Ok; |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 131 | |
David Turner | 01ca4da | 2009-03-03 13:28:59 +0000 | [diff] [blame] | 132 | static FT_Error |
| 133 | t42_ps_get_font_extra( FT_Face face, |
| 134 | PS_FontExtraRec* afont_extra ) |
| 135 | { |
| 136 | *afont_extra = ((T42_Face)face)->type1.font_extra; |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 137 | |
David Turner | 01ca4da | 2009-03-03 13:28:59 +0000 | [diff] [blame] | 138 | return T42_Err_Ok; |
| 139 | } |
Werner Lemberg | 40bb096 | 2003-11-01 14:36:20 +0000 | [diff] [blame] | 140 | |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 141 | |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 142 | static FT_Int |
| 143 | t42_ps_has_glyph_names( FT_Face face ) |
| 144 | { |
| 145 | FT_UNUSED( face ); |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 146 | |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 147 | return 1; |
| 148 | } |
| 149 | |
Werner Lemberg | 40bb096 | 2003-11-01 14:36:20 +0000 | [diff] [blame] | 150 | |
Werner Lemberg | 3605e47 | 2004-11-12 07:02:45 +0000 | [diff] [blame] | 151 | static FT_Error |
| 152 | t42_ps_get_font_private( FT_Face face, |
| 153 | PS_PrivateRec* afont_private ) |
| 154 | { |
| 155 | *afont_private = ((T42_Face)face)->type1.private_dict; |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 156 | |
Werner Lemberg | 3605e47 | 2004-11-12 07:02:45 +0000 | [diff] [blame] | 157 | return T42_Err_Ok; |
| 158 | } |
| 159 | |
| 160 | |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 161 | static const FT_Service_PsInfoRec t42_service_ps_info = |
| 162 | { |
Werner Lemberg | 3605e47 | 2004-11-12 07:02:45 +0000 | [diff] [blame] | 163 | (PS_GetFontInfoFunc) t42_ps_get_font_info, |
David Turner | 01ca4da | 2009-03-03 13:28:59 +0000 | [diff] [blame] | 164 | (PS_GetFontExtraFunc) t42_ps_get_font_extra, |
Werner Lemberg | 3605e47 | 2004-11-12 07:02:45 +0000 | [diff] [blame] | 165 | (PS_HasGlyphNamesFunc) t42_ps_has_glyph_names, |
| 166 | (PS_GetFontPrivateFunc)t42_ps_get_font_private |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | |
Werner Lemberg | 15b60bb | 2009-03-03 21:35:32 +0000 | [diff] [blame] | 170 | /* |
| 171 | * |
| 172 | * SERVICE LIST |
| 173 | * |
| 174 | */ |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 175 | |
| 176 | static const FT_ServiceDescRec t42_services[] = |
| 177 | { |
David Turner | b72d8a8 | 2003-09-29 20:33:37 +0000 | [diff] [blame] | 178 | { FT_SERVICE_ID_GLYPH_DICT, &t42_service_glyph_dict }, |
| 179 | { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &t42_service_ps_font_name }, |
Werner Lemberg | 40bb096 | 2003-11-01 14:36:20 +0000 | [diff] [blame] | 180 | { FT_SERVICE_ID_POSTSCRIPT_INFO, &t42_service_ps_info }, |
Werner Lemberg | 1c0b8e9 | 2003-10-23 04:54:14 +0000 | [diff] [blame] | 181 | { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TYPE_42 }, |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 182 | { NULL, NULL } |
| 183 | }; |
| 184 | |
Werner Lemberg | 013efd1 | 2003-09-17 05:26:33 +0000 | [diff] [blame] | 185 | |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 186 | static FT_Module_Interface |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 187 | T42_Get_Interface( FT_Driver driver, |
| 188 | const FT_String* t42_interface ) |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 189 | { |
| 190 | FT_UNUSED( driver ); |
| 191 | |
David Turner | c313c50 | 2003-09-11 19:51:54 +0000 | [diff] [blame] | 192 | return ft_service_list_lookup( t42_services, t42_interface ); |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | const FT_Driver_ClassRec t42_driver_class = |
| 197 | { |
| 198 | { |
Werner Lemberg | 052904e | 2003-06-17 10:42:27 +0000 | [diff] [blame] | 199 | FT_MODULE_FONT_DRIVER | |
| 200 | FT_MODULE_DRIVER_SCALABLE | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 201 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Werner Lemberg | 052904e | 2003-06-17 10:42:27 +0000 | [diff] [blame] | 202 | FT_MODULE_DRIVER_HAS_HINTER, |
Werner Lemberg | 7cf4d37 | 2002-05-21 14:13:01 +0000 | [diff] [blame] | 203 | #else |
| 204 | 0, |
| 205 | #endif |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 206 | |
| 207 | sizeof ( T42_DriverRec ), |
| 208 | |
| 209 | "type42", |
| 210 | 0x10000L, |
| 211 | 0x20000L, |
| 212 | |
| 213 | 0, /* format interface */ |
| 214 | |
| 215 | (FT_Module_Constructor)T42_Driver_Init, |
| 216 | (FT_Module_Destructor) T42_Driver_Done, |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 217 | (FT_Module_Requester) T42_Get_Interface, |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 218 | }, |
| 219 | |
| 220 | sizeof ( T42_FaceRec ), |
| 221 | sizeof ( T42_SizeRec ), |
| 222 | sizeof ( T42_GlyphSlotRec ), |
| 223 | |
| 224 | (FT_Face_InitFunc) T42_Face_Init, |
| 225 | (FT_Face_DoneFunc) T42_Face_Done, |
| 226 | (FT_Size_InitFunc) T42_Size_Init, |
| 227 | (FT_Size_DoneFunc) T42_Size_Done, |
| 228 | (FT_Slot_InitFunc) T42_GlyphSlot_Init, |
| 229 | (FT_Slot_DoneFunc) T42_GlyphSlot_Done, |
| 230 | |
David Turner | cda2d95 | 2006-02-16 22:45:31 +0000 | [diff] [blame] | 231 | #ifdef FT_CONFIG_OPTION_OLD_INTERNALS |
| 232 | ft_stub_set_char_sizes, |
| 233 | ft_stub_set_pixel_sizes, |
| 234 | #endif |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 235 | (FT_Slot_LoadFunc) T42_GlyphSlot_Load, |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 236 | |
| 237 | (FT_Face_GetKerningFunc) 0, |
| 238 | (FT_Face_AttachFunc) 0, |
| 239 | |
David Turner | cda2d95 | 2006-02-16 22:45:31 +0000 | [diff] [blame] | 240 | (FT_Face_GetAdvancesFunc) 0, |
| 241 | (FT_Size_RequestFunc) T42_Size_Request, |
| 242 | (FT_Size_SelectFunc) T42_Size_Select |
Werner Lemberg | 347a714 | 2002-05-15 06:16:57 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 245 | |
| 246 | /* END */ |