1 /***************************************************************************/
5 /* Type 1 driver interface (body). */
7 /* Copyright 1996-2004, 2006, 2007, 2009, 2011 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
33 #include FT_SERVICE_MULTIPLE_MASTERS_H
34 #include FT_SERVICE_GLYPH_DICT_H
35 #include FT_SERVICE_XFREE86_NAME_H
36 #include FT_SERVICE_POSTSCRIPT_NAME_H
37 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
38 #include FT_SERVICE_POSTSCRIPT_INFO_H
39 #include FT_SERVICE_KERNING_H
42 /*************************************************************************/
44 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
45 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
46 /* messages during execution. */
49 #define FT_COMPONENT trace_t1driver
57 t1_get_glyph_name( T1_Face face,
62 FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max );
69 t1_get_name_index( T1_Face face,
70 FT_String* glyph_name )
76 for ( i = 0; i < face->type1.num_glyphs; i++ )
78 gname = face->type1.glyph_names[i];
80 if ( !ft_strcmp( glyph_name, gname ) )
88 static const FT_Service_GlyphDictRec t1_service_glyph_dict =
90 (FT_GlyphDict_GetNameFunc) t1_get_glyph_name,
91 (FT_GlyphDict_NameIndexFunc)t1_get_name_index
96 * POSTSCRIPT NAME SERVICE
101 t1_get_ps_name( T1_Face face )
103 return (const char*) face->type1.font_name;
107 static const FT_Service_PsFontNameRec t1_service_ps_name =
109 (FT_PsName_GetFunc)t1_get_ps_name
114 * MULTIPLE MASTERS SERVICE
118 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
119 static const FT_Service_MultiMastersRec t1_service_multi_masters =
121 (FT_Get_MM_Func) T1_Get_Multi_Master,
122 (FT_Set_MM_Design_Func) T1_Set_MM_Design,
123 (FT_Set_MM_Blend_Func) T1_Set_MM_Blend,
124 (FT_Get_MM_Var_Func) T1_Get_MM_Var,
125 (FT_Set_Var_Design_Func)T1_Set_Var_Design
131 * POSTSCRIPT INFO SERVICE
136 t1_ps_get_font_info( FT_Face face,
137 PS_FontInfoRec* afont_info )
139 *afont_info = ((T1_Face)face)->type1.font_info;
146 t1_ps_get_font_extra( FT_Face face,
147 PS_FontExtraRec* afont_extra )
149 *afont_extra = ((T1_Face)face)->type1.font_extra;
156 t1_ps_has_glyph_names( FT_Face face )
165 t1_ps_get_font_private( FT_Face face,
166 PS_PrivateRec* afont_private )
168 *afont_private = ((T1_Face)face)->type1.private_dict;
175 t1_ps_get_font_value( FT_Face face,
182 T1_Face t1face = (T1_Face)face;
183 T1_Font type1 = &t1face->type1;
188 case PS_DICT_FONT_TYPE:
189 retval = sizeof ( type1->font_type );
190 if ( value && value_len >= retval )
191 *((FT_Byte *)value) = type1->font_type;
194 case PS_DICT_FONT_MATRIX:
195 if ( idx < sizeof ( type1->font_matrix ) /
196 sizeof ( type1->font_matrix.xx ) )
201 retval = sizeof ( val );
202 if ( value && value_len >= retval )
207 val = type1->font_matrix.xx;
210 val = type1->font_matrix.xy;
213 val = type1->font_matrix.yx;
216 val = type1->font_matrix.yy;
219 *((FT_Fixed *)value) = val;
224 case PS_DICT_FONT_BBOX:
225 if ( idx < sizeof ( type1->font_bbox ) /
226 sizeof ( type1->font_bbox.xMin ) )
231 retval = sizeof ( val );
232 if ( value && value_len >= retval )
237 val = type1->font_bbox.xMin;
240 val = type1->font_bbox.yMin;
243 val = type1->font_bbox.xMax;
246 val = type1->font_bbox.yMax;
249 *((FT_Fixed *)value) = val;
254 case PS_DICT_PAINT_TYPE:
255 retval = sizeof ( type1->paint_type );
256 if ( value && value_len >= retval )
257 *((FT_Byte *)value) = type1->paint_type;
260 case PS_DICT_FONT_NAME:
261 retval = ft_strlen( type1->font_name ) + 1;
262 if ( value && value_len >= retval )
263 ft_memcpy( value, (void *)( type1->font_name ), retval );
266 case PS_DICT_UNIQUE_ID:
267 retval = sizeof ( type1->private_dict.unique_id );
268 if ( value && value_len >= retval )
269 *((FT_Int *)value) = type1->private_dict.unique_id;
272 case PS_DICT_NUM_CHAR_STRINGS:
273 retval = sizeof ( type1->num_glyphs );
274 if ( value && value_len >= retval )
275 *((FT_Int *)value) = type1->num_glyphs;
278 case PS_DICT_CHAR_STRING_KEY:
279 if ( idx < (FT_UInt)type1->num_glyphs )
281 retval = ft_strlen( type1->glyph_names[idx] ) + 1;
282 if ( value && value_len >= retval )
284 ft_memcpy( value, (void *)( type1->glyph_names[idx] ), retval );
285 ((FT_Char *)value)[retval - 1] = (FT_Char)'\0';
290 case PS_DICT_CHAR_STRING:
291 if ( idx < (FT_UInt)type1->num_glyphs )
293 retval = type1->charstrings_len[idx] + 1;
294 if ( value && value_len >= retval )
296 ft_memcpy( value, (void *)( type1->charstrings[idx] ),
298 ((FT_Char *)value)[retval - 1] = (FT_Char)'\0';
303 case PS_DICT_ENCODING_TYPE:
304 retval = sizeof ( type1->encoding_type );
305 if ( value && value_len >= retval )
306 *((T1_EncodingType *)value) = type1->encoding_type;
309 case PS_DICT_ENCODING_ENTRY:
310 if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY &&
311 idx < (FT_UInt)type1->encoding.num_chars )
313 retval = ft_strlen( type1->encoding.char_name[idx] ) + 1;
314 if ( value && value_len >= retval )
316 ft_memcpy( value, (void *)( type1->encoding.char_name[idx] ),
318 ((FT_Char *)value)[retval - 1] = (FT_Char)'\0';
323 case PS_DICT_NUM_SUBRS:
324 retval = sizeof ( type1->num_subrs );
325 if ( value && value_len >= retval )
326 *((FT_Int *)value) = type1->num_subrs;
330 if ( idx < (FT_UInt)type1->num_subrs )
332 retval = type1->subrs_len[idx] + 1;
333 if ( value && value_len >= retval )
335 ft_memcpy( value, (void *)( type1->subrs[idx] ), retval - 1 );
336 ((FT_Char *)value)[retval - 1] = (FT_Char)'\0';
342 retval = sizeof ( type1->private_dict.standard_width[0] );
343 if ( value && value_len >= retval )
344 *((FT_UShort *)value) = type1->private_dict.standard_width[0];
348 retval = sizeof ( type1->private_dict.standard_height[0] );
349 if ( value && value_len >= retval )
350 *((FT_UShort *)value) = type1->private_dict.standard_height[0];
353 case PS_DICT_NUM_BLUE_VALUES:
354 retval = sizeof ( type1->private_dict.num_blue_values );
355 if ( value && value_len >= retval )
356 *((FT_Byte *)value) = type1->private_dict.num_blue_values;
359 case PS_DICT_BLUE_VALUE:
360 if ( idx < type1->private_dict.num_blue_values )
362 retval = sizeof ( type1->private_dict.blue_values[idx] );
363 if ( value && value_len >= retval )
364 *((FT_Short *)value) = type1->private_dict.blue_values[idx];
368 case PS_DICT_BLUE_SCALE:
369 retval = sizeof ( type1->private_dict.blue_scale );
370 if ( value && value_len >= retval )
371 *((FT_Fixed *)value) = type1->private_dict.blue_scale;
374 case PS_DICT_BLUE_FUZZ:
375 retval = sizeof ( type1->private_dict.blue_fuzz );
376 if ( value && value_len >= retval )
377 *((FT_Int *)value) = type1->private_dict.blue_fuzz;
380 case PS_DICT_BLUE_SHIFT:
381 retval = sizeof ( type1->private_dict.blue_shift );
382 if ( value && value_len >= retval )
383 *((FT_Int *)value) = type1->private_dict.blue_shift;
386 case PS_DICT_NUM_OTHER_BLUES:
387 retval = sizeof ( type1->private_dict.num_other_blues );
388 if ( value && value_len >= retval )
389 *((FT_Byte *)value) = type1->private_dict.num_other_blues;
392 case PS_DICT_OTHER_BLUE:
393 if ( idx < type1->private_dict.num_other_blues )
395 retval = sizeof ( type1->private_dict.other_blues[idx] );
396 if ( value && value_len >= retval )
397 *((FT_Short *)value) = type1->private_dict.other_blues[idx];
401 case PS_DICT_NUM_FAMILY_BLUES:
402 retval = sizeof ( type1->private_dict.num_family_blues );
403 if ( value && value_len >= retval )
404 *((FT_Byte *)value) = type1->private_dict.num_family_blues;
407 case PS_DICT_FAMILY_BLUE:
408 if ( idx < type1->private_dict.num_family_blues )
410 retval = sizeof ( type1->private_dict.family_blues[idx] );
411 if ( value && value_len >= retval )
412 *((FT_Short *)value) = type1->private_dict.family_blues[idx];
416 case PS_DICT_NUM_FAMILY_OTHER_BLUES:
417 retval = sizeof ( type1->private_dict.num_family_other_blues );
418 if ( value && value_len >= retval )
419 *((FT_Byte *)value) = type1->private_dict.num_family_other_blues;
422 case PS_DICT_FAMILY_OTHER_BLUE:
423 if ( idx < type1->private_dict.num_family_other_blues )
425 retval = sizeof ( type1->private_dict.family_other_blues[idx] );
426 if ( value && value_len >= retval )
427 *((FT_Short *)value) = type1->private_dict.family_other_blues[idx];
431 case PS_DICT_NUM_STEM_SNAP_H:
432 retval = sizeof ( type1->private_dict.num_snap_widths );
433 if ( value && value_len >= retval )
434 *((FT_Byte *)value) = type1->private_dict.num_snap_widths;
437 case PS_DICT_STEM_SNAP_H:
438 if ( idx < type1->private_dict.num_snap_widths )
440 retval = sizeof ( type1->private_dict.snap_widths[idx] );
441 if ( value && value_len >= retval )
442 *((FT_Short *)value) = type1->private_dict.snap_widths[idx];
446 case PS_DICT_NUM_STEM_SNAP_V:
447 retval = sizeof ( type1->private_dict.num_snap_heights );
448 if ( value && value_len >= retval )
449 *((FT_Byte *)value) = type1->private_dict.num_snap_heights;
452 case PS_DICT_STEM_SNAP_V:
453 if ( idx < type1->private_dict.num_snap_heights )
455 retval = sizeof ( type1->private_dict.snap_heights[idx] );
456 if ( value && value_len >= retval )
457 *((FT_Short *)value) = type1->private_dict.snap_heights[idx];
461 case PS_DICT_RND_STEM_UP:
462 retval = sizeof ( type1->private_dict.round_stem_up );
463 if ( value && value_len >= retval )
464 *((FT_Bool *)value) = type1->private_dict.round_stem_up;
467 case PS_DICT_FORCE_BOLD:
468 retval = sizeof ( type1->private_dict.force_bold );
469 if ( value && value_len >= retval )
470 *((FT_Bool *)value) = type1->private_dict.force_bold;
473 case PS_DICT_MIN_FEATURE:
474 if ( idx < sizeof ( type1->private_dict.min_feature ) /
475 sizeof ( type1->private_dict.min_feature[0] ) )
477 retval = sizeof ( type1->private_dict.min_feature[idx] );
478 if ( value && value_len >= retval )
479 *((FT_Short *)value) = type1->private_dict.min_feature[idx];
484 retval = sizeof ( type1->private_dict.lenIV );
485 if ( value && value_len >= retval )
486 *((FT_Int *)value) = type1->private_dict.lenIV;
489 case PS_DICT_PASSWORD:
490 retval = sizeof ( type1->private_dict.password );
491 if ( value && value_len >= retval )
492 *((FT_Long *)value) = type1->private_dict.password;
495 case PS_DICT_LANGUAGE_GROUP:
496 retval = sizeof ( type1->private_dict.language_group );
497 if ( value && value_len >= retval )
498 *((FT_Long *)value) = type1->private_dict.language_group;
501 case PS_DICT_IS_FIXED_PITCH:
502 retval = sizeof ( type1->font_info.is_fixed_pitch );
503 if ( value && value_len >= retval )
504 *((FT_Bool *)value) = type1->font_info.is_fixed_pitch;
507 case PS_DICT_UNDERLINE_POSITION:
508 retval = sizeof ( type1->font_info.underline_position );
509 if ( value && value_len >= retval )
510 *((FT_Short *)value) = type1->font_info.underline_position;
513 case PS_DICT_UNDERLINE_THICKNESS:
514 retval = sizeof ( type1->font_info.underline_thickness );
515 if ( value && value_len >= retval )
516 *((FT_UShort *)value) = type1->font_info.underline_thickness;
519 case PS_DICT_FS_TYPE:
520 retval = sizeof ( type1->font_extra.fs_type );
521 if ( value && value_len >= retval )
522 *((FT_UShort *)value) = type1->font_extra.fs_type;
525 case PS_DICT_VERSION:
526 retval = ft_strlen( type1->font_info.version ) + 1;
527 if ( value && value_len >= retval )
528 ft_memcpy( value, (void *)( type1->font_info.version ), retval );
532 retval = ft_strlen( type1->font_info.notice ) + 1;
533 if ( value && value_len >= retval )
534 ft_memcpy( value, (void *)( type1->font_info.notice ), retval );
537 case PS_DICT_FULL_NAME:
538 retval = ft_strlen( type1->font_info.full_name ) + 1;
539 if ( value && value_len >= retval )
540 ft_memcpy( value, (void *)( type1->font_info.full_name ), retval );
543 case PS_DICT_FAMILY_NAME:
544 retval = ft_strlen( type1->font_info.family_name ) + 1;
545 if ( value && value_len >= retval )
546 ft_memcpy( value, (void *)( type1->font_info.family_name ), retval );
550 retval = ft_strlen( type1->font_info.weight ) + 1;
551 if ( value && value_len >= retval )
552 ft_memcpy( value, (void *)( type1->font_info.weight ), retval );
555 case PS_DICT_ITALIC_ANGLE:
556 retval = sizeof ( type1->font_info.italic_angle );
557 if ( value && value_len >= retval )
558 *((FT_Long *)value) = type1->font_info.italic_angle;
569 static const FT_Service_PsInfoRec t1_service_ps_info =
571 (PS_GetFontInfoFunc) t1_ps_get_font_info,
572 (PS_GetFontExtraFunc) t1_ps_get_font_extra,
573 (PS_HasGlyphNamesFunc) t1_ps_has_glyph_names,
574 (PS_GetFontPrivateFunc)t1_ps_get_font_private,
575 (PS_GetFontValueFunc) t1_ps_get_font_value,
579 #ifndef T1_CONFIG_OPTION_NO_AFM
580 static const FT_Service_KerningRec t1_service_kerning =
582 T1_Get_Track_Kerning,
592 static const FT_ServiceDescRec t1_services[] =
594 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &t1_service_ps_name },
595 { FT_SERVICE_ID_GLYPH_DICT, &t1_service_glyph_dict },
596 { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TYPE_1 },
597 { FT_SERVICE_ID_POSTSCRIPT_INFO, &t1_service_ps_info },
599 #ifndef T1_CONFIG_OPTION_NO_AFM
600 { FT_SERVICE_ID_KERNING, &t1_service_kerning },
603 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
604 { FT_SERVICE_ID_MULTI_MASTERS, &t1_service_multi_masters },
610 FT_CALLBACK_DEF( FT_Module_Interface )
611 Get_Interface( FT_Module module,
612 const FT_String* t1_interface )
616 return ft_service_list_lookup( t1_services, t1_interface );
620 #ifndef T1_CONFIG_OPTION_NO_AFM
622 /*************************************************************************/
628 /* A driver method used to return the kerning vector between two */
629 /* glyphs of the same face. */
632 /* face :: A handle to the source face object. */
634 /* left_glyph :: The index of the left glyph in the kern pair. */
636 /* right_glyph :: The index of the right glyph in the kern pair. */
639 /* kerning :: The kerning vector. This is in font units for */
640 /* scalable formats, and in pixels for fixed-sizes */
644 /* FreeType error code. 0 means success. */
647 /* Only horizontal layouts (left-to-right & right-to-left) are */
648 /* supported by this function. Other layouts, or more sophisticated */
649 /* kernings are out of scope of this method (the basic driver */
650 /* interface is meant to be simple). */
652 /* They can be implemented by format-specific interfaces. */
655 Get_Kerning( FT_Face t1face, /* T1_Face */
660 T1_Face face = (T1_Face)t1face;
666 if ( face->afm_data )
667 T1_Get_Kerning( (AFM_FontInfo)face->afm_data,
676 #endif /* T1_CONFIG_OPTION_NO_AFM */
679 FT_CALLBACK_TABLE_DEF
680 const FT_Driver_ClassRec t1_driver_class =
683 FT_MODULE_FONT_DRIVER |
684 FT_MODULE_DRIVER_SCALABLE |
685 FT_MODULE_DRIVER_HAS_HINTER,
687 sizeof ( FT_DriverRec ),
693 0, /* format interface */
700 sizeof ( T1_FaceRec ),
701 sizeof ( T1_SizeRec ),
702 sizeof ( T1_GlyphSlotRec ),
711 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
712 ft_stub_set_char_sizes,
713 ft_stub_set_pixel_sizes,
717 #ifdef T1_CONFIG_OPTION_NO_AFM
718 0, /* FT_Face_GetKerningFunc */
719 0, /* FT_Face_AttachFunc */
726 0 /* FT_Size_SelectFunc */