Commit 4a3fce93c2a2e154ad7e84f93034240a55df35fa

Werner Lemberg 2015-10-27T19:27:39

[pfr] Formatting, improving comments.

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
diff --git a/src/pfr/pfrcmap.c b/src/pfr/pfrcmap.c
index 88ff55a..686edf1 100644
--- a/src/pfr/pfrcmap.c
+++ b/src/pfr/pfrcmap.c
@@ -130,7 +130,7 @@
         }
 
         if ( gchar->char_code < char_code )
-          min = mid+1;
+          min = mid + 1;
         else
           max = mid;
       }
diff --git a/src/pfr/pfrgload.c b/src/pfr/pfrgload.c
index 88df06a..e07c21a 100644
--- a/src/pfr/pfrgload.c
+++ b/src/pfr/pfrgload.c
@@ -92,8 +92,8 @@
     if ( outline->n_contours > 0 )
       first = outline->contours[outline->n_contours - 1];
 
-    /* if the last point falls on the same location than the first one */
-    /* we need to delete it                                            */
+    /* if the last point falls on the same location as the first one */
+    /* we need to delete it                                          */
     if ( last > first )
     {
       FT_Vector*  p1 = outline->points + first;
@@ -215,8 +215,10 @@
     /* check that there is space for a new contour and a new point */
     error = FT_GLYPHLOADER_CHECK_POINTS( loader, 1, 1 );
     if ( !error )
+    {
       /* add new start point */
       error = pfr_glyph_line_to( glyph, to );
+    }
 
     return error;
   }
@@ -304,8 +306,8 @@
 
     glyph->y_control = glyph->x_control + x_count;
 
-    mask  = 0;
-    x     = 0;
+    mask = 0;
+    x    = 0;
 
     for ( i = 0; i < count; i++ )
     {
@@ -331,9 +333,9 @@
       mask >>= 1;
     }
 
