Commit 51ecb69a88e232223050aa3c6fceff97300cfb24

Werner Lemberg 2003-11-13T10:19:27

* docs/CHANGES: Updated. Handle SETWIDTH_NAME and ADD_STYLE_NAME properties for BDF and PCF fonts. * src/bdf/bdfdrivr.c (bdf_interpret_style): New auxiliary function. (BDF_Face_Init): Don't handle style properties but call bdf_interpret_style. * src/pcf/pcfread.c (pcf_interpret_style): New auxiliary function. (pcf_load_font): Don't handle style properties but call pcf_interpret_style.

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
diff --git a/ChangeLog b/ChangeLog
index c2a3054..deed6a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2003-11-11  Werner Lemberg  <wl@gnu.org>
+
+	* docs/CHANGES: Updated.
+
+2003-11-11  John A. Boyd Jr.  <jaboydjr@netwalk.com>
+
+	Handle SETWIDTH_NAME and ADD_STYLE_NAME properties for BDF and PCF
+	fonts.
+
+	* src/bdf/bdfdrivr.c (bdf_interpret_style): New auxiliary function.
+	(BDF_Face_Init): Don't handle style properties but call
+	bdf_interpret_style.
+
+	* src/pcf/pcfread.c (pcf_interpret_style): New auxiliary function.
+	(pcf_load_font): Don't handle style properties but call
+	pcf_interpret_style.
+
 2003-11-07  Werner Lemberg  <wl@gnu.org>
 
 
diff --git a/docs/CHANGES b/docs/CHANGES
index 7a4c875..dea62e2 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -1,4 +1,18 @@
 
