Commit 3fd158d0ce3662f370b49b3a84ad59a1e09b4340

Bram Tassyns 2011-03-07T09:33:53

Fix Savannah bug #27988. * src/cff/cffobjs.c (remove_style): New function. (cff_face_init): Use it to strip off the style part of the family name.

diff --git a/ChangeLog b/ChangeLog
index 8fa4671..d55640d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-27  Bram Tassyns  <bramt@enfocus.be>
+
+	Fix Savannah bug #27988.
+
+	* src/cff/cffobjs.c (remove_style): New function.
+	(cff_face_init): Use it to strip off the style part of the family
+	name.
+
 2011-03-07  Werner Lemberg  <wl@gnu.org>
 
 	* docs/CHANGES: Updated.
@@ -145,7 +153,7 @@
 	[truetype] Improve handling of stack underflow.
 
 	* src/truetype/ttinterp.c (TT_RunIns, Ins_FLIPPT, Ins_DELTAP,
-	Ins_DELTAC): Exit with error only if `pedantic_hinting' is set. 
+	Ins_DELTAC): Exit with error only if `pedantic_hinting' is set.
 	Otherwise, try to do something sane.
 
 2011-01-30  Werner Lemberg  <wl@gnu.org>
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index d8913c2..fdb58a4 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -429,6 +429,51 @@
   }
 
 
+  /* Remove the style part from the family name (if present). */
+
+  static void
+  remove_style( FT_String*        family_name,
+                const FT_String*  style_name )
+  {
+    FT_Int32  family_name_length, style_name_length;
+
+
+    family_name_length = strlen( family_name );
+    style_name_length  = strlen( style_name );
+
+    if ( family_name_length > style_name_length )
+    {
+      FT_Int  idx;
+
+
+      for ( idx = 1; idx <= style_name_length; ++idx )
+      {
+        if ( family_name[family_name_length - idx] !=
+             style_name[style_name_length - idx] )
+          break;
+      }
+
+      if ( idx > style_name_length )
+      {
+        /* family_name ends with style_name; remove it */
+        idx = family_name_length - style_name_length - 1;
+
+        /* also remove special characters     */
+        /* between real family name and style */
+        while ( idx > 0                     &&
+                ( family_name[idx] == '-' ||
+                  family_name[idx] == ' ' ||
+                  family_name[idx] == '_' ||
+                  family_name[idx] == '+' ) )
+          --idx;
+
+        if ( idx > 0 )
+          family_name[idx + 1] = '\0';
+      }
+    }
+  }
+
+
   FT_LOCAL_DEF( FT_Error )
   cff_face_init( FT_Stream      stream,
                  FT_Face        cffface,        /* CFF_Face */
@@ -758,6 +803,9 @@
                 /* case, the remaining string in `fullp' will be used as */
                 /* the style name.                                       */
                 style_name = cff_strcpy( memory, fullp );
+
+                /* remove the style part from the family name (if present) */
+                remove_style( cffface->family_name, style_name ); 
               }
               break;
             }