38#define FT_COMPONENT t1gload
42 T1_Parse_Glyph_And_Get_Char_String( T1_Decoder decoder,
45 FT_Bool* force_scaling )
47 T1_Face face = (T1_Face)decoder->builder.face;
48 T1_Font type1 = &face->type1;
49 FT_Error error = FT_Err_Ok;
51 PSAux_Service psaux = (PSAux_Service)face->psaux;
52 const T1_Decoder_Funcs decoder_funcs = psaux->t1_decoder_funcs;
55#ifdef FT_CONFIG_OPTION_INCREMENTAL
56 FT_Incremental_InterfaceRec *inc =
57 face->root.internal->incremental_interface;
60#ifdef T1_CONFIG_OPTION_OLD_ENGINE
61 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( face );
65 decoder->font_matrix = type1->font_matrix;
66 decoder->font_offset = type1->font_offset;
68#ifdef FT_CONFIG_OPTION_INCREMENTAL
75 char_string->pointer = NULL;
77 error = inc->funcs->get_glyph_data( inc->object,
78 glyph_index, char_string );
86 char_string->pointer = type1->charstrings[glyph_index];
87 char_string->length = type1->charstrings_len[glyph_index];
93#ifdef T1_CONFIG_OPTION_OLD_ENGINE
94 if ( driver->hinting_engine == FT_HINTING_FREETYPE ||
95 decoder->builder.metrics_only )
96 error = decoder_funcs->parse_charstrings_old(
98 (FT_Byte*)char_string->pointer,
99 (FT_UInt)char_string->length );
101 if ( decoder->builder.metrics_only )
102 error = decoder_funcs->parse_metrics(
104 (FT_Byte*)char_string->pointer,
105 (FT_UInt)char_string->length );
109 CFF_SubFontRec subfont;
112 psaux->ps_decoder_init( &psdecoder, decoder, TRUE );
114 psaux->t1_make_subfont( FT_FACE( face ),
115 &face->type1.private_dict, &subfont );
116 psdecoder.current_subfont = &subfont;
118 error = decoder_funcs->parse_charstrings(
120 (FT_Byte*)char_string->pointer,
121 (FT_ULong)char_string->length );
125 if ( FT_ERR_EQ( error, Glyph_Too_Big ) )
130 ((T1_GlyphSlot)decoder->builder.glyph)->hint = FALSE;
132 *force_scaling = TRUE;
134 error = decoder_funcs->parse_charstrings(
136 (FT_Byte*)char_string->pointer,
137 (FT_ULong)char_string->length );
142#ifdef FT_CONFIG_OPTION_INCREMENTAL
145 if ( !error && inc && inc->funcs->get_glyph_metrics )
147 FT_Incremental_MetricsRec metrics;
150 metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x );
151 metrics.bearing_y = 0;
152 metrics.advance = FIXED_TO_INT( decoder->builder.advance.x );
153 metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y );
155 error = inc->funcs->get_glyph_metrics( inc->object,
156 glyph_index, FALSE, &metrics );
158 decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x );
159 decoder->builder.advance.x = INT_TO_FIXED( metrics.advance );
160 decoder->builder.advance.y = INT_TO_FIXED( metrics.advance_v );
164 inc->funcs->free_glyph_data( inc->object, char_string );
172 FT_CALLBACK_DEF( FT_Error )
173 T1_Parse_Glyph( T1_Decoder decoder,
174 FT_UInt glyph_index )
177 FT_Bool force_scaling = FALSE;
178 FT_Error error = T1_Parse_Glyph_And_Get_Char_String(
179 decoder, glyph_index, &glyph_data,
183#ifdef FT_CONFIG_OPTION_INCREMENTAL
187 T1_Face face = (T1_Face)decoder->builder.face;
190 if ( face->root.internal->incremental_interface )
191 face->root.internal->incremental_interface->funcs->free_glyph_data(
192 face->root.internal->incremental_interface->object,
219 FT_LOCAL_DEF( FT_Error )
220 T1_Compute_Max_Advance( T1_Face face,
221 FT_Pos* max_advance )
224 T1_DecoderRec decoder;
226 T1_Font type1 = &face->type1;
227 PSAux_Service psaux = (PSAux_Service)face->psaux;
230 FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
235 error = psaux->t1_decoder_funcs->init( &decoder,
239 (FT_Byte**)type1->glyph_names,
242 FT_RENDER_MODE_NORMAL,
247 decoder.builder.metrics_only = 1;
248 decoder.builder.load_points = 0;
250 decoder.num_subrs = type1->num_subrs;
251 decoder.subrs = type1->subrs;
252 decoder.subrs_len = type1->subrs_len;
253 decoder.subrs_hash = type1->subrs_hash;
255 decoder.buildchar = face->buildchar;
256 decoder.len_buildchar = face->len_buildchar;
260 FT_TRACE6((
"T1_Compute_Max_Advance:\n" ));
264 for ( glyph_index = 0; glyph_index < type1->num_glyphs; glyph_index++ )
267 (void)T1_Parse_Glyph( &decoder, (FT_UInt)glyph_index );
268 if ( glyph_index == 0 || decoder.builder.advance.x > *max_advance )
269 *max_advance = decoder.builder.advance.x;
274 FT_TRACE6((
"T1_Compute_Max_Advance: max advance: %f\n",
275 (
double)*max_advance / 65536 ));
277 psaux->t1_decoder_funcs->done( &decoder );
283 FT_LOCAL_DEF( FT_Error )
284 T1_Get_Advances( FT_Face t1face,
290 T1_Face face = (T1_Face)t1face;
291 T1_DecoderRec decoder;
292 T1_Font type1 = &face->type1;
293 PSAux_Service psaux = (PSAux_Service)face->psaux;
298 FT_TRACE5((
"T1_Get_Advances:\n" ));
300 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
302 for ( nn = 0; nn < count; nn++ )
306 FT_TRACE5((
" idx %u: advance height 0 font units\n",
313 error = psaux->t1_decoder_funcs->init( &decoder,
317 (FT_Byte**)type1->glyph_names,
320 FT_RENDER_MODE_NORMAL,
325 decoder.builder.metrics_only = 1;
326 decoder.builder.load_points = 0;
328 decoder.num_subrs = type1->num_subrs;
329 decoder.subrs = type1->subrs;
330 decoder.subrs_len = type1->subrs_len;
331 decoder.subrs_hash = type1->subrs_hash;
333 decoder.buildchar = face->buildchar;
334 decoder.len_buildchar = face->len_buildchar;
336 for ( nn = 0; nn < count; nn++ )
338 error = T1_Parse_Glyph( &decoder, first + nn );
340 advances[nn] = FIXED_TO_INT( decoder.builder.advance.x );
344 FT_TRACE5((
" idx %u: advance width %ld font unit%s\n",
347 advances[nn] == 1 ?
"" :
"s" ));
354 FT_LOCAL_DEF( FT_Error )
355 T1_Load_Glyph( FT_GlyphSlot t1glyph,
358 FT_Int32 load_flags )
360 T1_GlyphSlot glyph = (T1_GlyphSlot)t1glyph;
362 T1_DecoderRec decoder;
363 T1_Face face = (T1_Face)t1glyph->face;
366 FT_Bool force_scaling = FALSE;
367 T1_Font type1 = &face->type1;
368 PSAux_Service psaux = (PSAux_Service)face->psaux;
369 const T1_Decoder_Funcs decoder_funcs = psaux->t1_decoder_funcs;
371 FT_Matrix font_matrix;
372 FT_Vector font_offset;
374 FT_Bool must_finish_decoder = FALSE;
375#ifdef FT_CONFIG_OPTION_INCREMENTAL
376 FT_Bool glyph_data_loaded = 0;
380#ifdef FT_CONFIG_OPTION_INCREMENTAL
381 if ( glyph_index >= (FT_UInt)face->root.num_glyphs &&
382 !face->root.internal->incremental_interface )
384 if ( glyph_index >= (FT_UInt)face->root.num_glyphs )
387 error = FT_THROW( Invalid_Argument );
391 FT_TRACE1((
"T1_Load_Glyph: glyph index %u\n", glyph_index ));
393 FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
395 if ( load_flags & FT_LOAD_NO_RECURSE )
396 load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
400 glyph->x_scale = t1size->metrics.x_scale;
401 glyph->y_scale = t1size->metrics.y_scale;
405 glyph->x_scale = 0x10000L;
406 glyph->y_scale = 0x10000L;
409 hinting = FT_BOOL( !( load_flags & FT_LOAD_NO_SCALE ) &&
410 !( load_flags & FT_LOAD_NO_HINTING ) );
411 scaled = FT_BOOL( !( load_flags & FT_LOAD_NO_SCALE ) );
413 glyph->hint = hinting;
414 glyph->scaled = scaled;
416 error = decoder_funcs->init( &decoder,
420 (FT_Byte**)type1->glyph_names,
423 FT_LOAD_TARGET_MODE( load_flags ),
428 must_finish_decoder = TRUE;
430 decoder.builder.no_recurse = FT_BOOL( load_flags & FT_LOAD_NO_RECURSE );
432 decoder.num_subrs = type1->num_subrs;
433 decoder.subrs = type1->subrs;
434 decoder.subrs_len = type1->subrs_len;
435 decoder.subrs_hash = type1->subrs_hash;
437 decoder.buildchar = face->buildchar;
438 decoder.len_buildchar = face->len_buildchar;
441 error = T1_Parse_Glyph_And_Get_Char_String( &decoder, glyph_index,
446#ifdef FT_CONFIG_OPTION_INCREMENTAL
447 glyph_data_loaded = 1;
450 hinting = glyph->hint;
451 font_matrix = decoder.font_matrix;
452 font_offset = decoder.font_offset;
455 decoder_funcs->done( &decoder );
457 must_finish_decoder = FALSE;
465 if ( load_flags & FT_LOAD_NO_RECURSE )
467 FT_Slot_Internal internal = t1glyph->internal;
470 t1glyph->metrics.horiBearingX =
471 FIXED_TO_INT( decoder.builder.left_bearing.x );
472 t1glyph->metrics.horiAdvance =
473 FIXED_TO_INT( decoder.builder.advance.x );
475 internal->glyph_matrix = font_matrix;
476 internal->glyph_delta = font_offset;
477 internal->glyph_transformed = 1;
482 FT_Glyph_Metrics* metrics = &t1glyph->metrics;
485 t1glyph->format = FT_GLYPH_FORMAT_OUTLINE;
487 t1glyph->outline.flags &= FT_OUTLINE_OWNER;
488 t1glyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
489 if ( t1size && t1size->metrics.y_ppem < 24 )
490 t1glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
493 metrics->horiAdvance =
494 FIXED_TO_INT( decoder.builder.advance.x );
495 t1glyph->linearHoriAdvance =
496 FIXED_TO_INT( decoder.builder.advance.x );
497 t1glyph->internal->glyph_transformed = 0;
499 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
502 metrics->vertAdvance = ( face->type1.font_bbox.yMax -
503 face->type1.font_bbox.yMin ) >> 16;
504 t1glyph->linearVertAdvance = metrics->vertAdvance;
508 metrics->vertAdvance =
509 FIXED_TO_INT( decoder.builder.advance.y );
510 t1glyph->linearVertAdvance =
511 FIXED_TO_INT( decoder.builder.advance.y );
516 if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L ||
517 font_matrix.xy != 0 || font_matrix.yx != 0 )
519 FT_Outline_Transform( &t1glyph->outline, &font_matrix );
521 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance,
523 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance,
527 if ( font_offset.x || font_offset.y )
529 FT_Outline_Translate( &t1glyph->outline,
533 metrics->horiAdvance += font_offset.x;
534 metrics->vertAdvance += font_offset.y;
538 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || force_scaling )
542 FT_Outline* cur = decoder.builder.base;
543 FT_Vector* vec = cur->points;
544 FT_Fixed x_scale = glyph->x_scale;
545 FT_Fixed y_scale = glyph->y_scale;
549 if ( !hinting || !decoder.builder.hints_funcs )
550 for ( n = cur->n_points; n > 0; n--, vec++ )
552 vec->x = FT_MulFix( vec->x, x_scale );
553 vec->y = FT_MulFix( vec->y, y_scale );
557 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
558 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
562 FT_Outline_Get_CBox( &t1glyph->outline, &cbox );
564 metrics->width = cbox.xMax - cbox.xMin;
565 metrics->height = cbox.yMax - cbox.yMin;
567 metrics->horiBearingX = cbox.xMin;
568 metrics->horiBearingY = cbox.yMax;
570 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
573 ft_synthesize_vertical_metrics( metrics,
574 metrics->vertAdvance );
580 t1glyph->control_data = (FT_Byte*)glyph_data.pointer;
581 t1glyph->control_len = glyph_data.length;
587#ifdef FT_CONFIG_OPTION_INCREMENTAL
588 if ( glyph_data_loaded && face->root.internal->incremental_interface )
590 face->root.internal->incremental_interface->funcs->free_glyph_data(
591 face->root.internal->incremental_interface->object,
596 t1glyph->control_data = NULL;
597 t1glyph->control_len = 0;
601 if ( must_finish_decoder )
602 decoder_funcs->done( &decoder );