t42drivr.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /***************************************************************************/
  2. /* */
  3. /* t42drivr.c */
  4. /* */
  5. /* High-level Type 42 driver interface (body). */
  6. /* */
  7. /* Copyright 2002 by Roberto Alameda. */
  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. /* */
  18. /* This driver implements Type42 fonts as described in the */
  19. /* Technical Note #5012 from Adobe, with these limitations: */
  20. /* */
  21. /* 1) CID Fonts are not currently supported. */
  22. /* 2) Incremental fonts making use of the GlyphDirectory keyword */
  23. /* will be loaded, but the rendering will be using the TrueType */
  24. /* tables. */
  25. /* 3) The sfnts array is expected to be ASCII, not binary. */
  26. /* 4) As for Type1 fonts, CDevProc is not supported. */
  27. /* 5) The Metrics dictionary is not supported. */
  28. /* 6) AFM metrics are not supported. */
  29. /* */
  30. /* In other words, this driver supports Type42 fonts derived from */
  31. /* TrueType fonts in a non-CID manner, as done by usual conversion */
  32. /* programs. */
  33. /* */
  34. /*************************************************************************/
  35. #include "t42drivr.h"
  36. #include "t42objs.h"
  37. #include "t42error.h"
  38. #include FT_INTERNAL_DEBUG_H
  39. #undef FT_COMPONENT
  40. #define FT_COMPONENT trace_t42
  41. static FT_Error
  42. t42_get_glyph_name( T42_Face face,
  43. FT_UInt glyph_index,
  44. FT_Pointer buffer,
  45. FT_UInt buffer_max )
  46. {
  47. FT_String* gname;
  48. gname = face->type1.glyph_names[glyph_index];
  49. if ( buffer_max > 0 )
  50. {
  51. FT_UInt len = (FT_UInt)( ft_strlen( gname ) );
  52. if ( len >= buffer_max )
  53. len = buffer_max - 1;
  54. FT_MEM_COPY( buffer, gname, len );
  55. ((FT_Byte*)buffer)[len] = 0;
  56. }
  57. return T42_Err_Ok;
  58. }
  59. static const char*
  60. t42_get_ps_name( T42_Face face )
  61. {
  62. return (const char*)face->type1.font_name;
  63. }
  64. static FT_UInt
  65. t42_get_name_index( T42_Face face,
  66. FT_String* glyph_name )
  67. {
  68. FT_Int i;
  69. FT_String* gname;
  70. for ( i = 0; i < face->type1.num_glyphs; i++ )
  71. {
  72. gname = face->type1.glyph_names[i];
  73. if ( !ft_strcmp( glyph_name, gname ) )
  74. return ft_atoi( (const char *)face->type1.charstrings[i] );
  75. }
  76. return 0;
  77. }
  78. static FT_Module_Interface
  79. T42_Get_Interface( FT_Driver driver,
  80. const FT_String* t42_interface )
  81. {
  82. FT_UNUSED( driver );
  83. /* Any additional interface are defined here */
  84. if (ft_strcmp( (const char*)t42_interface, "glyph_name" ) == 0 )
  85. return (FT_Module_Interface)t42_get_glyph_name;
  86. if ( ft_strcmp( (const char*)t42_interface, "name_index" ) == 0 )
  87. return (FT_Module_Interface)t42_get_name_index;
  88. if ( ft_strcmp( (const char*)t42_interface, "postscript_name" ) == 0 )
  89. return (FT_Module_Interface)t42_get_ps_name;
  90. return 0;
  91. }
  92. const FT_Driver_ClassRec t42_driver_class =
  93. {
  94. {
  95. ft_module_font_driver |
  96. ft_module_driver_scalable |
  97. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  98. ft_module_driver_has_hinter,
  99. #else
  100. 0,
  101. #endif
  102. sizeof ( T42_DriverRec ),
  103. "type42",
  104. 0x10000L,
  105. 0x20000L,
  106. 0, /* format interface */
  107. (FT_Module_Constructor)T42_Driver_Init,
  108. (FT_Module_Destructor) T42_Driver_Done,
  109. (FT_Module_Requester) T42_Get_Interface,
  110. },
  111. sizeof ( T42_FaceRec ),
  112. sizeof ( T42_SizeRec ),
  113. sizeof ( T42_GlyphSlotRec ),
  114. (FT_Face_InitFunc) T42_Face_Init,
  115. (FT_Face_DoneFunc) T42_Face_Done,
  116. (FT_Size_InitFunc) T42_Size_Init,
  117. (FT_Size_DoneFunc) T42_Size_Done,
  118. (FT_Slot_InitFunc) T42_GlyphSlot_Init,
  119. (FT_Slot_DoneFunc) T42_GlyphSlot_Done,
  120. (FT_Size_ResetPointsFunc) T42_Size_SetChars,
  121. (FT_Size_ResetPixelsFunc) T42_Size_SetPixels,
  122. (FT_Slot_LoadFunc) T42_GlyphSlot_Load,
  123. (FT_Face_GetKerningFunc) 0,
  124. (FT_Face_AttachFunc) 0,
  125. (FT_Face_GetAdvancesFunc) 0
  126. };
  127. /* END */