Commit caf72cd6e5765aa5419f2f3e8e42610181dc82e8

David Turner 2001-04-25T18:11:16

* src/base/ftbbox.c (BBox_Cubic_Check): rewrote function to use direct computations with 16.16 values instead of sub-divisions. It is now slower, but proves a point :-) * src/raster/ftraster.c, src/smooth/ftgrays.c, src/base/ftbbox.c : fixed the bezier stack depths.. * src/base/ftcalc.c (FT_MulFix): minor rounding fix * builds/beos : added BeOS-specific files to the old build system (no changes were necessary to support BeOS in the Jamfile though)

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
diff --git a/ChangeLog b/ChangeLog
index 32a92e3..141d0c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,23 +1,27 @@
-2001-04-24  Werner Lemberg  <wl@gnu.org>
+2001-04-25  David Turner  <david@freetype.org>
 
-	* builds/unix/config.guess, builds/unix/config.sub: Updated to
-	latest versions from gnu.org.
+        * src/base/ftbbox.c (BBox_Cubic_Check): rewrote function to use
+        direct computations with 16.16 values instead of sub-divisions.
+        It is now slower, but proves a point :-)
 
-2001-04-22  Werner Lemberg  <wl@gnu.org>
+        * src/raster/ftraster.c, src/smooth/ftgrays.c, src/base/ftbbox.c :
+        fixed the bezier stack depths..
 
