zenilib: zenilib/jni/external/freetype2/src/cid/cidobjs.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cidobjs.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* cidobjs.c */
4 /* */
5 /* CID objects manager (body). */
6 /* */
7 /* Copyright 1996-2006, 2008, 2010-2011 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
30 #include "ciderrs.h"
31
32
33 /*************************************************************************/
34 /* */
35 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
36 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
37 /* messages during execution. */
38 /* */
39 #undef FT_COMPONENT
40 #define FT_COMPONENT trace_cidobjs
41
42
43 /*************************************************************************/
44 /* */
45 /* SLOT FUNCTIONS */
46 /* */
47 /*************************************************************************/
48
49 FT_LOCAL_DEF( void )
50 cid_slot_done( FT_GlyphSlot slot )
51 {
52 slot->internal->glyph_hints = 0;
53 }
54
55
56 FT_LOCAL_DEF( FT_Error )
57 cid_slot_init( FT_GlyphSlot slot )
58 {
59 CID_Face face;
60 PSHinter_Service pshinter;
61
62
63 face = (CID_Face)slot->face;
64 pshinter = (PSHinter_Service)face->pshinter;
65
66 if ( pshinter )
67 {
68 FT_Module module;
69
70
71 module = FT_Get_Module( slot->face->driver->root.library,
72 "pshinter" );
73 if ( module )
74 {
75 T1_Hints_Funcs funcs;
76
77
78 funcs = pshinter->get_t1_funcs( module );
79 slot->internal->glyph_hints = (void*)funcs;
80 }
81 }
82
83 return 0;
84 }
85
86
87 /*************************************************************************/
88 /* */
89 /* SIZE FUNCTIONS */
90 /* */
91 /*************************************************************************/
92
93
94 static PSH_Globals_Funcs
95 cid_size_get_globals_funcs( CID_Size size )
96 {
97 CID_Face face = (CID_Face)size->root.face;
98 PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
99 FT_Module module;
100
101
102 module = FT_Get_Module( size->root.face->driver->root.library,
103 "pshinter" );
104 return ( module && pshinter && pshinter->get_globals_funcs )
105 ? pshinter->get_globals_funcs( module )
106 : 0;
107 }
108
109
110 FT_LOCAL_DEF( void )
111 cid_size_done( FT_Size cidsize ) /* CID_Size */
112 {
113 CID_Size size = (CID_Size)cidsize;
114
115
116 if ( cidsize->internal )
117 {
118 PSH_Globals_Funcs funcs;
119
120
121 funcs = cid_size_get_globals_funcs( size );
122 if ( funcs )
123 funcs->destroy( (PSH_Globals)cidsize->internal );
124
125 cidsize->internal = 0;
126 }
127 }
128
129
130 FT_LOCAL_DEF( FT_Error )
131 cid_size_init( FT_Size cidsize ) /* CID_Size */
132 {
133 CID_Size size = (CID_Size)cidsize;
134 FT_Error error = CID_Err_Ok;
135 PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
136
137
138 if ( funcs )
139 {
140 PSH_Globals globals;
141 CID_Face face = (CID_Face)cidsize->face;
142 CID_FaceDict dict = face->cid.font_dicts + face->root.face_index;
143 PS_Private priv = &dict->private_dict;
144
145
146 error = funcs->create( cidsize->face->memory, priv, &globals );
147 if ( !error )
148 cidsize->internal = (FT_Size_Internal)(void*)globals;
149 }
150
151 return error;
152 }
153
154
155 FT_LOCAL( FT_Error )
156 cid_size_request( FT_Size size,
157 FT_Size_Request req )
158 {
159 PSH_Globals_Funcs funcs;
160
161
162 FT_Request_Metrics( size->face, req );
163
164 funcs = cid_size_get_globals_funcs( (CID_Size)size );
165
166 if ( funcs )
167 funcs->set_scale( (PSH_Globals)size->internal,
168 size->metrics.x_scale,
169 size->metrics.y_scale,
170 0, 0 );
171
172 return CID_Err_Ok;
173 }
174
175
176 /*************************************************************************/
177 /* */
178 /* FACE FUNCTIONS */
179 /* */
180 /*************************************************************************/
181
182 /*************************************************************************/
183 /* */
184 /* <Function> */
185 /* cid_face_done */
186 /* */
187 /* <Description> */
188 /* Finalizes a given face object. */
189 /* */
190 /* <Input> */
191 /* face :: A pointer to the face object to destroy. */
192 /* */
193 FT_LOCAL_DEF( void )
194 cid_face_done( FT_Face cidface ) /* CID_Face */
195 {
196 CID_Face face = (CID_Face)cidface;
197 FT_Memory memory;
198 CID_FaceInfo cid;
199 PS_FontInfo info;
200
201
202 if ( !face )
203 return;
204
205 cid = &face->cid;
206 info = &cid->font_info;
207 memory = cidface->memory;
208
209 /* release subrs */
210 if ( face->subrs )
211 {
212 FT_Int n;
213
214
215 for ( n = 0; n < cid->num_dicts; n++ )
216 {
217 CID_Subrs subr = face->subrs + n;
218
219
220 if ( subr->code )
221 {
222 FT_FREE( subr->code[0] );
223 FT_FREE( subr->code );
224 }
225 }
226
227 FT_FREE( face->subrs );
228 }
229
230 /* release FontInfo strings */
231 FT_FREE( info->version );
232 FT_FREE( info->notice );
233 FT_FREE( info->full_name );
234 FT_FREE( info->family_name );
235 FT_FREE( info->weight );
236
237 /* release font dictionaries */
238 FT_FREE( cid->font_dicts );
239 cid->num_dicts = 0;
240
241 /* release other strings */
242 FT_FREE( cid->cid_font_name );
243 FT_FREE( cid->registry );
244 FT_FREE( cid->ordering );
245
246 cidface->family_name = 0;
247 cidface->style_name = 0;
248
249 FT_FREE( face->binary_data );
250 FT_FREE( face->cid_stream );
251 }
252
253
254 /*************************************************************************/
255 /* */
256 /* <Function> */
257 /* cid_face_init */
258 /* */
259 /* <Description> */
260 /* Initializes a given CID face object. */
261 /* */
262 /* <Input> */
263 /* stream :: The source font stream. */
264 /* */
265 /* face_index :: The index of the font face in the resource. */
266 /* */
267 /* num_params :: Number of additional generic parameters. Ignored. */
268 /* */
269 /* params :: Additional generic parameters. Ignored. */
270 /* */
271 /* <InOut> */
272 /* face :: The newly built face object. */
273 /* */
274 /* <Return> */
275 /* FreeType error code. 0 means success. */
276 /* */
277 FT_LOCAL_DEF( FT_Error )
278 cid_face_init( FT_Stream stream,
279 FT_Face cidface, /* CID_Face */
280 FT_Int face_index,
281 FT_Int num_params,
282 FT_Parameter* params )
283 {
284 CID_Face face = (CID_Face)cidface;
285 FT_Error error;
286 PSAux_Service psaux;
287 PSHinter_Service pshinter;
288
289 FT_UNUSED( num_params );
290 FT_UNUSED( params );
291 FT_UNUSED( stream );
292
293
294 cidface->num_faces = 1;
295
296 psaux = (PSAux_Service)face->psaux;
297 if ( !psaux )
298 {
299 psaux = (PSAux_Service)FT_Get_Module_Interface(
300 FT_FACE_LIBRARY( face ), "psaux" );
301
302 if ( !psaux )
303 {
304 FT_ERROR(( "cid_face_init: cannot access `psaux' module\n" ));
305 error = CID_Err_Missing_Module;
306 goto Exit;
307 }
308
309 face->psaux = psaux;
310 }
311
312 pshinter = (PSHinter_Service)face->pshinter;
313 if ( !pshinter )
314 {
315 pshinter = (PSHinter_Service)FT_Get_Module_Interface(
316 FT_FACE_LIBRARY( face ), "pshinter" );
317
318 face->pshinter = pshinter;
319 }
320
321 FT_TRACE2(( "CID driver\n" ));
322
323 /* open the tokenizer; this will also check the font format */
324 if ( FT_STREAM_SEEK( 0 ) )
325 goto Exit;
326
327 error = cid_face_open( face, face_index );
328 if ( error )
329 goto Exit;
330
331 /* if we just wanted to check the format, leave successfully now */
332 if ( face_index < 0 )
333 goto Exit;
334
335 /* check the face index */
336 /* XXX: handle CID fonts with more than a single face */
337 if ( face_index != 0 )
338 {
339 FT_ERROR(( "cid_face_init: invalid face index\n" ));
340 error = CID_Err_Invalid_Argument;
341 goto Exit;
342 }
343
344 /* now load the font program into the face object */
345
346 /* initialize the face object fields */
347
348 /* set up root face fields */
349 {
350 CID_FaceInfo cid = &face->cid;
351 PS_FontInfo info = &cid->font_info;
352
353
354 cidface->num_glyphs = cid->cid_count;
355 cidface->num_charmaps = 0;
356
357 cidface->face_index = face_index;
358 cidface->face_flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */
359 FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
360 FT_FACE_FLAG_HINTER; /* has native hinter */
361
362 if ( info->is_fixed_pitch )
363 cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
364
365 /* XXX: TODO: add kerning with .afm support */
366
367 /* get style name -- be careful, some broken fonts only */
368 /* have a /FontName dictionary entry! */
369 cidface->family_name = info->family_name;
370 /* assume "Regular" style if we don't know better */
371 cidface->style_name = (char *)"Regular";
372 if ( cidface->family_name )
373 {
374 char* full = info->full_name;
375 char* family = cidface->family_name;
376
377
378 if ( full )
379 {
380 while ( *full )
381 {
382 if ( *full == *family )
383 {
384 family++;
385 full++;
386 }
387 else
388 {
389 if ( *full == ' ' || *full == '-' )
390 full++;
391 else if ( *family == ' ' || *family == '-' )
392 family++;
393 else
394 {
395 if ( !*family )
396 cidface->style_name = full;
397 break;
398 }
399 }
400 }
401 }
402 }
403 else
404 {
405 /* do we have a `/FontName'? */
406 if ( cid->cid_font_name )
407 cidface->family_name = cid->cid_font_name;
408 }
409
410 /* compute style flags */
411 cidface->style_flags = 0;
412 if ( info->italic_angle )
413 cidface->style_flags |= FT_STYLE_FLAG_ITALIC;
414 if ( info->weight )
415 {
416 if ( !ft_strcmp( info->weight, "Bold" ) ||
417 !ft_strcmp( info->weight, "Black" ) )
418 cidface->style_flags |= FT_STYLE_FLAG_BOLD;
419 }
420
421 /* no embedded bitmap support */
422 cidface->num_fixed_sizes = 0;
423 cidface->available_sizes = 0;
424
425 cidface->bbox.xMin = cid->font_bbox.xMin >> 16;
426 cidface->bbox.yMin = cid->font_bbox.yMin >> 16;
427 /* no `U' suffix here to 0xFFFF! */
428 cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFF ) >> 16;
429 cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFF ) >> 16;
430
431 if ( !cidface->units_per_EM )
432 cidface->units_per_EM = 1000;
433
434 cidface->ascender = (FT_Short)( cidface->bbox.yMax );
435 cidface->descender = (FT_Short)( cidface->bbox.yMin );
436
437 cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 );
438 if ( cidface->height < cidface->ascender - cidface->descender )
439 cidface->height = (FT_Short)( cidface->ascender - cidface->descender );
440
441 cidface->underline_position = (FT_Short)info->underline_position;
442 cidface->underline_thickness = (FT_Short)info->underline_thickness;
443 }
444
445 Exit:
446 return error;
447 }
448
449
450 /*************************************************************************/
451 /* */
452 /* <Function> */
453 /* cid_driver_init */
454 /* */
455 /* <Description> */
456 /* Initializes a given CID driver object. */
457 /* */
458 /* <Input> */
459 /* driver :: A handle to the target driver object. */
460 /* */
461 /* <Return> */
462 /* FreeType error code. 0 means success. */
463 /* */
464 FT_LOCAL_DEF( FT_Error )
465 cid_driver_init( FT_Module driver )
466 {
467 FT_UNUSED( driver );
468
469 return CID_Err_Ok;
470 }
471
472
473 /*************************************************************************/
474 /* */
475 /* <Function> */
476 /* cid_driver_done */
477 /* */
478 /* <Description> */
479 /* Finalizes a given CID driver. */
480 /* */
481 /* <Input> */
482 /* driver :: A handle to the target CID driver. */
483 /* */
484 FT_LOCAL_DEF( void )
485 cid_driver_done( FT_Module driver )
486 {
487 FT_UNUSED( driver );
488 }
489
490
491 /* END */
PSH_Globals_FuncsRec_::set_scale
PSH_Globals_SetScaleFunc set_scale
Definition: pshints.h:62
PSH_Globals
typedefFT_BEGIN_HEADER struct PSH_GlobalsRec_ * PSH_Globals
Definition: pshints.h:41
FT_SizeRec_::face
FT_Face face
Definition: freetype.h:1397
FT_SizeRec_
Definition: freetype.h:1395
FT_Error
int FT_Error
Definition: fttypes.h:296
CID_FaceInfoRec_::font_dicts
CID_FaceDict font_dicts
Definition: t1tables.h:374
CID_FaceInfoRec_::registry
FT_String * registry
Definition: t1tables.h:357
CID_Face
struct CID_FaceRec_ * CID_Face
Definition: t1types.h:195
CID_FaceRec_::psaux
void * psaux
Definition: t1types.h:236
FT_GlyphSlotRec_
Definition: freetype.h:1605
T1_Hints_FuncsRec_
Definition: pshints.h:342
FT_ModuleRec_
Definition: ftobjs.h:439
PSHinter_Interface_
Definition: pshints.h:672
FT_Int
signed int FT_Int
Definition: fttypes.h:216
CID_SizeRec_::root
FT_SizeRec root
Definition: cidobjs.h:95
FT_FaceRec_::face_index
FT_Long face_index
Definition: freetype.h:915
PSHinter_Service
PSHinter_Interface * PSHinter_Service
Definition: pshints.h:680
stream
GLuint GLuint stream
Definition: glew.h:6573
n
GLclampd n
Definition: glew.h:7287
FT_FACE_FLAG_SCALABLE
#define FT_FACE_FLAG_SCALABLE
Definition: freetype.h:1069
FT_ModuleRec_::library
FT_Library library
Definition: ftobjs.h:442
cid_driver_init
cid_driver_init(FT_Module driver)
Definition: cidobjs.c:465
CID_FaceInfoRec_::num_dicts
FT_Int num_dicts
Definition: t1tables.h:373
cid_size_done
cid_size_done(FT_Size cidsize)
Definition: cidobjs.c:111
PSH_Globals_FuncsRec_::create
PSH_Globals_NewFunc create
Definition: pshints.h:61
CID_FaceRec_::cid_stream
FT_Stream cid_stream
Definition: t1types.h:249
PS_FontInfoRec_::italic_angle
FT_Long italic_angle
Definition: t1tables.h:76
CID_FaceInfoRec_
Definition: t1tables.h:351
FT_Size_Internal
struct FT_Size_InternalRec_ * FT_Size_Internal
Definition: freetype.h:1302
PSH_Globals_FuncsRec_::destroy
PSH_Globals_DestroyFunc destroy
Definition: pshints.h:63
if
if(!yyg->yy_init)
Definition: glslang_lex.cpp:1037
CID_FaceRec_
Definition: t1types.h:232
cid_size_get_globals_funcs
static PSH_Globals_Funcs cid_size_get_globals_funcs(CID_Size size)
Definition: cidobjs.c:95
PSHinter_Interface_::get_t1_funcs
T1_Hints_Funcs(* get_t1_funcs)(FT_Module module)
Definition: pshints.h:675
FT_ERROR
#define FT_ERROR(varformat)
Definition: ftdebug.h:181
cid_driver_done
cid_driver_done(FT_Module driver)
Definition: cidobjs.c:485
FT_STYLE_FLAG_BOLD
#define FT_STYLE_FLAG_BOLD
Definition: freetype.h:1290
params
GLenum GLvoid ** params
Definition: gl2ext.h:806
CID_FaceInfoRec_::cid_font_name
FT_String * cid_font_name
Definition: t1tables.h:353
CID_FaceInfoRec_::font_bbox
FT_BBox font_bbox
Definition: t1tables.h:362
PS_FontInfoRec_::notice
FT_String * notice
Definition: t1tables.h:72
PS_PrivateRec_
Definition: t1tables.h:118
CID_SizeRec_
Definition: cidobjs.h:93
FT_LOCAL
#define FT_LOCAL(x)
Definition: ftconfig.h:466
CID_SubrsRec_::code
FT_Byte ** code
Definition: t1types.h:131
CID_FaceRec_::root
FT_FaceRec root
Definition: t1types.h:234
FT_FREE
#define FT_FREE(ptr)
Definition: ftmemory.h:286
FT_FACE_FLAG_FIXED_WIDTH
#define FT_FACE_FLAG_FIXED_WIDTH
Definition: freetype.h:1071
FT_BBox_::yMax
FT_Pos yMax
Definition: ftimage.h:119
FT_LOCAL_DEF
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:467
cid_face_done
cid_face_done(FT_Face cidface)
Definition: cidobjs.c:194
FT_BBox_::xMin
FT_Pos xMin
Definition: ftimage.h:118
FT_DriverRec_::root
FT_ModuleRec root
Definition: ftobjs.h:717
CID_SubrsRec_
Definition: t1types.h:128
CID_FaceInfoRec_::cid_count
FT_ULong cid_count
Definition: t1tables.h:371
FT_Request_Metrics
FT_Request_Metrics(FT_Face face, FT_Size_Request req)
Definition: ftobjs.c:2637
FT_FaceRec_
Definition: freetype.h:912
error
FT_Error error
Definition: cffdrivr.c:407
face
GLenum face
Definition: gl2ext.h:1490
FT_FACE_FLAG_HORIZONTAL
#define FT_FACE_FLAG_HORIZONTAL
Definition: freetype.h:1073
FT_Size_RequestRec_
Definition: freetype.h:2185
PSAux_Service
struct PSAux_ServiceRec_ * PSAux_Service
PS_FontInfoRec_::family_name
FT_String * family_name
Definition: t1tables.h:74
cid_face_init
cid_face_init(FT_Stream stream, FT_Face cidface, FT_Int face_index, FT_Int num_params, FT_Parameter *params)
Definition: cidobjs.c:278
FT_TRACE2
#define FT_TRACE2(varformat)
Definition: ftdebug.h:159
CID_FaceDictRec_
Definition: t1tables.h:305
cidload.h
PS_FontInfoRec_::underline_position
FT_Short underline_position
Definition: t1tables.h:78
CID_FaceInfoRec_::ordering
FT_String * ordering
Definition: t1tables.h:358
PS_FontInfoRec_
Definition: t1tables.h:69
CID_FaceInfoRec_::font_info
PS_FontInfoRec font_info
Definition: t1tables.h:361
ciderrs.h
cid_face_open
cid_face_open(CID_Face face, FT_Int face_index)
Definition: cidload.c:635
CID_FaceRec_::subrs
CID_Subrs subrs
Definition: t1types.h:242
FT_BBox_::xMax
FT_Pos xMax
Definition: ftimage.h:119
FT_Short
signed short FT_Short
Definition: fttypes.h:194
FT_Memory
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
FT_FACE_FLAG_HINTER
#define FT_FACE_FLAG_HINTER
Definition: freetype.h:1080
FT_STREAM_SEEK
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:496
CID_FaceRec_::cid
CID_FaceInfoRec cid
Definition: t1types.h:237
ft2build.h
PS_FontInfoRec_::version
FT_String * version
Definition: t1tables.h:71
PS_FontInfoRec_::full_name
FT_String * full_name
Definition: t1tables.h:73
CID_FaceRec_::pshinter
void * pshinter
Definition: t1types.h:245
PSH_Globals_FuncsRec_
Definition: pshints.h:59
PS_FontInfoRec_::underline_thickness
FT_UShort underline_thickness
Definition: t1tables.h:79
PS_FontInfoRec_::weight
FT_String * weight
Definition: t1tables.h:75
cid_slot_done
cid_slot_done(FT_GlyphSlot slot)
Definition: cidobjs.c:50
cid_size_request
cid_size_request(FT_Size size, FT_Size_Request req)
Definition: cidobjs.c:156
CID_Size
struct CID_SizeRec_ * CID_Size
Definition: cidobjs.h:56
FT_Get_Module
FT_Get_Module(FT_Library library, const char *module_name)
Definition: ftobjs.c:4256
cid_size_init
cid_size_init(FT_Size cidsize)
Definition: cidobjs.c:131
PS_FontInfoRec_::is_fixed_pitch
FT_Bool is_fixed_pitch
Definition: t1tables.h:77
cidgload.h
FT_FaceRec_::driver
FT_Driver driver
Definition: freetype.h:955
FT_Get_Module_Interface
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
Definition: ftobjs.c:4284
cid_slot_init
cid_slot_init(FT_GlyphSlot slot)
Definition: cidobjs.c:57
FT_STYLE_FLAG_ITALIC
#define FT_STYLE_FLAG_ITALIC
Definition: freetype.h:1289
FT_FACE_LIBRARY
#define FT_FACE_LIBRARY(x)
Definition: ftobjs.h:528
FT_StreamRec_
Definition: ftsystem.h:321
FT_BBox_::yMin
FT_Pos yMin
Definition: ftimage.h:118
PSAux_ServiceRec_
Definition: psaux.h:794
FT_UNUSED
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
FT_Parameter_
Definition: freetype.h:1763
ft_strcmp
#define ft_strcmp
Definition: ftstdlib.h:85
CID_FaceRec_::binary_data
FT_Byte * binary_data
Definition: t1types.h:248
size
GLsizei size
Definition: gl2ext.h:1467