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