-	* builds/compiler/gcc-dev.mk: Add `-Wno-long-long' flag.
+        * src/base/ftcalc.c (FT_MulFix): minor rounding fix
 
-2001-04-20  David Turner  <david@freetype.org>
+        * builds/beos : added BeOS-specific files to the old build system
+        (no changes were necessary to support BeOS in the Jamfile though)
 
-	* ftconfig.h, ftoption.h: Updated "ftconfig.h" to detect 64-bit int
-	types on platforms where Autoconf is not available.  Also removed
-	FTCALC_USE_LONG_LONG and replaced it with
-	FT_CONFIG_OPTION_FORCE_INT64.
+2001-04-20  David Turner  <david@freetype.org>
 
-	* builds/win32/freetype.dsp: Updated the Visual C++ project file.
-	Doesn't create a DLL yet.
+	* ftconfig.h, ftoption.h: updated "ftconfig.h" to detect 64-bit int
+	types on platforms where Autoconf is not available). Also removed
+	FTCALC_USE_LONG_LONG and replaced it with FT_CONFIG_OPTION_FORCE_INT64
+	
+	* builds/win32/freetype.dsp: updated the Visual C++ project file. Doesn't
+	create a DLL yet..
 
-	* cffgload.c: Removed a compilation warning.
+	* cffgload.c: removed a compilation warning
 
 2001-04-10  Tom Kacvinsky  <tjk@ams.org>
 
diff --git a/builds/beos/beos-def.mk b/builds/beos/beos-def.mk
new file mode 100644
index 0000000..60f9def
--- /dev/null
+++ b/builds/beos/beos-def.mk
@@ -0,0 +1,96 @@
+#
+# FreeType 2 configuration rules for a BeOS system
+#
+# this is similar to the "ansi-def.mk" file, except for BUILD and PLATFORM
+#
+
+
+# Copyright 1996-2000 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
+
+
+ifndef TOP
+  TOP := .
+endif
+
+DELETE   := rm -f
+SEP      := /
+HOSTSEP  := $(SEP)
+BUILD    := $(TOP)/builds/neos
+PLATFORM := beos
+
+
+# The directory where all object files are placed.
+#
+# This lets you build the library in your own directory with something like
+#
+#   set TOP=.../path/to/freetype2/top/dir...
+#   set OBJ_DIR=.../path/to/obj/dir
+#   make -f $TOP/Makefile setup [options]
+#   make -f $TOP/Makefile
+#
+ifndef OBJ_DIR
+  OBJ_DIR := $(TOP)$(SEP)objs
+endif
+
+
+# The directory where all library files are placed.
+#
+# By default, this is the same as $(OBJ_DIR); however, this can be changed
+# to suit particular needs.
+#
+LIB_DIR := $(OBJ_DIR)
+
+
+# The name of the final library file.  Note that the DOS-specific Makefile
+# uses a shorter (8.3) name.
+#
+LIBRARY := lib$(PROJECT)
+
+
+# Path inclusion flag.  Some compilers use a different flag than `-I' to
+# specify an additional include path.  Examples are `/i=' or `-J'.
+#
+I := -I
+
+
+# C flag used to define a macro before the compilation of a given source
+# object.  Usually it is `-D' like in `-DDEBUG'.
+#
+D := -D
+
+
+# The link flag used to specify a given library file on link.  Note that
+# this is only used to compile the demo programs, not the library itself.
+#
+L := -l
+
+
+# Target flag.
+#
+T := -o$(space)
+
+
+# C flags
+#
+#   These should concern: debug output, optimization & warnings.
+#
+#   Use the ANSIFLAGS variable to define the compiler flags used to enfore
+#   ANSI compliance.
+#
+ifndef CFLAGS
+  CFLAGS := -c
+endif
+
+# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant.
+#
+ANSIFLAGS :=
+
+
+# EOF
diff --git a/builds/beos/beos.mk b/builds/beos/beos.mk
new file mode 100644
index 0000000..956b96a
--- /dev/null
+++ b/builds/beos/beos.mk
@@ -0,0 +1,18 @@
+#
+# FreeType 2 configuration rules for a BeOS system
+#
+
+# Copyright 1996-2000 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
+
+include $(TOP)/builds/compiler/ansi-cc.mk
+include $(TOP)/builds/beos/beos-def.mk
+
+# EOF
+
diff --git a/builds/beos/detect.mk b/builds/beos/detect.mk
new file mode 100644
index 0000000..30330c7
--- /dev/null
+++ b/builds/beos/detect.mk
@@ -0,0 +1,41 @@
+#
+# FreeType 2 configuration file to detect an BeOS host platform.
+#
+
+
+# Copyright 1996-2000 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
+
+
+.PHONY: setup
+
+
+ifeq ($(PLATFORM),ansi)
+
+  ifdef BE_HOST_CPU
+
+    PLATFORM := beos
+
+  endif # test MACHTYPE beos
+endif
+
+ifeq ($(PLATFORM),beos)
+
+  DELETE   := rm -f
+  SEP      := /
+  HOSTSEP  := $(SEP)
+  BUILD    := $(TOP)/builds/beos
+  CONFIG_FILE := beos.mk
+
+  setup: std_setup
+
+endif   # test PLATFORM beos
+
+# EOF
+
diff --git a/docs/docmaker.py b/docs/docmaker.py
index 067e162..5c0c304 100644
--- a/docs/docmaker.py
+++ b/docs/docmaker.py
@@ -10,10 +10,18 @@
 
 import fileinput, sys, string, glob
 
-html_header = """\
+# the Project's title, this can be over-ridden from the command line with
+# an option
+project_title = "Project"
+
+# The following defines the HTML header used by all generated pages
+#
+html_header_1 = """\
 <html>
 <header>
-<title>FreeType 2 API Reference</title>
+<title>"""
+
+html_header_2= """ API Reference</title>
 <basefont face="Georgia, Arial, Helvetica, Geneva">
 <style content="text/css">
   P { text-align=justify }
@@ -26,35 +34,57 @@ html_header = """\
       link=#0000EF
       vlink=#51188E
       alink=#FF0000>
-<center><h1>FreeType 2 API Reference</h1></center>
+<center><h1>"""
+
+html_header_3=""" API Reference</h1></center>
 """
+# this is recomputed later when the project title changes
+html_header = html_header_1 + project_title + html_header_2 + project_title + html_header_3
 
+# The HTML footer used by all generated pages
+#
 html_footer = """\
 </body>
 </html>"""
 
+# The header and footer used for each section
+#
 section_title_header = "<center><h1>"
 section_title_footer = "</h1></center>"
 
+# The header and footer used for code segments
+#
 code_header = "<font color=blue><pre>"
 code_footer = "</pre></font>"
 
