ReactOS 0.4.16-dev-2354-g16de117
cidgload.c File Reference
Include dependency graph for cidgload.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   cidgload
 

Functions

 cid_load_glyph (T1_Decoder decoder, FT_UInt glyph_index)
 
 cid_slot_load_glyph (FT_GlyphSlot cidglyph, FT_Size cidsize, FT_UInt glyph_index, FT_Int32 load_flags)
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   cidgload

Definition at line 40 of file cidgload.c.

Function Documentation

◆ cid_load_glyph()

cid_load_glyph ( T1_Decoder  decoder,
FT_UInt  glyph_index 
)

Definition at line 44 of file cidgload.c.

46 {
47 CID_Face face = (CID_Face)decoder->builder.face;
48 CID_FaceInfo cid = &face->cid;
49 FT_Byte* p;
50 FT_ULong fd_select;
51 FT_Stream stream = face->cid_stream;
53 FT_Byte* charstring = NULL;
54 FT_Memory memory = face->root.memory;
55 FT_ULong glyph_length = 0;
56 PSAux_Service psaux = (PSAux_Service)face->psaux;
57
58 FT_Bool force_scaling = FALSE;
59
60#ifdef FT_CONFIG_OPTION_INCREMENTAL
62 face->root.internal->incremental_interface;
63#endif
64
65
66 FT_TRACE1(( "cid_load_glyph: glyph index %d\n", glyph_index ));
67
68#ifdef FT_CONFIG_OPTION_INCREMENTAL
69
70 /* For incremental fonts get the character data using */
71 /* the callback function. */
72 if ( inc )
73 {
74 FT_Data glyph_data;
75
76
77 error = inc->funcs->get_glyph_data( inc->object,
78 glyph_index, &glyph_data );
79 if ( error )
80 goto Exit;
81
82 p = (FT_Byte*)glyph_data.pointer;
83 fd_select = cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
84
85 if ( glyph_data.length != 0 )
86 {
87 glyph_length = (FT_ULong)( glyph_data.length - cid->fd_bytes );
88 (void)FT_ALLOC( charstring, glyph_length );
89 if ( !error )
90 ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes,
91 glyph_length );
92 }
93
94 inc->funcs->free_glyph_data( inc->object, &glyph_data );
95
96 if ( error )
97 goto Exit;
98 }
99
100 else
101
102#endif /* FT_CONFIG_OPTION_INCREMENTAL */
103
104 /* For ordinary fonts read the CID font dictionary index */
105 /* and charstring offset from the CIDMap. */
106 {
107 FT_UInt entry_len = (FT_UInt)( cid->fd_bytes + cid->gd_bytes );
108 FT_ULong off1, off2;
109
110
111 if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset +
112 glyph_index * entry_len ) ||
113 FT_FRAME_ENTER( 2 * entry_len ) )
114 goto Exit;
115
116 p = (FT_Byte*)stream->cursor;
117 fd_select = cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
118 off1 = cid_get_offset( &p, (FT_Byte)cid->gd_bytes );
119 p += cid->fd_bytes;
120 off2 = cid_get_offset( &p, (FT_Byte)cid->gd_bytes );
122
123 if ( fd_select >= (FT_ULong)cid->num_dicts ||
124 off2 > stream->size ||
125 off1 > off2 )
126 {
127 FT_TRACE0(( "cid_load_glyph: invalid glyph stream offsets\n" ));
128 error = FT_THROW( Invalid_Offset );
129 goto Exit;
130 }
131
132 glyph_length = off2 - off1;
133 if ( glyph_length == 0 )
134 goto Exit;
135 if ( FT_ALLOC( charstring, glyph_length ) )
136 goto Exit;
137 if ( FT_STREAM_READ_AT( cid->data_offset + off1,
138 charstring, glyph_length ) )
139 goto Exit;
140 }
141
142 /* Now set up the subrs array and parse the charstrings. */
143 {
144 CID_FaceDict dict;
145 CID_Subrs cid_subrs = face->subrs + fd_select;
146 FT_UInt cs_offset;
147
148
149 /* Set up subrs */
150 decoder->num_subrs = cid_subrs->num_subrs;
151 decoder->subrs = cid_subrs->code;
152 decoder->subrs_len = 0;
153 decoder->subrs_hash = NULL;
154
155 /* Set up font matrix */
156 dict = cid->font_dicts + fd_select;
157
158 decoder->font_matrix = dict->font_matrix;
159 decoder->font_offset = dict->font_offset;
160 decoder->lenIV = dict->private_dict.lenIV;
161
162 /* Decode the charstring. */
163
164 /* Adjustment for seed bytes. */
165 cs_offset = decoder->lenIV >= 0 ? (FT_UInt)decoder->lenIV : 0;
166 if ( cs_offset > glyph_length )
167 {
168 FT_TRACE0(( "cid_load_glyph: invalid glyph stream offsets\n" ));
169 error = FT_THROW( Invalid_Offset );
170 goto Exit;
171 }
172
173 /* Decrypt only if lenIV >= 0. */
174 if ( decoder->lenIV >= 0 )
175 psaux->t1_decrypt( charstring, glyph_length, 4330 );
176
177 /* choose which renderer to use */
178#ifdef T1_CONFIG_OPTION_OLD_ENGINE
179 if ( ( (PS_Driver)FT_FACE_DRIVER( face ) )->hinting_engine ==
181 decoder->builder.metrics_only )
182 error = psaux->t1_decoder_funcs->parse_charstrings_old(
183 decoder,
184 charstring + cs_offset,
185 glyph_length - cs_offset );
186#else
187 if ( decoder->builder.metrics_only )
188 error = psaux->t1_decoder_funcs->parse_metrics(
189 decoder,
190 charstring + cs_offset,
191 glyph_length - cs_offset );
192#endif
193 else
194 {
195 PS_Decoder psdecoder;
196 CFF_SubFontRec subfont;
197
198
199 psaux->ps_decoder_init( &psdecoder, decoder, TRUE );
200
201 psaux->t1_make_subfont( FT_FACE( face ),
202 &dict->private_dict,
203 &subfont );
204 psdecoder.current_subfont = &subfont;
205
206 error = psaux->t1_decoder_funcs->parse_charstrings(
207 &psdecoder,
208 charstring + cs_offset,
209 glyph_length - cs_offset );
210
211 /* Adobe's engine uses 16.16 numbers everywhere; */
212 /* as a consequence, glyphs larger than 2000ppem get rejected */
213 if ( FT_ERR_EQ( error, Glyph_Too_Big ) )
214 {
215 /* this time, we retry unhinted and scale up the glyph later on */
216 /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */
217 /* 0x400 for both `x_scale' and `y_scale' in this case) */
218 ((CID_GlyphSlot)decoder->builder.glyph)->hint = FALSE;
219
220 force_scaling = TRUE;
221
222 error = psaux->t1_decoder_funcs->parse_charstrings(
223 &psdecoder,
224 charstring + cs_offset,
225 glyph_length - cs_offset );
226 }
227 }
228 }
229
230#ifdef FT_CONFIG_OPTION_INCREMENTAL
231
232 /* Incremental fonts can optionally override the metrics. */
233 if ( !error && inc && inc->funcs->get_glyph_metrics )
234 {
236
237
238 metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x );
239 metrics.bearing_y = 0;
240 metrics.advance = FIXED_TO_INT( decoder->builder.advance.x );
241 metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y );
242
243 error = inc->funcs->get_glyph_metrics( inc->object,
244 glyph_index, FALSE, &metrics );
245
246 decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x );
247 decoder->builder.advance.x = INT_TO_FIXED( metrics.advance );
248 decoder->builder.advance.y = INT_TO_FIXED( metrics.advance_v );
249 }
250
251#endif /* FT_CONFIG_OPTION_INCREMENTAL */
252
253 Exit:
254 FT_FREE( charstring );
255
256 ((CID_GlyphSlot)decoder->builder.glyph)->scaled = force_scaling;
257
258 return error;
259 }
cid_get_offset(FT_Byte **start, FT_Byte offsize)
Definition: cidload.c:43
struct CID_GlyphSlotRec_ * CID_GlyphSlot
Definition: cidobjs.h:67
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
return FT_Err_Ok
Definition: ftbbox.c:526
#define FIXED_TO_INT(x)
Definition: ftcalc.h:450
#define INT_TO_FIXED(x)
Definition: ftcalc.h:448
#define FT_TRACE0(varformat)
Definition: ftdebug.h:187
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_TRACE1(varformat)
Definition: ftdebug.h:188
#define FT_HINTING_FREETYPE
Definition: ftdriver.h:343
#define FT_ALLOC(ptr, size)
Definition: ftmemory.h:311
#define FT_FREE(ptr)
Definition: ftmemory.h:337
#define FT_FACE(x)
Definition: ftobjs.h:597
#define FT_FACE_DRIVER(x)
Definition: ftobjs.h:601
#define ft_memcpy
Definition: ftstdlib.h:82
#define FT_FRAME_ENTER(size)
Definition: ftstream.h:548
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:525
#define FT_FRAME_EXIT()
Definition: ftstream.h:553
#define FT_STREAM_READ_AT(position, buffer, count)
Definition: ftstream.h:538
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
unsigned long FT_ULong
Definition: fttypes.h:253
unsigned char FT_Byte
Definition: fttypes.h:154
#define FT_ERR_EQ(x, e)
Definition: fttypes.h:604
int FT_Error
Definition: fttypes.h:299
unsigned int FT_UInt
Definition: fttypes.h:231
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLsizei GLenum const GLvoid GLuint GLsizei GLfloat * metrics
Definition: glext.h:11745
GLfloat GLfloat p
Definition: glext.h:8902
static TfClientId cid
if(dx< 0)
Definition: linetemp.h:194
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:122
FT_BEGIN_HEADER struct PS_DriverRec_ * PS_Driver
static void Exit(void)
Definition: sock.c:1330
PS_PrivateRec private_dict
Definition: t1tables.h:349
FT_Matrix font_matrix
Definition: t1tables.h:358
FT_Vector font_offset
Definition: t1tables.h:359
FT_Byte ** code
Definition: t1types.h:135
FT_Int num_subrs
Definition: t1types.h:134
const FT_Byte * pointer
Definition: fttypes.h:415
FT_Int length
Definition: fttypes.h:416
FT_Incremental_FreeGlyphDataFunc free_glyph_data
Definition: ftincrem.h:273
FT_Incremental_GetGlyphDataFunc get_glyph_data
Definition: ftincrem.h:272
FT_Incremental_GetGlyphMetricsFunc get_glyph_metrics
Definition: ftincrem.h:274
const FT_Incremental_FuncsRec * funcs
Definition: ftincrem.h:317
CFF_SubFont current_subfont
Definition: psaux.h:645
FT_Int lenIV
Definition: t1tables.h:139
Definition: parse.h:23
unsigned int size
Definition: parse.h:27
struct CID_FaceRec_ * CID_Face
Definition: t1types.h:199