-    /* XXX: for now we ignore the secondary stroke and edge definitions */
-    /*      since we don't want to support native PFR hinting           */
-    /*                                                                  */
+    /* XXX: we ignore the secondary stroke and edge definitions */
+    /*      since we don't support native PFR hinting           */
+    /*                                                          */
     if ( flags & PFR_GLYPH_EXTRA_ITEMS )
     {
       error = pfr_extra_items_skip( &p, limit );
@@ -366,27 +368,27 @@
 
         switch ( format >> 4 )
         {
-        case 0:                             /* end glyph */
+        case 0:                                               /* end glyph */
           FT_TRACE6(( "- end glyph" ));
           args_count = 0;
           break;
 
-        case 1:                             /* general line operation */
+        case 1:                                  /* general line operation */
           FT_TRACE6(( "- general line" ));
           goto Line1;
 
-        case 4:                             /* move to inside contour  */
+        case 4:                                 /* move to inside contour  */
           FT_TRACE6(( "- move to inside" ));
           goto Line1;
 
-        case 5:                             /* move to outside contour */
+        case 5:                                 /* move to outside contour */
           FT_TRACE6(( "- move to outside" ));
         Line1:
           args_format = format_low;
           args_count  = 1;
           break;
 
-        case 2:                             /* horizontal line to */
+        case 2:                                      /* horizontal line to */
           FT_TRACE6(( "- horizontal line to cx.%d", format_low ));
           if ( format_low >= x_count )
             goto Failure;
@@ -396,7 +398,7 @@
           args_count = 0;
           break;
 
-        case 3:                             /* vertical line to */
+        case 3:                                        /* vertical line to */
           FT_TRACE6(( "- vertical line to cy.%d", format_low ));
           if ( format_low >= y_count )
             goto Failure;
@@ -406,19 +408,19 @@
           args_count = 0;
           break;
 
-        case 6:                             /* horizontal to vertical curve */
+        case 6:                            /* horizontal to vertical curve */
           FT_TRACE6(( "- hv curve " ));
           args_format = 0xB8E;
           args_count  = 3;
           break;
 
-        case 7:                             /* vertical to horizontal curve */
+        case 7:                            /* vertical to horizontal curve */
           FT_TRACE6(( "- vh curve" ));
           args_format = 0xE2B;
           args_count  = 3;
           break;
 
-        default:                            /* general curve to */
+        default:                                       /* general curve to */
           FT_TRACE6(( "- general curve" ));
           args_count  = 4;
           args_format = format_low;
@@ -439,14 +441,14 @@
           {
           case 0:                           /* 8-bit index */
             PFR_CHECK( 1 );
-            idx  = PFR_NEXT_BYTE( p );
+            idx = PFR_NEXT_BYTE( p );
             if ( idx >= x_count )
               goto Failure;
             cur->x = glyph->x_control[idx];
             FT_TRACE7(( " cx#%d", idx ));
             break;
 
-          case 1:                           /* 16-bit value */
+          case 1:                           /* 16-bit absolute value */
             PFR_CHECK( 2 );
             cur->x = PFR_NEXT_SHORT( p );
             FT_TRACE7(( " x.%d", cur->x ));
@@ -516,22 +518,22 @@
         /*                                                         */
         switch ( format >> 4 )
         {
-        case 0:                             /* end glyph => EXIT */
+        case 0:                                       /* end glyph => EXIT */
           pfr_glyph_end( glyph );
           goto Exit;
 
-        case 1:                             /* line operations */
+        case 1:                                         /* line operations */
         case 2:
         case 3:
           error = pfr_glyph_line_to( glyph, pos );
           goto Test_Error;
 
-        case 4:                             /* move to inside contour  */
-        case 5:                             /* move to outside contour */
+        case 4:                                 /* move to inside contour  */
+        case 5:                                 /* move to outside contour */
           error = pfr_glyph_move_to( glyph, pos );
           goto Test_Error;
 
-        default:                            /* curve operations */
+        default:                                       /* curve operations */
           error = pfr_glyph_curve_to( glyph, pos, pos + 1, pos + 2 );
 
         Test_Error:  /* test error condition */
@@ -580,7 +582,8 @@
     if ( flags & PFR_GLYPH_EXTRA_ITEMS )
     {
       error = pfr_extra_items_skip( &p, limit );
-      if (error) goto Exit;
+      if ( error )
+        goto Exit;
     }
 
     /* we can't rely on the FT_GlyphLoader to load sub-glyphs, because   */
diff --git a/src/pfr/pfrload.c b/src/pfr/pfrload.c
index ec7311d..a1cae2c 100644
--- a/src/pfr/pfrload.c
+++ b/src/pfr/pfrload.c
@@ -75,7 +75,8 @@
           if ( extra->type == item_type )
           {
             error = extra->parser( p, p + item_size, item_data );
-            if ( error ) goto Exit;
+            if ( error )
+              goto Exit;
 
             break;
           }
@@ -183,7 +184,8 @@
     {
       result = 0;
     }
-    return  result;
+
+    return result;
   }
 
 
@@ -206,7 +208,8 @@
     FT_UInt   result = 0;
 
 
-    if ( FT_STREAM_SEEK( section_offset ) || FT_READ_USHORT( count ) )
+    if ( FT_STREAM_SEEK( section_offset ) ||
+         FT_READ_USHORT( count )          )
       goto Exit;
 
     result = count;
@@ -254,13 +257,14 @@
       FT_UInt   local;
 
 
-      if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) )
+      if ( FT_STREAM_SEEK( offset ) ||
+           FT_FRAME_ENTER( size )   )
         goto Exit;
 
       p     = stream->cursor;
       limit = p + size;
 
-      PFR_CHECK(13);
+      PFR_CHECK( 13 );
 
       log_font->matrix[0] = PFR_NEXT_LONG( p );
       log_font->matrix[1] = PFR_NEXT_LONG( p );
@@ -308,10 +312,11 @@
       if ( flags & PFR_LOG_EXTRA_ITEMS )
       {
         error = pfr_extra_items_skip( &p, limit );
-        if (error) goto Fail;
+        if ( error )
+          goto Fail;
       }
 
-      PFR_CHECK(5);
+      PFR_CHECK( 5 );
       log_font->phys_size   = PFR_NEXT_USHORT( p );
       log_font->phys_offset = PFR_NEXT_ULONG( p );
       if ( size_increment )
@@ -358,7 +363,7 @@
 
     PFR_CHECK( 5 );
 
-    p += 3;  /* skip bctSize */
+    p     += 3;  /* skip bctSize */
     flags0 = PFR_NEXT_BYTE( p );
     count  = PFR_NEXT_BYTE( p );
 
@@ -434,12 +439,12 @@
   }
 
 
-  /* Load font ID.  This is a so-called "unique" name that is rather
-   * long and descriptive (like "Tiresias ScreenFont v7.51").
+  /* Load font ID.  This is a so-called `unique' name that is rather
+   * long and descriptive (like `Tiresias ScreenFont v7.51').
    *
    * Note that a PFR font's family name is contained in an *undocumented*
-   * string of the "auxiliary data" portion of a physical font record.  This
-   * may also contain the "real" style name!
+   * string of the `auxiliary data' portion of a physical font record.  This
+   * may also contain the `real' style name!
    *
    * If no family name is present, the font ID is used instead for the
    * family.
@@ -612,7 +617,6 @@
   }
 
 
-
   static const PFR_ExtraItemRec  pfr_phy_font_extra_items[] =
   {
     { 1, (PFR_ExtraItem_ParseFunc)pfr_extra_item_load_bitmap_info },
@@ -623,7 +627,8 @@
   };
 
 
-  /* Loads a name from the auxiliary data.  Since this extracts undocumented
+  /*
+   * Load a name from the auxiliary data.  Since this extracts undocumented
    * strings from the font file, we need to be careful here.
    */
   static FT_Error
