Commit 4cb09724a3c128aa5b7a5fdf80b1fbab2e28fa4f

Werner Lemberg 2004-02-23T18:22:32

* src/pshinter/pshalgo.c (PSH_STRONG_THRESHOLD): Changed to hold the accepted shift for strong points in fractional pixels (which is a heuristic value). (psh_glyph_find_strong_points): Compute threshold for psh_hint_table_find_strong_points. (psh_hint_table_find_strong_point): Add parameter to pass threshold.

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
diff --git a/ChangeLog b/ChangeLog
index d969cbc..75ac247 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2004-02-21  Werner Lemberg  <wl@gnu.org>
+
+	* src/pshinter/pshalgo.c (PSH_STRONG_THRESHOLD): Changed to hold
+	the accepted shift for strong points in fractional pixels (which
+	is a heuristic value).
+	(psh_glyph_find_strong_points): Compute threshold for
+	psh_hint_table_find_strong_points.
+	(psh_hint_table_find_strong_point): Add parameter to pass threshold.
+
 2004-02-20  Werner Lemberg  <wl@gnu.org>
 
 	* src/pshinter/pshrec.c (ps_mask_table_set_bits): Don't call
diff --git a/src/pshinter/pshalgo.c b/src/pshinter/pshalgo.c
index 30ad1fb..43e38d9 100644
--- a/src/pshinter/pshalgo.c
+++ b/src/pshinter/pshalgo.c
@@ -1368,9 +1368,6 @@
   }
 
 
-#define PSH_STRONG_THRESHOLD  30
-
-
   /* major_dir is the direction for points on the bottom/left of the stem; */
   /* Points on the top/right of the stem will have a direction of          */
   /* -major_dir.                                                           */
@@ -1378,6 +1375,7 @@
   static void
   psh_hint_table_find_strong_point( PSH_Hint_Table  table,
                                     PSH_Point       point,
+                                    FT_Int          threshold,
                                     FT_Int          major_dir )
   {
     PSH_Hint*  sort      = table->sort;
@@ -1407,7 +1405,7 @@
           flag = PSH_POINT_EDGE_MIN;
           d    = point->org_u - hint->org_pos;
 
-          if ( ABS( d ) < PSH_STRONG_THRESHOLD )
+          if ( ABS( d ) < threshold )
           {
           Is_Strong:
             psh_point_set_strong( point );
@@ -1421,7 +1419,7 @@
           flag = PSH_POINT_EDGE_MAX;
           d    = point->org_u - hint->org_pos - hint->org_len;
 
-          if ( ABS( d ) < PSH_STRONG_THRESHOLD )
+          if ( ABS( d ) < threshold )
             goto Is_Strong;
         }
       }
@@ -1457,7 +1455,7 @@
           flag = PSH_POINT_EDGE_MIN;
           d    = point->org_u - hint->org_pos;
 
-          if ( ABS( d ) < PSH_STRONG_THRESHOLD )
+          if ( ABS( d ) < threshold )
           {
           Is_Strong2:
             point->flags2 |= flag;
@@ -1471,7 +1469,7 @@
           flag = PSH_POINT_EDGE_MAX;
           d    = point->org_u - hint->org_pos - hint->org_len;
 
-          if ( ABS( d ) < PSH_STRONG_THRESHOLD )
+          if ( ABS( d ) < threshold )
             goto Is_Strong2;
         }
 
@@ -1487,6 +1485,10 @@
   }
 
 