Referenced by cid_slot_load_glyph().

◆ cid_slot_load_glyph()

cid_slot_load_glyph ( FT_GlyphSlot  cidglyph,
FT_Size  cidsize,
FT_UInt  glyph_index,
FT_Int32  load_flags 
)

Definition at line 357 of file cidgload.c.

361 {
362 CID_GlyphSlot glyph = (CID_GlyphSlot)cidglyph;
364#ifdef __REACTOS__
365 T1_DecoderRec *decoder_allocated = malloc(sizeof(*decoder_allocated));
366 if (!decoder_allocated) return FT_Err_Out_Of_Memory;
367/* Ugly but it allows us to reduce the diff */
368#define decoder (*decoder_allocated)
369 {
370#else
372#endif
373 CID_Face face = (CID_Face)cidglyph->face;
374 FT_Bool hinting;
375 FT_Bool scaled;
376
377 PSAux_Service psaux = (PSAux_Service)face->psaux;
378 FT_Matrix font_matrix;
379 FT_Vector font_offset;
380 FT_Bool must_finish_decoder = FALSE;
381
382
383 if ( glyph_index >= (FT_UInt)face->root.num_glyphs )
384 {
385 error = FT_THROW( Invalid_Argument );
386 goto Exit;
387 }
388
389 if ( load_flags & FT_LOAD_NO_RECURSE )
390 load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
391
392 glyph->x_scale = cidsize->metrics.x_scale;
393 glyph->y_scale = cidsize->metrics.y_scale;
394
395 cidglyph->outline.n_points = 0;
396 cidglyph->outline.n_contours = 0;
397
398 hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 &&
399 ( load_flags & FT_LOAD_NO_HINTING ) == 0 );
400 scaled = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 );
401
402 glyph->hint = hinting;
403 glyph->scaled = scaled;
404 cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
405
406 error = psaux->t1_decoder_funcs->init( &decoder,
407 cidglyph->face,
408 cidsize,
409 cidglyph,
410 0, /* glyph names -- XXX */
411 0, /* blend == 0 */
412 hinting,
413 FT_LOAD_TARGET_MODE( load_flags ),
415 if ( error )
416 goto Exit;
417
418 /* TODO: initialize decoder.len_buildchar and decoder.buildchar */
419 /* if we ever support CID-keyed multiple master fonts */
420
421 must_finish_decoder = TRUE;
422
423 /* set up the decoder */
424 decoder.builder.no_recurse = FT_BOOL( load_flags & FT_LOAD_NO_RECURSE );
425
426 error = cid_load_glyph( &decoder, glyph_index );
427 if ( error )
428 goto Exit;
429
430 /* copy flags back for forced scaling */
431 hinting = glyph->hint;
432 scaled = glyph->scaled;
433
434 font_matrix = decoder.font_matrix;
435 font_offset = decoder.font_offset;
436
437 /* save new glyph tables */
438 psaux->t1_decoder_funcs->done( &decoder );
439
440 must_finish_decoder = FALSE;
441
442 /* now set the metrics -- this is rather simple, as */
443 /* the left side bearing is the xMin, and the top side */
444 /* bearing the yMax */
445 cidglyph->outline.flags &= FT_OUTLINE_OWNER;
447
448 /* for composite glyphs, return only left side bearing and */
449 /* advance width */
450 if ( load_flags & FT_LOAD_NO_RECURSE )
451 {
453
454
455 cidglyph->metrics.horiBearingX =
456 FIXED_TO_INT( decoder.builder.left_bearing.x );
457 cidglyph->metrics.horiAdvance =
458 FIXED_TO_INT( decoder.builder.advance.x );
459
460 internal->glyph_matrix = font_matrix;
461 internal->glyph_delta = font_offset;
462 internal->glyph_transformed = 1;
463 }
464 else
465 {
466 FT_BBox cbox;
467 FT_Glyph_Metrics* metrics = &cidglyph->metrics;
468
469
470 /* copy the _unscaled_ advance width */
471 metrics->horiAdvance =
472 FIXED_TO_INT( decoder.builder.advance.x );
473 cidglyph->linearHoriAdvance =
474 FIXED_TO_INT( decoder.builder.advance.x );
475 cidglyph->internal->glyph_transformed = 0;
476
477 /* make up vertical ones */
478 metrics->vertAdvance = ( face->cid.font_bbox.yMax -
479 face->cid.font_bbox.yMin ) >> 16;
480 cidglyph->linearVertAdvance = metrics->vertAdvance;
481
482 cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
483
484 if ( cidsize->metrics.y_ppem < 24 )
486
487 /* apply the font matrix, if any */
488 if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L ||
489 font_matrix.xy != 0 || font_matrix.yx != 0 )
490 {
491 FT_Outline_Transform( &cidglyph->outline, &font_matrix );
492
493 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance,
494 font_matrix.xx );
495 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance,
496 font_matrix.yy );
497 }
498
499 if ( font_offset.x || font_offset.y )
500 {
501 FT_Outline_Translate( &cidglyph->outline,
502 font_offset.x,
503 font_offset.y );
504
505 metrics->horiAdvance += font_offset.x;
506 metrics->vertAdvance += font_offset.y;
507 }
508
509 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || scaled )
510 {
511 /* scale the outline and the metrics */
512 FT_Int n;
513 FT_Outline* cur = decoder.builder.base;
514 FT_Vector* vec = cur->points;
515 FT_Fixed x_scale = glyph->x_scale;
516 FT_Fixed y_scale = glyph->y_scale;
517
518
519 /* First of all, scale the points */
520 if ( !hinting || !decoder.builder.hints_funcs )
521 for ( n = cur->n_points; n > 0; n--, vec++ )
522 {
523 vec->x = FT_MulFix( vec->x, x_scale );
524 vec->y = FT_MulFix( vec->y, y_scale );
525 }
526
527 /* Then scale the metrics */
528 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
529 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
530 }
531
532 /* compute the other metrics */
533 FT_Outline_Get_CBox( &cidglyph->outline, &cbox );
534
535 metrics->width = cbox.xMax - cbox.xMin;
536 metrics->height = cbox.yMax - cbox.yMin;
537
538 metrics->horiBearingX = cbox.xMin;
539 metrics->horiBearingY = cbox.yMax;
540
541 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
542 {
543 /* make up vertical ones */
545 metrics->vertAdvance );
546 }
547 }
548
549 Exit:
550
551 if ( must_finish_decoder )
552 psaux->t1_decoder_funcs->done( &decoder );
553
554#ifdef __REACTOS__
555 free(decoder_allocated);
556#undef decoder
557 }
558#endif
559 return error;
560 }
ios_base &_STLP_CALL internal(ios_base &__s)
Definition: _ios_base.h:311
cid_load_glyph(T1_Decoder decoder, FT_UInt glyph_index)
Definition: cidgload.c:44
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define FT_LOAD_VERTICAL_LAYOUT
Definition: freetype.h:3026
#define FT_LOAD_TARGET_MODE(x)
Definition: freetype.h:3154
FT_BEGIN_HEADER struct FT_Glyph_Metrics_ FT_Glyph_Metrics
#define FT_LOAD_NO_SCALE
Definition: freetype.h:3022
#define FT_LOAD_NO_RECURSE
Definition: freetype.h:3031
#define FT_LOAD_NO_HINTING
Definition: freetype.h:3023
FT_MulFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:508
FT_Vector * vec
Definition: ftbbox.c:469
#define FT_OUTLINE_HIGH_PRECISION
Definition: ftimage.h:443
#define FT_OUTLINE_OWNER
Definition: ftimage.h:435
#define FT_OUTLINE_REVERSE_FILL
Definition: ftimage.h:437
ft_synthesize_vertical_metrics(FT_Glyph_Metrics *metrics, FT_Pos advance)
Definition: ftobjs.c:2997
FT_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
Definition: ftoutln.c:507
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:706
FT_Outline_Get_CBox(const FT_Outline *outline, FT_BBox *acbox)
Definition: ftoutln.c:457
signed long FT_Fixed
Definition: fttypes.h:287
#define FT_BOOL(x)
Definition: fttypes.h:591
signed int FT_Int
Definition: fttypes.h:220
FxCollectionEntry * cur
GLdouble n
Definition: glext.h:7729
FT_Fixed x_scale
Definition: cidobjs.h:108
FT_Bool hint
Definition: cidobjs.h:105
FT_Fixed y_scale
Definition: cidobjs.h:109
FT_Bool scaled
Definition: cidobjs.h:106
FT_Pos xMin
Definition: ftimage.h:120
FT_Pos yMax
Definition: ftimage.h:121
FT_Pos yMin
Definition: ftimage.h:120
FT_Pos xMax
Definition: ftimage.h:121
FT_Outline outline
Definition: freetype.h:1890
FT_Slot_Internal internal
Definition: freetype.h:1903
FT_Fixed linearHoriAdvance
Definition: freetype.h:1880
FT_Fixed linearVertAdvance
Definition: freetype.h:1881
FT_Glyph_Metrics metrics
Definition: freetype.h:1879
FT_Glyph_Format format
Definition: freetype.h:1884
FT_Fixed xx
Definition: fttypes.h:392
FT_Fixed yx
Definition: fttypes.h:393
FT_Fixed yy
Definition: fttypes.h:393
FT_Fixed xy
Definition: fttypes.h:392
short n_contours
Definition: ftimage.h:338
int flags
Definition: ftimage.h:345
short n_points
Definition: ftimage.h:339
FT_Size_Metrics metrics
Definition: freetype.h:1636
FT_Fixed y_scale
Definition: freetype.h:1601
FT_Fixed x_scale
Definition: freetype.h:1600
FT_UShort y_ppem
Definition: freetype.h:1598
FT_Bool glyph_transformed
Definition: ftobjs.h:427
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78