* src/truetype/ttgload.c (TT_Load_Composite_Glyph) [FT_CONFIG_OPTION_BYTECODE_INTERPRETER]: Make it compilable again. Formatting, documentation fixes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
diff --git a/ChangeLog b/ChangeLog
index 393ded2..0032396 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,26 +1,69 @@
+2006-05-18 Werner Lemberg <wl@gnu.org>
+
+ * src/truetype/ttgload.c (TT_Load_Composite_Glyph)
+ [FT_CONFIG_OPTION_BYTECODE_INTERPRETER]: Make it compilable again.
+
2006-05-17 David Turner <david@freetype.org>
- * include/freetype/internal/tttypes.h, src/autofit/afangles.c,
- src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
- src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
- src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
- src/type1/t1gload.c:
+ This is a major patch used to drastically improve the performance of
+ loading glyphs. This both speeds up loading the glyph vectors
+ themselves and the auto-fitter module.
+
+ We now use inline assembler code with GCC to implement `FT_MulFix',
+ which is probably the most important function related to the
+ engine's performance.
+
+ The resulting speed-up is about 25%.
+
+
+ * include/freetype/internal/tttypes.h (TT_LoaderRec): Add fields
+ `cursor' and `limit'.
+
+ * src/autofit/afangles.c (af_corner_is_flat, af_corner_orientation):
+ New functions.
+ (AF_ATAN_BITS, af_arctan, af_angle_atan): Comment out.
+ [TEST]: Remove.
+
+ * src/autofit/afcjk.c (AF_Script_UniRangeRec): Comment out test
+ code.
+
+ * src/autofit/afhints.c (af_axis_hints_new_segment): Don't call
+ `FT_ZERO'
+ (af_direction_compute, af_glyph_hints_compute_inflections): Rewritten.
+ (af_glyph_hints_reload: Rewrite recognition of weak points.
+
+ * src/autofit/aflatin.c (af_latin_hints_compute_segments): Move
+ constant values out of the loops.
+
+ * src/autofit/aftypes.h: Updated.
+
+ * src/base/ftcalc.c (FT_MulFix): Use inline assembler code.
+
+ * src/base/ftoutln.c (FT_Outline_Get_Orientation): Use vector
+ product to get orientation.
+
+ * src/gzip/ftgzip.c (ft_get_uncompressed_size): New function.
+ (FT_Stream_OpenGzip): Use it to handle small files directly in
+ memory.
+
+ * src/psaux/psconv.c (PS_Conv_ASCIIHexDecode, PS_ConvEexecDecode):
+ Improve performance.
- this is a major patch used to drastically improve the performance
- of loading glyphs. This both speeds up loading the glypn vector
- themselves and the auto-fitter.
+ * src/truetype/ttgload.c (TT_Access_Glyph_Frame): Set `cursor' and
+ `limit'.
- note that we've started using inline assembler with GCC to
- implement FT_MulFix, given that this function is so damn
- important for the engine's performance.
+ (TT_Load_Glyph_Header, TT_Load_Simple_Glyph,
+ TT_Load_Composite_Glyph): Updated. Add threshold to protect against
+ exceedingly large values of number of contours. Speed up by
+ reducing the number of loops.
- the resulting speed-up is about 25%.
+ * src/type1/t1gload.c (T1_Load_Glyph): Don't apply unit matrix.
- * src/ftccmap.c (FTC_CMapCache_Lookup): changed the threshold
- used to detect rogue clients from 4 to 16. This is to prevent
- some segmentation faults with fonts like KozMinProVI-Regular.otf
- which comes from the Japanese Adobe Reader Asian Font pack.
+ * src/cache/ftccmap.c (FTC_CMapCache_Lookup): Change the threshold
+ used to detect rogue clients from 4 to 16. This is to prevent some
+ segmentation faults with fonts like `KozMinProVI-Regular.otf' which
+ comes from the Japanese Adobe Reader Asian Font pack.
2007-05-17 Werner Lemberg <wl@gnu.org>
diff --git a/src/autofit/afangles.c b/src/autofit/afangles.c
index dac8ba8..d7841d3 100644
--- a/src/autofit/afangles.c
+++ b/src/autofit/afangles.c
@@ -5,7 +5,7 @@
/* Routines used to compute vector angles with limited accuracy */
/* and very high speed. It also contains sorting routines (body). */
/* */
-/* Copyright 2003, 2004, 2005 by */
+/* Copyright 2003, 2004, 2005, 2006 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -21,29 +21,40 @@
FT_LOCAL_DEF( FT_Int )
- af_corner_is_flat( FT_Pos x_in,
- FT_Pos y_in,
- FT_Pos x_out,
- FT_Pos y_out )
+ af_corner_is_flat( FT_Pos x_in,
+ FT_Pos y_in,
+ FT_Pos x_out,
+ FT_Pos y_out )
{
FT_Pos ax = x_in;
FT_Pos ay = y_in;
FT_Pos d_in, d_out, d_corner;
- if ( ax < 0 ) ax = -ax;
- if ( ay < 0 ) ay = -ay;
- d_in = ax + ay;
-
- ax = x_out; if ( ax < 0 ) ax = -ax;
- ay = y_out; if ( ay < 0 ) ay = -ay;
- d_out = ax+ay;
- ax = x_out + x_in; if ( ax < 0 ) ax = -ax;
- ay = y_out + y_in; if ( ay < 0 ) ay = -ay;
- d_corner = ax+ay;
+ if ( ax < 0 )
+ ax = -ax;
+ if ( ay < 0 )
+ ay = -ay;
+ d_in = ax + ay;
- return ( d_in + d_out - d_corner ) < (d_corner >> 4);
+ ax = x_out;
+ if ( ax < 0 )
+ ax = -ax;
+ ay = y_out;
+ if ( ay < 0 )
+ ay = -ay;
+ d_out = ax + ay;
+
+ ax = x_out + x_in;
+ if ( ax < 0 )
+ ax = -ax;
+ ay = y_out + y_in;
+ if ( ay < 0 )
+ ay = -ay;
+ d_corner = ax + ay;
+
+ return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
}
@@ -53,30 +64,39 @@
FT_Pos x_out,
FT_Pos y_out )
{
- FT_Pos delta;
+ FT_Pos delta;
- delta = x_in*y_out - y_in*x_out;
+
+ delta = x_in * y_out - y_in * x_out;
if ( delta == 0 )
return 0;
else
- return 1 - 2*(delta < 0);
+ return 1 - 2 * ( delta < 0 );
}
- /* we're not using af_angle_atan anymore, but we keep the source
- * code below just in case :-)
+ /*
+ * We are not using `af_angle_atan' anymore, but we keep the source
+ * code below just in case...
*/
+
+
#if 0
- /* the trick here is to realize that we don't need an very accurate
- * angle approximation. We're going to use the result of af_angle_atan
- * to only compare the sign of angle differences, or see if its magnitude
- * is very small.
- *
- * the approximation (dy*PI/(|dx|+|dy|))) should be enough, and much
- * faster to compute.
- */
+
+ /*
+ * The trick here is to realize that we don't need a very accurate angle
+ * approximation. We are going to use the result of `af_angle_atan' to
+ * only compare the sign of angle differences, or check whether its
+ * magnitude is very small.
+ *
+ * The approximation
+ *
+ * dy * PI / (|dx|+|dy|)
+ *
+ * should be enough, and much faster to compute.
+ */
FT_LOCAL_DEF( AF_Angle )
af_angle_atan( FT_Fixed dx,
FT_Fixed dy )
@@ -85,8 +105,11 @@
FT_Fixed ax = dx;
FT_Fixed ay = dy;
- if ( ax < 0 ) ax = -ax;
- if ( ay < 0 ) ay = -ay;
+
+ if ( ax < 0 )
+ ax = -ax;
+ if ( ay < 0 )
+ ay = -ay;
ax += ay;
@@ -94,7 +117,7 @@
angle = 0;
else
{
- angle = (AF_ANGLE_PI2*dy)/(ax+ay);
+ angle = ( AF_ANGLE_PI2 * dy ) / ( ax + ay );
if ( dx < 0 )
{
if ( angle >= 0 )
@@ -107,8 +130,10 @@
return angle;
}
+
#elif 0
+
/* the following table has been automatically generated with */
/* the `mather.py' Python script */
@@ -211,7 +236,7 @@
}
-#endif
+#endif /* 0 */
FT_LOCAL_DEF( void )
diff --git a/src/autofit/afcjk.c b/src/autofit/afcjk.c
index 78d4fd8..2d01111 100644
--- a/src/autofit/afcjk.c
+++ b/src/autofit/afcjk.c
@@ -1438,7 +1438,7 @@
static const AF_Script_UniRangeRec af_cjk_uniranges[] =
{
#if 0
- { 0x0100, 0xFFFF }, /* why ?? */
+ { 0x0100, 0xFFFF }, /* why this? */
#endif
{ 0x2E80, 0x2EFF }, /* CJK Radicals Supplement */
{ 0x2F00, 0x2FDF }, /* Kangxi Radicals */
diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c
index 818c6b7..6b3a310 100644
--- a/src/autofit/afhints.c
+++ b/src/autofit/afhints.c
@@ -267,16 +267,18 @@
#endif /* AF_DEBUG */
-
/* compute the direction value of a given vector */
FT_LOCAL_DEF( AF_Direction )
af_direction_compute( FT_Pos dx,
FT_Pos dy )
{
+
#if 1
+
FT_Pos ll, ss; /* long and short arm lengths */
AF_Direction dir; /* candidate direction */
+
if ( dy >= dx )
{
if ( dy >= -dx )
@@ -309,11 +311,13 @@
}
ss *= 12;
- if ( ll <= FT_ABS(ss) )
+ if ( ll <= FT_ABS( ss ) )
dir = AF_DIR_NONE;
return dir;
+
#else /* 0 */
+
AF_Direction dir;
FT_Pos ax = FT_ABS( dx );
FT_Pos ay = FT_ABS( dy );
@@ -335,13 +339,16 @@
}
return dir;
+
#endif /* 0 */
}
/* compute all inflex points in a given glyph */
+
#if 1
+
static void
af_glyph_hints_compute_inflections( AF_GlyphHints hints )
{
@@ -403,7 +410,7 @@
in_x = out_x;
in_y = out_y;
- /* now, process all segments in the contour */
+ /* now process all segments in the contour */
do
{
/* first, extend current segment's end whenever possible */
@@ -439,8 +446,8 @@
start->flags |= AF_FLAG_INFLECTION;
}
- start = end;
- end = after;
+ start = end;
+ end = after;
orient_prev = orient_cur;
in_x = out_x;
@@ -454,6 +461,7 @@
}
#else /* old code */
+
static void
af_glyph_hints_compute_inflections( AF_GlyphHints hints )
{
@@ -560,6 +568,7 @@
;
}
}
+
#endif /* old code */
@@ -809,7 +818,9 @@
}
else if ( point->out_dir == point->in_dir )
{
+
#if 1
+
if ( point->out_dir != AF_DIR_NONE )
goto Is_Weak_Point;
@@ -817,6 +828,7 @@
goto Is_Weak_Point;
#else /* old code */
+
AF_Angle angle_in, angle_out, delta;
@@ -830,7 +842,9 @@
if ( delta < 2 && delta > -2 )
goto Is_Weak_Point;
+
#endif /* old code */
+
}
else if ( point->in_dir == -point->out_dir )
goto Is_Weak_Point;
diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c
index 5329a0b..48c36b2 100644
--- a/src/autofit/aflatin.c
+++ b/src/autofit/aflatin.c
@@ -602,6 +602,7 @@
FT_Pos max_coord = -32000;
#endif
+
FT_ZERO( &seg0 );
seg0.score = 32000;
seg0.flags = AF_EDGE_NORMAL;
diff --git a/src/autofit/aftypes.h b/src/autofit/aftypes.h
index ebce1a3..078bc82 100644
--- a/src/autofit/aftypes.h
+++ b/src/autofit/aftypes.h
@@ -137,27 +137,30 @@ FT_BEGIN_HEADER
#endif /* 0 */
- /* return TRUE if a corner is flat, or nearly flat, this is equivalent
- * to say that the angle difference between the 'in' and 'out' vectors is
- * very small
- */
+ /*
+ * Return TRUE if a corner is flat or nearly flat. This is equivalent to
+ * saying that the angle difference between the `in' and `out' vectors is
+ * very small.
+ */
FT_LOCAL( FT_Int )
- af_corner_is_flat( FT_Pos x_in,
- FT_Pos y_in,
- FT_Pos x_out,
- FT_Pos y_out );
-
- /* return a value that can be -1, 0 or +1 depending on the orientation
- * of a given corner. We're using the Cartesian coordinate system,
- * with positive Ys going upwards. The function returns +1 when
- * the corner turns to the left, -1 to the right, and 0 for undecided
- */
+ af_corner_is_flat( FT_Pos x_in,
+ FT_Pos y_in,
+ FT_Pos x_out,
+ FT_Pos y_out );
+
+ /*
+ * Return -1, 0, or +1, depending on the orientation of a given corner.
+ * We use the Cartesian coordinate system, with positive vertical values
+ * going upwards. The function returns +1 when the corner turns to the
+ * left, -1 to the right, and 0 for undecided.
+ */
FT_LOCAL( FT_Int )
af_corner_orientation( FT_Pos x_in,
FT_Pos y_in,
FT_Pos x_out,
FT_Pos y_out );
+
#define AF_ANGLE_DIFF( result, angle1, angle2 ) \
FT_BEGIN_STMNT \
AF_Angle _delta = (angle2) - (angle1); \
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index f75bc9a..ede9308 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -396,29 +396,32 @@
FT_MulFix( FT_Long a,
FT_Long b )
{
- /* let's use inline assembly to speed things a bit */
-#if defined(__GNUC__) && defined(i386)
+ /* use inline assembly to speed up things a bit */
+
+#if defined( __GNUC__ ) && defined( i386 )
FT_Long result;
+
__asm__ __volatile__ (
- "imul %%edx\n"
- "movl %%edx, %%ecx\n"
- "sarl $31, %%ecx\n"
- "addl $0x8000, %%ecx\n"
- "addl %%ecx, %%eax\n"
- "adcl $0, %%edx\n"
- "shrl $16, %%eax\n"
- "shll $16, %%edx\n"
- "addl %%edx, %%eax\n"
- "mov %%eax, %0\n"
- : "=r"(result)
- : "a"(a), "d"(b)
- : "%ecx"
- );
- return result;
+ "imul %%edx\n"
+ "movl %%edx, %%ecx\n"
+ "sarl $31, %%ecx\n"
+ "addl $0x8000, %%ecx\n"
+ "addl %%ecx, %%eax\n"
+ "adcl $0, %%edx\n"
+ "shrl $16, %%eax\n"
+ "shll $16, %%edx\n"
+ "addl %%edx, %%eax\n"
+ "mov %%eax, %0\n"
+ : "=r"(result)
+ : "a"(a), "d"(b)
+ : "%ecx"
+ );
+ return result;
#elif 1
+
FT_Long sa, sb;
FT_ULong ua, ub;
@@ -427,24 +430,22 @@
return a;
sa = ( a >> ( sizeof ( a ) * 8 - 1 ) );
- a = ( a ^ sa ) - sa;
+ a = ( a ^ sa ) - sa;
sb = ( b >> ( sizeof ( b ) * 8 - 1 ) );
- b = ( b ^ sb ) - sb;
+ b = ( b ^ sb ) - sb;
ua = (FT_ULong)a;
ub = (FT_ULong)b;
if ( ua <= 2048 && ub <= 1048576L )
- {
- ua = ( ua * ub + 0x8000 ) >> 16;
- }
+ ua = ( ua * ub + 0x8000U ) >> 16;
else
{
- FT_ULong al = ua & 0xFFFF;
+ FT_ULong al = ua & 0xFFFFU;
ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
- ( ( al * ( ub & 0xFFFF ) + 0x8000 ) >> 16 );
+ ( ( al * ( ub & 0xFFFFU ) + 0x8000U ) >> 16 );
}
sa ^= sb,
@@ -461,23 +462,21 @@
if ( a == 0 || b == 0x10000L )
return a;
- s = a; a = FT_ABS(a);
- s ^= b; b = FT_ABS(b);
+ s = a; a = FT_ABS( a );
+ s ^= b; b = FT_ABS( b );
ua = (FT_ULong)a;
ub = (FT_ULong)b;
if ( ua <= 2048 && ub <= 1048576L )
- {
- ua = ( ua * ub + 0x8000L ) >> 16;
- }
+ ua = ( ua * ub + 0x8000UL ) >> 16;
else
{
- FT_ULong al = ua & 0xFFFFL;
+ FT_ULong al = ua & 0xFFFFUL;
ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
- ( ( al * ( ub & 0xFFFFL ) + 0x8000L ) >> 16 );
+ ( ( al * ( ub & 0xFFFFUL ) + 0x8000UL ) >> 16 );
}
return ( s < 0 ? -(FT_Long)ua : (FT_Long)ua );
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index cef7ae7..a6d5553 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -1013,24 +1013,29 @@
}
#if 1
+
{
FT_Pos dx1 = prev->x - xmin_point->x;
FT_Pos dy1 = prev->y - xmin_point->y;
FT_Pos dx2 = next->x - xmin_point->x;
FT_Pos dy2 = next->y - xmin_point->y;
- if ( dy1*dx2 > dy2*dx1 )
+
+ if ( dy1 * dx2 > dy2 * dx1 )
return FT_ORIENTATION_POSTSCRIPT;
else
return FT_ORIENTATION_TRUETYPE;
}
-#else
+
+#else /* 0 */
+
if ( FT_Atan2( prev->x - xmin_point->x, prev->y - xmin_point->y ) >
FT_Atan2( next->x - xmin_point->x, next->y - xmin_point->y ) )
return FT_ORIENTATION_POSTSCRIPT;
else
return FT_ORIENTATION_TRUETYPE;
-#endif
+
+#endif /* 0 */
}
diff --git a/src/cache/ftccmap.c b/src/cache/ftccmap.c
index 4d6fd9a..1568e5e 100644
--- a/src/cache/ftccmap.c
+++ b/src/cache/ftccmap.c
@@ -307,9 +307,9 @@
* It is also very unlikely that a rogue client is interested
* in Unicode values 0 to 15.
*
- * NOTE: The original threshold was 4, but we found a font
- * from the Adobe Acrobat Reader Pack, named
- * "KozMinProVI-Regular.otf" which contained more than 5 charmaps.
+ * NOTE: The original threshold was 4, but we found a font from the
+ * Adobe Acrobat Reader Pack, named `KozMinProVI-Regular.otf',
+ * which contains more than 5 charmaps.
*/
if ( cmap_index >= 16 )
{
diff --git a/src/gzip/ftgzip.c b/src/gzip/ftgzip.c
index f3ab4f9..af2022d 100644
--- a/src/gzip/ftgzip.c
+++ b/src/gzip/ftgzip.c
@@ -561,6 +561,7 @@
FT_ULong old_pos;
FT_ULong result = 0;
+
old_pos = stream->pos;
if ( !FT_Stream_Seek( stream, stream->size - 4 ) )
{
@@ -607,24 +608,28 @@
stream->descriptor.pointer = zip;
}
- /* ok, here's a trick to try to dramatically improve the performance
- * of dealing with small files. If the original stream size is less
- * than a certain threshold, we try to load the whole font file in
- * memory. this saves us from the 32KB buffer needed to inflate the
- * file anyway, plus the two 4KB intermediate input/output buffers
- * used in the FT_GZipFile structure.
- */
+ /*
+ * We use the following trick to try to dramatically improve the
+ * performance while dealing with small files. If the original stream
+ * size is less than a certain threshold, we try to load the whole font
+ * file into memory. This saves us from using the 32KB buffer needed
+ * to inflate the file, plus the two 4KB intermediate input/output
+ * buffers used in the `FT_GZipFile' structure.
+ */
{
- FT_ULong zip_size = ft_gzip_get_uncompressed_size( source );
+ FT_ULong zip_size = ft_gzip_get_uncompressed_size( source );
+
- if ( zip_size != 0 && zip_size < 40*1024 )
+ if ( zip_size != 0 && zip_size < 40 * 1024 )
{
FT_Byte* zip_buff;
+
if ( !FT_ALLOC( zip_buff, zip_size ) )
{
FT_ULong count;
+
count = ft_gzip_file_io( zip, 0, zip_buff, zip_size );
if ( count == zip_size )
{
@@ -641,6 +646,7 @@
goto Exit;
}
+
ft_gzip_file_io( zip, 0, NULL, 0 );
FT_FREE( zip_buff );
}
diff --git a/src/psaux/psconv.c b/src/psaux/psconv.c
index bfb679b..3bbeab6 100644
--- a/src/psaux/psconv.c
+++ b/src/psaux/psconv.c
@@ -337,28 +337,30 @@
n *= 2;
+
#if 1
+
p = *cursor;
- if ( n > (FT_UInt)(limit-p) )
- n = (FT_UInt)(limit - p);
+ if ( n > (FT_UInt)( limit - p ) )
+ n = (FT_UInt)( limit - p );
- /* we try to process two nibbles at a time to be as fast as possible
- */
+ /* we try to process two nibbles at a time to be as fast as possible */
for ( ; r < n; r++ )
{
FT_UInt c = p[r];
- if ( IS_PS_SPACE(c) )
+
+ if ( IS_PS_SPACE( c ) )
continue;
if ( c OP 0x80 )
break;
- c = ft_char_table[ c & 0x7F ];
+ c = ft_char_table[c & 0x7F];
if ( (unsigned)c >= 16 )
break;
- pad = (pad << 4) | c;
+ pad = ( pad << 4 ) | c;
if ( pad & 0x100 )
{
buffer[w++] = (FT_Byte)pad;
@@ -367,11 +369,14 @@
}
if ( pad != 0x01 )
- buffer[w++] = (FT_Byte)(pad << 4);
+ buffer[w++] = (FT_Byte)( pad << 4 );
+
+ *cursor = p + r;
- *cursor = p+r;
return w;
-#else
+
+#else /* 0 */
+
for ( r = 0; r < n; r++ )
{
FT_Char c;
@@ -402,7 +407,9 @@
*cursor = p;
return ( r + 1 ) / 2;
-#endif
+
+#endif /* 0 */
+
}
@@ -413,11 +420,13 @@
FT_UInt n,
FT_UShort* seed )
{
- FT_Byte* p;
- FT_UInt r;
- FT_UInt s = *seed;
+ FT_Byte* p;
+ FT_UInt r;
+ FT_UInt s = *seed;
+
#if 1
+
p = *cursor;
if ( n > (FT_UInt)(limit - p) )
n = (FT_UInt)(limit - p);
@@ -425,7 +434,8 @@
for ( r = 0; r < n; r++ )
{
FT_UInt val = p[r];
- FT_UInt b = ( val ^ (s >> 8) );
+ FT_UInt b = ( val ^ ( s >> 8 ) );
+
s = ( (val + s)*52845U + 22719 ) & 0xFFFFU;
buffer[r] = (FT_Byte) b;
@@ -433,7 +443,9 @@
*cursor = p + n;
*seed = (FT_UShort)s;
-#else
+
+#else /* 0 */
+
for ( r = 0, p = *cursor; r < n && p < limit; r++, p++ )
{
FT_Byte b = (FT_Byte)( *p ^ ( s >> 8 ) );
@@ -444,7 +456,8 @@
}
*cursor = p;
*seed = s;
-#endif
+
+#endif /* 0 */
return r;
}
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 26c6429..039649e 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -208,19 +208,19 @@
FT_CALLBACK_DEF( FT_Error )
TT_Load_Glyph_Header( TT_Loader loader )
{
- FT_Byte* p = loader->cursor;
- FT_Byte* limit = loader->limit;
+ FT_Byte* p = loader->cursor;
+ FT_Byte* limit = loader->limit;
if ( p + 10 > limit )
return TT_Err_Invalid_Outline;
- loader->n_contours = FT_NEXT_SHORT(p);
+ loader->n_contours = FT_NEXT_SHORT( p );
- loader->bbox.xMin = FT_NEXT_SHORT(p);
- loader->bbox.yMin = FT_NEXT_SHORT(p);
- loader->bbox.xMax = FT_NEXT_SHORT(p);
- loader->bbox.yMax = FT_NEXT_SHORT(p);
+ loader->bbox.xMin = FT_NEXT_SHORT( p );
+ loader->bbox.yMin = FT_NEXT_SHORT( p );
+ loader->bbox.xMax = FT_NEXT_SHORT( p );
+ loader->bbox.yMax = FT_NEXT_SHORT( p );
FT_TRACE5(( " # of contours: %d\n", loader->n_contours ));
FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin,
@@ -263,11 +263,11 @@
cont_limit = cont + n_contours;
/* check space for contours array + instructions count */
- if ( n_contours >= 0xFFF || p + (n_contours+1)*2 > limit )
+ if ( n_contours >= 0xFFF || p + (n_contours + 1) * 2 > limit )
goto Invalid_Outline;
for ( ; cont < cont_limit; cont++ )
- cont[0] = FT_NEXT_USHORT(p);
+ cont[0] = FT_NEXT_USHORT( p );
n_points = 0;
if ( n_contours > 0 )
@@ -289,10 +289,10 @@
load->glyph->control_len = 0;
load->glyph->control_data = 0;
- if ( p+2 > limit )
+ if ( p + 2 > limit )
goto Invalid_Outline;
- n_ins = FT_NEXT_USHORT(p);
+ n_ins = FT_NEXT_USHORT( p );
FT_TRACE5(( " Instructions size: %u\n", n_ins ));
@@ -303,7 +303,7 @@
goto Fail;
}
- if ( (limit - p) < n_ins )
+ if ( ( limit - p ) < n_ins )
{
FT_TRACE0(( "TT_Load_Simple_Glyph: Instruction count mismatch!\n" ));
error = TT_Err_Too_Many_Hints;
@@ -332,16 +332,16 @@
while ( flag < flag_limit )
{
- if ( p+1 > limit )
+ if ( p + 1 > limit )
goto Invalid_Outline;
- *flag++ = c = FT_NEXT_BYTE(p);
+ *flag++ = c = FT_NEXT_BYTE( p );
if ( c & 8 )
{
- if ( p+1 > limit )
+ if ( p + 1 > limit )
goto Invalid_Outline;
- count = FT_NEXT_BYTE(p);
+ count = FT_NEXT_BYTE( p );
if ( flag + (FT_Int)count > flag_limit )
goto Invalid_Outline;
@@ -364,19 +364,19 @@
if ( *flag & 2 )
{
- if ( p+1 > limit )
+ if ( p + 1 > limit )
goto Invalid_Outline;
- y = (FT_Pos)FT_NEXT_BYTE(p);
+ y = (FT_Pos)FT_NEXT_BYTE( p );
if ( ( *flag & 16 ) == 0 )
y = -y;
}
else if ( ( *flag & 16 ) == 0 )
{
- if ( p+2 > limit )
+ if ( p + 2 > limit )
goto Invalid_Outline;
- y = (FT_Pos)FT_NEXT_SHORT(p);
+ y = (FT_Pos)FT_NEXT_SHORT( p );
}
x += y;
@@ -397,19 +397,19 @@
if ( *flag & 4 )
{
- if ( p+1 > limit )
+ if ( p +1 > limit )
goto Invalid_Outline;
- y = (FT_Pos)FT_NEXT_BYTE(p);
+ y = (FT_Pos)FT_NEXT_BYTE( p );
if ( ( *flag & 32 ) == 0 )
y = -y;
}
else if ( ( *flag & 32 ) == 0 )
{
- if ( p+2 > limit )
+ if ( p + 2 > limit )
goto Invalid_Outline;
- y = (FT_Pos)FT_NEXT_SHORT(p);
+ y = (FT_Pos)FT_NEXT_SHORT( p );
}
x += y;
@@ -459,15 +459,15 @@
goto Fail;
/* check space */
- if ( p+4 > limit )
+ if ( p + 4 > limit )
goto Invalid_Composite;
subglyph = gloader->current.subglyphs + num_subglyphs;
subglyph->arg1 = subglyph->arg2 = 0;
- subglyph->flags = FT_NEXT_USHORT(p);
- subglyph->index = FT_NEXT_USHORT(p);
+ subglyph->flags = FT_NEXT_USHORT( p );
+ subglyph->index = FT_NEXT_USHORT( p );
/* check space */
count = 2;
@@ -486,13 +486,13 @@
/* read arguments */
if ( subglyph->flags & ARGS_ARE_WORDS )
{
- subglyph->arg1 = FT_NEXT_SHORT(p);
- subglyph->arg2 = FT_NEXT_SHORT(p);
+ subglyph->arg1 = FT_NEXT_SHORT( p );
+ subglyph->arg2 = FT_NEXT_SHORT( p );
}
else
{
- subglyph->arg1 = FT_NEXT_CHAR(p);
- subglyph->arg2 = FT_NEXT_CHAR(p);
+ subglyph->arg1 = FT_NEXT_CHAR( p );
+ subglyph->arg2 = FT_NEXT_CHAR( p );
}
/* read transform */
@@ -501,20 +501,20 @@
if ( subglyph->flags & WE_HAVE_A_SCALE )
{
- xx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
+ xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
yy = xx;
}
else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
{
- xx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
- yy = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
+ xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
+ yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
}
else if ( subglyph->flags & WE_HAVE_A_2X2 )
{
- xx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
- yx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
- xy = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
- yy = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
+ xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
+ yx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
+ xy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
+ yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
}
subglyph->transform.xx = xx;
@@ -531,6 +531,9 @@
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
{
+ FT_Stream stream = loader->stream;
+
+
/* we must undo the FT_FRAME_ENTER in order to point to the */
/* composite instructions, if we find some. */
/* we will process them later... */