1 /***************************************************************************/ 2 /* */ 3 /* ttobjs.c */ 4 /* */ 5 /* Objects manager (body). */ 6 /* */ 7 /* Copyright 1996-2018 by */ 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 /* */ 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. */ 15 /* */ 16 /***************************************************************************/ 17 18 19 #include <ft2build.h> 20 #include FT_INTERNAL_DEBUG_H 21 #include FT_INTERNAL_STREAM_H 22 #include FT_TRUETYPE_TAGS_H 23 #include FT_INTERNAL_SFNT_H 24 #include FT_DRIVER_H 25 26 #include "ttgload.h" 27 #include "ttpload.h" 28 29 #include "tterrors.h" 30 31 #ifdef TT_USE_BYTECODE_INTERPRETER 32 #include "ttinterp.h" 33 #endif 34 35 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 36 #include "ttgxvar.h" 37 #endif 38 39 /*************************************************************************/ 40 /* */ 41 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 42 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 43 /* messages during execution. */ 44 /* */ 45 #undef FT_COMPONENT 46 #define FT_COMPONENT trace_ttobjs 47 48 49 #ifdef TT_USE_BYTECODE_INTERPRETER 50 51 /*************************************************************************/ 52 /* */ 53 /* GLYPH ZONE FUNCTIONS */ 54 /* */ 55 /*************************************************************************/ 56 57 58 /*************************************************************************/ 59 /* */ 60 /* <Function> */ 61 /* tt_glyphzone_done */ 62 /* */ 63 /* <Description> */ 64 /* Deallocate a glyph zone. */ 65 /* */ 66 /* <Input> */ 67 /* zone :: A pointer to the target glyph zone. */ 68 /* */ 69 FT_LOCAL_DEF( void ) 70 tt_glyphzone_done( TT_GlyphZone zone ) 71 { 72 FT_Memory memory = zone->memory; 73 74 75 if ( memory ) 76 { 77 FT_FREE( zone->contours ); 78 FT_FREE( zone->tags ); 79 FT_FREE( zone->cur ); 80 FT_FREE( zone->org ); 81 FT_FREE( zone->orus ); 82 83 zone->max_points = zone->n_points = 0; 84 zone->max_contours = zone->n_contours = 0; 85 zone->memory = NULL; 86 } 87 } 88 89 90 /*************************************************************************/ 91 /* */ 92 /* <Function> */ 93 /* tt_glyphzone_new */ 94 /* */ 95 /* <Description> */ 96 /* Allocate a new glyph zone. */ 97 /* */ 98 /* <Input> */ 99 /* memory :: A handle to the current memory object. */ 100 /* */ 101 /* maxPoints :: The capacity of glyph zone in points. */ 102 /* */ 103 /* maxContours :: The capacity of glyph zone in contours. */ 104 /* */ 105 /* <Output> */ 106 /* zone :: A pointer to the target glyph zone record. */ 107 /* */ 108 /* <Return> */ 109 /* FreeType error code. 0 means success. */ 110 /* */ 111 FT_LOCAL_DEF( FT_Error ) 112 tt_glyphzone_new( FT_Memory memory, 113 FT_UShort maxPoints, 114 FT_Short maxContours, 115 TT_GlyphZone zone ) 116 { 117 FT_Error error; 118 119 120 FT_ZERO( zone ); 121 zone->memory = memory; 122 123 if ( FT_NEW_ARRAY( zone->org, maxPoints ) || 124 FT_NEW_ARRAY( zone->cur, maxPoints ) || 125 FT_NEW_ARRAY( zone->orus, maxPoints ) || 126 FT_NEW_ARRAY( zone->tags, maxPoints ) || 127 FT_NEW_ARRAY( zone->contours, maxContours ) ) 128 { 129 tt_glyphzone_done( zone ); 130 } 549 if ( glyph_index == 0 ) 550 result = TRUE; 551 else 552 { 553 /* FIXME: Need to test glyphname == .notdef ? */ 554 FT_Error error; 555 char buf[8]; 556 557 558 error = FT_Get_Glyph_Name( ttface, glyph_index, buf, 8 ); 559 if ( !error && 560 buf[0] == '.' && !ft_strncmp( buf, ".notdef", 8 ) ) 561 result = TRUE; 562 } 563 } 564 565 return result; 566 } 567 568 569 /*************************************************************************/ 570 /* */ 571 /* <Function> */ 572 /* tt_face_init */ 573 /* */ 574 /* <Description> */ 575 /* Initialize a given TrueType face object. */ 576 /* */ 577 /* <Input> */ 578 /* stream :: The source font stream. */ 579 /* */ 580 /* face_index :: The index of the TrueType font, if we are opening a */ 581 /* collection, in bits 0-15. The numbered instance */ 582 /* index~+~1 of a GX (sub)font, if applicable, in bits */ 583 /* 16-30. */ 584 /* */ 585 /* num_params :: Number of additional generic parameters. Ignored. */ 586 /* */ 587 /* params :: Additional generic parameters. Ignored. */ 588 /* */ 589 /* <InOut> */ 590 /* face :: The newly built face object. */ 591 /* */ 592 /* <Return> */ 593 /* FreeType error code. 0 means success. */ 594 /* */ 595 FT_LOCAL_DEF( FT_Error ) 596 tt_face_init( FT_Stream stream, 597 FT_Face ttface, /* TT_Face */ 598 FT_Int face_index, 599 FT_Int num_params, 600 FT_Parameter* params ) 601 { 602 FT_Error error; 603 FT_Library library; 604 SFNT_Service sfnt; 605 TT_Face face = (TT_Face)ttface; 606 607 608 FT_TRACE2(( "TTF driver\n" )); 609 610 library = ttface->driver->root.library; 611 612 sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); 613 if ( !sfnt ) 614 { 726 goto Exit; 727 728 tt_apply_mvar( face ); 729 } 730 } 731 732 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 733 734 /* initialize standard glyph loading routines */ 735 TT_Init_Glyph_Loading( face ); 736 737 Exit: 738 return error; 739 740 Bad_Format: 741 error = FT_THROW( Unknown_File_Format ); 742 goto Exit; 743 } 744 745 746 /*************************************************************************/ 747 /* */ 748 /* <Function> */ 749 /* tt_face_done */ 750 /* */ 751 /* <Description> */ 752 /* Finalize a given face object. */ 753 /* */ 754 /* <Input> */ 755 /* face :: A pointer to the face object to destroy. */ 756 /* */ 757 FT_LOCAL_DEF( void ) 758 tt_face_done( FT_Face ttface ) /* TT_Face */ 759 { 760 TT_Face face = (TT_Face)ttface; 761 FT_Memory memory; 762 FT_Stream stream; 763 SFNT_Service sfnt; 764 765 766 if ( !face ) 767 return; 768 769 memory = ttface->memory; 770 stream = ttface->stream; 771 sfnt = (SFNT_Service)face->sfnt; 772 773 /* for `extended TrueType formats' (i.e. compressed versions) */ 774 if ( face->extra.finalizer ) 775 face->extra.finalizer( face->extra.data ); 776 782 783 tt_face_free_hdmx( face ); 784 785 /* freeing the CVT */ 786 FT_FREE( face->cvt ); 787 face->cvt_size = 0; 788 789 /* freeing the programs */ 790 FT_FRAME_RELEASE( face->font_program ); 791 FT_FRAME_RELEASE( face->cvt_program ); 792 face->font_program_size = 0; 793 face->cvt_program_size = 0; 794 795 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 796 tt_done_blend( face ); 797 face->blend = NULL; 798 #endif 799 } 800 801 802 /*************************************************************************/ 803 /* */ 804 /* SIZE FUNCTIONS */ 805 /* */ 806 /*************************************************************************/ 807 808 #ifdef TT_USE_BYTECODE_INTERPRETER 809 810 /*************************************************************************/ 811 /* */ 812 /* <Function> */ 813 /* tt_size_run_fpgm */ 814 /* */ 815 /* <Description> */ 816 /* Run the font program. */ 817 /* */ 818 /* <Input> */ 819 /* size :: A handle to the size object. */ 820 /* */ 821 /* pedantic :: Set if bytecode execution should be pedantic. */ 822 /* */ 823 /* <Return> */ 824 /* FreeType error code. 0 means success. */ 825 /* */ 826 FT_LOCAL_DEF( FT_Error ) 827 tt_size_run_fpgm( TT_Size size, 828 FT_Bool pedantic ) 829 { 830 TT_Face face = (TT_Face)size->root.face; 831 TT_ExecContext exec; 832 FT_Error error; 833 834 835 exec = size->context; 836 837 error = TT_Load_Context( exec, face, size ); 838 if ( error ) 839 return error; 840 841 exec->callTop = 0; 842 exec->top = 0; 843 844 exec->period = 64; 845 exec->phase = 0; 882 FT_TRACE4(( "Executing `fpgm' table.\n" )); 883 error = face->interpreter( exec ); 884 #ifdef FT_DEBUG_LEVEL_TRACE 885 if ( error ) 886 FT_TRACE4(( " interpretation failed with error code 0x%x\n", 887 error )); 888 #endif 889 } 890 else 891 error = FT_Err_Ok; 892 893 size->bytecode_ready = error; 894 895 if ( !error ) 896 TT_Save_Context( exec, size ); 897 898 return error; 899 } 900 901 902 /*************************************************************************/ 903 /* */ 904 /* <Function> */ 905 /* tt_size_run_prep */ 906 /* */ 907 /* <Description> */ 908 /* Run the control value program. */ 909 /* */ 910 /* <Input> */ 911 /* size :: A handle to the size object. */ 912 /* */ 913 /* pedantic :: Set if bytecode execution should be pedantic. */ 914 /* */ 915 /* <Return> */ 916 /* FreeType error code. 0 means success. */ 917 /* */ 918 FT_LOCAL_DEF( FT_Error ) 919 tt_size_run_prep( TT_Size size, 920 FT_Bool pedantic ) 921 { 922 TT_Face face = (TT_Face)size->root.face; 923 TT_ExecContext exec; 924 FT_Error error; 925 926 927 exec = size->context; 928 929 error = TT_Load_Context( exec, face, size ); 930 if ( error ) 931 return error; 932 933 exec->callTop = 0; 934 exec->top = 0; 935 936 exec->instruction_trap = FALSE; 937 1143 { 1144 FT_Error error = FT_Err_Ok; 1145 1146 1147 if ( size->bytecode_ready < 0 ) 1148 error = tt_size_init_bytecode( (FT_Size)size, pedantic ); 1149 else 1150 error = size->bytecode_ready; 1151 1152 if ( error ) 1153 goto Exit; 1154 1155 /* rescale CVT when needed */ 1156 if ( size->cvt_ready < 0 ) 1157 { 1158 FT_UInt i; 1159 TT_Face face = (TT_Face)size->root.face; 1160 1161 1162 /* Scale the cvt values to the new ppem. */ 1163 /* We use by default the y ppem to scale the CVT. */ 1164 for ( i = 0; i < size->cvt_size; i++ ) 1165 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); 1166 1167 /* all twilight points are originally zero */ 1168 for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ ) 1169 { 1170 size->twilight.org[i].x = 0; 1171 size->twilight.org[i].y = 0; 1172 size->twilight.cur[i].x = 0; 1173 size->twilight.cur[i].y = 0; 1174 } 1175 1176 /* clear storage area */ 1177 for ( i = 0; i < (FT_UInt)size->storage_size; i++ ) 1178 size->storage[i] = 0; 1179 1180 size->GS = tt_default_graphics_state; 1181 1182 error = tt_size_run_prep( size, pedantic ); 1183 } 1184 else 1185 error = size->cvt_ready; 1186 1187 Exit: 1188 return error; 1189 } 1190 1191 #endif /* TT_USE_BYTECODE_INTERPRETER */ 1192 1193 1194 /*************************************************************************/ 1195 /* */ 1196 /* <Function> */ 1197 /* tt_size_init */ 1198 /* */ 1199 /* <Description> */ 1200 /* Initialize a new TrueType size object. */ 1201 /* */ 1202 /* <InOut> */ 1203 /* size :: A handle to the size object. */ 1204 /* */ 1205 /* <Return> */ 1206 /* FreeType error code. 0 means success. */ 1207 /* */ 1208 FT_LOCAL_DEF( FT_Error ) 1209 tt_size_init( FT_Size ttsize ) /* TT_Size */ 1210 { 1211 TT_Size size = (TT_Size)ttsize; 1212 FT_Error error = FT_Err_Ok; 1213 1214 1215 #ifdef TT_USE_BYTECODE_INTERPRETER 1216 size->bytecode_ready = -1; 1217 size->cvt_ready = -1; 1218 #endif 1219 1220 size->ttmetrics.valid = FALSE; 1221 size->strike_index = 0xFFFFFFFFUL; 1222 1223 return error; 1224 } 1225 1226 1227 /*************************************************************************/ 1228 /* */ 1229 /* <Function> */ 1230 /* tt_size_done */ 1231 /* */ 1232 /* <Description> */ 1233 /* The TrueType size object finalizer. */ 1234 /* */ 1235 /* <Input> */ 1236 /* size :: A handle to the target size object. */ 1237 /* */ 1238 FT_LOCAL_DEF( void ) 1239 tt_size_done( FT_Size ttsize ) /* TT_Size */ 1240 { 1241 TT_Size size = (TT_Size)ttsize; 1242 1243 1244 #ifdef TT_USE_BYTECODE_INTERPRETER 1245 tt_size_done_bytecode( ttsize ); 1246 #endif 1247 1248 size->ttmetrics.valid = FALSE; 1249 } 1250 1251 1252 /*************************************************************************/ 1253 /* */ 1254 /* <Function> */ 1255 /* tt_size_reset */ 1256 /* */ 1257 /* <Description> */ 1258 /* Reset a TrueType size when resolutions and character dimensions */ 1259 /* have been changed. */ 1260 /* */ 1261 /* <Input> */ 1262 /* size :: A handle to the target size object. */ 1263 /* */ 1264 /* only_height :: Only recompute ascender, descender, and height; */ 1265 /* this flag is used for variation fonts where */ 1266 /* `tt_size_reset' is used as an iterator function. */ 1267 /* */ 1268 FT_LOCAL_DEF( FT_Error ) 1269 tt_size_reset( TT_Size size, 1270 FT_Bool only_height ) 1271 { 1272 TT_Face face; 1273 FT_Size_Metrics* size_metrics; 1274 1275 1276 face = (TT_Face)size->root.face; 1277 1278 /* nothing to do for CFF2 */ 1279 if ( face->is_cff2 ) 1280 return FT_Err_Ok; 1281 1282 size->ttmetrics.valid = FALSE; 1283 1284 size_metrics = &size->hinted_metrics; 1285 1286 /* copy the result from base layer */ 1287 *size_metrics = size->root.metrics; 1341 } 1342 else 1343 { 1344 size->ttmetrics.scale = size_metrics->y_scale; 1345 size->ttmetrics.ppem = size_metrics->y_ppem; 1346 size->ttmetrics.x_ratio = FT_DivFix( size_metrics->x_ppem, 1347 size_metrics->y_ppem ); 1348 size->ttmetrics.y_ratio = 0x10000L; 1349 } 1350 1351 size->metrics = size_metrics; 1352 1353 #ifdef TT_USE_BYTECODE_INTERPRETER 1354 size->cvt_ready = -1; 1355 #endif /* TT_USE_BYTECODE_INTERPRETER */ 1356 1357 return FT_Err_Ok; 1358 } 1359 1360 1361 /*************************************************************************/ 1362 /* */ 1363 /* <Function> */ 1364 /* tt_driver_init */ 1365 /* */ 1366 /* <Description> */ 1367 /* Initialize a given TrueType driver object. */ 1368 /* */ 1369 /* <Input> */ 1370 /* driver :: A handle to the target driver object. */ 1371 /* */ 1372 /* <Return> */ 1373 /* FreeType error code. 0 means success. */ 1374 /* */ 1375 FT_LOCAL_DEF( FT_Error ) 1376 tt_driver_init( FT_Module ttdriver ) /* TT_Driver */ 1377 { 1378 1379 #ifdef TT_USE_BYTECODE_INTERPRETER 1380 1381 TT_Driver driver = (TT_Driver)ttdriver; 1382 1383 driver->interpreter_version = TT_INTERPRETER_VERSION_35; 1384 #ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 1385 driver->interpreter_version = TT_INTERPRETER_VERSION_38; 1386 #endif 1387 #ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 1388 driver->interpreter_version = TT_INTERPRETER_VERSION_40; 1389 #endif 1390 1391 #else /* !TT_USE_BYTECODE_INTERPRETER */ 1392 1393 FT_UNUSED( ttdriver ); 1394 1395 #endif /* !TT_USE_BYTECODE_INTERPRETER */ 1396 1397 return FT_Err_Ok; 1398 } 1399 1400 1401 /*************************************************************************/ 1402 /* */ 1403 /* <Function> */ 1404 /* tt_driver_done */ 1405 /* */ 1406 /* <Description> */ 1407 /* Finalize a given TrueType driver. */ 1408 /* */ 1409 /* <Input> */ 1410 /* driver :: A handle to the target TrueType driver. */ 1411 /* */ 1412 FT_LOCAL_DEF( void ) 1413 tt_driver_done( FT_Module ttdriver ) /* TT_Driver */ 1414 { 1415 FT_UNUSED( ttdriver ); 1416 } 1417 1418 1419 /*************************************************************************/ 1420 /* */ 1421 /* <Function> */ 1422 /* tt_slot_init */ 1423 /* */ 1424 /* <Description> */ 1425 /* Initialize a new slot object. */ 1426 /* */ 1427 /* <InOut> */ 1428 /* slot :: A handle to the slot object. */ 1429 /* */ 1430 /* <Return> */ 1431 /* FreeType error code. 0 means success. */ 1432 /* */ 1433 FT_LOCAL_DEF( FT_Error ) 1434 tt_slot_init( FT_GlyphSlot slot ) 1435 { 1436 return FT_GlyphLoader_CreateExtra( slot->internal->loader ); 1437 } 1438 1439 1440 /* END */ | 1 /**************************************************************************** 2 * 3 * ttobjs.c 4 * 5 * Objects manager (body). 6 * 7 * Copyright (C) 1996-2019 by 8 * David Turner, Robert Wilhelm, and Werner Lemberg. 9 * 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. 15 * 16 */ 17 18 19 #include <ft2build.h> 20 #include FT_INTERNAL_DEBUG_H 21 #include FT_INTERNAL_STREAM_H 22 #include FT_TRUETYPE_TAGS_H 23 #include FT_INTERNAL_SFNT_H 24 #include FT_DRIVER_H 25 26 #include "ttgload.h" 27 #include "ttpload.h" 28 29 #include "tterrors.h" 30 31 #ifdef TT_USE_BYTECODE_INTERPRETER 32 #include "ttinterp.h" 33 #endif 34 35 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 36 #include "ttgxvar.h" 37 #endif 38 39 /************************************************************************** 40 * 41 * The macro FT_COMPONENT is used in trace mode. It is an implicit 42 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log 43 * messages during execution. 44 */ 45 #undef FT_COMPONENT 46 #define FT_COMPONENT ttobjs 47 48 49 #ifdef TT_USE_BYTECODE_INTERPRETER 50 51 /************************************************************************** 52 * 53 * GLYPH ZONE FUNCTIONS 54 * 55 */ 56 57 58 /************************************************************************** 59 * 60 * @Function: 61 * tt_glyphzone_done 62 * 63 * @Description: 64 * Deallocate a glyph zone. 65 * 66 * @Input: 67 * zone :: 68 * A pointer to the target glyph zone. 69 */ 70 FT_LOCAL_DEF( void ) 71 tt_glyphzone_done( TT_GlyphZone zone ) 72 { 73 FT_Memory memory = zone->memory; 74 75 76 if ( memory ) 77 { 78 FT_FREE( zone->contours ); 79 FT_FREE( zone->tags ); 80 FT_FREE( zone->cur ); 81 FT_FREE( zone->org ); 82 FT_FREE( zone->orus ); 83 84 zone->max_points = zone->n_points = 0; 85 zone->max_contours = zone->n_contours = 0; 86 zone->memory = NULL; 87 } 88 } 89 90 91 /************************************************************************** 92 * 93 * @Function: 94 * tt_glyphzone_new 95 * 96 * @Description: 97 * Allocate a new glyph zone. 98 * 99 * @Input: 100 * memory :: 101 * A handle to the current memory object. 102 * 103 * maxPoints :: 104 * The capacity of glyph zone in points. 105 * 106 * maxContours :: 107 * The capacity of glyph zone in contours. 108 * 109 * @Output: 110 * zone :: 111 * A pointer to the target glyph zone record. 112 * 113 * @Return: 114 * FreeType error code. 0 means success. 115 */ 116 FT_LOCAL_DEF( FT_Error ) 117 tt_glyphzone_new( FT_Memory memory, 118 FT_UShort maxPoints, 119 FT_Short maxContours, 120 TT_GlyphZone zone ) 121 { 122 FT_Error error; 123 124 125 FT_ZERO( zone ); 126 zone->memory = memory; 127 128 if ( FT_NEW_ARRAY( zone->org, maxPoints ) || 129 FT_NEW_ARRAY( zone->cur, maxPoints ) || 130 FT_NEW_ARRAY( zone->orus, maxPoints ) || 131 FT_NEW_ARRAY( zone->tags, maxPoints ) || 132 FT_NEW_ARRAY( zone->contours, maxContours ) ) 133 { 134 tt_glyphzone_done( zone ); 135 } 554 if ( glyph_index == 0 ) 555 result = TRUE; 556 else 557 { 558 /* FIXME: Need to test glyphname == .notdef ? */ 559 FT_Error error; 560 char buf[8]; 561 562 563 error = FT_Get_Glyph_Name( ttface, glyph_index, buf, 8 ); 564 if ( !error && 565 buf[0] == '.' && !ft_strncmp( buf, ".notdef", 8 ) ) 566 result = TRUE; 567 } 568 } 569 570 return result; 571 } 572 573 574 /************************************************************************** 575 * 576 * @Function: 577 * tt_face_init 578 * 579 * @Description: 580 * Initialize a given TrueType face object. 581 * 582 * @Input: 583 * stream :: 584 * The source font stream. 585 * 586 * face_index :: 587 * The index of the TrueType font, if we are opening a 588 * collection, in bits 0-15. The numbered instance 589 * index~+~1 of a GX (sub)font, if applicable, in bits 590 * 16-30. 591 * 592 * num_params :: 593 * Number of additional generic parameters. Ignored. 594 * 595 * params :: 596 * Additional generic parameters. Ignored. 597 * 598 * @InOut: 599 * face :: 600 * The newly built face object. 601 * 602 * @Return: 603 * FreeType error code. 0 means success. 604 */ 605 FT_LOCAL_DEF( FT_Error ) 606 tt_face_init( FT_Stream stream, 607 FT_Face ttface, /* TT_Face */ 608 FT_Int face_index, 609 FT_Int num_params, 610 FT_Parameter* params ) 611 { 612 FT_Error error; 613 FT_Library library; 614 SFNT_Service sfnt; 615 TT_Face face = (TT_Face)ttface; 616 617 618 FT_TRACE2(( "TTF driver\n" )); 619 620 library = ttface->driver->root.library; 621 622 sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); 623 if ( !sfnt ) 624 { 736 goto Exit; 737 738 tt_apply_mvar( face ); 739 } 740 } 741 742 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 743 744 /* initialize standard glyph loading routines */ 745 TT_Init_Glyph_Loading( face ); 746 747 Exit: 748 return error; 749 750 Bad_Format: 751 error = FT_THROW( Unknown_File_Format ); 752 goto Exit; 753 } 754 755 756 /************************************************************************** 757 * 758 * @Function: 759 * tt_face_done 760 * 761 * @Description: 762 * Finalize a given face object. 763 * 764 * @Input: 765 * face :: 766 * A pointer to the face object to destroy. 767 */ 768 FT_LOCAL_DEF( void ) 769 tt_face_done( FT_Face ttface ) /* TT_Face */ 770 { 771 TT_Face face = (TT_Face)ttface; 772 FT_Memory memory; 773 FT_Stream stream; 774 SFNT_Service sfnt; 775 776 777 if ( !face ) 778 return; 779 780 memory = ttface->memory; 781 stream = ttface->stream; 782 sfnt = (SFNT_Service)face->sfnt; 783 784 /* for `extended TrueType formats' (i.e. compressed versions) */ 785 if ( face->extra.finalizer ) 786 face->extra.finalizer( face->extra.data ); 787 793 794 tt_face_free_hdmx( face ); 795 796 /* freeing the CVT */ 797 FT_FREE( face->cvt ); 798 face->cvt_size = 0; 799 800 /* freeing the programs */ 801 FT_FRAME_RELEASE( face->font_program ); 802 FT_FRAME_RELEASE( face->cvt_program ); 803 face->font_program_size = 0; 804 face->cvt_program_size = 0; 805 806 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 807 tt_done_blend( face ); 808 face->blend = NULL; 809 #endif 810 } 811 812 813 /************************************************************************** 814 * 815 * SIZE FUNCTIONS 816 * 817 */ 818 819 #ifdef TT_USE_BYTECODE_INTERPRETER 820 821 /************************************************************************** 822 * 823 * @Function: 824 * tt_size_run_fpgm 825 * 826 * @Description: 827 * Run the font program. 828 * 829 * @Input: 830 * size :: 831 * A handle to the size object. 832 * 833 * pedantic :: 834 * Set if bytecode execution should be pedantic. 835 * 836 * @Return: 837 * FreeType error code. 0 means success. 838 */ 839 FT_LOCAL_DEF( FT_Error ) 840 tt_size_run_fpgm( TT_Size size, 841 FT_Bool pedantic ) 842 { 843 TT_Face face = (TT_Face)size->root.face; 844 TT_ExecContext exec; 845 FT_Error error; 846 847 848 exec = size->context; 849 850 error = TT_Load_Context( exec, face, size ); 851 if ( error ) 852 return error; 853 854 exec->callTop = 0; 855 exec->top = 0; 856 857 exec->period = 64; 858 exec->phase = 0; 895 FT_TRACE4(( "Executing `fpgm' table.\n" )); 896 error = face->interpreter( exec ); 897 #ifdef FT_DEBUG_LEVEL_TRACE 898 if ( error ) 899 FT_TRACE4(( " interpretation failed with error code 0x%x\n", 900 error )); 901 #endif 902 } 903 else 904 error = FT_Err_Ok; 905 906 size->bytecode_ready = error; 907 908 if ( !error ) 909 TT_Save_Context( exec, size ); 910 911 return error; 912 } 913 914 915 /************************************************************************** 916 * 917 * @Function: 918 * tt_size_run_prep 919 * 920 * @Description: 921 * Run the control value program. 922 * 923 * @Input: 924 * size :: 925 * A handle to the size object. 926 * 927 * pedantic :: 928 * Set if bytecode execution should be pedantic. 929 * 930 * @Return: 931 * FreeType error code. 0 means success. 932 */ 933 FT_LOCAL_DEF( FT_Error ) 934 tt_size_run_prep( TT_Size size, 935 FT_Bool pedantic ) 936 { 937 TT_Face face = (TT_Face)size->root.face; 938 TT_ExecContext exec; 939 FT_Error error; 940 941 942 exec = size->context; 943 944 error = TT_Load_Context( exec, face, size ); 945 if ( error ) 946 return error; 947 948 exec->callTop = 0; 949 exec->top = 0; 950 951 exec->instruction_trap = FALSE; 952 1158 { 1159 FT_Error error = FT_Err_Ok; 1160 1161 1162 if ( size->bytecode_ready < 0 ) 1163 error = tt_size_init_bytecode( (FT_Size)size, pedantic ); 1164 else 1165 error = size->bytecode_ready; 1166 1167 if ( error ) 1168 goto Exit; 1169 1170 /* rescale CVT when needed */ 1171 if ( size->cvt_ready < 0 ) 1172 { 1173 FT_UInt i; 1174 TT_Face face = (TT_Face)size->root.face; 1175 1176 1177 /* Scale the cvt values to the new ppem. */ 1178 /* By default, we use the y ppem value for scaling. */ 1179 FT_TRACE6(( "CVT values:\n" )); 1180 for ( i = 0; i < size->cvt_size; i++ ) 1181 { 1182 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); 1183 FT_TRACE6(( " %3d: %d (%f)\n", 1184 i, face->cvt[i], size->cvt[i] / 64.0 )); 1185 } 1186 FT_TRACE6(( "\n" )); 1187 1188 /* all twilight points are originally zero */ 1189 for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ ) 1190 { 1191 size->twilight.org[i].x = 0; 1192 size->twilight.org[i].y = 0; 1193 size->twilight.cur[i].x = 0; 1194 size->twilight.cur[i].y = 0; 1195 } 1196 1197 /* clear storage area */ 1198 for ( i = 0; i < (FT_UInt)size->storage_size; i++ ) 1199 size->storage[i] = 0; 1200 1201 size->GS = tt_default_graphics_state; 1202 1203 error = tt_size_run_prep( size, pedantic ); 1204 } 1205 else 1206 error = size->cvt_ready; 1207 1208 Exit: 1209 return error; 1210 } 1211 1212 #endif /* TT_USE_BYTECODE_INTERPRETER */ 1213 1214 1215 /************************************************************************** 1216 * 1217 * @Function: 1218 * tt_size_init 1219 * 1220 * @Description: 1221 * Initialize a new TrueType size object. 1222 * 1223 * @InOut: 1224 * size :: 1225 * A handle to the size object. 1226 * 1227 * @Return: 1228 * FreeType error code. 0 means success. 1229 */ 1230 FT_LOCAL_DEF( FT_Error ) 1231 tt_size_init( FT_Size ttsize ) /* TT_Size */ 1232 { 1233 TT_Size size = (TT_Size)ttsize; 1234 FT_Error error = FT_Err_Ok; 1235 1236 1237 #ifdef TT_USE_BYTECODE_INTERPRETER 1238 size->bytecode_ready = -1; 1239 size->cvt_ready = -1; 1240 #endif 1241 1242 size->ttmetrics.valid = FALSE; 1243 size->strike_index = 0xFFFFFFFFUL; 1244 1245 return error; 1246 } 1247 1248 1249 /************************************************************************** 1250 * 1251 * @Function: 1252 * tt_size_done 1253 * 1254 * @Description: 1255 * The TrueType size object finalizer. 1256 * 1257 * @Input: 1258 * size :: 1259 * A handle to the target size object. 1260 */ 1261 FT_LOCAL_DEF( void ) 1262 tt_size_done( FT_Size ttsize ) /* TT_Size */ 1263 { 1264 TT_Size size = (TT_Size)ttsize; 1265 1266 1267 #ifdef TT_USE_BYTECODE_INTERPRETER 1268 tt_size_done_bytecode( ttsize ); 1269 #endif 1270 1271 size->ttmetrics.valid = FALSE; 1272 } 1273 1274 1275 /************************************************************************** 1276 * 1277 * @Function: 1278 * tt_size_reset 1279 * 1280 * @Description: 1281 * Reset a TrueType size when resolutions and character dimensions 1282 * have been changed. 1283 * 1284 * @Input: 1285 * size :: 1286 * A handle to the target size object. 1287 * 1288 * only_height :: 1289 * Only recompute ascender, descender, and height; 1290 * this flag is used for variation fonts where 1291 * `tt_size_reset' is used as an iterator function. 1292 */ 1293 FT_LOCAL_DEF( FT_Error ) 1294 tt_size_reset( TT_Size size, 1295 FT_Bool only_height ) 1296 { 1297 TT_Face face; 1298 FT_Size_Metrics* size_metrics; 1299 1300 1301 face = (TT_Face)size->root.face; 1302 1303 /* nothing to do for CFF2 */ 1304 if ( face->is_cff2 ) 1305 return FT_Err_Ok; 1306 1307 size->ttmetrics.valid = FALSE; 1308 1309 size_metrics = &size->hinted_metrics; 1310 1311 /* copy the result from base layer */ 1312 *size_metrics = size->root.metrics; 1366 } 1367 else 1368 { 1369 size->ttmetrics.scale = size_metrics->y_scale; 1370 size->ttmetrics.ppem = size_metrics->y_ppem; 1371 size->ttmetrics.x_ratio = FT_DivFix( size_metrics->x_ppem, 1372 size_metrics->y_ppem ); 1373 size->ttmetrics.y_ratio = 0x10000L; 1374 } 1375 1376 size->metrics = size_metrics; 1377 1378 #ifdef TT_USE_BYTECODE_INTERPRETER 1379 size->cvt_ready = -1; 1380 #endif /* TT_USE_BYTECODE_INTERPRETER */ 1381 1382 return FT_Err_Ok; 1383 } 1384 1385 1386 /************************************************************************** 1387 * 1388 * @Function: 1389 * tt_driver_init 1390 * 1391 * @Description: 1392 * Initialize a given TrueType driver object. 1393 * 1394 * @Input: 1395 * driver :: 1396 * A handle to the target driver object. 1397 * 1398 * @Return: 1399 * FreeType error code. 0 means success. 1400 */ 1401 FT_LOCAL_DEF( FT_Error ) 1402 tt_driver_init( FT_Module ttdriver ) /* TT_Driver */ 1403 { 1404 1405 #ifdef TT_USE_BYTECODE_INTERPRETER 1406 1407 TT_Driver driver = (TT_Driver)ttdriver; 1408 1409 driver->interpreter_version = TT_INTERPRETER_VERSION_35; 1410 #ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 1411 driver->interpreter_version = TT_INTERPRETER_VERSION_38; 1412 #endif 1413 #ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 1414 driver->interpreter_version = TT_INTERPRETER_VERSION_40; 1415 #endif 1416 1417 #else /* !TT_USE_BYTECODE_INTERPRETER */ 1418 1419 FT_UNUSED( ttdriver ); 1420 1421 #endif /* !TT_USE_BYTECODE_INTERPRETER */ 1422 1423 return FT_Err_Ok; 1424 } 1425 1426 1427 /************************************************************************** 1428 * 1429 * @Function: 1430 * tt_driver_done 1431 * 1432 * @Description: 1433 * Finalize a given TrueType driver. 1434 * 1435 * @Input: 1436 * driver :: 1437 * A handle to the target TrueType driver. 1438 */ 1439 FT_LOCAL_DEF( void ) 1440 tt_driver_done( FT_Module ttdriver ) /* TT_Driver */ 1441 { 1442 FT_UNUSED( ttdriver ); 1443 } 1444 1445 1446 /************************************************************************** 1447 * 1448 * @Function: 1449 * tt_slot_init 1450 * 1451 * @Description: 1452 * Initialize a new slot object. 1453 * 1454 * @InOut: 1455 * slot :: 1456 * A handle to the slot object. 1457 * 1458 * @Return: 1459 * FreeType error code. 0 means success. 1460 */ 1461 FT_LOCAL_DEF( FT_Error ) 1462 tt_slot_init( FT_GlyphSlot slot ) 1463 { 1464 return FT_GlyphLoader_CreateExtra( slot->internal->loader ); 1465 } 1466 1467 1468 /* END */ |