Commit 2e57343f900ed73846a95d898117e5eb3961aa17

Werner Lemberg 2003-04-23T14:14:06

* src/pfr/pfrload.c (pfr_extra_item_load_font_id): Use FT_PtrDist instead of FT_Uint for `len'. Cleanups.

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
diff --git a/ChangeLog b/ChangeLog
index 0c83c64..0489e75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-04-23  Werner Lemberg  <wl@gnu.org>
+
+	* src/pfr/pfrload.c (pfr_extra_item_load_font_id): Use FT_PtrDist
+	instead of FT_Uint for `len'.
+
 2003-04-22  Werner Lemberg  <wl@gnu.org>
 
 	* src/gzip/ftgzip.c (zcalloc) [!FT_CONFIG_OPTION_SYSTEM_ZLIB]:
@@ -92,7 +97,10 @@
 	Use `ft_glyphslot_*' functions.
 	Don't set `FT_GLYPH_OWN_BITMAP'.
 
-	* src/pfr/pfrsbit.c, src/sfnt/ttsbit.c, src/type42/t42objs.c,
+	* src/pfr/pfrsbit.c (pfr_slot_load_bitmap): Use
+	`ft_glyphslot_alloc_bitmap'.
+
+	* src/sfnt/ttsbit.c, src/type42/t42objs.c,
 	src/winfonts/winfnt.c:
 
 	* src/cache/ftlru.c (FT_LruList_Lookup): Fixed an invalid assertion
@@ -143,8 +151,8 @@
 	* src/cache/ftlru.c: Include FT_INTERNAL_DEBUG_H.
 	(FT_LruList_Lookup): Implement loop.
 
-	* src/pfr/pfrobjs.c, src/pfr/pfrsbits.c: Fixing compiler warnings
-	and a small memory leak.
+	* src/pfr/pfrobjs.c (pfr_face_done): Fix memory leak.
+	(pfr_face_init): Fixing compiler warnings.
 
 	* src/psaux/psobjs.c (t1_reallocate_table): Fixed a bug (memory
 	leak) that only happened when a try to resize an array would end in
@@ -178,8 +186,7 @@
 
 	  touch 0123456789 ; gzip 0123456789 ; ftdump 0123456789.gz
 
-	* src/pfr/pfrobjs.c, src/pfr/pfrload.c, src/pfr/pfrtypes.h: Several
-	fixes to the PFR font driver:
+	Several fixes to the PFR font driver:
 
 	- The list of available embedded bitmaps was not correctly set in
 	  the root FT_FaceRec structure describing the face.
@@ -193,6 +200,20 @@
 
 	NOTE THAT THESE CHANGES THE FAMILY NAME OF MANY PFR FONTS!
 
+	* src/pfr/pfrload.c (pfr_aux_name_load): New function.
+	(pfr_phy_font_done): Free `family_name' and `style_name' also.
+	Remove unused variables.
+	(pfr_phy_font_load): Extract useful information from the auxiliary
+	bytes.
+
+	* src/pfr/pfrobjs.c (pfr_face_done): Set pointers to NULL.
+	(pfr_face_init): Provide fallback values for `family_name' and
+	`style_name'.
+	Handle strikes.
+	(pfr_slot_load): Handle FT_LOAD_SBITS_ONLY.
+	* src/pfr/pfrtypes.h (PFR_PhyFontRec): Add fields `ascent',
+	`descent', `leading', `family_name', and `style_name'.
+
 	* src/truetype/ttdriver.c (Set_Char_Sizes): Fixed a rounding bug
 	when computing the scale factors for a given character size in
 	points with resolution.
@@ -587,7 +608,7 @@
 	* src/sfnt/ttcmap0.c (tt_face_build_cmaps): Removed compiler
 	warnings in optimized mode relative to the "volatile" local
 	variables.  This was not a compiler bug after all, but the fact that
