From 40a5383c82272dd22d2c1dd2c06a506b80eb2163 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 30 Sep 2009 20:28:06 +0100 Subject: [PATCH] Arrange to emit an SFD file instead of PostScript. The result is broken in various ways, but it can at least be loaded into Fontforge. --- ttxt.c | 302 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 167 insertions(+), 135 deletions(-) diff --git a/ttxt.c b/ttxt.c index 89f33b4..d7a0c2d 100644 --- a/ttxt.c +++ b/ttxt.c @@ -20,114 +20,117 @@ getpix(char data[YSIZE], int x, int y) { void doprologue(void); void dochar(char data[YSIZE]); -char data[][YSIZE] = { - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 004, 004, 004, 004, 004, 000, 004, 000, 000, 000, - 012, 012, 012, 000, 000, 000, 000, 000, 000, 000, - 012, 012, 037, 012, 037, 012, 012, 000, 000, 000, - 016, 025, 024, 016, 005, 025, 016, 000, 000, 000, - 030, 031, 002, 004, 010, 023, 003, 000, 000, 000, - 010, 024, 024, 010, 025, 022, 015, 000, 000, 000, - 004, 004, 004, 000, 000, 000, 000, 000, 000, 000, - 002, 004, 010, 010, 010, 004, 002, 000, 000, 000, - 010, 004, 002, 002, 002, 004, 010, 000, 000, 000, - 004, 025, 016, 004, 016, 025, 004, 000, 000, 000, - 000, 004, 004, 037, 004, 004, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 004, 004, 010, 000, 000, - 000, 000, 000, 016, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 004, 000, 000, 000, - 000, 001, 002, 004, 010, 020, 000, 000, 000, 000, - 004, 012, 021, 021, 021, 012, 004, 000, 000, 000, /* 0 */ - 004, 014, 004, 004, 004, 004, 016, 000, 000, 000, /* 1 */ - 016, 021, 001, 006, 010, 020, 037, 000, 000, 000, /* 2 */ - 037, 001, 002, 006, 001, 021, 016, 000, 000, 000, - 002, 006, 012, 022, 037, 002, 002, 000, 000, 000, - 037, 020, 036, 001, 001, 021, 016, 000, 000, 000, - 006, 010, 020, 036, 021, 021, 016, 000, 000, 000, - 037, 001, 002, 004, 010, 010, 010, 000, 000, 000, - 016, 021, 021, 016, 021, 021, 016, 000, 000, 000, - 016, 021, 021, 017, 001, 002, 014, 000, 000, 000, - 000, 000, 004, 000, 000, 000, 004, 000, 000, 000, - 000, 000, 004, 000, 000, 004, 004, 010, 000, 000, - 002, 004, 010, 020, 010, 004, 002, 000, 000, 000, - 000, 000, 037, 000, 037, 000, 000, 000, 000, 000, - 010, 004, 002, 001, 002, 004, 010, 000, 000, 000, - 016, 021, 002, 004, 004, 000, 004, 000, 000, 000, - 016, 021, 027, 025, 027, 020, 016, 000, 000, 000, - 004, 012, 021, 021, 037, 021, 021, 000, 000, 000, - 036, 021, 021, 036, 021, 021, 036, 000, 000, 000, - 016, 021, 020, 020, 020, 021, 016, 000, 000, 000, - 036, 021, 021, 021, 021, 021, 036, 000, 000, 000, - 037, 020, 020, 036, 020, 020, 037, 000, 000, 000, - 037, 020, 020, 036, 020, 020, 020, 000, 000, 000, - 016, 021, 020, 020, 023, 021, 016, 000, 000, 000, - 021, 021, 021, 037, 021, 021, 021, 000, 000, 000, - 016, 004, 004, 004, 004, 004, 016, 000, 000, 000, - 001, 001, 001, 001, 001, 021, 016, 000, 000, 000, - 021, 022, 024, 030, 024, 022, 021, 000, 000, 000, - 020, 020, 020, 020, 020, 020, 037, 000, 000, 000, - 021, 033, 025, 021, 021, 021, 021, 000, 000, 000, - 021, 021, 031, 025, 023, 021, 021, 000, 000, 000, - 016, 021, 021, 021, 021, 021, 016, 000, 000, 000, - 036, 021, 021, 036, 020, 020, 020, 000, 000, 000, - 016, 021, 021, 021, 025, 022, 015, 000, 000, 000, - 036, 021, 021, 036, 024, 022, 021, 000, 000, 000, - 016, 021, 020, 016, 001, 021, 016, 000, 000, 000, - 037, 004, 004, 004, 004, 004, 004, 000, 000, 000, /* T */ - 021, 021, 021, 021, 021, 021, 016, 000, 000, 000, - 021, 021, 021, 012, 012, 004, 004, 000, 000, 000, - 021, 021, 021, 025, 025, 025, 012, 000, 000, 000, - 021, 021, 012, 004, 012, 021, 021, 000, 000, 000, - 021, 021, 012, 004, 004, 004, 004, 000, 000, 000, - 037, 001, 002, 004, 010, 020, 037, 000, 000, 000, /* Z */ - 016, 010, 010, 010, 010, 010, 016, 000, 000, 000, /* bracketleft */ - 000, 020, 010, 004, 002, 001, 000, 000, 000, 000, /* backslash */ - 016, 002, 002, 002, 002, 002, 016, 000, 000, 000, /* bracketright */ - 004, 012, 021, 000, 000, 000, 000, 000, 000, 000, /* asciicircum */ - 000, 000, 000, 000, 000, 000, 000, 037, 000, 000, /* underscore */ - 010, 004, 002, 000, 000, 000, 000, 000, 000, 000, /* asciigrave */ - 000, 000, 016, 001, 017, 021, 017, 000, 000, 000, - 020, 020, 036, 021, 021, 021, 036, 000, 000, 000, - 000, 000, 017, 020, 020, 020, 017, 000, 000, 000, - 001, 001, 017, 021, 021, 021, 017, 000, 000, 000, - 000, 000, 016, 021, 037, 020, 016, 000, 000, 000, /* e */ - 002, 004, 004, 016, 004, 004, 004, 000, 000, 000, - 000, 000, 017, 021, 021, 021, 017, 001, 016, 000, - 020, 020, 036, 021, 021, 021, 021, 000, 000, 000, - 004, 000, 014, 004, 004, 004, 016, 000, 000, 000, - 004, 000, 004, 004, 004, 004, 004, 004, 010, 000, - 010, 010, 011, 012, 014, 012, 011, 000, 000, 000, - 014, 004, 004, 004, 004, 004, 016, 000, 000, 000, - 000, 000, 032, 025, 025, 025, 025, 000, 000, 000, - 000, 000, 036, 021, 021, 021, 021, 000, 000, 000, - 000, 000, 016, 021, 021, 021, 016, 000, 000, 000, - 000, 000, 036, 021, 021, 021, 036, 020, 020, 000, - 000, 000, 017, 021, 021, 021, 017, 001, 001, 000, - 000, 000, 013, 014, 010, 010, 010, 000, 000, 000, - 000, 000, 017, 020, 016, 001, 036, 000, 000, 000, - 004, 004, 016, 004, 004, 004, 002, 000, 000, 000, - 000, 000, 021, 021, 021, 021, 017, 000, 000, 000, - 000, 000, 021, 021, 012, 012, 004, 000, 000, 000, - 000, 000, 021, 021, 025, 025, 012, 000, 000, 000, - 000, 000, 021, 012, 004, 012, 021, 000, 000, 000, - 000, 000, 021, 021, 021, 021, 017, 001, 016, 000, - 000, 000, 037, 002, 004, 010, 037, 000, 000, 000, - 003, 004, 004, 030, 004, 004, 003, 000, 000, 000, /* braceleft */ - 004, 004, 004, 004, 004, 004, 004, 000, 000, 000, /* bar */ - 030, 004, 004, 003, 004, 004, 030, 000, 000, 000, /* braceright */ - 010, 025, 002, 000, 000, 000, 000, 000, 000, 000, /* asciitilde */ - 037, 037, 037, 037, 037, 037, 037, 000, 000, 000, - - 000, 004, 010, 037, 010, 004, 000, 000, 000, 000, /* leftarrow */ - 020, 020, 020, 020, 026, 001, 002, 004, 007, 000, /* onehalf */ - 000, 004, 002, 037, 002, 004, 000, 000, 000, 000, /* rightarrow */ - 000, 004, 016, 025, 004, 004, 000, 000, 000, 000, /* uparrow */ - 000, 000, 000, 037, 000, 000, 000, 000, 000, 000, /* endash */ - 006, 011, 010, 010, 034, 010, 010, 037, 000, 000, /* sterling */ - 010, 010, 010, 010, 011, 003, 005, 007, 001, 000, /* onequarter */ - 012, 012, 012, 012, 012, 012, 012, 000, 000, 000, /* doublebar */ - 030, 004, 030, 004, 031, 003, 005, 007, 001, 000, /* threequarters */ - 000, 004, 000, 037, 000, 004, 000, 000, 000, 000, /* divide */ +struct glyph { + char data[YSIZE]; + unsigned unicode; + char const *name; +} glyphs[] = { + {{000,000,000,000,000,000,000,000,000,000}, 0x0020, "space" }, + {{004,004,004,004,004,000,004,000,000,000}, 0x0021, "exclam" }, + {{012,012,012,000,000,000,000,000,000,000}, 0x0022, "quotedbl" }, + {{012,012,037,012,037,012,012,000,000,000}, 0x0023, "numbersign" }, + {{016,025,024,016,005,025,016,000,000,000}, 0x0024, "dollar" }, + {{030,031,002,004,010,023,003,000,000,000}, 0x0025, "percent" }, + {{010,024,024,010,025,022,015,000,000,000}, 0x0026, "ampersand" }, + {{004,004,004,000,000,000,000,000,000,000}, 0x0027, "quotesingle" }, + {{002,004,010,010,010,004,002,000,000,000}, 0x0028, "parenleft" }, + {{010,004,002,002,002,004,010,000,000,000}, 0x0029, "parenright" }, + {{004,025,016,004,016,025,004,000,000,000}, 0x002a, "asterisk" }, + {{000,004,004,037,004,004,000,000,000,000}, 0x002b, "plus" }, + {{000,000,000,000,000,004,004,010,000,000}, 0x002c, "comma" }, + {{000,000,000,016,000,000,000,000,000,000}, 0x002d, "hyphen" }, + {{000,000,000,000,000,000,004,000,000,000}, 0x002e, "period" }, + {{000,001,002,004,010,020,000,000,000,000}, 0x002f, "slash" }, + {{004,012,021,021,021,012,004,000,000,000}, 0x0030, "zero" }, + {{004,014,004,004,004,004,016,000,000,000}, 0x0031, "one" }, + {{016,021,001,006,010,020,037,000,000,000}, 0x0032, "two" }, + {{037,001,002,006,001,021,016,000,000,000}, 0x0033, "three" }, + {{002,006,012,022,037,002,002,000,000,000}, 0x0034, "four" }, + {{037,020,036,001,001,021,016,000,000,000}, 0x0035, "five" }, + {{006,010,020,036,021,021,016,000,000,000}, 0x0036, "six" }, + {{037,001,002,004,010,010,010,000,000,000}, 0x0037, "seven" }, + {{016,021,021,016,021,021,016,000,000,000}, 0x0038, "eight" }, + {{016,021,021,017,001,002,014,000,000,000}, 0x0039, "nine" }, + {{000,000,004,000,000,000,004,000,000,000}, 0x003a, "colon" }, + {{000,000,004,000,000,004,004,010,000,000}, 0x003b, "semicolon" }, + {{002,004,010,020,010,004,002,000,000,000}, 0x003c, "less" }, + {{000,000,037,000,037,000,000,000,000,000}, 0x003d, "equal" }, + {{010,004,002,001,002,004,010,000,000,000}, 0x003e, "greater" }, + {{016,021,002,004,004,000,004,000,000,000}, 0x003f, "question" }, + {{016,021,027,025,027,020,016,000,000,000}, 0x0040, "at" }, + {{004,012,021,021,037,021,021,000,000,000}, 0x0041, "A" }, + {{036,021,021,036,021,021,036,000,000,000}, 0x0042, "B" }, + {{016,021,020,020,020,021,016,000,000,000}, 0x0043, "C" }, + {{036,021,021,021,021,021,036,000,000,000}, 0x0044, "D" }, + {{037,020,020,036,020,020,037,000,000,000}, 0x0045, "E" }, + {{037,020,020,036,020,020,020,000,000,000}, 0x0046, "F" }, + {{016,021,020,020,023,021,016,000,000,000}, 0x0047, "G" }, + {{021,021,021,037,021,021,021,000,000,000}, 0x0048, "H" }, + {{016,004,004,004,004,004,016,000,000,000}, 0x0049, "I" }, + {{001,001,001,001,001,021,016,000,000,000}, 0x004a, "J" }, + {{021,022,024,030,024,022,021,000,000,000}, 0x004b, "K" }, + {{020,020,020,020,020,020,037,000,000,000}, 0x004c, "L" }, + {{021,033,025,021,021,021,021,000,000,000}, 0x004d, "M" }, + {{021,021,031,025,023,021,021,000,000,000}, 0x004e, "N" }, + {{016,021,021,021,021,021,016,000,000,000}, 0x004f, "O" }, + {{036,021,021,036,020,020,020,000,000,000}, 0x0050, "P" }, + {{016,021,021,021,025,022,015,000,000,000}, 0x0051, "Q" }, + {{036,021,021,036,024,022,021,000,000,000}, 0x0052, "R" }, + {{016,021,020,016,001,021,016,000,000,000}, 0x0053, "S" }, + {{037,004,004,004,004,004,004,000,000,000}, 0x0054, "T" }, /* T */ + {{021,021,021,021,021,021,016,000,000,000}, 0x0055, "U" }, + {{021,021,021,012,012,004,004,000,000,000}, 0x0056, "V" }, + {{021,021,021,025,025,025,012,000,000,000}, 0x0057, "W" }, + {{021,021,012,004,012,021,021,000,000,000}, 0x0058, "X" }, + {{021,021,012,004,004,004,004,000,000,000}, 0x0059, "Y" }, + {{037,001,002,004,010,020,037,000,000,000}, 0x005a, "Z" }, /* Z */ + {{016,010,010,010,010,010,016,000,000,000}, 0x005b, "bracketleft" }, + {{000,020,010,004,002,001,000,000,000,000}, 0x005c, "backslash" }, + {{016,002,002,002,002,002,016,000,000,000}, 0x005d, "bracketright" }, + {{004,012,021,000,000,000,000,000,000,000}, 0x005e, "asciicircum" }, + {{000,000,000,000,000,000,000,037,000,000}, 0x005f, "underscore" }, + {{010,004,002,000,000,000,000,000,000,000}, 0x0060, "asciigrave" }, + {{000,000,016,001,017,021,017,000,000,000}, 0x0061, "a" }, + {{020,020,036,021,021,021,036,000,000,000}, 0x0062, "b" }, + {{000,000,017,020,020,020,017,000,000,000}, 0x0063, "c" }, + {{001,001,017,021,021,021,017,000,000,000}, 0x0064, "d" }, + {{000,000,016,021,037,020,016,000,000,000}, 0x0065, "e" }, /* e */ + {{002,004,004,016,004,004,004,000,000,000}, 0x0066, "f" }, + {{000,000,017,021,021,021,017,001,016,000}, 0x0067, "g" }, + {{020,020,036,021,021,021,021,000,000,000}, 0x0068, "h" }, + {{004,000,014,004,004,004,016,000,000,000}, 0x0069, "i" }, + {{004,000,004,004,004,004,004,004,010,000}, 0x006a, "j" }, + {{010,010,011,012,014,012,011,000,000,000}, 0x006b, "k" }, + {{014,004,004,004,004,004,016,000,000,000}, 0x006c, "l" }, + {{000,000,032,025,025,025,025,000,000,000}, 0x006d, "m" }, + {{000,000,036,021,021,021,021,000,000,000}, 0x006e, "n" }, + {{000,000,016,021,021,021,016,000,000,000}, 0x006f, "o" }, + {{000,000,036,021,021,021,036,020,020,000}, 0x0070, "p" }, + {{000,000,017,021,021,021,017,001,001,000}, 0x0071, "q" }, + {{000,000,013,014,010,010,010,000,000,000}, 0x0072, "r" }, + {{000,000,017,020,016,001,036,000,000,000}, 0x0073, "s" }, + {{004,004,016,004,004,004,002,000,000,000}, 0x0074, "t" }, + {{000,000,021,021,021,021,017,000,000,000}, 0x0075, "u" }, + {{000,000,021,021,012,012,004,000,000,000}, 0x0076, "v" }, + {{000,000,021,021,025,025,012,000,000,000}, 0x0077, "w" }, + {{000,000,021,012,004,012,021,000,000,000}, 0x0078, "x" }, + {{000,000,021,021,021,021,017,001,016,000}, 0x0079, "y" }, + {{000,000,037,002,004,010,037,000,000,000}, 0x007a, "z" }, + {{003,004,004,030,004,004,003,000,000,000}, 0x007b, "braceleft" }, + {{004,004,004,004,004,004,004,000,000,000}, 0x007c, "bar" }, + {{030,004,004,003,004,004,030,000,000,000}, 0x007d, "braceright" }, + {{010,025,002,000,000,000,000,000,000,000}, 0x007e, "asciitilde" }, + {{037,037,037,037,037,037,037,000,000,000}, 0x2588, "block" }, + {{000,004,010,037,010,004,000,000,000,000}, 0x2190, "arrowleft" }, + {{020,020,020,020,026,001,002,004,007,000}, 0x00bd, "onehalf" }, + {{000,004,002,037,002,004,000,000,000,000}, 0x2192, "arrowright" }, + {{000,004,016,025,004,004,000,000,000,000}, 0x2191, "arrowup" }, + {{000,000,000,037,000,000,000,000,000,000}, 0x2013, "endash" }, + {{006,011,010,010,034,010,010,037,000,000}, 0x00a3, "sterling" }, + {{010,010,010,010,011,003,005,007,001,000}, 0x00bc, "onequarter" }, + {{012,012,012,012,012,012,012,000,000,000}, 0x0000, "doublebar" }, /*XXX*/ + {{030,004,030,004,031,003,005,007,001,000}, 0x00be, "threequarters" }, + {{000,004,000,037,000,004,000,000,000,000}, 0x00f7, "divide" }, }; int @@ -135,14 +138,40 @@ main(int argc, char **argv) { int i; + printf("SplineFontDB: 3.0\n"); + printf("FontName: TTXT\n"); + printf("FullName: TTXT\n"); + printf("FamilyName: TTXT\n"); + printf("Weight: Medium\n"); + printf("Copyright: Who knows?\n"); + printf("Version: 000.001\n"); + printf("ItalicAngle: 0\n"); + printf("UnderlinePosition: -50\n"); + printf("UnderlineWidth: 50\n"); + printf("Ascent: 700\n"); + printf("Descent: 300\n"); + printf("LayerCount: 2\n"); + printf("Layer: 0 0 \"Back\" 1\n"); + printf("Layer: 1 0 \"Fore\" 0\n"); + printf("Encoding: UnicodeBmp\n"); + printf("NameList: Adobe Glyph List\n"); + printf("DisplaySize: -24\n"); + printf("AntiAlias: 1\n"); + printf("FitToEm: 1\n"); + printf("BeginChars: 65537 105\n"); for (i = 0; i < 105; i++) { - printf("gsave %d %d translate\n", - i % 16 * XSIZE, (6 - i / 16) * YSIZE); - printf("0.25 0.25 scale\n"); - dochar(&data[i][0]); - printf("grestore\n"); + printf("StartChar: %s\n", glyphs[i].name); + printf("Encoding: %d %d %d\n", + glyphs[i].unicode, glyphs[i].unicode, i); + printf("Width: 600\n"); + printf("Flags:\n"); + printf("LayerCount: 2\n"); + printf("Fore\n"); + dochar(glyphs[i].data); + printf("EndChar\n"); } - printf("showpage\n"); + printf("EndChars\n"); + printf("EndSplineFont\n"); return 0; } @@ -241,6 +270,7 @@ vec_bearing(vec v) static void fix_identical(point *p) { + if (!p->next) return; if (vec_eqp(p->next->v, p->v)) killpoint(p); } @@ -262,10 +292,18 @@ vec_inline4(vec a, vec b, vec c, vec d) static void fix_collinear(point *p) { + if (!p->next) return; if (vec_inline3(p->prev->v, p->v, p->next->v)) killpoint(p); } +static void +fix_isolated(point *p) +{ + if (p->next == p) + killpoint(p); +} + static int done_anything; static void @@ -283,20 +321,14 @@ fix_edges(point *a0, point *b0) vec_inline4(b1->v, a0->v, b0->v, a1->v) || vec_inline4(b1->v, a0->v, a1->v, b0->v) || vec_eqp(a0->v, b1->v) || vec_eqp(a1->v, b0->v))) { - if (a0 == b1) - killpoint(a0); - else { - a0->next = b1; b1->prev = a0; - fix_identical(a0); - fix_collinear(b1); - } - if (b0 == a1) - killpoint(b0); - else { - b0->next = a1; a1->prev = b0; - fix_identical(b0); - fix_collinear(a1); - } + a0->next = b1; b1->prev = a0; + b0->next = a1; a1->prev = b0; + fix_isolated(a0); + fix_identical(a0); + fix_collinear(b1); + fix_isolated(b0); + fix_identical(b0); + fix_collinear(a1); done_anything = 1; } } @@ -321,21 +353,21 @@ emit_path() int i; point *p, *p1; - printf("newpath\n"); + printf("SplineSet\n"); for (i = 0; i < nextpoint; i++) { p = &points[i]; if (p->next) { - while (p->next) { - printf(" %d %d %s\n", p->v.x, p->v.y, - p == &points[i] ? "moveto" : "lineto"); + do { + printf(" %d %d %s 1\n", + p->v.x*25, p->v.y*25 - 300, + p == &points[i] && p->next ? "m" : "l"); p1 = p->next; p->prev = p->next = NULL; p = p1; - } - printf(" closepath\n"); + } while (p); } } - printf("stroke\n"); + printf("EndSplineSet\n"); } static void -- 2.30.2