1 /***************************************************************************/
5 /* Objects manager (body). */
7 /* Copyright 1996-2013 */
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 /***************************************************************************/
19 #include "../../include/ft2build.h"
20 #include "../../include/freetype/internal/ftdebug.h"
21 #include "../../include/freetype/internal/ftstream.h"
22 #include "../../include/freetype/tttags.h"
23 #include "../../include/freetype/internal/sfnt.h"
24 #include "../../include/freetype/ftttdrv.h"
31 #ifdef TT_USE_BYTECODE_INTERPRETER
35 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
36 #include "../../include/freetype/ttunpat.h"
39 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
43 /*************************************************************************/
45 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
46 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
47 /* messages during execution. */
50 #define FT_COMPONENT trace_ttobjs
53 #ifdef TT_USE_BYTECODE_INTERPRETER
55 /*************************************************************************/
57 /* GLYPH ZONE FUNCTIONS */
59 /*************************************************************************/
62 /*************************************************************************/
65 /* tt_glyphzone_done */
68 /* Deallocate a glyph zone. */
71 /* zone :: A pointer to the target glyph zone. */
74 tt_glyphzone_done( TT_GlyphZone zone )
76 FT_Memory memory = zone->memory;
81 FT_FREE( zone->contours );
82 FT_FREE( zone->tags );
85 FT_FREE( zone->orus );
87 zone->max_points = zone->n_points = 0;
88 zone->max_contours = zone->n_contours = 0;
94 /*************************************************************************/
97 /* tt_glyphzone_new */
100 /* Allocate a new glyph zone. */
103 /* memory :: A handle to the current memory object. */
105 /* maxPoints :: The capacity of glyph zone in points. */
107 /* maxContours :: The capacity of glyph zone in contours. */
110 /* zone :: A pointer to the target glyph zone record. */
113 /* FreeType error code. 0 means success. */
115 FT_LOCAL_DEF( FT_Error )
116 tt_glyphzone_new( FT_Memory memory,
118 FT_Short maxContours,
124 FT_MEM_ZERO( zone, sizeof ( *zone ) );
125 zone->memory = memory;
127 if ( FT_NEW_ARRAY( zone->org, maxPoints ) ||
128 FT_NEW_ARRAY( zone->cur, maxPoints ) ||
129 FT_NEW_ARRAY( zone->orus, maxPoints ) ||
130 FT_NEW_ARRAY( zone->tags, maxPoints ) ||
131 FT_NEW_ARRAY( zone->contours, maxContours ) )
133 tt_glyphzone_done( zone );
137 zone->max_points = maxPoints;
138 zone->max_contours = maxContours;
143 #endif /* TT_USE_BYTECODE_INTERPRETER */
146 /* Compare the face with a list of well-known `tricky' fonts. */
147 /* This list shall be expanded as we find more of them. */
150 tt_check_trickyness_family( FT_String* name )
153 #define TRICK_NAMES_MAX_CHARACTERS 16
154 #define TRICK_NAMES_COUNT 8
156 static const char trick_names[TRICK_NAMES_COUNT]
157 [TRICK_NAMES_MAX_CHARACTERS + 1] =
159 "DFKaiSho-SB", /* dfkaisb.ttf */
161 "DFKai-SB", /* kaiu.ttf */
162 "HuaTianKaiTi?", /* htkt2.ttf */
163 "HuaTianSongTi?", /* htst3.ttf */
164 "MingLiU", /* mingliu.ttf & mingliu.ttc */
165 "PMingLiU", /* mingliu.ttc */
166 "MingLi43", /* mingli.ttf */
172 for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ )
173 if ( ft_strstr( name, trick_names[nn] ) )
180 /* XXX: This function should be in the `sfnt' module. */
182 /* Some PDF generators clear the checksums in the TrueType header table. */
183 /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF */
184 /* Printer clears the entries for subsetted subtables. We thus have to */
185 /* recalculate the checksums where necessary. */
188 tt_synth_sfnt_checksum( FT_Stream stream,
192 FT_UInt32 checksum = 0;
196 if ( FT_FRAME_ENTER( length ) )
199 for ( ; length > 3; length -= 4 )
200 checksum += (FT_UInt32)FT_GET_ULONG();
202 for ( i = 3; length > 0; length --, i-- )
203 checksum += (FT_UInt32)( FT_GET_BYTE() << ( i * 8 ) );
211 /* XXX: This function should be in the `sfnt' module. */
214 tt_get_sfnt_checksum( TT_Face face,
217 #if 0 /* if we believe the written value, use following part. */
218 if ( face->dir_tables[i].CheckSum )
219 return face->dir_tables[i].CheckSum;
222 if ( !face->goto_table )
225 if ( face->goto_table( face,
226 face->dir_tables[i].Tag,
231 return (FT_ULong)tt_synth_sfnt_checksum( face->root.stream,
232 face->dir_tables[i].Length );
236 typedef struct tt_sfnt_id_rec_
245 tt_check_trickyness_sfnt_ids( TT_Face face )
247 #define TRICK_SFNT_IDS_PER_FACE 3
248 #define TRICK_SFNT_IDS_NUM_FACES 17
250 static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES]
251 [TRICK_SFNT_IDS_PER_FACE] = {
253 #define TRICK_SFNT_ID_cvt 0
254 #define TRICK_SFNT_ID_fpgm 1
255 #define TRICK_SFNT_ID_prep 2
258 { 0x05bcf058, 0x000002e4 }, /* cvt */
259 { 0x28233bf1, 0x000087c4 }, /* fpgm */
260 { 0xa344a1ea, 0x000001e1 } /* prep */
262 { /* MingLiU 1996- */
263 { 0x05bcf058, 0x000002e4 }, /* cvt */
264 { 0x28233bf1, 0x000087c4 }, /* fpgm */
265 { 0xa344a1eb, 0x000001e1 } /* prep */
268 { 0x11e5ead4, 0x00000350 }, /* cvt */
269 { 0x5a30ca3b, 0x00009063 }, /* fpgm */
270 { 0x13a42602, 0x0000007e } /* prep */
273 { 0xfffbfffc, 0x00000008 }, /* cvt */
274 { 0x9c9e48b8, 0x0000bea2 }, /* fpgm */
275 { 0x70020112, 0x00000008 } /* prep */
277 { /* HuaTianSongTi */
278 { 0xfffbfffc, 0x00000008 }, /* cvt */
279 { 0x0a5a0483, 0x00017c39 }, /* fpgm */
280 { 0x70020112, 0x00000008 } /* prep */
282 { /* NEC fadpop7.ttf */
283 { 0x00000000, 0x00000000 }, /* cvt */
284 { 0x40c92555, 0x000000e5 }, /* fpgm */
285 { 0xa39b58e3, 0x0000117c } /* prep */
287 { /* NEC fadrei5.ttf */
288 { 0x00000000, 0x00000000 }, /* cvt */
289 { 0x33c41652, 0x000000e5 }, /* fpgm */
290 { 0x26d6c52a, 0x00000f6a } /* prep */
292 { /* NEC fangot7.ttf */
293 { 0x00000000, 0x00000000 }, /* cvt */
294 { 0x6db1651d, 0x0000019d }, /* fpgm */
295 { 0x6c6e4b03, 0x00002492 } /* prep */
297 { /* NEC fangyo5.ttf */
298 { 0x00000000, 0x00000000 }, /* cvt */
299 { 0x40c92555, 0x000000e5 }, /* fpgm */
300 { 0xde51fad0, 0x0000117c } /* prep */
302 { /* NEC fankyo5.ttf */
303 { 0x00000000, 0x00000000 }, /* cvt */
304 { 0x85e47664, 0x000000e5 }, /* fpgm */
305 { 0xa6c62831, 0x00001caa } /* prep */
307 { /* NEC fanrgo5.ttf */
308 { 0x00000000, 0x00000000 }, /* cvt */
309 { 0x2d891cfd, 0x0000019d }, /* fpgm */
310 { 0xa0604633, 0x00001de8 } /* prep */
312 { /* NEC fangot5.ttc */
313 { 0x00000000, 0x00000000 }, /* cvt */
314 { 0x40aa774c, 0x000001cb }, /* fpgm */
315 { 0x9b5caa96, 0x00001f9a } /* prep */
317 { /* NEC fanmin3.ttc */
318 { 0x00000000, 0x00000000 }, /* cvt */
319 { 0x0d3de9cb, 0x00000141 }, /* fpgm */
320 { 0xd4127766, 0x00002280 } /* prep */
322 { /* NEC FA-Gothic, 1996 */
323 { 0x00000000, 0x00000000 }, /* cvt */
324 { 0x4a692698, 0x000001f0 }, /* fpgm */
325 { 0x340d4346, 0x00001fca } /* prep */
327 { /* NEC FA-Minchou, 1996 */
328 { 0x00000000, 0x00000000 }, /* cvt */
329 { 0xcd34c604, 0x00000166 }, /* fpgm */
330 { 0x6cf31046, 0x000022b0 } /* prep */
332 { /* NEC FA-RoundGothicB, 1996 */
333 { 0x00000000, 0x00000000 }, /* cvt */
334 { 0x5da75315, 0x0000019d }, /* fpgm */
335 { 0x40745a5f, 0x000022e0 } /* prep */
337 { /* NEC FA-RoundGothicM, 1996 */
338 { 0x00000000, 0x00000000 }, /* cvt */
339 { 0xf055fc48, 0x000001c2 }, /* fpgm */
340 { 0x3900ded3, 0x00001e18 } /* prep */
345 int num_matched_ids[TRICK_SFNT_IDS_NUM_FACES];
346 FT_Bool has_cvt, has_fpgm, has_prep;
351 FT_MEM_SET( num_matched_ids, 0,
352 sizeof ( int ) * TRICK_SFNT_IDS_NUM_FACES );
357 for ( i = 0; i < face->num_tables; i++ )
361 switch( face->dir_tables[i].Tag )
364 k = TRICK_SFNT_ID_cvt;
369 k = TRICK_SFNT_ID_fpgm;
374 k = TRICK_SFNT_ID_prep;
382 for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
383 if ( face->dir_tables[i].Length == sfnt_id[j][k].Length )
386 checksum = tt_get_sfnt_checksum( face, i );
388 if ( sfnt_id[j][k].CheckSum == checksum )
389 num_matched_ids[j]++;
391 if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
396 for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
398 if ( !has_cvt && !sfnt_id[j][TRICK_SFNT_ID_cvt].Length )
399 num_matched_ids[j] ++;
400 if ( !has_fpgm && !sfnt_id[j][TRICK_SFNT_ID_fpgm].Length )
401 num_matched_ids[j] ++;
402 if ( !has_prep && !sfnt_id[j][TRICK_SFNT_ID_prep].Length )
403 num_matched_ids[j] ++;
404 if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
413 tt_check_trickyness( FT_Face face )
418 /* For first, check the face name for quick check. */
419 if ( face->family_name &&
420 tt_check_trickyness_family( face->family_name ) )
423 /* Type42 fonts may lack `name' tables, we thus try to identify */
424 /* tricky fonts by checking the checksums of Type42-persistent */
425 /* sfnt tables (`cvt', `fpgm', and `prep'). */
426 if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) )
433 /* Check whether `.notdef' is the only glyph in the `loca' table. */
435 tt_check_single_notdef( FT_Face ttface )
437 FT_Bool result = FALSE;
439 TT_Face face = (TT_Face)ttface;
442 FT_ULong glyph_index = 0;
446 for( i = 0; i < face->num_locations; i++ )
448 tt_face_get_location( face, i, &asize );
458 /* Only have a single outline. */
461 if ( glyph_index == 0 )
465 /* FIXME: Need to test glyphname == .notdef ? */
470 error = FT_Get_Glyph_Name( ttface, glyph_index, buf, 8 );
472 buf[0] == '.' && !ft_strncmp( buf, ".notdef", 8 ) )
481 /*************************************************************************/
487 /* Initialize a given TrueType face object. */
490 /* stream :: The source font stream. */
492 /* face_index :: The index of the font face in the resource. */
494 /* num_params :: Number of additional generic parameters. Ignored. */
496 /* params :: Additional generic parameters. Ignored. */
499 /* face :: The newly built face object. */
502 /* FreeType error code. 0 means success. */
504 FT_LOCAL_DEF( FT_Error )
505 tt_face_init( FT_Stream stream,
506 FT_Face ttface, /* TT_Face */
509 FT_Parameter* params )
514 TT_Face face = (TT_Face)ttface;
517 FT_TRACE2(( "TTF driver\n" ));
519 library = ttface->driver->root.library;
521 sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
524 FT_ERROR(( "tt_face_init: cannot access `sfnt' module\n" ));
525 error = FT_THROW( Missing_Module );
529 /* create input stream from resource */
530 if ( FT_STREAM_SEEK( 0 ) )
533 /* check that we have a valid TrueType file */
534 error = sfnt->init_face( stream, face, face_index, num_params, params );
538 /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
539 /* The 0x00020000 tag is completely undocumented; some fonts from */
540 /* Arphic made for Chinese Windows 3.1 have this. */
541 if ( face->format_tag != 0x00010000L && /* MS fonts */
542 face->format_tag != 0x00020000L && /* CJK fonts for Win 3.1 */
543 face->format_tag != TTAG_true ) /* Mac fonts */
545 FT_TRACE2(( " not a TTF font\n" ));
551 if (face->goto_table( face, TTAG_CFF, stream, &table_len) != TT_Err_Table_Missing &&
552 face->goto_table( face, TTAG_loca, stream, &table_len) == TT_Err_Table_Missing)
554 FT_TRACE2(( "[not a valid TTF font]\n" ));
559 #ifdef TT_USE_BYTECODE_INTERPRETER
560 ttface->face_flags |= FT_FACE_FLAG_HINTER;
563 /* If we are performing a simple font format check, exit immediately. */
564 if ( face_index < 0 )
567 /* Load font directory */
568 error = sfnt->load_face( stream, face, face_index, num_params, params );
572 if ( tt_check_trickyness( ttface ) )
573 ttface->face_flags |= FT_FACE_FLAG_TRICKY;
575 error = tt_face_load_hdmx( face, stream );
579 if ( FT_IS_SCALABLE( ttface ) )
582 #ifdef FT_CONFIG_OPTION_INCREMENTAL
584 if ( !ttface->internal->incremental_interface )
585 error = tt_face_load_loca( face, stream );
587 error = tt_face_load_cvt( face, stream );
589 error = tt_face_load_fpgm( face, stream );
591 error = tt_face_load_prep( face, stream );
593 /* Check the scalable flag based on `loca'. */
594 if ( !ttface->internal->incremental_interface &&
595 ttface->num_fixed_sizes &&
596 face->glyph_locations &&
597 tt_check_single_notdef( ttface ) )
599 FT_TRACE5(( "tt_face_init:"
600 " Only the `.notdef' glyph has an outline.\n"
602 " Resetting scalable flag to FALSE.\n" ));
604 ttface->face_flags &= ~FT_FACE_FLAG_SCALABLE;
610 error = tt_face_load_loca( face, stream );
612 error = tt_face_load_cvt( face, stream );
614 error = tt_face_load_fpgm( face, stream );
616 error = tt_face_load_prep( face, stream );
618 /* Check the scalable flag based on `loca'. */
619 if ( ttface->num_fixed_sizes &&
620 face->glyph_locations &&
621 tt_check_single_notdef( ttface ) )
623 FT_TRACE5(( "tt_face_init:"
624 " Only the `.notdef' glyph has an outline.\n"
626 " Resetting scalable flag to FALSE.\n" ));
628 ttface->face_flags &= ~FT_FACE_FLAG_SCALABLE;
635 #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
636 !defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
639 FT_Bool unpatented_hinting;
643 /* Determine whether unpatented hinting is to be used for this face. */
644 unpatented_hinting = FT_BOOL
645 ( library->debug_hooks[FT_DEBUG_HOOK_UNPATENTED_HINTING] != NULL );
647 for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
648 if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
649 unpatented_hinting = TRUE;
651 if ( !unpatented_hinting )
652 ttface->internal->ignore_unpatented_hinter = TRUE;
655 #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING &&
656 !TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
658 /* initialize standard glyph loading routines */
659 TT_Init_Glyph_Loading( face );
665 error = FT_THROW( Unknown_File_Format );
670 /*************************************************************************/
676 /* Finalize a given face object. */
679 /* face :: A pointer to the face object to destroy. */
682 tt_face_done( FT_Face ttface ) /* TT_Face */
684 TT_Face face = (TT_Face)ttface;
693 memory = ttface->memory;
694 stream = ttface->stream;
695 sfnt = (SFNT_Service)face->sfnt;
697 /* for `extended TrueType formats' (i.e. compressed versions) */
698 if ( face->extra.finalizer )
699 face->extra.finalizer( face->extra.data );
702 sfnt->done_face( face );
704 /* freeing the locations table */
705 tt_face_done_loca( face );
707 tt_face_free_hdmx( face );
709 /* freeing the CVT */
710 FT_FREE( face->cvt );
713 /* freeing the programs */
714 FT_FRAME_RELEASE( face->font_program );
715 FT_FRAME_RELEASE( face->cvt_program );
716 face->font_program_size = 0;
717 face->cvt_program_size = 0;
719 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
720 tt_done_blend( memory, face->blend );
726 /*************************************************************************/
730 /*************************************************************************/
732 #ifdef TT_USE_BYTECODE_INTERPRETER
734 /*************************************************************************/
737 /* tt_size_run_fpgm */
740 /* Run the font program. */
743 /* size :: A handle to the size object. */
745 /* pedantic :: Set if bytecode execution should be pedantic. */
748 /* FreeType error code. 0 means success. */
750 FT_LOCAL_DEF( FT_Error )
751 tt_size_run_fpgm( TT_Size size,
754 TT_Face face = (TT_Face)size->root.face;
759 /* debugging instances have their own context */
761 exec = size->context;
763 exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
766 return FT_THROW( Could_Not_Find_Context );
768 TT_Load_Context( exec, face, size );
777 exec->instruction_trap = FALSE;
778 exec->F_dot_P = 0x4000L;
780 exec->pedantic_hinting = pedantic;
783 FT_Size_Metrics* metrics = &exec->metrics;
784 TT_Size_Metrics* tt_metrics = &exec->tt_metrics;
789 metrics->x_scale = 0;
790 metrics->y_scale = 0;
792 tt_metrics->ppem = 0;
793 tt_metrics->scale = 0;
794 tt_metrics->ratio = 0x10000L;
797 /* allow font program execution */
798 TT_Set_CodeRange( exec,
801 face->font_program_size );
803 /* disable CVT and glyph programs coderange */
804 TT_Clear_CodeRange( exec, tt_coderange_cvt );
805 TT_Clear_CodeRange( exec, tt_coderange_glyph );
807 if ( face->font_program_size > 0 )
809 error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
813 FT_TRACE4(( "Executing `fpgm' table.\n" ));
815 error = face->interpreter( exec );
822 TT_Save_Context( exec, size );
828 /*************************************************************************/
831 /* tt_size_run_prep */
834 /* Run the control value program. */
837 /* size :: A handle to the size object. */
839 /* pedantic :: Set if bytecode execution should be pedantic. */
842 /* FreeType error code. 0 means success. */
844 FT_LOCAL_DEF( FT_Error )
845 tt_size_run_prep( TT_Size size,
848 TT_Face face = (TT_Face)size->root.face;
853 /* debugging instances have their own context */
855 exec = size->context;
857 exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
860 return FT_THROW( Could_Not_Find_Context );
862 TT_Load_Context( exec, face, size );
867 exec->instruction_trap = FALSE;
869 exec->pedantic_hinting = pedantic;
871 TT_Set_CodeRange( exec,
874 face->cvt_program_size );
876 TT_Clear_CodeRange( exec, tt_coderange_glyph );
878 if ( face->cvt_program_size > 0 )
880 error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
882 if ( !error && !size->debug )
884 FT_TRACE4(( "Executing `prep' table.\n" ));
886 error = face->interpreter( exec );
892 /* UNDOCUMENTED! The MS rasterizer doesn't allow the following */
893 /* graphics state variables to be modified by the CVT program. */
895 exec->GS.dualVector.x = 0x4000;
896 exec->GS.dualVector.y = 0;
897 exec->GS.projVector.x = 0x4000;
898 exec->GS.projVector.y = 0x0;
899 exec->GS.freeVector.x = 0x4000;
900 exec->GS.freeVector.y = 0x0;
912 /* save as default graphics state */
915 TT_Save_Context( exec, size );
920 #endif /* TT_USE_BYTECODE_INTERPRETER */
923 #ifdef TT_USE_BYTECODE_INTERPRETER
926 tt_size_done_bytecode( FT_Size ftsize )
928 TT_Size size = (TT_Size)ftsize;
929 TT_Face face = (TT_Face)ftsize->face;
930 FT_Memory memory = face->root.memory;
935 /* the debug context must be deleted by the debugger itself */
936 size->context = NULL;
940 FT_FREE( size->cvt );
943 /* free storage area */
944 FT_FREE( size->storage );
945 size->storage_size = 0;
948 tt_glyphzone_done( &size->twilight );
950 FT_FREE( size->function_defs );
951 FT_FREE( size->instruction_defs );
953 size->num_function_defs = 0;
954 size->max_function_defs = 0;
955 size->num_instruction_defs = 0;
956 size->max_instruction_defs = 0;
961 size->bytecode_ready = 0;
966 /* Initialize bytecode-related fields in the size object. */
967 /* We do this only if bytecode interpretation is really needed. */
969 tt_size_init_bytecode( FT_Size ftsize,
973 TT_Size size = (TT_Size)ftsize;
974 TT_Face face = (TT_Face)ftsize->face;
975 FT_Memory memory = face->root.memory;
978 FT_UShort n_twilight;
979 TT_MaxProfile* maxp = &face->max_profile;
982 size->bytecode_ready = 1;
985 size->max_function_defs = maxp->maxFunctionDefs;
986 size->max_instruction_defs = maxp->maxInstructionDefs;
988 size->num_function_defs = 0;
989 size->num_instruction_defs = 0;
994 size->cvt_size = face->cvt_size;
995 size->storage_size = maxp->maxStorage;
997 /* Set default metrics */
999 TT_Size_Metrics* metrics = &size->ttmetrics;
1002 metrics->rotated = FALSE;
1003 metrics->stretched = FALSE;
1005 /* set default compensation (all 0) */
1006 for ( i = 0; i < 4; i++ )
1007 metrics->compensations[i] = 0;
1010 /* allocate function defs, instruction defs, cvt, and storage area */
1011 if ( FT_NEW_ARRAY( size->function_defs, size->max_function_defs ) ||
1012 FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
1013 FT_NEW_ARRAY( size->cvt, size->cvt_size ) ||
1014 FT_NEW_ARRAY( size->storage, size->storage_size ) )
1017 /* reserve twilight zone */
1018 n_twilight = maxp->maxTwilightPoints;
1020 /* there are 4 phantom points (do we need this?) */
1023 error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
1027 size->twilight.n_points = n_twilight;
1029 size->GS = tt_default_graphics_state;
1031 /* set `face->interpreter' according to the debug hook present */
1033 FT_Library library = face->root.driver->root.library;
1036 face->interpreter = (TT_Interpreter)
1037 library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
1038 if ( !face->interpreter )
1039 face->interpreter = (TT_Interpreter)TT_RunIns;
1042 /* Fine, now run the font program! */
1043 error = tt_size_run_fpgm( size, pedantic );
1044 /* It seems fpgm proc is causing some problem for some font, so we ignore the error. TESTDOC: Bug #12690 - Restaurantkarte_Oktober09+Wild.pdf*/
1046 tt_size_done_bytecode( ftsize );
1051 tt_size_done_bytecode( ftsize );
1057 FT_LOCAL_DEF( FT_Error )
1058 tt_size_ready_bytecode( TT_Size size,
1061 FT_Error error = FT_Err_Ok;
1064 if ( !size->bytecode_ready )
1066 error = tt_size_init_bytecode( (FT_Size)size, pedantic );
1071 /* rescale CVT when needed */
1072 if ( !size->cvt_ready )
1075 TT_Face face = (TT_Face)size->root.face;
1078 /* Scale the cvt values to the new ppem. */
1079 /* We use by default the y ppem to scale the CVT. */
1080 for ( i = 0; i < size->cvt_size; i++ )
1081 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
1083 /* all twilight points are originally zero */
1084 for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
1086 size->twilight.org[i].x = 0;
1087 size->twilight.org[i].y = 0;
1088 size->twilight.cur[i].x = 0;
1089 size->twilight.cur[i].y = 0;
1092 /* clear storage area */
1093 for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
1094 size->storage[i] = 0;
1096 size->GS = tt_default_graphics_state;
1098 tt_size_run_prep( size, pedantic );/* It seems prep proc is causing some problem for some font, so we ignore the error. TESTDOC: Bug #5025 - naredba-rd-16-296.pdf */
1099 /* However we can't disable the prep. TESTDOC: Bug #0063 - 050826_differ_table.pdf, page #4 */
1101 size->cvt_ready = 1;
1108 #endif /* TT_USE_BYTECODE_INTERPRETER */
1111 /*************************************************************************/
1117 /* Initialize a new TrueType size object. */
1120 /* size :: A handle to the size object. */
1123 /* FreeType error code. 0 means success. */
1125 FT_LOCAL_DEF( FT_Error )
1126 tt_size_init( FT_Size ttsize ) /* TT_Size */
1128 TT_Size size = (TT_Size)ttsize;
1129 FT_Error error = FT_Err_Ok;
1131 #ifdef TT_USE_BYTECODE_INTERPRETER
1132 size->bytecode_ready = 0;
1133 size->cvt_ready = 0;
1136 size->ttmetrics.valid = FALSE;
1137 size->strike_index = 0xFFFFFFFFUL;
1143 /*************************************************************************/
1149 /* The TrueType size object finalizer. */
1152 /* size :: A handle to the target size object. */
1154 FT_LOCAL_DEF( void )
1155 tt_size_done( FT_Size ttsize ) /* TT_Size */
1157 TT_Size size = (TT_Size)ttsize;
1160 #ifdef TT_USE_BYTECODE_INTERPRETER
1161 if ( size->bytecode_ready )
1162 tt_size_done_bytecode( ttsize );
1165 size->ttmetrics.valid = FALSE;
1169 /*************************************************************************/
1175 /* Reset a TrueType size when resolutions and character dimensions */
1176 /* have been changed. */
1179 /* size :: A handle to the target size object. */
1181 FT_LOCAL_DEF( FT_Error )
1182 tt_size_reset( TT_Size size )
1185 FT_Error error = FT_Err_Ok;
1186 FT_Size_Metrics* metrics;
1189 size->ttmetrics.valid = FALSE;
1191 face = (TT_Face)size->root.face;
1193 metrics = &size->metrics;
1195 /* copy the result from base layer */
1196 *metrics = size->root.metrics;
1198 if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
1199 return FT_THROW( Invalid_PPem );
1201 /* This bit flag, if set, indicates that the ppems must be */
1202 /* rounded to integers. Nearly all TrueType fonts have this bit */
1203 /* set, as hinting won't work really well otherwise. */
1205 if ( face->header.Flags & 8 )
1207 metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
1208 face->root.units_per_EM );
1209 metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
1210 face->root.units_per_EM );
1213 FT_PIX_ROUND( FT_MulFix( face->root.ascender, metrics->y_scale ) );
1214 metrics->descender =
1215 FT_PIX_ROUND( FT_MulFix( face->root.descender, metrics->y_scale ) );
1217 FT_PIX_ROUND( FT_MulFix( face->root.height, metrics->y_scale ) );
1218 metrics->max_advance =
1219 FT_PIX_ROUND( FT_MulFix( face->root.max_advance_width,
1220 metrics->x_scale ) );
1223 /* compute new transformation */
1224 if ( metrics->x_ppem >= metrics->y_ppem )
1226 size->ttmetrics.scale = metrics->x_scale;
1227 size->ttmetrics.ppem = metrics->x_ppem;
1228 size->ttmetrics.x_ratio = 0x10000L;
1229 size->ttmetrics.y_ratio = FT_DivFix( metrics->y_ppem,
1234 size->ttmetrics.scale = metrics->y_scale;
1235 size->ttmetrics.ppem = metrics->y_ppem;
1236 size->ttmetrics.x_ratio = FT_DivFix( metrics->x_ppem,
1238 size->ttmetrics.y_ratio = 0x10000L;
1241 #ifdef TT_USE_BYTECODE_INTERPRETER
1242 size->cvt_ready = 0;
1243 #endif /* TT_USE_BYTECODE_INTERPRETER */
1246 size->ttmetrics.valid = TRUE;
1252 /*************************************************************************/
1255 /* tt_driver_init */
1258 /* Initialize a given TrueType driver object. */
1261 /* driver :: A handle to the target driver object. */
1264 /* FreeType error code. 0 means success. */
1266 FT_LOCAL_DEF( FT_Error )
1267 tt_driver_init( FT_Module ttdriver ) /* TT_Driver */
1270 #ifdef TT_USE_BYTECODE_INTERPRETER
1272 TT_Driver driver = (TT_Driver)ttdriver;
1275 if ( !TT_New_Context( driver ) )
1276 return FT_THROW( Could_Not_Find_Context );
1278 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
1279 driver->interpreter_version = TT_INTERPRETER_VERSION_38;
1281 driver->interpreter_version = TT_INTERPRETER_VERSION_35;
1284 #else /* !TT_USE_BYTECODE_INTERPRETER */
1286 FT_UNUSED( ttdriver );
1288 #endif /* !TT_USE_BYTECODE_INTERPRETER */
1294 /*************************************************************************/
1297 /* tt_driver_done */
1300 /* Finalize a given TrueType driver. */
1303 /* driver :: A handle to the target TrueType driver. */
1305 FT_LOCAL_DEF( void )
1306 tt_driver_done( FT_Module ttdriver ) /* TT_Driver */
1308 #ifdef TT_USE_BYTECODE_INTERPRETER
1309 TT_Driver driver = (TT_Driver)ttdriver;
1312 /* destroy the execution context */
1313 if ( driver->context )
1315 TT_Done_Context( driver->context );
1316 driver->context = NULL;
1319 FT_UNUSED( ttdriver );
1325 /*************************************************************************/
1331 /* Initialize a new slot object. */
1334 /* slot :: A handle to the slot object. */
1337 /* FreeType error code. 0 means success. */
1339 FT_LOCAL_DEF( FT_Error )
1340 tt_slot_init( FT_GlyphSlot slot )
1342 return FT_GlyphLoader_CreateExtra( slot->internal->loader );