ReactOS 0.4.16-dev-981-g80eb313
cidobjs.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * cidobjs.c
4 *
5 * CID objects manager (body).
6 *
7 * Copyright (C) 1996-2019 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 FT_INTERNAL_DEBUG_H
21#include FT_INTERNAL_STREAM_H
22
23#include "cidgload.h"
24#include "cidload.h"
25
26#include FT_SERVICE_POSTSCRIPT_CMAPS_H
27#include FT_INTERNAL_POSTSCRIPT_AUX_H
28#include FT_INTERNAL_POSTSCRIPT_HINTS_H
29#include FT_DRIVER_H
30
31#include "ciderrs.h"
32
33
34 /**************************************************************************
35 *
36 * The macro FT_COMPONENT is used in trace mode. It is an implicit
37 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
38 * messages during execution.
39 */
40#undef FT_COMPONENT
41#define FT_COMPONENT cidobjs
42
43
44 /**************************************************************************
45 *
46 * SLOT FUNCTIONS
47 *
48 */
49
50 FT_LOCAL_DEF( void )
52 {
53 slot->internal->glyph_hints = NULL;
54 }
55
56
59 {
61 PSHinter_Service pshinter;
62
63
64 face = (CID_Face)slot->face;
65 pshinter = (PSHinter_Service)face->pshinter;
66
67 if ( pshinter )
68 {
70
71
72 module = FT_Get_Module( slot->face->driver->root.library,
73 "pshinter" );
74 if ( module )
75 {
77
78
79 funcs = pshinter->get_t1_funcs( module );
80 slot->internal->glyph_hints = (void*)funcs;
81 }
82 }
83
84 return 0;
85 }
86
87
88 /**************************************************************************
89 *
90 * SIZE FUNCTIONS
91 *
92 */
93
94
97 {
99 PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
101
102
103 module = FT_Get_Module( size->root.face->driver->root.library,
104 "pshinter" );
105 return ( module && pshinter && pshinter->get_globals_funcs )
106 ? pshinter->get_globals_funcs( module )
107 : 0;
108 }
109
110
111 FT_LOCAL_DEF( void )
112 cid_size_done( FT_Size cidsize ) /* CID_Size */
113 {
114 CID_Size size = (CID_Size)cidsize;
115
116
117 if ( cidsize->internal->module_data )
118 {
120
121
123 if ( funcs )
124 funcs->destroy( (PSH_Globals)cidsize->internal->module_data );
125
126 cidsize->internal->module_data = NULL;
127 }
128 }
129
130
132 cid_size_init( FT_Size cidsize ) /* CID_Size */
133 {
134 CID_Size size = (CID_Size)cidsize;
137
138
139 if ( funcs )
140 {
141 PSH_Globals globals;
142 CID_Face face = (CID_Face)cidsize->face;
143 CID_FaceDict dict = face->cid.font_dicts + face->root.face_index;
144 PS_Private priv = &dict->private_dict;
145
146
147 error = funcs->create( cidsize->face->memory, priv, &globals );
148 if ( !error )
149 cidsize->internal->module_data = globals;
150 }
151
152 return error;
153 }
154
155
158 FT_Size_Request req )
159 {
161
162
163 FT_Request_Metrics( size->face, req );
164
166
167 if ( funcs )
168 funcs->set_scale( (PSH_Globals)size->internal->module_data,
169 size->metrics.x_scale,
170 size->metrics.y_scale,
171 0, 0 );
172
173 return FT_Err_Ok;
174 }
175
176
177 /**************************************************************************
178 *
179 * FACE FUNCTIONS
180 *
181 */
182
183 /**************************************************************************
184 *
185 * @Function:
186 * cid_face_done
187 *
188 * @Description:
189 * Finalizes a given face object.
190 *
191 * @Input:
192 * face ::
193 * A pointer to the face object to destroy.
194 */
195 FT_LOCAL_DEF( void )
196 cid_face_done( FT_Face cidface ) /* CID_Face */
197 {
198 CID_Face face = (CID_Face)cidface;
202
203
204 if ( !face )
205 return;
206
207 cid = &face->cid;
208 info = &cid->font_info;
209 memory = cidface->memory;
210
211 /* release subrs */
212 if ( face->subrs )
213 {
214 FT_Int n;
215
216
217 for ( n = 0; n < cid->num_dicts; n++ )
218 {
219 CID_Subrs subr = face->subrs + n;
220
221
222 if ( subr->code )
223 {
224 FT_FREE( subr->code[0] );
225 FT_FREE( subr->code );
226 }
227 }
228
229 FT_FREE( face->subrs );
230 }
231
232 /* release FontInfo strings */
233 FT_FREE( info->version );
234 FT_FREE( info->notice );
235 FT_FREE( info->full_name );
236 FT_FREE( info->family_name );
237 FT_FREE( info->weight );
238
239 /* release font dictionaries */
240 FT_FREE( cid->font_dicts );
241 cid->num_dicts = 0;
242
243 /* release other strings */
244 FT_FREE( cid->cid_font_name );
245 FT_FREE( cid->registry );
246 FT_FREE( cid->ordering );
247
248 cidface->family_name = NULL;
249 cidface->style_name = NULL;
250
251 FT_FREE( face->binary_data );
252 FT_FREE( face->cid_stream );
253 }
254
255
256 /**************************************************************************
257 *
258 * @Function:
259 * cid_face_init
260 *
261 * @Description:
262 * Initializes a given CID face object.
263 *
264 * @Input:
265 * stream ::
266 * The source font stream.
267 *
268 * face_index ::
269 * The index of the font face in the resource.
270 *
271 * num_params ::
272 * Number of additional generic parameters. Ignored.
273 *
274 * params ::
275 * Additional generic parameters. Ignored.
276 *
277 * @InOut:
278 * face ::
279 * The newly built face object.
280 *
281 * @Return:
282 * FreeType error code. 0 means success.
283 */
286 FT_Face cidface, /* CID_Face */
287 FT_Int face_index,
288 FT_Int num_params,
290 {
291 CID_Face face = (CID_Face)cidface;
293 PSAux_Service psaux;
294 PSHinter_Service pshinter;
295
296 FT_UNUSED( num_params );
297 FT_UNUSED( params );
298 FT_UNUSED( stream );
299
300
301 cidface->num_faces = 1;
302
303 psaux = (PSAux_Service)face->psaux;
304 if ( !psaux )
305 {
307 FT_FACE_LIBRARY( face ), "psaux" );
308
309 if ( !psaux )
310 {
311 FT_ERROR(( "cid_face_init: cannot access `psaux' module\n" ));
312 error = FT_THROW( Missing_Module );
313 goto Exit;
314 }
315
316 face->psaux = psaux;
317 }
318
319 pshinter = (PSHinter_Service)face->pshinter;
320 if ( !pshinter )
321 {
323 FT_FACE_LIBRARY( face ), "pshinter" );
324
325 face->pshinter = pshinter;
326 }
327
328 FT_TRACE2(( "CID driver\n" ));
329
330 /* open the tokenizer; this will also check the font format */
331 if ( FT_STREAM_SEEK( 0 ) )
332 goto Exit;
333
334 error = cid_face_open( face, face_index );
335 if ( error )
336 goto Exit;
337
338 /* if we just wanted to check the format, leave successfully now */
339 if ( face_index < 0 )
340 goto Exit;
341
342 /* check the face index */
343 /* XXX: handle CID fonts with more than a single face */
344 if ( ( face_index & 0xFFFF ) != 0 )
345 {
346 FT_ERROR(( "cid_face_init: invalid face index\n" ));
347 error = FT_THROW( Invalid_Argument );
348 goto Exit;
349 }
350
351 /* now load the font program into the face object */
352
353 /* initialize the face object fields */
354
355 /* set up root face fields */
356 {
357 CID_FaceInfo cid = &face->cid;
358 PS_FontInfo info = &cid->font_info;
359
360
361 cidface->num_glyphs = (FT_Long)cid->cid_count;
362 cidface->num_charmaps = 0;
363
364 cidface->face_index = face_index & 0xFFFF;
365
366 cidface->face_flags |= FT_FACE_FLAG_SCALABLE | /* scalable outlines */
367 FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
368 FT_FACE_FLAG_HINTER; /* has native hinter */
369
370 if ( info->is_fixed_pitch )
371 cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
372
373 /* XXX: TODO: add kerning with .afm support */
374
375 /* get style name -- be careful, some broken fonts only */
376 /* have a /FontName dictionary entry! */
377 cidface->family_name = info->family_name;
378 /* assume "Regular" style if we don't know better */
379 cidface->style_name = (char *)"Regular";
380 if ( cidface->family_name )
381 {
382 char* full = info->full_name;
383 char* family = cidface->family_name;
384
385
386 if ( full )
387 {
388 while ( *full )
389 {
390 if ( *full == *family )
391 {
392 family++;
393 full++;
394 }
395 else
396 {
397 if ( *full == ' ' || *full == '-' )
398 full++;
399 else if ( *family == ' ' || *family == '-' )
400 family++;
401 else
402 {
403 if ( !*family )
404 cidface->style_name = full;
405 break;
406 }
407 }
408 }
409 }
410 }
411 else
412 {
413 /* do we have a `/FontName'? */
414 if ( cid->cid_font_name )
415 cidface->family_name = cid->cid_font_name;
416 }
417
418 /* compute style flags */
419 cidface->style_flags = 0;
420 if ( info->italic_angle )
421 cidface->style_flags |= FT_STYLE_FLAG_ITALIC;
422 if ( info->weight )
423 {
424 if ( !ft_strcmp( info->weight, "Bold" ) ||
425 !ft_strcmp( info->weight, "Black" ) )
426 cidface->style_flags |= FT_STYLE_FLAG_BOLD;
427 }
428
429 /* no embedded bitmap support */
430 cidface->num_fixed_sizes = 0;
431 cidface->available_sizes = NULL;
432
433 cidface->bbox.xMin = cid->font_bbox.xMin >> 16;
434 cidface->bbox.yMin = cid->font_bbox.yMin >> 16;
435 /* no `U' suffix here to 0xFFFF! */
436 cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFF ) >> 16;
437 cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFF ) >> 16;
438
439 if ( !cidface->units_per_EM )
440 cidface->units_per_EM = 1000;
441
442 cidface->ascender = (FT_Short)( cidface->bbox.yMax );
443 cidface->descender = (FT_Short)( cidface->bbox.yMin );
444
445 cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 );
446 if ( cidface->height < cidface->ascender - cidface->descender )
447 cidface->height = (FT_Short)( cidface->ascender - cidface->descender );
448
449 cidface->underline_position = (FT_Short)info->underline_position;
450 cidface->underline_thickness = (FT_Short)info->underline_thickness;
451 }
452
453 Exit:
454 return error;
455 }
456
457
458 /**************************************************************************
459 *
460 * @Function:
461 * cid_driver_init
462 *
463 * @Description:
464 * Initializes a given CID driver object.
465 *
466 * @Input:
467 * driver ::
468 * A handle to the target driver object.
469 *
470 * @Return:
471 * FreeType error code. 0 means success.
472 */
475 {
477
478 FT_UInt32 seed;
479
480
481 /* set default property values, cf. `ftt1drv.h' */
482#ifdef T1_CONFIG_OPTION_OLD_ENGINE
483 driver->hinting_engine = FT_HINTING_FREETYPE;
484#else
485 driver->hinting_engine = FT_HINTING_ADOBE;
486#endif
487
488 driver->no_stem_darkening = TRUE;
489
498
499 /* compute random seed from some memory addresses */
500 seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^
501 (FT_Offset)(char*)&module ^
502 (FT_Offset)(char*)module->memory );
503 seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 );
504
505 driver->random_seed = (FT_Int32)seed;
506 if ( driver->random_seed < 0 )
507 driver->random_seed = -driver->random_seed;
508 else if ( driver->random_seed == 0 )
509 driver->random_seed = 123456789;
510
511 return FT_Err_Ok;
512 }
513
514
515 /**************************************************************************
516 *
517 * @Function:
518 * cid_driver_done
519 *
520 * @Description:
521 * Finalizes a given CID driver.
522 *
523 * @Input:
524 * driver ::
525 * A handle to the target CID driver.
526 */
527 FT_LOCAL_DEF( void )
529 {
530 FT_UNUSED( driver );
531 }
532
533
534/* END */
cid_face_open(CID_Face face, FT_Int face_index)
Definition: cidload.c:766
cid_face_init(FT_Stream stream, FT_Face cidface, FT_Int face_index, FT_Int num_params, FT_Parameter *params)
Definition: cidobjs.c:285
cid_driver_init(FT_Module module)
Definition: cidobjs.c:474
cid_slot_init(FT_GlyphSlot slot)
Definition: cidobjs.c:58
cid_size_init(FT_Size cidsize)
Definition: cidobjs.c:132
cid_size_done(FT_Size cidsize)
Definition: cidobjs.c:112
cid_slot_done(FT_GlyphSlot slot)
Definition: cidobjs.c:51
cid_face_done(FT_Face cidface)
Definition: cidobjs.c:196
static PSH_Globals_Funcs cid_size_get_globals_funcs(CID_Size size)
Definition: cidobjs.c:96
cid_driver_done(FT_Module driver)
Definition: cidobjs.c:528
cid_size_request(FT_Size size, FT_Size_Request req)
Definition: cidobjs.c:157
struct CID_SizeRec_ * CID_Size
Definition: cidobjs.h:56
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
WORD face[3]
Definition: mesh.c:4747
#define FT_STYLE_FLAG_ITALIC
Definition: freetype.h:1488
#define FT_FACE_FLAG_SCALABLE
Definition: freetype.h:1210
#define FT_FACE_FLAG_HINTER
Definition: freetype.h:1221
#define FT_FACE_FLAG_FIXED_WIDTH
Definition: freetype.h:1212
#define FT_STYLE_FLAG_BOLD
Definition: freetype.h:1489
#define FT_FACE_FLAG_HORIZONTAL
Definition: freetype.h:1214
return FT_Err_Ok
Definition: ftbbox.c:527
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:387
#define FT_UNUSED(arg)
Definition: ftconfig.h:100
#define FT_LOCAL(x)
Definition: ftconfig.h:386
#define FT_ERROR(varformat)
Definition: ftdebug.h:209
#define FT_THROW(e)
Definition: ftdebug.h:241
#define FT_TRACE2(varformat)
Definition: ftdebug.h:187
#define FT_HINTING_FREETYPE
Definition: ftdriver.h:344
#define FT_HINTING_ADOBE
Definition: ftdriver.h:345
#define FT_FREE(ptr)
Definition: ftmemory.h:328
FT_Get_Module(FT_Library library, const char *module_name)
Definition: ftobjs.c:4964
#define FT_FACE_LIBRARY(x)
Definition: ftobjs.h:604
FT_Request_Metrics(FT_Face face, FT_Size_Request req)
Definition: ftobjs.c:3072
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
Definition: ftobjs.c:4992
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1
Definition: ftoption.h:813
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4
Definition: ftoption.h:823
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4
Definition: ftoption.h:822
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2
Definition: ftoption.h:816
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2
Definition: ftoption.h:817
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1
Definition: ftoption.h:814
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3
Definition: ftoption.h:819
#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3
Definition: ftoption.h:820
#define ft_strcmp
Definition: ftstdlib.h:86
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:514
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:65
int FT_Error
Definition: fttypes.h:299
signed long FT_Long
Definition: fttypes.h:242
signed short FT_Short
Definition: fttypes.h:198
size_t FT_Offset
Definition: fttypes.h:323
signed int FT_Int
Definition: fttypes.h:220
GLdouble n
Definition: glext.h:7729
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLenum const GLfloat * params
Definition: glext.h:5645
PSHinter_Interface * PSHinter_Service
Definition: pshints.h:679
typedefFT_BEGIN_HEADER struct PSH_GlobalsRec_ * PSH_Globals
Definition: pshints.h:41
if(dx< 0)
Definition: linetemp.h:194
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:116
static TfClientId cid
struct @1709::@1710 driver
FT_BEGIN_HEADER struct PS_DriverRec_ * PS_Driver
struct PSAux_ServiceRec_ * PSAux_Service
static struct __wine_debug_functions funcs
Definition: debug.c:59
static void Exit(void)
Definition: sock.c:1330
FT_FaceRec root
Definition: t1types.h:235
FT_Byte ** code
Definition: t1types.h:136
T1_Hints_Funcs(* get_t1_funcs)(FT_Module module)
Definition: pshints.h:674
Definition: vfat.h:185
Definition: parse.h:23
struct CID_FaceRec_ * CID_Face
Definition: t1types.h:200