Browse Source

g.mkfontscap: fix segfault on cygwin & Windows 7

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67034 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 years ago
parent
commit
3790b4dfb4
2 changed files with 18 additions and 10 deletions
  1. 17 9
      general/g.mkfontcap/freetype_fonts.c
  2. 1 1
      general/g.mkfontcap/main.c

+ 17 - 9
general/g.mkfontcap/freetype_fonts.c

@@ -117,8 +117,11 @@ static void find_fonts(const char *dirpath)
 				  maxfonts * sizeof(struct GFONT_CAP));
 		}
 
+		G_debug(3, "find_fonts(): file=%s",  filepath);
 		if (FT_New_Face(ftlibrary, filepath, index, &face) == 0) {
-		    facesinfile = face->num_faces;
+		    if (index == 0)
+			facesinfile = face->num_faces;
+
 		    /* Only use scalable fonts */
 		    if (face->face_flags & FT_FACE_FLAG_SCALABLE) {
 			char *buf_ptr;
@@ -139,14 +142,19 @@ static void find_fonts(const char *dirpath)
 				       buf_ptr, (int)index);
 			else
 			    fontcap[totalfonts].name = G_store(buf_ptr);
-			/* There might not be a style name but there will always be a
-			 * family name. */
-			if (face->style_name == NULL)
-			    fontcap[totalfonts].longname =
-				G_store(face->family_name);
-			else
-			    G_asprintf(&fontcap[totalfonts].longname, "%s %s",
-				       face->family_name, face->style_name);
+			
+			if (face->family_name && face->family_name > (FT_String *) 31) { /* avoid segfault on cygwin */
+			    /* There might not be a style name but there will always be a
+			     * family name. */
+			    if (face->style_name == NULL)
+				fontcap[totalfonts].longname = G_store(face->family_name);
+			    else
+				G_asprintf(&fontcap[totalfonts].longname, "%s %s",
+					   face->family_name, face->style_name);
+			}
+			else {
+			    fontcap[totalfonts].longname = G_store("");
+			}
 			totalfonts++;
 		    }
 

+ 1 - 1
general/g.mkfontcap/main.c

@@ -46,7 +46,7 @@ static const char *standarddirs[] = {
     "${HOME}/Library/Fonts",
     "/Library/Fonts",
     "/System/Library/Fonts",
-    "${WINDIR}/Fonts",
+    "${WINDIR}\\Fonts",
     NULL
 };