1 /***************************************************************************/
5 /* 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
27 #include <type1/t1driver.h>
28 #include <type1/t1gload.h>
29 #include <type1/t1afm.h>
34 #include <freetype/internal/ftdebug.h>
35 #include <freetype/internal/ftstream.h>
36 #include <freetype/internal/psnames.h>
38 #include <string.h> /* for strcmp() */
41 /*************************************************************************/
43 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
44 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
45 /* messages during execution. */
48 #define FT_COMPONENT trace_t1driver
51 #ifndef T1_CONFIG_OPTION_NO_AFM
54 /*************************************************************************/
60 /* A driver method used to return the kerning vector between two */
61 /* glyphs of the same face. */
64 /* face :: A handle to the source face object. */
66 /* left_glyph :: The index of the left glyph in the kern pair. */
68 /* right_glyph :: The index of the right glyph in the kern pair. */
71 /* kerning :: The kerning vector. This is in font units for */
72 /* scalable formats, and in pixels for fixed-sizes */
76 /* FreeType error code. 0 means success. */
79 /* Only horizontal layouts (left-to-right & right-to-left) are */
80 /* supported by this function. Other layouts, or more sophisticated */
81 /* kernings are out of scope of this method (the basic driver */
82 /* interface is meant to be simple). */
84 /* They can be implemented by format-specific interfaces. */
87 FT_Error
Get_Kerning( T1_Face face
,
98 afm
= (T1_AFM
*)face
->afm_data
;
100 T1_Get_Kerning( afm
, left_glyph
, right_glyph
, kerning
);
106 #endif /* T1_CONFIG_OPTION_NO_AFM */
110 FT_Error
get_t1_glyph_name( T1_Face face
,
118 gname
= face
->type1
.glyph_names
[glyph_index
];
120 if ( buffer_max
> 0 )
122 FT_UInt len
= strlen( gname
);
125 if ( len
>= buffer_max
)
126 len
= buffer_max
- 1;
128 MEM_Copy( buffer
, gname
, len
);
129 ((FT_Byte
*)buffer
)[len
] = 0;
137 FT_Module_Interface
T1_Get_Interface( FT_Module
module,
138 const char* interface
)
142 if ( strcmp( interface
, "glyph_name" ) == 0 )
143 return (FT_Module_Interface
)get_t1_glyph_name
;
150 /*************************************************************************/
156 /* A driver method used to reset a size's character sizes (horizontal */
157 /* and vertical) expressed in fractional points. */
160 /* char_width :: The character width expressed in 26.6 */
161 /* fractional points. */
163 /* char_height :: The character height expressed in 26.6 */
164 /* fractional points. */
166 /* horz_resolution :: The horizontal resolution of the output device. */
168 /* vert_resolution :: The vertical resolution of the output device. */
171 /* size :: A handle to the target size object. */
174 /* FreeType error code. 0 means success. */
177 FT_Error
Set_Char_Sizes( T1_Size size
,
178 FT_F26Dot6 char_width
,
179 FT_F26Dot6 char_height
,
180 FT_UInt horz_resolution
,
181 FT_UInt vert_resolution
)
183 FT_UNUSED( char_width
);
184 FT_UNUSED( char_height
);
185 FT_UNUSED( horz_resolution
);
186 FT_UNUSED( vert_resolution
);
190 return T1_Reset_Size( size
);
194 /*************************************************************************/
197 /* Set_Pixel_Sizes */
200 /* A driver method used to reset a size's character sizes (horizontal */
201 /* and vertical) expressed in integer pixels. */
204 /* pixel_width :: The character width expressed in integer pixels. */
206 /* pixel_height :: The character height expressed in integer pixels. */
209 /* size :: A handle to the target size object. */
212 /* FreeType error code. 0 means success. */
215 FT_Error
Set_Pixel_Sizes( T1_Size size
,
217 FT_Int pixel_height
)
219 FT_UNUSED( pixel_width
);
220 FT_UNUSED( pixel_height
);
224 return T1_Reset_Size( size
);
228 /*************************************************************************/
234 /* Uses a charmap to return a given character code's glyph index. */
237 /* charmap :: A handle to the source charmap object. */
238 /* charcode :: The character code. */
241 /* Glyph index. 0 means `undefined character code'. */
244 FT_UInt
Get_Char_Index( FT_CharMap charmap
,
249 PSNames_Interface
* psnames
;
252 face
= (T1_Face
)charmap
->face
;
253 psnames
= (PSNames_Interface
*)face
->psnames
;
255 switch ( charmap
->encoding
)
257 /*******************************************************************/
259 /* Unicode encoding support */
261 case ft_encoding_unicode
:
262 /* use the `PSNames' module to synthetize the Unicode charmap */
263 result
= psnames
->lookup_unicode( &face
->unicode_map
,
264 (FT_ULong
)charcode
);
266 /* the function returns 0xFFFF if the Unicode charcode has */
267 /* no corresponding glyph */
268 if ( result
== 0xFFFF )
272 /*******************************************************************/
274 /* Custom Type 1 encoding */
276 case ft_encoding_adobe_custom
:
278 T1_Encoding
* encoding
= &face
->type1
.encoding
;
281 if ( charcode
>= encoding
->code_first
&&
282 charcode
<= encoding
->code_last
)
283 result
= encoding
->char_index
[charcode
];
287 /*******************************************************************/
289 /* Adobe Standard & Expert encoding support */
292 if ( charcode
< 256 )
296 const char* glyph_name
;
299 code
= psnames
->adobe_std_encoding
[charcode
];
300 if ( charmap
->encoding
== ft_encoding_adobe_expert
)
301 code
= psnames
->adobe_expert_encoding
[charcode
];
303 glyph_name
= psnames
->adobe_std_strings( code
);
307 for ( n
= 0; n
< face
->type1
.num_glyphs
; n
++ )
309 const char* gname
= face
->type1
.glyph_names
[n
];
312 if ( gname
&& gname
[0] == glyph_name
[0] &&
313 strcmp( gname
, glyph_name
) == 0 )
327 const FT_Driver_Class t1_driver_class
=
330 ft_module_font_driver
| ft_module_driver_scalable
,
331 sizeof( FT_DriverRec
),
333 "type1", /* driver name */
334 0x10000L
, /* driver version 1.0 */
335 0x20000L
, /* driver requires FreeType 2.0 or above */
337 0, /* module specific interface */
339 (FT_Module_Constructor
)0,
340 (FT_Module_Destructor
) 0,
341 (FT_Module_Requester
) T1_Get_Interface
344 sizeof( T1_FaceRec
),
345 sizeof( T1_SizeRec
),
346 sizeof( T1_GlyphSlotRec
),
348 (FTDriver_initFace
) T1_Init_Face
,
349 (FTDriver_doneFace
) T1_Done_Face
,
350 (FTDriver_initSize
) T1_Init_Size
,
351 (FTDriver_doneSize
) T1_Done_Size
,
352 (FTDriver_initGlyphSlot
)T1_Init_GlyphSlot
,
353 (FTDriver_doneGlyphSlot
)T1_Done_GlyphSlot
,
355 (FTDriver_setCharSizes
) Set_Char_Sizes
,
356 (FTDriver_setPixelSizes
)Set_Pixel_Sizes
,
357 (FTDriver_loadGlyph
) T1_Load_Glyph
,
358 (FTDriver_getCharIndex
) Get_Char_Index
,
360 #ifdef T1_CONFIG_OPTION_NO_AFM
361 (FTDriver_getKerning
) 0,
362 (FTDriver_attachFile
) 0,
364 (FTDriver_getKerning
) Get_Kerning
,
365 (FTDriver_attachFile
) T1_Read_AFM
,
367 (FTDriver_getAdvances
) 0
371 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
373 EXPORT_FUNC( const FT_Driver_Class
* ) getDriverClass( void )
375 return &t1_driver_class
;
378 #endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */