chiark / gitweb /
Generate PostScript FontName programmatically from FullName.
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 31 Jul 2017 16:02:08 +0000 (17:02 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Mon, 31 Jul 2017 16:02:08 +0000 (17:02 +0100)
This has th unfortunate effect of changing the FontName of Bedstead
Semi Condensed from Bedstead-Semicondensed to Bedstead-SemiCondensed.
The former name was an error.

bedstead.c

index bdd0328afa0ca4be25a9e4c23d41d7b8f15b8889..3016497fead1b2aa52c7ef6d47bf4484eaa7793e 100644 (file)
 
 struct width {
        char const * option;
-       char const * fontname;
        char const * fullname;
        int xpix;
        int ttfwidth;
@@ -136,37 +135,37 @@ struct width {
 struct width const widths[] = {
        {
                "--normal",
-               "Bedstead", "Bedstead",
+               "Bedstead",
                100,            /* xpix */
                5,              /* ttfwidth */
        },
        {
                "--ultra-condensed",
-               "Bedstead-UltraCondensed", "Bedstead Ultra Condensed",
+               "Bedstead Ultra Condensed",
                50,             /* xpix */
                1,              /* ttfwidth */
        },
        {
                "--extra-condensed",
-               "Bedstead-ExtraCondensed", "Bedstead Extra Condensed",
+               "Bedstead Extra Condensed",
                62,             /* xpix */
                2,              /* ttfwidth */
        },
        {
                "--condensed",
-               "Bedstead-Condensed", "Bedstead Condensed",
+               "Bedstead Condensed",
                76,             /* xpix */
                3,              /* ttfwidth */
        },
        {
                "--semi-condensed",
-               "Bedstead-Semicondensed", "Bedstead Semi Condensed",
+               "Bedstead Semi Condensed",
                88,             /* xpix */
                4,              /* ttfwidth */
        },
        {
                "--extended",
-               "Bedstead-Extended", "Bedstead Extended",
+               "Bedstead Extended",
                124,            /* xpix */
                7,              /* ttfwidth */
        },
@@ -1260,6 +1259,29 @@ getpix(char const data[YSIZE], int x, int y, unsigned flags)
 
 static bool plottermode = false;
 
+static char * fullname_to_fontname(char const *fullname)
+{
+#define FONTNAME_MAX 29 /* Adobe-recommended limit */
+       static char fontname[FONTNAME_MAX + 1], *op = fontname;
+       char const *p = fullname;
+       bool gotfamily = false;
+
+       while (*p != '\0') {
+               assert(op - fontname <= FONTNAME_MAX);
+               if (*p == ' ') {
+                       if (!gotfamily) {
+                               *op++ = '-';
+                               gotfamily = true;
+                       }
+               } else {
+                       *op++ = *p;
+               }
+               ++p;
+       }
+       *op++ = '\0';
+       return fontname;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -1324,7 +1346,7 @@ main(int argc, char **argv)
                if (glyphs[i].unicode == -1)
                        extraglyphs++;
        printf("SplineFontDB: 3.0\n");
-       printf("FontName: %s\n", width->fontname);
+       printf("FontName: %s\n", fullname_to_fontname(width->fullname));
        printf("FullName: %s\n", width->fullname);
        printf("FamilyName: Bedstead\n");
        printf("Weight: Medium\n");