Commit 66cb4790bfc5146158a388c6cc9ab2cc40dcf6fb

David Turner 2001-05-14T14:04:23

* src/base/ftcalc.c (FT_DivFix): fixed a bug in the 64-bit code that created incorrect scale factors !! * src/autohint/ahglobal.c, src/autohint/ahglyph.c, src/autohint/ahhint.c: fixed the incorrect blue zone computations, and improved the composite support. Note that these changes result in improved rendering, while sometimes introducing their own artefacts. That's probably the last big change to the autohinter before the introduction of its complete replacement..

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
diff --git a/ChangeLog b/ChangeLog
index e7abe8b..e499c51 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-05-14  David Turner  <david@freetype.org>
+
+    * src/base/ftcalc.c (FT_DivFix): fixed a bug in the 64-bit code that
+    created incorrect scale factors !!
+
+    * src/autohint/ahglobal.c, src/autohint/ahglyph.c, src/autohint/ahhint.c:
+    fixed the incorrect blue zone computations, and improved the composite
+    support. Note that these changes result in improved rendering, while
+    sometimes introducing their own artefacts. That's probably the last
+    big change to the autohinter before the introduction of its complete
+    replacement..
+
 2001-05-12  Werner Lemberg  <wl@gnu.org>
 
 	* include/freetype/ftbbox.h: FTBBOX_H -> __FTBBOX_H__.
