diff options
author | Christopher Zimmermann <madroach@gmerlin.de> | 2020-10-24 11:41:32 +0200 |
---|---|---|
committer | Christopher Zimmermann <madroach@gmerlin.de> | 2020-10-26 08:45:20 +0100 |
commit | 899eadee6750ea39ddb6b874529c29c011599bb2 (patch) | |
tree | a3bdd230dc1107b397fe519536116b2883b12a9d | |
parent | 5f2307d883de6ddf55f499f1690840747b1a3ad9 (diff) |
Fall back to using FONT property as family name
-rw-r--r-- | fonttosfnt.h | 1 | ||||
-rw-r--r-- | read.c | 48 | ||||
-rw-r--r-- | util.c | 18 |
3 files changed, 43 insertions, 24 deletions
diff --git a/fonttosfnt.h b/fonttosfnt.h index 0dcc31c..53d9587 100644 --- a/fonttosfnt.h +++ b/fonttosfnt.h @@ -191,6 +191,7 @@ unsigned faceFoundry(FT_Face); char *faceEncoding(FT_Face); int faceFlags(FT_Face); int faceIntProp(FT_Face, const char *); +char *faceStringProp(FT_Face, const char *); int faceWeight(FT_Face); int faceWidth(FT_Face); int faceItalicAngle(FT_Face); @@ -103,7 +103,7 @@ readFile(char *filename, FontPtr font) BitmapPtr bitmap; int symbol = 0; int force_unicode = 1; - const char *encoding_name, *file_format; + const char *family_name, *encoding_name, *file_format; FontMapPtr mapping = NULL; FontMapReversePtr reverse = NULL; @@ -171,6 +171,11 @@ readFile(char *filename, FontPtr font) } } + if(face->family_name) + family_name = face->family_name; + else + family_name = faceStringProp(face, "FONT"); + if(verbose_flag) { fprintf(stderr, "%s %s %s: %d sizes%s\n", filename ? filename : "<stdin>", @@ -178,15 +183,14 @@ readFile(char *filename, FontPtr font) symbol ? " (symbol)" : ""); } - if(font->numNames == 0 && face->style_name && face->family_name) { - char *full_name, *unique_name; - BDF_PropertyRec prop; + if(font->numNames == 0 && face->style_name && family_name) { + char *full_name, *unique_name, *buf; int i; if(strcmp(face->style_name, "Regular") == 0) - full_name = sprintf_alloc("%s", face->family_name); + full_name = sprintf_alloc("%s", family_name); else full_name = sprintf_alloc("%s %s", - face->family_name, face->style_name); + family_name, face->style_name); /* The unique name doesn't actually need to be globally unique; it only needs to be unique among all installed fonts on a @@ -214,17 +218,18 @@ readFile(char *filename, FontPtr font) } i = 0; - rc = FT_Get_BDF_Property(face, "COPYRIGHT", &prop); - if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) { + buf = faceStringProp(face, "COPYRIGHT"); + if(buf) { font->names[i].nid = 0; - font->names[i].size = 2 * strlen(prop.u.atom); - font->names[i].value = makeUTF16((char*)prop.u.atom); + font->names[i].size = 2 * strlen(buf); + font->names[i].value = makeUTF16(buf); + free(buf); i++; - } + } font->names[i].nid = 1; - font->names[i].size = 2 * strlen(face->family_name); - font->names[i].value = makeUTF16(face->family_name); + font->names[i].size = 2 * strlen(family_name); + font->names[i].value = makeUTF16(family_name); i++; font->names[i].nid = 2; @@ -247,19 +252,14 @@ readFile(char *filename, FontPtr font) font->names[i].value = makeUTF16("Version 0.0"); i++; - rc = FT_Get_BDF_Property(face, "FOUNDRY", &prop); - if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) { + buf = faceStringProp(face, "FOUNDRY"); + if(buf) { font->names[i].nid = 8; - if(prop.u.atom) { - font->names[i].size = 2 * strlen(prop.u.atom); - font->names[i].value = makeUTF16((char*)prop.u.atom); - } - else { - font->names[i].size = 0; - font->names[i].value = makeUTF16(""); - } + font->names[i].size = 2 * strlen(buf); + font->names[i].value = makeUTF16(buf); + free(buf); i++; - } + } font->names[i].nid = 10; font->names[i].size = 2 * strlen(XVENDORNAMESHORT @@ -405,6 +405,24 @@ faceIntProp(FT_Face face, const char *name) } char * +faceStringProp(FT_Face face, const char *name) +{ + int rc; + BDF_PropertyRec prop; + char *buf = NULL; + + rc = FT_Get_BDF_Property(face, name, &prop); + if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) { + buf = sprintf_alloc("%s", prop.u.atom ? prop.u.atom : ""); + if(buf == NULL) { + perror("sprintf_alloc failed"); + exit(1); + } + } + return buf; +} + +char * faceEncoding(FT_Face face) { BDF_PropertyRec p1, p2; |