@@ -729,7 +734,8 @@
     phy_font->kern_items      = NULL;
     phy_font->kern_items_tail = &phy_font->kern_items;
 
-    if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) )
+    if ( FT_STREAM_SEEK( offset ) ||
+         FT_FRAME_ENTER( size )   )
       goto Exit;
 
     phy_font->cursor = stream->cursor;
@@ -757,16 +763,16 @@
     /* load the extra items when present */
     if ( flags & PFR_PHY_EXTRA_ITEMS )
     {
-      error =  pfr_extra_items_parse( &p, limit,
-                                      pfr_phy_font_extra_items, phy_font );
+      error = pfr_extra_items_parse( &p, limit,
+                                     pfr_phy_font_extra_items, phy_font );
 
       if ( error )
         goto Fail;
     }
 
-    /* In certain fonts, the auxiliary bytes contain interesting  */
-    /* information. These are not in the specification but can be */
-    /* guessed by looking at the content of a few PFR0 fonts.     */
+    /* In certain fonts, the auxiliary bytes contain interesting   */
+    /* information.  These are not in the specification but can be */
+    /* guessed by looking at the content of a few PFR0 fonts.      */
     PFR_CHECK( 3 );
     num_aux = PFR_NEXT_ULONG( p );
 
@@ -797,9 +803,8 @@
         switch ( type )
         {
         case 1:
-          /* this seems to correspond to the font's family name,
-           * padded to 16-bits with one zero when necessary
-           */
+          /* this seems to correspond to the font's family name, padded to */
+          /* an even number of bytes with a zero byte appended if needed   */
           error = pfr_aux_name_load( q, length - 4U, memory,
                                      &phy_font->family_name );
           if ( error )
@@ -817,9 +822,8 @@
           break;
 
         case 3:
-          /* this seems to correspond to the font's style name,
-           * padded to 16-bits with one zero when necessary
-           */
+          /* this seems to correspond to the font's style name, padded to */
+          /* an even number of bytes with a zero byte appended if needed  */
           error = pfr_aux_name_load( q, length - 4U, memory,
                                      &phy_font->style_name );
           if ( error )
diff --git a/src/pfr/pfrobjs.c b/src/pfr/pfrobjs.c
index b854b00..20d316d 100644
--- a/src/pfr/pfrobjs.c
+++ b/src/pfr/pfrobjs.c
@@ -118,9 +118,11 @@
 
     /* load the face */
     error = pfr_log_font_load(
-               &face->log_font, stream, (FT_UInt)( face_index & 0xFFFF ),
-               face->header.log_dir_offset,
-               FT_BOOL( face->header.phy_font_max_size_high != 0 ) );
+              &face->log_font,
+              stream,
+              (FT_UInt)( face_index & 0xFFFF ),
+              face->header.log_dir_offset,
+              FT_BOOL( face->header.phy_font_max_size_high != 0 ) );
     if ( error )
       goto Exit;
 
@@ -141,8 +143,8 @@
 
       pfrface->face_flags |= FT_FACE_FLAG_SCALABLE;
 
-      /* if all characters point to the same gps_offset 0, we */
-      /* assume that the font only contains bitmaps           */
+      /* if gps_offset == 0 for all characters, we  */
+      /* assume that the font only contains bitmaps */
       {
         FT_UInt  nn;
 
@@ -164,7 +166,7 @@
         }
       }
 
-      if ( (phy_font->flags & PFR_PHY_PROPORTIONAL) == 0 )
+      if ( ( phy_font->flags & PFR_PHY_PROPORTIONAL ) == 0 )
         pfrface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
 
       if ( phy_font->flags & PFR_PHY_VERTICAL )
@@ -178,7 +180,7 @@
       if ( phy_font->num_kern_pairs > 0 )
         pfrface->face_flags |= FT_FACE_FLAG_KERNING;
 
-      /* If no family name was found in the "undocumented" auxiliary
+      /* If no family name was found in the `undocumented' auxiliary
        * data, use the font ID instead.  This sucks but is better than
        * nothing.
        */
@@ -187,7 +189,7 @@
         pfrface->family_name = phy_font->font_id;
 
       /* note that the style name can be NULL in certain PFR fonts,
-       * probably meaning "Regular"
+       * probably meaning `Regular'
        */
       pfrface->style_name = phy_font->style_name;
 
@@ -264,13 +266,13 @@
         error = FT_CMap_New( &pfr_cmap_class_rec, NULL, &charmap, NULL );
 
 #if 0
