shithub: freetype+ttf2subf

Download patch

ref: 3fd158d0ce3662f370b49b3a84ad59a1e09b4340
parent: 9c111b01798ac8c3f39c1a2fdd3ab960effc2077
author: Bram Tassyns <[email protected]>
date: Mon Mar 7 04:33:53 EST 2011

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.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-27  Bram Tassyns  <[email protected]>
+
+	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  <[email protected]>
 
 	* 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  <[email protected]>
--- 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;
             }