source: buchla-68k/font/svg-glyphs.c@ 018c029

Last change on this file since 018c029 was 018c029, checked in by Thomas Lopatic <thomas@…>, 5 years ago

Create web fonts.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <assert.h>
2#include <stddef.h>
3#include <stdint.h>
4#include <stdio.h>
5
6#include "cg2.c"
7
8int32_t main(int32_t argc, char *argv[])
9{
10 (void)argc;
11 (void)argv;
12
13 for (int32_t glyph = 0; glyph < 256; ++glyph) {
14 int32_t code;
15
16 if (glyph < 32) {
17 code = 10240 + glyph;
18 }
19 else if (glyph < 127) {
20 code = glyph;
21 }
22 else {
23 code = (10240 + 32) + (glyph - 127);
24 }
25
26 char name[16];
27
28 snprintf(name, sizeof(name), "glyphs/%04x.svg", code);
29
30 FILE *fh = fopen(name, "w");
31 assert(fh != NULL);
32
33 fprintf(fh, "<?xml version=\"1.0\"?>\n");
34 fprintf(fh, "<svg width=\"2048\" height=\"3072\" viewBox=\"0 0 2048 3072\" xmlns=\"http://www.w3.org/2000/svg\">\n");
35
36 for (int32_t row = 0; row < cg_rows; ++row) {
37 int32_t y = row * 256 + 8;
38 int32_t bits = cgtable[cg_rows - 1 - row][glyph];
39 int32_t mask = 0x01;
40
41 for (int32_t col = 0; col < 8; ++col) {
42 if ((bits & mask) != 0) {
43 int32_t x = col * 256 + 8;
44
45 fprintf(fh, " <path d=\"M %d %d l 240 0 l 0 240 l -240 0 z\"/>\n", x, y);
46 }
47
48 mask <<= 1;
49 }
50 }
51
52 fprintf(fh, "</svg>\n");
53
54 fclose(fh);
55 }
56
57 return 0;
58}
Note: See TracBrowser for help on using the repository browser.