chiark / gitweb /
Very rough code for a single-line skeleton font.
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 17 Jul 2017 20:19:03 +0000 (21:19 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Mon, 17 Jul 2017 20:19:03 +0000 (21:19 +0100)
This uses a different dochar() function which currently emits a lot of
little path fragments in roughly the right places.

bedstead.c

index fff2d67c16094bcfaeb11da051df63047edffe1f..45fc759ceb16d4220231eb2ff15226a22b6c0006 100644 (file)
@@ -189,6 +189,7 @@ struct param const *param = &params[0];
 
 void doprologue(void);
 void dochar(char const data[YSIZE], unsigned flags);
+static void dochar_plotter(char const data[YSIZE], unsigned flags);
 static void domosaic(unsigned code, bool sep);
 static void dopanose();
 
@@ -1238,6 +1239,8 @@ getpix(char const data[YSIZE], int x, int y, unsigned flags)
                return (data[y] >> (XSIZE - x - 1)) & 1;
 }
 
+static bool plottermode = false;
+
 int
 main(int argc, char **argv)
 {
@@ -1254,7 +1257,10 @@ main(int argc, char **argv)
                                argv++; argc--;
                                goto next;
                        }
-               if (strcmp(argv[1], "--") == 0) {
+               if (strcmp(argv[1], "--plotter") == 0) {
+                       plottermode = true;
+                       argv++; argc--;
+               } else if (strcmp(argv[1], "--") == 0) {
                        argv++; argc--;
                        break;
                } else if (argv[1][0] == '-') {
@@ -1331,6 +1337,10 @@ main(int argc, char **argv)
        printf("DisplaySize: -24\n");
        printf("AntiAlias: 1\n");
        printf("FitToEm: 1\n");
+       if (plottermode) {
+               printf("StrokedFont: 1\n");
+               printf("StrokeWidth: 50\n");
+       }
        printf("BeginPrivate: 2\n");
        printf(" StdHW 5 [%d]\n", YPIX);
        printf(" StdVW 5 [%d]\n", XPIX);
@@ -1374,8 +1384,12 @@ main(int argc, char **argv)
                if (glyphs[i].flags & MOS)
                        domosaic(glyphs[i].data[0],
                                 (glyphs[i].data[0] & 0x20) != 0);
-               else
-                       dochar(glyphs[i].data, glyphs[i].flags);
+               else {
+                       if (plottermode)
+                               dochar_plotter(glyphs[i].data, glyphs[i].flags);
+                       else
+                               dochar(glyphs[i].data, glyphs[i].flags);
+               }
                printf("EndChar\n");
        }
        printf("EndChars\n");
@@ -1884,6 +1898,30 @@ dochar(char const data[YSIZE], unsigned flags)
        emit_path();
 }
 
+static void
+dochar_plotter(char const data[YSIZE], unsigned flags)
+{
+       int x, y;
+
+#define CONNECT(dx, dy) do { \
+               moveto(x * XPIX_S, (YSIZE-y-1) * YPIX_S); \
+               lineto((x+dx) * XPIX_S, (YSIZE-y-1+dy) * YPIX_S); \
+       } while (0)
+       
+       clearpath();
+       for (x = 0; x < XSIZE; x++) {
+               for (y = 0; y < YSIZE; y++) {
+                       if (GETPIX(x, y)) {
+                               if (R) CONNECT(1, 0);
+                               if (D) CONNECT(0, -1);
+                               if (DR && !D && !R) CONNECT(1, -1);
+                               if (DL && !D && !L) CONNECT(-1, -1);
+                       }
+               }
+       }
+       emit_path();
+}
+
 static void
 tile(int x0, int y0, int x1, int y1)
 {