-        /* Select default charmap */
+        /* select default charmap */
         if ( pfrface->num_charmaps )
           pfrface->charmap = pfrface->charmaps[0];
 #endif
       }
 
-      /* check whether we've loaded any kerning pairs */
+      /* check whether we have loaded any kerning pairs */
       if ( phy_font->num_kern_pairs )
         pfrface->face_flags |= FT_FACE_FLAG_KERNING;
     }
@@ -402,7 +404,7 @@
       pfrslot->linearHoriAdvance = metrics->horiAdvance;
       pfrslot->linearVertAdvance = metrics->vertAdvance;
 
-      /* make-up vertical metrics(?) */
+      /* make up vertical metrics(?) */
       metrics->vertBearingX = 0;
       metrics->vertBearingY = 0;
 
@@ -596,4 +598,5 @@
     return error;
   }
 
+
 /* END */
diff --git a/src/pfr/pfrsbit.c b/src/pfr/pfrsbit.c
index bb5df5c..bed082e 100644
--- a/src/pfr/pfrsbit.c
+++ b/src/pfr/pfrsbit.c
@@ -37,11 +37,11 @@
 
   typedef struct  PFR_BitWriter_
   {
-    FT_Byte*  line;      /* current line start                    */
-    FT_Int    pitch;     /* line size in bytes                    */
-    FT_UInt   width;     /* width in pixels/bits                  */
-    FT_UInt   rows;      /* number of remaining rows to scan      */
-    FT_UInt   total;     /* total number of bits to draw          */
+    FT_Byte*  line;      /* current line start               */
+    FT_Int    pitch;     /* line size in bytes               */
+    FT_UInt   width;     /* width in pixels/bits             */
+    FT_UInt   rows;      /* number of remaining rows to scan */
+    FT_UInt   total;     /* total number of bits to draw     */
 
   } PFR_BitWriterRec, *PFR_BitWriter;
 
@@ -341,8 +341,8 @@
   }
 
 
-  /* load bitmap metrics.  "*padvance" must be set to the default value */
-  /* before calling this function...                                    */
+  /* load bitmap metrics.  `*padvance' must be set to the default value */
+  /* before calling this function                                       */
   /*                                                                    */
   static FT_Error
   pfr_load_bitmap_metrics( FT_Byte**  pdata,
@@ -544,7 +544,7 @@
 
     character = &phys->chars[glyph_index];
 
-    /* Look-up a bitmap strike corresponding to the current */
+    /* look up a bitmap strike corresponding to the current */
     /* character dimensions                                 */
     {
       FT_UInt  n;
@@ -555,9 +555,7 @@
       {
         if ( strike->x_ppm == (FT_UInt)size->root.metrics.x_ppem &&
              strike->y_ppm == (FT_UInt)size->root.metrics.y_ppem )
-        {
           goto Found_Strike;
-        }
 
         strike++;
       }
@@ -568,7 +566,7 @@
 
   Found_Strike:
 
-    /* Now lookup the glyph's position within the file */
+    /* now look up the glyph's position within the file */
     {
       FT_UInt  char_len;
 
@@ -578,7 +576,7 @@
       if ( strike->flags & 2 ) char_len += 1;
       if ( strike->flags & 4 ) char_len += 1;
 
-      /* Access data directly in the frame to speed lookups */
+      /* access data directly in the frame to speed lookups */
       if ( FT_STREAM_SEEK( phys->bct_offset + strike->bct_offset ) ||
            FT_FRAME_ENTER( char_len * strike->num_bitmaps )        )
         goto Exit;
@@ -595,7 +593,7 @@
 
       if ( gps_size == 0 )
       {
-        /* Could not find a bitmap program string for this glyph */
+        /* could not find a bitmap program string for this glyph */
         error = FT_THROW( Invalid_Argument );
         goto Exit;
       }
@@ -617,8 +615,8 @@
 
       glyph->root.linearHoriAdvance = advance;
 
-      /* compute default advance, i.e., scaled advance.  This can be */
-      /* overridden in the bitmap header of certain glyphs.          */
+      /* compute default advance, i.e., scaled advance; this can be */
+      /* overridden in the bitmap header of certain glyphs          */
       advance = FT_MulDiv( (FT_Fixed)size->root.metrics.x_ppem << 8,
                            character->advance,
                            (FT_Long)phys->metrics_resolution );
@@ -684,14 +682,12 @@
 
           error = ft_glyphslot_alloc_bitmap( &glyph->root, len );
           if ( !error )
-          {
             error = pfr_load_bitmap_bits(
                       p,
                       stream->limit,
                       format,
                       FT_BOOL(face->header.color_flags & 2),
                       &glyph->root.bitmap );
-          }
         }
       }
 
@@ -702,4 +698,5 @@
     return error;
   }
 
+
 /* END */