1 /***************************************************************************/
5 /* Type 1 driver interface (body). */
7 /* Copyright 1996-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
26 #ifndef T1_CONFIG_OPTION_NO_AFM
30 #include FT_INTERNAL_DEBUG_H
31 #include FT_INTERNAL_STREAM_H
32 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
34 #include <string.h> /* for strcmp() */
37 /*************************************************************************/
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. */
44 #define FT_COMPONENT trace_t1driver
48 t1_get_glyph_name( T1_Face face,
56 gname = face->type1.glyph_names[glyph_index];
60 FT_UInt len = (FT_UInt)( strlen( gname ) );
63 if (len >= buffer_max)
66 MEM_Copy( buffer, gname, len );
67 ((FT_Byte*)buffer)[len] = 0;
74 /*************************************************************************/
77 /* t1_get_name_index */
80 /* Uses the Type 1 font's `glyph_names' table to find a given glyph */
81 /* name's glyph index. */
84 /* face :: A handle to the source face object. */
86 /* glyph_name :: The glyph name. */
89 /* Glyph index. 0 means `undefined character code'. */
92 t1_get_name_index( T1_Face face,
93 FT_String* glyph_name )
99 for ( i = 0; i < face->type1.num_glyphs; i++ )
101 gname = face->type1.glyph_names[i];
103 if ( !strcmp( glyph_name, gname ) )
112 t1_get_ps_name( T1_Face face )
114 return (const char*) face->type1.font_name;
118 /*************************************************************************/
124 /* Each driver can provide one or more extensions to the base */
125 /* FreeType API. These can be used to access format specific */
126 /* features (e.g., all TrueType/OpenType resources share a common */
127 /* file structure and common tables which can be accessed through the */
128 /* `sfnt' interface), or more simply generic ones (e.g., the */
129 /* `postscript names' interface which can be used to retrieve the */
130 /* PostScript name of a given glyph index). */
133 /* driver :: A handle to a driver object. */
136 /* interface :: A string designing the interface. Examples are */
137 /* `sfnt', `post_names', `charmaps', etc. */
140 /* A typeless pointer to the extension's interface (normally a table */
141 /* of function pointers). Returns NULL if the requested extension */
142 /* isn't available (i.e., wasn't compiled in the driver at build */
145 static FT_Module_Interface
146 Get_Interface( FT_Driver driver,
147 const FT_String* interface )
150 FT_UNUSED( interface );
152 if ( strcmp( (const char*)interface, "glyph_name" ) == 0 )
153 return (FT_Module_Interface)t1_get_glyph_name;
155 if ( strcmp( (const char*)interface, "name_index" ) == 0 )
156 return (FT_Module_Interface)t1_get_name_index;
158 if ( strcmp( (const char*)interface, "postscript_name" ) == 0 )
159 return (FT_Module_Interface)t1_get_ps_name;
161 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
162 if ( strcmp( (const char*)interface, "get_mm" ) == 0 )
163 return (FT_Module_Interface)T1_Get_Multi_Master;
165 if ( strcmp( (const char*)interface, "set_mm_design") == 0 )
166 return (FT_Module_Interface)T1_Set_MM_Design;
168 if ( strcmp( (const char*)interface, "set_mm_blend") == 0 )
169 return (FT_Module_Interface)T1_Set_MM_Blend;
175 #ifndef T1_CONFIG_OPTION_NO_AFM
177 /*************************************************************************/
183 /* A driver method used to return the kerning vector between two */
184 /* glyphs of the same face. */
187 /* face :: A handle to the source face object. */
189 /* left_glyph :: The index of the left glyph in the kern pair. */
191 /* right_glyph :: The index of the right glyph in the kern pair. */
194 /* kerning :: The kerning vector. This is in font units for */
195 /* scalable formats, and in pixels for fixed-sizes */
199 /* FreeType error code. 0 means success. */
202 /* Only horizontal layouts (left-to-right & right-to-left) are */
203 /* supported by this function. Other layouts, or more sophisticated */
204 /* kernings are out of scope of this method (the basic driver */
205 /* interface is meant to be simple). */
207 /* They can be implemented by format-specific interfaces. */
210 Get_Kerning( T1_Face face,
221 afm = (T1_AFM*)face->afm_data;
223 T1_Get_Kerning( afm, left_glyph, right_glyph, kerning );
229 #endif /* T1_CONFIG_OPTION_NO_AFM */
232 /*************************************************************************/
238 /* Uses a charmap to return a given character code's glyph index. */
241 /* charmap :: A handle to the source charmap object. */
242 /* charcode :: The character code. */
245 /* Glyph index. 0 means `undefined character code'. */
248 Get_Char_Index( FT_CharMap charmap,
253 PSNames_Interface* psnames;
256 face = (T1_Face)charmap->face;
257 psnames = (PSNames_Interface*)face->psnames;
259 switch ( charmap->encoding )
261 /*******************************************************************/
263 /* Unicode encoding support */
265 case ft_encoding_unicode:
266 /* use the `PSNames' module to synthetize the Unicode charmap */
267 result = psnames->lookup_unicode( &face->unicode_map,
268 (FT_ULong)charcode );
270 /* the function returns 0xFFFF if the Unicode charcode has */
271 /* no corresponding glyph */
272 if ( result == 0xFFFF )
276 /*******************************************************************/
278 /* Custom Type 1 encoding */
280 case ft_encoding_adobe_custom:
282 T1_Encoding* encoding = &face->type1.encoding;
285 if ( charcode >= encoding->code_first &&
286 charcode <= encoding->code_last )
287 result = encoding->char_index[charcode];
291 /*******************************************************************/
293 /* Adobe Standard & Expert encoding support */
296 if ( charcode < 256 )
300 const char* glyph_name;
303 code = psnames->adobe_std_encoding[charcode];
304 if ( charmap->encoding == ft_encoding_adobe_expert )
305 code = psnames->adobe_expert_encoding[charcode];
307 glyph_name = psnames->adobe_std_strings( code );
311 for ( n = 0; n < face->type1.num_glyphs; n++ )
313 const char* gname = face->type1.glyph_names[n];
316 if ( gname && gname[0] == glyph_name[0] &&
317 strcmp( gname, glyph_name ) == 0 )
330 FT_CALLBACK_TABLE_DEF
331 const FT_Driver_Class t1_driver_class =
334 ft_module_font_driver | ft_module_driver_scalable,
335 sizeof( FT_DriverRec ),
341 0, /* format interface */
343 (FT_Module_Constructor)T1_Init_Driver,
344 (FT_Module_Destructor) T1_Done_Driver,
345 (FT_Module_Requester) Get_Interface,
348 sizeof( T1_FaceRec ),
349 sizeof( T1_SizeRec ),
350 sizeof( T1_GlyphSlotRec ),
352 (FTDriver_initFace) T1_Init_Face,
353 (FTDriver_doneFace) T1_Done_Face,
354 (FTDriver_initSize) 0,
355 (FTDriver_doneSize) 0,
356 (FTDriver_initGlyphSlot)0,
357 (FTDriver_doneGlyphSlot)0,
359 (FTDriver_setCharSizes) 0,
360 (FTDriver_setPixelSizes)0,
361 (FTDriver_loadGlyph) T1_Load_Glyph,
362 (FTDriver_getCharIndex) Get_Char_Index,
364 #ifdef T1_CONFIG_OPTION_NO_AFM
365 (FTDriver_getKerning) 0,
366 (FTDriver_attachFile) 0,
368 (FTDriver_getKerning) Get_Kerning,
369 (FTDriver_attachFile) T1_Read_AFM,
371 (FTDriver_getAdvances) 0
375 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
378 /*************************************************************************/
384 /* This function is used when compiling the TrueType driver as a */
385 /* shared library (`.DLL' or `.so'). It will be used by the */
386 /* high-level library of FreeType to retrieve the address of the */
387 /* driver's generic interface. */
389 /* It shouldn't be implemented in a static build, as each driver must */
390 /* have the same function as an exported entry point. */
393 /* The address of the TrueType's driver generic interface. The */
394 /* format-specific interface can then be retrieved through the method */
395 /* interface->get_format_interface. */
397 FT_EXPORT_DEF( const FT_Driver_Class* )
398 getDriverClass( void )
400 return &t1_driver_class;
404 #endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */