summary refs log tree commit diff
path: root/pkgs/development/libraries/freetype/pcf-config-long-family-names.patch
blob: 95ed83c60f8fccec3dc2fbe964263856a2e847c9 (plain) (blame)
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
diff --git a/devel/ftoption.h b/devel/ftoption.h
index 3b63931..b8b0a8d 100644
--- a/devel/ftoption.h
+++ b/devel/ftoption.h
@@ -82,8 +82,8 @@ FT_BEGIN_HEADER
   /* to control the various font drivers and modules.  The controllable    */
   /* properties are listed in the section `Controlling FreeType Modules'   */
   /* in the reference's table of contents; currently there are properties  */
-  /* for the auto-hinter (file `ftautoh.h'), CFF (file `ftcffdrv.h'), and  */
-  /* TrueType (file `ftttdrv.h').                                          */
+  /* for the auto-hinter (file `ftautoh.h'), CFF (file `ftcffdrv.h'),      */
+  /* TrueType (file `ftttdrv.h'), and PCF (file `ftpcfdrv.h').             */
   /*                                                                       */
   /* `FREETYPE_PROPERTIES' has the following syntax form (broken here into */
   /* multiple lines for better readability).                               */
@@ -835,6 +835,33 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*************************************************************************/
   /****                                                                 ****/
+  /****         P C F   D R I V E R    C O N F I G U R A T I O N        ****/
+  /****                                                                 ****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* There are many PCF fonts just called `Fixed' which look completely    */
+  /* different, and which have nothing to do with each other.  When        */
+  /* selecting `Fixed' in KDE or Gnome one gets results that appear rather */
+  /* random, the style changes often if one changes the size and one       */
+  /* cannot select some fonts at all.  This option makes the PCF module    */
+  /* prepend the foundry name (plus a space) to the family name.           */
+  /*                                                                       */
+  /* We also check whether we have `wide' characters; all put together, we */
+  /* get family names like `Sony Fixed' or `Misc Fixed Wide'.              */
+  /*                                                                       */
+  /* If this option is activated, it can be controlled with the            */
+  /* `no-long-family-names' property of the pcf driver module.             */
+  /*                                                                       */
+#define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /****                                                                 ****/
   /****    A U T O F I T   M O D U L E    C O N F I G U R A T I O N     ****/
   /****                                                                 ****/
   /*************************************************************************/
diff --git a/docs/CHANGES b/docs/CHANGES
index cb3b327..3823395 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -1,4 +1,20 @@
 
+CHANGES BETWEEN 2.7.1 and 2.7.2
+
+  I. IMPORTANT CHANGES
+
+    - The PCF change to show more `colourful' family names (introduced
+      in version 2.7.1) was too radical; it can now be configured with
+      PCF_CONFIG_OPTION_LONG_FAMILY_NAMES   at   compile   time.    If
+      activated, it can  be switched off at run time  with the new pcf
+      property  `no-long-family-names'.  If  the `FREETYPE_PROPERTIES'
+      environment variable is available, you can say
+
+        FREETYPE_PROPERTIES=pcf:no-long-family-names=1
+
+
+======================================================================
+
 CHANGES BETWEEN 2.7 and 2.7.1
 
   I. IMPORTANT CHANGES
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index 950d36c..d491af5 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -357,6 +357,19 @@
   /*************************************************************************
    *
    * @macro:
+   *   FT_PCF_DRIVER_H
+   *
+   * @description:
+   *   A macro used in #include statements to name the file containing
+   *   structures and macros related to the PCF driver module.
+   *
+   */
+#define FT_PCF_DRIVER_H  <freetype/ftpcfdrv.h>
+
+
+  /*************************************************************************
+   *
+   * @macro:
    *   FT_TYPE1_TABLES_H
    *
    * @description:
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index f5bc540..5676074 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -82,8 +82,8 @@ FT_BEGIN_HEADER
   /* to control the various font drivers and modules.  The controllable    */
   /* properties are listed in the section `Controlling FreeType Modules'   */
   /* in the reference's table of contents; currently there are properties  */
-  /* for the auto-hinter (file `ftautoh.h'), CFF (file `ftcffdrv.h'), and  */
-  /* TrueType (file `ftttdrv.h').                                          */
+  /* for the auto-hinter (file `ftautoh.h'), CFF (file `ftcffdrv.h'),      */
+  /* TrueType (file `ftttdrv.h'), and PCF (file `ftpcfdrv.h').             */
   /*                                                                       */
   /* `FREETYPE_PROPERTIES' has the following syntax form (broken here into */
   /* multiple lines for better readability).                               */
@@ -835,6 +835,33 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*************************************************************************/
   /****                                                                 ****/
+  /****         P C F   D R I V E R    C O N F I G U R A T I O N        ****/
+  /****                                                                 ****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* There are many PCF fonts just called `Fixed' which look completely    */
+  /* different, and which have nothing to do with each other.  When        */
+  /* selecting `Fixed' in KDE or Gnome one gets results that appear rather */
+  /* random, the style changes often if one changes the size and one       */
+  /* cannot select some fonts at all.  This option makes the PCF module    */
+  /* prepend the foundry name (plus a space) to the family name.           */
+  /*                                                                       */
+  /* We also check whether we have `wide' characters; all put together, we */
+  /* get family names like `Sony Fixed' or `Misc Fixed Wide'.              */
+  /*                                                                       */
+  /* If this option is activated, it can be controlled with the            */
+  /* `no-long-family-names' property of the pcf driver module.             */
+  /*                                                                       */
+#define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /****                                                                 ****/
   /****    A U T O F I T   M O D U L E    C O N F I G U R A T I O N     ****/
   /****                                                                 ****/
   /*************************************************************************/
diff --git a/include/freetype/ftchapters.h b/include/freetype/ftchapters.h
index ab43895..a0a121b 100644
--- a/include/freetype/ftchapters.h
+++ b/include/freetype/ftchapters.h
@@ -77,6 +77,7 @@
 /*    auto_hinter                                                          */
 /*    cff_driver                                                           */
 /*    tt_driver                                                            */
+/*    pcf_driver                                                           */
 /*                                                                         */
 /***************************************************************************/
 
diff --git a/include/freetype/ftpcfdrv.h b/include/freetype/ftpcfdrv.h
new file mode 100644
index 0000000..6622c93
--- /dev/null
+++ b/include/freetype/ftpcfdrv.h
@@ -0,0 +1,105 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftpcfdrv.h                                                             */
+/*                                                                         */
+/*    FreeType API for controlling the PCF driver (specification only).    */
+/*                                                                         */
+/*  Copyright 2017 by                                                      */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#ifndef FTPCFDRV_H_
+#define FTPCFDRV_H_
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#ifdef FREETYPE_H
+#error "freetype.h of FreeType 1 has been loaded!"
+#error "Please fix the directory search order for header files"
+#error "so that freetype.h of FreeType 2 is found first."
+#endif
+
+
+FT_BEGIN_HEADER
+
+
+  /**************************************************************************
+   *
+   * @section:
+   *   pcf_driver
+   *
+   * @title:
+   *   The PCF driver
+   *
+   * @abstract:
+   *   Controlling the PCF driver module.
+   *
+   * @description:
+   *   While FreeType's PCF driver doesn't expose API functions by itself,
+   *   it is possible to control its behaviour with @FT_Property_Set and
+   *   @FT_Property_Get.  Right now, there is a single property
+   *   `no-long-family-names' available if FreeType is compiled with
+   *   PCF_CONFIG_OPTION_LONG_FAMILY_NAMES.
+   *
+   *   The PCF driver's module name is `pcf'.
+   *
+   */
+
+
+  /**************************************************************************
+   *
+   * @property:
+   *   no-long-family-names
+   *
+   * @description:
+   *   If PCF_CONFIG_OPTION_LONG_FAMILY_NAMES is active while compiling
+   *   FreeType, the PCF driver constructs long family names.
+   *
+   *   There are many PCF fonts just called `Fixed' which look completely
+   *   different, and which have nothing to do with each other.  When
+   *   selecting `Fixed' in KDE or Gnome one gets results that appear rather
+   *   random, the style changes often if one changes the size and one
+   *   cannot select some fonts at all.  The improve this situation, the PCF
+   *   module prepends the foundry name (plus a space) to the family name. 
+   *   It also checks whether there are `wide' characters; all put together,
+   *   family names like `Sony Fixed' or `Misc Fixed Wide' are constructed.
+   *
+   *   If `no-long-family-names' is set, this feature gets switched off.
+   *
+   *   {
+   *     FT_Library  library;
+   *     FT_Bool     no_long_family_names = TRUE;
+   *
+   *
+   *     FT_Init_FreeType( &library );
+   *
+   *     FT_Property_Set( library, "pcf",
+   *                               "no-long-family-names",
+   *                               &no_long_family_names );
+   *   }
+   *
+   * @note:
+   *   This property can be used with @FT_Property_Get also.
+   *
+   *   This property can be set via the `FREETYPE_PROPERTIES' environment
+   *   variable (using values 1 and 0 for `on' and `off', respectively).
+   *
+   */
+
+
+FT_END_HEADER
+
+
+#endif /* FTPCFDRV_H_ */
+
+
+/* END */
diff --git a/src/pcf/pcf.h b/src/pcf/pcf.h
index 830cabe..f0390cb 100644
--- a/src/pcf/pcf.h
+++ b/src/pcf/pcf.h
@@ -167,6 +167,8 @@ FT_BEGIN_HEADER
   {
     FT_DriverRec  root;
 
+    FT_Bool  no_long_family_names;
+
   } PCF_DriverRec, *PCF_Driver;
 
 
diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c
index 8f4a90d..bc65423 100644
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -49,6 +49,8 @@ THE SOFTWARE.
 
 #include FT_SERVICE_BDF_H
 #include FT_SERVICE_FONT_FORMAT_H
+#include FT_SERVICE_PROPERTIES_H
+#include FT_PCF_DRIVER_H
 
 
   /*************************************************************************/
@@ -667,6 +669,110 @@ THE SOFTWARE.
   };
 
 
+  /*
+   *  PROPERTY SERVICE
+   *
+   */
+  static FT_Error
+  pcf_property_set( FT_Module    module,         /* PCF_Driver */
+                    const char*  property_name,
+                    const void*  value,
+                    FT_Bool      value_is_string )
+  {
+#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
+
+    FT_Error    error  = FT_Err_Ok;
+    PCF_Driver  driver = (PCF_Driver)module;
+
+#ifndef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
+    FT_UNUSED( value_is_string );
+#endif
+
+
+    if ( !ft_strcmp( property_name, "no-long-family-names" ) )
+    {
+#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
+      if ( value_is_string )
+      {
+        const char*  s   = (const char*)value;
+        long         lfn = ft_strtol( s, NULL, 10 );
+
+
+        if ( lfn == 0 )
+          driver->no_long_family_names = 0;
+        else if ( lfn == 1 )
+          driver->no_long_family_names = 1;
+        else
+          return FT_THROW( Invalid_Argument );
+      }
+      else
+#endif
+      {
+        FT_Bool*  no_long_family_names = (FT_Bool*)value;
+
+
+        driver->no_long_family_names = *no_long_family_names;
+      }
+
+      return error;
+    }
+
+#else /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */
+
+    FT_UNUSED( module );
+    FT_UNUSED( value );
+    FT_UNUSED( value_is_string );
+
+#endif /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */
+
+    FT_TRACE0(( "pcf_property_set: missing property `%s'\n",
+                property_name ));
+    return FT_THROW( Missing_Property );
+  }
+
+
+  static FT_Error
+  pcf_property_get( FT_Module    module,         /* PCF_Driver */
+                    const char*  property_name,
+                    const void*  value )
+  {
+#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
+
+    FT_Error    error  = FT_Err_Ok;
+    PCF_Driver  driver = (PCF_Driver)module;
+
+
+    if ( !ft_strcmp( property_name, "no-long-family-names" ) )
+    {
+      FT_Bool   no_long_family_names = driver->no_long_family_names;
+      FT_Bool*  val                  = (FT_Bool*)value;
+
+
+      *val = no_long_family_names;
+
+      return error;
+    }
+
+#else /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */
+
+    FT_UNUSED( module );
+    FT_UNUSED( value );
+
+#endif /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */
+
+    FT_TRACE0(( "pcf_property_get: missing property `%s'\n",
+                property_name ));
+    return FT_THROW( Missing_Property );
+  }
+
+
+  FT_DEFINE_SERVICE_PROPERTIESREC(
+    pcf_service_properties,
+
+    (FT_Properties_SetFunc)pcf_property_set,      /* set_property */
+    (FT_Properties_GetFunc)pcf_property_get )     /* get_property */
+
+
  /*
   *
   *  SERVICE LIST
@@ -677,6 +783,7 @@ THE SOFTWARE.
   {
     { FT_SERVICE_ID_BDF,         &pcf_service_bdf },
     { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_PCF },
+    { FT_SERVICE_ID_PROPERTIES,  &pcf_service_properties },
     { NULL, NULL }
   };
 
@@ -694,7 +801,14 @@ THE SOFTWARE.
   FT_CALLBACK_DEF( FT_Error )
   pcf_driver_init( FT_Module  module )      /* PCF_Driver */
   {
+#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
+    PCF_Driver  driver = (PCF_Driver)module;
+
+
+    driver->no_long_family_names = 0;
+#else
     FT_UNUSED( module );
+#endif
 
     return FT_Err_Ok;
   }
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 38ba110..3eacf2b 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -1393,57 +1393,75 @@ THE SOFTWARE.
       prop = pcf_find_property( face, "FAMILY_NAME" );
       if ( prop && prop->isString )
       {
-        /* Prepend the foundry name plus a space to the family name.      */
-        /* There are many fonts just called `Fixed' which look completely */
-        /* different, and which have nothing to do with each other.  When */
-        /* selecting `Fixed' in KDE or Gnome one gets results that appear */
-        /* rather random, the style changes often if one changes the size */
-        /* and one cannot select some fonts at all.                       */
-        /*                                                                */
-        /* We also check whether we have `wide' characters; all put       */
-        /* together, we get family names like `Sony Fixed' or `Misc Fixed */
-        /* Wide'.                                                         */
-        PCF_Property  foundry_prop, point_size_prop, average_width_prop;
-
-        int  l    = ft_strlen( prop->value.atom ) + 1;
-        int  wide = 0;
-
-
-        foundry_prop       = pcf_find_property( face, "FOUNDRY" );
-        point_size_prop    = pcf_find_property( face, "POINT_SIZE" );
-        average_width_prop = pcf_find_property( face, "AVERAGE_WIDTH" );
-
-        if ( point_size_prop && average_width_prop )
+
+#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
+
+        PCF_Driver  driver = (PCF_Driver)FT_FACE_DRIVER( face );
+
+
+        if ( !driver->no_long_family_names )
         {
-          if ( average_width_prop->value.l >= point_size_prop->value.l )
+          /* Prepend the foundry name plus a space to the family name.     */
+          /* There are many fonts just called `Fixed' which look           */
+          /* completely different, and which have nothing to do with each  */
+          /* other.  When selecting `Fixed' in KDE or Gnome one gets       */
+          /* results that appear rather random, the style changes often if */
+          /* one changes the size and one cannot select some fonts at all. */
+          /*                                                               */
+          /* We also check whether we have `wide' characters; all put      */
+          /* together, we get family names like `Sony Fixed' or `Misc      */
+          /* Fixed Wide'.                                                  */
+
+          PCF_Property  foundry_prop, point_size_prop, average_width_prop;
+
+          int  l    = ft_strlen( prop->value.atom ) + 1;
+          int  wide = 0;
+
+
+          foundry_prop       = pcf_find_property( face, "FOUNDRY" );
+          point_size_prop    = pcf_find_property( face, "POINT_SIZE" );
+          average_width_prop = pcf_find_property( face, "AVERAGE_WIDTH" );
+
+          if ( point_size_prop && average_width_prop )
           {
-            /* This font is at least square shaped or even wider */
-            wide = 1;
-            l   += ft_strlen( " Wide" );
+            if ( average_width_prop->value.l >= point_size_prop->value.l )
+            {
+              /* This font is at least square shaped or even wider */
+              wide = 1;
+              l   += ft_strlen( " Wide" );
+            }
           }
-        }
 
-        if ( foundry_prop && foundry_prop->isString )
-        {
-          l += ft_strlen( foundry_prop->value.atom ) + 1;
+          if ( foundry_prop && foundry_prop->isString )
+          {
+            l += ft_strlen( foundry_prop->value.atom ) + 1;
 
-          if ( FT_NEW_ARRAY( root->family_name, l ) )
-            goto Exit;
+            if ( FT_NEW_ARRAY( root->family_name, l ) )
+              goto Exit;
+
+            ft_strcpy( root->family_name, foundry_prop->value.atom );
+            ft_strcat( root->family_name, " " );
+            ft_strcat( root->family_name, prop->value.atom );
+          }
+          else
+          {
+            if ( FT_NEW_ARRAY( root->family_name, l ) )
+              goto Exit;
 
-          ft_strcpy( root->family_name, foundry_prop->value.atom );
-          ft_strcat( root->family_name, " " );
-          ft_strcat( root->family_name, prop->value.atom );
+            ft_strcpy( root->family_name, prop->value.atom );
+          }
+
+          if ( wide )
+            ft_strcat( root->family_name, " Wide" );
         }
         else
+
+#endif /* PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */
+
         {
-          if ( FT_NEW_ARRAY( root->family_name, l ) )
+          if ( FT_STRDUP( root->family_name, prop->value.atom ) )
             goto Exit;
-
-          ft_strcpy( root->family_name, prop->value.atom );
         }
-
-        if ( wide )
-          ft_strcat( root->family_name, " Wide" );
       }
       else
         root->family_name = NULL;
-- 
cgit v1.0-41-gc330