+LATEST CHANGES BETWEEN 2.1.8 and 2.1.7
+
+  I. IMPORTANT BUG FIXES
+
+
+  II. IMPORTANT CHANGES
+
+    - Both  PCF  and BDF  drivers  now  handle  the SETWIDTH_NAME  and
+      ADD_STYLE_NAME    properties.     Values    are   appended    to
+      face->style_name; example: `Bold SemiCondensed'.
+
+
+======================================================================
+
 LATEST CHANGES BETWEEN 2.1.7 and 2.1.6
 
   I. IMPORTANT BUG FIXES
diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c
index 9b9e11e..03dc8d3 100644
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -172,6 +172,113 @@ THE SOFTWARE.
   };
 
 
+  static FT_Error
+  bdf_interpret_style( BDF_Face  bdf )
+  {
+    FT_Error         error  = BDF_Err_Ok;
+    FT_Face          face   = FT_FACE( bdf );
+    FT_Memory        memory = face->memory;
+    bdf_font_t*      font   = bdf->bdffont;
+    bdf_property_t*  prop;
+
+    char  *istr = NULL, *bstr = NULL;
+    char  *sstr = NULL, *astr = NULL;
+
+    int  parts = 0, len = 0;  
+
+
+    face->style_flags = 0;
+
+    prop = bdf_get_font_property( font, (char *)"SLANT" );
+    if ( prop && prop->format == BDF_ATOM                             &&
+         prop->value.atom                                             &&
+         ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ||
+           *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) )
+    {
+      face->style_flags |= FT_STYLE_FLAG_ITALIC;
+      istr = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' )
+               ? (char *)"Oblique"
+               : (char *)"Italic";
+      len += ft_strlen( istr );
+      parts++;
+    }
+
+    prop = bdf_get_font_property( font, (char *)"WEIGHT_NAME" );
+    if ( prop && prop->format == BDF_ATOM                             &&
+         prop->value.atom                                             &&
+         ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
+    {
+      face->style_flags |= FT_STYLE_FLAG_BOLD;
+      bstr = (char *)"Bold";
+      len += ft_strlen( bstr );
+      parts++;
+    }
+
+    prop = bdf_get_font_property( font, (char *)"SETWIDTH_NAME" );
+    if ( prop && prop->format == BDF_ATOM                              &&
+         prop->value.atom && *(prop->value.atom)                       &&
+         !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
+    {
+      sstr = (char *)(prop->value.atom);
+      len += ft_strlen( sstr );
+      parts++;
+    }
+
+    prop = bdf_get_font_property( font, (char *)"ADD_STYLE_NAME" );
+    if ( prop && prop->format == BDF_ATOM                              &&
+         prop->value.atom && *(prop->value.atom)                       &&
+         !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
+    {
+      astr = (char *)(prop->value.atom);
+      len += ft_strlen( astr );
+      parts++;
+    }
+
+    if ( !parts || !len )
+      face->style_name = (char *)"Regular";
+    else
+    {
+      char  *style, *s; 
+
+
+      if ( FT_ALLOC( style, len + parts ) )
+        return error;
+
+      s = style;
+
+      if ( astr )
+      {
+        ft_strcpy( s, astr);
+        s += ft_strlen( astr );
+        *(s++) = ' ';
+      }
+      if ( bstr )
+      {
+        ft_strcpy( s, bstr );
+        s += ft_strlen( bstr );
+        *(s++) = ' ';
+      }
+      if ( istr )
+      {
+        ft_strcpy( s, istr );
+        s += ft_strlen( istr );
+        *(s++) = ' ';
+      }
+      if ( sstr )
+      {
+        ft_strcpy( s, sstr );
+        s += ft_strlen( sstr );
+        *(s++) = ' ';
+      }
+      *(--s) = '\0';        /* overwrite last ' ', terminate the string */
+
+      face->style_name = style;                     /* allocated string */
+    }
+
+    return error;
+  }
+
+
   FT_CALLBACK_DEF( FT_Error )
   BDF_Face_Done( BDF_Face  face )
   {
@@ -252,39 +359,17 @@ THE SOFTWARE.
                          FT_FACE_FLAG_FAST_GLYPHS;
 
       prop = bdf_get_font_property( font, "SPACING" );
-      if ( prop != NULL )
-        if ( prop->format == BDF_ATOM )
-          if ( prop->value.atom != NULL )
-            if ( ( *(prop->value.atom) == 'M' ) ||
-                 ( *(prop->value.atom) == 'm' ) ||
-                 ( *(prop->value.atom) == 'C' ) ||
-                 ( *(prop->value.atom) == 'c' ) )
-              root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
+      if ( prop && prop->format == BDF_ATOM                             &&
+           prop->value.atom                                             &&
+           ( *(prop->value.atom) == 'M' || *(prop->value.atom) == 'm' ||
+             *(prop->value.atom) == 'C' || *(prop->value.atom) == 'c' ) )
+        root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
 
       /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL   */
       /* FZ XXX: I need a font to implement this */
 
-      root->style_flags = 0;
-      prop = bdf_get_font_property( font, "SLANT" );
-      if ( prop != NULL )
-        if ( prop->format == BDF_ATOM )
-          if ( prop->value.atom != NULL )
-            if ( ( *(prop->value.atom) == 'O' ) ||
-                 ( *(prop->value.atom) == 'o' ) ||
-                 ( *(prop->value.atom) == 'I' ) ||
-                 ( *(prop->value.atom) == 'i' ) )
-              root->style_flags |= FT_STYLE_FLAG_ITALIC;
-
-      prop = bdf_get_font_property( font, "WEIGHT_NAME" );
-      if ( prop != NULL )
-        if ( prop->format == BDF_ATOM )
-          if ( prop->value.atom != NULL )
-            if ( ( *(prop->value.atom) == 'B' ) ||
-                 ( *(prop->value.atom) == 'b' ) )
-              root->style_flags |= FT_STYLE_FLAG_BOLD;
-
       prop = bdf_get_font_property( font, "FAMILY_NAME" );
-      if ( ( prop != NULL ) && ( prop->value.atom != NULL ) )
+      if ( prop && prop->value.atom )
       {
         int  l = ft_strlen( prop->value.atom ) + 1;
 
@@ -296,16 +381,8 @@ THE SOFTWARE.
       else
         root->family_name = 0;
 
-      root->style_name = (char *)"Regular";
-      if ( root->style_flags & FT_STYLE_FLAG_BOLD )
-      {
-        if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
-          root->style_name = (char *)"Bold Italic";
-        else
-          root->style_name = (char *)"Bold";
-      }
-      else if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
-        root->style_name = (char *)"Italic";
+      if ( ( error = bdf_interpret_style( face ) ) )
+        goto Exit;
 
       root->num_glyphs = font->glyphs_size;     /* unencoded included */
 
@@ -320,26 +397,26 @@ THE SOFTWARE.
         FT_MEM_ZERO( bsize, sizeof ( FT_Bitmap_Size ) );
 
         prop = bdf_get_font_property( font, "PIXEL_SIZE" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->height = (FT_Short)prop->value.int32;
 
         prop = bdf_get_font_property( font, "AVERAGE_WIDTH" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->width = (FT_Short)( ( prop->value.int32 + 5 ) / 10 );
 
         prop = bdf_get_font_property( font, "POINT_SIZE" );
-        if ( prop != NULL )
+        if ( prop )
           /* convert from 722.7 decipoints to 72 points per inch */
           bsize->size =
             (FT_Pos)( ( prop->value.int32 * 64 * 7200 + 36135L ) / 72270L );
 
         prop = bdf_get_font_property( font, "RESOLUTION_X" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->x_ppem =
             (FT_Pos)( ( prop->value.int32 * bsize->size + 36 ) / 72 );
 
         prop = bdf_get_font_property( font, "RESOLUTION_Y" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->y_ppem =
             (FT_Pos)( ( prop->value.int32 * bsize->size + 36 ) / 72 );
 
@@ -381,12 +458,12 @@ THE SOFTWARE.
           bdf_get_font_property( font, "CHARSET_REGISTRY" );
         charset_encoding =
           bdf_get_font_property( font, "CHARSET_ENCODING" );
-        if ( ( charset_registry != NULL ) && ( charset_encoding != NULL ) )
+        if ( charset_registry && charset_encoding )
         {
-          if ( ( charset_registry->format == BDF_ATOM ) &&
-               ( charset_encoding->format == BDF_ATOM ) &&
-               ( charset_registry->value.atom != NULL ) &&
-               ( charset_encoding->value.atom != NULL ) )
+          if ( charset_registry->format == BDF_ATOM &&
+               charset_encoding->format == BDF_ATOM &&
+               charset_registry->value.atom         &&
+               charset_encoding->value.atom         )
           {
             const char*  s;
 
@@ -669,7 +746,7 @@ THE SOFTWARE.
     FT_ASSERT( face && face->bdffont );
 
     prop = bdf_get_font_property( face->bdffont, prop_name );
-    if ( prop != NULL )
+    if ( prop )
     {
       switch ( prop->format )
       {
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 1b377b5..e2deab3 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -862,6 +862,111 @@ THE SOFTWARE.
   }
 
 
+  static FT_Error
+  pcf_interpret_style( PCF_Face  pcf )
+  {
+    FT_Error   error  = PCF_Err_Ok;
+    FT_Face    face   = FT_FACE( pcf );
+    FT_Memory  memory = face->memory;
+
+    PCF_Property  prop;
+
+    char  *istr = NULL, *bstr = NULL;
+    char  *sstr = NULL, *astr = NULL;
+
+    int  parts = 0, len = 0;  
+
+
+    face->style_flags = 0;
+
+    prop = pcf_find_property( pcf, "SLANT" );
+    if ( prop && prop->isString                                       &&
+         ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ||
+           *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) )
+    {
+      face->style_flags |= FT_STYLE_FLAG_ITALIC;
+      istr = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' )
+               ? (char *)"Oblique"
+               : (char *)"Italic";
+      len += ft_strlen( istr );
+      parts++;
+    }
+
+    prop = pcf_find_property( pcf, "WEIGHT_NAME" );
+    if ( prop && prop->isString                                       &&
+         ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
+    {
+      face->style_flags |= FT_STYLE_FLAG_BOLD;
+      bstr = (char *)"Bold";
+      len += ft_strlen( bstr );
+      parts++;
+    }
+
+    prop = pcf_find_property( pcf, "SETWIDTH_NAME" );
+    if ( prop && prop->isString                                        &&
+         *(prop->value.atom)                                           &&
+         !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
+    {
+      sstr = (char *)(prop->value.atom);
+      len += ft_strlen( sstr );
+      parts++;
+    }
+
+    prop = pcf_find_property( pcf, "ADD_STYLE_NAME" );
+    if ( prop && prop->isString                                        &&
+         *(prop->value.atom)                                           &&
+         !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
+    {
+      astr = (char *)(prop->value.atom);
+      len += ft_strlen( astr );
+      parts++;
+    }
+
+    if ( !parts || !len )
+      face->style_name = (char *)"Regular";
+    else
+    {
+      char  *style, *s; 
+
+
+      if ( FT_ALLOC( style, len + parts ) )
+        return error;
+
+      s = style;
+
+      if ( astr )
+      {
+        ft_strcpy( s, astr );
+        s += ft_strlen( astr );
+        *(s++) = ' ';
+      }
+      if ( bstr )
+      {
+        ft_strcpy( s, bstr );
+        s += ft_strlen( bstr );
+        *(s++) = ' ';
+      }
+      if ( istr )
+      {
+        ft_strcpy( s, istr );
+        s += ft_strlen( istr );
+        *(s++) = ' ';
+      }
+      if ( sstr )
+      {
+        ft_strcpy( s, sstr );
+        s += ft_strlen( sstr );
+        *(s++) = ' ';
+      }
+      *(--s) = '\0';        /* overwrite last ' ', terminate the string */
+
+      face->style_name = style;                     /* allocated string */
+    }
+
+    return error;
+  }
+
+
   FT_LOCAL_DEF( FT_Error )
   pcf_load_font( FT_Stream  stream,
                  PCF_Face   face )
@@ -930,49 +1035,21 @@ THE SOFTWARE.
       if ( face->accel.constantWidth )
         root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
 
-      root->style_flags = 0;
-      prop = pcf_find_property( face, "SLANT" );
-      if ( prop != NULL )
-        if ( prop->isString )
-          if ( ( *(prop->value.atom) == 'O' ) ||
-               ( *(prop->value.atom) == 'o' ) ||
-               ( *(prop->value.atom) == 'I' ) ||
-               ( *(prop->value.atom) == 'i' ) )
-            root->style_flags |= FT_STYLE_FLAG_ITALIC;
-
-      prop = pcf_find_property( face, "WEIGHT_NAME" );
-      if ( prop != NULL )
-        if ( prop->isString )
-          if ( ( *(prop->value.atom) == 'B' ) ||
-               ( *(prop->value.atom) == 'b' ) )
-            root->style_flags |= FT_STYLE_FLAG_BOLD;
-
-      root->style_name = (char *)"Regular";
-
-      if ( root->style_flags & FT_STYLE_FLAG_BOLD ) {
-        if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
-          root->style_name = (char *)"Bold Italic";
-        else
-          root->style_name = (char *)"Bold";
-      }
-      else if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
-        root->style_name = (char *)"Italic";
+      if ( ( error = pcf_interpret_style( face ) ) )
+         goto Exit;
 
       prop = pcf_find_property( face, "FAMILY_NAME" );
-      if ( prop != NULL )
+      if ( prop && prop->isString )
       {
-        if ( prop->isString )
-        {
-          int  l = ft_strlen( prop->value.atom ) + 1;
+        int  l = ft_strlen( prop->value.atom ) + 1;
 
 
-          if ( FT_NEW_ARRAY( root->family_name, l ) )
-            goto Exit;
-          ft_strcpy( root->family_name, prop->value.atom );
-        }
+        if ( FT_NEW_ARRAY( root->family_name, l ) )
+          goto Exit;
+        ft_strcpy( root->family_name, prop->value.atom );
       }
       else
-        root->family_name = 0;
+        root->family_name = NULL;
 
       /* Note: We shift all glyph indices by +1 since we must
        * respect the convention that glyph 0 always corresponds
@@ -993,26 +1070,26 @@ THE SOFTWARE.
         FT_MEM_ZERO( bsize, sizeof ( FT_Bitmap_Size ) );
 
         prop = pcf_find_property( face, "PIXEL_SIZE" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->height = (FT_Short)prop->value.integer;
 
         prop = pcf_find_property( face, "AVERAGE_WIDTH" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->width = (FT_Short)( ( prop->value.integer + 5 ) / 10 );
 
         prop = pcf_find_property( face, "POINT_SIZE" );
-        if ( prop != NULL )
+        if ( prop )
           /* convert from 722,7 decipoints to 72 points per inch */
           bsize->size =
             (FT_Pos)( ( prop->value.integer * 64 * 7200 + 36135L ) / 72270L );
 
         prop = pcf_find_property( face, "RESOLUTION_X" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->x_ppem =
             (FT_Pos)( ( prop->value.integer * bsize->size + 36 ) / 72 );
 
         prop = pcf_find_property( face, "RESOLUTION_Y" );
-        if ( prop != NULL )
+        if ( prop )
           bsize->y_ppem =
             (FT_Pos)( ( prop->value.integer * bsize->size + 36 ) / 72 );
 
@@ -1031,23 +1108,19 @@ THE SOFTWARE.
         charset_registry = pcf_find_property( face, "CHARSET_REGISTRY" );
         charset_encoding = pcf_find_property( face, "CHARSET_ENCODING" );
 
-        if ( ( charset_registry != NULL ) &&
-             ( charset_encoding != NULL ) )
+        if ( charset_registry && charset_registry->isString &&
+             charset_encoding && charset_encoding->isString )
         {
-          if ( ( charset_registry->isString ) &&
-               ( charset_encoding->isString ) )
-          {
-            if ( FT_NEW_ARRAY( face->charset_encoding,
-                               ft_strlen( charset_encoding->value.atom ) + 1 ) )
-              goto Exit;
-
-            if ( FT_NEW_ARRAY( face->charset_registry,
-                               ft_strlen( charset_registry->value.atom ) + 1 ) )
-              goto Exit;
-
-            ft_strcpy( face->charset_registry, charset_registry->value.atom );
-            ft_strcpy( face->charset_encoding, charset_encoding->value.atom );
-          }
+          if ( FT_NEW_ARRAY( face->charset_encoding,
+                             ft_strlen( charset_encoding->value.atom ) + 1 ) )
+            goto Exit;
+
+          if ( FT_NEW_ARRAY( face->charset_registry,
+                             ft_strlen( charset_registry->value.atom ) + 1 ) )
+            goto Exit;
+
+          ft_strcpy( face->charset_registry, charset_registry->value.atom );
+          ft_strcpy( face->charset_encoding, charset_encoding->value.atom );
         }
       }
     }