1/****************************************************************************
2 *
3 * cidriver.c
4 *
5 * CID driver interface (body).
6 *
7 * Copyright (C) 1996-2023 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 FT_CALLBACK_DEF( const char* )
52 cid_get_postscript_name( FT_Face face ) /* CID_Face */
53 {
54 CID_Face cidface = (CID_Face)face;
55 const char* result = cidface->cid.cid_font_name;
56
57
58 if ( result && result[0] == '/' )
59 result++;
60
61 return result;
62 }
63
64
65 static const FT_Service_PsFontNameRec cid_service_ps_name =
66 {
67 (FT_PsName_GetFunc)cid_get_postscript_name /* get_ps_font_name */
68 };
69
70
71 /*
72 * POSTSCRIPT INFO SERVICE
73 *
74 */
75
76 FT_CALLBACK_DEF( FT_Error )
77 cid_ps_get_font_info( FT_Face face, /* CID_Face */
78 PS_FontInfoRec* afont_info )
79 {
80 *afont_info = ( (CID_Face)face )->cid.font_info;
81
82 return FT_Err_Ok;
83 }
84
85
86 FT_CALLBACK_DEF( FT_Error )
87 cid_ps_get_font_extra( FT_Face face, /* CID_Face */
88 PS_FontExtraRec* afont_extra )
89 {
90 *afont_extra = ( (CID_Face)face )->font_extra;
91
92 return FT_Err_Ok;
93 }
94
95
96 static const FT_Service_PsInfoRec cid_service_ps_info =
97 {
98 cid_ps_get_font_info, /* PS_GetFontInfoFunc ps_get_font_info */
99 cid_ps_get_font_extra, /* PS_GetFontExtraFunc ps_get_font_extra */
100 /* unsupported with CID fonts */
101 NULL, /* PS_HasGlyphNamesFunc ps_has_glyph_names */
102 /* unsupported */
103 NULL, /* PS_GetFontPrivateFunc ps_get_font_private */
104 /* not implemented */
105 NULL /* PS_GetFontValueFunc ps_get_font_value */
106 };
107
108
109 /*
110 * CID INFO SERVICE
111 *
112 */
113 FT_CALLBACK_DEF( FT_Error )
114 cid_get_ros( FT_Face face, /* CID_Face */
115 const char* *registry,
116 const char* *ordering,
117 FT_Int *supplement )
118 {
119 CID_Face cidface = (CID_Face)face;
120 CID_FaceInfo cid = &cidface->cid;
121
122
123 if ( registry )
124 *registry = cid->registry;
125
126 if ( ordering )
127 *ordering = cid->ordering;
128
129 if ( supplement )
130 *supplement = cid->supplement;
131
132 return FT_Err_Ok;
133 }
134
135
136 FT_CALLBACK_DEF( FT_Error )
137 cid_get_is_cid( FT_Face face, /* CID_Face */
138 FT_Bool *is_cid )
139 {
140 FT_Error error = FT_Err_Ok;
141 FT_UNUSED( face );
142
143
144 /*
145 * XXX: If the ROS is Adobe-Identity-H or -V,
146 * the font has no reliable information about
147 * its glyph collection. Should we not set
148 * *is_cid in such cases?
149 */
150 if ( is_cid )
151 *is_cid = 1;
152
153 return error;
154 }
155
156
157 FT_CALLBACK_DEF( FT_Error )
158 cid_get_cid_from_glyph_index( FT_Face face, /* CID_Face */
159 FT_UInt glyph_index,
160 FT_UInt *cid )
161 {
162 FT_Error error = FT_Err_Ok;
163 CID_Face cidface = (CID_Face)face;
164
165
166 /*
167 * Currently, FreeType does not support incrementally-defined, CID-keyed
168 * fonts that store the glyph description data in a `/GlyphDirectory`
169 * array or dictionary. Fonts loaded by the incremental loading feature
170 * are thus not handled here.
171 */
172 error = cid_compute_fd_and_offsets( cidface, glyph_index,
173 NULL, NULL, NULL );
174 if ( error )
175 *cid = 0;
176 else
177 *cid = glyph_index;
178
179 return error;
180 }
181
182
183 static const FT_Service_CIDRec cid_service_cid_info =
184 {
185 cid_get_ros,
186 /* FT_CID_GetRegistryOrderingSupplementFunc get_ros */
187 cid_get_is_cid,
188 /* FT_CID_GetIsInternallyCIDKeyedFunc get_is_cid */
189 cid_get_cid_from_glyph_index
190 /* FT_CID_GetCIDFromGlyphIndexFunc get_cid_from_glyph_index */
191 };
192
193
194 /*
195 * PROPERTY SERVICE
196 *
197 */
198
199 FT_DEFINE_SERVICE_PROPERTIESREC(
200 cid_service_properties,
201
202 ps_property_set, /* FT_Properties_SetFunc set_property */
203 ps_property_get /* FT_Properties_GetFunc get_property */
204 )
205
206 /*
207 * SERVICE LIST
208 *
209 */
210
211 static const FT_ServiceDescRec cid_services[] =
212 {
213 { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CID },
214 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cid_service_ps_name },
215 { FT_SERVICE_ID_POSTSCRIPT_INFO, &cid_service_ps_info },
216 { FT_SERVICE_ID_CID, &cid_service_cid_info },
217 { FT_SERVICE_ID_PROPERTIES, &cid_service_properties },
218 { NULL, NULL }
219 };
220
221
222 FT_CALLBACK_DEF( FT_Module_Interface )
223 cid_get_interface( FT_Module module,
224 const char* cid_interface )
225 {
226 FT_UNUSED( module );
227
228 return ft_service_list_lookup( cid_services, cid_interface );
229 }
230
231
232 FT_CALLBACK_TABLE_DEF
233 const FT_Driver_ClassRec t1cid_driver_class =
234 {
235 {
236 FT_MODULE_FONT_DRIVER |
237 FT_MODULE_DRIVER_SCALABLE |
238 FT_MODULE_DRIVER_HAS_HINTER,
239 sizeof ( PS_DriverRec ),
240
241 "t1cid", /* module name */
242 0x10000L, /* version 1.0 of driver */
243 0x20000L, /* requires FreeType 2.0 */
244
245 NULL, /* module-specific interface */
246
247 cid_driver_init, /* FT_Module_Constructor module_init */
248 cid_driver_done, /* FT_Module_Destructor module_done */
249 cid_get_interface /* FT_Module_Requester get_interface */
250 },
251
252 sizeof ( CID_FaceRec ),
253 sizeof ( CID_SizeRec ),
254 sizeof ( CID_GlyphSlotRec ),
255
256 cid_face_init, /* FT_Face_InitFunc init_face */
257 cid_face_done, /* FT_Face_DoneFunc done_face */
258 cid_size_init, /* FT_Size_InitFunc init_size */
259 cid_size_done, /* FT_Size_DoneFunc done_size */
260 cid_slot_init, /* FT_Slot_InitFunc init_slot */
261 cid_slot_done, /* FT_Slot_DoneFunc done_slot */
262
263 cid_slot_load_glyph, /* FT_Slot_LoadFunc load_glyph */
264
265 NULL, /* FT_Face_GetKerningFunc get_kerning */
266 NULL, /* FT_Face_AttachFunc attach_file */
267 NULL, /* FT_Face_GetAdvancesFunc get_advances */
268
269 cid_size_request, /* FT_Size_RequestFunc request_size */
270 NULL /* FT_Size_SelectFunc select_size */
271 };
272
273
274/* END */
275