+# Paragraph header and footer
+#
 para_header = "<p>"
 para_footer = "</p>"
 
+# Block header and footer
+#
 block_header = "<center><table width=75%><tr><td>"
 block_footer = "</td></tr></table><hr width=75%></center>"
 
+# Description header/footer
+#
 description_header = "<center><table width=87%><tr><td>"
 description_footer = "</td></tr></table></center><br>"
 
+# Marker header/inter/footer combination
+#
 marker_header = "<center><table width=87% cellpadding=5><tr bgcolor=#EEEEFF><td><em><b>"
 marker_inter  = "</b></em></td></tr><tr><td>"
 marker_footer = "</td></tr></table></center>"
 
+# Source code extracts header/footer
+#
 source_header = "<center><table width=87%><tr bgcolor=#D6E8FF width=100%><td><pre>"
 source_footer = "</pre></table></center><br>"
 
+# Chapter header/inter/footer
+#
 chapter_header = "<center><table width=75%><tr><td><h2>"
 chapter_inter  = "</h2><ul>"
 chapter_footer = "</ul></td></tr></table></center>"
@@ -106,6 +136,16 @@ def sort_order_list( input_list, order_list ):
     return new_list
 
 
+# translate a single line of source to HTML. This will convert
+# a "<" into "&lt.", ">" into "&gt.", etc..
+#
+def html_format( line )
+    result = string.replace( line, "<", "&lt." )
+    result = string.replace( line, ">", "&gt." )
+    result = string.replace( line, "&", "&amp." )
+    return result
+
+
 # The FreeType 2 reference is extracted from the source files. These contain
 # various comment blocks that follow one of the following formats:
 #
@@ -153,7 +193,7 @@ def sort_order_list( input_list, order_list ):
 # The first two markers contain arbitrary text, while the last one contains
 # a list of fields.
 #
-# Each field is simple of the format:  WORD :: TEXT...
+# Each field is simply of the format:  WORD :: TEXT...
 #
 # Note that typically each comment block is followed by some source
 # code declaration that may need to be kept in the reference.
@@ -242,8 +282,8 @@ class DocCode:
         # line to avoid an additional blank line
         #
         sys.stdout.write( code_header )
-        for line in self.lines[0 : l+1]:
-            sys.stdout.write( '\n' + line )
+        for line in self.lines[0 : l+1]:            
+            sys.stdout.write( '\n' + html_format(line) )
         sys.stdout.write( code_footer )
 
 
@@ -320,7 +360,7 @@ class DocParagraph:
                     word = '?' + word
 
             if cursor + len( word ) + 1 > max_width:
-                print line
+                print html_format( line )
                 cursor = 0
                 line = ""
 
@@ -335,7 +375,7 @@ class DocParagraph:
             #
             if extra:
                 if cursor + len( extra ) + 1 > max_width:
-                    print line
+                    print html_format( line )
                     cursor = 0
                     line   = ""
 
@@ -344,7 +384,7 @@ class DocParagraph:
                 extra  = None
 
         if cursor > 0:
-            print line
+            print html_format(line)
 
         # print "§" # for debugging only
 
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index 917f1c8..3983783 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -338,6 +338,18 @@
   /*************************************************************************/
   /*                                                                       */
   /* @macro:                                                               */
+  /*    FT_BEZIER_H                                                        */
+  /*                                                                       */
+  /* @description:                                                         */
+  /*    A macro used in #include statements to name the file containing    */
+  /*    a small useful API to handle bezier arcs. Note that you _must_     */
+  /*    include FT_FREETYPE_H or FT_IMAGE_H before this header..           */
+  /*                                                                       */
+#define FT_BEZIER_H  <freetype/ftbezier.h>
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* @macro:                                                               */
   /*    FT_CACHE_H                                                         */
   /*                                                                       */
   /* @description:                                                         */
diff --git a/src/base/ftbbox.c b/src/base/ftbbox.c
index 657227b..59e3822 100644
--- a/src/base/ftbbox.c
+++ b/src/base/ftbbox.c
@@ -28,6 +28,7 @@
 #include FT_BBOX_H
 #include FT_IMAGE_H
 #include FT_OUTLINE_H
