chiark / gitweb /
Generate 'head' table for TTX
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 2 Nov 2024 10:02:28 +0000 (10:02 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 14 Nov 2024 22:27:18 +0000 (22:27 +0000)
bedstead.c

index f44517d891a854a6c939c3407563d10848e06b16..3db3a4e3cfeb6027c4b5b014ad926493a6baad38 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
+
+#define VERSION "002.009"
 
 #define XSIZE 6
 #define YSIZE 10
@@ -2674,6 +2677,31 @@ fullname_to_fontname(char const *fullname)
        return fontname;
 }
 
+/* Get a suitable asctime-format time string for a TTX file. */
+static char *
+time_for_ttx(void)
+{
+       time_t now;
+       struct tm *timeptr;
+       char *timestr;
+
+       /* Work out what timestamp to use. */
+       now = time(NULL);
+       if (now == (time_t)-1) {
+               fprintf(stderr, "Can't get current time\n");
+               return NULL;
+       }
+       timeptr = gmtime(&now);
+       if (timeptr == NULL) {
+               fprintf(stderr, "Can't convert time to UTC\n");
+               return NULL;
+       }
+       timestr = asctime(timeptr);
+       assert(strlen(timestr) == 25);
+       timestr[24] = '\0'; /* Remove newline. */
+       return timestr;
+}
+
 static int
 compare_glyphs_by_name(const void *va, const void *vb)
 {
@@ -2731,7 +2759,7 @@ main(int argc, char **argv)
        bool gen_bdf = false;
        int i;
        int extraglyphs = 0;
-       char *endptr;
+       char *endptr, *timestr;
 
        if (argc == 2 && strcmp(argv[1], "--complement") == 0) {
                glyph_complement();
@@ -2816,6 +2844,34 @@ main(int argc, char **argv)
                        extraglyphs++;
        printf("<?xml version='1.0'?>\n");
        printf("<ttFont sfntVersion='OTTO'>\n");
+       printf(" <head>\n");
+       printf("  <tableVersion value='1.0'/>\n");
+       printf("  <fontRevision value='%s'/>\n", VERSION);
+       printf("  <checkSumAdjustment value='0'/>\n");
+       printf("  <magicNumber value='0x5f0f3cf5'/>\n");
+       /*
+        * Flags:
+        *  Baseline and left sidebearing point at (0,0)
+        *  Force ppem to integer
+        */
+       printf("  <flags value='00000000 00001011'/>\n");
+       printf("  <unitsPerEm value='%d'/>\n", (int)(YSIZE * YPIX));
+       if ((timestr = time_for_ttx()) == NULL) return 1;
+       printf("  <created value='%s'/>\n", timestr);
+       printf("  <modified value='%s'/>\n", timestr);
+       printf("  <xMin value='%d'/>\n", 0);
+       printf("  <yMin value='%d'/>\n", (int)(-2 * YPIX));
+       printf("  <xMax value='%d'/>\n", (int)(XSIZE * XPIX));
+       printf("  <yMax value='%d'/>\n", (int)((YSIZE - 2) * YPIX));
+       printf("  <macStyle value='00000000 0%c%c000%c'/>\n",
+              width->ttfwidth > 5 ? '1' : '0', /* Expanded? */
+              width->ttfwidth < 5 ? '1' : '0', /* Condensed? */
+              weight->ttfweight > 500 ? '1' : '0'); /* Bold? */
+       printf("  <lowestRecPPEM value='%d'/>\n", (int)YSIZE);
+       printf("  <fontDirectionHint value='0'/>\n"); /* Fully bi-di. */
+       printf("  <indexToLocFormat value='0'/>\n");
+       printf("  <glyphDataFormat value='0'/>\n");
+       printf(" </head>\n");
        /* printf("FontName: %s\n", fullname_to_fontname(get_fullname())); */
        /* printf("FullName: %s\n", get_fullname()); */
        /* printf("FamilyName: Bedstead\n"); */