From: Ben Harris Date: Mon, 31 Jul 2017 16:02:08 +0000 (+0100) Subject: Generate PostScript FontName programmatically from FullName. X-Git-Tag: bedstead-002.000~113 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=df0d4ee7681e48a94c5bf6a177b10350de239c43;p=bedstead.git Generate PostScript FontName programmatically from FullName. 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. --- diff --git a/bedstead.c b/bedstead.c index bdd0328..3016497 100644 --- a/bedstead.c +++ b/bedstead.c @@ -127,7 +127,6 @@ 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");