xref: /inferno-os/libfreetype/t1driver.c (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 /***************************************************************************/
2 /*                                                                         */
3 /*  t1driver.c                                                             */
4 /*                                                                         */
5 /*    Type 1 driver interface (body).                                      */
6 /*                                                                         */
7 /*  Copyright 1996-2001, 2002 by                                           */
8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9 /*                                                                         */
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.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17 
18 
19 #include <ft2build.h>
20 #include "t1driver.h"
21 #include "t1gload.h"
22 #include "t1load.h"
23 
24 #include "t1errors.h"
25 
26 #ifndef T1_CONFIG_OPTION_NO_AFM
27 #include "t1afm.h"
28 #endif
29 
30 #include FT_INTERNAL_DEBUG_H
31 #include FT_INTERNAL_STREAM_H
32 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
33 
34 
35   /*************************************************************************/
36   /*                                                                       */
37   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
38   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
39   /* messages during execution.                                            */
40   /*                                                                       */
41 #undef  FT_COMPONENT
42 #define FT_COMPONENT  trace_t1driver
43 
44 
45   static FT_Error
t1_get_glyph_name(T1_Face face,FT_UInt glyph_index,FT_Pointer buffer,FT_UInt buffer_max)46   t1_get_glyph_name( T1_Face     face,
47                      FT_UInt     glyph_index,
48                      FT_Pointer  buffer,
49                      FT_UInt     buffer_max )
50   {
51     FT_String*  gname;
52 
53 
54     gname = face->type1.glyph_names[glyph_index];
55 
56     if ( buffer_max > 0 )
57     {
58       FT_UInt  len = (FT_UInt)( ft_strlen( gname ) );
59 
60 
61       if (len >= buffer_max)
62         len = buffer_max - 1;
63 
64       FT_MEM_COPY( buffer, gname, len );
65       ((FT_Byte*)buffer)[len] = 0;
66     }
67 
68     return T1_Err_Ok;
69   }
70 
71 
72   /*************************************************************************/
73   /*                                                                       */
74   /* <Function>                                                            */
75   /*    t1_get_name_index                                                  */
76   /*                                                                       */
77   /* <Description>                                                         */
78   /*    Uses the Type 1 font's `glyph_names' table to find a given glyph   */
79   /*    name's glyph index.                                                */
80   /*                                                                       */
81   /* <Input>                                                               */
82   /*    face       :: A handle to the source face object.                  */
83   /*                                                                       */
84   /*    glyph_name :: The glyph name.                                      */
85   /*                                                                       */
86   /* <Return>                                                              */
87   /*    Glyph index.  0 means `undefined character code'.                  */
88   /*                                                                       */
89   static FT_UInt
t1_get_name_index(T1_Face face,FT_String * glyph_name)90   t1_get_name_index( T1_Face     face,
91                      FT_String*  glyph_name )
92   {
93     FT_Int      i;
94     FT_String*  gname;
95 
96 
97     for ( i = 0; i < face->type1.num_glyphs; i++ )
98     {
99       gname = face->type1.glyph_names[i];
100 
101       if ( !ft_strcmp( glyph_name, gname ) )
102         return (FT_UInt)i;
103     }
104 
105     return 0;
106   }
107 
108 
109   static const char*
t1_get_ps_name(T1_Face face)110   t1_get_ps_name( T1_Face  face )
111   {
112     return (const char*) face->type1.font_name;
113   }
114 
115 
116   /*************************************************************************/
117   /*                                                                       */
118   /* <Function>                                                            */
119   /*    Get_Interface                                                      */
120   /*                                                                       */
121   /* <Description>                                                         */
122   /*    Each driver can provide one or more extensions to the base         */
123   /*    FreeType API.  These can be used to access format specific         */
124   /*    features (e.g., all TrueType/OpenType resources share a common     */
125   /*    file structure and common tables which can be accessed through the */
126   /*    `sfnt' interface), or more simply generic ones (e.g., the          */
127   /*    `postscript names' interface which can be used to retrieve the     */
128   /*     PostScript name of a given glyph index).                          */
129   /*                                                                       */
130   /* <InOut>                                                               */
131   /*    driver       :: A handle to a driver object.                       */
132   /*                                                                       */
133   /* <Input>                                                               */
134   /*    t1_interface :: A string designing the interface.  Examples are    */
135   /*                    `sfnt', `post_names', `charmaps', etc.             */
136   /*                                                                       */
137   /* <Return>                                                              */
138   /*    A typeless pointer to the extension's interface (normally a table  */
139   /*    of function pointers).  Returns NULL if the requested extension    */
140   /*    isn't available (i.e., wasn't compiled in the driver at build      */
141   /*    time).                                                             */
142   /*                                                                       */
143   static FT_Module_Interface
Get_Interface(FT_Driver driver,const FT_String * t1_interface)144   Get_Interface( FT_Driver         driver,
145                  const FT_String*  t1_interface )
146   {
147     FT_UNUSED( driver );
148     FT_UNUSED( t1_interface );
149 
150     if ( ft_strcmp( (const char*)t1_interface, "glyph_name" ) == 0 )
151       return (FT_Module_Interface)t1_get_glyph_name;
152 
153     if ( ft_strcmp( (const char*)t1_interface, "name_index" ) == 0 )
154       return (FT_Module_Interface)t1_get_name_index;
155 
156     if ( ft_strcmp( (const char*)t1_interface, "postscript_name" ) == 0 )
157       return (FT_Module_Interface)t1_get_ps_name;
158 
159 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
160     if ( ft_strcmp( (const char*)t1_interface, "get_mm" ) == 0 )
161       return (FT_Module_Interface)T1_Get_Multi_Master;
162 
163     if ( ft_strcmp( (const char*)t1_interface, "set_mm_design") == 0 )
164       return (FT_Module_Interface)T1_Set_MM_Design;
165 
166     if ( ft_strcmp( (const char*)t1_interface, "set_mm_blend") == 0 )
167       return (FT_Module_Interface)T1_Set_MM_Blend;
168 #endif
169     return 0;
170   }
171 
172 
173 #ifndef T1_CONFIG_OPTION_NO_AFM
174 
175   /*************************************************************************/
176   /*                                                                       */
177   /* <Function>                                                            */
178   /*    Get_Kerning                                                        */
179   /*                                                                       */
180   /* <Description>                                                         */
181   /*    A driver method used to return the kerning vector between two      */
182   /*    glyphs of the same face.                                           */
183   /*                                                                       */
184   /* <Input>                                                               */
185   /*    face        :: A handle to the source face object.                 */
186   /*                                                                       */
187   /*    left_glyph  :: The index of the left glyph in the kern pair.       */
188   /*                                                                       */
189   /*    right_glyph :: The index of the right glyph in the kern pair.      */
190   /*                                                                       */
191   /* <Output>                                                              */
192   /*    kerning     :: The kerning vector.  This is in font units for      */
193   /*                   scalable formats, and in pixels for fixed-sizes     */
194   /*                   formats.                                            */
195   /*                                                                       */
196   /* <Return>                                                              */
197   /*    FreeType error code.  0 means success.                             */
198   /*                                                                       */
199   /* <Note>                                                                */
200   /*    Only horizontal layouts (left-to-right & right-to-left) are        */
201   /*    supported by this function.  Other layouts, or more sophisticated  */
202   /*    kernings are out of scope of this method (the basic driver         */
203   /*    interface is meant to be simple).                                  */
204   /*                                                                       */
205   /*    They can be implemented by format-specific interfaces.             */
206   /*                                                                       */
207   static FT_Error
Get_Kerning(T1_Face face,FT_UInt left_glyph,FT_UInt right_glyph,FT_Vector * kerning)208   Get_Kerning( T1_Face     face,
209                FT_UInt     left_glyph,
210                FT_UInt     right_glyph,
211                FT_Vector*  kerning )
212   {
213     T1_AFM*  afm;
214 
215 
216     kerning->x = 0;
217     kerning->y = 0;
218 
219     afm = (T1_AFM*)face->afm_data;
220     if ( afm )
221       T1_Get_Kerning( afm, left_glyph, right_glyph, kerning );
222 
223     return T1_Err_Ok;
224   }
225 
226 
227 #endif /* T1_CONFIG_OPTION_NO_AFM */
228 
229 
230 
231 
232   FT_CALLBACK_TABLE_DEF
233   const FT_Driver_ClassRec  t1_driver_class =
234   {
235     {
236       ft_module_font_driver      |
237       ft_module_driver_scalable  |
238       ft_module_driver_has_hinter,
239 
240       sizeof( FT_DriverRec ),
241 
242       "type1",
243       0x10000L,
244       0x20000L,
245 
246       0,   /* format interface */
247 
248       (FT_Module_Constructor)T1_Driver_Init,
249       (FT_Module_Destructor) T1_Driver_Done,
250       (FT_Module_Requester)  Get_Interface,
251     },
252 
253     sizeof( T1_FaceRec ),
254     sizeof( T1_SizeRec ),
255     sizeof( T1_GlyphSlotRec ),
256 
257     (FT_Face_InitFunc)        T1_Face_Init,
258     (FT_Face_DoneFunc)        T1_Face_Done,
259     (FT_Size_InitFunc)        T1_Size_Init,
260     (FT_Size_DoneFunc)        T1_Size_Done,
261     (FT_Slot_InitFunc)        T1_GlyphSlot_Init,
262     (FT_Slot_DoneFunc)        T1_GlyphSlot_Done,
263 
264     (FT_Size_ResetPointsFunc) T1_Size_Reset,
265     (FT_Size_ResetPixelsFunc) T1_Size_Reset,
266     (FT_Slot_LoadFunc)        T1_Load_Glyph,
267 
268 #ifdef T1_CONFIG_OPTION_NO_AFM
269     (FT_Face_GetKerningFunc)  0,
270     (FT_Face_AttachFunc)      0,
271 #else
272     (FT_Face_GetKerningFunc)  Get_Kerning,
273     (FT_Face_AttachFunc)      T1_Read_AFM,
274 #endif
275     (FT_Face_GetAdvancesFunc) 0
276   };
277 
278 
279 /* END */
280