+#include FT_BEZIER_H
 
 
   typedef struct  TBBox_Rec_
@@ -101,7 +102,7 @@
                           FT_Pos*  min,
                           FT_Pos*  max )
   {
-    if ( y1 == y3 )
+    if ( y1 <= y3 )
     {
       if ( y2 == y1 )               /* Flat arc */
         goto Suite;
@@ -205,6 +206,7 @@
   /*    min :: The address of the current minimum.                         */
   /*    max :: The address of the current maximum.                         */
   /*                                                                       */
+#if 0
   static
   void  BBox_Cubic_Check( FT_Pos   p1,
                           FT_Pos   p2,
@@ -213,7 +215,7 @@
                           FT_Pos*  min,
                           FT_Pos*  max )
   {
-    FT_Pos  stack[33], *arc;
+    FT_Pos  stack[32*3+1], *arc;
 
 
     arc = stack;
@@ -252,7 +254,7 @@
         }
       }
 
-      /* Unknown direction, split the arc in two */
+      /* Unknown direction - split the arc in two */
       arc[6] = y4;
       arc[1] = y1 = ( y1 + y2 ) / 2;
       arc[5] = y4 = ( y4 + y3 ) / 2;
@@ -273,6 +275,164 @@
       ;
     } while ( arc >= stack );
   }
