Commit 54169b35f8ba994ba4cb9d46c75fdde78c8c0cc3

David Turner 2000-10-26T00:06:35

- reviving the "ftbbox" component, used to compute exact bounding box computations - minor update to docmaker.py, more is coming

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
diff --git a/docs/docmaker.py b/docs/docmaker.py
index b71d81f..aa1ba84 100644
--- a/docs/docmaker.py
+++ b/docs/docmaker.py
@@ -3,6 +3,10 @@
 # DocMaker is a very simple program used to generate HTML documentation
 # from the source files of the FreeType packages.
 #
+# I should really be using regular expressions to do this, but hey,
+# i'm too lazy right now, and the damn thing seems to work :-)
+#   - David
+#
 
 import fileinput, sys, string
 
@@ -110,6 +114,34 @@ source_footer = """</pre></table>
 # instead of "<MAKRER>". All marker identifiers are converted to
 # lower case during parsing, in order to simply sorting..
 #
+# We associate with each block the following source lines that do not
+# begin with a comment. For example, the following:
+#
+#   /**********************************
+#    *
+#    * <mytag>  blabla
+#    *
+#    */
+#
+#    bla_bla_bla
+#     bilip_bilip
+#
+#   /* - this comment acts as a separator - */
+#
+#     blo_blo_blo
+#
+#
+#  will only keep the first two lines of sources with
+#  the "blabla" block
+#
+#  However, the comment will be kept, with following source lines
+#  if it contains a starting '#' or '@' as in:
+#
+#     /*@.....*/
+#     /*#.....*/
+#     /* @.....*/
+#     /* #.....*/
+#
 
 
 def make_block_list():
@@ -146,9 +178,19 @@ def make_block_list():
         # if this line begins with a comment and we are processing some
         # source, exit to state 0
         #
+        # unless we encounter something like:
+        #
+        #    /*@.....
+        #    /*#.....
+        #
+        #    /* @.....
+        #    /* #.....
+        #
         if format >= 4 and l > 2 and line2[0 : 2] == '/*':
-            list.append( ( block, source ) )
-            format = 0
+            if l < 4 or ( line2[3] != '@' and line2[3:4] != ' @' and
+                          line2[3] != '#' and line2[3:4] != ' #'):
+                list.append( ( block, source ) )
+                format = 0
 
         if format == 0:  #### wait for beginning of comment ####
 
diff --git a/include/freetype/ftbbox.h b/include/freetype/ftbbox.h
index e144664..54a05b9 100644
--- a/include/freetype/ftbbox.h
+++ b/include/freetype/ftbbox.h
@@ -2,7 +2,7 @@
 /*                                                                         */
 /*  ftbbox.h                                                               */
 /*                                                                         */
-/*    FreeType bbox computation (specification).                           */
+/*    FreeType exact bbox computation (specification).                     */
 /*                                                                         */
 /*  Copyright 1996-2000 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
@@ -40,7 +40,7 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FT_Raster_GetBBox                                                  */
+  /*    FT_Outline_Get_BBox                                                */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Computes the exact bounding box of an outline.  This is slower     */
@@ -58,8 +58,8 @@
   /* <Return>                                                              */
   /*    Error code.  0 means success.                                      */
   /*                                                                       */
-  FT_EXPORT_DEF(FT_Error)  FT_Raster_GetBBox( FT_Outline*  outline,
-                                              FT_BBox*     abbox );
+  FT_EXPORT_DEF(FT_Error)  FT_Outline_Get_BBox( FT_Outline*  outline,
+                                                FT_BBox     *abbox );
 
 
 #ifdef __cplusplus
diff --git a/src/base/ftbbox.c b/src/base/ftbbox.c
new file mode 100644
index 0000000..484ea4a
--- /dev/null
+++ b/src/base/ftbbox.c
@@ -0,0 +1,447 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftbbox.c                                                               */
+/*                                                                         */
+/*    FreeType bbox computation (body).                                    */
+/*                                                                         */
+/*  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.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* This component has a _single_ role: to compute exact outline bounding */
+  /* boxes.                                                                */
+  /*                                                                       */
+  /* It is separated from the rest of the engine for various technical     */
+  /* reasons.  It may well be integrated in `ftoutln' later.               */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+#include <freetype/ftbbox.h>
+#include <freetype/ftimage.h>
+#include <freetype/ftoutln.h>
+
+  typedef struct  TBBox_Rec_
+  {
+    FT_Vector  last;
+    FT_BBox    bbox;
+
+  } TBBox_Rec;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    BBox_Move_To                                                       */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    This function is used as a `move_to' and `line_to' emitter during  */
+  /*    FT_Outline_Decompose.  It simply records the destination point in  */
+  /*    `user->last'.                                                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    to   :: A pointer to the destination vector.                       */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    user :: A pointer to the current walk context.                     */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Error code.  0 means success.                                      */
+  /*                                                                       */
+  static
+  int  BBox_Move_To( FT_Vector*  to,
+                     TBBox_Rec*  user )
+  {
+    user->last = *to;
+
+    return 0;
+  }
+
+
+#define CHECK_X( p, bbox )  \
+          ( p->x < bbox.xMin || p->x > bbox.xMax )
+
+#define CHECK_Y( p, bbox )  \
+          ( p->y < bbox.yMin || p->y > bbox.yMax )
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    BBox_Conic_Check                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Finds the extrema of a 1-dimensional conic Bezier curve and update */
+  /*    a bounding range.  This version uses direct computation, as it     */
+  /*    doesn't need square roots.                                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    y1  :: The start coordinate.                                       */
+  /*    y2  :: The coordinate of the control point.                        */
+  /*    y3  :: The end coordinate.                                         */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    min :: The address of the current minimum.                         */
+  /*    max :: The address of the current maximum.                         */
+  /*                                                                       */
+  static
+  void  BBox_Conic_Check( FT_Pos   y1,
+                          FT_Pos   y2,
+                          FT_Pos   y3,
+                          FT_Pos*  min,
+                          FT_Pos*  max )
+  {
+    if( y1 == y3 )
+    {
+      if ( y2 == y1 )               /* Flat arc */
+      {
+        y3 = y1;
+        goto Suite;
+      }
+    }
+    else if ( y1 < y3 )
+    {
+      if ( y2 >= y1 && y2 <= y3 )   /* Ascending arc */
+        goto Suite;
+    }
+    else
+    {
+      if ( y2 >= y3 && y2 <= y1 )   /* Descending arc */
+      {
+        y2 = y1;
+        y1 = y3;
+        y3 = y2;
+        goto Suite;
+      }
+    }
+
+    y1 = y3 = FT_MulDiv( y2 - y1, y2 - y1, y1 - 2*y2 + y3 );
+
+  Suite:
+    if ( y1 < *min ) *min = y1;
+    if ( y3 > *max ) *max = y3;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    BBox_Conic_To                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    This function is used as a `conic_to' emitter during               */
+  /*    FT_Raster_Decompose().  It checks a conic Bezier curve with the    */
+  /*    current bounding box, and computes its extrema if necessary to     */
+  /*    update it.                                                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    control :: A pointer to a control point.                           */
+  /*    to      :: A pointer to the destination vector.                    */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    user    :: The address of the current walk context.                */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Error code.  0 means success.                                      */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    In the case of a non-monotonous arc, we compute directly the       */
+  /*    extremum coordinates, as it is sufficiently fast.                  */
+  /*                                                                       */
+  static
+  int  BBox_Conic_To( FT_Vector*  control,
+                      FT_Vector*  to,
+                      TBBox_Rec*  user )
+  {
+    if ( CHECK_X( control, user->bbox ) ||
+         CHECK_X( to,      user->bbox ) )
+
+      BBox_Conic_Check( user->last.x,
+                        control->x,
+                        to->x,
+                        &user->bbox.xMin,
+                        &user->bbox.xMax );
+
+    if ( CHECK_Y( control, user->bbox ) ||
+         CHECK_Y( to,      user->bbox ) )
+
+      BBox_Conic_Check( user->last.y,
+                        control->y,
+                        to->y,
+                        &user->bbox.yMin,
+                        &user->bbox.yMax );
+
+    return 0;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    BBox_Cubic_Check                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Finds the extrema of a 1-dimensional cubic Bezier curve and        */
+  /*    updates a bounding range.  This version uses splitting because we  */
+  /*    don't want to use square roots and extra accuracies.               */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    p1  :: The start coordinate.                                       */
+  /*    p2  :: The coordinate of the first control point.                  */
+  /*    p3  :: The coordinate of the second control point.                 */
+  /*    p4  :: The end coordinate.                                         */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    min :: The address of the current minimum.                         */
+  /*    max :: The address of the current maximum.                         */
+  /*                                                                       */
+  static
+  void  BBox_Cubic_Check( FT_Pos   p1,
+                          FT_Pos   p2,
+                          FT_Pos   p3,
+                          FT_Pos   p4,
+                          FT_Pos*  min,
+                          FT_Pos*  max )
+  {
+    FT_Pos  stack[33], *arc;
+
+
+    arc = stack;
+
+    arc[0] = p1;
+    arc[1] = p2;
+    arc[2] = p3;
+    arc[3] = p4;
+
+    do
+    {
+      FT_Pos  y1 = arc[0];
+      FT_Pos  y2 = arc[1];
+      FT_Pos  y3 = arc[2];
+      FT_Pos  y4 = arc[3];
+
+
+      if ( y1 == y4 )
+      {
+        if ( y1 == y2 && y1 == y3 )                         /* Flat */
+        {
+          y4 = y1;
+          goto Test;
+        }
+      }
+      else if ( y1 < y4 )
+      {
+        if ( y2 >= y1 && y2 <= y4 && y3 >= y1 && y3 <= y4 ) /* Ascending */
+          goto Test;
+      }
+      else
+      {
+        if ( y2 >= y4 && y2 <= y1 && y3 >= y4 && y3 <= y1 ) /* Descending */
+        {
+          y2 = y1;
+          y1 = y4;
+          y4 = y2;
+          goto Test;
+        }
+      }
+
+      /* Unknown direction, split the arc in two */
+      arc[6] = y4;
+      arc[1] = y1 = ( y1 + y2 ) / 2;
+      arc[5] = y4 = ( y4 + y3 ) / 2;
+      y2 = ( y2 + y3 ) / 2;
+      arc[2] = y1 = ( y1 + y2 ) / 2;
+      arc[4] = y4 = ( y4 + y2 ) / 2;
+      arc[3] = ( y1 + y4 ) / 2;
+
+      arc += 3;
+      goto Suite;
+
+   Test:
+      if ( y1 < *min ) *min = y1;
+      if ( y4 > *max ) *max = y4;
+      arc -= 3;
+
+    Suite:
+      ;
+    } while (arc >= stack);
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    BBox_Cubic_To                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    This function is used as a `cubic_to' emitter during               */
+  /*    FT_Raster_Decompose().  It checks a cubic Bezier curve with the    */
+  /*    current bounding box, and computes its extrema if necessary to     */
+  /*    update it.                                                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    control1 :: A pointer to the first control point.                  */
+  /*    control2 :: A pointer to the second control point.                 */
+  /*    to       :: A pointer to the destination vector.                   */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    user     :: The address of the current walk context.               */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Error code.  0 means success.                                      */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    In the case of a non-monotonous arc, we don't compute directly     */
+  /*    extremum coordinates, we subdivise instead.                        */
+  /*                                                                       */
+  static
+  int  BBox_Cubic_To( FT_Vector*  control1,
+                      FT_Vector*  control2,
+                      FT_Vector*  to,
+                      TBBox_Rec*  user )
+  {
+    if ( CHECK_X( control1, user->bbox ) ||
+         CHECK_X( control2, user->bbox ) ||
+         CHECK_X( to,       user->bbox ) )
+
+        BBox_Cubic_Check( user->last.x,
+                          control1->x,
+                          control2->x,
+                          to->x,
+                          &user->bbox.xMin,
+                          &user->bbox.xMax );
+
+    if ( CHECK_Y( control1, user->bbox ) ||
+         CHECK_Y( control2, user->bbox ) ||
+         CHECK_Y( to,       user->bbox ) )
+
+        BBox_Cubic_Check( user->last.y,
+                          control1->y,
+                          control2->y,
+                          to->y,
+                          &user->bbox.yMin,
+                          &user->bbox.yMax );
+
+    return 0;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Outline_Get_BBox                                                */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Computes the exact bounding box of an outline.  This is slower     */
+  /*    than computing the control box.  However, it uses an advanced      */
+  /*    algorithm which returns _very_ quickly when the two boxes          */
+  /*    coincide.  Otherwise, the outline Bezier arcs are walked over to   */
+  /*    extract their extrema.                                             */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    outline :: A pointer to the source outline.                        */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    abbox   :: A pointer to the outline's exact bounding box.          */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Error code.  0 means success.                                      */
+  /*                                                                       */
+  FT_EXPORT_FUNC( FT_Error )  FT_Outline_Get_BBox( FT_Outline*  outline,
+                                                   FT_BBox*     abbox )
+  {
+    FT_BBox    cbox;
+    FT_BBox    bbox;
+    FT_Vector* vec;
+    FT_UShort  n;
+
+
+    /* if outline is empty, return (0,0,0,0) */
+    if ( !outline )
+      return FT_Err_Invalid_Outline;
+
+    if ( outline->n_points == 0 || outline->n_contours <= 0 )
+    {
+      abbox->xMin = abbox->xMax = 0;
+      abbox->yMin = abbox->yMax = 0;
+      return 0;
+    }
+
+    /* We compute the control box as well as the bounding box of  */
+    /* all `on' points in the outline.  Then, if the two boxes    */
+    /* coincide, we exit immediately.                             */
+
+    vec = outline->points;
+    bbox.xMin = bbox.xMax = cbox.xMin = cbox.xMax = vec->x;
+    bbox.yMin = bbox.yMax = cbox.yMin = cbox.yMax = vec->y;
+
+    for ( n = 1; n < outline->n_points; n++ )
+    {
+      FT_Pos  x = vec->x;
+      FT_Pos  y = vec->y;
+
+
+      /* update control box */
+      if ( x < cbox.xMin ) cbox.xMin = x;
+      if ( x > cbox.xMax ) cbox.xMax = x;
+
+      if ( y < cbox.yMin ) cbox.yMin = y;
+      if ( y > cbox.yMax ) cbox.yMax = y;
+
+      if ( FT_CURVE_TAG( outline->tags[n] ) == FT_Curve_Tag_On )
+      {
+        /* update bbox for `on' points only */
+        if ( x < bbox.xMin ) bbox.xMin = x;
+        if ( x > bbox.xMax ) bbox.xMax = x;
+
+        if ( y < bbox.yMin ) bbox.yMin = y;
+        if ( y > bbox.yMax ) bbox.yMax = y;
+      }
+
+      vec++;
+    }
+
+    /* test two boxes for equality */
+    if ( cbox.xMin < bbox.xMin || cbox.xMax > bbox.xMax ||
+         cbox.yMin < bbox.yMin || cbox.yMax > bbox.yMax )
+    {
+      /* the two boxes are different, now walk over the outline to */
+      /* get the Bezier arc extrema.                               */
+
+      static const FT_Outline_Funcs  interface =
+      {
+        (FT_Outline_MoveTo_Func) BBox_Move_To,
+        (FT_Outline_LineTo_Func) BBox_Move_To,
+        (FT_Outline_ConicTo_Func)BBox_Conic_To,
+        (FT_Outline_CubicTo_Func)BBox_Cubic_To
+      };
+
+      FT_Error   error;
+      TBBox_Rec  user;
+
+
+      user.bbox = bbox;
+
+      error = FT_Outline_Decompose( outline, &interface, &user );
+      if ( error )
+        return error;
+
+      *abbox = user.bbox;
+    }
+    else
+      *abbox = bbox;
+
+    return FT_Err_Ok;
+  }
+
+
+/* END */