diff --git a/src/autohint/ahglobal.c b/src/autohint/ahglobal.c
index 68f68c4..f2ebc6e 100644
--- a/src/autohint/ahglobal.c
+++ b/src/autohint/ahglobal.c
@@ -47,7 +47,7 @@
 
     for ( i = 1; i < count; i++ )
     {
-      for ( j = i; j > 1; j-- )
+      for ( j = i; j > 0; j-- )
       {
         if ( table[j] > table[j - 1] )
           break;
diff --git a/src/autohint/ahglyph.c b/src/autohint/ahglyph.c
index 252572d..6656ba4 100644
--- a/src/autohint/ahglyph.c
+++ b/src/autohint/ahglyph.c
@@ -28,7 +28,109 @@
 #include <stdio.h>
 
 
-#define xxxAH_DEBUG_GLYPH
+
+#ifdef AH_DEBUG
+
+  void  ah_dump_edges( AH_Outline*  outline )
+  {
+    AH_Edge*     edges;
+    AH_Edge*     edge_limit;
+    AH_Segment*  segments;
+    FT_Int       dimension;
+
+
+    edges      = outline->horz_edges;
+    edge_limit = edges + outline->num_hedges;
+    segments   = outline->horz_segments;
+
+    for ( dimension = 1; dimension >= 0; dimension-- )
+    {
+      AH_Edge*  edge;
+
+
+      printf ( "Table of %s edges:\n",
+               !dimension ? "vertical" : "horizontal" );
+      printf ( "  [ index |  pos |  dir  | link |"
+               " serif | blue | opos  |  pos  ]\n" );
+
+      for ( edge = edges; edge < edge_limit; edge++ )
+      {
+        printf ( "  [ %5d | %4d | %5s | %4d | %5d |  %c  | %5.2f | %5.2f ]\n",
+                 edge - edges,
+                 (int)edge->fpos,
+                 edge->dir == ah_dir_up
+                   ? "up"
+                   : ( edge->dir == ah_dir_down
+                         ? "down"
+                         : ( edge->dir == ah_dir_left
+                               ? "left"
+                               : ( edge->dir == ah_dir_right
+                                     ? "right"
+                                     : "none" ) ) ),
+                 edge->link ? ( edge->link - edges ) : -1,
+                 edge->serif ? ( edge->serif - edges ) : -1,
+                 edge->blue_edge ? 'y' : 'n',
+                 edge->opos / 64.0,
+                 edge->pos / 64.0 );
+      }
+
+      edges      = outline->vert_edges;
+      edge_limit = edges + outline->num_vedges;
+      segments   = outline->vert_segments;
+    }
+  }
+
+
+  /* A function used to dump the array of linked segments */
+  void  ah_dump_segments( AH_Outline*  outline )
+  {
+    AH_Segment*  segments;
+    AH_Segment*  segment_limit;
+    AH_Point*    points;
+    FT_Int       dimension;
+
+
+    points        = outline->points;
+    segments      = outline->horz_segments;
+    segment_limit = segments + outline->num_hsegments;
+
+    for ( dimension = 1; dimension >= 0; dimension-- )
+    {
+      AH_Segment*  seg;
+
+
+      printf ( "Table of %s segments:\n",
+               !dimension ? "vertical" : "horizontal" );
+      printf ( "  [ index |  pos |  dir  | link | serif |"
+               " numl | first | start ]\n" );
+
+      for ( seg = segments; seg < segment_limit; seg++ )
+      {
+        printf ( "  [ %5d | %4d | %5s | %4d | %5d | %4d | %5d | %5d ]\n",
+                 seg - segments,
+                 (int)seg->pos,
+                 seg->dir == ah_dir_up
+                   ? "up"
+                   : ( seg->dir == ah_dir_down
+                         ? "down"
+                         : ( seg->dir == ah_dir_left
+                               ? "left"
+                               : ( seg->dir == ah_dir_right
+                                     ? "right"
+                                     : "none" ) ) ),
+                 seg->link ? (seg->link-segments) : -1,
+                 seg->serif ? (seg->serif-segments) : -1,
+                 (int)seg->num_linked,
+                 seg->first - points,
+                 seg->last - points );
+      }
+
+      segments      = outline->vert_segments;
+      segment_limit = segments + outline->num_vsegments;
+    }
+  }
+
+#endif /* AH_DEBUG */
 
 
   /* compute the direction value of a given vector.. */
@@ -344,8 +446,6 @@
     outline->num_hsegments = 0;
     outline->num_vsegments = 0;
 
-#if 1
-
     /* We can't rely on the value of `FT_Outline.flags' to know the fill  */
     /* direction used for a glyph, given that some fonts are broken (e.g. */
     /* the Arphic ones). We thus recompute it each time we need to.       */
@@ -359,23 +459,6 @@
       outline->horz_major_dir = ah_dir_right;
     }
 
-#else  /* !1 */
-
-    /* Compute the vertical and horizontal major directions; this is     */
-    /* currently done by inspecting the `ft_outline_reverse_fill' flag.  */
-    /* However, some fonts have improper glyphs, and it'd be a good idea */
-    /* to be able to re-compute these values on the fly.                 */
-    outline->vert_major_dir = ah_dir_up;
-    outline->horz_major_dir = ah_dir_left;
-
-    if ( source->flags & ft_outline_reverse_fill )
-    {
-      outline->vert_major_dir = ah_dir_down;
-      outline->horz_major_dir = ah_dir_right;
-    }
-
-#endif /* !1 */
-
     outline->x_scale = face->size->metrics.x_scale;
     outline->y_scale = face->size->metrics.y_scale;
 
@@ -952,59 +1035,6 @@
   }
 
 
