Commit 3576487add2f0e9691e8c43f8b0cd8e61aebf14f

Werner Lemberg 2016-09-30T08:11:52

[pcf] Enrich family name with foundry name and glyph width info. This is a very old patch from openSuSE (from 2006, submitted to FreeType in 2011) that I forgot to apply. https://build.opensuse.org/package/view_file/openSUSE:Factory/freetype2/freetype2-bitmap-foundry.patch 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'. * src/pcf/pcfread.c (pcf_load_font): Implement it. * docs/CHANGES: Document it.

diff --git a/ChangeLog b/ChangeLog
index ce78d60..6c67f87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2016-09-29  Werner Lemberg  <wl@gnu.org>
 
+	[pcf] Enrich family name with foundry name and glyph width info.
+
+	This is a very old patch from openSuSE (from 2006, submitted to
+	FreeType in 2011) that I forgot to apply.
+
+	  https://build.opensuse.org/package/view_file/openSUSE:Factory/freetype2/freetype2-bitmap-foundry.patch
+
+	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'.
+
+	* src/pcf/pcfread.c (pcf_load_font): Implement it.
+
+	* docs/CHANGES: Document it.
+
+2016-09-29  Werner Lemberg  <wl@gnu.org>
+
 	[ftfuzzer] Speed up.
 
 	* src/tools/ftfuzzer/ftfuzzer.cc (LLVMFuzzerTestOneInput): Don't
diff --git a/docs/CHANGES b/docs/CHANGES
index 307d83c..c7c2cd4 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -24,6 +24,12 @@ CHANGES BETWEEN 2.7 and 2.7.1
       and the number of CVT entries.  Please report if you encounter a
       font where the selected values are not adequate.
 
+    - PCF family names are made more `colourful'; they now include the
+      foundry  and information  whether they contain  wide characters.
+      For example,  you no longer get `Fixed' but  rather `Sony Fixed'
+      or `Misc Fixed Wide'.
+
+
 ======================================================================
 
 CHANGES BETWEEN 2.6.5 and 2.7
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 3917a75..60a6e92 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -1266,8 +1266,57 @@ THE SOFTWARE.
       prop = pcf_find_property( face, "FAMILY_NAME" );
       if ( prop && prop->isString )
       {
-        if ( FT_STRDUP( root->family_name, prop->value.atom ) )
-          goto Exit;
+        /* 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 )
+        {
+          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 ( 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, prop->value.atom );
+        }
+
+        if ( wide )
+          ft_strcat( root->family_name, " Wide" );
       }
       else
         root->family_name = NULL;