summaryrefslogtreecommitdiff
path: root/src/cli.c
blob: 269cf346b2fa0ffd0aa6d649a341e626ef07b758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <stdlib.h>

#include "encoding.h"
#include "fm.h"
#include "ft.h"
#include "glyph.h"
#include "glyphs.h"
#include "intmetrics.h"
#include "outlines.h"
#include "utils.h"

static void progress(int value)
{
	UNUSED(value);
}

void ttf2f_poll(int active)
{
	UNUSED(active);
}

int main(int argc, char **argv)
{
	int fail;
	int nglyphs;
	struct glyph *glist;
	struct font_metrics *metrics;

	if (argc != 3) {
		fprintf(stderr, "Usage: %s <input.ttf> <output>\n", argv[0]);
		return 1;
	}

	ft_init();
	load_glyph_list();

	fail = open_font(argv[1]);
	if (fail) {
		fprintf(stderr, "ERROR: Failed opening font %s\n", argv[1]);
		return 1;
	}

	nglyphs = count_glyphs();

	glist = calloc(nglyphs, sizeof(struct glyph));
	if (glist == NULL) {
		fprintf(stderr, "ERROR: insufficient memory for glyphs\n");
		return 1;
	}

	for (int i = 0; i != nglyphs; i++) {
		struct glyph *g = &glist[i];

		g->code = -1;
	}

	metrics = calloc(1, sizeof(struct font_metrics));
	if (metrics == NULL) {
		fprintf(stderr, "ERROR: insufficient memory for font metrics\n");
		return 1;
	}

	fail = fnmetrics(metrics);
	if (fail) {
		fprintf(stderr, "ERROR: failed reading font metrics\n");
		return 1;
	}

	fail = glenc(glist);
	if (fail) {
		fprintf(stderr, "ERROR: failed reading glyph encoding\n");
		return 1;
	}

	fail = glnames(glist);
	if (fail) {
		fprintf(stderr, "ERROR: failed reading glyph names\n");
		return 1;
	}

	glmetrics(glist, NULL);

	write_intmetrics("", argv[2], glist, nglyphs, metrics, progress);

	write_outlines("", argv[2], glist, nglyphs, metrics, progress);

	write_encoding("", argv[2], glist, nglyphs, 0, progress);

	free(metrics);
	free(glist);

	close_font();

	ft_fini();
	destroy_glyphs();

	return 0;
}