File fix-ufo-export.patch of Package fontforge

From 9565a274e00fa2491984c4ce0c45c395dc8545b3 Mon Sep 17 00:00:00 2001
From: MihailJP <mihailjp@gmail.com>
Date: Mon, 15 Dec 2025 06:42:59 +0900
Subject: [PATCH] At UFO export, use family name for styleMapFamilyName (#5672)

* Drop SplineFont::styleMapFamilyName
* Add SFD_GetFontMetaDataData::lastStyleMapFamilyName
---
 fontforge/sfd.c        | 20 +++++++++++++++-----
 fontforge/sfd.h        |  1 +
 fontforge/splinefont.h |  1 -
 fontforge/splineutil.c |  1 -
 fontforge/ufo.c        | 21 ++++-----------------
 5 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/fontforge/sfd.c b/fontforge/sfd.c
index aca965eef5..6b980a4785 100644
--- a/fontforge/sfd.c
+++ b/fontforge/sfd.c
@@ -2254,8 +2254,6 @@ int SFD_DumpSplineFontMetadata( FILE *sfd, SplineFont *sf )
 
     if ( sf->version!=NULL )
 	fprintf(sfd, "Version: %s\n", sf->version );
-    if ( sf->styleMapFamilyName!=NULL )
-	fprintf(sfd, "StyleMapFamilyName: %s\n", sf->styleMapFamilyName );
     if ( sf->fondname!=NULL )
 	fprintf(sfd, "FONDName: %s\n", sf->fondname );
     if ( sf->defbasefilename!=NULL )
@@ -7691,13 +7689,11 @@ bool SFD_GetFontMetaData( FILE *sfd,
     }
     else if ( strmatch(tok,"StyleMapFamilyName:")==0 )
     {
-    sf->styleMapFamilyName = SFDReadUTF7Str(sfd);
+	d->lastStyleMapFamilyName = SFDReadUTF7Str(sfd);
     }
     /* Legacy attribute for StyleMapFamilyName. Deprecated. */
     else if ( strmatch(tok,"OS2FamilyName:")==0 )
     {
-    if (sf->styleMapFamilyName == NULL)
-        sf->styleMapFamilyName = SFDReadUTF7Str(sfd);
     }
     else if ( strmatch(tok,"FONDName:")==0 )
     {
@@ -7738,7 +7734,21 @@ bool SFD_GetFontMetaData( FILE *sfd,
     }
     else if ( strmatch(tok,"LangName:")==0 )
     {
+	struct ttflangname *english;
+
 	sf->names = SFDGetLangName(sfd,sf->names);
+
+	for ( english=sf->names; english!=NULL && english->lang!=0x409; english=english->next );
+	if ( english && d->lastStyleMapFamilyName ) {
+	    if ( english->names[ttf_family] ) {
+		LogError(_("'StyleMapFamilyName' entry has been ignored") );
+		free(d->lastStyleMapFamilyName);
+	    }
+	    else {
+		english->names[ttf_family] = d->lastStyleMapFamilyName;
+	    }
+	    d->lastStyleMapFamilyName = NULL;
+	}
     }
     else if ( strmatch(tok,"GaspTable:")==0 )
     {
diff --git a/fontforge/sfd.h b/fontforge/sfd.h
index caf9838fb4..017d15522d 100644
--- a/fontforge/sfd.h
+++ b/fontforge/sfd.h
@@ -25,6 +25,7 @@ typedef struct sfd_getfontmetadatadata {
 	FPST*                   lastfp;
 	ASM*                    lastsm;
 	struct ttf_table*       lastttf[2];
+	char*                   lastStyleMapFamilyName;
 } SFD_GetFontMetaDataData;
 
 extern void SFD_GetFontMetaDataData_Init(SFD_GetFontMetaDataData* d);
diff --git a/fontforge/splinefont.h b/fontforge/splinefont.h
index 4a1bd99a8c..dae2a530f3 100644
--- a/fontforge/splinefont.h
+++ b/fontforge/splinefont.h
@@ -1343,7 +1343,6 @@ typedef struct splinefont {
     char *woffMetadata;
     real ufo_ascent, ufo_descent;	/* I don't know what these mean, they don't seem to correspond to any other ascent/descent pair, but retain them so round-trip ufo input/output leaves them unchanged */
 	    /* ufo_descent is negative */
-    char *styleMapFamilyName;
     struct sfundoes *undoes;
     int preferred_kerning; // 1 for U. F. O. native, 2 for feature file, 0 undefined. Input functions shall flag 2, I think. This is now in S. F. D. in order to round-trip U. F. O. consistently.
 } SplineFont;
diff --git a/fontforge/splineutil.c b/fontforge/splineutil.c
index 40ba51dd5f..d7c3979d9b 100644
--- a/fontforge/splineutil.c
+++ b/fontforge/splineutil.c
@@ -6584,7 +6584,6 @@ return;
     free(sf->xuid);
     free(sf->cidregistry);
     free(sf->ordering);
-    if ( sf->styleMapFamilyName && sf->styleMapFamilyName[0]!='\0' ) { free(sf->styleMapFamilyName); sf->styleMapFamilyName = NULL; }
     MacFeatListFree(sf->features);
     /* We don't free the EncMap. That field is only a temporary pointer. Let the FontViewBase free it, that's where it really lives */
     // TODO: But that doesn't always get freed. The statement below causes double-frees, so we need to come up with better conditions.
diff --git a/fontforge/ufo.c b/fontforge/ufo.c
index d686333593..a45bdf4f62 100644
--- a/fontforge/ufo.c
+++ b/fontforge/ufo.c
@@ -1170,19 +1170,8 @@ static int UFOOutputFontInfo(const char *basedir, SplineFont *sf, int layer, int
     if (styleNameSynthetic)
 	    PListAddString(dictnode,"styleName",styleNameSynthetic);
     {
-        char* preferredFamilyName = fetchTTFAttribute(sf,ttf_preffamilyname);
-        char* preferredSubfamilyName = fetchTTFAttribute(sf,ttf_prefmodifiers);
-        char* styleMapFamily = NULL;
-        if (sf->styleMapFamilyName != NULL) {
-            /* Empty styleMapStyleName means we imported a UFO that does not have this field. Bypass the fallback. */
-            if (sf->styleMapFamilyName[0]!='\0')
-                styleMapFamily = sf->styleMapFamilyName;
-        } else if (preferredFamilyName != NULL && preferredSubfamilyName != NULL) {
-            styleMapFamily = malloc(strlen(preferredFamilyName)+strlen(preferredSubfamilyName)+2);
-            strcpy(styleMapFamily, preferredFamilyName);
-            strcat(styleMapFamily, " ");
-            strcat(styleMapFamily, preferredSubfamilyName);
-        } else if (sf->fullname != NULL) styleMapFamily = sf->fullname;
+        char* styleMapFamily = fetchTTFAttribute(sf,ttf_family);
+        if (styleMapFamily == NULL && sf->familyname != NULL) styleMapFamily = sf->familyname;
         if (styleMapFamily != NULL) PListAddString(dictnode,"styleMapFamilyName", styleMapFamily);
     }
     {
@@ -3840,8 +3829,8 @@ SplineFont *SFReadUFO(char *basedir, int flags) {
 		else free(valname);
 	    }
 	    else if ( xmlStrcmp(keyname,(xmlChar *) "styleMapFamilyName")==0 ) {
-		if (sf->styleMapFamilyName == NULL) sf->styleMapFamilyName = (char *) valname;
-		else free(valname);
+		if (strcmp((char *) valname, sf->familyname) != 0)
+		    UFOAddName(sf,(char *) valname, ttf_family);
 	    }
 	    else if ( xmlStrcmp(keyname,(xmlChar *) "styleMapStyleName")==0 ) {
 		if (strcmp((char *) valname, "regular")==0) sf->pfminfo.stylemap = 0x40;
@@ -4111,8 +4100,6 @@ SplineFont *SFReadUFO(char *basedir, int flags) {
     if ( sf->familyname==NULL )
 	sf->familyname = copy(sf->fontname);
     free(stylename); stylename = NULL;
-    if (sf->styleMapFamilyName == NULL)
-        sf->styleMapFamilyName = ""; // Empty default to disable fallback at export (not user-accessible anyway as of now).
     if ( sf->weight==NULL )
 	sf->weight = copy("Regular");
     // We can now free the document.
openSUSE Build Service is sponsored by