The BIG graph update
[rrdtool.git] / libraries / freetype-2.0.5 / cidriver.c
1 /***************************************************************************/
2 /*                                                                         */
3 /*  cidriver.c                                                             */
4 /*                                                                         */
5 /*    CID driver interface (body).                                         */
6 /*                                                                         */
7 /*  Copyright 1996-2001 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 "cidriver.h"
21 #include "cidgload.h"
22 #include FT_INTERNAL_DEBUG_H
23 #include FT_INTERNAL_STREAM_H
24 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
25
26 #include "ciderrs.h"
27
28 #include <string.h>         /* for strcmp() */
29
30
31   /*************************************************************************/
32   /*                                                                       */
33   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
34   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
35   /* messages during execution.                                            */
36   /*                                                                       */
37 #undef  FT_COMPONENT
38 #define FT_COMPONENT  trace_ciddriver
39
40
41
42   static const char*
43   cid_get_postscript_name( CID_Face  face )
44   {
45     return (const char*)face->cid.cid_font_name;
46   }
47
48
49   static FT_Module_Interface
50   CID_Get_Interface( FT_Driver         driver,
51                      const FT_String*  interface )
52   {
53     FT_UNUSED( driver );
54     FT_UNUSED( interface );
55
56     if ( strcmp( (const char*)interface, "postscript_name" ) == 0 )
57       return (FT_Module_Interface)cid_get_postscript_name;
58
59     return 0;
60   }
61
62
63 #if 0 /* unimplemented yet */
64
65   static FT_Error
66   cid_Get_Kerning( T1_Face     face,
67                    FT_UInt     left_glyph,
68                    FT_UInt     right_glyph,
69                    FT_Vector*  kerning )
70   {
71     CID_AFM*  afm;
72
73
74     kerning->x = 0;
75     kerning->y = 0;
76
77     afm = (CID_AFM*)face->afm_data;
78     if ( afm )
79       CID_Get_Kerning( afm, left_glyph, right_glyph, kerning );
80
81     return CID_Err_Ok;
82   }
83
84
85 #endif /* 0 */
86
87
88   /*************************************************************************/
89   /*                                                                       */
90   /* <Function>                                                            */
91   /*    Cid_Get_Char_Index                                                 */
92   /*                                                                       */
93   /* <Description>                                                         */
94   /*    Uses a charmap to return a given character code's glyph index.     */
95   /*                                                                       */
96   /* <Input>                                                               */
97   /*    charmap  :: A handle to the source charmap object.                 */
98   /*                                                                       */
99   /*    charcode :: The character code.                                    */
100   /*                                                                       */
101   /* <Return>                                                              */
102   /*    Glyph index.  0 means `undefined character code'.                  */
103   /*                                                                       */
104   static FT_UInt
105   CID_Get_Char_Index( FT_CharMap  charmap,
106                       FT_Long     charcode )
107   {
108     T1_Face             face;
109     FT_UInt             result = 0;
110     PSNames_Interface*  psnames;
111
112
113     face = (T1_Face)charmap->face;
114     psnames = (PSNames_Interface*)face->psnames;
115     if ( psnames )
116       switch ( charmap->encoding )
117       {
118         /*******************************************************************/
119         /*                                                                 */
120         /* Unicode encoding support                                        */
121         /*                                                                 */
122       case ft_encoding_unicode:
123         /* use the `PSNames' module to synthetize the Unicode charmap */
124         result = psnames->lookup_unicode( &face->unicode_map,
125                                           (FT_ULong)charcode );
126
127         /* the function returns 0xFFFF if the Unicode charcode has */
128         /* no corresponding glyph.                                 */
129         if ( result == 0xFFFF )
130           result = 0;
131         goto Exit;
132
133         /*******************************************************************/
134         /*                                                                 */
135         /* Custom Type 1 encoding                                          */
136         /*                                                                 */
137       case ft_encoding_adobe_custom:
138         {
139           T1_Encoding*  encoding = &face->type1.encoding;
140
141
142           if ( charcode >= encoding->code_first &&
143                charcode <= encoding->code_last  )
144             result = encoding->char_index[charcode];
145           goto Exit;
146         }
147
148         /*******************************************************************/
149         /*                                                                 */
150         /* Adobe Standard & Expert encoding support                        */
151         /*                                                                 */
152       default:
153         if ( charcode < 256 )
154         {
155           FT_UInt      code;
156           FT_Int       n;
157           const char*  glyph_name;
158
159
160           code = psnames->adobe_std_encoding[charcode];
161           if ( charmap->encoding == ft_encoding_adobe_expert )
162             code = psnames->adobe_expert_encoding[charcode];
163
164           glyph_name = psnames->adobe_std_strings( code );
165           if ( !glyph_name )
166             break;
167
168           for ( n = 0; n < face->type1.num_glyphs; n++ )
169           {
170             const char*  gname = face->type1.glyph_names[n];
171
172
173             if ( gname && gname[0] == glyph_name[0] &&
174                  strcmp( gname, glyph_name ) == 0   )
175             {
176               result = n;
177               break;
178             }
179           }
180         }
181       }
182
183   Exit:
184     return result;
185   }
186
187
188
189   FT_CALLBACK_TABLE_DEF
190   const FT_Driver_Class  t1cid_driver_class =
191   {
192     /* first of all, the FT_Module_Class fields */
193     {
194       ft_module_font_driver | ft_module_driver_scalable,
195       sizeof( FT_DriverRec ),
196       "t1cid",   /* module name           */
197       0x10000L,  /* version 1.0 of driver */
198       0x20000L,  /* requires FreeType 2.0 */
199
200       0,
201
202       (FT_Module_Constructor)CID_Init_Driver,
203       (FT_Module_Destructor) CID_Done_Driver,
204       (FT_Module_Requester)  CID_Get_Interface
205     },
206
207     /* then the other font drivers fields */
208     sizeof( CID_FaceRec ),
209     sizeof( CID_SizeRec ),
210     sizeof( CID_GlyphSlotRec ),
211
212     (FTDriver_initFace)     CID_Init_Face,
213     (FTDriver_doneFace)     CID_Done_Face,
214
215     (FTDriver_initSize)     0,
216     (FTDriver_doneSize)     0,
217     (FTDriver_initGlyphSlot)0,
218     (FTDriver_doneGlyphSlot)0,
219
220     (FTDriver_setCharSizes) 0,
221     (FTDriver_setPixelSizes)0,
222
223     (FTDriver_loadGlyph)    CID_Load_Glyph,
224     (FTDriver_getCharIndex) CID_Get_Char_Index,
225
226     (FTDriver_getKerning)   0,
227     (FTDriver_attachFile)   0,
228
229     (FTDriver_getAdvances)  0
230   };
231
232
233 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
234
235
236   /*************************************************************************/
237   /*                                                                       */
238   /* <Function>                                                            */
239   /*    getDriverClass                                                     */
240   /*                                                                       */
241   /* <Description>                                                         */
242   /*    This function is used when compiling the TrueType driver as a      */
243   /*    shared library (`.DLL' or `.so').  It will be used by the          */
244   /*    high-level library of FreeType to retrieve the address of the      */
245   /*    driver's generic interface.                                        */
246   /*                                                                       */
247   /*    It shouldn't be implemented in a static build, as each driver must */
248   /*    have the same function as an exported entry point.                 */
249   /*                                                                       */
250   /* <Return>                                                              */
251   /*    The address of the TrueType's driver generic interface.  The       */
252   /*    format-specific interface can then be retrieved through the method */
253   /*    interface->get_format_interface.                                   */
254   /*                                                                       */
255   FT_EXPORT_DEF( const FT_Driver_Class* )
256   getDriverClass( void )
257   {
258     return &t1cid_driver_class;
259   }
260
261
262 #endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */
263
264
265 /* END */