-#ifdef AH_DEBUG_GLYPH
-
-  /* A function used to dump the array of linked segments */
-  void  ah_dump_segments( AH_Outline*  outline )
-  {
-    AH_Segment*  segments;
-    AH_Segment*  segment_limit;
-    AH_Point*    points;
-    FT_Int       dimension;
-
-
-    points        = outline->points;
-    segments      = outline->horz_segments;
-    segment_limit = segments + outline->num_hsegments;
-
-    for ( dimension = 1; dimension >= 0; dimension-- )
-    {
-      AH_Segment*  seg;
-
-
-      printf ( "Table of %s segments:\n",
-               !dimension ? "vertical" : "horizontal" );
-      printf ( "  [ index |  pos |  dir  | link | serif |"
-               " numl | first | start ]\n" );
-
-      for ( seg = segments; seg < segment_limit; seg++ )
-      {
-        printf ( "  [ %5d | %4d | %5s | %4d | %5d | %4d | %5d | %5d ]\n",
-                 seg - segments,
-                 (int)seg->pos,
-                 seg->dir == ah_dir_up
-                   ? "up"
-                   : ( seg->dir == ah_dir_down
-                         ? "down"
-                         : ( seg->dir == ah_dir_left
-                               ? "left"
-                               : ( seg->dir == ah_dir_right
-                                     ? "right"
-                                     : "none" ) ) ),
-                 seg->link ? (seg->link-segments) : -1,
-                 seg->serif ? (seg->serif-segments) : -1,
-                 (int)seg->num_linked,
-                 seg->first - points,
-                 seg->last - points );
-      }
-
-      segments      = outline->vert_segments;
-      segment_limit = segments + outline->num_vsegments;
-    }
-  }
-
-#endif /* AH_DEBUG_GLYPH */
-
 
   static
   void  ah_outline_compute_edges( AH_Outline*  outline )
@@ -1218,7 +1248,7 @@
         /* set the round/straight flags */
         edge->flags = ah_edge_normal;
 
-        if ( is_straight == 0 && is_round )
+        if ( is_round > 0 && is_round >= is_straight )
           edge->flags |= ah_edge_round;
 
         /* set the edge's main direction */
@@ -1286,6 +1316,38 @@
     AH_Globals*  globals    = &face_globals->design;
     FT_Fixed     y_scale    = outline->y_scale;
 
+    FT_Bool      blue_active[ ah_blue_max ];
+
+
+    /* compute which blue zones are active, i.e. have their scaled */
+    /* size < 3/4 pixels                                           */
+    {
+      AH_Blue  blue;
+      FT_Bool  check = 0;
+
+      for ( blue = ah_blue_capital_top; blue < ah_blue_max; blue++ )
+      {
+        FT_Pos  ref, shoot, dist;
+
+        ref   = globals->blue_refs[blue];
+        shoot = globals->blue_shoots[blue];
+        dist  = ref-shoot;
+        if (dist < 0)
+          dist = -dist;
+
+        blue_active[blue] = 0;
+
+        if ( FT_MulFix( dist, y_scale ) < 48 )
+        {
+          blue_active[blue] = 1;
+          check = 1;
+        }
+      }
+
+      /* return immediately if no blue zone is active */
+      if (!check)
+        return;
+    }
 
     /* compute for each horizontal edge, which blue zone is closer */
     for ( ; edge < edge_limit; edge++ )
@@ -1309,6 +1371,8 @@
         FT_Bool  is_top_blue  = AH_IS_TOP_BLUE( blue );
         FT_Bool  is_major_dir = edge->dir == outline->horz_major_dir;
 
+        if ( !blue_active[blue] )
+          continue;
 
         /* if it is a top zone, the edge must be against the major    */
         /* direction; if it is a bottom zone, it must be in the major */
@@ -1392,58 +1456,6 @@
   }
 
 
-#ifdef AH_DEBUG_GLYPH
-
-  void  ah_dump_edges( AH_Outline*  outline )
-  {
-    AH_Edge*     edges;
-    AH_Edge*     edge_limit;
-    AH_Segment*  segments;
-    FT_Int       dimension;
-
-
-    edges      = outline->horz_edges;
-    edge_limit = edges + outline->num_hedges;
-    segments   = outline->horz_segments;
-
-    for ( dimension = 1; dimension >= 0; dimension-- )
-    {
-      AH_Edge*  edge;
-
-
-      printf ( "Table of %s edges:\n",
-               !dimension ? "vertical" : "horizontal" );
-      printf ( "  [ index |  pos |  dir  | link |"
-               " serif | blue | opos  |  pos  ]\n" );
-
-      for ( edge = edges; edge < edge_limit; edge++ )
-      {
-        printf ( "  [ %5d | %4d | %5s | %4d | %5d |  %c  | %5.2f | %5.2f ]\n",
-                 edge - edges,
-                 (int)edge->fpos,
-                 edge->dir == ah_dir_up
-                   ? "up"
-                   : ( edge->dir == ah_dir_down
-                         ? "down"
-                         : ( edge->dir == ah_dir_left
-                               ? "left"
-                               : ( edge->dir == ah_dir_right
-                                     ? "right"
-                                     : "none" ) ) ),
-                 edge->link ? ( edge->link - edges ) : -1,
-                 edge->serif ? ( edge->serif - edges ) : -1,
-                 edge->blue_edge ? 'y' : 'n',
-                 edge->opos / 64.0,
-                 edge->pos / 64.0 );
-      }
-
-      edges      = outline->vert_edges;
-      edge_limit = edges + outline->num_vedges;
-      segments   = outline->vert_segments;
-    }
-  }
-
-#endif /* AH_DEBUG_GLYPH */
 
 
 /* END */