+  /* the accepted shift for strong points in fractional pixels */
+#define PSH_STRONG_THRESHOLD  50
+
+
   /* find strong points in a glyph */
   static void
   psh_glyph_find_strong_points( PSH_Glyph  glyph,
@@ -1494,68 +1496,74 @@
   {
     /* a point is strong if it is located on a stem                   */
     /* edge and has an "in" or "out" tangent to the hint's direction  */
-    {
-      PSH_Hint_Table  table     = &glyph->hint_tables[dimension];
-      PS_Mask         mask      = table->hint_masks->masks;
-      FT_UInt         num_masks = table->hint_masks->num_masks;
-      FT_UInt         first     = 0;
-      FT_Int          major_dir = dimension == 0 ? PSH_DIR_VERTICAL
-                                                 : PSH_DIR_HORIZONTAL;
+
+    PSH_Hint_Table  table     = &glyph->hint_tables[dimension];
+    PS_Mask         mask      = table->hint_masks->masks;
+    FT_UInt         num_masks = table->hint_masks->num_masks;
+    FT_UInt         first     = 0;
+    FT_Int          major_dir = dimension == 0 ? PSH_DIR_VERTICAL
+                                               : PSH_DIR_HORIZONTAL;
+    PSH_Dimension   dim       = &glyph->globals->dimension[dimension];
+    FT_Fixed        scale     = dim->scale_mult;
+    FT_Int          threshold;
 
 
-      /* process secondary hints to "selected" points */
-      if ( num_masks > 1 && glyph->num_points > 0 )
+    threshold = (FT_Int)FT_DivFix( PSH_STRONG_THRESHOLD, scale );
+
+    /* process secondary hints to "selected" points */
+    if ( num_masks > 1 && glyph->num_points > 0 )
+    {
+      first = mask->end_point;
+      mask++;
+      for ( ; num_masks > 1; num_masks--, mask++ )
       {
-        first = mask->end_point;
-        mask++;
-        for ( ; num_masks > 1; num_masks--, mask++ )
-        {
-          FT_UInt  next;
-          FT_Int   count;
+        FT_UInt  next;
+        FT_Int   count;
 
 
-          next  = mask->end_point;
-          count = next - first;
-          if ( count > 0 )
-          {
-            PSH_Point  point = glyph->points + first;
+        next  = mask->end_point;
+        count = next - first;
+        if ( count > 0 )
+        {
+          PSH_Point  point = glyph->points + first;
 
 
-            psh_hint_table_activate_mask( table, mask );
+          psh_hint_table_activate_mask( table, mask );
 
-            for ( ; count > 0; count--, point++ )
-              psh_hint_table_find_strong_point( table, point, major_dir );
-          }
-          first = next;
+          for ( ; count > 0; count--, point++ )
+            psh_hint_table_find_strong_point( table, point,
+                                              threshold, major_dir );
         }
+        first = next;
       }
+    }
 
-      /* process primary hints for all points */
-      if ( num_masks == 1 )
-      {
-        FT_UInt    count = glyph->num_points;
-        PSH_Point  point = glyph->points;
+    /* process primary hints for all points */
+    if ( num_masks == 1 )
+    {
+      FT_UInt    count = glyph->num_points;
+      PSH_Point  point = glyph->points;
 
 
-        psh_hint_table_activate_mask( table, table->hint_masks->masks );
-        for ( ; count > 0; count--, point++ )
-        {
-          if ( !psh_point_is_strong( point ) )
-            psh_hint_table_find_strong_point( table, point, major_dir );
-        }
+      psh_hint_table_activate_mask( table, table->hint_masks->masks );
+      for ( ; count > 0; count--, point++ )
+      {
+        if ( !psh_point_is_strong( point ) )
+          psh_hint_table_find_strong_point( table, point,
+                                            threshold, major_dir );
       }
+    }
 
-      /* now, certain points may have been attached to hint and */
-      /* not marked as strong; update their flags then          */
-      {
-        FT_UInt    count = glyph->num_points;
-        PSH_Point  point = glyph->points;
+    /* now, certain points may have been attached to hint and */
+    /* not marked as strong; update their flags then          */
+    {
+      FT_UInt    count = glyph->num_points;
+      PSH_Point  point = glyph->points;
 
 
-        for ( ; count > 0; count--, point++ )
-          if ( point->hint && !psh_point_is_strong( point ) )
-            psh_point_set_strong( point );
-      }
+      for ( ; count > 0; count--, point++ )
+        if ( point->hint && !psh_point_is_strong( point ) )
+          psh_point_set_strong( point );
     }
   }
 
@@ -1568,50 +1576,45 @@
     PSH_Dimension  dim   = &glyph->globals->dimension[dimension];
     FT_Fixed       scale = dim->scale_mult;
 
+    FT_UInt        count = glyph->num_points;
+    PSH_Point      point = glyph->points;
 
+
+    for ( ; count > 0; count--, point++ )
     {
-      FT_UInt    count = glyph->num_points;
-      PSH_Point  point = glyph->points;
+      PSH_Hint  hint = point->hint;
 
 
-      for ( ; count > 0; count--, point++ )
+      if ( hint )
       {
-        PSH_Hint  hint = point->hint;
+        FT_Pos  delta;
 
 
-        if ( hint )
-        {
-          FT_Pos  delta;
+        if ( psh_point_is_edge_min( point ) )
+          point->cur_u = hint->cur_pos;
 
+        else if ( psh_point_is_edge_max( point ) )
+          point->cur_u = hint->cur_pos + hint->cur_len;
 
-          if ( psh_point_is_edge_min( point ) )
-          {
-            point->cur_u = hint->cur_pos;
-          }
-          else if ( psh_point_is_edge_max( point ) )
-          {
-            point->cur_u = hint->cur_pos + hint->cur_len;
-          }
-          else
-          {
-            delta = point->org_u - hint->org_pos;
+        else
+        {
+          delta = point->org_u - hint->org_pos;
 
-            if ( delta <= 0 )
-              point->cur_u = hint->cur_pos + FT_MulFix( delta, scale );
+          if ( delta <= 0 )
+            point->cur_u = hint->cur_pos + FT_MulFix( delta, scale );
 
-            else if ( delta >= hint->org_len )
-              point->cur_u = hint->cur_pos + hint->cur_len +
-                               FT_MulFix( delta - hint->org_len, scale );
+          else if ( delta >= hint->org_len )
+            point->cur_u = hint->cur_pos + hint->cur_len +
+                             FT_MulFix( delta - hint->org_len, scale );
 
-            else if ( hint->org_len > 0 )
-              point->cur_u = hint->cur_pos +
-                               FT_MulDiv( delta, hint->cur_len,
-                                          hint->org_len );
-            else
-              point->cur_u = hint->cur_pos;
-          }
-          psh_point_set_fitted( point );
+          else if ( hint->org_len > 0 )
+            point->cur_u = hint->cur_pos +
+                             FT_MulDiv( delta, hint->cur_len,
+                                        hint->org_len );
+          else
+            point->cur_u = hint->cur_pos;
         }
+        psh_point_set_fitted( point );
       }
     }
   }
@@ -1623,109 +1626,107 @@
   {
 
 #if 1
+    /* first technique: a point is strong if it is a local extrema */
 
     PSH_Dimension  dim   = &glyph->globals->dimension[dimension];
     FT_Fixed       scale = dim->scale_mult;
 
+    FT_UInt        count = glyph->num_points;
+    PSH_Point      point = glyph->points;
 
-    /* first technique: a point is strong if it is a local extrema */
-    {
-      FT_UInt    count = glyph->num_points;
-      PSH_Point  point = glyph->points;
 
+    for ( ; count > 0; count--, point++ )
+    {
+      if ( psh_point_is_strong( point ) )
+        continue;
 
-      for ( ; count > 0; count--, point++ )
+      /* sometimes, some local extremas are smooth points */
+      if ( psh_point_is_smooth( point ) )
       {
-        if ( psh_point_is_strong( point ) )
+        if ( point->dir_in == PSH_DIR_NONE   ||
+             point->dir_in != point->dir_out )
           continue;
 
-        /* sometimes, some local extremas are smooth points */
-        if ( psh_point_is_smooth( point ) )
-        {
-          if ( point->dir_in == PSH_DIR_NONE   ||
-               point->dir_in != point->dir_out )
-            continue;
-
-          if ( !psh_point_is_extremum( point )   &&
-               !psh_point_is_inflex( point ) )
-            continue;
+        if ( !psh_point_is_extremum( point ) &&
+             !psh_point_is_inflex( point )   )
+          continue;
 
-          point->flags &= ~PSH_POINT_SMOOTH;
-        }
+        point->flags &= ~PSH_POINT_SMOOTH;
+      }
 
-        /* find best enclosing point coordinates */
-        {
-          PSH_Point  before = 0;
-          PSH_Point  after  = 0;
+      /* find best enclosing point coordinates */
+      {
+        PSH_Point  before = 0;
+        PSH_Point  after  = 0;
 
-          FT_Pos     diff_before = -32000;
-          FT_Pos     diff_after  =  32000;
-          FT_Pos     u = point->org_u;
+        FT_Pos     diff_before = -32000;
+        FT_Pos     diff_after  =  32000;
+        FT_Pos     u = point->org_u;
 
-          FT_Int     count2 = glyph->num_points;
-          PSH_Point  cur    = glyph->points;
+        FT_Int     count2 = glyph->num_points;
+        PSH_Point  cur    = glyph->points;
 
 
-          for ( ; count2 > 0; count2--, cur++ )
+        for ( ; count2 > 0; count2--, cur++ )
+        {
+          if ( psh_point_is_strong( cur ) )
           {
-            if ( psh_point_is_strong( cur ) )
-            {
-              FT_Pos  diff = cur->org_u - u;;
+            FT_Pos  diff = cur->org_u - u;;
 
 
-              if ( diff <= 0 )
+            if ( diff <= 0 )
+            {
+              if ( diff > diff_before )
               {
-                if ( diff > diff_before )
-                {
-                  diff_before = diff;
-                  before      = cur;
-                }
+                diff_before = diff;
+                before      = cur;
               }
-              else if ( diff >= 0 )
+            }
+
+            else if ( diff >= 0 )
+            {
+              if ( diff < diff_after )
               {
-                if ( diff < diff_after )
-                {
-                  diff_after = diff;
-                  after      = cur;
-                }
+                diff_after = diff;
+                after      = cur;
               }
             }
           }
+        }
 
-          if ( !before )
-          {
-            if ( !after )
-              continue;
+        if ( !before )
+        {
+          if ( !after )
+            continue;
 
-            /* we are before the first strong point coordinate; */
-            /* simply translate the point                       */
-            point->cur_u = after->cur_u +
+          /* we are before the first strong point coordinate; */
+          /* simply translate the point                       */
+          point->cur_u = after->cur_u +
                            FT_MulFix( point->org_u - after->org_u, scale );
-          }
-          else if ( !after )
-          {
-            /* we are after the last strong point coordinate; */
-            /* simply translate the point                     */
-            point->cur_u = before->cur_u +
+        }
+        else if ( !after )
+        {
+          /* we are after the last strong point coordinate; */
+          /* simply translate the point                     */
+          point->cur_u = before->cur_u +
                            FT_MulFix( point->org_u - before->org_u, scale );
-          }
-          else
-          {
-            if ( diff_before == 0 )
-              point->cur_u = before->cur_u;
+        }
+        else
+        {
+          if ( diff_before == 0 )
+            point->cur_u = before->cur_u;
 
-            else if ( diff_after == 0 )
-              point->cur_u = after->cur_u;
+          else if ( diff_after == 0 )
+            point->cur_u = after->cur_u;
 
-            else
-              point->cur_u = before->cur_u +
+          else
+            point->cur_u = before->cur_u +
                              FT_MulDiv( u - before->org_u,
                                         after->cur_u - before->cur_u,
                                         after->org_u - before->org_u );
-          }
-
-          psh_point_set_fitted( point );
         }
+
+        psh_point_set_fitted( point );
       }
     }