ReactOS 0.4.16-dev-2332-g4cba65d
ttpload.c File Reference
Include dependency graph for ttpload.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   ttpload
 

Functions

 tt_face_load_loca (TT_Face face, FT_Stream stream)
 
 tt_face_get_location (TT_Face face, FT_UInt gindex, FT_UInt *asize)
 
 tt_face_done_loca (TT_Face face)
 
 tt_face_load_cvt (TT_Face face, FT_Stream stream)
 
 tt_face_load_fpgm (TT_Face face, FT_Stream stream)
 
 tt_face_load_prep (TT_Face face, FT_Stream stream)
 
 tt_face_load_hdmx (TT_Face face, FT_Stream stream)
 
 tt_face_free_hdmx (TT_Face face)
 
 tt_face_get_device_metrics (TT_Face face, FT_UInt ppem, FT_UInt gindex)
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   ttpload

Definition at line 40 of file ttpload.c.

Function Documentation

◆ tt_face_done_loca()

tt_face_done_loca ( TT_Face  face)

Definition at line 290 of file ttpload.c.

291 {
292 FT_Stream stream = face->root.stream;
293
294
295 FT_FRAME_RELEASE( face->glyph_locations );
296 face->num_locations = 0;
297 }
#define FT_FRAME_RELEASE(bytes)
Definition: ftstream.h:562
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
Definition: parse.h:23

Referenced by tt_face_done().

◆ tt_face_free_hdmx()

tt_face_free_hdmx ( TT_Face  face)

Definition at line 611 of file ttpload.c.

612 {
613 FT_Stream stream = face->root.stream;
614 FT_Memory memory = stream->memory;
615
616
617 FT_FREE( face->hdmx_record_sizes );
618 FT_FRAME_RELEASE( face->hdmx_table );
619 }
#define FT_FREE(ptr)
Definition: ftmemory.h:337
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
static char memory[1024 *256]
Definition: process.c:122

Referenced by tt_face_done().

◆ tt_face_get_device_metrics()

tt_face_get_device_metrics ( TT_Face  face,
FT_UInt  ppem,
FT_UInt  gindex 
)

Definition at line 628 of file ttpload.c.

631 {
632 FT_UInt nn;
634 FT_ULong record_size = face->hdmx_record_size;
635 FT_Byte* record = FT_OFFSET( face->hdmx_table, 8 );
636
637
638 for ( nn = 0; nn < face->hdmx_record_count; nn++ )
639 if ( face->hdmx_record_sizes[nn] == ppem )
640 {
641 gindex += 2;
642 if ( gindex < record_size )
643 result = record + nn * record_size + gindex;
644 break;
645 }
646
647 return result;
648 }
#define NULL
Definition: types.h:112
#define FT_OFFSET(base, count)
Definition: ftmemory.h:66
unsigned long FT_ULong
Definition: fttypes.h:253
unsigned char FT_Byte
Definition: fttypes.h:154
unsigned int FT_UInt
Definition: fttypes.h:231
GLuint64EXT * result
Definition: glext.h:11304

Referenced by compute_glyph_metrics().

◆ tt_face_get_location()

tt_face_get_location ( TT_Face  face,
FT_UInt  gindex,
FT_UInt asize 
)

Definition at line 196 of file ttpload.c.

199 {
200 FT_ULong pos1, pos2;
201 FT_Byte* p;
202 FT_Byte* p_limit;
203
204
205 pos1 = pos2 = 0;
206
207 if ( gindex < face->num_locations )
208 {
209 if ( face->header.Index_To_Loc_Format != 0 )
210 {
211 p = face->glyph_locations + gindex * 4;
212 p_limit = face->glyph_locations + face->num_locations * 4;
213
214 pos1 = FT_NEXT_ULONG( p );
215 pos2 = pos1;
216
217 if ( p + 4 <= p_limit )
218 pos2 = FT_NEXT_ULONG( p );
219 }
220 else
221 {
222 p = face->glyph_locations + gindex * 2;
223 p_limit = face->glyph_locations + face->num_locations * 2;
224
225 pos1 = FT_NEXT_USHORT( p );
226 pos2 = pos1;
227
228 if ( p + 2 <= p_limit )
229 pos2 = FT_NEXT_USHORT( p );
230
231 pos1 <<= 1;
232 pos2 <<= 1;
233 }
234 }
235
236 /* Check broken location data. */
237 if ( pos1 > face->glyf_len )
238 {
239 FT_TRACE1(( "tt_face_get_location:"
240 " too large offset (0x%08lx) found for glyph index %d,\n"
241 " "
242 " exceeding the end of `glyf' table (0x%08lx)\n",
243 pos1, gindex, face->glyf_len ));
244 *asize = 0;
245 return 0;
246 }
247
248 if ( pos2 > face->glyf_len )
249 {
250 /* We try to sanitize the last `loca' entry. */
251 if ( gindex == face->num_locations - 2 )
252 {
253 FT_TRACE1(( "tt_face_get_location:"
254 " too large size (%ld bytes) found for glyph index %d,\n"
255 " "
256 " truncating at the end of `glyf' table to %ld bytes\n",
257 pos2 - pos1, gindex, face->glyf_len - pos1 ));
258 pos2 = face->glyf_len;
259 }
260 else
261 {
262 FT_TRACE1(( "tt_face_get_location:"
263 " too large offset (0x%08lx) found for glyph index %d,\n"
264 " "
265 " exceeding the end of `glyf' table (0x%08lx)\n",
266 pos2, gindex + 1, face->glyf_len ));
267 *asize = 0;
268 return 0;
269 }
270 }
271
272 /* The `loca' table must be ordered; it refers to the length of */
273 /* an entry as the difference between the current and the next */
274 /* position. However, there do exist (malformed) fonts which */
275 /* don't obey this rule, so we are only able to provide an */
276 /* upper bound for the size. */
277 /* */
278 /* We get (intentionally) a wrong, non-zero result in case the */
279 /* `glyf' table is missing. */
280 if ( pos2 >= pos1 )
281 *asize = (FT_UInt)( pos2 - pos1 );
282 else
283 *asize = (FT_UInt)( face->glyf_len - pos1 );
284
285 return pos1;
286 }
#define FT_TRACE1(varformat)
Definition: ftdebug.h:188
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:244
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:256
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by load_truetype_glyph(), and tt_check_single_notdef().

◆ tt_face_load_cvt()

tt_face_load_cvt ( TT_Face  face,
FT_Stream  stream 
)

Definition at line 321 of file ttpload.c.

323 {
324#ifdef TT_USE_BYTECODE_INTERPRETER
325
327 FT_Memory memory = stream->memory;
328 FT_ULong table_len;
329
330
331 FT_TRACE2(( "CVT " ));
332
333 error = face->goto_table( face, TTAG_cvt, stream, &table_len );
334 if ( error )
335 {
336 FT_TRACE2(( "is missing\n" ));
337
338 face->cvt_size = 0;
339 face->cvt = NULL;
341
342 goto Exit;
343 }
344
345 face->cvt_size = table_len / 2;
346
347 if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) )
348 goto Exit;
349
350 if ( FT_FRAME_ENTER( face->cvt_size * 2L ) )
351 goto Exit;
352
353 {
354 FT_Int32* cur = face->cvt;
355 FT_Int32* limit = cur + face->cvt_size;
356
357
358 for ( ; cur < limit; cur++ )
359 *cur = FT_GET_SHORT() * 64;
360 }
361
363 FT_TRACE2(( "loaded\n" ));
364
365#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
366 if ( face->doblend )
367 error = tt_face_vary_cvt( face, stream );
368#endif
369
370 Exit:
371 return error;
372
373#else /* !TT_USE_BYTECODE_INTERPRETER */
374
375 FT_UNUSED( face );
376 FT_UNUSED( stream );
377
378 return FT_Err_Ok;
379
380#endif
381 }
return FT_Err_Ok
Definition: ftbbox.c:526
#define FT_TRACE2(varformat)
Definition: ftdebug.h:189
#define FT_NEW_ARRAY(ptr, count)
Definition: ftmemory.h:341
#define FT_FRAME_ENTER(size)
Definition: ftstream.h:548
#define FT_GET_SHORT()
Definition: ftstream.h:310
#define FT_FRAME_EXIT()
Definition: ftstream.h:553
int FT_Error
Definition: fttypes.h:299
FxCollectionEntry * cur
GLint limit
Definition: glext.h:10326
#define error(str)
Definition: mkdosfs.c:1605
#define FT_UNUSED(arg)
static void Exit(void)
Definition: sock.c:1330
#define TTAG_cvt
Definition: tttags.h:51

Referenced by tt_face_init().

◆ tt_face_load_fpgm()

tt_face_load_fpgm ( TT_Face  face,
FT_Stream  stream 
)

Definition at line 404 of file ttpload.c.

406 {
407#ifdef TT_USE_BYTECODE_INTERPRETER
408
410 FT_ULong table_len;
411
412
413 FT_TRACE2(( "Font program " ));
414
415 /* The font program is optional */
416 error = face->goto_table( face, TTAG_fpgm, stream, &table_len );
417 if ( error )
418 {
419 face->font_program = NULL;
420 face->font_program_size = 0;
422
423 FT_TRACE2(( "is missing\n" ));
424 }
425 else
426 {
427 face->font_program_size = table_len;
428 if ( FT_FRAME_EXTRACT( table_len, face->font_program ) )
429 goto Exit;
430
431 FT_TRACE2(( "loaded, %12ld bytes\n", face->font_program_size ));
432 }
433
434 Exit:
435 return error;
436
437#else /* !TT_USE_BYTECODE_INTERPRETER */
438
439 FT_UNUSED( face );
440 FT_UNUSED( stream );
441
442 return FT_Err_Ok;
443
444#endif
445 }
#define FT_FRAME_EXTRACT(size, bytes)
Definition: ftstream.h:556
#define TTAG_fpgm
Definition: tttags.h:58

Referenced by tt_face_init().

◆ tt_face_load_hdmx()

tt_face_load_hdmx ( TT_Face  face,
FT_Stream  stream 
)

Definition at line 531 of file ttpload.c.

533 {
535 FT_Memory memory = stream->memory;
536 FT_UInt nn, num_records;
537 FT_ULong table_size, record_size;
538 FT_Byte* p;
539 FT_Byte* limit;
540
541
542 /* this table is optional */
543 error = face->goto_table( face, TTAG_hdmx, stream, &table_size );
544 if ( error || table_size < 8 )
545 return FT_Err_Ok;
546
547 if ( FT_FRAME_EXTRACT( table_size, face->hdmx_table ) )
548 goto Exit;
549
550 p = face->hdmx_table;
551 limit = p + table_size;
552
553 /* Given that `hdmx' tables are losing its importance (for example, */
554 /* variation fonts introduced in OpenType 1.8 must not have this */
555 /* table) we no longer test for a correct `version' field. */
556 p += 2;
557 num_records = FT_NEXT_USHORT( p );
558 record_size = FT_NEXT_ULONG( p );
559
560 /* The maximum number of bytes in an hdmx device record is the */
561 /* maximum number of glyphs + 2; this is 0xFFFF + 2, thus */
562 /* explaining why `record_size' is a long (which we read as */
563 /* unsigned long for convenience). In practice, two bytes are */
564 /* sufficient to hold the size value. */
565 /* */
566 /* There are at least two fonts, HANNOM-A and HANNOM-B version */
567 /* 2.0 (2005), which get this wrong: The upper two bytes of */
568 /* the size value are set to 0xFF instead of 0x00. We catch */
569 /* and fix this. */
570
571 if ( record_size >= 0xFFFF0000UL )
572 record_size &= 0xFFFFU;
573
574 /* The limit for `num_records' is a heuristic value. */
575 if ( num_records > 255 ||
576 ( num_records > 0 &&
577 ( record_size > 0x10001L ||
578 record_size < 4 ) ) )
579 {
580 error = FT_THROW( Invalid_File_Format );
581 goto Fail;
582 }
583
584 if ( FT_NEW_ARRAY( face->hdmx_record_sizes, num_records ) )
585 goto Fail;
586
587 for ( nn = 0; nn < num_records; nn++ )
588 {
589 if ( p + record_size > limit )
590 break;
591
592 face->hdmx_record_sizes[nn] = p[0];
593 p += record_size;
594 }
595
596 face->hdmx_record_count = nn;
597 face->hdmx_table_size = table_size;
598 face->hdmx_record_size = record_size;
599
600 Exit:
601 return error;
602
603 Fail:
604 FT_FRAME_RELEASE( face->hdmx_table );
605 face->hdmx_table_size = 0;
606 goto Exit;
607 }
int Fail
Definition: ehthrow.cxx:24
#define FT_THROW(e)
Definition: ftdebug.h:243
LOCAL int table_size
Definition: write.c:65
#define TTAG_hdmx
Definition: tttags.h:67

Referenced by tt_face_init().

◆ tt_face_load_loca()

tt_face_load_loca ( TT_Face  face,
FT_Stream  stream 
)

Definition at line 63 of file ttpload.c.

65 {
67 FT_ULong table_len;
69
70
71 /* we need the size of the `glyf' table for malformed `loca' tables */
72 error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len );
73
74 /* it is possible that a font doesn't have a glyf table at all */
75 /* or its size is zero */
76 if ( FT_ERR_EQ( error, Table_Missing ) )
77 {
78 face->glyf_len = 0;
79 face->glyf_offset = 0;
80 }
81 else if ( error )
82 goto Exit;
83 else
84 {
85#ifdef FT_CONFIG_OPTION_INCREMENTAL
86 if ( face->root.internal->incremental_interface )
87 face->glyf_offset = 0;
88 else
89#endif
90 face->glyf_offset = FT_STREAM_POS();
91 }
92
93 FT_TRACE2(( "Locations " ));
94 error = face->goto_table( face, TTAG_loca, stream, &table_len );
95 if ( error )
96 {
97 error = FT_THROW( Locations_Missing );
98 goto Exit;
99 }
100
101 if ( face->header.Index_To_Loc_Format != 0 )
102 {
103 shift = 2;
104
105 if ( table_len >= 0x40000L )
106 {
107 FT_TRACE2(( "table too large\n" ));
108 table_len = 0x3FFFFL;
109 }
110 face->num_locations = table_len >> shift;
111 }
112 else
113 {
114 shift = 1;
115
116 if ( table_len >= 0x20000L )
117 {
118 FT_TRACE2(( "table too large\n" ));
119 table_len = 0x1FFFFL;
120 }
121 face->num_locations = table_len >> shift;
122 }
123
124 if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 )
125 {
126 FT_TRACE2(( "glyph count mismatch! loca: %ld, maxp: %ld\n",
127 face->num_locations - 1, face->root.num_glyphs ));
128
129 /* we only handle the case where `maxp' gives a larger value */
130 if ( face->num_locations <= (FT_ULong)face->root.num_glyphs )
131 {
132 FT_ULong new_loca_len =
133 ( (FT_ULong)face->root.num_glyphs + 1 ) << shift;
134
135 TT_Table entry = face->dir_tables;
136 TT_Table limit = entry + face->num_tables;
137
139 FT_Long dist = 0x7FFFFFFFL;
140 FT_Bool found = 0;
141
142
143 /* compute the distance to next table in font file */
144 for ( ; entry < limit; entry++ )
145 {
146 FT_Long diff = (FT_Long)entry->Offset - pos;
147
148
149 if ( diff > 0 && diff < dist )
150 {
151 dist = diff;
152 found = 1;
153 }
154 }
155
156 if ( !found )
157 {
158 /* `loca' is the last table */
159 dist = (FT_Long)stream->size - pos;
160 }
161
162 if ( new_loca_len <= (FT_ULong)dist )
163 {
164 face->num_locations = (FT_ULong)face->root.num_glyphs + 1;
165 table_len = new_loca_len;
166
167 FT_TRACE2(( "adjusting num_locations to %ld\n",
168 face->num_locations ));
169 }
170 else
171 {
172 face->root.num_glyphs = face->num_locations
173 ? (FT_Long)face->num_locations - 1 : 0;
174
175 FT_TRACE2(( "adjusting num_glyphs to %ld\n",
176 face->root.num_glyphs ));
177 }
178 }
179 }
180
181 /*
182 * Extract the frame. We don't need to decompress it since
183 * we are able to parse it directly.
184 */
185 if ( FT_FRAME_EXTRACT( table_len, face->glyph_locations ) )
186 goto Exit;
187
188 FT_TRACE2(( "loaded\n" ));
189
190 Exit:
191 return error;
192 }
#define FT_STREAM_POS()
Definition: ftstream.h:522
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
#define FT_ERR_EQ(x, e)
Definition: fttypes.h:604
signed long FT_Long
Definition: fttypes.h:242
signed int FT_Int
Definition: fttypes.h:220
uint32_t entry
Definition: isohybrid.c:63
if(dx< 0)
Definition: linetemp.h:194
#define shift
Definition: input.c:1755
unsigned int size
Definition: parse.h:27
#define TTAG_glyf
Definition: tttags.h:62
#define TTAG_loca
Definition: tttags.h:75

Referenced by tt_face_init().

◆ tt_face_load_prep()

tt_face_load_prep ( TT_Face  face,
FT_Stream  stream 
)

Definition at line 468 of file ttpload.c.

470 {
471#ifdef TT_USE_BYTECODE_INTERPRETER
472
474 FT_ULong table_len;
475
476
477 FT_TRACE2(( "Prep program " ));
478
479 error = face->goto_table( face, TTAG_prep, stream, &table_len );
480 if ( error )
481 {
482 face->cvt_program = NULL;
483 face->cvt_program_size = 0;
485
486 FT_TRACE2(( "is missing\n" ));
487 }
488 else
489 {
490 face->cvt_program_size = table_len;
491 if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) )
492 goto Exit;
493
494 FT_TRACE2(( "loaded, %12ld bytes\n", face->cvt_program_size ));
495 }
496
497 Exit:
498 return error;
499
500#else /* !TT_USE_BYTECODE_INTERPRETER */
501
502 FT_UNUSED( face );
503 FT_UNUSED( stream );
504
505 return FT_Err_Ok;
506
507#endif
508 }
#define TTAG_prep
Definition: tttags.h:93

Referenced by tt_face_init().