1 /****************************************************************************
2  *
3  * cidriver.c
4  *
5  *   CID driver interface (body).
6  *
7  * Copyright (C) 1996-2020 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 "cidriver.h"
20 #include "cidgload.h"
21 #include <freetype/internal/ftdebug.h>
22 #include <freetype/internal/ftpsprop.h>
23 
24 #include "ciderrs.h"
25 
26 #include <freetype/internal/services/svpostnm.h>
27 #include <freetype/internal/services/svfntfmt.h>
28 #include <freetype/internal/services/svpsinfo.h>
29 #include <freetype/internal/services/svcid.h>
30 #include <freetype/internal/services/svprop.h>
31 #include <freetype/ftdriver.h>
32 
33 #include <freetype/internal/psaux.h>
34 
35 
36   /**************************************************************************
37    *
38    * The macro FT_COMPONENT is used in trace mode.  It is an implicit
39    * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
40    * messages during execution.
41    */
42 #undef  FT_COMPONENT
43 #define FT_COMPONENT  ciddriver
44 
45 
46   /*
47    * POSTSCRIPT NAME SERVICE
48    *
49    */
50 
51   static const char*
cid_get_postscript_name(CID_Face face)52   cid_get_postscript_name( CID_Face  face )
53   {
54     const char*  result = face->cid.cid_font_name;
55 
56 
57     if ( result && result[0] == '/' )
58       result++;
59 
60     return result;
61   }
62 
63 
64   static const FT_Service_PsFontNameRec  cid_service_ps_name =
65   {
66     (FT_PsName_GetFunc)cid_get_postscript_name    /* get_ps_font_name */
67   };
68 
69 
70   /*
71    * POSTSCRIPT INFO SERVICE
72    *
73    */
74 
75   static FT_Error
cid_ps_get_font_info(FT_Face face,PS_FontInfoRec * afont_info)76   cid_ps_get_font_info( FT_Face          face,
77                         PS_FontInfoRec*  afont_info )
78   {
79     *afont_info = ((CID_Face)face)->cid.font_info;
80 
81     return FT_Err_Ok;
82   }
83 
84   static FT_Error
cid_ps_get_font_extra(FT_Face face,PS_FontExtraRec * afont_extra)85   cid_ps_get_font_extra( FT_Face          face,
86                         PS_FontExtraRec*  afont_extra )
87   {
88     *afont_extra = ((CID_Face)face)->font_extra;
89 
90     return FT_Err_Ok;
91   }
92 
93   static const FT_Service_PsInfoRec  cid_service_ps_info =
94   {
95     (PS_GetFontInfoFunc)   cid_ps_get_font_info,   /* ps_get_font_info    */
96     (PS_GetFontExtraFunc)  cid_ps_get_font_extra,  /* ps_get_font_extra   */
97     /* unsupported with CID fonts */
98     (PS_HasGlyphNamesFunc) NULL,                   /* ps_has_glyph_names  */
99     /* unsupported                */
100     (PS_GetFontPrivateFunc)NULL,                   /* ps_get_font_private */
101     /* not implemented            */
102     (PS_GetFontValueFunc)  NULL                    /* ps_get_font_value   */
103   };
104 
105 
106   /*
107    * CID INFO SERVICE
108    *
109    */
110   static FT_Error
cid_get_ros(CID_Face face,const char ** registry,const char ** ordering,FT_Int * supplement)111   cid_get_ros( CID_Face      face,
112                const char*  *registry,
113                const char*  *ordering,
114                FT_Int       *supplement )
115   {
116     CID_FaceInfo  cid = &face->cid;
117 
118 
119     if ( registry )
120       *registry = cid->registry;
121 
122     if ( ordering )
123       *ordering = cid->ordering;
124 
125     if ( supplement )
126       *supplement = cid->supplement;
127 
128     return FT_Err_Ok;
129   }
130 
131 
132   static FT_Error
cid_get_is_cid(CID_Face face,FT_Bool * is_cid)133   cid_get_is_cid( CID_Face  face,
134                   FT_Bool  *is_cid )
135   {
136     FT_Error  error = FT_Err_Ok;
137     FT_UNUSED( face );
138 
139 
140     if ( is_cid )
141       *is_cid = 1; /* cid driver is only used for CID keyed fonts */
142 
143     return error;
144   }
145 
146 
147   static FT_Error
cid_get_cid_from_glyph_index(CID_Face face,FT_UInt glyph_index,FT_UInt * cid)148   cid_get_cid_from_glyph_index( CID_Face  face,
149                                 FT_UInt   glyph_index,
150                                 FT_UInt  *cid )
151   {
152     FT_Error  error = FT_Err_Ok;
153     FT_UNUSED( face );
154 
155 
156     if ( cid )
157       *cid = glyph_index; /* identity mapping */
158 
159     return error;
160   }
161 
162 
163   static const FT_Service_CIDRec  cid_service_cid_info =
164   {
165     (FT_CID_GetRegistryOrderingSupplementFunc)
166       cid_get_ros,                             /* get_ros                  */
167     (FT_CID_GetIsInternallyCIDKeyedFunc)
168       cid_get_is_cid,                          /* get_is_cid               */
169     (FT_CID_GetCIDFromGlyphIndexFunc)
170       cid_get_cid_from_glyph_index             /* get_cid_from_glyph_index */
171   };
172 
173 
174   /*
175    * PROPERTY SERVICE
176    *
177    */
178 
179   FT_DEFINE_SERVICE_PROPERTIESREC(
180     cid_service_properties,
181 
182     (FT_Properties_SetFunc)ps_property_set,      /* set_property */
183     (FT_Properties_GetFunc)ps_property_get )     /* get_property */
184 
185 
186   /*
187    * SERVICE LIST
188    *
189    */
190 
191   static const FT_ServiceDescRec  cid_services[] =
192   {
193     { FT_SERVICE_ID_FONT_FORMAT,          FT_FONT_FORMAT_CID },
194     { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cid_service_ps_name },
195     { FT_SERVICE_ID_POSTSCRIPT_INFO,      &cid_service_ps_info },
196     { FT_SERVICE_ID_CID,                  &cid_service_cid_info },
197     { FT_SERVICE_ID_PROPERTIES,           &cid_service_properties },
198     { NULL, NULL }
199   };
200 
201 
202   FT_CALLBACK_DEF( FT_Module_Interface )
cid_get_interface(FT_Module module,const char * cid_interface)203   cid_get_interface( FT_Module    module,
204                      const char*  cid_interface )
205   {
206     FT_UNUSED( module );
207 
208     return ft_service_list_lookup( cid_services, cid_interface );
209   }
210 
211 
212 
213   FT_CALLBACK_TABLE_DEF
214   const FT_Driver_ClassRec  t1cid_driver_class =
215   {
216     {
217       FT_MODULE_FONT_DRIVER       |
218       FT_MODULE_DRIVER_SCALABLE   |
219       FT_MODULE_DRIVER_HAS_HINTER,
220       sizeof ( PS_DriverRec ),
221 
222       "t1cid",   /* module name           */
223       0x10000L,  /* version 1.0 of driver */
224       0x20000L,  /* requires FreeType 2.0 */
225 
226       NULL,    /* module-specific interface */
227 
228       cid_driver_init,          /* FT_Module_Constructor  module_init   */
229       cid_driver_done,          /* FT_Module_Destructor   module_done   */
230       cid_get_interface         /* FT_Module_Requester    get_interface */
231     },
232 
233     sizeof ( CID_FaceRec ),
234     sizeof ( CID_SizeRec ),
235     sizeof ( CID_GlyphSlotRec ),
236 
237     cid_face_init,              /* FT_Face_InitFunc  init_face */
238     cid_face_done,              /* FT_Face_DoneFunc  done_face */
239     cid_size_init,              /* FT_Size_InitFunc  init_size */
240     cid_size_done,              /* FT_Size_DoneFunc  done_size */
241     cid_slot_init,              /* FT_Slot_InitFunc  init_slot */
242     cid_slot_done,              /* FT_Slot_DoneFunc  done_slot */
243 
244     cid_slot_load_glyph,        /* FT_Slot_LoadFunc  load_glyph */
245 
246     NULL,                       /* FT_Face_GetKerningFunc   get_kerning  */
247     NULL,                       /* FT_Face_AttachFunc       attach_file  */
248     NULL,                       /* FT_Face_GetAdvancesFunc  get_advances */
249 
250     cid_size_request,           /* FT_Size_RequestFunc  request_size */
251     NULL                        /* FT_Size_SelectFunc   select_size  */
252   };
253 
254 
255 /* END */
256