summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-07 16:50:17 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-05-07 16:50:17 +0000
commit4aed351e3376d70cedf1dfbcf4f396cc904e2703 (patch)
treed3412d04166396c092ab35398f1d0d271b43750e /src
parent1b4de3064739d6232c98fe7f35c5490821a49d04 (diff)
downloadttf2f-4aed351e3376d70cedf1dfbcf4f396cc904e2703.tar.gz
ttf2f-4aed351e3376d70cedf1dfbcf4f396cc904e2703.tar.bz2
Command line interface
svn path=/trunk/tools/ttf2f/; revision=7430
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/cli.c100
2 files changed, 101 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 4f16a84..0bd3fb2 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
# Sources
-DIR_SOURCES := encoding.c ft.c glyphs.c intmetrics.c outlines.c utils.c
+DIR_SOURCES := cli.c encoding.c ft.c glyphs.c intmetrics.c outlines.c utils.c
include build/makefiles/Makefile.subdir
diff --git a/src/cli.c b/src/cli.c
new file mode 100644
index 0000000..269cf34
--- /dev/null
+++ b/src/cli.c
@@ -0,0 +1,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;
+}
+