1 /***************************************************************************/
5 /* Experimental Type 1 driver interface (body). */
7 /* Copyright 1996-2000 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 /***************************************************************************/
19 #ifdef FT_FLAT_COMPILE
28 #include <type1z/z1driver.h>
29 #include <type1z/z1gload.h>
30 #include <type1z/z1load.h>
31 #include <type1z/z1afm.h>
36 #include <freetype/internal/ftdebug.h>
37 #include <freetype/internal/ftstream.h>
38 #include <freetype/internal/psnames.h>
40 #include <string.h> /* for strcmp() */
43 /*************************************************************************/
45 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
46 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
47 /* messages during execution. */
50 #define FT_COMPONENT trace_z1driver
54 FT_Error
get_z1_glyph_name( T1_Face face
,
62 gname
= face
->type1
.glyph_names
[glyph_index
];
66 FT_UInt len
= strlen( gname
);
69 if (len
>= buffer_max
)
72 MEM_Copy( buffer
, gname
, len
);
73 ((FT_Byte
*)buffer
)[len
] = 0;
80 /*************************************************************************/
86 /* Each driver can provide one or more extensions to the base */
87 /* FreeType API. These can be used to access format specific */
88 /* features (e.g., all TrueType/OpenType resources share a common */
89 /* file structure and common tables which can be accessed through the */
90 /* `sfnt' interface), or more simply generic ones (e.g., the */
91 /* `postscript names' interface which can be used to retrieve the */
92 /* PostScript name of a given glyph index). */
95 /* driver :: A handle to a driver object. */
98 /* interface :: A string designing the interface. Examples are */
99 /* `sfnt', `post_names', `charmaps', etc. */
102 /* A typeless pointer to the extension's interface (normally a table */
103 /* of function pointers). Returns NULL if the requested extension */
104 /* isn't available (i.e., wasn't compiled in the driver at build */
108 FT_Module_Interface
Get_Interface( FT_Driver driver
,
109 const FT_String
* interface
)
112 FT_UNUSED( interface
);
114 if ( strcmp( (const char*)interface
, "glyph_name" ) == 0 )
115 return (FT_Module_Interface
)get_z1_glyph_name
;
117 #ifndef Z1_CONFIG_OPTION_NO_MM_SUPPORT
118 if ( strcmp( (const char*)interface
, "get_mm" ) == 0 )
119 return (FT_Module_Interface
)Z1_Get_Multi_Master
;
121 if ( strcmp( (const char*)interface
, "set_mm_design") == 0 )
122 return (FT_Module_Interface
)Z1_Set_MM_Design
;
124 if ( strcmp( (const char*)interface
, "set_mm_blend") == 0 )
125 return (FT_Module_Interface
)Z1_Set_MM_Blend
;
131 #ifndef Z1_CONFIG_OPTION_NO_AFM
133 /*************************************************************************/
139 /* A driver method used to return the kerning vector between two */
140 /* glyphs of the same face. */
143 /* face :: A handle to the source face object. */
145 /* left_glyph :: The index of the left glyph in the kern pair. */
147 /* right_glyph :: The index of the right glyph in the kern pair. */
150 /* kerning :: The kerning vector. This is in font units for */
151 /* scalable formats, and in pixels for fixed-sizes */
155 /* FreeType error code. 0 means success. */
158 /* Only horizontal layouts (left-to-right & right-to-left) are */
159 /* supported by this function. Other layouts, or more sophisticated */
160 /* kernings are out of scope of this method (the basic driver */
161 /* interface is meant to be simple). */
163 /* They can be implemented by format-specific interfaces. */
166 FT_Error
Get_Kerning( T1_Face face
,
177 afm
= (Z1_AFM
*)face
->afm_data
;
179 Z1_Get_Kerning( afm
, left_glyph
, right_glyph
, kerning
);
185 #endif /* T1_CONFIG_OPTION_NO_AFM */
188 /*************************************************************************/
194 /* Uses a charmap to return a given character code's glyph index. */
197 /* charmap :: A handle to the source charmap object. */
198 /* charcode :: The character code. */
201 /* Glyph index. 0 means `undefined character code'. */
204 FT_UInt
Get_Char_Index( FT_CharMap charmap
,
209 PSNames_Interface
* psnames
;
212 face
= (T1_Face
)charmap
->face
;
213 psnames
= (PSNames_Interface
*)face
->psnames
;
215 switch ( charmap
->encoding
)
217 /*******************************************************************/
219 /* Unicode encoding support */
221 case ft_encoding_unicode
:
222 /* use the `PSNames' module to synthetize the Unicode charmap */
223 result
= psnames
->lookup_unicode( &face
->unicode_map
,
224 (FT_ULong
)charcode
);
226 /* the function returns 0xFFFF if the Unicode charcode has */
227 /* no corresponding glyph */
228 if ( result
== 0xFFFF )
232 /*******************************************************************/
234 /* Custom Type 1 encoding */
236 case ft_encoding_adobe_custom
:
238 T1_Encoding
* encoding
= &face
->type1
.encoding
;
241 if ( charcode
>= encoding
->code_first
&&
242 charcode
<= encoding
->code_last
)
243 result
= encoding
->char_index
[charcode
];
247 /*******************************************************************/
249 /* Adobe Standard & Expert encoding support */
252 if ( charcode
< 256 )
256 const char* glyph_name
;
259 code
= psnames
->adobe_std_encoding
[charcode
];
260 if ( charmap
->encoding
== ft_encoding_adobe_expert
)
261 code
= psnames
->adobe_expert_encoding
[charcode
];
263 glyph_name
= psnames
->adobe_std_strings( code
);
267 for ( n
= 0; n
< face
->type1
.num_glyphs
; n
++ )
269 const char* gname
= face
->type1
.glyph_names
[n
];
272 if ( gname
&& gname
[0] == glyph_name
[0] &&
273 strcmp( gname
, glyph_name
) == 0 )
286 const FT_Driver_Class t1_driver_class
=
289 ft_module_font_driver
| ft_module_driver_scalable
,
290 sizeof( FT_DriverRec
),
296 0, /* format interface */
298 (FT_Module_Constructor
)Z1_Init_Driver
,
299 (FT_Module_Destructor
) Z1_Done_Driver
,
300 (FT_Module_Requester
) Get_Interface
,
303 sizeof( T1_FaceRec
),
304 sizeof( Z1_SizeRec
),
305 sizeof( Z1_GlyphSlotRec
),
307 (FTDriver_initFace
) Z1_Init_Face
,
308 (FTDriver_doneFace
) Z1_Done_Face
,
309 (FTDriver_initSize
) 0,
310 (FTDriver_doneSize
) 0,
311 (FTDriver_initGlyphSlot
)0,
312 (FTDriver_doneGlyphSlot
)0,
314 (FTDriver_setCharSizes
) 0,
315 (FTDriver_setPixelSizes
)0,
316 (FTDriver_loadGlyph
) Z1_Load_Glyph
,
317 (FTDriver_getCharIndex
) Get_Char_Index
,
319 #ifdef Z1_CONFIG_OPTION_NO_AFM
320 (FTDriver_getKerning
) 0,
321 (FTDriver_attachFile
) 0,
323 (FTDriver_getKerning
) Get_Kerning
,
324 (FTDriver_attachFile
) Z1_Read_AFM
,
326 (FTDriver_getAdvances
) 0
330 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
332 EXPORT_FUNC( const FT_Driver_Class
* ) getDriverClass( void )
334 return &t1z_driver_class
;
337 #endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */