26#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
40#define FT_COMPONENT ttpload
62 FT_LOCAL_DEF( FT_Error )
63 tt_face_load_loca( TT_Face face,
72 error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len );
76 if ( FT_ERR_EQ( error, Table_Missing ) )
79 face->glyf_offset = 0;
85#ifdef FT_CONFIG_OPTION_INCREMENTAL
86 if ( face->root.internal->incremental_interface )
87 face->glyf_offset = 0;
90 face->glyf_offset = FT_STREAM_POS();
93 FT_TRACE2((
"Locations " ));
94 error = face->goto_table( face, TTAG_loca, stream, &table_len );
97 error = FT_THROW( Locations_Missing );
101 shift = face->header.Index_To_Loc_Format != 0 ? 2 : 1;
103 if ( table_len > 0x10000UL << shift )
105 FT_TRACE2((
"table too large\n" ));
106 table_len = 0x10000UL << shift;
109 face->num_locations = table_len >> shift;
111 if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 )
113 FT_TRACE2((
"glyph count mismatch! loca: %lu, maxp: %ld\n",
114 face->num_locations - 1, face->root.num_glyphs ));
117 if ( face->num_locations < (FT_ULong)face->root.num_glyphs + 1 )
119 FT_ULong new_loca_len =
120 ( (FT_ULong)face->root.num_glyphs + 1 ) << shift;
122 TT_Table entry = face->dir_tables;
123 TT_Table limit = entry + face->num_tables;
125 FT_Long pos = (FT_Long)FT_STREAM_POS();
126 FT_Long dist = 0x7FFFFFFFL;
131 for ( ; entry < limit; entry++ )
133 FT_Long diff = (FT_Long)entry->Offset - pos;
136 if ( diff > 0 && diff < dist )
146 dist = (FT_Long)stream->size - pos;
149 if ( new_loca_len <= (FT_ULong)dist )
151 face->num_locations = (FT_ULong)face->root.num_glyphs + 1;
152 table_len = new_loca_len;
154 FT_TRACE2((
"adjusting num_locations to %lu\n",
155 face->num_locations ));
159 face->root.num_glyphs = face->num_locations
160 ? (FT_Long)face->num_locations - 1 : 0;
162 FT_TRACE2((
"adjusting num_glyphs to %ld\n",
163 face->root.num_glyphs ));
172 if ( FT_FRAME_EXTRACT( table_len, face->glyph_locations ) )
175 FT_TRACE2((
"loaded\n" ));
182 FT_LOCAL_DEF( FT_ULong )
183 tt_face_get_location( FT_Face face,
187 TT_Face ttface = (TT_Face)face;
195 if ( gindex < ttface->num_locations )
197 if ( ttface->header.Index_To_Loc_Format != 0 )
199 p = ttface->glyph_locations + gindex * 4;
200 p_limit = ttface->glyph_locations + ttface->num_locations * 4;
202 pos1 = FT_NEXT_ULONG( p );
205 if ( p + 4 <= p_limit )
206 pos2 = FT_NEXT_ULONG( p );
210 p = ttface->glyph_locations + gindex * 2;
211 p_limit = ttface->glyph_locations + ttface->num_locations * 2;
213 pos1 = FT_NEXT_USHORT( p );
216 if ( p + 2 <= p_limit )
217 pos2 = FT_NEXT_USHORT( p );
225 if ( pos1 > ttface->glyf_len )
227 FT_TRACE1((
"tt_face_get_location:"
228 " too large offset (0x%08lx) found for glyph index %u,\n",
231 " exceeding the end of `glyf' table (0x%08lx)\n",
237 if ( pos2 > ttface->glyf_len )
240 if ( gindex == ttface->num_locations - 2 )
242 FT_TRACE1((
"tt_face_get_location:"
243 " too large size (%lu bytes) found for glyph index %u,\n",
244 pos2 - pos1, gindex ));
246 " truncating at the end of `glyf' table to %lu bytes\n",
247 ttface->glyf_len - pos1 ));
248 pos2 = ttface->glyf_len;
252 FT_TRACE1((
"tt_face_get_location:"
253 " too large offset (0x%08lx) found for glyph index %u,\n",
256 " exceeding the end of `glyf' table (0x%08lx)\n",
272 *asize = (FT_ULong)( pos2 - pos1 );
274 *asize = (FT_ULong)( ttface->glyf_len - pos1 );
281 tt_face_done_loca( TT_Face face )
283 FT_Stream stream = face->root.stream;
286 FT_FRAME_RELEASE( face->glyph_locations );
287 face->num_locations = 0;
311 FT_LOCAL_DEF( FT_Error )
312 tt_face_load_cvt( TT_Face face,
315#ifdef TT_USE_BYTECODE_INTERPRETER
318 FT_Memory memory = stream->memory;
322 FT_TRACE2((
"CVT " ));
324 error = face->goto_table( face, TTAG_cvt, stream, &table_len );
327 FT_TRACE2((
"is missing\n" ));
336 face->cvt_size = table_len / 2;
338 if ( FT_QNEW_ARRAY( face->cvt, face->cvt_size ) )
341 if ( FT_FRAME_ENTER( face->cvt_size * 2L ) )
345 FT_Int32* cur = face->cvt;
346 FT_Int32* limit = cur + face->cvt_size;
349 for ( ; cur < limit; cur++ )
350 *cur = FT_GET_SHORT() * 64;
354 FT_TRACE2((
"loaded\n" ));
356#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
358 error = tt_face_vary_cvt( face, stream );
394 FT_LOCAL_DEF( FT_Error )
395 tt_face_load_fpgm( TT_Face face,
398#ifdef TT_USE_BYTECODE_INTERPRETER
404 FT_TRACE2((
"Font program " ));
407 error = face->goto_table( face, TTAG_fpgm, stream, &table_len );
410 face->font_program = NULL;
411 face->font_program_size = 0;
414 FT_TRACE2((
"is missing\n" ));
418 face->font_program_size = table_len;
419 if ( FT_FRAME_EXTRACT( table_len, face->font_program ) )
422 FT_TRACE2((
"loaded, %12lu bytes\n", face->font_program_size ));
458 FT_LOCAL_DEF( FT_Error )
459 tt_face_load_prep( TT_Face face,
462#ifdef TT_USE_BYTECODE_INTERPRETER
468 FT_TRACE2((
"Prep program " ));
470 error = face->goto_table( face, TTAG_prep, stream, &table_len );
473 face->cvt_program = NULL;
474 face->cvt_program_size = 0;
477 FT_TRACE2((
"is missing\n" ));
481 face->cvt_program_size = table_len;
482 if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) )
485 FT_TRACE2((
"loaded, %12lu bytes\n", face->cvt_program_size ));
502 FT_COMPARE_DEF(
int )
503 compare_ppem(
const void* a,
506 return **(FT_Byte**)a - **(FT_Byte**)b;
529 FT_LOCAL_DEF( FT_Error )
530 tt_face_load_hdmx( TT_Face face,
534 FT_Memory memory = stream->memory;
535 FT_UInt nn, num_records;
536 FT_ULong table_size, record_size;
542 error = face->goto_table( face, TTAG_hdmx, stream, &table_size );
543 if ( error || table_size < 8 )
546 if ( FT_FRAME_EXTRACT( table_size, face->hdmx_table ) )
549 p = face->hdmx_table;
550 limit = p + table_size;
556 num_records = FT_NEXT_USHORT( p );
557 record_size = FT_NEXT_ULONG( p );
564 if ( record_size >= 0xFFFF0000UL )
565 record_size &= 0xFFFFU;
567 FT_TRACE2((
"Hdmx " ));
570 if ( num_records > 255 || num_records == 0 )
572 FT_TRACE2((
"with unreasonable %u records rejected\n", num_records ));
578 if ( (FT_Long)record_size != ( ( face->root.num_glyphs + 2 + 3 ) & ~3 ) )
580 FT_TRACE2((
"with record size off by %ld bytes rejected\n",
581 (FT_Long)record_size -
582 ( ( face->root.num_glyphs + 2 + 3 ) & ~3 ) ));
586 if ( FT_QNEW_ARRAY( face->hdmx_records, num_records ) )
589 for ( nn = 0; nn < num_records; nn++ )
591 if ( p + record_size > limit )
593 face->hdmx_records[nn] = p;
599 ft_qsort( face->hdmx_records, nn, sizeof ( FT_Byte* ), compare_ppem );
601 face->hdmx_record_count = nn;
602 face->hdmx_table_size = table_size;
603 face->hdmx_record_size = record_size;
605 FT_TRACE2((
"%ux%lu loaded\n", num_records, record_size ));
611 FT_FRAME_RELEASE( face->hdmx_table );
612 face->hdmx_table_size = 0;
618 tt_face_free_hdmx( TT_Face face )
620 FT_Stream stream = face->root.stream;
621 FT_Memory memory = stream->memory;
624 FT_FREE( face->hdmx_records );
625 FT_FRAME_RELEASE( face->hdmx_table );
635 FT_LOCAL_DEF( FT_Byte* )
636 tt_face_get_device_metrics( TT_Face face,
641 FT_UInt max = face->hdmx_record_count;
643 FT_Byte* result = NULL;
648 mid = ( min + max ) >> 1;
650 if ( face->hdmx_records[mid][0] > ppem )
652 else if ( face->hdmx_records[mid][0] < ppem )
656 result = face->hdmx_records[mid] + 2 + gindex;