1 /***************************************************************************/
5 /* Objects manager (body). */
7 /* Copyright 1996-2011 */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_STREAM_H
22 #include FT_TRUETYPE_TAGS_H
23 #include FT_INTERNAL_SFNT_H
30 #ifdef TT_USE_BYTECODE_INTERPRETER
34 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
35 #include FT_TRUETYPE_UNPATENTED_H
38 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
42 /*************************************************************************/
44 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
45 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
46 /* messages during execution. */
49 #define FT_COMPONENT trace_ttobjs
52 #ifdef TT_USE_BYTECODE_INTERPRETER
54 /*************************************************************************/
56 /* GLYPH ZONE FUNCTIONS */
58 /*************************************************************************/
61 /*************************************************************************/
64 /* tt_glyphzone_done */
67 /* Deallocate a glyph zone. */
70 /* zone :: A pointer to the target glyph zone. */
73 tt_glyphzone_done( TT_GlyphZone zone )
75 FT_Memory memory = zone->memory;
80 FT_FREE( zone->contours );
81 FT_FREE( zone->tags );
84 FT_FREE( zone->orus );
86 zone->max_points = zone->n_points = 0;
87 zone->max_contours = zone->n_contours = 0;
93 /*************************************************************************/
96 /* tt_glyphzone_new */
99 /* Allocate a new glyph zone. */
102 /* memory :: A handle to the current memory object. */
104 /* maxPoints :: The capacity of glyph zone in points. */
106 /* maxContours :: The capacity of glyph zone in contours. */
109 /* zone :: A pointer to the target glyph zone record. */
112 /* FreeType error code. 0 means success. */
114 FT_LOCAL_DEF( FT_Error )
115 tt_glyphzone_new( FT_Memory memory,
117 FT_Short maxContours,
123 FT_MEM_ZERO( zone, sizeof ( *zone ) );
124 zone->memory = memory;
126 if ( FT_NEW_ARRAY( zone->org, maxPoints ) ||
127 FT_NEW_ARRAY( zone->cur, maxPoints ) ||
128 FT_NEW_ARRAY( zone->orus, maxPoints ) ||
129 FT_NEW_ARRAY( zone->tags, maxPoints ) ||
130 FT_NEW_ARRAY( zone->contours, maxContours ) )
132 tt_glyphzone_done( zone );
136 zone->max_points = maxPoints;
137 zone->max_contours = maxContours;
142 #endif /* TT_USE_BYTECODE_INTERPRETER */
145 /* Compare the face with a list of well-known `tricky' fonts. */
146 /* This list shall be expanded as we find more of them. */
149 tt_check_trickyness_family( FT_String* name )
152 #define TRICK_NAMES_MAX_CHARACTERS 16
153 #define TRICK_NAMES_COUNT 8
155 static const char trick_names[TRICK_NAMES_COUNT]
156 [TRICK_NAMES_MAX_CHARACTERS + 1] =
158 "DFKaiSho-SB", /* dfkaisb.ttf */
160 "DFKai-SB", /* kaiu.ttf */
161 "HuaTianKaiTi?", /* htkt2.ttf */
162 "HuaTianSongTi?", /* htst3.ttf */
163 "MingLiU", /* mingliu.ttf & mingliu.ttc */
164 "PMingLiU", /* mingliu.ttc */
165 "MingLi43", /* mingli.ttf */
171 for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ )
172 if ( ft_strstr( name, trick_names[nn] ) )
179 /* XXX: This function should be in the `sfnt' module. */
181 /* Some PDF generators clear the checksums in the TrueType header table. */
182 /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF */
183 /* Printer clears the entries for subsetted subtables. We thus have to */
184 /* recalculate the checksums where necessary. */
187 tt_synth_sfnt_checksum( FT_Stream stream,
191 FT_UInt32 checksum = 0;
195 if ( FT_FRAME_ENTER( length ) )
198 for ( ; length > 3; length -= 4 )
199 checksum += (FT_UInt32)FT_GET_ULONG();
201 for ( i = 3; length > 0; length --, i-- )
202 checksum += (FT_UInt32)( FT_GET_BYTE() << ( i * 8 ) );
210 /* XXX: This function should be in the `sfnt' module. */
213 tt_get_sfnt_checksum( TT_Face face,
216 #if 0 /* if we believe the written value, use following part. */
217 if ( face->dir_tables[i].CheckSum )
218 return face->dir_tables[i].CheckSum;
221 if ( !face->goto_table )
224 if ( face->goto_table( face,
225 face->dir_tables[i].Tag,
230 return (FT_ULong)tt_synth_sfnt_checksum( face->root.stream,
231 face->dir_tables[i].Length );
235 typedef struct tt_sfnt_id_rec_
244 tt_check_trickyness_sfnt_ids( TT_Face face )
246 #define TRICK_SFNT_IDS_PER_FACE 3
247 #define TRICK_SFNT_IDS_NUM_FACES 13
249 static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES]
250 [TRICK_SFNT_IDS_PER_FACE] = {
252 #define TRICK_SFNT_ID_cvt 0
253 #define TRICK_SFNT_ID_fpgm 1
254 #define TRICK_SFNT_ID_prep 2
257 { 0x05bcf058, 0x000002e4 }, /* cvt */
258 { 0x28233bf1, 0x000087c4 }, /* fpgm */
259 { 0xa344a1ea, 0x000001e1 } /* prep */
261 { /* MingLiU 1996- */
262 { 0x05bcf058, 0x000002e4 }, /* cvt */
263 { 0x28233bf1, 0x000087c4 }, /* fpgm */
264 { 0xa344a1eb, 0x000001e1 } /* prep */
267 { 0x11e5ead4, 0x00000350 }, /* cvt */
268 { 0x5a30ca3b, 0x00009063 }, /* fpgm */
269 { 0x13a42602, 0x0000007e } /* prep */
272 { 0xfffbfffc, 0x00000008 }, /* cvt */
273 { 0x9c9e48b8, 0x0000bea2 }, /* fpgm */
274 { 0x70020112, 0x00000008 } /* prep */
276 { /* HuaTianSongTi */
277 { 0xfffbfffc, 0x00000008 }, /* cvt */
278 { 0x0a5a0483, 0x00017c39 }, /* fpgm */
279 { 0x70020112, 0x00000008 } /* prep */
281 { /* NEC fadpop7.ttf */
282 { 0x00000000, 0x00000000 }, /* cvt */
283 { 0x40c92555, 0x000000e5 }, /* fpgm */
284 { 0xa39b58e3, 0x0000117c } /* prep */
286 { /* NEC fadrei5.ttf */
287 { 0x00000000, 0x00000000 }, /* cvt */
288 { 0x33c41652, 0x000000e5 }, /* fpgm */
289 { 0x26d6c52a, 0x00000f6a } /* prep */
291 { /* NEC fangot7.ttf */
292 { 0x00000000, 0x00000000 }, /* cvt */
293 { 0x6db1651d, 0x0000019d }, /* fpgm */
294 { 0x6c6e4b03, 0x00002492 } /* prep */
296 { /* NEC fangyo5.ttf */
297 { 0x00000000, 0x00000000 }, /* cvt */
298 { 0x40c92555, 0x000000e5 }, /* fpgm */
299 { 0xde51fad0, 0x0000117c } /* prep */
301 { /* NEC fankyo5.ttf */
302 { 0x00000000, 0x00000000 }, /* cvt */
303 { 0x85e47664, 0x000000e5 }, /* fpgm */
304 { 0xa6c62831, 0x00001caa } /* prep */
306 { /* NEC fanrgo5.ttf */
307 { 0x00000000, 0x00000000 }, /* cvt */
308 { 0x2d891cfd, 0x0000019d }, /* fpgm */
309 { 0xa0604633, 0x00001de8 } /* prep */
311 { /* NEC fangot5.ttc */
312 { 0x00000000, 0x00000000 }, /* cvt */
313 { 0x40aa774c, 0x000001cb }, /* fpgm */
314 { 0x9b5caa96, 0x00001f9a } /* prep */
316 { /* NEC fanmin3.ttc */
317 { 0x00000000, 0x00000000 }, /* cvt */
318 { 0x0d3de9cb, 0x00000141 }, /* fpgm */
319 { 0xd4127766, 0x00002280 } /* prep */
324 int num_matched_ids[TRICK_SFNT_IDS_NUM_FACES];
325 FT_Bool has_cvt, has_fpgm, has_prep;
330 FT_MEM_SET( num_matched_ids, 0,
331 sizeof ( int ) * TRICK_SFNT_IDS_NUM_FACES );
336 for ( i = 0; i < face->num_tables; i++ )
340 switch( face->dir_tables[i].Tag )
343 k = TRICK_SFNT_ID_cvt;
348 k = TRICK_SFNT_ID_fpgm;
353 k = TRICK_SFNT_ID_prep;
361 for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
362 if ( face->dir_tables[i].Length == sfnt_id[j][k].Length )
365 checksum = tt_get_sfnt_checksum( face, i );
367 if ( sfnt_id[j][k].CheckSum == checksum )
368 num_matched_ids[j]++;
370 if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
375 for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
377 if ( !has_cvt && !sfnt_id[j][TRICK_SFNT_ID_cvt].Length )
378 num_matched_ids[j] ++;
379 if ( !has_fpgm && !sfnt_id[j][TRICK_SFNT_ID_fpgm].Length )
380 num_matched_ids[j] ++;
381 if ( !has_prep && !sfnt_id[j][TRICK_SFNT_ID_prep].Length )
382 num_matched_ids[j] ++;
383 if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
392 tt_check_trickyness( FT_Face face )
397 /* For first, check the face name for quick check. */
398 if ( face->family_name &&
399 tt_check_trickyness_family( face->family_name ) )
402 /* Type42 fonts may lack `name' tables, we thus try to identify */
403 /* tricky fonts by checking the checksums of Type42-persistent */
404 /* sfnt tables (`cvt', `fpgm', and `prep'). */
405 if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) )
412 /* Check whether `.notdef' is the only glyph in the `loca' table. */
414 tt_check_single_notdef( FT_Face ttface )
416 FT_Bool result = FALSE;
418 TT_Face face = (TT_Face)ttface;
421 FT_ULong glyph_index = 0;
425 for( i = 0; i < face->num_locations; i++ )
427 tt_face_get_location( face, i, &asize );
437 /* Only have a single outline. */
440 if ( glyph_index == 0 )
444 /* FIXME: Need to test glyphname == .notdef ? */
449 error = FT_Get_Glyph_Name( ttface, glyph_index, buf, 8 );
451 buf[0] == '.' && !ft_strncmp( buf, ".notdef", 8 ) )
460 /*************************************************************************/
466 /* Initialize a given TrueType face object. */
469 /* stream :: The source font stream. */
471 /* face_index :: The index of the font face in the resource. */
473 /* num_params :: Number of additional generic parameters. Ignored. */
475 /* params :: Additional generic parameters. Ignored. */
478 /* face :: The newly built face object. */
481 /* FreeType error code. 0 means success. */
483 FT_LOCAL_DEF( FT_Error )
484 tt_face_init( FT_Stream stream,
485 FT_Face ttface, /* TT_Face */
488 FT_Parameter* params )
493 TT_Face face = (TT_Face)ttface;
496 FT_TRACE2(( "TTF driver\n" ));
498 library = ttface->driver->root.library;
500 sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
503 FT_ERROR(( "tt_face_init: cannot access `sfnt' module\n" ));
504 error = TT_Err_Missing_Module;
508 /* create input stream from resource */
509 if ( FT_STREAM_SEEK( 0 ) )
512 /* check that we have a valid TrueType file */
513 error = sfnt->init_face( stream, face, face_index, num_params, params );
517 /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
518 /* The 0x00020000 tag is completely undocumented; some fonts from */
519 /* Arphic made for Chinese Windows 3.1 have this. */
520 if ( face->format_tag != 0x00010000L && /* MS fonts */
521 face->format_tag != 0x00020000L && /* CJK fonts for Win 3.1 */
522 face->format_tag != TTAG_true ) /* Mac fonts */
524 FT_TRACE2(( " not a TTF font\n" ));
528 #ifdef TT_USE_BYTECODE_INTERPRETER
529 ttface->face_flags |= FT_FACE_FLAG_HINTER;
532 /* If we are performing a simple font format check, exit immediately. */
533 if ( face_index < 0 )
536 /* Load font directory */
537 error = sfnt->load_face( stream, face, face_index, num_params, params );
541 if ( tt_check_trickyness( ttface ) )
542 ttface->face_flags |= FT_FACE_FLAG_TRICKY;
544 error = tt_face_load_hdmx( face, stream );
548 if ( FT_IS_SCALABLE( ttface ) )
551 #ifdef FT_CONFIG_OPTION_INCREMENTAL
553 if ( !ttface->internal->incremental_interface )
554 error = tt_face_load_loca( face, stream );
556 error = tt_face_load_cvt( face, stream );
558 error = tt_face_load_fpgm( face, stream );
560 error = tt_face_load_prep( face, stream );
562 /* Check the scalable flag based on `loca'. */
563 if ( !ttface->internal->incremental_interface &&
564 ttface->num_fixed_sizes &&
565 face->glyph_locations &&
566 tt_check_single_notdef( ttface ) )
568 FT_TRACE5(( "tt_face_init:"
569 " Only the `.notdef' glyph has an outline.\n"
571 " Resetting scalable flag to FALSE.\n" ));
573 ttface->face_flags &= ~FT_FACE_FLAG_SCALABLE;
579 error = tt_face_load_loca( face, stream );
581 error = tt_face_load_cvt( face, stream );
583 error = tt_face_load_fpgm( face, stream );
585 error = tt_face_load_prep( face, stream );
587 /* Check the scalable flag based on `loca'. */
588 if ( ttface->num_fixed_sizes &&
589 face->glyph_locations &&
590 tt_check_single_notdef( ttface ) )
592 FT_TRACE5(( "tt_face_init:"
593 " Only the `.notdef' glyph has an outline.\n"
595 " Resetting scalable flag to FALSE.\n" ));
597 ttface->face_flags &= ~FT_FACE_FLAG_SCALABLE;
604 #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
605 !defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
608 FT_Bool unpatented_hinting;
612 /* Determine whether unpatented hinting is to be used for this face. */
613 unpatented_hinting = FT_BOOL
614 ( library->debug_hooks[FT_DEBUG_HOOK_UNPATENTED_HINTING] != NULL );
616 for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
617 if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
618 unpatented_hinting = TRUE;
620 if ( !unpatented_hinting )
621 ttface->internal->ignore_unpatented_hinter = TRUE;
624 #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING &&
625 !TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
627 /* initialize standard glyph loading routines */
628 TT_Init_Glyph_Loading( face );
634 error = TT_Err_Unknown_File_Format;
639 /*************************************************************************/
645 /* Finalize a given face object. */
648 /* face :: A pointer to the face object to destroy. */
651 tt_face_done( FT_Face ttface ) /* TT_Face */
653 TT_Face face = (TT_Face)ttface;
662 memory = ttface->memory;
663 stream = ttface->stream;
664 sfnt = (SFNT_Service)face->sfnt;
666 /* for `extended TrueType formats' (i.e. compressed versions) */
667 if ( face->extra.finalizer )
668 face->extra.finalizer( face->extra.data );
671 sfnt->done_face( face );
673 /* freeing the locations table */
674 tt_face_done_loca( face );
676 tt_face_free_hdmx( face );
678 /* freeing the CVT */
679 FT_FREE( face->cvt );
682 /* freeing the programs */
683 FT_FRAME_RELEASE( face->font_program );
684 FT_FRAME_RELEASE( face->cvt_program );
685 face->font_program_size = 0;
686 face->cvt_program_size = 0;
688 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
689 tt_done_blend( memory, face->blend );
695 /*************************************************************************/
699 /*************************************************************************/
701 #ifdef TT_USE_BYTECODE_INTERPRETER
703 /*************************************************************************/
706 /* tt_size_run_fpgm */
709 /* Run the font program. */
712 /* size :: A handle to the size object. */
714 /* pedantic :: Set if bytecode execution should be pedantic. */
717 /* FreeType error code. 0 means success. */
719 FT_LOCAL_DEF( FT_Error )
720 tt_size_run_fpgm( TT_Size size,
723 TT_Face face = (TT_Face)size->root.face;
728 /* debugging instances have their own context */
730 exec = size->context;
732 exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
735 return TT_Err_Could_Not_Find_Context;
737 TT_Load_Context( exec, face, size );
746 exec->instruction_trap = FALSE;
747 exec->F_dot_P = 0x10000L;
749 exec->pedantic_hinting = pedantic;
752 FT_Size_Metrics* metrics = &exec->metrics;
753 TT_Size_Metrics* tt_metrics = &exec->tt_metrics;
758 metrics->x_scale = 0;
759 metrics->y_scale = 0;
761 tt_metrics->ppem = 0;
762 tt_metrics->scale = 0;
763 tt_metrics->ratio = 0x10000L;
766 /* allow font program execution */
767 TT_Set_CodeRange( exec,
770 face->font_program_size );
772 /* disable CVT and glyph programs coderange */
773 TT_Clear_CodeRange( exec, tt_coderange_cvt );
774 TT_Clear_CodeRange( exec, tt_coderange_glyph );
776 if ( face->font_program_size > 0 )
778 error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
782 FT_TRACE4(( "Executing `fpgm' table.\n" ));
784 error = face->interpreter( exec );
791 TT_Save_Context( exec, size );
797 /*************************************************************************/
800 /* tt_size_run_prep */
803 /* Run the control value program. */
806 /* size :: A handle to the size object. */
808 /* pedantic :: Set if bytecode execution should be pedantic. */
811 /* FreeType error code. 0 means success. */
813 FT_LOCAL_DEF( FT_Error )
814 tt_size_run_prep( TT_Size size,
817 TT_Face face = (TT_Face)size->root.face;
822 /* debugging instances have their own context */
824 exec = size->context;
826 exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
829 return TT_Err_Could_Not_Find_Context;
831 TT_Load_Context( exec, face, size );
836 exec->instruction_trap = FALSE;
838 exec->pedantic_hinting = pedantic;
840 TT_Set_CodeRange( exec,
843 face->cvt_program_size );
845 TT_Clear_CodeRange( exec, tt_coderange_glyph );
847 if ( face->cvt_program_size > 0 )
849 error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
851 if ( !error && !size->debug )
853 FT_TRACE4(( "Executing `prep' table.\n" ));
855 error = face->interpreter( exec );
861 /* save as default graphics state */
864 TT_Save_Context( exec, size );
869 #endif /* TT_USE_BYTECODE_INTERPRETER */
872 #ifdef TT_USE_BYTECODE_INTERPRETER
875 tt_size_done_bytecode( FT_Size ftsize )
877 TT_Size size = (TT_Size)ftsize;
878 TT_Face face = (TT_Face)ftsize->face;
879 FT_Memory memory = face->root.memory;
884 /* the debug context must be deleted by the debugger itself */
885 size->context = NULL;
889 FT_FREE( size->cvt );
892 /* free storage area */
893 FT_FREE( size->storage );
894 size->storage_size = 0;
897 tt_glyphzone_done( &size->twilight );
899 FT_FREE( size->function_defs );
900 FT_FREE( size->instruction_defs );
902 size->num_function_defs = 0;
903 size->max_function_defs = 0;
904 size->num_instruction_defs = 0;
905 size->max_instruction_defs = 0;
910 size->bytecode_ready = 0;
915 /* Initialize bytecode-related fields in the size object. */
916 /* We do this only if bytecode interpretation is really needed. */
918 tt_size_init_bytecode( FT_Size ftsize,
922 TT_Size size = (TT_Size)ftsize;
923 TT_Face face = (TT_Face)ftsize->face;
924 FT_Memory memory = face->root.memory;
927 FT_UShort n_twilight;
928 TT_MaxProfile* maxp = &face->max_profile;
931 size->bytecode_ready = 1;
934 size->max_function_defs = maxp->maxFunctionDefs;
935 size->max_instruction_defs = maxp->maxInstructionDefs;
937 size->num_function_defs = 0;
938 size->num_instruction_defs = 0;
943 size->cvt_size = face->cvt_size;
944 size->storage_size = maxp->maxStorage;
946 /* Set default metrics */
948 TT_Size_Metrics* metrics = &size->ttmetrics;
951 metrics->rotated = FALSE;
952 metrics->stretched = FALSE;
954 /* set default compensation (all 0) */
955 for ( i = 0; i < 4; i++ )
956 metrics->compensations[i] = 0;
959 /* allocate function defs, instruction defs, cvt, and storage area */
960 if ( FT_NEW_ARRAY( size->function_defs, size->max_function_defs ) ||
961 FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
962 FT_NEW_ARRAY( size->cvt, size->cvt_size ) ||
963 FT_NEW_ARRAY( size->storage, size->storage_size ) )
966 /* reserve twilight zone */
967 n_twilight = maxp->maxTwilightPoints;
969 /* there are 4 phantom points (do we need this?) */
972 error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
976 size->twilight.n_points = n_twilight;
978 size->GS = tt_default_graphics_state;
980 /* set `face->interpreter' according to the debug hook present */
982 FT_Library library = face->root.driver->root.library;
985 face->interpreter = (TT_Interpreter)
986 library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
987 if ( !face->interpreter )
988 face->interpreter = (TT_Interpreter)TT_RunIns;
991 /* Fine, now run the font program! */
992 error = tt_size_run_fpgm( size, pedantic );
996 tt_size_done_bytecode( ftsize );
1002 FT_LOCAL_DEF( FT_Error )
1003 tt_size_ready_bytecode( TT_Size size,
1006 FT_Error error = TT_Err_Ok;
1009 if ( !size->bytecode_ready )
1011 error = tt_size_init_bytecode( (FT_Size)size, pedantic );
1016 /* rescale CVT when needed */
1017 if ( !size->cvt_ready )
1020 TT_Face face = (TT_Face)size->root.face;
1023 /* Scale the cvt values to the new ppem. */
1024 /* We use by default the y ppem to scale the CVT. */
1025 for ( i = 0; i < size->cvt_size; i++ )
1026 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
1028 /* all twilight points are originally zero */
1029 for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
1031 size->twilight.org[i].x = 0;
1032 size->twilight.org[i].y = 0;
1033 size->twilight.cur[i].x = 0;
1034 size->twilight.cur[i].y = 0;
1037 /* clear storage area */
1038 for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
1039 size->storage[i] = 0;
1041 size->GS = tt_default_graphics_state;
1043 error = tt_size_run_prep( size, pedantic );
1045 size->cvt_ready = 1;
1052 #endif /* TT_USE_BYTECODE_INTERPRETER */
1055 /*************************************************************************/
1061 /* Initialize a new TrueType size object. */
1064 /* size :: A handle to the size object. */
1067 /* FreeType error code. 0 means success. */
1069 FT_LOCAL_DEF( FT_Error )
1070 tt_size_init( FT_Size ttsize ) /* TT_Size */
1072 TT_Size size = (TT_Size)ttsize;
1073 FT_Error error = TT_Err_Ok;
1075 #ifdef TT_USE_BYTECODE_INTERPRETER
1076 size->bytecode_ready = 0;
1077 size->cvt_ready = 0;
1080 size->ttmetrics.valid = FALSE;
1081 size->strike_index = 0xFFFFFFFFUL;
1087 /*************************************************************************/
1093 /* The TrueType size object finalizer. */
1096 /* size :: A handle to the target size object. */
1098 FT_LOCAL_DEF( void )
1099 tt_size_done( FT_Size ttsize ) /* TT_Size */
1101 TT_Size size = (TT_Size)ttsize;
1104 #ifdef TT_USE_BYTECODE_INTERPRETER
1105 if ( size->bytecode_ready )
1106 tt_size_done_bytecode( ttsize );
1109 size->ttmetrics.valid = FALSE;
1113 /*************************************************************************/
1119 /* Reset a TrueType size when resolutions and character dimensions */
1120 /* have been changed. */
1123 /* size :: A handle to the target size object. */
1125 FT_LOCAL_DEF( FT_Error )
1126 tt_size_reset( TT_Size size )
1129 FT_Error error = TT_Err_Ok;
1130 FT_Size_Metrics* metrics;
1133 size->ttmetrics.valid = FALSE;
1135 face = (TT_Face)size->root.face;
1137 metrics = &size->metrics;
1139 /* copy the result from base layer */
1140 *metrics = size->root.metrics;
1142 if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
1143 return TT_Err_Invalid_PPem;
1145 /* This bit flag, if set, indicates that the ppems must be */
1146 /* rounded to integers. Nearly all TrueType fonts have this bit */
1147 /* set, as hinting won't work really well otherwise. */
1149 if ( face->header.Flags & 8 )
1151 metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
1152 face->root.units_per_EM );
1153 metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
1154 face->root.units_per_EM );
1157 FT_PIX_ROUND( FT_MulFix( face->root.ascender, metrics->y_scale ) );
1158 metrics->descender =
1159 FT_PIX_ROUND( FT_MulFix( face->root.descender, metrics->y_scale ) );
1161 FT_PIX_ROUND( FT_MulFix( face->root.height, metrics->y_scale ) );
1162 metrics->max_advance =
1163 FT_PIX_ROUND( FT_MulFix( face->root.max_advance_width,
1164 metrics->x_scale ) );
1167 /* compute new transformation */
1168 if ( metrics->x_ppem >= metrics->y_ppem )
1170 size->ttmetrics.scale = metrics->x_scale;
1171 size->ttmetrics.ppem = metrics->x_ppem;
1172 size->ttmetrics.x_ratio = 0x10000L;
1173 size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
1179 size->ttmetrics.scale = metrics->y_scale;
1180 size->ttmetrics.ppem = metrics->y_ppem;
1181 size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
1184 size->ttmetrics.y_ratio = 0x10000L;
1187 #ifdef TT_USE_BYTECODE_INTERPRETER
1188 size->cvt_ready = 0;
1189 #endif /* TT_USE_BYTECODE_INTERPRETER */
1192 size->ttmetrics.valid = TRUE;
1198 /*************************************************************************/
1201 /* tt_driver_init */
1204 /* Initialize a given TrueType driver object. */
1207 /* driver :: A handle to the target driver object. */
1210 /* FreeType error code. 0 means success. */
1212 FT_LOCAL_DEF( FT_Error )
1213 tt_driver_init( FT_Module ttdriver ) /* TT_Driver */
1216 #ifdef TT_USE_BYTECODE_INTERPRETER
1218 TT_Driver driver = (TT_Driver)ttdriver;
1221 if ( !TT_New_Context( driver ) )
1222 return TT_Err_Could_Not_Find_Context;
1226 FT_UNUSED( ttdriver );
1234 /*************************************************************************/
1237 /* tt_driver_done */
1240 /* Finalize a given TrueType driver. */
1243 /* driver :: A handle to the target TrueType driver. */
1245 FT_LOCAL_DEF( void )
1246 tt_driver_done( FT_Module ttdriver ) /* TT_Driver */
1248 #ifdef TT_USE_BYTECODE_INTERPRETER
1249 TT_Driver driver = (TT_Driver)ttdriver;
1252 /* destroy the execution context */
1253 if ( driver->context )
1255 TT_Done_Context( driver->context );
1256 driver->context = NULL;
1259 FT_UNUSED( ttdriver );
1265 /*************************************************************************/
1271 /* Initialize a new slot object. */
1274 /* slot :: A handle to the slot object. */
1277 /* FreeType error code. 0 means success. */
1279 FT_LOCAL_DEF( FT_Error )
1280 tt_slot_init( FT_GlyphSlot slot )
1282 return FT_GlyphLoader_CreateExtra( slot->internal->loader );