diff --git a/src/autohint/ahhint.c b/src/autohint/ahhint.c
index 754687c..ead32fd 100644
--- a/src/autohint/ahhint.c
+++ b/src/autohint/ahhint.c
@@ -1051,13 +1051,13 @@
     switch ( slot->format )
     {
     case ft_glyph_format_outline:
-    
+
       /* translate glyph outline if we need to */
       if ( hinter->transformed )
       {
         FT_UInt     n     = slot->outline.n_points;
         FT_Vector*  point = slot->outline.points;
-        
+
 
         for ( ; n > 0; point++, n-- )
         {
@@ -1065,7 +1065,7 @@
           point->y += hinter->trans_delta.y;
         }
       }
-      
+
       /* copy the outline points in the loader's current                */
       /* extra points, which is used to keep original glyph coordinates */
       error = ah_loader_check_points( gloader, slot->outline.n_points + 2,
@@ -1365,7 +1365,11 @@
 
     ah_loader_rewind( hinter->loader );
 
+#if 1
+    load_flags = FT_LOAD_NO_SCALE;
+#else
     load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE;
+#endif
 
     error = ah_hinter_load( hinter, glyph_index, load_flags, 0 );
 
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index dfcecc1..327b318 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -55,7 +55,8 @@
 
   FT_EXPORT_DEF( FT_Fixed )  FT_RoundFix( FT_Fixed  a )
   {
-    return( ( a + 0x8000L ) & -0x10000L );
+    return ( a >= 0 ) ?   ( a + 0x8000L ) & -0x10000L
+                      : -((-a + 0x8000L ) & -0x10000L );
   }
 
 
@@ -63,7 +64,8 @@
 
   FT_EXPORT_DEF( FT_Fixed )  FT_CeilFix( FT_Fixed  a )
   {
-    return( ( a + 0x10000L - 1 ) & -0x10000L );
+    return ( a >= 0 ) ?   ( a + 0xFFFFL ) & -0x10000L
+                      : -((-a + 0xFFFFL ) & -0x10000L );
   }
 
 
@@ -71,7 +73,8 @@
 
   FT_EXPORT_DEF( FT_Fixed )  FT_FloorFix( FT_Fixed  a )
   {
-    return( a & -0x10000L );
+    return ( a >= 0 ) ?   a & -0x10000L
+                      : -((-a) & -0x10000L );
   }
 
 
@@ -176,16 +179,16 @@
     FT_Int32   s;
     FT_UInt32  q;
 
-
-    s  = a; a = ABS(a);
-    s ^= b; b = ABS(b);
+    s = 1;
+    if ( a < 0 ) { a = -a; s = -1; }
+    if ( b < 0 ) { b = -b; s = -s; }
 
     if ( b == 0 )
       /* check for division by 0 */
       q = 0x7FFFFFFFL;
     else
       /* compute result directly */
-      q = ( ((FT_Int64)a + (b >> 1)) << 16 ) / b;
+      q = ( ((FT_Int64)a << 16) + (b >> 1)) / b;
 
     return (FT_Long)( s < 0 ? -q : q );
   }