OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* cf2intrp.c */ | 3 /* cf2intrp.c */ |
4 /* */ | 4 /* */ |
5 /* Adobe's CFF Interpreter (body). */ | 5 /* Adobe's CFF Interpreter (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 2007-2014 Adobe Systems Incorporated. */ | 7 /* Copyright 2007-2014 Adobe Systems Incorporated. */ |
8 /* */ | 8 /* */ |
9 /* This software, and all works of authorship, whether in source or */ | 9 /* This software, and all works of authorship, whether in source or */ |
10 /* object code form as indicated by the copyright notice(s) included */ | 10 /* object code form as indicated by the copyright notice(s) included */ |
(...skipping 25 matching lines...) Expand all Loading... |
36 /***************************************************************************/ | 36 /***************************************************************************/ |
37 | 37 |
38 | 38 |
39 #include "cf2ft.h" | 39 #include "cf2ft.h" |
40 #include FT_INTERNAL_DEBUG_H | 40 #include FT_INTERNAL_DEBUG_H |
41 | 41 |
42 #include "cf2glue.h" | 42 #include "cf2glue.h" |
43 #include "cf2font.h" | 43 #include "cf2font.h" |
44 #include "cf2stack.h" | 44 #include "cf2stack.h" |
45 #include "cf2hints.h" | 45 #include "cf2hints.h" |
| 46 #include "cf2intrp.h" |
46 | 47 |
47 #include "cf2error.h" | 48 #include "cf2error.h" |
48 | 49 |
49 | 50 |
50 /*************************************************************************/ | 51 /*************************************************************************/ |
51 /* */ | 52 /* */ |
52 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ | 53 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
53 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ | 54 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
54 /* messages during execution. */ | 55 /* messages during execution. */ |
55 /* */ | 56 /* */ |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 | 754 |
754 if ( charstringIndex > CF2_MAX_SUBR ) | 755 if ( charstringIndex > CF2_MAX_SUBR ) |
755 { | 756 { |
756 /* max subr plus one for charstring */ | 757 /* max subr plus one for charstring */ |
757 lastError = FT_THROW( Invalid_Glyph_Format ); | 758 lastError = FT_THROW( Invalid_Glyph_Format ); |
758 goto exit; /* overflow of stack */ | 759 goto exit; /* overflow of stack */ |
759 } | 760 } |
760 | 761 |
761 /* push our current CFF charstring region on subrStack */ | 762 /* push our current CFF charstring region on subrStack */ |
762 charstring = (CF2_Buffer) | 763 charstring = (CF2_Buffer) |
763 cf2_arrstack_getPointer( &subrStack, | 764 cf2_arrstack_getPointer( |
764 charstringIndex + 1 ); | 765 &subrStack, |
| 766 (size_t)charstringIndex + 1 ); |
765 | 767 |
766 /* set up the new CFF region and pointer */ | 768 /* set up the new CFF region and pointer */ |
767 subrIndex = cf2_stack_popInt( opStack ); | 769 subrIndex = (CF2_UInt)cf2_stack_popInt( opStack ); |
768 | 770 |
769 switch ( op1 ) | 771 switch ( op1 ) |
770 { | 772 { |
771 case cf2_cmdCALLGSUBR: | 773 case cf2_cmdCALLGSUBR: |
772 FT_TRACE4(( "(%d)\n", subrIndex + decoder->globals_bias )); | 774 FT_TRACE4(( " (idx %d, entering level %d)\n", |
| 775 subrIndex + (CF2_UInt)decoder->globals_bias, |
| 776 charstringIndex + 1 )); |
773 | 777 |
774 if ( cf2_initGlobalRegionBuffer( decoder, | 778 if ( cf2_initGlobalRegionBuffer( decoder, |
775 subrIndex, | 779 subrIndex, |
776 charstring ) ) | 780 charstring ) ) |
777 { | 781 { |
778 lastError = FT_THROW( Invalid_Glyph_Format ); | 782 lastError = FT_THROW( Invalid_Glyph_Format ); |
779 goto exit; /* subroutine lookup or stream error */ | 783 goto exit; /* subroutine lookup or stream error */ |
780 } | 784 } |
781 break; | 785 break; |
782 | 786 |
783 default: | 787 default: |
784 /* cf2_cmdCALLSUBR */ | 788 /* cf2_cmdCALLSUBR */ |
785 FT_TRACE4(( "(%d)\n", subrIndex + decoder->locals_bias )); | 789 FT_TRACE4(( " (idx %d, entering level %d)\n", |
| 790 subrIndex + (CF2_UInt)decoder->locals_bias, |
| 791 charstringIndex + 1 )); |
786 | 792 |
787 if ( cf2_initLocalRegionBuffer( decoder, | 793 if ( cf2_initLocalRegionBuffer( decoder, |
788 subrIndex, | 794 subrIndex, |
789 charstring ) ) | 795 charstring ) ) |
790 { | 796 { |
791 lastError = FT_THROW( Invalid_Glyph_Format ); | 797 lastError = FT_THROW( Invalid_Glyph_Format ); |
792 goto exit; /* subroutine lookup or stream error */ | 798 goto exit; /* subroutine lookup or stream error */ |
793 } | 799 } |
794 } | 800 } |
795 | 801 |
796 charstringIndex += 1; /* entry is valid now */ | 802 charstringIndex += 1; /* entry is valid now */ |
797 } | 803 } |
798 continue; /* do not clear the stack */ | 804 continue; /* do not clear the stack */ |
799 | 805 |
800 case cf2_cmdRETURN: | 806 case cf2_cmdRETURN: |
801 FT_TRACE4(( " return\n" )); | 807 FT_TRACE4(( " return (leaving level %d)\n", charstringIndex )); |
802 | 808 |
803 if ( charstringIndex < 1 ) | 809 if ( charstringIndex < 1 ) |
804 { | 810 { |
805 /* Note: cannot return from top charstring */ | 811 /* Note: cannot return from top charstring */ |
806 lastError = FT_THROW( Invalid_Glyph_Format ); | 812 lastError = FT_THROW( Invalid_Glyph_Format ); |
807 goto exit; /* underflow of stack */ | 813 goto exit; /* underflow of stack */ |
808 } | 814 } |
809 | 815 |
810 /* restore position in previous charstring */ | 816 /* restore position in previous charstring */ |
811 charstring = (CF2_Buffer) | 817 charstring = (CF2_Buffer) |
812 cf2_arrstack_getPointer( &subrStack, | 818 cf2_arrstack_getPointer( |
813 --charstringIndex ); | 819 &subrStack, |
| 820 (CF2_UInt)--charstringIndex ); |
814 continue; /* do not clear the stack */ | 821 continue; /* do not clear the stack */ |
815 | 822 |
816 case cf2_cmdESC: | 823 case cf2_cmdESC: |
817 { | 824 { |
818 FT_Byte op2 = (FT_Byte)cf2_buf_readByte( charstring ); | 825 FT_Byte op2 = (FT_Byte)cf2_buf_readByte( charstring ); |
819 | 826 |
820 | 827 |
821 switch ( op2 ) | 828 switch ( op2 ) |
822 { | 829 { |
823 case cf2_escDOTSECTION: | 830 case cf2_escDOTSECTION: |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 goto exit; | 1088 goto exit; |
1082 | 1089 |
1083 /* close path if still open */ | 1090 /* close path if still open */ |
1084 cf2_glyphpath_closeOpenPath( &glyphPath ); | 1091 cf2_glyphpath_closeOpenPath( &glyphPath ); |
1085 | 1092 |
1086 if ( cf2_stack_count( opStack ) > 1 ) | 1093 if ( cf2_stack_count( opStack ) > 1 ) |
1087 { | 1094 { |
1088 /* must be either 4 or 5 -- */ | 1095 /* must be either 4 or 5 -- */ |
1089 /* this is a (deprecated) implied `seac' operator */ | 1096 /* this is a (deprecated) implied `seac' operator */ |
1090 | 1097 |
1091 CF2_UInt achar; | 1098 CF2_Int achar; |
1092 CF2_UInt bchar; | 1099 CF2_Int bchar; |
1093 CF2_BufferRec component; | 1100 CF2_BufferRec component; |
1094 CF2_Fixed dummyWidth; /* ignore component width */ | 1101 CF2_Fixed dummyWidth; /* ignore component width */ |
1095 FT_Error error2; | 1102 FT_Error error2; |
1096 | 1103 |
1097 | 1104 |
1098 if ( doingSeac ) | 1105 if ( doingSeac ) |
1099 { | 1106 { |
1100 lastError = FT_THROW( Invalid_Glyph_Format ); | 1107 lastError = FT_THROW( Invalid_Glyph_Format ); |
1101 goto exit; /* nested seac */ | 1108 goto exit; /* nested seac */ |
1102 } | 1109 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 curY = y3; | 1291 curY = y3; |
1285 index += 6; | 1292 index += 6; |
1286 } | 1293 } |
1287 | 1294 |
1288 cf2_stack_clear( opStack ); | 1295 cf2_stack_clear( opStack ); |
1289 } | 1296 } |
1290 continue; /* no need to clear stack again */ | 1297 continue; /* no need to clear stack again */ |
1291 | 1298 |
1292 case cf2_cmdVVCURVETO: | 1299 case cf2_cmdVVCURVETO: |
1293 { | 1300 { |
1294 CF2_UInt count = cf2_stack_count( opStack ); | 1301 CF2_UInt count, count1 = cf2_stack_count( opStack ); |
1295 CF2_UInt index = 0; | 1302 CF2_UInt index = 0; |
1296 | 1303 |
1297 | 1304 |
| 1305 /* if `cf2_stack_count' isn't of the form 4n or 4n+1, */ |
| 1306 /* we enforce it by clearing the second bit */ |
| 1307 /* (and sorting the stack indexing to suit) */ |
| 1308 count = count1 & ~2U; |
| 1309 index += count1 - count; |
| 1310 |
1298 FT_TRACE4(( " vvcurveto\n" )); | 1311 FT_TRACE4(( " vvcurveto\n" )); |
1299 | 1312 |
1300 while ( index < count ) | 1313 while ( index < count ) |
1301 { | 1314 { |
1302 CF2_Fixed x1, y1, x2, y2, x3, y3; | 1315 CF2_Fixed x1, y1, x2, y2, x3, y3; |
1303 | 1316 |
1304 | 1317 |
1305 if ( ( count - index ) & 1 ) | 1318 if ( ( count - index ) & 1 ) |
1306 { | 1319 { |
1307 x1 = cf2_stack_getReal( opStack, index ) + curX; | 1320 x1 = cf2_stack_getReal( opStack, index ) + curX; |
(...skipping 15 matching lines...) Expand all Loading... |
1323 curY = y3; | 1336 curY = y3; |
1324 index += 4; | 1337 index += 4; |
1325 } | 1338 } |
1326 | 1339 |
1327 cf2_stack_clear( opStack ); | 1340 cf2_stack_clear( opStack ); |
1328 } | 1341 } |
1329 continue; /* no need to clear stack again */ | 1342 continue; /* no need to clear stack again */ |
1330 | 1343 |
1331 case cf2_cmdHHCURVETO: | 1344 case cf2_cmdHHCURVETO: |
1332 { | 1345 { |
1333 CF2_UInt count = cf2_stack_count( opStack ); | 1346 CF2_UInt count, count1 = cf2_stack_count( opStack ); |
1334 CF2_UInt index = 0; | 1347 CF2_UInt index = 0; |
1335 | 1348 |
1336 | 1349 |
| 1350 /* if `cf2_stack_count' isn't of the form 4n or 4n+1, */ |
| 1351 /* we enforce it by clearing the second bit */ |
| 1352 /* (and sorting the stack indexing to suit) */ |
| 1353 count = count1 & ~2U; |
| 1354 index += count1 - count; |
| 1355 |
1337 FT_TRACE4(( " hhcurveto\n" )); | 1356 FT_TRACE4(( " hhcurveto\n" )); |
1338 | 1357 |
1339 while ( index < count ) | 1358 while ( index < count ) |
1340 { | 1359 { |
1341 CF2_Fixed x1, y1, x2, y2, x3, y3; | 1360 CF2_Fixed x1, y1, x2, y2, x3, y3; |
1342 | 1361 |
1343 | 1362 |
1344 if ( ( count - index ) & 1 ) | 1363 if ( ( count - index ) & 1 ) |
1345 { | 1364 { |
1346 y1 = cf2_stack_getReal( opStack, index ) + curY; | 1365 y1 = cf2_stack_getReal( opStack, index ) + curY; |
(...skipping 16 matching lines...) Expand all Loading... |
1363 index += 4; | 1382 index += 4; |
1364 } | 1383 } |
1365 | 1384 |
1366 cf2_stack_clear( opStack ); | 1385 cf2_stack_clear( opStack ); |
1367 } | 1386 } |
1368 continue; /* no need to clear stack again */ | 1387 continue; /* no need to clear stack again */ |
1369 | 1388 |
1370 case cf2_cmdVHCURVETO: | 1389 case cf2_cmdVHCURVETO: |
1371 case cf2_cmdHVCURVETO: | 1390 case cf2_cmdHVCURVETO: |
1372 { | 1391 { |
1373 CF2_UInt count = cf2_stack_count( opStack ); | 1392 CF2_UInt count, count1 = cf2_stack_count( opStack ); |
1374 CF2_UInt index = 0; | 1393 CF2_UInt index = 0; |
1375 | 1394 |
1376 FT_Bool alternate = op1 == cf2_cmdHVCURVETO; | 1395 FT_Bool alternate = op1 == cf2_cmdHVCURVETO; |
1377 | 1396 |
1378 | 1397 |
| 1398 /* if `cf2_stack_count' isn't of the form 8n, 8n+1, */ |
| 1399 /* 8n+4, or 8n+5, we enforce it by clearing the */ |
| 1400 /* second bit */ |
| 1401 /* (and sorting the stack indexing to suit) */ |
| 1402 count = count1 & ~2U; |
| 1403 index += count1 - count; |
| 1404 |
1379 FT_TRACE4(( alternate ? " hvcurveto\n" : " vhcurveto\n" )); | 1405 FT_TRACE4(( alternate ? " hvcurveto\n" : " vhcurveto\n" )); |
1380 | 1406 |
1381 while ( index < count ) | 1407 while ( index < count ) |
1382 { | 1408 { |
1383 CF2_Fixed x1, x2, x3, y1, y2, y3; | 1409 CF2_Fixed x1, x2, x3, y1, y2, y3; |
1384 | 1410 |
1385 | 1411 |
1386 if ( alternate ) | 1412 if ( alternate ) |
1387 { | 1413 { |
1388 x1 = cf2_stack_getReal( opStack, index + 0 ) + curX; | 1414 x1 = cf2_stack_getReal( opStack, index + 0 ) + curX; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 cf2_arrstack_finalize( &subrStack ); | 1562 cf2_arrstack_finalize( &subrStack ); |
1537 cf2_stack_free( opStack ); | 1563 cf2_stack_free( opStack ); |
1538 | 1564 |
1539 FT_TRACE4(( "\n" )); | 1565 FT_TRACE4(( "\n" )); |
1540 | 1566 |
1541 return; | 1567 return; |
1542 } | 1568 } |
1543 | 1569 |
1544 | 1570 |
1545 /* END */ | 1571 /* END */ |
OLD | NEW |