+#else
+
+  static void
+  test_cubic_zero( FT_Pos    y1,
+                   FT_Pos    y2,
+                   FT_Pos    y3,
+                   FT_Pos    y4,
+                   FT_Fixed  u,
+                   FT_Pos*   min,
+                   FT_Pos*   max )
+  {
+    FT_Pos   a = y4 - 3*y3 + 3*y2 - y1;
+    FT_Pos   b = y3 - 2*y2 + y1;
+    FT_Pos   c = y2 - y1;
+    FT_Pos   d = y1;
+    FT_Pos   y;
+    FT_Fixed uu;
+    
+    /* the polynom is "a*x^3 + 3b*x^2 + 3c*x + d", however, we also      */
+    /* have dP/dx(u) = 0, which implies that P(t0) = b*t0^2 + 2c*t0 + d  */
+    if ( u > 0 && u < 0x10000L )
+    {
+      uu = FT_MulFix( u, u );
+      y  = d + FT_MulFix( c, 2*u ) + FT_MulFix( b, uu );
+
+      if ( y < *min ) *min = y;
+      if ( y > *max ) *max = y;
+    }
+  }
+
+
+  static
+  void  BBox_Cubic_Check( FT_Pos   y1,
+                          FT_Pos   y2,
+                          FT_Pos   y3,
+                          FT_Pos   y4,
+                          FT_Pos*  min,
+                          FT_Pos*  max )
+  {
+    /* always compare first and last points */
+    if      ( y1 < *min )  *min = y1;
+    else if ( y1 > *max )  *max = y1;
+    
+    if      ( y4 < *min )  *min = y4;
+    else if ( y4 > *max )  *max = y4;
+
+    /* now, try to see if there are split points here */
+    if ( y1 <= y4 )
+    {
+      /* flat or ascending arc test */
+      if ( y1 <= y2 && y2 <= y4 && y1 <= y3 && y3 <= y4 )
+        return;
+    }
+    else /* y1 > y4 */
+    {
+      /* descending arc test */
+      if ( y1 >= y2 && y2 >= y4 && y1 >= y3 && y3 >= y4 )
+        return;
+    }
+
+    /* there are some split points, now, find them.. */
+    {
+      FT_Pos    a = y4 - 3*y3 + 3*y2 - y1;
+      FT_Pos    b = y3 - 2*y2 + y1;
+      FT_Pos    c = y2 - y1;
+      FT_Pos    d, t1;
+      FT_Fixed  t;
+      
+      /* we need to solve "ax˛+2bx+c" here, without floating points !!     */
+      /* the trick is to normalize to a different representation in order  */
+      /* to use our 16.16 fixed point routines..                           */
+      /*                                                                   */
+      /* we're going to compute FT_MulFix(b,b) and FT_MulFix(a,c) after    */
+      /* the normalisation. these values must fit in a single 16.16        */
+      /* value.                                                            */
+      /*                                                                   */
+      /* we normalize a, b and c to "8.16" fixed float values to ensure    */
+      /* that their product is held in a "16.16" value..                   */
+      /*                                                                   */
+      {
+        FT_ULong  t1, t2;
+        int       shift = 0;
+        
+        t1  = (FT_ULong)((a >= 0) ? a : -a );
+        t2  = (FT_ULong)((b >= 0) ? b : -b );
+        t1 |= t2;
+        t2  = (FT_ULong)((c >= 0) ? c : -c );
+        t1 |= t2;
+        
+        if ( t1 == 0 )  /* all coefficients are 0 !! */
+          return;
+        
+        if ( t1 > 0xFFFFFFL )
+        {
+          /* on 64-bit machines .. */
+          do
+          {
+            shift--;
+            t1 >>= 1;
+          }
+          while ( t1 > 0xFFFFFFL );
+          
+          a >>= shift;
+          b >>= shift;
+          c >>= shift;
+        }
+        else if ( t1 < 0x800000L )
+        {
+          do
+          {
+            shift++;
+            t1 <<= 1;
+          }
+          while ( t1 < 0x800000L );
+          
+          a <<= shift;
+          b <<= shift;
+          c <<= shift;
+        }
+      }
+
+      /* handle a == 0 */
+      if ( a == 0 )
+      {
+        if ( b != 0 )
+        {
+          t = - FT_DivFix( c, b )/2;
+          test_cubic_zero( y1, y2, y3, y4, t, min, max );
+        }
+      }
+      else
+      {
+        /* solve the equation now */
+        d = FT_MulFix( b, b ) - FT_MulFix( a, c );
+        if ( d < 0 )
+          return;
+
+        if ( d == 0 )
+        {
+          /* there is a single split point, at -b/a */
+          t = - FT_DivFix( b, a );
+          test_cubic_zero( y1, y2, y3, y4, t, min, max );
+        }
+        else
+        {
+          /* there are two solutions, we need to filter them though */
+          d = FT_SqrtFixed( (FT_Int32)d );
+          t = - FT_DivFix( b - d, a );
+          test_cubic_zero( y1, y2, y3, y4, t, min, max );
+          
+          t = - FT_DivFix( b + d, a );
+          test_cubic_zero( y1, y2, y3, y4, t, min, max );
+        }
+      }
+    }
+ }
+
+#endif
 
 
   /*************************************************************************/
@@ -368,6 +528,7 @@
     vec = outline->points;
     bbox.xMin = bbox.xMax = cbox.xMin = cbox.xMax = vec->x;
     bbox.yMin = bbox.yMax = cbox.yMin = cbox.yMax = vec->y;
+    vec++;
 
     for ( n = 1; n < outline->n_points; n++ )
     {
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index ec7202a..eda214d 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -309,9 +309,8 @@
       FT_ULong  al = ua & 0xFFFF;
 
 
-      ua = ( ua >> 16 ) * ub +
-           al * ( ub >> 16 ) +
-           ( al * ( ub & 0xFFFF ) >> 16 );
+      ua = ( ua >> 16 ) * ub +  al * ( ub >> 16 ) +
+           ( ( al * ( ub & 0xFFFF ) + 0x8000 ) >> 16 );
     }
 
     return ( s < 0 ? -(FT_Long)ua : ua );
@@ -551,18 +550,40 @@
   }
 
 
+
+#endif /* FT_CONFIG_OPTION_OLD_CALCS */
+
+
+ /* a not-so-fast but working 16.16 fixed point square root function */
   FT_EXPORT_DEF( FT_Int32 )  FT_SqrtFixed( FT_Int32  x )
   {
-    FT_Int64  z;
-
+    FT_UInt32  root, rem_hi, rem_lo, test_div;
+    FT_Int     count;
 
-    z.hi = (FT_UInt32)((FT_Int32)(x) >> 16);
-    z.lo = (FT_UInt32)( x << 16 );
-    return FT_Sqrt64( &z );
-  }
+    root = 0;
 