-	a pointer to a volatile variable is not the same than a volatile
+	a pointer to a volatile variable is not the same as a volatile
 	pointer to a variable :-)
 
 	The fix was to change
@@ -595,8 +616,9 @@
 	into
 	  `FT_Byte* volatile p'.
 
-	* src/pfr/pfrload.c, src/pfr/pfrdrivr.c, src/gzip/inftrees.c:
-	Removed compiler warnings in optimized modes.
+	* src/pfr/pfrload.c (pfr_phy_font_load), src/pfr/pfrdrivr.c
+	(pfr_get_metrics), src/gzip/inftrees.c: Removed compiler warnings in
+	optimized modes.
 
 	* src/gzip/*.[hc]: Modified our zlib copy in order to prevent
 	exporting any zlib function names outside of the component.  This
@@ -620,10 +642,16 @@
 	* include/freetype/internal/internal.h (FT_INTERNAL_PFR_H): New
 	macro for pfr.h.
 
-	src/base/ftpfr.c: New file.
-
+	* src/base/ftpfr.c: New file.
 	* src/base/Jamfile, src/base/descrip.mms: Updated.
 
+	* src/pfr/pfrdrivr.c: Include FT_INTERNAL_PFR_H.
+	(pfr_get_kerning, pfr_get_advance, pfr_get_metrics): New functions.
+	(pfr_service_rec): New format interface.
+	(pfr_driver_class): Use `pfr_service_rec'.
+	Replace `pfr_face_get_kerning' with `pfr_get_kerning'.
+	* src/pfr/pfrobjs.c: Remove dead code.
+
 	* src/base/ftobjs.c (ft_glyphslot_clear): Small internal fix to
 	better support bitmap-based font formats.
 
diff --git a/src/pfr/pfrdrivr.c b/src/pfr/pfrdrivr.c
index 07ba9b4..d75b3a3 100644
--- a/src/pfr/pfrdrivr.c
+++ b/src/pfr/pfrdrivr.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType PFR driver interface (body).                                */
 /*                                                                         */
-/*  Copyright 2002 by                                                      */
+/*  Copyright 2002, 2003 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -32,11 +32,13 @@
   {
     FT_Error  error;
 
+
     error = pfr_face_get_kerning( face, left, right, avector );
     if ( !error )
     {
       PFR_PhyFont  phys = &face->phy_font;
 
+
       /* convert from metrics to outline units when necessary */
       if ( phys->outline_resolution != phys->metrics_resolution )
       {
@@ -49,6 +51,7 @@
                                               phys->metrics_resolution );
       }
     }
+
     return error;
   }
 