+    if ( x > 0 )
+    {
+      rem_hi = 0;
+      rem_lo = x;
+      count  = 32;
+      do
+      {
+        rem_hi   = (rem_hi << 2) | (rem_lo >> 30);
+        rem_lo <<= 2;
+        root   <<= 1;
+        test_div = (root << 1) + 1;
+        if ( rem_hi >= test_div )
+        {
+          rem_hi -= test_div;
+          root   += 1;
+        }
+        count--;
+      }
+    }
 
-#endif /* FT_CONFIG_OPTION_OLD_CALCS */
+    return (FT_Int32)root;
+  }
 
 #endif /* FT_LONG64 */
 
diff --git a/src/raster/ftraster.c b/src/raster/ftraster.c
index ef35b80..d8cf1d7 100644
--- a/src/raster/ftraster.c
+++ b/src/raster/ftraster.c
@@ -436,7 +436,7 @@
                                     /* no horizontal pass during gray      */
                                     /* rendering.                          */
 
-    TPoint    arcs[2 * MaxBezier + 1]; /* The Bezier stack                 */
+    TPoint    arcs[3 * MaxBezier + 1]; /* The Bezier stack                 */
 
     TBand     band_stack[16];       /* band stack used for sub-banding     */
     Int       band_top;             /* band stack top                      */
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index 6ac2608..d6e759c 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -247,7 +247,7 @@
 
     TScan  last_ey;
 
-    FT_Vector   bez_stack[32 * 3];
+    FT_Vector   bez_stack[32 * 3+1];
     int         lev_stack[32];
 
     FT_Outline  outline;
diff --git a/src/winfonts/winfnt.c b/src/winfonts/winfnt.c
index d834960..1fa47d7 100644
--- a/src/winfonts/winfnt.c
+++ b/src/winfonts/winfnt.c
@@ -109,9 +109,9 @@
   };
 
 
-  static
-  void  fnt_done_font( FT_Stream  stream,
-                       FNT_Font*  font )
+  static void
+  fnt_font_done( FNT_Font*  font,
+                 FT_Stream  stream )
   {
     if ( font->fnt_frame )
       RELEASE_Frame( font->fnt_frame );
@@ -121,9 +121,9 @@
   }
 
 
-  static
-  FT_Error  fnt_load_font( FT_Stream  stream,
-                           FNT_Font*  font )
+  static FT_Error
+  fnt_font_load( FNT_Font*  font,
+                 FT_Stream  stream )
   {
     FT_Error        error;
     WinFNT_Header*  header = &font->header;
@@ -164,8 +164,8 @@
   }
 
 
-  static
-  void  fnt_done_fonts( FNT_Face  face )
+  static void
+  fnt_face_done_fonts( FNT_Face  face )
   {
     FT_Memory  memory = FT_FACE(face)->memory;
     FT_Stream  stream = FT_FACE(face)->stream;
@@ -174,15 +174,15 @@
 
 
     for ( ; cur < limit; cur++ )
-      fnt_done_font( stream, cur );
+      fnt_font_done( cur, stream );
 
     FREE( face->fonts );
     face->num_fonts = 0;
   }
 
 
-  static
-  FT_Error  fnt_get_dll_fonts( FNT_Face  face )
+  static FT_Error
+  fnt_face_get_dll_fonts( FNT_Face  face )
   {
     FT_Error      error;
     FT_Stream     stream = FT_FACE(face)->stream;
@@ -291,7 +291,7 @@
 
           for ( ; cur < limit; cur++ )
           {
-            error = fnt_load_font( stream, cur );
+            error = fnt_font_load( cur, stream );
             if ( error )
               goto Fail;
           }
@@ -301,32 +301,32 @@
 
   Fail:
     if ( error )
-      fnt_done_fonts( face );
+      fnt_face_done_fonts( face );
 
   Exit:
     return error;
   }
 
 
-  static
-  void  FNT_Done_Face( FNT_Face  face )
+  static void
+  FNT_Face_Done( FNT_Face  face )
   {
     FT_Memory  memory = FT_FACE_MEMORY( face );
 
 
-    fnt_done_fonts( face );
+    fnt_face_done_fonts( face );
 
     FREE( face->root.available_sizes );
     face->root.num_fixed_sizes = 0;
   }
 
 
-  static
-  FT_Error  FNT_Init_Face( FT_Stream      stream,
-                           FNT_Face       face,
-                           FT_Int         face_index,
-                           FT_Int         num_params,
-                           FT_Parameter*  params )
+  static FT_Error
+  FNT_Face_Init( FT_Stream      stream,
+                 FNT_Face       face,
+                 FT_Int         face_index,
+                 FT_Int         num_params,
+                 FT_Parameter*  params )
   {
     FT_Error   error;
     FT_Memory  memory = FT_FACE_MEMORY( face );
@@ -337,7 +337,7 @@
 
 
     /* try to load several fonts from a DLL */
-    error = fnt_get_dll_fonts( face );
+    error = fnt_face_get_dll_fonts( face );
     if ( error )
     {
       /* this didn't work, now try to load a single FNT font */
@@ -352,7 +352,7 @@
       font->offset   = 0;
       font->fnt_size = stream->size;
 
-      error = fnt_load_font( stream, font );
+      error = fnt_font_load( font, stream );
       if ( error )
         goto Fail;
     }
@@ -431,15 +431,15 @@
 
   Fail:
     if ( error )
-      FNT_Done_Face( face );
+      FNT_Face_Done( face );
 
   Exit:
     return error;
   }
 
 
-  static
-  FT_Error  FNT_Set_Pixel_Size( FNT_Size  size )
+  static FT_Error
+  FNT_Size_Set_Pixels( FNT_Size  size )
   {
     /* look up a font corresponding to the current pixel size */
     FNT_Face   face  = (FNT_Face)FT_SIZE_FACE( size );
@@ -468,9 +468,9 @@
   }
 
 
-  static
-  FT_UInt  FNT_Get_Char_Index( FT_CharMap  charmap,
-                               FT_Long     char_code )
+  static FT_UInt
+  FNT_Get_Char_Index( FT_CharMap  charmap,
+                      FT_Long     char_code )
   {
     FT_Long  result = char_code;
 
@@ -493,11 +493,11 @@
   }
 
 
-  static
-  FT_Error  FNT_Load_Glyph( FT_GlyphSlot  slot,
-                            FNT_Size      size,
-                            FT_UInt       glyph_index,
-                            FT_Int        load_flags )
+  static FT_Error
+  FNT_Load_Glyph( FT_GlyphSlot  slot,
+                  FNT_Size      size,
+                  FT_UInt       glyph_index,
+                  FT_Int        load_flags )
   {
     FNT_Font*   font  = size->font;
     FT_Error    error = 0;
@@ -605,15 +605,15 @@
     sizeof( FNT_SizeRec ),
     sizeof( FT_GlyphSlotRec ),
 
-    (FTDriver_initFace)     FNT_Init_Face,
-    (FTDriver_doneFace)     FNT_Done_Face,
+    (FTDriver_initFace)     FNT_Face_Init,
+    (FTDriver_doneFace)     FNT_Face_Done,
     (FTDriver_initSize)     0,
     (FTDriver_doneSize)     0,
     (FTDriver_initGlyphSlot)0,
     (FTDriver_doneGlyphSlot)0,
 
-    (FTDriver_setCharSizes) FNT_Set_Pixel_Size,
-    (FTDriver_setPixelSizes)FNT_Set_Pixel_Size,
+    (FTDriver_setCharSizes) FNT_Size_Set_Pixels,
+    (FTDriver_setPixelSizes)FNT_Size_Set_Pixels,
 
     (FTDriver_loadGlyph)    FNT_Load_Glyph,
     (FTDriver_getCharIndex) FNT_Get_Char_Index,