@@ -58,13 +61,15 @@
                    FT_UInt    gindex,
                    FT_Pos    *aadvance )
   {
-    FT_Error     error = FT_Err_Bad_Argument;
+    FT_Error  error = FT_Err_Bad_Argument;
+
 
     *aadvance = 0;
     if ( face )
     {
       PFR_PhyFont  phys  = &face->phy_font;
 
+
       if ( gindex < phys->num_chars )
       {
         *aadvance = phys->chars[ gindex ].advance;
@@ -87,6 +92,7 @@
     FT_Fixed     x_scale, y_scale;
     FT_Size      size = face->root.size;
 
+
     if ( aoutline_resolution )
       *aoutline_resolution = phys->outline_resolution;
 
diff --git a/src/pfr/pfrload.c b/src/pfr/pfrload.c
index 87d0757..e92ead9 100644
--- a/src/pfr/pfrload.c
+++ b/src/pfr/pfrload.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType PFR loader (body).                                          */
 /*                                                                         */
-/*  Copyright 2002 by                                                      */
+/*  Copyright 2002, 2003 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -153,7 +153,7 @@
   pfr_header_load( PFR_Header  header,
                    FT_Stream   stream )
   {
-    FT_Error   error;
+    FT_Error  error;
 
 
     /* read header directly */
@@ -201,9 +201,9 @@
                       FT_UInt32  section_offset,
                       FT_UInt   *acount )
   {
-    FT_Error   error;
-    FT_UInt    count;
-    FT_UInt    result = 0;
+    FT_Error  error;
+    FT_UInt   count;
+    FT_UInt   result = 0;
 
 
     if ( FT_STREAM_SEEK( section_offset ) || FT_READ_USHORT( count ) )
@@ -239,8 +239,8 @@
       return PFR_Err_Invalid_Argument;
 
     if ( FT_STREAM_SKIP( idx * 5 ) ||
-         FT_READ_USHORT( size )      ||
-         FT_READ_UOFF3 ( offset )    )
+         FT_READ_USHORT( size )    ||
+         FT_READ_UOFF3 ( offset )  )
       goto Exit;
 
     /* save logical font size and offset */
@@ -365,7 +365,8 @@
     /* re-allocate when needed */
     if ( phy_font->num_strikes + count > phy_font->max_strikes )
     {
-      FT_UInt  new_max = (phy_font->num_strikes + count + 3) & -4;
+      FT_UInt  new_max = ( phy_font->num_strikes + count + 3 ) & -4;
+
 
       if ( FT_RENEW_ARRAY( phy_font->strikes,
                            phy_font->num_strikes,
@@ -432,30 +433,30 @@
   }
 
 
- /* 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 !
-  *
-  * if no family name is present, the font id is used instead for the
-  * family
-  */
+  /* 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!
+   *
+   * If no family name is present, the font ID is used instead for the
+   * family.
+   */
   FT_CALLBACK_DEF( FT_Error )
   pfr_extra_item_load_font_id( FT_Byte*     p,
                                FT_Byte*     limit,
                                PFR_PhyFont  phy_font )
   {
-    FT_Error   error  = 0;
-    FT_Memory  memory = phy_font->memory;
-    FT_UInt    len    = (FT_UInt)( limit - p );
+    FT_Error    error  = 0;
+    FT_Memory   memory = phy_font->memory;
+    FT_PtrDist  len    = limit - p;
 
 
     if ( phy_font->font_id != NULL )
       goto Exit;
 
-    if ( FT_ALLOC( phy_font->font_id, len+1 ) )
+    if ( FT_ALLOC( phy_font->font_id, len + 1 ) )
       goto Exit;
 
     /* copy font ID name, and terminate it for safety */
@@ -702,9 +703,9 @@
   };
 
 
- /* loads a name from the auxiliary data. Since this extracts undocumented
-  * strings from the font file, we need to be careful here
-  */
+  /* Loads a name from the auxiliary data.  Since this extracts undocumented
+   * strings from the font file, we need to be careful here.
+   */
   static FT_Error
   pfr_aux_name_load( FT_Byte*     p,
                      FT_UInt      len,
@@ -715,13 +716,14 @@
     FT_String*  result = NULL;
     FT_UInt     n, ok;
 
-    if ( len > 0 && p[len-1] == 0 )
+
+    if ( len > 0 && p[len - 1] == 0 )
       len--;
 
-   /* check that each character is ASCII, that's to be sure
-    * to not load garbage..
-    */
-    ok = (len > 0);
+    /* check that each character is ASCII for making sure not to
+       load garbage
+     */
+    ok = ( len > 0 );
     for ( n = 0; n < len; n++ )
       if ( p[n] < 32 || p[n] > 127 )
       {
@@ -731,7 +733,7 @@
 
     if ( ok )
     {
-      if ( FT_ALLOC( result, len+1 ) )
+      if ( FT_ALLOC( result, len + 1 ) )
         goto Exit;
 
       FT_MEM_COPY( result, p, len );
@@ -787,7 +789,6 @@
   }
 
 
-
   FT_LOCAL_DEF( FT_Error )
   pfr_phy_font_load( PFR_PhyFont  phy_font,
                      FT_Stream    stream,
@@ -842,9 +843,9 @@
         goto Fail;
     }
 
-    /* in certain fonts, the auxiliary bytes contain interesting  */
+    /* 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      */
+    /* guessed by looking at the content of a few PFR0 fonts.     */
     PFR_CHECK( 3 );
     num_aux = PFR_NEXT_ULONG( p );
 
@@ -853,6 +854,7 @@
       FT_Byte*  q = p;
       FT_Byte*  q2;
 
+
       PFR_CHECK( num_aux );
       p += num_aux;
 
@@ -860,58 +862,54 @@
       {
         FT_UInt  length, type;
 
+
         if ( q + 4 > p )
           break;
 
-        length = PFR_NEXT_USHORT(q);
+        length = PFR_NEXT_USHORT( q );
         if ( length < 4 || length > num_aux )
           break;
 
         q2   = q + length - 2;
-        type = PFR_NEXT_USHORT(q);
+        type = PFR_NEXT_USHORT( q );
 
         switch ( type )
         {
-          case 1:
-            {
-             /* this seems to correspond to the font's family name,
-              * padded to 16-bits with one zero when necessary
-              */
-              error = pfr_aux_name_load( q, length-4U, memory,
-                                         &phy_font->family_name );
-              if ( error )
-                goto Exit;
-            }
-            break;
+        case 1:
+          /* this seems to correspond to the font's family name,
+           * padded to 16-bits with one zero when necessary
+           */
+          error = pfr_aux_name_load( q, length - 4U, memory,
+                                     &phy_font->family_name );
+          if ( error )
+            goto Exit;
+          break;
 
-          case 2:
-            {
-              if ( q + 32 > q2 )
-                break;
-
-              q += 10;
-              phy_font->ascent  = PFR_NEXT_SHORT(q);
-              phy_font->descent = PFR_NEXT_SHORT(q);
-              phy_font->leading = PFR_NEXT_SHORT(q);
-              q += 16;
-            }
+        case 2:
+          if ( q + 32 > q2 )
             break;
 
-          case 3:
-            {
-             /* this seems to correspond to the font's style name,
-              * padded to 16-bits with one zero when necessary
-              */
-              error = pfr_aux_name_load( q, length-4U, memory,
-                                         &phy_font->style_name );
-              if ( error )
-                goto Exit;
-            }
-            break;
+          q += 10;
+          phy_font->ascent  = PFR_NEXT_SHORT( q );
+          phy_font->descent = PFR_NEXT_SHORT( q );
+          phy_font->leading = PFR_NEXT_SHORT( q );
+          q += 16;
+          break;
 
-          default:
-            ;
+        case 3:
+          /* this seems to correspond to the font's style name,
+           * padded to 16-bits with one zero when necessary
+           */
+          error = pfr_aux_name_load( q, length - 4U, memory,
+                                     &phy_font->style_name );
+          if ( error )
+            goto Exit;
+          break;
+
+        default:
+          ;
         }
+
         q        = q2;
         num_aux -= length;
       }
@@ -921,6 +919,7 @@
     {
       FT_UInt  n, count;
 
+
       PFR_CHECK( 1 );
       phy_font->num_blue_values = count = PFR_NEXT_BYTE( p );
 
@@ -1000,7 +999,8 @@
       }
     }
 
-    /* that's it !! */
+    /* that's it! */
+
   Fail:
     FT_FRAME_EXIT();
 
diff --git a/src/pfr/pfrobjs.c b/src/pfr/pfrobjs.c
index 867644a..84f99ad 100644
--- a/src/pfr/pfrobjs.c
+++ b/src/pfr/pfrobjs.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType PFR object methods (body).                                  */
 /*                                                                         */
-/*  Copyright 2002 by                                                      */
+/*  Copyright 2002, 2003 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -41,7 +41,8 @@
   FT_LOCAL_DEF( void )
   pfr_face_done( PFR_Face  face )
   {
-    FT_Memory   memory = face->root.driver->root.memory;
+    FT_Memory  memory = face->root.driver->root.memory;
+
 
     /* we don't want dangling pointers */
     face->root.family_name = NULL;
@@ -143,18 +144,18 @@
        if ( phy_font->num_kern_pairs > 0 )
          root->face_flags |= FT_FACE_FLAG_KERNING;
 
-      /* if no family name was found in the "undocumented" auxiliary
-       * data, use the font ID instead. This sucks but is better than
-       * nothing
-       */
+       /* If no family name was found in the "undocumented" auxiliary
+        * data, use the font ID instead.  This sucks but is better than
+        * nothing.
+        */
        root->family_name = phy_font->family_name;
        if ( root->family_name == NULL )
          root->family_name = phy_font->font_id;
 
-      /* note that the style name can be NULL in certain PFR fonts,
-       * probably meaning "Regular"
-       */
-       root->style_name  = phy_font->style_name;
+       /* note that the style name can be NULL in certain PFR fonts,
+        * probably meaning "Regular"
+        */
+       root->style_name = phy_font->style_name;
 
        root->num_fixed_sizes = 0;
        root->available_sizes = 0;
@@ -182,8 +183,8 @@
          strike = phy_font->strikes;
          for ( n = 0; n < count; n++, size++, strike++ )
          {
-           size->height = (FT_UShort) strike->y_ppm;
-           size->width  = (FT_UShort) strike->x_ppm;
+           size->height = (FT_UShort)strike->y_ppm;
+           size->width  = (FT_UShort)strike->x_ppm;
          }
          root->num_fixed_sizes = count;
        }
@@ -279,7 +280,8 @@
     FT_Outline*  outline = &slot->root.outline;
     FT_ULong     gps_offset;
 
-    if (gindex > 0)
+
+    if ( gindex > 0 )
       gindex--;
 
     /* check that the glyph index is correct */
diff --git a/src/pfr/pfrsbit.c b/src/pfr/pfrsbit.c
index 408b063..5499d29 100644
--- a/src/pfr/pfrsbit.c
+++ b/src/pfr/pfrsbit.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType PFR bitmap loader (body).                                   */
 /*                                                                         */
-/*  Copyright 2002 by                                                      */
+/*  Copyright 2002, 2003 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -115,7 +115,7 @@
     }
 
     if ( mask != 0x80 )
-      cur[0] = (FT_Byte) c;
+      cur[0] = (FT_Byte)c;
   }
 
 
@@ -185,7 +185,7 @@
       }
       else if ( mask == 0 )
       {
-        cur[0] = (FT_Byte) c;
+        cur[0] = (FT_Byte)c;
         mask   = 0x80;
         c      = 0;
         cur ++;
@@ -249,7 +249,7 @@
       }
       else if ( mask == 0 )
       {
-        cur[0] = (FT_Byte) c;
+        cur[0] = (FT_Byte)c;
         c      = 0;
         mask   = 0x80;
         cur ++;
@@ -583,7 +583,7 @@
       pfr_lookup_bitmap_data( stream->cursor,
                               stream->limit,
                               strike->num_bitmaps,
-                              (FT_Byte) strike->flags,
+                              (FT_Byte)strike->flags,
                               character->char_code,
                               &gps_offset,
                               &gps_size );
@@ -645,7 +645,8 @@
 
         /* Allocate and read bitmap data */
         {
-          FT_ULong    len    = glyph->root.bitmap.pitch * ysize;
+          FT_ULong  len = glyph->root.bitmap.pitch * ysize;
+
 
           error = ft_glyphslot_alloc_bitmap( &glyph->root, len );
           if ( !error )
diff --git a/src/pfr/pfrtypes.h b/src/pfr/pfrtypes.h
index 96744fc..21b4e3d 100644
--- a/src/pfr/pfrtypes.h
+++ b/src/pfr/pfrtypes.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType PFR data structures (specification only).                   */
 /*                                                                         */
-/*  Copyright 2002 by                                                      */
+/*  Copyright 2002, 2003 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */